Messages: if thread already open, go directly there instead of dedicated Compose page
This commit is contained in:
parent
6c618d1a0c
commit
8456c5d0f5
|
@ -41,6 +41,12 @@ func Compose() http.HandlerFunc {
|
||||||
return
|
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?
|
// POSTing?
|
||||||
if r.Method == http.MethodPost {
|
if r.Method == http.MethodPost {
|
||||||
var (
|
var (
|
||||||
|
|
|
@ -75,6 +75,21 @@ func GetMessageThread(sourceUserID, targetUserID uint64, pager *Pagination) ([]*
|
||||||
return m, result.Error
|
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.
|
// DeleteMessageThread removes all message history between two people.
|
||||||
func DeleteMessageThread(message *Message) error {
|
func DeleteMessageThread(message *Message) error {
|
||||||
return DB.Where(
|
return DB.Where(
|
||||||
|
|
|
@ -133,7 +133,7 @@ document.addEventListener('DOMContentLoaded', () => {
|
||||||
node.addEventListener("click", e => {
|
node.addEventListener("click", e => {
|
||||||
if (node.classList.contains("blurred-explicit")) {
|
if (node.classList.contains("blurred-explicit")) {
|
||||||
node.classList.remove("blurred-explicit");
|
node.classList.remove("blurred-explicit");
|
||||||
if (node.tagName.toLowerCase() !== "video") {
|
if (node.tagName !== "VIDEO") {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user