aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMax Magorsch <arzano@gentoo.org>2020-06-19 15:51:41 +0200
committerMax Magorsch <arzano@gentoo.org>2020-06-19 15:51:41 +0200
commit21181c518cf41828917d36005b726f9452fde657 (patch)
tree38fab1b3c86a41383e48be6b2686d92efd86db62 /pkg/app/message/show.go
downloadarchives-21181c518cf41828917d36005b726f9452fde657.tar.gz
archives-21181c518cf41828917d36005b726f9452fde657.tar.bz2
archives-21181c518cf41828917d36005b726f9452fde657.zip
Initial version
Signed-off-by: Max Magorsch <arzano@gentoo.org>
Diffstat (limited to 'pkg/app/message/show.go')
-rw-r--r--pkg/app/message/show.go49
1 files changed, 49 insertions, 0 deletions
diff --git a/pkg/app/message/show.go b/pkg/app/message/show.go
new file mode 100644
index 0000000..a027596
--- /dev/null
+++ b/pkg/app/message/show.go
@@ -0,0 +1,49 @@
+// Used to show the landing page of the application
+
+package message
+
+import (
+ "archives/pkg/database"
+ "archives/pkg/models"
+ "net/http"
+ "strings"
+)
+
+// Show renders a template to show the landing page of the application
+func Show(w http.ResponseWriter, r *http.Request) {
+
+ urlParts := strings.Split(r.URL.Path, "/")
+ listName := urlParts[1]
+ messageHash := urlParts[len(urlParts)-1]
+
+ message := &models.Message{Id: messageHash}
+ err := database.DBCon.Select(message)
+
+ if err != nil {
+ http.NotFound(w, r)
+ return
+ }
+
+ var inReplyTos []*models.Message
+ var inReplyTo *models.Message
+ if message.HasHeaderField("In-Reply-To") {
+ err = database.DBCon.Model(&inReplyTos).
+ Where(`(headers::jsonb->>'Message-Id')::jsonb ? '` + message.GetHeaderField("In-Reply-To") + `'`).
+ 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.GetHeaderField("Message-Id") + `'`).
+ WhereOr(`(headers::jsonb->>'In-Reply-To')::jsonb ? '` + message.GetHeaderField("Message-Id") + `'`).
+ Order("date ASC").Select()
+
+ renderMessageTemplate(w, listName, message, inReplyTo, replies)
+}