From cd7577c84c55206cf02f3c332ab87fc4a6f62eb8 Mon Sep 17 00:00:00 2001 From: Azareal Date: Thu, 13 Feb 2020 20:44:03 +1000 Subject: [PATCH] convo alerts change convo_dev phrase change account_menu_messages phrase change alerts_no_linked_topic phrase change alerts_no_linked_topic_by_reply phrase add alerts.convo_create phrase add alerts.convo_reply phrase add alerts_no_linked_convo phrase --- common/alerts.go | 13 ++++++++++++- common/conversations.go | 2 ++ langs/english.json | 12 ++++++++---- routes/convos.go | 26 +++++++++++++++++++++++++- 4 files changed, 47 insertions(+), 6 deletions(-) diff --git a/common/alerts.go b/common/alerts.go index d7a62eb5..fdce4b5a 100644 --- a/common/alerts.go +++ b/common/alerts.go @@ -100,6 +100,14 @@ func BuildAlert(alert Alert, user User /* The current user */) (out string, err var url, area string phraseName := "." + alert.ElementType switch alert.ElementType { + case "convo": + convo, err := Convos.Get(alert.ElementID) + if err != nil { + DebugLogf("Unable to find linked convo %d", alert.ElementID) + return "", errors.New(phrases.GetErrorPhrase("alerts_no_linked_convo")) + } + url = convo.Link + area = "" case "topic": topic, err := Topics.Get(alert.ElementID) if err != nil { @@ -138,6 +146,8 @@ func BuildAlert(alert Alert, user User /* The current user */) (out string, err } switch alert.Event { + case "create": + phraseName += "_create" case "like": phraseName += "_like" case "mention": @@ -149,6 +159,7 @@ func BuildAlert(alert Alert, user User /* The current user */) (out string, err return buildAlertString(phraseName, []string{alert.Actor.Name, area}, url, alert.Actor.Avatar, alert.ASID), nil } +// TODO: Use a string builder? func buildAlertString(msg string, sub []string, path, avatar string, asid int) string { var subString string for _, item := range sub { @@ -242,4 +253,4 @@ func notifyWatchers(asid int) { func DismissAlert(uid, aid int) { _ = WsHub.PushMessage(uid, `{"event":"dismiss-alert","id":`+strconv.Itoa(aid)+`}`) -} \ No newline at end of file +} diff --git a/common/conversations.go b/common/conversations.go index 908a0f7a..d4d5328a 100644 --- a/common/conversations.go +++ b/common/conversations.go @@ -183,6 +183,7 @@ func NewDefaultConversationStore(acc *qgen.Accumulator) (*DefaultConversationSto func (s *DefaultConversationStore) Get(id int) (*Conversation, error) { co := &Conversation{ID: id} err := s.get.QueryRow(id).Scan(&co.CreatedBy, &co.CreatedAt, &co.LastReplyBy, &co.LastReplyAt) + co.Link = BuildConvoURL(co.ID) return co, err } @@ -199,6 +200,7 @@ func (s *DefaultConversationStore) GetUser(uid, offset int) (cos []*Conversation if err != nil { return nil, err } + co.Link = BuildConvoURL(co.ID) cos = append(cos, co) } err = rows.Err() diff --git a/langs/english.json b/langs/english.json index baf94bef..80d851b6 100644 --- a/langs/english.json +++ b/langs/english.json @@ -111,8 +111,9 @@ "alerts_no_actor":"Unable to find the actor", "alerts_no_target_user":"Unable to find the target user", - "alerts_no_linked_topic":"Unable to find the linked topic", - "alerts_no_linked_topic_by_reply":"Unable to find the linked reply or parent topic", + "alerts_no_linked_topic":"Unable to find linked topic", + "alerts_no_linked_topic_by_reply":"Unable to find linked reply or parent topic", + "alerts_no_linked_convo":"Unable to find linked convo", "alerts_invalid_elementtype":"Invalid elementType", "panel_groups_need_name":"The group name can't be left blank.", @@ -328,7 +329,7 @@ "password_reset_email_sent":"An email was sent to you. Please follow the steps within.", "password_reset_token_token_verified":"Your password was successfully updated.", - "convo_dev":"Messages are currently under development. Some features may not work yet and your messages may be purged every now and then.", + "convo_dev":"Conversations are currently under development. Some features may not work yet and your messages may be purged every now and then.", "panel_forum_created":"The forum was successfully created.", "panel_forum_deleted":"The forum was successfully deleted.", @@ -380,6 +381,9 @@ "alerts.user_mention":"{0} mentioned you on {1}'s profile", "alerts.new_friend_invite":"You received a friend invite from {0}", + "alerts.convo_create":"{0} added you to a conversation", + "alerts.convo_reply":"{0} replied to a conversation", + "alerts.no_alerts":"You don't have any alerts", "alerts.no_alerts_short":"No new alerts", @@ -511,7 +515,7 @@ "account_menu_privacy":"Privacy", "account_menu_blocked":"Blocked", "account_menu_penalties":"Penalties", - "account_menu_messages":"Messages", + "account_menu_messages":"Conversations", "account_coming_soon":"Coming Soon", diff --git a/routes/convos.go b/routes/convos.go index c03dd4d4..09224717 100644 --- a/routes/convos.go +++ b/routes/convos.go @@ -210,6 +210,26 @@ func ConvosCreateSubmit(w http.ResponseWriter, r *http.Request, user c.User) c.R return c.InternalError(err, w, r) } + // TODO: Don't bother making the subscription if the convo creator is the only recipient? + for _, uid := range rlist { + if uid == user.ID { + continue + } + err := c.Subscriptions.Add(uid, cid, "convo") + if err != nil { + return c.InternalError(err, w, r) + } + } + err = c.Subscriptions.Add(user.ID, cid, "convo") + if err != nil { + return c.InternalError(err, w, r) + } + + err = c.AddActivityAndNotifyAll(c.Alert{ActorID: user.ID, Event: "create", ElementType: "convo", ElementID: cid, Actor: &user}) + if err != nil { + return c.InternalError(err, w, r) + } + http.Redirect(w, r, "/user/convo/"+strconv.Itoa(cid), http.StatusSeeOther) return nil } @@ -269,7 +289,11 @@ func ConvosCreateReplySubmit(w http.ResponseWriter, r *http.Request, user c.User body := c.PreparseMessage(r.PostFormValue("content")) post := &c.ConversationPost{CID: cid, Body: body, CreatedBy: user.ID} - _, err = post.Create() + pid, err := post.Create() + if err != nil { + return c.InternalError(err, w, r) + } + err = c.AddActivityAndNotifyAll(c.Alert{ActorID: user.ID, Event: "reply", ElementType: "convo", ElementID: cid, Actor: &user, Extra: strconv.Itoa(pid)}) if err != nil { return c.InternalError(err, w, r) }