aboutsummaryrefslogtreecommitdiff
path: root/pkg
diff options
context:
space:
mode:
authorMax Magorsch <arzano@gentoo.org>2020-06-24 18:52:00 +0200
committerMax Magorsch <arzano@gentoo.org>2020-06-24 18:52:00 +0200
commit73bbbd365c229f4918e798094e7b82a8336e84c8 (patch)
tree374c00f472d0b55bbe9c42bf019173991062e8ff /pkg
parentOnly show threads for popular messages (diff)
downloadarchives-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>
Diffstat (limited to 'pkg')
-rw-r--r--pkg/app/message/show.go22
-rw-r--r--pkg/app/message/utils.go4
2 files changed, 6 insertions, 20 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,
}