aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--pkg/app/message/show.go51
-rw-r--r--web/packs/message.js3
-rw-r--r--web/packs/src/javascript/message/replies.js11
-rw-r--r--web/templates/message/show.tmpl19
4 files changed, 69 insertions, 15 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)
}
diff --git a/web/packs/message.js b/web/packs/message.js
index 8595541..c7f8f1c 100644
--- a/web/packs/message.js
+++ b/web/packs/message.js
@@ -1,2 +1,3 @@
import './src/javascript/message/quotes'
-import './src/javascript/message/git' \ No newline at end of file
+import './src/javascript/message/git'
+import './src/javascript/message/replies'
diff --git a/web/packs/src/javascript/message/replies.js b/web/packs/src/javascript/message/replies.js
new file mode 100644
index 0000000..4578e14
--- /dev/null
+++ b/web/packs/src/javascript/message/replies.js
@@ -0,0 +1,11 @@
+$("#show-more-replies").click(function () {
+ $(".more-replies").removeClass("d-none");
+ $("#show-more-replies").addClass("d-none");
+ $("#show-less-replies").removeClass("d-none");
+});
+
+$("#show-less-replies").click(function () {
+ $(".more-replies").addClass("d-none");
+ $("#show-less-replies").addClass("d-none");
+ $("#show-more-replies").removeClass("d-none");
+});
diff --git a/web/templates/message/show.tmpl b/web/templates/message/show.tmpl
index 8accbde..b5888d3 100644
--- a/web/templates/message/show.tmpl
+++ b/web/templates/message/show.tmpl
@@ -42,7 +42,7 @@
{{if .Message.InReplyTo}}
<tr>
<th>In Reply to:</th>
- <td colspan="3"><a href="/{{.Message.InReplyTo.List}}/messages/{{.Message.InReplyTo.Id}}">{{.Message.InReplyTo.GetSubject}}</a> by {{.Message.InReplyTo.GetAuthorName}}</td>
+ <td colspan="3"><a href="/{{.Message.InReplyTo.List}}/message/{{.Message.InReplyTo.Id}}">{{.Message.InReplyTo.GetSubject}}</a> by {{.Message.InReplyTo.GetAuthorName}}</td>
</tr>
{{end}}
@@ -72,16 +72,27 @@
{{end}}
{{if .Replies}}
+ <h3>Replies</h3>
<div class="table-responsive">
<table class="table table-sm ag-replies-table">
<tbody><tr>
<th>Subject</th>
<th>Author</th>
+ <th>Date</th>
</tr>
- {{range .Replies}}
+ {{range $index, $reply := .Replies}}
+ <tr {{if ge $index 5}}class="more-replies d-none"{{end}}>
+ <td><a href="/{{$reply.List}}/message/{{$reply.Id}}">{{.GetSubject}}</a></td>
+ <td>{{formatAddr $reply.From}}</td>
+ <td>{{$reply.Date.Format "2006-01-02 15:04:05"}}</td>
+ </tr>
+ {{end}}
+ {{ if gt (len .Replies) 5}}
+ <tr>
+ <td id="show-more-replies" colspan="3" class="text-center"><button class="btn btn-link" type="button">Show more</button></td>
+ </tr>
<tr>
- <td><a href="{{.Id}}">{{.GetSubject}}</a></td>
- <td>{{formatAddr .From}}</td>
+ <td id="show-less-replies" colspan="3" class="text-center d-none"><button class="btn btn-link" type="button">Show less</button></td>
</tr>
{{end}}
</tbody>