aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMax Magorsch <arzano@gentoo.org>2020-06-24 21:54:41 +0000
committerMax Magorsch <arzano@gentoo.org>2020-06-24 21:54:41 +0000
commit165e85189fad078b40387ed5d86066521a5d023e (patch)
tree9b462c6c5a989515d8b142b67fb40b62a4c54b6c /pkg/app/message/show.go
parentRemove verbose logging messages (diff)
downloadarchives-165e85189fad078b40387ed5d86066521a5d023e.tar.gz
archives-165e85189fad078b40387ed5d86066521a5d023e.tar.bz2
archives-165e85189fad078b40387ed5d86066521a5d023e.zip
Fix the computation of replies to a message
Signed-off-by: Max Magorsch <arzano@gentoo.org>
Diffstat (limited to 'pkg/app/message/show.go')
-rw-r--r--pkg/app/message/show.go51
1 files changed, 41 insertions, 10 deletions
diff --git a/pkg/app/message/show.go b/pkg/app/message/show.go
index e8eb456..baed3f1 100644
--- a/pkg/app/message/show.go
+++ b/pkg/app/message/show.go
@@ -6,6 +6,7 @@ import (
"archives/pkg/database"
"archives/pkg/models"
"net/http"
+ "sort"
"strings"
)
@@ -29,10 +30,15 @@ func Show(w http.ResponseWriter, r *http.Request) {
return
}
+ //
+ // Compute Replies
+ //
+ var replies []*models.Message
var queryParts []string
for _, reference := range message.References {
queryParts = append(queryParts, "reference_id = '" + reference.Id + "'")
}
+ queryParts = append(queryParts, "reference_id = '" + message.Id + "'")
query := strings.Join(queryParts, " OR ")
var refs []*models.MessageToReferences
@@ -41,18 +47,43 @@ func Show(w http.ResponseWriter, r *http.Request) {
Select()
// part 2
- // TODO only if len(refs) >= 1
- var nextQueryParts []string
- for _, reference := range refs {
- nextQueryParts = append(nextQueryParts, "id = '" + reference.MessageId + "'")
+ if len(refs) > 0 {
+ var nextQueryParts []string
+ for _, reference := range refs {
+ nextQueryParts = append(nextQueryParts, "id = '" + reference.MessageId + "'")
+ }
+ nextQuery := strings.Join(nextQueryParts, " OR ")
+
+
+ err = database.DBCon.Model(&replies).
+ Where(nextQuery).
+ Where("date >= '" + message.Date.Format("2006-01-02 15:04:05") + "'").
+ Where("NOT id = ?", message.Id).
+ Select()
+
+ //
+ // If In-Reply is null, but there are references we will use the last message
+ // in the thread as In-Reply-To message
+ //
+ var inReplyTo []*models.Message
+ if message.InReplyToId == "" || message.InReplyTo == nil {
+ err = database.DBCon.Model(&inReplyTo).
+ Where(nextQuery).
+ Where("date <= '" + message.Date.Format("2006-01-02 15:04:05") + "'").
+ Where("NOT id = ?", message.Id).
+ Order("date DESC").
+ Limit(1).
+ Select()
+
+ if err == nil && len(inReplyTo) > 0 {
+ message.InReplyTo = inReplyTo[0]
+ }
+ }
}
- nextQuery := strings.Join(nextQueryParts, " OR ")
- var replies []*models.Message
- err = database.DBCon.Model(&replies).
- Where(nextQuery).
- // Where date is newer than message
- Select()
+ sort.Slice(replies, func(i,j int) bool {
+ return replies[i].Date.Before(replies[j].Date)
+ })
renderMessageTemplate(w, listName, message, replies)
}