aboutsummaryrefslogtreecommitdiff
path: root/pkg
diff options
context:
space:
mode:
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,
}