aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--pkg/app/message/show.go36
-rw-r--r--web/templates/message/show.tmpl4
2 files changed, 34 insertions, 6 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)
}
diff --git a/web/templates/message/show.tmpl b/web/templates/message/show.tmpl
index 913ca4e..8accbde 100644
--- a/web/templates/message/show.tmpl
+++ b/web/templates/message/show.tmpl
@@ -80,8 +80,8 @@
</tr>
{{range .Replies}}
<tr>
- <td><a href="{{.Id}}">{{.GetHeaderField "Subject"}}</a></td>
- <td>{{formatAddr (.GetHeaderField "From")}}</td>
+ <td><a href="{{.Id}}">{{.GetSubject}}</a></td>
+ <td>{{formatAddr .From}}</td>
</tr>
{{end}}
</tbody>