PLT-3193 Add channel notification preferences for push and email noti… (#5500)
* PLT-3193 Add channel notification preferences for push and email notifications * unit tests, model validation and localization * Feedback review * Adding back allowFromCache check * Setting push and email to use default settings * Move props as constants * address feedback
Этот коммит содержится в:
@@ -1536,7 +1536,7 @@ func TestUpdateNotifyProps(t *testing.T) {
|
|||||||
data := make(map[string]string)
|
data := make(map[string]string)
|
||||||
data["channel_id"] = channel1.Id
|
data["channel_id"] = channel1.Id
|
||||||
data["user_id"] = user.Id
|
data["user_id"] = user.Id
|
||||||
data["desktop"] = model.CHANNEL_NOTIFY_MENTION
|
data[model.DESKTOP_NOTIFY_PROP] = model.CHANNEL_NOTIFY_MENTION
|
||||||
|
|
||||||
//timeBeforeUpdate := model.GetMillis()
|
//timeBeforeUpdate := model.GetMillis()
|
||||||
time.Sleep(100 * time.Millisecond)
|
time.Sleep(100 * time.Millisecond)
|
||||||
@@ -1544,46 +1544,65 @@ func TestUpdateNotifyProps(t *testing.T) {
|
|||||||
// test updating desktop
|
// test updating desktop
|
||||||
if result, err := Client.UpdateNotifyProps(data); err != nil {
|
if result, err := Client.UpdateNotifyProps(data); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
} else if notifyProps := result.Data.(map[string]string); notifyProps["desktop"] != model.CHANNEL_NOTIFY_MENTION {
|
} else if notifyProps := result.Data.(map[string]string); notifyProps[model.DESKTOP_NOTIFY_PROP] != model.CHANNEL_NOTIFY_MENTION {
|
||||||
t.Fatal("NotifyProps[\"desktop\"] did not update properly")
|
t.Fatal("NotifyProps[\"desktop\"] did not update properly")
|
||||||
} else if notifyProps["mark_unread"] != model.CHANNEL_MARK_UNREAD_ALL {
|
} else if notifyProps[model.MARK_UNREAD_NOTIFY_PROP] != model.CHANNEL_MARK_UNREAD_ALL {
|
||||||
t.Fatalf("NotifyProps[\"mark_unread\"] changed to %v", notifyProps["mark_unread"])
|
t.Fatalf("NotifyProps[\"mark_unread\"] changed to %v", notifyProps[model.MARK_UNREAD_NOTIFY_PROP])
|
||||||
}
|
}
|
||||||
|
|
||||||
// test an empty update
|
// test an empty update
|
||||||
delete(data, "desktop")
|
delete(data, model.DESKTOP_NOTIFY_PROP)
|
||||||
|
|
||||||
if result, err := Client.UpdateNotifyProps(data); err != nil {
|
if result, err := Client.UpdateNotifyProps(data); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
} else if notifyProps := result.Data.(map[string]string); notifyProps["mark_unread"] != model.CHANNEL_MARK_UNREAD_ALL {
|
} else if notifyProps := result.Data.(map[string]string); notifyProps[model.MARK_UNREAD_NOTIFY_PROP] != model.CHANNEL_MARK_UNREAD_ALL {
|
||||||
t.Fatalf("NotifyProps[\"mark_unread\"] changed to %v", notifyProps["mark_unread"])
|
t.Fatalf("NotifyProps[\"mark_unread\"] changed to %v", notifyProps[model.MARK_UNREAD_NOTIFY_PROP])
|
||||||
} else if notifyProps["desktop"] != model.CHANNEL_NOTIFY_MENTION {
|
} else if notifyProps[model.DESKTOP_NOTIFY_PROP] != model.CHANNEL_NOTIFY_MENTION {
|
||||||
t.Fatalf("NotifyProps[\"desktop\"] changed to %v", notifyProps["desktop"])
|
t.Fatalf("NotifyProps[\"desktop\"] changed to %v", notifyProps[model.DESKTOP_NOTIFY_PROP])
|
||||||
}
|
}
|
||||||
|
|
||||||
// test updating mark unread
|
// test updating mark unread
|
||||||
data["mark_unread"] = model.CHANNEL_MARK_UNREAD_MENTION
|
data[model.MARK_UNREAD_NOTIFY_PROP] = model.CHANNEL_MARK_UNREAD_MENTION
|
||||||
|
|
||||||
if result, err := Client.UpdateNotifyProps(data); err != nil {
|
if result, err := Client.UpdateNotifyProps(data); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
} else if notifyProps := result.Data.(map[string]string); notifyProps["mark_unread"] != model.CHANNEL_MARK_UNREAD_MENTION {
|
} else if notifyProps := result.Data.(map[string]string); notifyProps[model.MARK_UNREAD_NOTIFY_PROP] != model.CHANNEL_MARK_UNREAD_MENTION {
|
||||||
t.Fatal("NotifyProps[\"mark_unread\"] did not update properly")
|
t.Fatal("NotifyProps[\"mark_unread\"] did not update properly")
|
||||||
} else if notifyProps["desktop"] != model.CHANNEL_NOTIFY_MENTION {
|
} else if notifyProps[model.DESKTOP_NOTIFY_PROP] != model.CHANNEL_NOTIFY_MENTION {
|
||||||
t.Fatalf("NotifyProps[\"desktop\"] changed to %v", notifyProps["desktop"])
|
t.Fatalf("NotifyProps[\"desktop\"] changed to %v", notifyProps[model.DESKTOP_NOTIFY_PROP])
|
||||||
}
|
}
|
||||||
|
|
||||||
// test updating both
|
// test updating both
|
||||||
data["desktop"] = model.CHANNEL_NOTIFY_NONE
|
data[model.DESKTOP_NOTIFY_PROP] = model.CHANNEL_NOTIFY_NONE
|
||||||
data["mark_unread"] = model.CHANNEL_MARK_UNREAD_MENTION
|
data[model.MARK_UNREAD_NOTIFY_PROP] = model.CHANNEL_MARK_UNREAD_MENTION
|
||||||
|
|
||||||
if result, err := Client.UpdateNotifyProps(data); err != nil {
|
if result, err := Client.UpdateNotifyProps(data); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
} else if notifyProps := result.Data.(map[string]string); notifyProps["desktop"] != model.CHANNEL_NOTIFY_NONE {
|
} else if notifyProps := result.Data.(map[string]string); notifyProps[model.DESKTOP_NOTIFY_PROP] != model.CHANNEL_NOTIFY_NONE {
|
||||||
t.Fatal("NotifyProps[\"desktop\"] did not update properly")
|
t.Fatal("NotifyProps[\"desktop\"] did not update properly")
|
||||||
} else if notifyProps["mark_unread"] != model.CHANNEL_MARK_UNREAD_MENTION {
|
} else if notifyProps[model.MARK_UNREAD_NOTIFY_PROP] != model.CHANNEL_MARK_UNREAD_MENTION {
|
||||||
t.Fatal("NotifyProps[\"mark_unread\"] did not update properly")
|
t.Fatal("NotifyProps[\"mark_unread\"] did not update properly")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// test updating push notification preferences
|
||||||
|
delete(data, model.DESKTOP_NOTIFY_PROP)
|
||||||
|
delete(data, model.MARK_UNREAD_NOTIFY_PROP)
|
||||||
|
data[model.PUSH_NOTIFY_PROP] = model.CHANNEL_NOTIFY_MENTION
|
||||||
|
if result, err := Client.UpdateNotifyProps(data); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
} else if notifyProps := result.Data.(map[string]string); notifyProps[model.PUSH_NOTIFY_PROP] != model.CHANNEL_NOTIFY_MENTION {
|
||||||
|
t.Fatal("NotifyProps[\"push\"] did not update properly")
|
||||||
|
}
|
||||||
|
|
||||||
|
// test updating email preferences
|
||||||
|
delete(data, model.PUSH_NOTIFY_PROP)
|
||||||
|
data[model.EMAIL_NOTIFY_PROP] = "true"
|
||||||
|
if result, err := Client.UpdateNotifyProps(data); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
} else if notifyProps := result.Data.(map[string]string); notifyProps[model.EMAIL_NOTIFY_PROP] != "true" {
|
||||||
|
t.Fatal("NotifyProps[\"email\"] did not update properly")
|
||||||
|
}
|
||||||
|
|
||||||
// test error cases
|
// test error cases
|
||||||
data["user_id"] = "junk"
|
data["user_id"] = "junk"
|
||||||
if _, err := Client.UpdateNotifyProps(data); err == nil {
|
if _, err := Client.UpdateNotifyProps(data); err == nil {
|
||||||
@@ -1606,24 +1625,38 @@ func TestUpdateNotifyProps(t *testing.T) {
|
|||||||
t.Fatal("Should have errored - bad channel id")
|
t.Fatal("Should have errored - bad channel id")
|
||||||
}
|
}
|
||||||
|
|
||||||
data["desktop"] = "junk"
|
data[model.DESKTOP_NOTIFY_PROP] = "junk"
|
||||||
data["mark_unread"] = model.CHANNEL_MARK_UNREAD_ALL
|
data[model.MARK_UNREAD_NOTIFY_PROP] = model.CHANNEL_MARK_UNREAD_ALL
|
||||||
if _, err := Client.UpdateNotifyProps(data); err == nil {
|
if _, err := Client.UpdateNotifyProps(data); err == nil {
|
||||||
t.Fatal("Should have errored - bad desktop notify level")
|
t.Fatal("Should have errored - bad desktop notify level")
|
||||||
}
|
}
|
||||||
|
|
||||||
data["desktop"] = model.CHANNEL_NOTIFY_ALL
|
data[model.DESKTOP_NOTIFY_PROP] = model.CHANNEL_NOTIFY_ALL
|
||||||
data["mark_unread"] = "junk"
|
data[model.MARK_UNREAD_NOTIFY_PROP] = "junk"
|
||||||
if _, err := Client.UpdateNotifyProps(data); err == nil {
|
if _, err := Client.UpdateNotifyProps(data); err == nil {
|
||||||
t.Fatal("Should have errored - bad mark unread level")
|
t.Fatal("Should have errored - bad mark unread level")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
data[model.DESKTOP_NOTIFY_PROP] = model.CHANNEL_NOTIFY_ALL
|
||||||
|
data[model.MARK_UNREAD_NOTIFY_PROP] = model.CHANNEL_MARK_UNREAD_ALL
|
||||||
|
data[model.PUSH_NOTIFY_PROP] = "junk"
|
||||||
|
data[model.EMAIL_NOTIFY_PROP] = "true"
|
||||||
|
if _, err := Client.UpdateNotifyProps(data); err == nil {
|
||||||
|
t.Fatal("Should have errored - bad push level")
|
||||||
|
}
|
||||||
|
|
||||||
|
data[model.PUSH_NOTIFY_PROP] = model.CHANNEL_NOTIFY_ALL
|
||||||
|
data[model.EMAIL_NOTIFY_PROP] = "junk"
|
||||||
|
if _, err := Client.UpdateNotifyProps(data); err == nil {
|
||||||
|
t.Fatal("Should have errored - bad email notification option")
|
||||||
|
}
|
||||||
|
|
||||||
th.LoginBasic2()
|
th.LoginBasic2()
|
||||||
|
|
||||||
data["channel_id"] = channel1.Id
|
data["channel_id"] = channel1.Id
|
||||||
data["user_id"] = user2.Id
|
data["user_id"] = user2.Id
|
||||||
data["desktop"] = model.CHANNEL_NOTIFY_MENTION
|
data[model.DESKTOP_NOTIFY_PROP] = model.CHANNEL_NOTIFY_MENTION
|
||||||
data["mark_unread"] = model.CHANNEL_MARK_UNREAD_MENTION
|
data[model.MARK_UNREAD_NOTIFY_PROP] = model.CHANNEL_MARK_UNREAD_MENTION
|
||||||
if _, err := Client.UpdateNotifyProps(data); err == nil {
|
if _, err := Client.UpdateNotifyProps(data); err == nil {
|
||||||
t.Fatal("Should have errored - user not in channel")
|
t.Fatal("Should have errored - user not in channel")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -226,18 +226,27 @@ func UpdateChannelMemberNotifyProps(data map[string]string, channelId string, us
|
|||||||
}
|
}
|
||||||
|
|
||||||
// update whichever notify properties have been provided, but don't change the others
|
// update whichever notify properties have been provided, but don't change the others
|
||||||
if markUnread, exists := data["mark_unread"]; exists {
|
if markUnread, exists := data[model.MARK_UNREAD_NOTIFY_PROP]; exists {
|
||||||
member.NotifyProps["mark_unread"] = markUnread
|
member.NotifyProps[model.MARK_UNREAD_NOTIFY_PROP] = markUnread
|
||||||
}
|
}
|
||||||
|
|
||||||
if desktop, exists := data["desktop"]; exists {
|
if desktop, exists := data[model.DESKTOP_NOTIFY_PROP]; exists {
|
||||||
member.NotifyProps["desktop"] = desktop
|
member.NotifyProps[model.DESKTOP_NOTIFY_PROP] = desktop
|
||||||
|
}
|
||||||
|
|
||||||
|
if email, exists := data[model.EMAIL_NOTIFY_PROP]; exists {
|
||||||
|
member.NotifyProps[model.EMAIL_NOTIFY_PROP] = email
|
||||||
|
}
|
||||||
|
|
||||||
|
if push, exists := data[model.PUSH_NOTIFY_PROP]; exists {
|
||||||
|
member.NotifyProps[model.PUSH_NOTIFY_PROP] = push
|
||||||
}
|
}
|
||||||
|
|
||||||
if result := <-Srv.Store.Channel().UpdateMember(member); result.Err != nil {
|
if result := <-Srv.Store.Channel().UpdateMember(member); result.Err != nil {
|
||||||
return nil, result.Err
|
return nil, result.Err
|
||||||
} else {
|
} else {
|
||||||
InvalidateCacheForUser(userId)
|
InvalidateCacheForUser(userId)
|
||||||
|
InvalidateCacheForChannelMembersNotifyProps(channelId)
|
||||||
return member, nil
|
return member, nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -581,11 +581,11 @@ func ImportUserChannels(user *model.User, team *model.Team, data *[]UserChannelI
|
|||||||
notifyProps := member.NotifyProps
|
notifyProps := member.NotifyProps
|
||||||
|
|
||||||
if cdata.NotifyProps.Desktop != nil {
|
if cdata.NotifyProps.Desktop != nil {
|
||||||
notifyProps["desktop"] = *cdata.NotifyProps.Desktop
|
notifyProps[model.DESKTOP_NOTIFY_PROP] = *cdata.NotifyProps.Desktop
|
||||||
}
|
}
|
||||||
|
|
||||||
if cdata.NotifyProps.MarkUnread != nil {
|
if cdata.NotifyProps.MarkUnread != nil {
|
||||||
notifyProps["mark_unread"] = *cdata.NotifyProps.MarkUnread
|
notifyProps[model.MARK_UNREAD_NOTIFY_PROP] = *cdata.NotifyProps.MarkUnread
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, err := UpdateChannelMemberNotifyProps(notifyProps, channel.Id, user.Id); err != nil {
|
if _, err := UpdateChannelMemberNotifyProps(notifyProps, channel.Id, user.Id); err != nil {
|
||||||
|
|||||||
@@ -1157,7 +1157,7 @@ func TestImportImportUser(t *testing.T) {
|
|||||||
// Check channel member properties.
|
// Check channel member properties.
|
||||||
if channelMember, err := GetChannelMember(channel.Id, user.Id); err != nil {
|
if channelMember, err := GetChannelMember(channel.Id, user.Id); err != nil {
|
||||||
t.Fatalf("Failed to get channel member from database.")
|
t.Fatalf("Failed to get channel member from database.")
|
||||||
} else if channelMember.Roles != "channel_user" || channelMember.NotifyProps["desktop"] != "default" || channelMember.NotifyProps["mark_unread"] != "all" {
|
} else if channelMember.Roles != "channel_user" || channelMember.NotifyProps[model.DESKTOP_NOTIFY_PROP] != "default" || channelMember.NotifyProps[model.MARK_UNREAD_NOTIFY_PROP] != "all" {
|
||||||
t.Fatalf("Channel member properties not as expected")
|
t.Fatalf("Channel member properties not as expected")
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1171,8 +1171,8 @@ func TestImportImportUser(t *testing.T) {
|
|||||||
Name: &channelName,
|
Name: &channelName,
|
||||||
Roles: ptrStr("channel_user channel_admin"),
|
Roles: ptrStr("channel_user channel_admin"),
|
||||||
NotifyProps: &UserChannelNotifyPropsImportData{
|
NotifyProps: &UserChannelNotifyPropsImportData{
|
||||||
Desktop: ptrStr("mention"),
|
Desktop: ptrStr(model.USER_NOTIFY_MENTION),
|
||||||
MarkUnread: ptrStr("mention"),
|
MarkUnread: ptrStr(model.USER_NOTIFY_MENTION),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@@ -1191,7 +1191,7 @@ func TestImportImportUser(t *testing.T) {
|
|||||||
|
|
||||||
if channelMember, err := GetChannelMember(channel.Id, user.Id); err != nil {
|
if channelMember, err := GetChannelMember(channel.Id, user.Id); err != nil {
|
||||||
t.Fatalf("Failed to get channel member Desktop from database.")
|
t.Fatalf("Failed to get channel member Desktop from database.")
|
||||||
} else if channelMember.Roles != "channel_user channel_admin" && channelMember.NotifyProps["desktop"] == "mention" && channelMember.NotifyProps["mark_unread"] == "mention" {
|
} else if channelMember.Roles != "channel_user channel_admin" && channelMember.NotifyProps[model.DESKTOP_NOTIFY_PROP] == model.USER_NOTIFY_MENTION && channelMember.NotifyProps[model.MARK_UNREAD_NOTIFY_PROP] == model.USER_NOTIFY_MENTION {
|
||||||
t.Fatalf("Channel member properties not as expected")
|
t.Fatalf("Channel member properties not as expected")
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1211,14 +1211,14 @@ func TestImportImportUser(t *testing.T) {
|
|||||||
// Add a user with some preferences.
|
// Add a user with some preferences.
|
||||||
username = model.NewId()
|
username = model.NewId()
|
||||||
data = UserImportData{
|
data = UserImportData{
|
||||||
Username: &username,
|
Username: &username,
|
||||||
Email: ptrStr(model.NewId() + "@example.com"),
|
Email: ptrStr(model.NewId() + "@example.com"),
|
||||||
Theme: ptrStr(`{"awayIndicator":"#DCBD4E","buttonBg":"#23A2FF","buttonColor":"#FFFFFF","centerChannelBg":"#ffffff","centerChannelColor":"#333333","codeTheme":"github","image":"/static/files/a4a388b38b32678e83823ef1b3e17766.png","linkColor":"#2389d7","mentionBj":"#2389d7","mentionColor":"#ffffff","mentionHighlightBg":"#fff2bb","mentionHighlightLink":"#2f81b7","newMessageSeparator":"#FF8800","onlineIndicator":"#7DBE00","sidebarBg":"#fafafa","sidebarHeaderBg":"#3481B9","sidebarHeaderTextColor":"#ffffff","sidebarText":"#333333","sidebarTextActiveBorder":"#378FD2","sidebarTextActiveColor":"#111111","sidebarTextHoverBg":"#e6f2fa","sidebarUnreadText":"#333333","type":"Mattermost"}`),
|
Theme: ptrStr(`{"awayIndicator":"#DCBD4E","buttonBg":"#23A2FF","buttonColor":"#FFFFFF","centerChannelBg":"#ffffff","centerChannelColor":"#333333","codeTheme":"github","image":"/static/files/a4a388b38b32678e83823ef1b3e17766.png","linkColor":"#2389d7","mentionBj":"#2389d7","mentionColor":"#ffffff","mentionHighlightBg":"#fff2bb","mentionHighlightLink":"#2f81b7","newMessageSeparator":"#FF8800","onlineIndicator":"#7DBE00","sidebarBg":"#fafafa","sidebarHeaderBg":"#3481B9","sidebarHeaderTextColor":"#ffffff","sidebarText":"#333333","sidebarTextActiveBorder":"#378FD2","sidebarTextActiveColor":"#111111","sidebarTextHoverBg":"#e6f2fa","sidebarUnreadText":"#333333","type":"Mattermost"}`),
|
||||||
SelectedFont: ptrStr("Roboto Slab"),
|
SelectedFont: ptrStr("Roboto Slab"),
|
||||||
UseMilitaryTime: ptrStr("true"),
|
UseMilitaryTime: ptrStr("true"),
|
||||||
NameFormat: ptrStr("nickname_full_name"),
|
NameFormat: ptrStr("nickname_full_name"),
|
||||||
CollapsePreviews: ptrStr("true"),
|
CollapsePreviews: ptrStr("true"),
|
||||||
MessageDisplay: ptrStr("compact"),
|
MessageDisplay: ptrStr("compact"),
|
||||||
ChannelDisplayMode: ptrStr("centered"),
|
ChannelDisplayMode: ptrStr("centered"),
|
||||||
}
|
}
|
||||||
if err := ImportUser(&data, false); err != nil {
|
if err := ImportUser(&data, false); err != nil {
|
||||||
@@ -1226,12 +1226,12 @@ func TestImportImportUser(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Check their values.
|
// Check their values.
|
||||||
user, err = GetUserByUsername(username);
|
user, err = GetUserByUsername(username)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Failed to get user from database.")
|
t.Fatalf("Failed to get user from database.")
|
||||||
}
|
}
|
||||||
|
|
||||||
if res := <- Srv.Store.Preference().GetCategory(user.Id, model.PREFERENCE_CATEGORY_THEME); res.Err != nil {
|
if res := <-Srv.Store.Preference().GetCategory(user.Id, model.PREFERENCE_CATEGORY_THEME); res.Err != nil {
|
||||||
t.Fatalf("Failed to get theme category preferences")
|
t.Fatalf("Failed to get theme category preferences")
|
||||||
} else {
|
} else {
|
||||||
preferences := res.Data.(model.Preferences)
|
preferences := res.Data.(model.Preferences)
|
||||||
@@ -1242,7 +1242,7 @@ func TestImportImportUser(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if res := <- Srv.Store.Preference().GetCategory(user.Id, model.PREFERENCE_CATEGORY_DISPLAY_SETTINGS); res.Err != nil {
|
if res := <-Srv.Store.Preference().GetCategory(user.Id, model.PREFERENCE_CATEGORY_DISPLAY_SETTINGS); res.Err != nil {
|
||||||
t.Fatalf("Failed to get display category preferences")
|
t.Fatalf("Failed to get display category preferences")
|
||||||
} else {
|
} else {
|
||||||
preferences := res.Data.(model.Preferences)
|
preferences := res.Data.(model.Preferences)
|
||||||
@@ -1275,14 +1275,14 @@ func TestImportImportUser(t *testing.T) {
|
|||||||
|
|
||||||
// Change those preferences.
|
// Change those preferences.
|
||||||
data = UserImportData{
|
data = UserImportData{
|
||||||
Username: &username,
|
Username: &username,
|
||||||
Email: ptrStr(model.NewId() + "@example.com"),
|
Email: ptrStr(model.NewId() + "@example.com"),
|
||||||
Theme: ptrStr(`{"awayIndicator":"#123456","buttonBg":"#23A2FF","buttonColor":"#FFFFFF","centerChannelBg":"#ffffff","centerChannelColor":"#333333","codeTheme":"github","image":"/static/files/a4a388b38b32678e83823ef1b3e17766.png","linkColor":"#2389d7","mentionBj":"#2389d7","mentionColor":"#ffffff","mentionHighlightBg":"#fff2bb","mentionHighlightLink":"#2f81b7","newMessageSeparator":"#FF8800","onlineIndicator":"#7DBE00","sidebarBg":"#fafafa","sidebarHeaderBg":"#3481B9","sidebarHeaderTextColor":"#ffffff","sidebarText":"#333333","sidebarTextActiveBorder":"#378FD2","sidebarTextActiveColor":"#111111","sidebarTextHoverBg":"#e6f2fa","sidebarUnreadText":"#333333","type":"Mattermost"}`),
|
Theme: ptrStr(`{"awayIndicator":"#123456","buttonBg":"#23A2FF","buttonColor":"#FFFFFF","centerChannelBg":"#ffffff","centerChannelColor":"#333333","codeTheme":"github","image":"/static/files/a4a388b38b32678e83823ef1b3e17766.png","linkColor":"#2389d7","mentionBj":"#2389d7","mentionColor":"#ffffff","mentionHighlightBg":"#fff2bb","mentionHighlightLink":"#2f81b7","newMessageSeparator":"#FF8800","onlineIndicator":"#7DBE00","sidebarBg":"#fafafa","sidebarHeaderBg":"#3481B9","sidebarHeaderTextColor":"#ffffff","sidebarText":"#333333","sidebarTextActiveBorder":"#378FD2","sidebarTextActiveColor":"#111111","sidebarTextHoverBg":"#e6f2fa","sidebarUnreadText":"#333333","type":"Mattermost"}`),
|
||||||
SelectedFont: ptrStr("Lato"),
|
SelectedFont: ptrStr("Lato"),
|
||||||
UseMilitaryTime: ptrStr("false"),
|
UseMilitaryTime: ptrStr("false"),
|
||||||
NameFormat: ptrStr("full_name"),
|
NameFormat: ptrStr("full_name"),
|
||||||
CollapsePreviews: ptrStr("false"),
|
CollapsePreviews: ptrStr("false"),
|
||||||
MessageDisplay: ptrStr("clean"),
|
MessageDisplay: ptrStr("clean"),
|
||||||
ChannelDisplayMode: ptrStr("full"),
|
ChannelDisplayMode: ptrStr("full"),
|
||||||
}
|
}
|
||||||
if err := ImportUser(&data, false); err != nil {
|
if err := ImportUser(&data, false); err != nil {
|
||||||
@@ -1290,7 +1290,7 @@ func TestImportImportUser(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Check their values again.
|
// Check their values again.
|
||||||
if res := <- Srv.Store.Preference().GetCategory(user.Id, model.PREFERENCE_CATEGORY_THEME); res.Err != nil {
|
if res := <-Srv.Store.Preference().GetCategory(user.Id, model.PREFERENCE_CATEGORY_THEME); res.Err != nil {
|
||||||
t.Fatalf("Failed to get theme category preferences")
|
t.Fatalf("Failed to get theme category preferences")
|
||||||
} else {
|
} else {
|
||||||
preferences := res.Data.(model.Preferences)
|
preferences := res.Data.(model.Preferences)
|
||||||
@@ -1301,7 +1301,7 @@ func TestImportImportUser(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if res := <- Srv.Store.Preference().GetCategory(user.Id, model.PREFERENCE_CATEGORY_DISPLAY_SETTINGS); res.Err != nil {
|
if res := <-Srv.Store.Preference().GetCategory(user.Id, model.PREFERENCE_CATEGORY_DISPLAY_SETTINGS); res.Err != nil {
|
||||||
t.Fatalf("Failed to get display category preferences")
|
t.Fatalf("Failed to get display category preferences")
|
||||||
} else {
|
} else {
|
||||||
preferences := res.Data.(model.Preferences)
|
preferences := res.Data.(model.Preferences)
|
||||||
@@ -1388,7 +1388,7 @@ func TestImportBulkImport(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Run bulk import using valid JSON but missing version line at the start.
|
// Run bulk import using valid JSON but missing version line at the start.
|
||||||
data3:= `{"type": "team", "team": {"type": "O", "display_name": "lskmw2d7a5ao7ppwqh5ljchvr4", "name": "` + teamName + `"}}
|
data3 := `{"type": "team", "team": {"type": "O", "display_name": "lskmw2d7a5ao7ppwqh5ljchvr4", "name": "` + teamName + `"}}
|
||||||
{"type": "channel", "channel": {"type": "O", "display_name": "xr6m6udffngark2uekvr3hoeny", "team": "` + teamName + `", "name": "` + channelName + `"}}
|
{"type": "channel", "channel": {"type": "O", "display_name": "xr6m6udffngark2uekvr3hoeny", "team": "` + teamName + `", "name": "` + channelName + `"}}
|
||||||
{"type": "user", "user": {"username": "kufjgnkxkrhhfgbrip6qxkfsaa", "email": "kufjgnkxkrhhfgbrip6qxkfsaa@example.com"}}
|
{"type": "user", "user": {"username": "kufjgnkxkrhhfgbrip6qxkfsaa", "email": "kufjgnkxkrhhfgbrip6qxkfsaa@example.com"}}
|
||||||
{"type": "user", "user": {"username": "bwshaim6qnc2ne7oqkd5b2s2rq", "email": "bwshaim6qnc2ne7oqkd5b2s2rq@example.com", "teams": [{"name": "` + teamName + `", "channels": [{"name": "` + channelName + `"}]}]}}`
|
{"type": "user", "user": {"username": "bwshaim6qnc2ne7oqkd5b2s2rq", "email": "bwshaim6qnc2ne7oqkd5b2s2rq@example.com", "teams": [{"name": "` + teamName + `", "channels": [{"name": "` + channelName + `"}]}]}}`
|
||||||
@@ -1401,7 +1401,7 @@ func TestImportProcessImportDataFileVersionLine(t *testing.T) {
|
|||||||
_ = Setup()
|
_ = Setup()
|
||||||
|
|
||||||
data := LineImportData{
|
data := LineImportData{
|
||||||
Type: "version",
|
Type: "version",
|
||||||
Version: ptrInt(1),
|
Version: ptrInt(1),
|
||||||
}
|
}
|
||||||
if version, err := processImportDataFileVersionLine(data); err != nil || version != 1 {
|
if version, err := processImportDataFileVersionLine(data); err != nil || version != 1 {
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ import (
|
|||||||
|
|
||||||
func SendNotifications(post *model.Post, team *model.Team, channel *model.Channel, sender *model.User) ([]string, *model.AppError) {
|
func SendNotifications(post *model.Post, team *model.Team, channel *model.Channel, sender *model.User) ([]string, *model.AppError) {
|
||||||
pchan := Srv.Store.User().GetAllProfilesInChannel(channel.Id, true)
|
pchan := Srv.Store.User().GetAllProfilesInChannel(channel.Id, true)
|
||||||
|
cmnchan := Srv.Store.Channel().GetAllChannelMembersNotifyPropsForChannel(channel.Id, true)
|
||||||
var fchan store.StoreChannel
|
var fchan store.StoreChannel
|
||||||
|
|
||||||
if len(post.FileIds) != 0 {
|
if len(post.FileIds) != 0 {
|
||||||
@@ -39,6 +40,13 @@ func SendNotifications(post *model.Post, team *model.Team, channel *model.Channe
|
|||||||
profileMap = result.Data.(map[string]*model.User)
|
profileMap = result.Data.(map[string]*model.User)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var channelMemberNotifyPropsMap map[string]model.StringMap
|
||||||
|
if result := <-cmnchan; result.Err != nil {
|
||||||
|
return nil, result.Err
|
||||||
|
} else {
|
||||||
|
channelMemberNotifyPropsMap = result.Data.(map[string]model.StringMap)
|
||||||
|
}
|
||||||
|
|
||||||
mentionedUserIds := make(map[string]bool)
|
mentionedUserIds := make(map[string]bool)
|
||||||
allActivityPushUserIds := []string{}
|
allActivityPushUserIds := []string{}
|
||||||
hereNotification := false
|
hereNotification := false
|
||||||
@@ -94,7 +102,7 @@ func SendNotifications(post *model.Post, team *model.Team, channel *model.Channe
|
|||||||
|
|
||||||
// find which users in the channel are set up to always receive mobile notifications
|
// find which users in the channel are set up to always receive mobile notifications
|
||||||
for _, profile := range profileMap {
|
for _, profile := range profileMap {
|
||||||
if profile.NotifyProps["push"] == model.USER_NOTIFY_ALL &&
|
if profile.NotifyProps[model.PUSH_NOTIFY_PROP] == model.USER_NOTIFY_ALL &&
|
||||||
(post.UserId != profile.Id || post.Props["from_webhook"] == "true") &&
|
(post.UserId != profile.Id || post.Props["from_webhook"] == "true") &&
|
||||||
!post.IsSystemMessage() {
|
!post.IsSystemMessage() {
|
||||||
allActivityPushUserIds = append(allActivityPushUserIds, profile.Id)
|
allActivityPushUserIds = append(allActivityPushUserIds, profile.Id)
|
||||||
@@ -137,7 +145,12 @@ func SendNotifications(post *model.Post, team *model.Team, channel *model.Channe
|
|||||||
|
|
||||||
if utils.Cfg.EmailSettings.SendEmailNotifications {
|
if utils.Cfg.EmailSettings.SendEmailNotifications {
|
||||||
for _, id := range mentionedUsersList {
|
for _, id := range mentionedUsersList {
|
||||||
userAllowsEmails := profileMap[id].NotifyProps["email"] != "false"
|
userAllowsEmails := profileMap[id].NotifyProps[model.EMAIL_NOTIFY_PROP] != "false"
|
||||||
|
if channelEmail, ok := channelMemberNotifyPropsMap[id][model.EMAIL_NOTIFY_PROP]; ok {
|
||||||
|
if channelEmail != model.CHANNEL_NOTIFY_DEFAULT {
|
||||||
|
userAllowsEmails = channelEmail != "false"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
var status *model.Status
|
var status *model.Status
|
||||||
var err *model.AppError
|
var err *model.AppError
|
||||||
@@ -245,7 +258,7 @@ func SendNotifications(post *model.Post, team *model.Team, channel *model.Channe
|
|||||||
}
|
}
|
||||||
|
|
||||||
if DoesStatusAllowPushNotification(profileMap[id], status, post.ChannelId) {
|
if DoesStatusAllowPushNotification(profileMap[id], status, post.ChannelId) {
|
||||||
sendPushNotification(post, profileMap[id], channel, senderName[id], true)
|
sendPushNotification(post, profileMap[id], channel, senderName[id], channelMemberNotifyPropsMap[id], true)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -258,7 +271,7 @@ func SendNotifications(post *model.Post, team *model.Team, channel *model.Channe
|
|||||||
}
|
}
|
||||||
|
|
||||||
if DoesStatusAllowPushNotification(profileMap[id], status, post.ChannelId) {
|
if DoesStatusAllowPushNotification(profileMap[id], status, post.ChannelId) {
|
||||||
sendPushNotification(post, profileMap[id], channel, senderName[id], false)
|
sendPushNotification(post, profileMap[id], channel, senderName[id], channelMemberNotifyPropsMap[id], false)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -442,7 +455,7 @@ func GetMessageForNotification(post *model.Post, translateFunc i18n.TranslateFun
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func sendPushNotification(post *model.Post, user *model.User, channel *model.Channel, senderName string, wasMentioned bool) *model.AppError {
|
func sendPushNotification(post *model.Post, user *model.User, channel *model.Channel, senderName string, channelNotifyProps model.StringMap, wasMentioned bool) *model.AppError {
|
||||||
sessions, err := getMobileAppSessions(user.Id)
|
sessions, err := getMobileAppSessions(user.Id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -450,6 +463,14 @@ func sendPushNotification(post *model.Post, user *model.User, channel *model.Cha
|
|||||||
|
|
||||||
var channelName string
|
var channelName string
|
||||||
|
|
||||||
|
if channelNotify, ok := channelNotifyProps[model.PUSH_NOTIFY_PROP]; ok {
|
||||||
|
if channelNotify == model.USER_NOTIFY_NONE {
|
||||||
|
return nil
|
||||||
|
} else if channelNotify == model.USER_NOTIFY_MENTION && !wasMentioned {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if channel.Type == model.CHANNEL_DIRECT {
|
if channel.Type == model.CHANNEL_DIRECT {
|
||||||
channelName = senderName
|
channelName = senderName
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -134,6 +134,18 @@ func InvalidateCacheForChannelMembersSkipClusterSend(channelId string) {
|
|||||||
Srv.Store.Channel().InvalidateMemberCount(channelId)
|
Srv.Store.Channel().InvalidateMemberCount(channelId)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func InvalidateCacheForChannelMembersNotifyProps(channelId string) {
|
||||||
|
InvalidateCacheForChannelMembersNotifyPropsSkipClusterSend(channelId)
|
||||||
|
|
||||||
|
if cluster := einterfaces.GetClusterInterface(); cluster != nil {
|
||||||
|
cluster.InvalidateCacheForChannelMembersNotifyProps(channelId)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func InvalidateCacheForChannelMembersNotifyPropsSkipClusterSend(channelId string) {
|
||||||
|
Srv.Store.Channel().InvalidateCacheForChannelMembersNotifyProps(channelId)
|
||||||
|
}
|
||||||
|
|
||||||
func InvalidateCacheForChannelByNameSkipClusterSend(teamId, name string) {
|
func InvalidateCacheForChannelByNameSkipClusterSend(teamId, name string) {
|
||||||
Srv.Store.Channel().InvalidateChannelByName(teamId, name)
|
Srv.Store.Channel().InvalidateChannelByName(teamId, name)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ type ClusterInterface interface {
|
|||||||
InvalidateCacheForChannel(channelId string)
|
InvalidateCacheForChannel(channelId string)
|
||||||
InvalidateCacheForChannelByName(teamId, name string)
|
InvalidateCacheForChannelByName(teamId, name string)
|
||||||
InvalidateCacheForChannelMembers(channelId string)
|
InvalidateCacheForChannelMembers(channelId string)
|
||||||
|
InvalidateCacheForChannelMembersNotifyProps(channelId string)
|
||||||
InvalidateCacheForChannelPosts(channelId string)
|
InvalidateCacheForChannelPosts(channelId string)
|
||||||
InvalidateCacheForWebhook(webhookId string)
|
InvalidateCacheForWebhook(webhookId string)
|
||||||
Publish(event *model.WebSocketEvent)
|
Publish(event *model.WebSocketEvent)
|
||||||
|
|||||||
@@ -3519,10 +3519,18 @@
|
|||||||
"id": "model.channel_member.is_valid.role.app_error",
|
"id": "model.channel_member.is_valid.role.app_error",
|
||||||
"translation": "Invalid role"
|
"translation": "Invalid role"
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"id": "model.channel_member.is_valid.email_value.app_error",
|
||||||
|
"translation": "Invalid email notification value"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"id": "model.channel_member.is_valid.unread_level.app_error",
|
"id": "model.channel_member.is_valid.unread_level.app_error",
|
||||||
"translation": "Invalid mark unread level"
|
"translation": "Invalid mark unread level"
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"id": "model.channel_member.is_valid.push_level.app_error",
|
||||||
|
"translation": "Invalid push notification level"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"id": "model.channel_member.is_valid.user_id.app_error",
|
"id": "model.channel_member.is_valid.user_id.app_error",
|
||||||
"translation": "Invalid user id"
|
"translation": "Invalid user id"
|
||||||
|
|||||||
@@ -88,18 +88,32 @@ func (o *ChannelMember) IsValid() *AppError {
|
|||||||
return NewLocAppError("ChannelMember.IsValid", "model.channel_member.is_valid.user_id.app_error", nil, "")
|
return NewLocAppError("ChannelMember.IsValid", "model.channel_member.is_valid.user_id.app_error", nil, "")
|
||||||
}
|
}
|
||||||
|
|
||||||
notifyLevel := o.NotifyProps["desktop"]
|
notifyLevel := o.NotifyProps[DESKTOP_NOTIFY_PROP]
|
||||||
if len(notifyLevel) > 20 || !IsChannelNotifyLevelValid(notifyLevel) {
|
if len(notifyLevel) > 20 || !IsChannelNotifyLevelValid(notifyLevel) {
|
||||||
return NewLocAppError("ChannelMember.IsValid", "model.channel_member.is_valid.notify_level.app_error",
|
return NewLocAppError("ChannelMember.IsValid", "model.channel_member.is_valid.notify_level.app_error",
|
||||||
nil, "notify_level="+notifyLevel)
|
nil, "notify_level="+notifyLevel)
|
||||||
}
|
}
|
||||||
|
|
||||||
markUnreadLevel := o.NotifyProps["mark_unread"]
|
markUnreadLevel := o.NotifyProps[MARK_UNREAD_NOTIFY_PROP]
|
||||||
if len(markUnreadLevel) > 20 || !IsChannelMarkUnreadLevelValid(markUnreadLevel) {
|
if len(markUnreadLevel) > 20 || !IsChannelMarkUnreadLevelValid(markUnreadLevel) {
|
||||||
return NewLocAppError("ChannelMember.IsValid", "model.channel_member.is_valid.unread_level.app_error",
|
return NewLocAppError("ChannelMember.IsValid", "model.channel_member.is_valid.unread_level.app_error",
|
||||||
nil, "mark_unread_level="+markUnreadLevel)
|
nil, "mark_unread_level="+markUnreadLevel)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if pushLevel, ok := o.NotifyProps[PUSH_NOTIFY_PROP]; ok {
|
||||||
|
if len(pushLevel) > 20 || !IsChannelNotifyLevelValid(pushLevel) {
|
||||||
|
return NewLocAppError("ChannelMember.IsValid", "model.channel_member.is_valid.push_level.app_error",
|
||||||
|
nil, "push_notification_level="+pushLevel)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if sendEmail, ok := o.NotifyProps[EMAIL_NOTIFY_PROP]; ok {
|
||||||
|
if len(sendEmail) > 20 || !IsSendEmailValid(sendEmail) {
|
||||||
|
return NewLocAppError("ChannelMember.IsValid", "model.channel_member.is_valid.email_value.app_error",
|
||||||
|
nil, "push_notification_level="+sendEmail)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -126,9 +140,15 @@ func IsChannelMarkUnreadLevelValid(markUnreadLevel string) bool {
|
|||||||
return markUnreadLevel == CHANNEL_MARK_UNREAD_ALL || markUnreadLevel == CHANNEL_MARK_UNREAD_MENTION
|
return markUnreadLevel == CHANNEL_MARK_UNREAD_ALL || markUnreadLevel == CHANNEL_MARK_UNREAD_MENTION
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func IsSendEmailValid(sendEmail string) bool {
|
||||||
|
return sendEmail == CHANNEL_NOTIFY_DEFAULT || sendEmail == "true" || sendEmail == "false"
|
||||||
|
}
|
||||||
|
|
||||||
func GetDefaultChannelNotifyProps() StringMap {
|
func GetDefaultChannelNotifyProps() StringMap {
|
||||||
return StringMap{
|
return StringMap{
|
||||||
"desktop": CHANNEL_NOTIFY_DEFAULT,
|
DESKTOP_NOTIFY_PROP: CHANNEL_NOTIFY_DEFAULT,
|
||||||
"mark_unread": CHANNEL_MARK_UNREAD_ALL,
|
MARK_UNREAD_NOTIFY_PROP: CHANNEL_MARK_UNREAD_ALL,
|
||||||
|
PUSH_NOTIFY_PROP: CHANNEL_NOTIFY_DEFAULT,
|
||||||
|
EMAIL_NOTIFY_PROP: CHANNEL_NOTIFY_DEFAULT,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,9 +16,14 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
USER_NOTIFY_ALL = "all"
|
USER_NOTIFY_ALL = "all"
|
||||||
USER_NOTIFY_MENTION = "mention"
|
USER_NOTIFY_MENTION = "mention"
|
||||||
USER_NOTIFY_NONE = "none"
|
USER_NOTIFY_NONE = "none"
|
||||||
|
DESKTOP_NOTIFY_PROP = "desktop"
|
||||||
|
MARK_UNREAD_NOTIFY_PROP = "mark_unread"
|
||||||
|
PUSH_NOTIFY_PROP = "push"
|
||||||
|
EMAIL_NOTIFY_PROP = "email"
|
||||||
|
|
||||||
DEFAULT_LOCALE = "en"
|
DEFAULT_LOCALE = "en"
|
||||||
USER_AUTH_SERVICE_EMAIL = "email"
|
USER_AUTH_SERVICE_EMAIL = "email"
|
||||||
USER_AUTH_SERVICE_USERNAME = "username"
|
USER_AUTH_SERVICE_USERNAME = "username"
|
||||||
|
|||||||
@@ -25,6 +25,9 @@ const (
|
|||||||
ALL_CHANNEL_MEMBERS_FOR_USER_CACHE_SIZE = model.SESSION_CACHE_SIZE
|
ALL_CHANNEL_MEMBERS_FOR_USER_CACHE_SIZE = model.SESSION_CACHE_SIZE
|
||||||
ALL_CHANNEL_MEMBERS_FOR_USER_CACHE_SEC = 900 // 15 mins
|
ALL_CHANNEL_MEMBERS_FOR_USER_CACHE_SEC = 900 // 15 mins
|
||||||
|
|
||||||
|
ALL_CHANNEL_MEMBERS_NOTIFY_PROPS_FOR_CHANNEL_CACHE_SIZE = model.SESSION_CACHE_SIZE
|
||||||
|
ALL_CHANNEL_MEMBERS_NOTIFY_PROPS_FOR_CHANNEL_CACHE_SEC = 1800 // 30 mins
|
||||||
|
|
||||||
CHANNEL_MEMBERS_COUNTS_CACHE_SIZE = model.CHANNEL_CACHE_SIZE
|
CHANNEL_MEMBERS_COUNTS_CACHE_SIZE = model.CHANNEL_CACHE_SIZE
|
||||||
CHANNEL_MEMBERS_COUNTS_CACHE_SEC = 1800 // 30 mins
|
CHANNEL_MEMBERS_COUNTS_CACHE_SEC = 1800 // 30 mins
|
||||||
|
|
||||||
@@ -37,12 +40,14 @@ type SqlChannelStore struct {
|
|||||||
|
|
||||||
var channelMemberCountsCache = utils.NewLru(CHANNEL_MEMBERS_COUNTS_CACHE_SIZE)
|
var channelMemberCountsCache = utils.NewLru(CHANNEL_MEMBERS_COUNTS_CACHE_SIZE)
|
||||||
var allChannelMembersForUserCache = utils.NewLru(ALL_CHANNEL_MEMBERS_FOR_USER_CACHE_SIZE)
|
var allChannelMembersForUserCache = utils.NewLru(ALL_CHANNEL_MEMBERS_FOR_USER_CACHE_SIZE)
|
||||||
|
var allChannelMembersNotifyPropsForChannelCache = utils.NewLru(ALL_CHANNEL_MEMBERS_NOTIFY_PROPS_FOR_CHANNEL_CACHE_SIZE)
|
||||||
var channelCache = utils.NewLru(model.CHANNEL_CACHE_SIZE)
|
var channelCache = utils.NewLru(model.CHANNEL_CACHE_SIZE)
|
||||||
var channelByNameCache = utils.NewLru(model.CHANNEL_CACHE_SIZE)
|
var channelByNameCache = utils.NewLru(model.CHANNEL_CACHE_SIZE)
|
||||||
|
|
||||||
func ClearChannelCaches() {
|
func ClearChannelCaches() {
|
||||||
channelMemberCountsCache.Purge()
|
channelMemberCountsCache.Purge()
|
||||||
allChannelMembersForUserCache.Purge()
|
allChannelMembersForUserCache.Purge()
|
||||||
|
allChannelMembersNotifyPropsForChannelCache.Purge()
|
||||||
channelCache.Purge()
|
channelCache.Purge()
|
||||||
channelByNameCache.Purge()
|
channelByNameCache.Purge()
|
||||||
}
|
}
|
||||||
@@ -919,6 +924,69 @@ func (s SqlChannelStore) GetAllChannelMembersForUser(userId string, allowFromCac
|
|||||||
return storeChannel
|
return storeChannel
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (us SqlChannelStore) InvalidateCacheForChannelMembersNotifyProps(channelId string) {
|
||||||
|
allChannelMembersNotifyPropsForChannelCache.Remove(channelId)
|
||||||
|
}
|
||||||
|
|
||||||
|
type allChannelMemberNotifyProps struct {
|
||||||
|
UserId string
|
||||||
|
NotifyProps model.StringMap
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s SqlChannelStore) GetAllChannelMembersNotifyPropsForChannel(channelId string, allowFromCache bool) StoreChannel {
|
||||||
|
storeChannel := make(StoreChannel, 1)
|
||||||
|
|
||||||
|
go func() {
|
||||||
|
result := StoreResult{}
|
||||||
|
metrics := einterfaces.GetMetricsInterface()
|
||||||
|
|
||||||
|
if allowFromCache {
|
||||||
|
if cacheItem, ok := allChannelMembersNotifyPropsForChannelCache.Get(channelId); ok {
|
||||||
|
if metrics != nil {
|
||||||
|
metrics.IncrementMemCacheHitCounter("All Channel Members Notify Props for Channel")
|
||||||
|
}
|
||||||
|
result.Data = cacheItem.(map[string]model.StringMap)
|
||||||
|
storeChannel <- result
|
||||||
|
close(storeChannel)
|
||||||
|
return
|
||||||
|
} else {
|
||||||
|
if metrics != nil {
|
||||||
|
metrics.IncrementMemCacheMissCounter("All Channel Members Notify Props for Channel")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if metrics != nil {
|
||||||
|
metrics.IncrementMemCacheMissCounter("All Channel Members Notify Props for Channel")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var data []allChannelMemberNotifyProps
|
||||||
|
_, err := s.GetReplica().Select(&data, `
|
||||||
|
SELECT ChannelMembers.UserId, ChannelMembers.NotifyProps
|
||||||
|
FROM Channels, ChannelMembers
|
||||||
|
WHERE Channels.Id = ChannelMembers.ChannelId AND ChannelMembers.ChannelId = :ChannelId`, map[string]interface{}{"ChannelId": channelId})
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
result.Err = model.NewLocAppError("SqlChannelStore.GetAllChannelMembersPropsForChannel", "store.sql_channel.get_members.app_error", nil, "channelId="+channelId+", err="+err.Error())
|
||||||
|
} else {
|
||||||
|
|
||||||
|
props := make(map[string]model.StringMap)
|
||||||
|
for i := range data {
|
||||||
|
props[data[i].UserId] = data[i].NotifyProps
|
||||||
|
}
|
||||||
|
|
||||||
|
result.Data = props
|
||||||
|
|
||||||
|
allChannelMembersNotifyPropsForChannelCache.AddWithExpiresInSecs(channelId, props, ALL_CHANNEL_MEMBERS_NOTIFY_PROPS_FOR_CHANNEL_CACHE_SEC)
|
||||||
|
}
|
||||||
|
|
||||||
|
storeChannel <- result
|
||||||
|
close(storeChannel)
|
||||||
|
}()
|
||||||
|
|
||||||
|
return storeChannel
|
||||||
|
}
|
||||||
|
|
||||||
func (us SqlChannelStore) InvalidateMemberCount(channelId string) {
|
func (us SqlChannelStore) InvalidateMemberCount(channelId string) {
|
||||||
channelMemberCountsCache.Remove(channelId)
|
channelMemberCountsCache.Remove(channelId)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -110,6 +110,8 @@ type ChannelStore interface {
|
|||||||
GetAllChannelMembersForUser(userId string, allowFromCache bool) StoreChannel
|
GetAllChannelMembersForUser(userId string, allowFromCache bool) StoreChannel
|
||||||
InvalidateAllChannelMembersForUser(userId string)
|
InvalidateAllChannelMembersForUser(userId string)
|
||||||
IsUserInChannelUseCache(userId string, channelId string) bool
|
IsUserInChannelUseCache(userId string, channelId string) bool
|
||||||
|
GetAllChannelMembersNotifyPropsForChannel(channelId string, allowFromCache bool) StoreChannel
|
||||||
|
InvalidateCacheForChannelMembersNotifyProps(channelId string)
|
||||||
GetMemberForPost(postId string, userId string) StoreChannel
|
GetMemberForPost(postId string, userId string) StoreChannel
|
||||||
InvalidateMemberCount(channelId string)
|
InvalidateMemberCount(channelId string)
|
||||||
GetMemberCountFromCache(channelId string) int64
|
GetMemberCountFromCache(channelId string) int64
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user