From 57603557694718da60c28c48cfc879280ff4b8e3 Mon Sep 17 00:00:00 2001 From: Jan-Lukas Else Date: Thu, 18 Nov 2021 22:56:30 +0100 Subject: [PATCH] Show comment threads --- templates/interactions.gohtml | 13 ++---------- templates/mentions.gohtml | 19 ++++++++++++++++++ webmention.go | 38 ++++++++++++++++++++++++----------- 3 files changed, 47 insertions(+), 23 deletions(-) create mode 100644 templates/mentions.gohtml diff --git a/templates/interactions.gohtml b/templates/interactions.gohtml index 95bc5bd..bf4a0bb 100644 --- a/templates/interactions.gohtml +++ b/templates/interactions.gohtml @@ -1,18 +1,9 @@ {{ define "interactions" }}
{{ string .Blog.Lang "interactions" }} + {{ $rd := . }} {{ with ( mentions .Canonical ) }} - + {{ include "mentions" $rd . }} {{ end }}
diff --git a/templates/mentions.gohtml b/templates/mentions.gohtml new file mode 100644 index 0000000..8bdc3bd --- /dev/null +++ b/templates/mentions.gohtml @@ -0,0 +1,19 @@ +{{ define "mentions" }} + {{ $rd := . }} + +{{ end }} \ No newline at end of file diff --git a/webmention.go b/webmention.go index 7661c48..3263142 100644 --- a/webmention.go +++ b/webmention.go @@ -21,15 +21,16 @@ const ( ) type mention struct { - ID int - Source string - NewSource string - Target string - Created int64 - Title string - Content string - Author string - Status webmentionStatus + ID int + Source string + NewSource string + Target string + Created int64 + Title string + Content string + Author string + Status webmentionStatus + Submentions []*mention } func (a *goBlog) initWebmention() { @@ -156,6 +157,7 @@ type webmentionsRequestConfig struct { id int asc bool offset, limit int + submentions bool } func buildWebmentionsQuery(config *webmentionsRequestConfig) (query string, args []interface{}) { @@ -206,6 +208,17 @@ func (db *database) getWebmentions(config *webmentionsRequestConfig) ([]*mention if err != nil { return nil, err } + if config.submentions { + m.Submentions, err = db.getWebmentions(&webmentionsRequestConfig{ + target: m.Source, + submentions: true, + asc: config.asc, + status: config.status, + }) + if err != nil { + return nil, err + } + } mentions = append(mentions, m) } return mentions, nil @@ -213,9 +226,10 @@ func (db *database) getWebmentions(config *webmentionsRequestConfig) ([]*mention func (db *database) getWebmentionsByAddress(address string) []*mention { mentions, _ := db.getWebmentions(&webmentionsRequestConfig{ - target: address, - status: webmentionStatusApproved, - asc: true, + target: address, + status: webmentionStatusApproved, + asc: true, + submentions: true, }) return mentions }