diff options
author | samogot <samogot@gmail.com> | 2016-07-19 15:27:23 +0300 |
---|---|---|
committer | Christopher Speller <crspeller@gmail.com> | 2016-07-19 08:27:23 -0400 |
commit | f31e8e09f54418f867f95192a71e67b450340c13 (patch) | |
tree | 313f38a9bd8c999909b26cf49172df32e427dedc /api | |
parent | febe3a01cd5db03d152e993d42f39800e494a83a (diff) | |
download | chat-f31e8e09f54418f867f95192a71e67b450340c13.tar.gz chat-f31e8e09f54418f867f95192a71e67b450340c13.tar.bz2 chat-f31e8e09f54418f867f95192a71e67b450340c13.zip |
PLT-914 Add mention notifications for replies on a comment thread (#3130)
* PLT-914 Add mention notifications for replies on a comment thread
* remove useless store method
fix highlighting comments posted before th user write something to thread
* refactor out isCommentMention function after rebase
* change comment bar highlighting to replay icon mention highlighting
* settings and always visible highlight
* fix unit tests for new settings
* change highlight behaviour
- if any message in comment thread generates mention - all thread is highlighted
- remove always visible highlightion
* fix bug about the textarea in the center channel not clearing
* fix default settings value notify_props.comments
* do not highlight own comments if there is no other user's messages in thread
* refactor out ReactDOM.findDOMNode
* refactor out using of UserStore from component
Diffstat (limited to 'api')
-rw-r--r-- | api/post.go | 27 | ||||
-rw-r--r-- | api/user.go | 6 | ||||
-rw-r--r-- | api/user_test.go | 10 |
3 files changed, 37 insertions, 6 deletions
diff --git a/api/post.go b/api/post.go index 4533823f6..951ccb527 100644 --- a/api/post.go +++ b/api/post.go @@ -535,9 +535,8 @@ func sendNotifications(c *Context, post *model.Post, team *model.Team, channel * return model.SplitRunes[c] } splitMessage := strings.Fields(post.Message) + var userIds []string for _, word := range splitMessage { - var userIds []string - // Non-case-sensitive check for regular keys if ids, match := keywordMap[strings.ToLower(word)]; match { userIds = append(userIds, ids...) @@ -565,14 +564,30 @@ func sendNotifications(c *Context, post *model.Post, team *model.Team, channel * } } } + } + + if len(post.RootId) > 0 { + if result := <-Srv.Store.Post().Get(post.RootId); result.Err != nil { + l4g.Error(utils.T("api.post.send_notifications_and_forget.comment_thread.error"), post.RootId, result.Err) + return + } else { + list := result.Data.(*model.PostList) - for _, userId := range userIds { - if post.UserId == userId && post.Props["from_webhook"] != "true" { - continue + for _, threadPost := range list.Posts { + profile := profileMap[threadPost.UserId] + if profile.NotifyProps["comments"] == "any" || (profile.NotifyProps["comments"] == "root" && threadPost.Id == list.Order[0]) { + userIds = append(userIds, threadPost.UserId) + } } + } + } - mentionedUserIds[userId] = true + for _, userId := range userIds { + if post.UserId == userId && post.Props["from_webhook"] != "true" { + continue } + + mentionedUserIds[userId] = true } for id := range mentionedUserIds { diff --git a/api/user.go b/api/user.go index 652da14ad..7dd24fe1b 100644 --- a/api/user.go +++ b/api/user.go @@ -1930,6 +1930,12 @@ func updateUserNotify(c *Context, w http.ResponseWriter, r *http.Request) { return } + comments := props["comments"] + if len(comments) == 0 { + c.SetInvalidParam("updateUserNotify", "comments") + return + } + var user *model.User if result := <-uchan; result.Err != nil { c.Err = result.Err diff --git a/api/user_test.go b/api/user_test.go index 7d1e4026c..1b6662269 100644 --- a/api/user_test.go +++ b/api/user_test.go @@ -1247,6 +1247,7 @@ func TestUserUpdateNotify(t *testing.T) { data["email"] = "true" data["desktop"] = "all" data["desktop_sound"] = "false" + data["comments"] = "any" if _, err := Client.UpdateUserNotify(data); err == nil { t.Fatal("Should have errored - not logged in") @@ -1267,6 +1268,9 @@ func TestUserUpdateNotify(t *testing.T) { if result.Data.(*model.User).NotifyProps["email"] != data["email"] { t.Fatal("NotifyProps did not update properly - email") } + if result.Data.(*model.User).NotifyProps["comments"] != data["comments"] { + t.Fatal("NotifyProps did not update properly - comments") + } } if _, err := Client.UpdateUserNotify(nil); err == nil { @@ -1300,6 +1304,12 @@ func TestUserUpdateNotify(t *testing.T) { if _, err := Client.UpdateUserNotify(data); err == nil { t.Fatal("Should have errored - empty email") } + + data["email"] = "true" + data["comments"] = "" + if _, err := Client.UpdateUserNotify(data); err == nil { + t.Fatal("Should have errored - empty comments") + } } func TestFuzzyUserCreate(t *testing.T) { |