aboutsummaryrefslogtreecommitdiff
path: root/pkg/app
diff options
context:
space:
mode:
authorMax Magorsch <arzano@gentoo.org>2020-06-24 20:17:31 +0200
committerMax Magorsch <arzano@gentoo.org>2020-06-24 20:17:31 +0200
commitec6e229d7b64f81c8dce09444be98d12c436fe36 (patch)
tree8e65f7d1e7b68d4d0f614f8d46190641750913b2 /pkg/app
parentRename MessageId to MessageIdField (diff)
downloadarchives-ec6e229d7b64f81c8dce09444be98d12c436fe36.tar.gz
archives-ec6e229d7b64f81c8dce09444be98d12c436fe36.tar.bz2
archives-ec6e229d7b64f81c8dce09444be98d12c436fe36.zip
Fix the references of a message
Signed-off-by: Max Magorsch <arzano@gentoo.org>
Diffstat (limited to 'pkg/app')
-rw-r--r--pkg/app/message/show.go36
1 files changed, 32 insertions, 4 deletions
diff --git a/pkg/app/message/show.go b/pkg/app/message/show.go
index 60038d5..7ceb84c 100644
--- a/pkg/app/message/show.go
+++ b/pkg/app/message/show.go
@@ -5,6 +5,7 @@ package message
import (
"archives/pkg/database"
"archives/pkg/models"
+ "fmt"
"net/http"
"strings"
)
@@ -18,7 +19,9 @@ func Show(w http.ResponseWriter, r *http.Request) {
message := &models.Message{Id: messageHash}
err := database.DBCon.Model(message).
+ Column("message.*").
Relation("InReplyTo").
+ Relation("References").
WherePK().
Select()
@@ -27,11 +30,36 @@ func Show(w http.ResponseWriter, r *http.Request) {
return
}
+ var queryParts []string
+ for _, reference := range message.References {
+ fmt.Println("> " + reference.Id)
+ queryParts = append(queryParts, "reference_id = '" + reference.Id + "'")
+ }
+ query := strings.Join(queryParts, " OR ")
+
+ var refs []*models.MessageToReferences
+ err = database.DBCon.Model(&refs).
+ Where(query).
+ Select()
+
+ // part 2
+ // TODO only if len(refs) >= 1
+ var nextQueryParts []string
+ for _, reference := range refs {
+ fmt.Println("> " + reference.MessageId)
+ nextQueryParts = append(nextQueryParts, "id = '" + reference.MessageId + "'")
+ }
+ nextQuery := strings.Join(nextQueryParts, " OR ")
+
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()
+ err = database.DBCon.Model(&replies).
+ Where(nextQuery).
+ // Where date is newer than message
+ Select()
+
+ fmt.Println("-------------------")
+ fmt.Println(err)
+ fmt.Println(len(replies))
renderMessageTemplate(w, listName, message, replies)
}