summaryrefslogtreecommitdiffstats
path: root/api
diff options
context:
space:
mode:
authorChristian Claus <ch.claus@me.com>2018-03-28 06:02:04 +0200
committerElias Nahum <nahumhbl@gmail.com>2018-03-28 07:02:04 +0300
commit257f74873297a6c6b4d14f2d21ffc3adad620c4c (patch)
treee4220b50c707759fb98bd2e49a765952bd705cc9 /api
parent71c9dff7662868770f66ab876ad66b354133c2c1 (diff)
downloadchat-257f74873297a6c6b4d14f2d21ffc3adad620c4c.tar.gz
chat-257f74873297a6c6b4d14f2d21ffc3adad620c4c.tar.bz2
chat-257f74873297a6c6b4d14f2d21ffc3adad620c4c.zip
[PLT-4340] Channel Mute and "/mute" command #7617 (#7713)
* Add command and store changes to allow mute toggling * Change channel muting to use ChannelMember notification structure * Suppress email and push notifications for a muted channel * Make i18n keys issue-compliant * Add notification-cache handling for channel-muting * Add channel handle for channel-muting slash-command * Add unit test for mute command * Merge branch 'master' into PLT-4340 # Conflicts: # app/notification.go * Fix issue that command_mute responses will be overwritten * Fix i18n key for channel muting * Apply new Provider Interface to MuteCommand * Migrate mute notification property to mark_unread PLT-4340 * Make some i18n improvements for command_mute PLT-4340 * Remove de.json translations * Prevent push notifications when channel is muted * Treat Group messages like Direct messages * Fix unit test * Send WS event when the channel member notify props changed
Diffstat (limited to 'api')
-rw-r--r--api/command_mute_test.go114
1 files changed, 114 insertions, 0 deletions
diff --git a/api/command_mute_test.go b/api/command_mute_test.go
new file mode 100644
index 000000000..6b2dad944
--- /dev/null
+++ b/api/command_mute_test.go
@@ -0,0 +1,114 @@
+// Copyright (c) 2017-present Mattermost, Inc. All Rights Reserved.
+// See License.txt for license information.
+
+package api
+
+import (
+ "strings"
+ "testing"
+
+ "github.com/mattermost/mattermost-server/model"
+ "github.com/nicksnyder/go-i18n/i18n"
+)
+
+func TestMuteCommand(t *testing.T) {
+ th := Setup().InitBasic()
+ defer th.TearDown()
+
+ i18n.MustLoadTranslationFile("../i18n/en.json")
+ T, _ := i18n.Tfunc("en")
+
+ // Create client and users
+ Client := th.BasicClient
+ team := th.BasicTeam
+ user1 := Client.Must(Client.GetMe("")).Data.(*model.User)
+ user2 := th.BasicUser2
+
+ // Mute channel1 directly with '/mute'
+ channel1 := &model.Channel{DisplayName: "AA", Name: "aa" + model.NewId() + "a", Type: model.CHANNEL_OPEN, TeamId: team.Id}
+ channel1 = Client.Must(Client.CreateChannel(channel1)).Data.(*model.Channel)
+ Client.Must(Client.JoinChannel(channel1.Id))
+
+ channel1M := Client.Must(Client.GetChannelMember(channel1.Id, user1.Id)).Data.(*model.ChannelMember)
+ if channel1M.NotifyProps[model.MARK_UNREAD_NOTIFY_PROP] == model.CHANNEL_NOTIFY_MENTION {
+ t.Fatal("channel shouldn't be muted on initial setup")
+ }
+
+ rs := Client.Must(Client.Command(channel1.Id, "/mute")).Data.(*model.CommandResponse)
+ if !strings.EqualFold(rs.Text, T("api.command_mute.success_mute", map[string]interface{}{"Channel": channel1.DisplayName})) {
+ t.Fatal("failed to mute channel")
+ }
+
+ channel1M = Client.Must(Client.GetChannelMember(channel1.Id, user1.Id)).Data.(*model.ChannelMember)
+ if channel1M.NotifyProps[model.MARK_UNREAD_NOTIFY_PROP] == model.CHANNEL_NOTIFY_ALL {
+ t.Fatal("channel should be muted")
+ }
+
+ rs = Client.Must(Client.Command(channel1.Id, "/mute")).Data.(*model.CommandResponse)
+ if !strings.EqualFold(rs.Text, T("api.command_mute.success_unmute", map[string]interface{}{"Channel": channel1.DisplayName})) {
+ t.Fatal("failed to mute channel")
+ }
+
+ channel1M = Client.Must(Client.GetChannelMember(channel1.Id, user1.Id)).Data.(*model.ChannelMember)
+ if channel1M.NotifyProps[model.MARK_UNREAD_NOTIFY_PROP] == model.CHANNEL_NOTIFY_MENTION {
+ t.Fatal("channel shouldn't be muted anymore")
+ }
+
+ // Mute channel2 via channel1 with chan-handle '/mute ~aa'
+ channel2 := &model.Channel{DisplayName: "BB", Name: "bb" + model.NewId() + "a", Type: model.CHANNEL_PRIVATE, TeamId: team.Id}
+ channel2 = Client.Must(Client.CreateChannel(channel2)).Data.(*model.Channel)
+ Client.Must(Client.JoinChannel(channel2.Id))
+ Client.Must(Client.AddChannelMember(channel2.Id, user2.Id))
+
+ channel2M := Client.Must(Client.GetChannelMember(channel2.Id, user1.Id)).Data.(*model.ChannelMember)
+ if channel2M.NotifyProps[model.MARK_UNREAD_NOTIFY_PROP] == model.CHANNEL_NOTIFY_MENTION {
+ t.Fatal("channel shouldn't be muted on initial setup")
+ }
+
+ rs = Client.Must(Client.Command(channel1.Id, "/mute ~" + channel2.Name)).Data.(*model.CommandResponse)
+ if !strings.EqualFold(rs.Text, T("api.command_mute.success_mute", map[string]interface{}{"Channel": channel2.DisplayName})) {
+ t.Fatal("failed to mute channel")
+ }
+
+ channel2M = Client.Must(Client.GetChannelMember(channel2.Id, user1.Id)).Data.(*model.ChannelMember)
+ if channel2M.NotifyProps[model.MARK_UNREAD_NOTIFY_PROP] == model.CHANNEL_NOTIFY_ALL {
+ t.Fatal("channel should be muted")
+ }
+
+ rs = Client.Must(Client.Command(channel1.Id, "/mute ~" + channel2.Name)).Data.(*model.CommandResponse)
+ if !strings.EqualFold(rs.Text, T("api.command_mute.success_unmute", map[string]interface{}{"Channel": channel2.DisplayName})) {
+ t.Fatal("failed to mute channel")
+ }
+
+ channel2M = Client.Must(Client.GetChannelMember(channel2.Id, user1.Id)).Data.(*model.ChannelMember)
+ if channel2M.NotifyProps[model.MARK_UNREAD_NOTIFY_PROP] == model.CHANNEL_NOTIFY_MENTION {
+ t.Fatal("channel shouldn't be muted anymore")
+ }
+
+ // Mute direct message
+ channel3 := Client.Must(Client.CreateDirectChannel(user2.Id)).Data.(*model.Channel)
+ channel3M := Client.Must(Client.GetChannelMember(channel3.Id, user1.Id)).Data.(*model.ChannelMember)
+ if channel3M.NotifyProps[model.MARK_UNREAD_NOTIFY_PROP] == model.CHANNEL_NOTIFY_MENTION {
+ t.Fatal("channel shouldn't be muted on initial setup")
+ }
+
+ rs = Client.Must(Client.Command(channel3.Id, "/mute")).Data.(*model.CommandResponse)
+ if !strings.EqualFold(rs.Text, T("api.command_mute.success_mute_direct_msg")) {
+ t.Fatal("failed to mute channel")
+ }
+
+ channel3M = Client.Must(Client.GetChannelMember(channel3.Id, user1.Id)).Data.(*model.ChannelMember)
+ if channel3M.NotifyProps[model.MARK_UNREAD_NOTIFY_PROP] == model.CHANNEL_NOTIFY_ALL {
+ t.Fatal("channel should be muted")
+ }
+
+ rs = Client.Must(Client.Command(channel3.Id, "/mute")).Data.(*model.CommandResponse)
+ if !strings.EqualFold(rs.Text, T("api.command_mute.success_unmute_direct_msg")) {
+ t.Fatal("failed to mute channel")
+ }
+
+ channel3M = Client.Must(Client.GetChannelMember(channel3.Id, user1.Id)).Data.(*model.ChannelMember)
+ if channel3M.NotifyProps[model.MARK_UNREAD_NOTIFY_PROP] == model.CHANNEL_NOTIFY_MENTION {
+ t.Fatal("channel shouldn't be muted anymore")
+ }
+}