diff --git a/pkg/controller/inbox/compose.go b/pkg/controller/inbox/compose.go index aed3627..490047b 100644 --- a/pkg/controller/inbox/compose.go +++ b/pkg/controller/inbox/compose.go @@ -41,6 +41,12 @@ func Compose() http.HandlerFunc { return } + // If we already have a thread open with them, go to that instead of the stand-alone compose page. + if msgID, ok := models.HasMessageThread(currentUser, user); ok { + templates.Redirect(w, fmt.Sprintf("/messages/read/%d", msgID)) + return + } + // POSTing? if r.Method == http.MethodPost { var ( diff --git a/pkg/models/message.go b/pkg/models/message.go index 25e7507..fd0f884 100644 --- a/pkg/models/message.go +++ b/pkg/models/message.go @@ -75,6 +75,21 @@ func GetMessageThread(sourceUserID, targetUserID uint64, pager *Pagination) ([]* return m, result.Error } +// HasMessageThread returns if a message thread exists between two users (either direction). +// Returns the ID of the thread and a boolean OK that it existed. +func HasMessageThread(a, b *User) (uint64, bool) { + var pager = &Pagination{ + Page: 1, + PerPage: 1, + Sort: "updated_at desc", + } + messages, err := GetMessageThread(a.ID, b.ID, pager) + if err == nil && len(messages) > 0 { + return messages[0].ID, true + } + return 0, false +} + // DeleteMessageThread removes all message history between two people. func DeleteMessageThread(message *Message) error { return DB.Where( diff --git a/web/static/js/bulma.js b/web/static/js/bulma.js index 26b9865..a3e41f5 100644 --- a/web/static/js/bulma.js +++ b/web/static/js/bulma.js @@ -133,7 +133,7 @@ document.addEventListener('DOMContentLoaded', () => { node.addEventListener("click", e => { if (node.classList.contains("blurred-explicit")) { node.classList.remove("blurred-explicit"); - if (node.tagName.toLowerCase() !== "video") { + if (node.tagName !== "VIDEO") { e.preventDefault(); e.stopPropagation(); }