diff --git a/app/export_converters.go b/app/export_converters.go index b73536c7f9..a2ce20abf6 100644 --- a/app/export_converters.go +++ b/app/export_converters.go @@ -4,8 +4,9 @@ package app import ( - "github.com/mattermost/mattermost-server/model" "strings" + + "github.com/mattermost/mattermost-server/model" ) func ImportLineFromTeam(team *model.TeamForExport) *LineImportData { @@ -78,10 +79,27 @@ func ImportUserChannelDataFromChannelMember(member *model.ChannelMemberForExport if member.SchemeUser { rolesList = append(rolesList, model.CHANNEL_USER_ROLE_ID) } + props := member.NotifyProps + notifyProps := UserChannelNotifyPropsImportData{} + + desktop, exist := props[model.DESKTOP_NOTIFY_PROP] + if exist { + notifyProps.Desktop = &desktop + } + mobile, exist := props[model.PUSH_NOTIFY_PROP] + if exist { + notifyProps.Mobile = &mobile + } + markUnread, exist := props[model.MARK_UNREAD_NOTIFY_PROP] + if exist { + notifyProps.MarkUnread = &markUnread + } + roles := strings.Join(rolesList, " ") return &UserChannelImportData{ - Name: &member.ChannelName, - Roles: &roles, + Name: &member.ChannelName, + Roles: &roles, + NotifyProps: ¬ifyProps, } } diff --git a/app/export_test.go b/app/export_test.go index bb6d533924..3d12b4d505 100644 --- a/app/export_test.go +++ b/app/export_test.go @@ -59,3 +59,34 @@ func TestExportUserNotifyProps(t *testing.T) { require.Equal(t, userNotifyProps[model.COMMENTS_NOTIFY_PROP], *exportNotifyProps.CommentsTrigger) require.Equal(t, userNotifyProps[model.MENTION_KEYS_NOTIFY_PROP], *exportNotifyProps.MentionKeys) } + +func TestExportUserChannelsNotifyProps(t *testing.T) { + th := Setup().InitBasic() + defer th.TearDown() + channel := th.BasicChannel + user := th.BasicUser + team := th.BasicTeam + channelName := channel.Name + notifyProps := model.StringMap{ + model.DESKTOP_NOTIFY_PROP: model.USER_NOTIFY_ALL, + model.PUSH_NOTIFY_PROP: model.USER_NOTIFY_NONE, + } + channelMember := model.ChannelMember{ + ChannelId: channel.Id, + UserId: user.Id, + } + th.App.Srv.Store.Channel().SaveMember(&channelMember) + th.App.UpdateChannelMemberNotifyProps(notifyProps, channel.Id, user.Id) + exportData, _ := th.App.buildUserChannelMemberships(user.Id, team.Id) + for _, data := range *exportData { + if *data.Name == channelName { + assert.Equal(t, *data.NotifyProps.Desktop, "all") + assert.Equal(t, *data.NotifyProps.Mobile, "none") + assert.Equal(t, *data.NotifyProps.MarkUnread, "all") // default value + } else { // default values + assert.Equal(t, *data.NotifyProps.Desktop, "default") + assert.Equal(t, *data.NotifyProps.Mobile, "default") + assert.Equal(t, *data.NotifyProps.MarkUnread, "all") + } + } +}