diff options
author | 2020-06-24 18:52:00 +0200 | |
---|---|---|
committer | 2020-06-24 18:52:00 +0200 | |
commit | 73bbbd365c229f4918e798094e7b82a8336e84c8 (patch) | |
tree | 374c00f472d0b55bbe9c42bf019173991062e8ff | |
parent | Only show threads for popular messages (diff) | |
download | archives-73bbbd365c229f4918e798094e7b82a8336e84c8.tar.gz archives-73bbbd365c229f4918e798094e7b82a8336e84c8.tar.bz2 archives-73bbbd365c229f4918e798094e7b82a8336e84c8.zip |
Fix the InReplyTo reference
The model has been changed and so has to be
the InReplyTo Reference.
Signed-off-by: Max Magorsch <arzano@gentoo.org>
-rw-r--r-- | pkg/app/message/show.go | 22 | ||||
-rw-r--r-- | pkg/app/message/utils.go | 4 | ||||
-rw-r--r-- | web/templates/message/show.tmpl | 4 |
3 files changed, 8 insertions, 22 deletions
diff --git a/pkg/app/message/show.go b/pkg/app/message/show.go index 3d56544..60038d5 100644 --- a/pkg/app/message/show.go +++ b/pkg/app/message/show.go @@ -17,33 +17,21 @@ func Show(w http.ResponseWriter, r *http.Request) { messageHash := urlParts[len(urlParts)-1] message := &models.Message{Id: messageHash} - err := database.DBCon.Select(message) + err := database.DBCon.Model(message). + Relation("InReplyTo"). + WherePK(). + Select() if err != nil { http.NotFound(w, r) return } - var inReplyTos []*models.Message - var inReplyTo *models.Message - if message.InReplyTo != nil { - err = database.DBCon.Model(&inReplyTos). - Where(`(headers::jsonb->>'Message-Id')::jsonb ? '` + message.InReplyTo.Id + `'`). - Select() - if err != nil || len(inReplyTos) < 1 { - inReplyTo = nil - } else { - inReplyTo = inReplyTos[0] - } - } else { - inReplyTo = nil - } - var replies []*models.Message database.DBCon.Model(&replies). Where(`(headers::jsonb->>'References')::jsonb ? '` + message.Id + `'`). WhereOr(`(headers::jsonb->>'In-Reply-To')::jsonb ? '` + message.Id + `'`). Order("date ASC").Select() - renderMessageTemplate(w, listName, message, inReplyTo, replies) + renderMessageTemplate(w, listName, message, replies) } diff --git a/pkg/app/message/utils.go b/pkg/app/message/utils.go index 3c8e116..d8e038a 100644 --- a/pkg/app/message/utils.go +++ b/pkg/app/message/utils.go @@ -10,7 +10,7 @@ import ( ) // renderIndexTemplate renders all templates used for the landing page -func renderMessageTemplate(w http.ResponseWriter, listName string, message *models.Message, inReplyTo *models.Message, replies []*models.Message) { +func renderMessageTemplate(w http.ResponseWriter, listName string, message *models.Message, replies []*models.Message) { templates := template.Must( template.Must( template.New("Show"). @@ -21,12 +21,10 @@ func renderMessageTemplate(w http.ResponseWriter, listName string, message *mode templateData := struct { ListName string Message *models.Message - InReplyTo *models.Message Replies []*models.Message }{ ListName: listName, Message: message, - InReplyTo: inReplyTo, Replies: replies, } diff --git a/web/templates/message/show.tmpl b/web/templates/message/show.tmpl index 390fe0a..913ca4e 100644 --- a/web/templates/message/show.tmpl +++ b/web/templates/message/show.tmpl @@ -39,10 +39,10 @@ <td><tt>{{.Message.GetMessageId}}</tt></td> </tr> - {{if .InReplyTo}} + {{if .Message.InReplyTo}} <tr> <th>In Reply to:</th> - <td colspan="3"><a href="/{{.ListName}}/messages/{{.InReplyTo.Id}}">{{.InReplyTo.GetHeaderField "Subject"}}</a> by {{.InReplyTo.GetAuthorName}}</td> + <td colspan="3"><a href="/{{.Message.InReplyTo.List}}/messages/{{.Message.InReplyTo.Id}}">{{.Message.InReplyTo.GetSubject}}</a> by {{.Message.InReplyTo.GetAuthorName}}</td> </tr> {{end}} |