Skip to content

Commit

Permalink
Show post-replies to ActivityPub-created comments (when they are in r…
Browse files Browse the repository at this point in the history
…eply to the original URL)
  • Loading branch information
jlelse committed Dec 26, 2024
1 parent 8253ad5 commit 44688dc
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 18 deletions.
4 changes: 2 additions & 2 deletions posts.go
Original file line number Diff line number Diff line change
Expand Up @@ -316,13 +316,13 @@ func (a *goBlog) serveIndex(w http.ResponseWriter, r *http.Request) {
visibility = defaultVisibility
}
// Parameter filter
params, paramValues := []string{}, []string{}
params, paramValues := []string{}, [][]string{}
paramUrlValues := url.Values{}
for param, values := range r.URL.Query() {
if strings.HasPrefix(param, "p:") {
paramKey := strings.TrimPrefix(param, "p:")
for _, value := range values {
params, paramValues = append(params, paramKey), append(paramValues, value)
params, paramValues = append(params, paramKey), append(paramValues, []string{value})
paramUrlValues.Add(param, value)
}
}
Expand Down
35 changes: 21 additions & 14 deletions postsDb.go
Original file line number Diff line number Diff line change
Expand Up @@ -374,13 +374,13 @@ type postsRequestConfig struct {
visibility []postVisibility
taxonomy *configTaxonomy
taxonomyValue string
anyParams []string // filter for posts that have any of these parameters (with non-empty values)
allParams []string // filter for posts that have all these parameters (with non-empty values)
allParamValues []string // ... with exactly these values
parameter string // filter for posts that have this parameter (with non-empty value)
parameterValue string // ... with exactly this value
excludeParameter string // exclude posts that have this parameter (with non-empty value)
excludeParameterValue string // ... with exactly this value
anyParams []string // filter for posts that have any of these parameters (with non-empty values)
allParams []string // filter for posts that have all these parameters (with non-empty values)
allParamValues [][]string // ... with exactly these values
parameter string // filter for posts that have this parameter (with non-empty value)
parameterValue string // ... with exactly this value
excludeParameter string // exclude posts that have this parameter (with non-empty value)
excludeParameterValue string // ... with exactly this value
publishedYear, publishedMonth, publishedDay int
publishedBefore time.Time
randomOrder bool
Expand Down Expand Up @@ -451,7 +451,7 @@ func buildPostsQuery(c *postsRequestConfig, selection string) (query string, arg
queryBuilder.WriteString(")")
}
allParams := append(c.allParams, c.parameter)
allParamValues := append(c.allParamValues, c.parameterValue)
allParamValues := append(c.allParamValues, []string{c.parameterValue})
if len(allParams) > 0 {
if len(allParamValues) > 0 && len(allParamValues) != len(allParams) {
return "", nil, errors.New("number of parameters != number of parameter values")
Expand All @@ -461,15 +461,22 @@ func buildPostsQuery(c *postsRequestConfig, selection string) (query string, arg
continue
}
named := "allparam" + strconv.Itoa(i)
paramValue := allParamValues[i]
queryBuilder.WriteString(" and path in (select path from post_parameters where parameter = @")
queryBuilder.WriteString(named)
queryBuilder.WriteString(" and ")
if paramValue != "" {
namedVal := "allparamval" + strconv.Itoa(i)
queryBuilder.WriteString("value = @")
queryBuilder.WriteString(namedVal)
args = append(args, sql.Named(namedVal, paramValue))
paramValues := lo.Filter(allParamValues[i], func(i string, _ int) bool { return i != "" })
if len(paramValues) > 0 {
queryBuilder.WriteString("value in (")
for ii, paramValue := range paramValues {
if ii > 0 {
queryBuilder.WriteString(", ")
}
queryBuilder.WriteString("@")
namedVal := "allparamval" + strconv.Itoa(i) + "x" + strconv.Itoa(ii)
queryBuilder.WriteString(namedVal)
args = append(args, sql.Named(namedVal, paramValue))
}
queryBuilder.WriteString(")")
} else {
queryBuilder.WriteString("length(coalesce(value, '')) > 0")
}
Expand Down
4 changes: 2 additions & 2 deletions webmention.go
Original file line number Diff line number Diff line change
Expand Up @@ -299,8 +299,8 @@ func (a *goBlog) getWebmentions(config *webmentionsRequestConfig) ([]*mention, e
}
if config.replies {
m.Replies, err = a.getPosts(&postsRequestConfig{
parameter: a.cfg.Micropub.ReplyParam,
parameterValue: m.Source,
allParams: []string{a.cfg.Micropub.ReplyParam},
allParamValues: [][]string{{m.Source, m.Url}},
visibility: []postVisibility{visibilityPublic, visibilityUnlisted},
fetchParams: []string{"title", "summary"},
ascendingOrder: true,
Expand Down

0 comments on commit 44688dc

Please sign in to comment.