* Migration completed

* Several corrections in tests

* Fix imports

* Fix some errors after testing

* Trigger CI

* Fix tests

* Suggestions

* Suggestions

* Add license

Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
Этот коммит содержится в:
Rodrigo Villablanca
2020-09-15 14:48:30 -03:00
коммит произвёл GitHub
родитель 7abc4f5383
Коммит 9ee9c78412
28 изменённых файлов: 1326 добавлений и 901 удалений

Просмотреть файл

@@ -9,10 +9,10 @@ import (
"strconv" "strconv"
"strings" "strings"
"github.com/mattermost/mattermost-server/v5/app"
"github.com/mattermost/mattermost-server/v5/audit" "github.com/mattermost/mattermost-server/v5/audit"
"github.com/mattermost/mattermost-server/v5/mlog" "github.com/mattermost/mattermost-server/v5/mlog"
"github.com/mattermost/mattermost-server/v5/model" "github.com/mattermost/mattermost-server/v5/model"
"github.com/mattermost/mattermost-server/v5/store"
) )
func (api *API) InitChannel() { func (api *API) InitChannel() {
@@ -1473,7 +1473,7 @@ func addChannelMember(c *Context, w http.ResponseWriter, r *http.Request) {
isNewMembership := false isNewMembership := false
if _, err = c.App.GetChannelMember(member.ChannelId, member.UserId); err != nil { if _, err = c.App.GetChannelMember(member.ChannelId, member.UserId); err != nil {
if err.Id == store.MISSING_CHANNEL_MEMBER_ERROR { if err.Id == app.MISSING_CHANNEL_MEMBER_ERROR {
isNewMembership = true isNewMembership = true
} else { } else {
c.Err = err c.Err = err
@@ -1730,7 +1730,7 @@ func channelMemberCountsByGroup(c *Context, w http.ResponseWriter, r *http.Reque
channelMemberCounts, err := c.App.Srv().Store.Channel().GetMemberCountsByGroup(c.Params.ChannelId, includeTimezones) channelMemberCounts, err := c.App.Srv().Store.Channel().GetMemberCountsByGroup(c.Params.ChannelId, includeTimezones)
if err != nil { if err != nil {
c.Err = err c.Err = model.NewAppError("Api4.channelMemberCountsByGroup", "app.channel.get_member_count.app_error", nil, err.Error(), http.StatusInternalServerError)
return return
} }

Просмотреть файл

@@ -47,12 +47,12 @@ func (a *App) GetAnalytics(name string, teamId string) (model.AnalyticsRows, *mo
privateChan := make(chan store.StoreResult, 1) privateChan := make(chan store.StoreResult, 1)
go func() { go func() {
count, err2 := a.Srv().Store.Channel().AnalyticsTypeCount(teamId, model.CHANNEL_OPEN) count, err2 := a.Srv().Store.Channel().AnalyticsTypeCount(teamId, model.CHANNEL_OPEN)
openChan <- store.StoreResult{Data: count, Err: err2} openChan <- store.StoreResult{Data: count, NErr: err2}
close(openChan) close(openChan)
}() }()
go func() { go func() {
count, err2 := a.Srv().Store.Channel().AnalyticsTypeCount(teamId, model.CHANNEL_PRIVATE) count, err2 := a.Srv().Store.Channel().AnalyticsTypeCount(teamId, model.CHANNEL_PRIVATE)
privateChan <- store.StoreResult{Data: count, Err: err2} privateChan <- store.StoreResult{Data: count, NErr: err2}
close(privateChan) close(privateChan)
}() }()
@@ -106,14 +106,14 @@ func (a *App) GetAnalytics(name string, teamId string) (model.AnalyticsRows, *mo
}() }()
r := <-openChan r := <-openChan
if r.Err != nil { if r.NErr != nil {
return nil, r.Err return nil, model.NewAppError("GetAnalytics", "app.channel.analytics_type_count.app_error", nil, r.NErr.Error(), http.StatusInternalServerError)
} }
rows[0].Value = float64(r.Data.(int64)) rows[0].Value = float64(r.Data.(int64))
r = <-privateChan r = <-privateChan
if r.Err != nil { if r.NErr != nil {
return nil, r.Err return nil, model.NewAppError("GetAnalytics", "app.channel.analytics_type_count.app_error", nil, r.NErr.Error(), http.StatusInternalServerError)
} }
rows[1].Value = float64(r.Data.(int64)) rows[1].Value = float64(r.Data.(int64))

Просмотреть файл

@@ -71,8 +71,8 @@ func (a *App) SessionHasPermissionToChannel(session model.Session, channelId str
} }
} }
channel, err := a.GetChannel(channelId) channel, appErr := a.GetChannel(channelId)
if err != nil && err.StatusCode == http.StatusNotFound { if appErr != nil && appErr.StatusCode == http.StatusNotFound {
return false return false
} }

Просмотреть файл

@@ -74,6 +74,7 @@ func (a *App) JoinDefaultChannels(teamId string, user *model.User, shouldBeAdmin
} }
var err *model.AppError var err *model.AppError
var nErr error
for _, channelName := range a.DefaultChannelNames() { for _, channelName := range a.DefaultChannelNames() {
channel, channelErr := a.Srv().Store.Channel().GetByName(teamId, channelName, true) channel, channelErr := a.Srv().Store.Channel().GetByName(teamId, channelName, true)
if channelErr != nil { if channelErr != nil {
@@ -100,7 +101,7 @@ func (a *App) JoinDefaultChannels(teamId string, user *model.User, shouldBeAdmin
NotifyProps: model.GetDefaultChannelNotifyProps(), NotifyProps: model.GetDefaultChannelNotifyProps(),
} }
_, err = a.Srv().Store.Channel().SaveMember(cm) _, nErr = a.Srv().Store.Channel().SaveMember(cm)
if histErr := a.Srv().Store.ChannelMemberHistory().LogJoinEvent(user.Id, channel.Id, model.GetMillis()); histErr != nil { if histErr := a.Srv().Store.ChannelMemberHistory().LogJoinEvent(user.Id, channel.Id, model.GetMillis()); histErr != nil {
mlog.Error("Failed to update ChannelMemberHistory table", mlog.Err(histErr)) mlog.Error("Failed to update ChannelMemberHistory table", mlog.Err(histErr))
return model.NewAppError("JoinDefaultChannels", "app.channel_member_history.log_join_event.internal_error", nil, histErr.Error(), http.StatusInternalServerError) return model.NewAppError("JoinDefaultChannels", "app.channel_member_history.log_join_event.internal_error", nil, histErr.Error(), http.StatusInternalServerError)
@@ -119,7 +120,22 @@ func (a *App) JoinDefaultChannels(teamId string, user *model.User, shouldBeAdmin
} }
return err if nErr != nil {
var appErr *model.AppError
var cErr *store.ErrConflict
switch {
case errors.As(nErr, &cErr):
if cErr.Resource == "ChannelMembers" {
return model.NewAppError("JoinDefaultChannels", "app.channel.save_member.exists.app_error", nil, cErr.Error(), http.StatusBadRequest)
}
case errors.As(nErr, &appErr):
return appErr
default:
return model.NewAppError("JoinDefaultChannels", "app.channel.create_direct_channel.internal_error", nil, nErr.Error(), http.StatusInternalServerError)
}
}
return nil
} }
func (a *App) postJoinMessageForDefaultChannel(user *model.User, requestor *model.User, channel *model.Channel) { func (a *App) postJoinMessageForDefaultChannel(user *model.User, requestor *model.User, channel *model.Channel) {
@@ -254,9 +270,22 @@ func (a *App) CreateChannel(channel *model.Channel, addMember bool) (*model.Chan
NotifyProps: model.GetDefaultChannelNotifyProps(), NotifyProps: model.GetDefaultChannelNotifyProps(),
} }
if _, err := a.Srv().Store.Channel().SaveMember(cm); err != nil { if _, nErr := a.Srv().Store.Channel().SaveMember(cm); nErr != nil {
return nil, err var appErr *model.AppError
var cErr *store.ErrConflict
switch {
case errors.As(nErr, &cErr):
switch cErr.Resource {
case "ChannelMembers":
return nil, model.NewAppError("CreateChannel", "app.channel.save_member.exists.app_error", nil, cErr.Error(), http.StatusBadRequest)
}
case errors.As(nErr, &appErr):
return nil, appErr
default:
return nil, model.NewAppError("CreateChannel", "app.channel.create_direct_channel.internal_error", nil, nErr.Error(), http.StatusInternalServerError)
}
} }
if err := a.Srv().Store.ChannelMemberHistory().LogJoinEvent(channel.CreatorId, sc.Id, model.GetMillis()); err != nil { if err := a.Srv().Store.ChannelMemberHistory().LogJoinEvent(channel.CreatorId, sc.Id, model.GetMillis()); err != nil {
mlog.Error("Failed to update ChannelMemberHistory table", mlog.Err(err)) mlog.Error("Failed to update ChannelMemberHistory table", mlog.Err(err))
return nil, model.NewAppError("CreateChannel", "app.channel_member_history.log_join_event.internal_error", nil, err.Error(), http.StatusInternalServerError) return nil, model.NewAppError("CreateChannel", "app.channel_member_history.log_join_event.internal_error", nil, err.Error(), http.StatusInternalServerError)
@@ -365,7 +394,7 @@ func (a *App) createDirectChannel(userId string, otherUserId string) (*model.Cha
case "Channel": case "Channel":
return channel, model.NewAppError("CreateChannel", store.CHANNEL_EXISTS_ERROR, nil, cErr.Error(), http.StatusBadRequest) return channel, model.NewAppError("CreateChannel", store.CHANNEL_EXISTS_ERROR, nil, cErr.Error(), http.StatusBadRequest)
case "ChannelMembers": case "ChannelMembers":
return nil, model.NewAppError("CreateChannel", "store.sql_channel.save_member.exists.app_error", nil, cErr.Error(), http.StatusBadRequest) return nil, model.NewAppError("CreateChannel", "app.channel.save_member.exists.app_error", nil, cErr.Error(), http.StatusBadRequest)
} }
case errors.As(nErr, &ltErr): case errors.As(nErr, &ltErr):
return nil, model.NewAppError("CreateChannel", "store.sql_channel.save_channel.limit.app_error", nil, ltErr.Error(), http.StatusBadRequest) return nil, model.NewAppError("CreateChannel", "store.sql_channel.save_channel.limit.app_error", nil, ltErr.Error(), http.StatusBadRequest)
@@ -409,7 +438,8 @@ func (a *App) WaitForChannelMembership(channelId string, userId string) {
} }
// If we received an error, but it wasn't a missing channel member then return // If we received an error, but it wasn't a missing channel member then return
if err.Id != store.MISSING_CHANNEL_MEMBER_ERROR { var nfErr *store.ErrNotFound
if !errors.As(err, &nfErr) {
return return
} }
} }
@@ -497,8 +527,20 @@ func (a *App) createGroupChannel(userIds []string, creatorId string) (*model.Cha
SchemeUser: !user.IsGuest(), SchemeUser: !user.IsGuest(),
} }
if _, err := a.Srv().Store.Channel().SaveMember(cm); err != nil { if _, nErr = a.Srv().Store.Channel().SaveMember(cm); nErr != nil {
return nil, err var appErr *model.AppError
var cErr *store.ErrConflict
switch {
case errors.As(nErr, &cErr):
switch cErr.Resource {
case "ChannelMembers":
return nil, model.NewAppError("createGroupChannel", "app.channel.save_member.exists.app_error", nil, cErr.Error(), http.StatusBadRequest)
}
case errors.As(nErr, &appErr):
return nil, appErr
default:
return nil, model.NewAppError("createGroupChannel", "app.channel.create_direct_channel.internal_error", nil, nErr.Error(), http.StatusInternalServerError)
}
} }
if err := a.Srv().Store.ChannelMemberHistory().LogJoinEvent(user.Id, channel.Id, model.GetMillis()); err != nil { if err := a.Srv().Store.ChannelMemberHistory().LogJoinEvent(user.Id, channel.Id, model.GetMillis()); err != nil {
mlog.Error("Failed to update ChannelMemberHistory table", mlog.Err(err)) mlog.Error("Failed to update ChannelMemberHistory table", mlog.Err(err))
@@ -1038,9 +1080,18 @@ func (a *App) UpdateChannelMemberRoles(channelId string, userId string, newRoles
member.ExplicitRoles = strings.Join(newExplicitRoles, " ") member.ExplicitRoles = strings.Join(newExplicitRoles, " ")
member, err = a.Srv().Store.Channel().UpdateMember(member) member, nErr := a.Srv().Store.Channel().UpdateMember(member)
if err != nil { if nErr != nil {
return nil, err var appErr *model.AppError
var nfErr *store.ErrNotFound
switch {
case errors.As(nErr, &appErr):
return nil, appErr
case errors.As(nErr, &nfErr):
return nil, model.NewAppError("UpdateChannelMemberRoles", MISSING_CHANNEL_MEMBER_ERROR, nil, nfErr.Error(), http.StatusNotFound)
default:
return nil, model.NewAppError("UpdateChannelMemberRoles", "app.channel.get_member.app_error", nil, nErr.Error(), http.StatusInternalServerError)
}
} }
a.InvalidateCacheForUser(userId) a.InvalidateCacheForUser(userId)
@@ -1066,9 +1117,18 @@ func (a *App) UpdateChannelMemberSchemeRoles(channelId string, userId string, is
member.ExplicitRoles = RemoveRoles([]string{model.CHANNEL_GUEST_ROLE_ID, model.CHANNEL_USER_ROLE_ID, model.CHANNEL_ADMIN_ROLE_ID}, member.ExplicitRoles) member.ExplicitRoles = RemoveRoles([]string{model.CHANNEL_GUEST_ROLE_ID, model.CHANNEL_USER_ROLE_ID, model.CHANNEL_ADMIN_ROLE_ID}, member.ExplicitRoles)
} }
member, err = a.Srv().Store.Channel().UpdateMember(member) member, nErr := a.Srv().Store.Channel().UpdateMember(member)
if err != nil { if nErr != nil {
return nil, err var appErr *model.AppError
var nfErr *store.ErrNotFound
switch {
case errors.As(nErr, &appErr):
return nil, appErr
case errors.As(nErr, &nfErr):
return nil, model.NewAppError("UpdateChannelMemberSchemeRoles", MISSING_CHANNEL_MEMBER_ERROR, nil, nfErr.Error(), http.StatusNotFound)
default:
return nil, model.NewAppError("UpdateChannelMemberSchemeRoles", "app.channel.get_member.app_error", nil, nErr.Error(), http.StatusInternalServerError)
}
} }
// Notify the clients that the member notify props changed // Notify the clients that the member notify props changed
@@ -1108,9 +1168,18 @@ func (a *App) UpdateChannelMemberNotifyProps(data map[string]string, channelId s
member.NotifyProps[model.IGNORE_CHANNEL_MENTIONS_NOTIFY_PROP] = ignoreChannelMentions member.NotifyProps[model.IGNORE_CHANNEL_MENTIONS_NOTIFY_PROP] = ignoreChannelMentions
} }
member, err = a.Srv().Store.Channel().UpdateMember(member) member, nErr := a.Srv().Store.Channel().UpdateMember(member)
if err != nil { if nErr != nil {
return nil, err var appErr *model.AppError
var nfErr *store.ErrNotFound
switch {
case errors.As(nErr, &appErr):
return nil, appErr
case errors.As(nErr, &nfErr):
return nil, model.NewAppError("UpdateChannelMemberNotifyProps", MISSING_CHANNEL_MEMBER_ERROR, nil, nfErr.Error(), http.StatusNotFound)
default:
return nil, model.NewAppError("UpdateChannelMemberNotifyProps", "app.channel.get_member.app_error", nil, nErr.Error(), http.StatusInternalServerError)
}
} }
a.InvalidateCacheForUser(userId) a.InvalidateCacheForUser(userId)
@@ -1222,10 +1291,11 @@ func (a *App) addUserToChannel(user *model.User, channel *model.Channel, teamMem
return nil, model.NewAppError("AddUserToChannel", "api.channel.add_user_to_channel.type.app_error", nil, "", http.StatusBadRequest) return nil, model.NewAppError("AddUserToChannel", "api.channel.add_user_to_channel.type.app_error", nil, "", http.StatusBadRequest)
} }
channelMember, err := a.Srv().Store.Channel().GetMember(channel.Id, user.Id) channelMember, nErr := a.Srv().Store.Channel().GetMember(channel.Id, user.Id)
if err != nil { if nErr != nil {
if err.Id != store.MISSING_CHANNEL_MEMBER_ERROR { var nfErr *store.ErrNotFound
return nil, err if !errors.As(nErr, &nfErr) {
return nil, model.NewAppError("AddUserToChannel", "app.channel.get_member.app_error", nil, nErr.Error(), http.StatusInternalServerError)
} }
} else { } else {
return channelMember, nil return channelMember, nil
@@ -1251,16 +1321,16 @@ func (a *App) addUserToChannel(user *model.User, channel *model.Channel, teamMem
if !user.IsGuest() { if !user.IsGuest() {
var userShouldBeAdmin bool var userShouldBeAdmin bool
userShouldBeAdmin, err = a.UserIsInAdminRoleGroup(user.Id, channel.Id, model.GroupSyncableTypeChannel) userShouldBeAdmin, appErr := a.UserIsInAdminRoleGroup(user.Id, channel.Id, model.GroupSyncableTypeChannel)
if err != nil { if appErr != nil {
return nil, err return nil, appErr
} }
newMember.SchemeAdmin = userShouldBeAdmin newMember.SchemeAdmin = userShouldBeAdmin
} }
newMember, err = a.Srv().Store.Channel().SaveMember(newMember) newMember, nErr = a.Srv().Store.Channel().SaveMember(newMember)
if err != nil { if nErr != nil {
mlog.Error("Failed to add member", mlog.String("user_id", user.Id), mlog.String("channel_id", channel.Id), mlog.Err(err)) mlog.Error("Failed to add member", mlog.String("user_id", user.Id), mlog.String("channel_id", channel.Id), mlog.Err(nErr))
return nil, model.NewAppError("AddUserToChannel", "api.channel.add_user.to.channel.failed.app_error", nil, "", http.StatusInternalServerError) return nil, model.NewAppError("AddUserToChannel", "api.channel.add_user.to.channel.failed.app_error", nil, "", http.StatusInternalServerError)
} }
a.WaitForChannelMembership(channel.Id, user.Id) a.WaitForChannelMembership(channel.Id, user.Id)
@@ -1301,8 +1371,9 @@ func (a *App) AddUserToChannel(user *model.User, channel *model.Channel) (*model
func (a *App) AddChannelMember(userId string, channel *model.Channel, userRequestorId string, postRootId string) (*model.ChannelMember, *model.AppError) { func (a *App) AddChannelMember(userId string, channel *model.Channel, userRequestorId string, postRootId string) (*model.ChannelMember, *model.AppError) {
if member, err := a.Srv().Store.Channel().GetMember(channel.Id, userId); err != nil { if member, err := a.Srv().Store.Channel().GetMember(channel.Id, userId); err != nil {
if err.Id != store.MISSING_CHANNEL_MEMBER_ERROR { var nfErr *store.ErrNotFound
return nil, err if !errors.As(err, &nfErr) {
return nil, model.NewAppError("AddChannelMember", "app.channel.get_member.app_error", nil, err.Error(), http.StatusInternalServerError)
} }
} else { } else {
return member, nil return member, nil
@@ -1665,17 +1736,33 @@ func (a *App) GetPrivateChannelsForTeam(teamId string, offset int, limit int) (*
} }
func (a *App) GetChannelMember(channelId string, userId string) (*model.ChannelMember, *model.AppError) { func (a *App) GetChannelMember(channelId string, userId string) (*model.ChannelMember, *model.AppError) {
return a.Srv().Store.Channel().GetMember(channelId, userId) channelMember, err := a.Srv().Store.Channel().GetMember(channelId, userId)
if err != nil {
var nfErr *store.ErrNotFound
switch {
case errors.As(err, &nfErr):
return nil, model.NewAppError("GetChannelMember", MISSING_CHANNEL_MEMBER_ERROR, nil, nfErr.Error(), http.StatusNotFound)
default:
return nil, model.NewAppError("GetChannelMember", "app.channel.get_member.app_error", nil, err.Error(), http.StatusInternalServerError)
}
}
return channelMember, nil
} }
func (a *App) GetChannelMembersPage(channelId string, page, perPage int) (*model.ChannelMembers, *model.AppError) { func (a *App) GetChannelMembersPage(channelId string, page, perPage int) (*model.ChannelMembers, *model.AppError) {
return a.Srv().Store.Channel().GetMembers(channelId, page*perPage, perPage) channelMembers, err := a.Srv().Store.Channel().GetMembers(channelId, page*perPage, perPage)
if err != nil {
return nil, model.NewAppError("GetChannelMembersPage", "app.channel.get_members.app_error", nil, err.Error(), http.StatusInternalServerError)
}
return channelMembers, nil
} }
func (a *App) GetChannelMembersTimezones(channelId string) ([]string, *model.AppError) { func (a *App) GetChannelMembersTimezones(channelId string) ([]string, *model.AppError) {
membersTimezones, err := a.Srv().Store.Channel().GetChannelMembersTimezones(channelId) membersTimezones, err := a.Srv().Store.Channel().GetChannelMembersTimezones(channelId)
if err != nil { if err != nil {
return nil, err return nil, model.NewAppError("GetChannelMembersTimezones", "app.channel.get_members.app_error", nil, err.Error(), http.StatusInternalServerError)
} }
var timezones []string var timezones []string
@@ -1694,13 +1781,18 @@ func (a *App) GetChannelMembersByIds(channelId string, userIds []string) (*model
} }
func (a *App) GetChannelMembersForUser(teamId string, userId string) (*model.ChannelMembers, *model.AppError) { func (a *App) GetChannelMembersForUser(teamId string, userId string) (*model.ChannelMembers, *model.AppError) {
return a.Srv().Store.Channel().GetMembersForUser(teamId, userId) channelMembers, err := a.Srv().Store.Channel().GetMembersForUser(teamId, userId)
if err != nil {
return nil, model.NewAppError("GetChannelMembersForUser", "app.channel.get_members.app_error", nil, err.Error(), http.StatusInternalServerError)
}
return channelMembers, nil
} }
func (a *App) GetChannelMembersForUserWithPagination(teamId, userId string, page, perPage int) ([]*model.ChannelMember, *model.AppError) { func (a *App) GetChannelMembersForUserWithPagination(teamId, userId string, page, perPage int) ([]*model.ChannelMember, *model.AppError) {
m, err := a.Srv().Store.Channel().GetMembersForUserWithPagination(teamId, userId, page, perPage) m, err := a.Srv().Store.Channel().GetMembersForUserWithPagination(teamId, userId, page, perPage)
if err != nil { if err != nil {
return nil, err return nil, model.NewAppError("GetChannelMembersForUserWithPagination", "app.channel.get_members.app_error", nil, err.Error(), http.StatusInternalServerError)
} }
members := make([]*model.ChannelMember, 0) members := make([]*model.ChannelMember, 0)
@@ -1714,15 +1806,30 @@ func (a *App) GetChannelMembersForUserWithPagination(teamId, userId string, page
} }
func (a *App) GetChannelMemberCount(channelId string) (int64, *model.AppError) { func (a *App) GetChannelMemberCount(channelId string) (int64, *model.AppError) {
return a.Srv().Store.Channel().GetMemberCount(channelId, true) count, err := a.Srv().Store.Channel().GetMemberCount(channelId, true)
if err != nil {
return 0, model.NewAppError("GetChannelMemberCount", "app.channel.get_member_count.app_error", nil, err.Error(), http.StatusInternalServerError)
}
return count, nil
} }
func (a *App) GetChannelGuestCount(channelId string) (int64, *model.AppError) { func (a *App) GetChannelGuestCount(channelId string) (int64, *model.AppError) {
return a.Srv().Store.Channel().GetGuestCount(channelId, true) count, err := a.Srv().Store.Channel().GetGuestCount(channelId, true)
if err != nil {
return 0, model.NewAppError("SqlChannelStore.GetGuestCount", "app.channel.get_member_count.app_error", nil, err.Error(), http.StatusInternalServerError)
}
return count, nil
} }
func (a *App) GetChannelPinnedPostCount(channelId string) (int64, *model.AppError) { func (a *App) GetChannelPinnedPostCount(channelId string) (int64, *model.AppError) {
return a.Srv().Store.Channel().GetPinnedPostCount(channelId, true) count, err := a.Srv().Store.Channel().GetPinnedPostCount(channelId, true)
if err != nil {
return 0, model.NewAppError("GetChannelPinnedPostCount", "app.channel.get_pinnedpost_count.app_error", nil, err.Error(), http.StatusInternalServerError)
}
return count, nil
} }
func (a *App) GetChannelCounts(teamId string, userId string) (*model.ChannelCounts, *model.AppError) { func (a *App) GetChannelCounts(teamId string, userId string) (*model.ChannelCounts, *model.AppError) {
@@ -1757,7 +1864,7 @@ func (a *App) JoinChannel(channel *model.Channel, userId string) *model.AppError
}() }()
go func() { go func() {
member, err := a.Srv().Store.Channel().GetMember(channel.Id, userId) member, err := a.Srv().Store.Channel().GetMember(channel.Id, userId)
memberChan <- store.StoreResult{Data: member, Err: err} memberChan <- store.StoreResult{Data: member, NErr: err}
close(memberChan) close(memberChan)
}() }()
@@ -1767,7 +1874,7 @@ func (a *App) JoinChannel(channel *model.Channel, userId string) *model.AppError
} }
mresult := <-memberChan mresult := <-memberChan
if mresult.Err == nil && mresult.Data != nil { if mresult.NErr == nil && mresult.Data != nil {
// user is already in the channel // user is already in the channel
return nil return nil
} }
@@ -1862,7 +1969,7 @@ func (a *App) LeaveChannel(channelId string, userId string) *model.AppError {
mcc := make(chan store.StoreResult, 1) mcc := make(chan store.StoreResult, 1)
go func() { go func() {
count, err := a.Srv().Store.Channel().GetMemberCount(channelId, false) count, err := a.Srv().Store.Channel().GetMemberCount(channelId, false)
mcc <- store.StoreResult{Data: count, Err: err} mcc <- store.StoreResult{Data: count, NErr: err}
close(mcc) close(mcc)
}() }()
@@ -1881,8 +1988,8 @@ func (a *App) LeaveChannel(channelId string, userId string) *model.AppError {
} }
} }
ccresult := <-mcc ccresult := <-mcc
if ccresult.Err != nil { if ccresult.NErr != nil {
return ccresult.Err return model.NewAppError("LeaveChannel", "app.channel.get_member_count.app_error", nil, ccresult.NErr.Error(), http.StatusInternalServerError)
} }
channel := cresult.Data.(*model.Channel) channel := cresult.Data.(*model.Channel)
@@ -2038,7 +2145,7 @@ func (a *App) removeUserFromChannel(userIdToRemove string, removerUserId string,
} }
if err := a.Srv().Store.Channel().RemoveMember(channel.Id, userIdToRemove); err != nil { if err := a.Srv().Store.Channel().RemoveMember(channel.Id, userIdToRemove); err != nil {
return err return model.NewAppError("removeUserFromChannel", "app.channel.remove_member.app_error", nil, err.Error(), http.StatusInternalServerError)
} }
if err := a.Srv().Store.ChannelMemberHistory().LogLeaveEvent(userIdToRemove, channel.Id, model.GetMillis()); err != nil { if err := a.Srv().Store.ChannelMemberHistory().LogLeaveEvent(userIdToRemove, channel.Id, model.GetMillis()); err != nil {
return model.NewAppError("removeUserFromChannel", "app.channel_member_history.log_leave_event.internal_error", nil, err.Error(), http.StatusInternalServerError) return model.NewAppError("removeUserFromChannel", "app.channel_member_history.log_leave_event.internal_error", nil, err.Error(), http.StatusInternalServerError)
@@ -2158,7 +2265,13 @@ func (a *App) SetActiveChannel(userId string, channelId string) *model.AppError
func (a *App) UpdateChannelLastViewedAt(channelIds []string, userId string) *model.AppError { func (a *App) UpdateChannelLastViewedAt(channelIds []string, userId string) *model.AppError {
if _, err := a.Srv().Store.Channel().UpdateLastViewedAt(channelIds, userId); err != nil { if _, err := a.Srv().Store.Channel().UpdateLastViewedAt(channelIds, userId); err != nil {
return err var invErr *store.ErrInvalidInput
switch {
case errors.As(err, &invErr):
return model.NewAppError("UpdateChannelLastViewedAt", "app.channel.update_last_viewed_at.app_error", nil, invErr.Error(), http.StatusBadRequest)
default:
return model.NewAppError("UpdateChannelLastViewedAt", "app.channel.update_last_viewed_at.app_error", nil, err.Error(), http.StatusInternalServerError)
}
} }
if *a.Config().ServiceSettings.EnableChannelViewedMessages { if *a.Config().ServiceSettings.EnableChannelViewedMessages {
@@ -2189,9 +2302,9 @@ func (a *App) MarkChannelAsUnreadFromPost(postID string, userID string) (*model.
return nil, err return nil, err
} }
channelUnread, updateErr := a.Srv().Store.Channel().UpdateLastViewedAtPost(post, userID, unreadMentions) channelUnread, nErr := a.Srv().Store.Channel().UpdateLastViewedAtPost(post, userID, unreadMentions)
if updateErr != nil { if nErr != nil {
return channelUnread, updateErr return channelUnread, model.NewAppError("MarkChannelAsUnreadFromPost", "app.channel.update_last_viewed_at_post.app_error", nil, nErr.Error(), http.StatusInternalServerError)
} }
message := model.NewWebSocketEvent(model.WEBSOCKET_EVENT_POST_UNREAD, channelUnread.TeamId, channelUnread.ChannelId, channelUnread.UserId, nil) message := model.NewWebSocketEvent(model.WEBSOCKET_EVENT_POST_UNREAD, channelUnread.TeamId, channelUnread.ChannelId, channelUnread.UserId, nil)
@@ -2327,7 +2440,13 @@ func (a *App) MarkChannelsAsViewed(channelIds []string, userId string, currentSe
} }
times, err := a.Srv().Store.Channel().UpdateLastViewedAt(channelIds, userId) times, err := a.Srv().Store.Channel().UpdateLastViewedAt(channelIds, userId)
if err != nil { if err != nil {
return nil, err var invErr *store.ErrInvalidInput
switch {
case errors.As(err, &invErr):
return nil, model.NewAppError("MarkChannelsAsViewed", "app.channel.update_last_viewed_at.app_error", nil, invErr.Error(), http.StatusBadRequest)
default:
return nil, model.NewAppError("MarkChannelsAsViewed", "app.channel.update_last_viewed_at.app_error", nil, err.Error(), http.StatusInternalServerError)
}
} }
if *a.Config().ServiceSettings.EnableChannelViewedMessages { if *a.Config().ServiceSettings.EnableChannelViewedMessages {
@@ -2371,7 +2490,7 @@ func (a *App) PermanentDeleteChannel(channel *model.Channel) *model.AppError {
} }
if err := a.Srv().Store.Channel().PermanentDeleteMembersByChannel(channel.Id); err != nil { if err := a.Srv().Store.Channel().PermanentDeleteMembersByChannel(channel.Id); err != nil {
return err return model.NewAppError("PermanentDeleteChannel", "app.channel.remove_member.app_error", nil, err.Error(), http.StatusInternalServerError)
} }
if err := a.Srv().Store.Webhook().PermanentDeleteIncomingByChannel(channel.Id); err != nil { if err := a.Srv().Store.Webhook().PermanentDeleteIncomingByChannel(channel.Id); err != nil {
@@ -2563,7 +2682,12 @@ func (a *App) RemoveUsersFromChannelNotMemberOfTeam(remover *model.User, channel
} }
func (a *App) GetPinnedPosts(channelId string) (*model.PostList, *model.AppError) { func (a *App) GetPinnedPosts(channelId string) (*model.PostList, *model.AppError) {
return a.Srv().Store.Channel().GetPinnedPosts(channelId) posts, err := a.Srv().Store.Channel().GetPinnedPosts(channelId)
if err != nil {
return nil, model.NewAppError("GetPinnedPosts", "app.channel.pinned_posts.app_error", nil, err.Error(), http.StatusInternalServerError)
}
return posts, nil
} }
func (a *App) ToggleMuteChannel(channelId string, userId string) *model.ChannelMember { func (a *App) ToggleMuteChannel(channelId string, userId string) *model.ChannelMember {

6
app/constants.go Обычный файл
Просмотреть файл

@@ -0,0 +1,6 @@
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
package app
const MISSING_CHANNEL_MEMBER_ERROR = "app.channel.get_member.missing.app_error"

Просмотреть файл

@@ -822,9 +822,9 @@ func (a *App) importUserChannels(user *model.User, team *model.Team, teamMember
isGuestByChannelId := map[string]bool{} isGuestByChannelId := map[string]bool{}
isUserByChannelId := map[string]bool{} isUserByChannelId := map[string]bool{}
isAdminByChannelId := map[string]bool{} isAdminByChannelId := map[string]bool{}
existingMemberships, err := a.Srv().Store.Channel().GetMembersForUser(team.Id, user.Id) existingMemberships, nErr := a.Srv().Store.Channel().GetMembersForUser(team.Id, user.Id)
if err != nil { if nErr != nil {
return err return model.NewAppError("importUserChannels", "app.channel.get_members.app_error", nil, nErr.Error(), http.StatusInternalServerError)
} }
existingMembershipsByChannelId := map[string]model.ChannelMember{} existingMembershipsByChannelId := map[string]model.ChannelMember{}
for _, channelMembership := range *existingMemberships { for _, channelMembership := range *existingMemberships {
@@ -913,16 +913,37 @@ func (a *App) importUserChannels(user *model.User, team *model.Team, teamMember
} }
} }
oldMembers, err := a.Srv().Store.Channel().UpdateMultipleMembers(oldChannelMembers) oldMembers, nErr := a.Srv().Store.Channel().UpdateMultipleMembers(oldChannelMembers)
if err != nil { if nErr != nil {
return err var nfErr *store.ErrNotFound
var appErr *model.AppError
switch {
case errors.As(nErr, &appErr):
return appErr
case errors.As(nErr, &nfErr):
return model.NewAppError("importUserChannels", MISSING_CHANNEL_MEMBER_ERROR, nil, nfErr.Error(), http.StatusNotFound)
default:
return model.NewAppError("importUserChannels", "app.channel.get_member.app_error", nil, nErr.Error(), http.StatusInternalServerError)
}
} }
newMembers := []*model.ChannelMember{} newMembers := []*model.ChannelMember{}
if len(newChannelMembers) > 0 { if len(newChannelMembers) > 0 {
newMembers, err = a.Srv().Store.Channel().SaveMultipleMembers(newChannelMembers) newMembers, nErr = a.Srv().Store.Channel().SaveMultipleMembers(newChannelMembers)
if err != nil { if nErr != nil {
return err var cErr *store.ErrConflict
var appErr *model.AppError
switch {
case errors.As(nErr, &cErr):
switch cErr.Resource {
case "ChannelMembers":
return model.NewAppError("importUserChannels", "app.channel.save_member.exists.app_error", nil, cErr.Error(), http.StatusBadRequest)
}
case errors.As(nErr, &appErr):
return appErr
default:
return model.NewAppError("importUserChannels", "app.channel.create_direct_channel.internal_error", nil, nErr.Error(), http.StatusInternalServerError)
}
} }
} }

Просмотреть файл

@@ -604,8 +604,8 @@ func TestImportImportChannel(t *testing.T) {
require.Nil(t, err, "Failed to get team from database.") require.Nil(t, err, "Failed to get team from database.")
// Check how many channels are in the database. // Check how many channels are in the database.
channelCount, err := th.App.Srv().Store.Channel().AnalyticsTypeCount("", model.CHANNEL_OPEN) channelCount, nErr := th.App.Srv().Store.Channel().AnalyticsTypeCount("", model.CHANNEL_OPEN)
require.Nil(t, err, "Failed to get team count.") require.Nil(t, nErr, "Failed to get team count.")
// Do an invalid channel in dry-run mode. // Do an invalid channel in dry-run mode.
data := ChannelImportData{ data := ChannelImportData{
@@ -3043,8 +3043,8 @@ func TestImportImportDirectChannel(t *testing.T) {
th.BasicUser2.Id, th.BasicUser2.Id,
user3.Id, user3.Id,
} }
channel, err = th.App.createGroupChannel(userIds, th.BasicUser.Id) channel, appErr := th.App.createGroupChannel(userIds, th.BasicUser.Id)
require.Equal(t, err.Id, store.CHANNEL_EXISTS_ERROR) require.Equal(t, appErr.Id, store.CHANNEL_EXISTS_ERROR)
require.Equal(t, channel.Header, *data.Header) require.Equal(t, channel.Header, *data.Header)
// Import a channel with some favorites. // Import a channel with some favorites.

Просмотреть файл

@@ -4,6 +4,7 @@
package app package app
import ( import (
"net/http"
"sort" "sort"
"strings" "strings"
"unicode" "unicode"
@@ -32,7 +33,7 @@ func (a *App) SendNotifications(post *model.Post, team *model.Team, channel *mod
cmnchan := make(chan store.StoreResult, 1) cmnchan := make(chan store.StoreResult, 1)
go func() { go func() {
props, err := a.Srv().Store.Channel().GetAllChannelMembersNotifyPropsForChannel(channel.Id, true) props, err := a.Srv().Store.Channel().GetAllChannelMembersNotifyPropsForChannel(channel.Id, true)
cmnchan <- store.StoreResult{Data: props, Err: err} cmnchan <- store.StoreResult{Data: props, NErr: err}
close(cmnchan) close(cmnchan)
}() }()
@@ -63,8 +64,8 @@ func (a *App) SendNotifications(post *model.Post, team *model.Team, channel *mod
profileMap := result.Data.(map[string]*model.User) profileMap := result.Data.(map[string]*model.User)
result = <-cmnchan result = <-cmnchan
if result.Err != nil { if result.NErr != nil {
return nil, result.Err return nil, result.NErr
} }
channelMemberNotifyPropsMap := result.Data.(map[string]model.StringMap) channelMemberNotifyPropsMap := result.Data.(map[string]model.StringMap)
@@ -164,7 +165,13 @@ func (a *App) SendNotifications(post *model.Post, team *model.Team, channel *mod
umc := make(chan *model.AppError, 1) umc := make(chan *model.AppError, 1)
go func(userId string) { go func(userId string) {
umc <- a.Srv().Store.Channel().IncrementMentionCount(post.ChannelId, userId) nErr := a.Srv().Store.Channel().IncrementMentionCount(post.ChannelId, userId)
if nErr != nil {
umc <- model.NewAppError("SendNotifications", "app.channel.increment_mention_count.app_error", nil, nErr.Error(), http.StatusInternalServerError)
} else {
umc <- nil
}
close(umc) close(umc)
}(id) }(id)
updateMentionChans = append(updateMentionChans, umc) updateMentionChans = append(updateMentionChans, umc)

Просмотреть файл

@@ -1292,12 +1292,12 @@ func (a *App) countMentionsFromPost(user *model.User, post *model.Post) (int, *m
if channel.Type == model.CHANNEL_DIRECT { if channel.Type == model.CHANNEL_DIRECT {
// In a DM channel, every post made by the other user is a mention // In a DM channel, every post made by the other user is a mention
count, countErr := a.Srv().Store.Channel().CountPostsAfter(post.ChannelId, post.CreateAt-1, channel.GetOtherUserIdForDM(user.Id)) count, nErr := a.Srv().Store.Channel().CountPostsAfter(post.ChannelId, post.CreateAt-1, channel.GetOtherUserIdForDM(user.Id))
if countErr != nil { if nErr != nil {
return 0, countErr return 0, model.NewAppError("countMentionsFromPost", "app.channel.count_posts_since.app_error", nil, nErr.Error(), http.StatusInternalServerError)
} }
return count, countErr return count, nil
} }
channelMember, err := a.GetChannelMember(channel.Id, user.Id) channelMember, err := a.GetChannelMember(channel.Id, user.Id)

Просмотреть файл

@@ -893,15 +893,15 @@ func TestCreatePostAsUser(t *testing.T) {
UserId: bot.UserId, UserId: bot.UserId,
} }
channelMemberBefore, appErr := th.App.Srv().Store.Channel().GetMember(th.BasicChannel.Id, th.BasicUser.Id) channelMemberBefore, nErr := th.App.Srv().Store.Channel().GetMember(th.BasicChannel.Id, th.BasicUser.Id)
require.Nil(t, appErr) require.Nil(t, nErr)
time.Sleep(1 * time.Millisecond) time.Sleep(1 * time.Millisecond)
_, appErr = th.App.CreatePostAsUser(post, "", true) _, appErr = th.App.CreatePostAsUser(post, "", true)
require.Nil(t, appErr) require.Nil(t, appErr)
channelMemberAfter, appErr := th.App.Srv().Store.Channel().GetMember(th.BasicChannel.Id, th.BasicUser.Id) channelMemberAfter, nErr := th.App.Srv().Store.Channel().GetMember(th.BasicChannel.Id, th.BasicUser.Id)
require.Nil(t, appErr) require.Nil(t, nErr)
require.Equal(t, channelMemberAfter.LastViewedAt, channelMemberBefore.LastViewedAt) require.Equal(t, channelMemberAfter.LastViewedAt, channelMemberBefore.LastViewedAt)
}) })

Просмотреть файл

@@ -82,7 +82,7 @@ func TestLeaveProviderDoCommand(t *testing.T) {
_, err = th.App.GetChannelMember(publicChannel.Id, th.BasicUser.Id) _, err = th.App.GetChannelMember(publicChannel.Id, th.BasicUser.Id)
assert.NotNil(t, err) assert.NotNil(t, err)
assert.NotNil(t, err.Id, "store.sql_channel.get_member.missing.app_error") assert.NotNil(t, err.Id, "app.channel.get_member.missing.app_error")
}) })
t.Run("Leave a private channel", func(t *testing.T) { t.Run("Leave a private channel", func(t *testing.T) {
@@ -124,7 +124,7 @@ func TestLeaveProviderDoCommand(t *testing.T) {
_, err = th.App.GetChannelMember(defaultChannel.Id, guest.Id) _, err = th.App.GetChannelMember(defaultChannel.Id, guest.Id)
assert.NotNil(t, err) assert.NotNil(t, err)
assert.NotNil(t, err.Id, "store.sql_channel.get_member.missing.app_error") assert.NotNil(t, err.Id, "app.channel.get_member.missing.app_error")
}) })
t.Run("Should redirect to the team if is the last channel", func(t *testing.T) { t.Run("Should redirect to the team if is the last channel", func(t *testing.T) {
@@ -142,6 +142,6 @@ func TestLeaveProviderDoCommand(t *testing.T) {
_, err = th.App.GetChannelMember(publicChannel.Id, guest.Id) _, err = th.App.GetChannelMember(publicChannel.Id, guest.Id)
assert.NotNil(t, err) assert.NotNil(t, err)
assert.NotNil(t, err.Id, "store.sql_channel.get_member.missing.app_error") assert.NotNil(t, err.Id, "app.channel.get_member.missing.app_error")
}) })
} }

Просмотреть файл

@@ -142,7 +142,7 @@ func TestCreateDefaultMemberships(t *testing.T) {
} }
_, err = th.App.GetChannelMember(experimentsChannel.Id, scientist1.Id) _, err = th.App.GetChannelMember(experimentsChannel.Id, scientist1.Id)
if err.Id != "store.sql_channel.get_member.missing.app_error" { if err.Id != "app.channel.get_member.missing.app_error" {
t.Errorf("wrong error: %s", err.Id) t.Errorf("wrong error: %s", err.Id)
} }
@@ -184,7 +184,7 @@ func TestCreateDefaultMemberships(t *testing.T) {
} }
_, err = th.App.GetChannelMember(experimentsChannel.Id, scientist1.Id) _, err = th.App.GetChannelMember(experimentsChannel.Id, scientist1.Id)
if err.Id != "store.sql_channel.get_member.missing.app_error" { if err.Id != "app.channel.get_member.missing.app_error" {
t.Errorf("wrong error: %s", err.Id) t.Errorf("wrong error: %s", err.Id)
} }

Просмотреть файл

@@ -1194,8 +1194,8 @@ func (a *App) LeaveTeam(team *model.Team, user *model.User, requestorId string)
for _, channel := range *channelList { for _, channel := range *channelList {
if !channel.IsGroupOrDirect() { if !channel.IsGroupOrDirect() {
a.invalidateCacheForChannelMembers(channel.Id) a.invalidateCacheForChannelMembers(channel.Id)
if err = a.Srv().Store.Channel().RemoveMember(channel.Id, user.Id); err != nil { if nErr = a.Srv().Store.Channel().RemoveMember(channel.Id, user.Id); nErr != nil {
return err return model.NewAppError("LeaveTeam", "app.channel.remove_member.app_error", nil, nErr.Error(), http.StatusInternalServerError)
} }
} }
} }

Просмотреть файл

@@ -1514,7 +1514,7 @@ func (a *App) PermanentDeleteUser(user *model.User) *model.AppError {
} }
if err := a.Srv().Store.Channel().PermanentDeleteMembersByUser(user.Id); err != nil { if err := a.Srv().Store.Channel().PermanentDeleteMembersByUser(user.Id); err != nil {
return err return model.NewAppError("PermanentDeleteUser", "app.channel.permanent_delete_members_by_user.app_error", nil, err.Error(), http.StatusInternalServerError)
} }
if err := a.Srv().Store.Group().PermanentDeleteMembersByUser(user.Id); err != nil { if err := a.Srv().Store.Group().PermanentDeleteMembersByUser(user.Id); err != nil {
@@ -2028,7 +2028,7 @@ func (a *App) GetViewUsersRestrictions(userId string) (*model.ViewUsersRestricti
userChannelMembers, err := a.Srv().Store.Channel().GetAllChannelMembersForUser(userId, true, true) userChannelMembers, err := a.Srv().Store.Channel().GetAllChannelMembersForUser(userId, true, true)
if err != nil { if err != nil {
return nil, err return nil, model.NewAppError("GetViewUsersRestrictions", "app.channel.get_channels.get.app_error", nil, err.Error(), http.StatusInternalServerError)
} }
channelIds := []string{} channelIds := []string{}

Просмотреть файл

@@ -3262,6 +3262,14 @@
"id": "app.bot.permenent_delete.bad_id", "id": "app.bot.permenent_delete.bad_id",
"translation": "Unable to delete the bot." "translation": "Unable to delete the bot."
}, },
{
"id": "app.channel.analytics_type_count.app_error",
"translation": "Unable to get channel type counts."
},
{
"id": "app.channel.count_posts_since.app_error",
"translation": "Unable to count messages since given date."
},
{ {
"id": "app.channel.create_channel.internal_error", "id": "app.channel.create_channel.internal_error",
"translation": "Unable to save channel." "translation": "Unable to save channel."
@@ -3342,10 +3350,30 @@
"id": "app.channel.get_for_post.app_error", "id": "app.channel.get_for_post.app_error",
"translation": "Unable to get the channel for the given post." "translation": "Unable to get the channel for the given post."
}, },
{
"id": "app.channel.get_member.app_error",
"translation": "Unable to get the channel member."
},
{
"id": "app.channel.get_member.missing.app_error",
"translation": "No channel member found for that user ID and channel ID."
},
{
"id": "app.channel.get_member_count.app_error",
"translation": "Unable to get the channel member count."
},
{
"id": "app.channel.get_members.app_error",
"translation": "Unable to get the channel members."
},
{ {
"id": "app.channel.get_more_channels.get.app_error", "id": "app.channel.get_more_channels.get.app_error",
"translation": "Unable to get the channels." "translation": "Unable to get the channels."
}, },
{
"id": "app.channel.get_pinnedpost_count.app_error",
"translation": "Unable to get the channel pinned post count."
},
{ {
"id": "app.channel.get_private_channels.get.app_error", "id": "app.channel.get_private_channels.get.app_error",
"translation": "Unable to get private channels." "translation": "Unable to get private channels."
@@ -3354,6 +3382,10 @@
"id": "app.channel.get_public_channels.get.app_error", "id": "app.channel.get_public_channels.get.app_error",
"translation": "Unable to get public channels." "translation": "Unable to get public channels."
}, },
{
"id": "app.channel.increment_mention_count.app_error",
"translation": "Unable to increment the mention count."
},
{ {
"id": "app.channel.move_channel.members_do_not_match.error", "id": "app.channel.move_channel.members_do_not_match.error",
"translation": "Unable to move a channel unless all its members are already members of the destination team." "translation": "Unable to move a channel unless all its members are already members of the destination team."
@@ -3362,6 +3394,14 @@
"id": "app.channel.permanent_delete.app_error", "id": "app.channel.permanent_delete.app_error",
"translation": "Unable to delete the channel." "translation": "Unable to delete the channel."
}, },
{
"id": "app.channel.permanent_delete_members_by_user.app_error",
"translation": "Unable to remove the channel member."
},
{
"id": "app.channel.pinned_posts.app_error",
"translation": "Unable to find the pinned posts."
},
{ {
"id": "app.channel.post_update_channel_purpose_message.post.error", "id": "app.channel.post_update_channel_purpose_message.post.error",
"translation": "Failed to post channel purpose message" "translation": "Failed to post channel purpose message"
@@ -3382,10 +3422,18 @@
"id": "app.channel.post_update_channel_purpose_message.updated_to", "id": "app.channel.post_update_channel_purpose_message.updated_to",
"translation": "%s updated the channel purpose to: %s" "translation": "%s updated the channel purpose to: %s"
}, },
{
"id": "app.channel.remove_member.app_error",
"translation": "Unable to remove the channel member."
},
{ {
"id": "app.channel.restore.app_error", "id": "app.channel.restore.app_error",
"translation": "Unable to restore the channel." "translation": "Unable to restore the channel."
}, },
{
"id": "app.channel.save_member.exists.app_error",
"translation": ""
},
{ {
"id": "app.channel.sidebar_categories.app_error", "id": "app.channel.sidebar_categories.app_error",
"translation": "Failed to insert record to database." "translation": "Failed to insert record to database."
@@ -3398,6 +3446,14 @@
"id": "app.channel.update_channel.internal_error", "id": "app.channel.update_channel.internal_error",
"translation": "Unable to update channel." "translation": "Unable to update channel."
}, },
{
"id": "app.channel.update_last_viewed_at.app_error",
"translation": "Unable to update the last viewed at time."
},
{
"id": "app.channel.update_last_viewed_at_post.app_error",
"translation": "Unable to mark channel as unread."
},
{ {
"id": "app.channel_member_history.log_join_event.internal_error", "id": "app.channel_member_history.log_join_event.internal_error",
"translation": "Failed to record channel member history." "translation": "Failed to record channel member history."
@@ -7234,10 +7290,6 @@
"id": "store.sql_channel.analytics_deleted_type_count.app_error", "id": "store.sql_channel.analytics_deleted_type_count.app_error",
"translation": "Unable to get deleted channel type counts." "translation": "Unable to get deleted channel type counts."
}, },
{
"id": "store.sql_channel.analytics_type_count.app_error",
"translation": "Unable to get channel type counts."
},
{ {
"id": "store.sql_channel.clear_all_custom_role_assignments.commit_transaction.app_error", "id": "store.sql_channel.clear_all_custom_role_assignments.commit_transaction.app_error",
"translation": "Failed to commit the database transaction." "translation": "Failed to commit the database transaction."
@@ -7254,10 +7306,6 @@
"id": "store.sql_channel.clear_all_custom_role_assignments.update.app_error", "id": "store.sql_channel.clear_all_custom_role_assignments.update.app_error",
"translation": "Failed to update the channel member." "translation": "Failed to update the channel member."
}, },
{
"id": "store.sql_channel.count_posts_since.app_error",
"translation": "Unable to count messages since given date."
},
{ {
"id": "store.sql_channel.get.existing.app_error", "id": "store.sql_channel.get.existing.app_error",
"translation": "Unable to find the existing channel." "translation": "Unable to find the existing channel."
@@ -7282,42 +7330,14 @@
"id": "store.sql_channel.get_channels_batch_for_indexing.get.app_error", "id": "store.sql_channel.get_channels_batch_for_indexing.get.app_error",
"translation": "Unable to get the channels batch for indexing." "translation": "Unable to get the channels batch for indexing."
}, },
{
"id": "store.sql_channel.get_member.app_error",
"translation": "Unable to get the channel member."
},
{
"id": "store.sql_channel.get_member.missing.app_error",
"translation": "No channel member found for that user ID and channel ID."
},
{
"id": "store.sql_channel.get_member_count.app_error",
"translation": "Unable to get the channel member count."
},
{
"id": "store.sql_channel.get_member_for_post.app_error",
"translation": "Unable to get the channel member for the given post."
},
{
"id": "store.sql_channel.get_members.app_error",
"translation": "Unable to get the channel members."
},
{ {
"id": "store.sql_channel.get_members_by_ids.app_error", "id": "store.sql_channel.get_members_by_ids.app_error",
"translation": "Unable to get the channel members." "translation": "Unable to get the channel members."
}, },
{
"id": "store.sql_channel.get_pinnedpost_count.app_error",
"translation": "Unable to get the channel pinned post count."
},
{ {
"id": "store.sql_channel.get_unread.app_error", "id": "store.sql_channel.get_unread.app_error",
"translation": "Unable to get the channel unread messages." "translation": "Unable to get the channel unread messages."
}, },
{
"id": "store.sql_channel.increment_mention_count.app_error",
"translation": "Unable to increment the mention count."
},
{ {
"id": "store.sql_channel.migrate_channel_members.commit_transaction.app_error", "id": "store.sql_channel.migrate_channel_members.commit_transaction.app_error",
"translation": "Failed to commit the database transaction." "translation": "Failed to commit the database transaction."
@@ -7334,22 +7354,10 @@
"id": "store.sql_channel.migrate_channel_members.update.app_error", "id": "store.sql_channel.migrate_channel_members.update.app_error",
"translation": "Failed to update the channel member." "translation": "Failed to update the channel member."
}, },
{
"id": "store.sql_channel.permanent_delete_members_by_user.app_error",
"translation": "Unable to remove the channel member."
},
{
"id": "store.sql_channel.pinned_posts.app_error",
"translation": "Unable to find the pinned posts."
},
{ {
"id": "store.sql_channel.remove_all_deactivated_members.app_error", "id": "store.sql_channel.remove_all_deactivated_members.app_error",
"translation": "We could not remove the deactivated users from the channel." "translation": "We could not remove the deactivated users from the channel."
}, },
{
"id": "store.sql_channel.remove_member.app_error",
"translation": "Unable to remove the channel member."
},
{ {
"id": "store.sql_channel.reset_all_channel_schemes.app_error", "id": "store.sql_channel.reset_all_channel_schemes.app_error",
"translation": "We could not reset the channel schemes." "translation": "We could not reset the channel schemes."
@@ -7386,18 +7394,6 @@
"id": "store.sql_channel.save_direct_channel.not_direct.app_error", "id": "store.sql_channel.save_direct_channel.not_direct.app_error",
"translation": "Not a direct channel attempted to be created with SaveDirectChannel." "translation": "Not a direct channel attempted to be created with SaveDirectChannel."
}, },
{
"id": "store.sql_channel.save_member.commit_transaction.app_error",
"translation": "Unable to commit transaction."
},
{
"id": "store.sql_channel.save_member.exists.app_error",
"translation": "A channel member with that ID already exists."
},
{
"id": "store.sql_channel.save_member.open_transaction.app_error",
"translation": "Unable to open transaction."
},
{ {
"id": "store.sql_channel.search.app_error", "id": "store.sql_channel.search.app_error",
"translation": "We encountered an error searching channels." "translation": "We encountered an error searching channels."
@@ -7422,18 +7418,6 @@
"id": "store.sql_channel.sidebar_categories.open_transaction.app_error", "id": "store.sql_channel.sidebar_categories.open_transaction.app_error",
"translation": "Failed to open the database transaction." "translation": "Failed to open the database transaction."
}, },
{
"id": "store.sql_channel.update_last_viewed_at.app_error",
"translation": "Unable to update the last viewed at time."
},
{
"id": "store.sql_channel.update_last_viewed_at_post.app_error",
"translation": "Unable to mark channel as unread."
},
{
"id": "store.sql_channel.update_member.app_error",
"translation": "We encountered an error updating the channel member."
},
{ {
"id": "store.sql_channel.user_belongs_to_channels.app_error", "id": "store.sql_channel.user_belongs_to_channels.app_error",
"translation": "Unable to determine if the user belongs to a list of channels." "translation": "Unable to determine if the user belongs to a list of channels."

Просмотреть файл

@@ -4,8 +4,7 @@
package store package store
const ( const (
MISSING_CHANNEL_MEMBER_ERROR = "store.sql_channel.get_member.missing.app_error" CHANNEL_EXISTS_ERROR = "store.sql_channel.save_channel.exists.app_error"
CHANNEL_EXISTS_ERROR = "store.sql_channel.save_channel.exists.app_error"
MISSING_ACCOUNT_ERROR = "store.sql_user.missing_account.const" MISSING_ACCOUNT_ERROR = "store.sql_user.missing_account.const"
MISSING_AUTH_ACCOUNT_ERROR = "store.sql_user.get_by_auth.missing_account.app_error" MISSING_AUTH_ACCOUNT_ERROR = "store.sql_user.get_by_auth.missing_account.app_error"

Просмотреть файл

@@ -87,7 +87,7 @@ func (s LocalCacheChannelStore) InvalidateChannel(channelId string) {
} }
} }
func (s LocalCacheChannelStore) GetMemberCount(channelId string, allowFromCache bool) (int64, *model.AppError) { func (s LocalCacheChannelStore) GetMemberCount(channelId string, allowFromCache bool) (int64, error) {
if allowFromCache { if allowFromCache {
var count int64 var count int64
if err := s.rootStore.doStandardReadCache(s.rootStore.channelMemberCountsCache, channelId, &count); err == nil { if err := s.rootStore.doStandardReadCache(s.rootStore.channelMemberCountsCache, channelId, &count); err == nil {
@@ -103,7 +103,7 @@ func (s LocalCacheChannelStore) GetMemberCount(channelId string, allowFromCache
return count, err return count, err
} }
func (s LocalCacheChannelStore) GetGuestCount(channelId string, allowFromCache bool) (int64, *model.AppError) { func (s LocalCacheChannelStore) GetGuestCount(channelId string, allowFromCache bool) (int64, error) {
if allowFromCache { if allowFromCache {
var count int64 var count int64
if err := s.rootStore.doStandardReadCache(s.rootStore.channelGuestCountCache, channelId, &count); err == nil { if err := s.rootStore.doStandardReadCache(s.rootStore.channelGuestCountCache, channelId, &count); err == nil {
@@ -133,7 +133,7 @@ func (s LocalCacheChannelStore) GetMemberCountFromCache(channelId string) int64
return count return count
} }
func (s LocalCacheChannelStore) GetPinnedPostCount(channelId string, allowFromCache bool) (int64, *model.AppError) { func (s LocalCacheChannelStore) GetPinnedPostCount(channelId string, allowFromCache bool) (int64, error) {
if allowFromCache { if allowFromCache {
var count int64 var count int64
if err := s.rootStore.doStandardReadCache(s.rootStore.channelPinnedPostCountsCache, channelId, &count); err == nil { if err := s.rootStore.doStandardReadCache(s.rootStore.channelPinnedPostCountsCache, channelId, &count); err == nil {
@@ -172,7 +172,7 @@ func (s LocalCacheChannelStore) Get(id string, allowFromCache bool) (*model.Chan
return ch, err return ch, err
} }
func (s LocalCacheChannelStore) SaveMember(member *model.ChannelMember) (*model.ChannelMember, *model.AppError) { func (s LocalCacheChannelStore) SaveMember(member *model.ChannelMember) (*model.ChannelMember, error) {
member, err := s.ChannelStore.SaveMember(member) member, err := s.ChannelStore.SaveMember(member)
if err != nil { if err != nil {
return nil, err return nil, err
@@ -181,7 +181,7 @@ func (s LocalCacheChannelStore) SaveMember(member *model.ChannelMember) (*model.
return member, nil return member, nil
} }
func (s LocalCacheChannelStore) SaveMultipleMembers(members []*model.ChannelMember) ([]*model.ChannelMember, *model.AppError) { func (s LocalCacheChannelStore) SaveMultipleMembers(members []*model.ChannelMember) ([]*model.ChannelMember, error) {
members, err := s.ChannelStore.SaveMultipleMembers(members) members, err := s.ChannelStore.SaveMultipleMembers(members)
if err != nil { if err != nil {
return nil, err return nil, err
@@ -192,7 +192,7 @@ func (s LocalCacheChannelStore) SaveMultipleMembers(members []*model.ChannelMemb
return members, nil return members, nil
} }
func (s LocalCacheChannelStore) UpdateMember(member *model.ChannelMember) (*model.ChannelMember, *model.AppError) { func (s LocalCacheChannelStore) UpdateMember(member *model.ChannelMember) (*model.ChannelMember, error) {
member, err := s.ChannelStore.UpdateMember(member) member, err := s.ChannelStore.UpdateMember(member)
if err != nil { if err != nil {
return nil, err return nil, err
@@ -201,7 +201,7 @@ func (s LocalCacheChannelStore) UpdateMember(member *model.ChannelMember) (*mode
return member, nil return member, nil
} }
func (s LocalCacheChannelStore) UpdateMultipleMembers(members []*model.ChannelMember) ([]*model.ChannelMember, *model.AppError) { func (s LocalCacheChannelStore) UpdateMultipleMembers(members []*model.ChannelMember) ([]*model.ChannelMember, error) {
members, err := s.ChannelStore.UpdateMultipleMembers(members) members, err := s.ChannelStore.UpdateMultipleMembers(members)
if err != nil { if err != nil {
return nil, err return nil, err
@@ -212,7 +212,7 @@ func (s LocalCacheChannelStore) UpdateMultipleMembers(members []*model.ChannelMe
return members, nil return members, nil
} }
func (s LocalCacheChannelStore) RemoveMember(channelId, userId string) *model.AppError { func (s LocalCacheChannelStore) RemoveMember(channelId, userId string) error {
err := s.ChannelStore.RemoveMember(channelId, userId) err := s.ChannelStore.RemoveMember(channelId, userId)
if err != nil { if err != nil {
return err return err
@@ -221,7 +221,7 @@ func (s LocalCacheChannelStore) RemoveMember(channelId, userId string) *model.Ap
return nil return nil
} }
func (s LocalCacheChannelStore) RemoveMembers(channelId string, userIds []string) *model.AppError { func (s LocalCacheChannelStore) RemoveMembers(channelId string, userIds []string) error {
err := s.ChannelStore.RemoveMembers(channelId, userIds) err := s.ChannelStore.RemoveMembers(channelId, userIds)
if err != nil { if err != nil {
return err return err

Просмотреть файл

@@ -492,7 +492,7 @@ func (s *OpenTracingLayerChannelStore) AnalyticsDeletedTypeCount(teamId string,
return result, err return result, err
} }
func (s *OpenTracingLayerChannelStore) AnalyticsTypeCount(teamId string, channelType string) (int64, *model.AppError) { func (s *OpenTracingLayerChannelStore) AnalyticsTypeCount(teamId string, channelType string) (int64, error) {
origCtx := s.Root.Store.Context() origCtx := s.Root.Store.Context()
span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "ChannelStore.AnalyticsTypeCount") span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "ChannelStore.AnalyticsTypeCount")
s.Root.Store.SetContext(newCtx) s.Root.Store.SetContext(newCtx)
@@ -595,7 +595,7 @@ func (s *OpenTracingLayerChannelStore) ClearSidebarOnTeamLeave(userId string, te
return err return err
} }
func (s *OpenTracingLayerChannelStore) CountPostsAfter(channelId string, timestamp int64, userId string) (int, *model.AppError) { func (s *OpenTracingLayerChannelStore) CountPostsAfter(channelId string, timestamp int64, userId string) (int, error) {
origCtx := s.Root.Store.Context() origCtx := s.Root.Store.Context()
span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "ChannelStore.CountPostsAfter") span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "ChannelStore.CountPostsAfter")
s.Root.Store.SetContext(newCtx) s.Root.Store.SetContext(newCtx)
@@ -757,7 +757,7 @@ func (s *OpenTracingLayerChannelStore) GetAll(teamId string) ([]*model.Channel,
return result, err return result, err
} }
func (s *OpenTracingLayerChannelStore) GetAllChannelMembersForUser(userId string, allowFromCache bool, includeDeleted bool) (map[string]string, *model.AppError) { func (s *OpenTracingLayerChannelStore) GetAllChannelMembersForUser(userId string, allowFromCache bool, includeDeleted bool) (map[string]string, error) {
origCtx := s.Root.Store.Context() origCtx := s.Root.Store.Context()
span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "ChannelStore.GetAllChannelMembersForUser") span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "ChannelStore.GetAllChannelMembersForUser")
s.Root.Store.SetContext(newCtx) s.Root.Store.SetContext(newCtx)
@@ -775,7 +775,7 @@ func (s *OpenTracingLayerChannelStore) GetAllChannelMembersForUser(userId string
return result, err return result, err
} }
func (s *OpenTracingLayerChannelStore) GetAllChannelMembersNotifyPropsForChannel(channelId string, allowFromCache bool) (map[string]model.StringMap, *model.AppError) { func (s *OpenTracingLayerChannelStore) GetAllChannelMembersNotifyPropsForChannel(channelId string, allowFromCache bool) (map[string]model.StringMap, error) {
origCtx := s.Root.Store.Context() origCtx := s.Root.Store.Context()
span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "ChannelStore.GetAllChannelMembersNotifyPropsForChannel") span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "ChannelStore.GetAllChannelMembersNotifyPropsForChannel")
s.Root.Store.SetContext(newCtx) s.Root.Store.SetContext(newCtx)
@@ -955,7 +955,7 @@ func (s *OpenTracingLayerChannelStore) GetChannelMembersForExport(userId string,
return result, err return result, err
} }
func (s *OpenTracingLayerChannelStore) GetChannelMembersTimezones(channelId string) ([]model.StringMap, *model.AppError) { func (s *OpenTracingLayerChannelStore) GetChannelMembersTimezones(channelId string) ([]model.StringMap, error) {
origCtx := s.Root.Store.Context() origCtx := s.Root.Store.Context()
span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "ChannelStore.GetChannelMembersTimezones") span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "ChannelStore.GetChannelMembersTimezones")
s.Root.Store.SetContext(newCtx) s.Root.Store.SetContext(newCtx)
@@ -1135,7 +1135,7 @@ func (s *OpenTracingLayerChannelStore) GetFromMaster(id string) (*model.Channel,
return result, err return result, err
} }
func (s *OpenTracingLayerChannelStore) GetGuestCount(channelId string, allowFromCache bool) (int64, *model.AppError) { func (s *OpenTracingLayerChannelStore) GetGuestCount(channelId string, allowFromCache bool) (int64, error) {
origCtx := s.Root.Store.Context() origCtx := s.Root.Store.Context()
span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "ChannelStore.GetGuestCount") span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "ChannelStore.GetGuestCount")
s.Root.Store.SetContext(newCtx) s.Root.Store.SetContext(newCtx)
@@ -1153,7 +1153,7 @@ func (s *OpenTracingLayerChannelStore) GetGuestCount(channelId string, allowFrom
return result, err return result, err
} }
func (s *OpenTracingLayerChannelStore) GetMember(channelId string, userId string) (*model.ChannelMember, *model.AppError) { func (s *OpenTracingLayerChannelStore) GetMember(channelId string, userId string) (*model.ChannelMember, error) {
origCtx := s.Root.Store.Context() origCtx := s.Root.Store.Context()
span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "ChannelStore.GetMember") span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "ChannelStore.GetMember")
s.Root.Store.SetContext(newCtx) s.Root.Store.SetContext(newCtx)
@@ -1171,7 +1171,7 @@ func (s *OpenTracingLayerChannelStore) GetMember(channelId string, userId string
return result, err return result, err
} }
func (s *OpenTracingLayerChannelStore) GetMemberCount(channelId string, allowFromCache bool) (int64, *model.AppError) { func (s *OpenTracingLayerChannelStore) GetMemberCount(channelId string, allowFromCache bool) (int64, error) {
origCtx := s.Root.Store.Context() origCtx := s.Root.Store.Context()
span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "ChannelStore.GetMemberCount") span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "ChannelStore.GetMemberCount")
s.Root.Store.SetContext(newCtx) s.Root.Store.SetContext(newCtx)
@@ -1202,7 +1202,7 @@ func (s *OpenTracingLayerChannelStore) GetMemberCountFromCache(channelId string)
return result return result
} }
func (s *OpenTracingLayerChannelStore) GetMemberCountsByGroup(channelID string, includeTimezones bool) ([]*model.ChannelMemberCountByGroup, *model.AppError) { func (s *OpenTracingLayerChannelStore) GetMemberCountsByGroup(channelID string, includeTimezones bool) ([]*model.ChannelMemberCountByGroup, error) {
origCtx := s.Root.Store.Context() origCtx := s.Root.Store.Context()
span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "ChannelStore.GetMemberCountsByGroup") span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "ChannelStore.GetMemberCountsByGroup")
s.Root.Store.SetContext(newCtx) s.Root.Store.SetContext(newCtx)
@@ -1220,7 +1220,7 @@ func (s *OpenTracingLayerChannelStore) GetMemberCountsByGroup(channelID string,
return result, err return result, err
} }
func (s *OpenTracingLayerChannelStore) GetMemberForPost(postId string, userId string) (*model.ChannelMember, *model.AppError) { func (s *OpenTracingLayerChannelStore) GetMemberForPost(postId string, userId string) (*model.ChannelMember, error) {
origCtx := s.Root.Store.Context() origCtx := s.Root.Store.Context()
span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "ChannelStore.GetMemberForPost") span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "ChannelStore.GetMemberForPost")
s.Root.Store.SetContext(newCtx) s.Root.Store.SetContext(newCtx)
@@ -1238,7 +1238,7 @@ func (s *OpenTracingLayerChannelStore) GetMemberForPost(postId string, userId st
return result, err return result, err
} }
func (s *OpenTracingLayerChannelStore) GetMembers(channelId string, offset int, limit int) (*model.ChannelMembers, *model.AppError) { func (s *OpenTracingLayerChannelStore) GetMembers(channelId string, offset int, limit int) (*model.ChannelMembers, error) {
origCtx := s.Root.Store.Context() origCtx := s.Root.Store.Context()
span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "ChannelStore.GetMembers") span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "ChannelStore.GetMembers")
s.Root.Store.SetContext(newCtx) s.Root.Store.SetContext(newCtx)
@@ -1274,7 +1274,7 @@ func (s *OpenTracingLayerChannelStore) GetMembersByIds(channelId string, userIds
return result, err return result, err
} }
func (s *OpenTracingLayerChannelStore) GetMembersForUser(teamId string, userId string) (*model.ChannelMembers, *model.AppError) { func (s *OpenTracingLayerChannelStore) GetMembersForUser(teamId string, userId string) (*model.ChannelMembers, error) {
origCtx := s.Root.Store.Context() origCtx := s.Root.Store.Context()
span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "ChannelStore.GetMembersForUser") span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "ChannelStore.GetMembersForUser")
s.Root.Store.SetContext(newCtx) s.Root.Store.SetContext(newCtx)
@@ -1292,7 +1292,7 @@ func (s *OpenTracingLayerChannelStore) GetMembersForUser(teamId string, userId s
return result, err return result, err
} }
func (s *OpenTracingLayerChannelStore) GetMembersForUserWithPagination(teamId string, userId string, page int, perPage int) (*model.ChannelMembers, *model.AppError) { func (s *OpenTracingLayerChannelStore) GetMembersForUserWithPagination(teamId string, userId string, page int, perPage int) (*model.ChannelMembers, error) {
origCtx := s.Root.Store.Context() origCtx := s.Root.Store.Context()
span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "ChannelStore.GetMembersForUserWithPagination") span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "ChannelStore.GetMembersForUserWithPagination")
s.Root.Store.SetContext(newCtx) s.Root.Store.SetContext(newCtx)
@@ -1328,7 +1328,7 @@ func (s *OpenTracingLayerChannelStore) GetMoreChannels(teamId string, userId str
return result, err return result, err
} }
func (s *OpenTracingLayerChannelStore) GetPinnedPostCount(channelId string, allowFromCache bool) (int64, *model.AppError) { func (s *OpenTracingLayerChannelStore) GetPinnedPostCount(channelId string, allowFromCache bool) (int64, error) {
origCtx := s.Root.Store.Context() origCtx := s.Root.Store.Context()
span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "ChannelStore.GetPinnedPostCount") span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "ChannelStore.GetPinnedPostCount")
s.Root.Store.SetContext(newCtx) s.Root.Store.SetContext(newCtx)
@@ -1346,7 +1346,7 @@ func (s *OpenTracingLayerChannelStore) GetPinnedPostCount(channelId string, allo
return result, err return result, err
} }
func (s *OpenTracingLayerChannelStore) GetPinnedPosts(channelId string) (*model.PostList, *model.AppError) { func (s *OpenTracingLayerChannelStore) GetPinnedPosts(channelId string) (*model.PostList, error) {
origCtx := s.Root.Store.Context() origCtx := s.Root.Store.Context()
span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "ChannelStore.GetPinnedPosts") span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "ChannelStore.GetPinnedPosts")
s.Root.Store.SetContext(newCtx) s.Root.Store.SetContext(newCtx)
@@ -1508,7 +1508,7 @@ func (s *OpenTracingLayerChannelStore) GroupSyncedChannelCount() (int64, *model.
return result, err return result, err
} }
func (s *OpenTracingLayerChannelStore) IncrementMentionCount(channelId string, userId string) *model.AppError { func (s *OpenTracingLayerChannelStore) IncrementMentionCount(channelId string, userId string) error {
origCtx := s.Root.Store.Context() origCtx := s.Root.Store.Context()
span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "ChannelStore.IncrementMentionCount") span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "ChannelStore.IncrementMentionCount")
s.Root.Store.SetContext(newCtx) s.Root.Store.SetContext(newCtx)
@@ -1702,7 +1702,7 @@ func (s *OpenTracingLayerChannelStore) PermanentDeleteByTeam(teamId string) erro
return err return err
} }
func (s *OpenTracingLayerChannelStore) PermanentDeleteMembersByChannel(channelId string) *model.AppError { func (s *OpenTracingLayerChannelStore) PermanentDeleteMembersByChannel(channelId string) error {
origCtx := s.Root.Store.Context() origCtx := s.Root.Store.Context()
span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "ChannelStore.PermanentDeleteMembersByChannel") span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "ChannelStore.PermanentDeleteMembersByChannel")
s.Root.Store.SetContext(newCtx) s.Root.Store.SetContext(newCtx)
@@ -1720,7 +1720,7 @@ func (s *OpenTracingLayerChannelStore) PermanentDeleteMembersByChannel(channelId
return err return err
} }
func (s *OpenTracingLayerChannelStore) PermanentDeleteMembersByUser(userId string) *model.AppError { func (s *OpenTracingLayerChannelStore) PermanentDeleteMembersByUser(userId string) error {
origCtx := s.Root.Store.Context() origCtx := s.Root.Store.Context()
span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "ChannelStore.PermanentDeleteMembersByUser") span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "ChannelStore.PermanentDeleteMembersByUser")
s.Root.Store.SetContext(newCtx) s.Root.Store.SetContext(newCtx)
@@ -1756,7 +1756,7 @@ func (s *OpenTracingLayerChannelStore) RemoveAllDeactivatedMembers(channelId str
return err return err
} }
func (s *OpenTracingLayerChannelStore) RemoveMember(channelId string, userId string) *model.AppError { func (s *OpenTracingLayerChannelStore) RemoveMember(channelId string, userId string) error {
origCtx := s.Root.Store.Context() origCtx := s.Root.Store.Context()
span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "ChannelStore.RemoveMember") span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "ChannelStore.RemoveMember")
s.Root.Store.SetContext(newCtx) s.Root.Store.SetContext(newCtx)
@@ -1774,7 +1774,7 @@ func (s *OpenTracingLayerChannelStore) RemoveMember(channelId string, userId str
return err return err
} }
func (s *OpenTracingLayerChannelStore) RemoveMembers(channelId string, userIds []string) *model.AppError { func (s *OpenTracingLayerChannelStore) RemoveMembers(channelId string, userIds []string) error {
origCtx := s.Root.Store.Context() origCtx := s.Root.Store.Context()
span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "ChannelStore.RemoveMembers") span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "ChannelStore.RemoveMembers")
s.Root.Store.SetContext(newCtx) s.Root.Store.SetContext(newCtx)
@@ -1864,7 +1864,7 @@ func (s *OpenTracingLayerChannelStore) SaveDirectChannel(channel *model.Channel,
return result, err return result, err
} }
func (s *OpenTracingLayerChannelStore) SaveMember(member *model.ChannelMember) (*model.ChannelMember, *model.AppError) { func (s *OpenTracingLayerChannelStore) SaveMember(member *model.ChannelMember) (*model.ChannelMember, error) {
origCtx := s.Root.Store.Context() origCtx := s.Root.Store.Context()
span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "ChannelStore.SaveMember") span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "ChannelStore.SaveMember")
s.Root.Store.SetContext(newCtx) s.Root.Store.SetContext(newCtx)
@@ -1882,7 +1882,7 @@ func (s *OpenTracingLayerChannelStore) SaveMember(member *model.ChannelMember) (
return result, err return result, err
} }
func (s *OpenTracingLayerChannelStore) SaveMultipleMembers(members []*model.ChannelMember) ([]*model.ChannelMember, *model.AppError) { func (s *OpenTracingLayerChannelStore) SaveMultipleMembers(members []*model.ChannelMember) ([]*model.ChannelMember, error) {
origCtx := s.Root.Store.Context() origCtx := s.Root.Store.Context()
span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "ChannelStore.SaveMultipleMembers") span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "ChannelStore.SaveMultipleMembers")
s.Root.Store.SetContext(newCtx) s.Root.Store.SetContext(newCtx)
@@ -2044,7 +2044,7 @@ func (s *OpenTracingLayerChannelStore) Update(channel *model.Channel) (*model.Ch
return result, err return result, err
} }
func (s *OpenTracingLayerChannelStore) UpdateLastViewedAt(channelIds []string, userId string) (map[string]int64, *model.AppError) { func (s *OpenTracingLayerChannelStore) UpdateLastViewedAt(channelIds []string, userId string) (map[string]int64, error) {
origCtx := s.Root.Store.Context() origCtx := s.Root.Store.Context()
span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "ChannelStore.UpdateLastViewedAt") span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "ChannelStore.UpdateLastViewedAt")
s.Root.Store.SetContext(newCtx) s.Root.Store.SetContext(newCtx)
@@ -2062,7 +2062,7 @@ func (s *OpenTracingLayerChannelStore) UpdateLastViewedAt(channelIds []string, u
return result, err return result, err
} }
func (s *OpenTracingLayerChannelStore) UpdateLastViewedAtPost(unreadPost *model.Post, userID string, mentionCount int) (*model.ChannelUnreadAt, *model.AppError) { func (s *OpenTracingLayerChannelStore) UpdateLastViewedAtPost(unreadPost *model.Post, userID string, mentionCount int) (*model.ChannelUnreadAt, error) {
origCtx := s.Root.Store.Context() origCtx := s.Root.Store.Context()
span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "ChannelStore.UpdateLastViewedAtPost") span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "ChannelStore.UpdateLastViewedAtPost")
s.Root.Store.SetContext(newCtx) s.Root.Store.SetContext(newCtx)
@@ -2080,7 +2080,7 @@ func (s *OpenTracingLayerChannelStore) UpdateLastViewedAtPost(unreadPost *model.
return result, err return result, err
} }
func (s *OpenTracingLayerChannelStore) UpdateMember(member *model.ChannelMember) (*model.ChannelMember, *model.AppError) { func (s *OpenTracingLayerChannelStore) UpdateMember(member *model.ChannelMember) (*model.ChannelMember, error) {
origCtx := s.Root.Store.Context() origCtx := s.Root.Store.Context()
span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "ChannelStore.UpdateMember") span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "ChannelStore.UpdateMember")
s.Root.Store.SetContext(newCtx) s.Root.Store.SetContext(newCtx)
@@ -2116,7 +2116,7 @@ func (s *OpenTracingLayerChannelStore) UpdateMembersRole(channelID string, userI
return err return err
} }
func (s *OpenTracingLayerChannelStore) UpdateMultipleMembers(members []*model.ChannelMember) ([]*model.ChannelMember, *model.AppError) { func (s *OpenTracingLayerChannelStore) UpdateMultipleMembers(members []*model.ChannelMember) ([]*model.ChannelMember, error) {
origCtx := s.Root.Store.Context() origCtx := s.Root.Store.Context()
span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "ChannelStore.UpdateMultipleMembers") span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "ChannelStore.UpdateMultipleMembers")
s.Root.Store.SetContext(newCtx) s.Root.Store.SetContext(newCtx)

Просмотреть файл

@@ -514,9 +514,23 @@ func (s *RetryLayerChannelStore) AnalyticsDeletedTypeCount(teamId string, channe
} }
func (s *RetryLayerChannelStore) AnalyticsTypeCount(teamId string, channelType string) (int64, *model.AppError) { func (s *RetryLayerChannelStore) AnalyticsTypeCount(teamId string, channelType string) (int64, error) {
return s.ChannelStore.AnalyticsTypeCount(teamId, channelType) tries := 0
for {
result, err := s.ChannelStore.AnalyticsTypeCount(teamId, channelType)
if err == nil {
return result, nil
}
if !isRepeatableError(err) {
return result, err
}
tries++
if tries >= 3 {
err = errors.Wrap(err, "giving up after 3 consecutive repeatable transaction failures")
return result, err
}
}
} }
@@ -564,9 +578,23 @@ func (s *RetryLayerChannelStore) ClearSidebarOnTeamLeave(userId string, teamId s
} }
func (s *RetryLayerChannelStore) CountPostsAfter(channelId string, timestamp int64, userId string) (int, *model.AppError) { func (s *RetryLayerChannelStore) CountPostsAfter(channelId string, timestamp int64, userId string) (int, error) {
return s.ChannelStore.CountPostsAfter(channelId, timestamp, userId) tries := 0
for {
result, err := s.ChannelStore.CountPostsAfter(channelId, timestamp, userId)
if err == nil {
return result, nil
}
if !isRepeatableError(err) {
return result, err
}
tries++
if tries >= 3 {
err = errors.Wrap(err, "giving up after 3 consecutive repeatable transaction failures")
return result, err
}
}
} }
@@ -702,15 +730,43 @@ func (s *RetryLayerChannelStore) GetAll(teamId string) ([]*model.Channel, error)
} }
func (s *RetryLayerChannelStore) GetAllChannelMembersForUser(userId string, allowFromCache bool, includeDeleted bool) (map[string]string, *model.AppError) { func (s *RetryLayerChannelStore) GetAllChannelMembersForUser(userId string, allowFromCache bool, includeDeleted bool) (map[string]string, error) {
return s.ChannelStore.GetAllChannelMembersForUser(userId, allowFromCache, includeDeleted) tries := 0
for {
result, err := s.ChannelStore.GetAllChannelMembersForUser(userId, allowFromCache, includeDeleted)
if err == nil {
return result, nil
}
if !isRepeatableError(err) {
return result, err
}
tries++
if tries >= 3 {
err = errors.Wrap(err, "giving up after 3 consecutive repeatable transaction failures")
return result, err
}
}
} }
func (s *RetryLayerChannelStore) GetAllChannelMembersNotifyPropsForChannel(channelId string, allowFromCache bool) (map[string]model.StringMap, *model.AppError) { func (s *RetryLayerChannelStore) GetAllChannelMembersNotifyPropsForChannel(channelId string, allowFromCache bool) (map[string]model.StringMap, error) {
return s.ChannelStore.GetAllChannelMembersNotifyPropsForChannel(channelId, allowFromCache) tries := 0
for {
result, err := s.ChannelStore.GetAllChannelMembersNotifyPropsForChannel(channelId, allowFromCache)
if err == nil {
return result, nil
}
if !isRepeatableError(err) {
return result, err
}
tries++
if tries >= 3 {
err = errors.Wrap(err, "giving up after 3 consecutive repeatable transaction failures")
return result, err
}
}
} }
@@ -852,9 +908,23 @@ func (s *RetryLayerChannelStore) GetChannelMembersForExport(userId string, teamI
} }
func (s *RetryLayerChannelStore) GetChannelMembersTimezones(channelId string) ([]model.StringMap, *model.AppError) { func (s *RetryLayerChannelStore) GetChannelMembersTimezones(channelId string) ([]model.StringMap, error) {
return s.ChannelStore.GetChannelMembersTimezones(channelId) tries := 0
for {
result, err := s.ChannelStore.GetChannelMembersTimezones(channelId)
if err == nil {
return result, nil
}
if !isRepeatableError(err) {
return result, err
}
tries++
if tries >= 3 {
err = errors.Wrap(err, "giving up after 3 consecutive repeatable transaction failures")
return result, err
}
}
} }
@@ -996,21 +1066,63 @@ func (s *RetryLayerChannelStore) GetFromMaster(id string) (*model.Channel, error
} }
func (s *RetryLayerChannelStore) GetGuestCount(channelId string, allowFromCache bool) (int64, *model.AppError) { func (s *RetryLayerChannelStore) GetGuestCount(channelId string, allowFromCache bool) (int64, error) {
return s.ChannelStore.GetGuestCount(channelId, allowFromCache) tries := 0
for {
result, err := s.ChannelStore.GetGuestCount(channelId, allowFromCache)
if err == nil {
return result, nil
}
if !isRepeatableError(err) {
return result, err
}
tries++
if tries >= 3 {
err = errors.Wrap(err, "giving up after 3 consecutive repeatable transaction failures")
return result, err
}
}
} }
func (s *RetryLayerChannelStore) GetMember(channelId string, userId string) (*model.ChannelMember, *model.AppError) { func (s *RetryLayerChannelStore) GetMember(channelId string, userId string) (*model.ChannelMember, error) {
return s.ChannelStore.GetMember(channelId, userId) tries := 0
for {
result, err := s.ChannelStore.GetMember(channelId, userId)
if err == nil {
return result, nil
}
if !isRepeatableError(err) {
return result, err
}
tries++
if tries >= 3 {
err = errors.Wrap(err, "giving up after 3 consecutive repeatable transaction failures")
return result, err
}
}
} }
func (s *RetryLayerChannelStore) GetMemberCount(channelId string, allowFromCache bool) (int64, *model.AppError) { func (s *RetryLayerChannelStore) GetMemberCount(channelId string, allowFromCache bool) (int64, error) {
return s.ChannelStore.GetMemberCount(channelId, allowFromCache) tries := 0
for {
result, err := s.ChannelStore.GetMemberCount(channelId, allowFromCache)
if err == nil {
return result, nil
}
if !isRepeatableError(err) {
return result, err
}
tries++
if tries >= 3 {
err = errors.Wrap(err, "giving up after 3 consecutive repeatable transaction failures")
return result, err
}
}
} }
@@ -1020,21 +1132,63 @@ func (s *RetryLayerChannelStore) GetMemberCountFromCache(channelId string) int64
} }
func (s *RetryLayerChannelStore) GetMemberCountsByGroup(channelID string, includeTimezones bool) ([]*model.ChannelMemberCountByGroup, *model.AppError) { func (s *RetryLayerChannelStore) GetMemberCountsByGroup(channelID string, includeTimezones bool) ([]*model.ChannelMemberCountByGroup, error) {
return s.ChannelStore.GetMemberCountsByGroup(channelID, includeTimezones) tries := 0
for {
result, err := s.ChannelStore.GetMemberCountsByGroup(channelID, includeTimezones)
if err == nil {
return result, nil
}
if !isRepeatableError(err) {
return result, err
}
tries++
if tries >= 3 {
err = errors.Wrap(err, "giving up after 3 consecutive repeatable transaction failures")
return result, err
}
}
} }
func (s *RetryLayerChannelStore) GetMemberForPost(postId string, userId string) (*model.ChannelMember, *model.AppError) { func (s *RetryLayerChannelStore) GetMemberForPost(postId string, userId string) (*model.ChannelMember, error) {
return s.ChannelStore.GetMemberForPost(postId, userId) tries := 0
for {
result, err := s.ChannelStore.GetMemberForPost(postId, userId)
if err == nil {
return result, nil
}
if !isRepeatableError(err) {
return result, err
}
tries++
if tries >= 3 {
err = errors.Wrap(err, "giving up after 3 consecutive repeatable transaction failures")
return result, err
}
}
} }
func (s *RetryLayerChannelStore) GetMembers(channelId string, offset int, limit int) (*model.ChannelMembers, *model.AppError) { func (s *RetryLayerChannelStore) GetMembers(channelId string, offset int, limit int) (*model.ChannelMembers, error) {
return s.ChannelStore.GetMembers(channelId, offset, limit) tries := 0
for {
result, err := s.ChannelStore.GetMembers(channelId, offset, limit)
if err == nil {
return result, nil
}
if !isRepeatableError(err) {
return result, err
}
tries++
if tries >= 3 {
err = errors.Wrap(err, "giving up after 3 consecutive repeatable transaction failures")
return result, err
}
}
} }
@@ -1044,15 +1198,43 @@ func (s *RetryLayerChannelStore) GetMembersByIds(channelId string, userIds []str
} }
func (s *RetryLayerChannelStore) GetMembersForUser(teamId string, userId string) (*model.ChannelMembers, *model.AppError) { func (s *RetryLayerChannelStore) GetMembersForUser(teamId string, userId string) (*model.ChannelMembers, error) {
return s.ChannelStore.GetMembersForUser(teamId, userId) tries := 0
for {
result, err := s.ChannelStore.GetMembersForUser(teamId, userId)
if err == nil {
return result, nil
}
if !isRepeatableError(err) {
return result, err
}
tries++
if tries >= 3 {
err = errors.Wrap(err, "giving up after 3 consecutive repeatable transaction failures")
return result, err
}
}
} }
func (s *RetryLayerChannelStore) GetMembersForUserWithPagination(teamId string, userId string, page int, perPage int) (*model.ChannelMembers, *model.AppError) { func (s *RetryLayerChannelStore) GetMembersForUserWithPagination(teamId string, userId string, page int, perPage int) (*model.ChannelMembers, error) {
return s.ChannelStore.GetMembersForUserWithPagination(teamId, userId, page, perPage) tries := 0
for {
result, err := s.ChannelStore.GetMembersForUserWithPagination(teamId, userId, page, perPage)
if err == nil {
return result, nil
}
if !isRepeatableError(err) {
return result, err
}
tries++
if tries >= 3 {
err = errors.Wrap(err, "giving up after 3 consecutive repeatable transaction failures")
return result, err
}
}
} }
@@ -1076,15 +1258,43 @@ func (s *RetryLayerChannelStore) GetMoreChannels(teamId string, userId string, o
} }
func (s *RetryLayerChannelStore) GetPinnedPostCount(channelId string, allowFromCache bool) (int64, *model.AppError) { func (s *RetryLayerChannelStore) GetPinnedPostCount(channelId string, allowFromCache bool) (int64, error) {
return s.ChannelStore.GetPinnedPostCount(channelId, allowFromCache) tries := 0
for {
result, err := s.ChannelStore.GetPinnedPostCount(channelId, allowFromCache)
if err == nil {
return result, nil
}
if !isRepeatableError(err) {
return result, err
}
tries++
if tries >= 3 {
err = errors.Wrap(err, "giving up after 3 consecutive repeatable transaction failures")
return result, err
}
}
} }
func (s *RetryLayerChannelStore) GetPinnedPosts(channelId string) (*model.PostList, *model.AppError) { func (s *RetryLayerChannelStore) GetPinnedPosts(channelId string) (*model.PostList, error) {
return s.ChannelStore.GetPinnedPosts(channelId) tries := 0
for {
result, err := s.ChannelStore.GetPinnedPosts(channelId)
if err == nil {
return result, nil
}
if !isRepeatableError(err) {
return result, err
}
tries++
if tries >= 3 {
err = errors.Wrap(err, "giving up after 3 consecutive repeatable transaction failures")
return result, err
}
}
} }
@@ -1192,9 +1402,23 @@ func (s *RetryLayerChannelStore) GroupSyncedChannelCount() (int64, *model.AppErr
} }
func (s *RetryLayerChannelStore) IncrementMentionCount(channelId string, userId string) *model.AppError { func (s *RetryLayerChannelStore) IncrementMentionCount(channelId string, userId string) error {
return s.ChannelStore.IncrementMentionCount(channelId, userId) tries := 0
for {
err := s.ChannelStore.IncrementMentionCount(channelId, userId)
if err == nil {
return nil
}
if !isRepeatableError(err) {
return err
}
tries++
if tries >= 3 {
err = errors.Wrap(err, "giving up after 3 consecutive repeatable transaction failures")
return err
}
}
} }
@@ -1312,15 +1536,43 @@ func (s *RetryLayerChannelStore) PermanentDeleteByTeam(teamId string) error {
} }
func (s *RetryLayerChannelStore) PermanentDeleteMembersByChannel(channelId string) *model.AppError { func (s *RetryLayerChannelStore) PermanentDeleteMembersByChannel(channelId string) error {
return s.ChannelStore.PermanentDeleteMembersByChannel(channelId) tries := 0
for {
err := s.ChannelStore.PermanentDeleteMembersByChannel(channelId)
if err == nil {
return nil
}
if !isRepeatableError(err) {
return err
}
tries++
if tries >= 3 {
err = errors.Wrap(err, "giving up after 3 consecutive repeatable transaction failures")
return err
}
}
} }
func (s *RetryLayerChannelStore) PermanentDeleteMembersByUser(userId string) *model.AppError { func (s *RetryLayerChannelStore) PermanentDeleteMembersByUser(userId string) error {
return s.ChannelStore.PermanentDeleteMembersByUser(userId) tries := 0
for {
err := s.ChannelStore.PermanentDeleteMembersByUser(userId)
if err == nil {
return nil
}
if !isRepeatableError(err) {
return err
}
tries++
if tries >= 3 {
err = errors.Wrap(err, "giving up after 3 consecutive repeatable transaction failures")
return err
}
}
} }
@@ -1330,15 +1582,43 @@ func (s *RetryLayerChannelStore) RemoveAllDeactivatedMembers(channelId string) *
} }
func (s *RetryLayerChannelStore) RemoveMember(channelId string, userId string) *model.AppError { func (s *RetryLayerChannelStore) RemoveMember(channelId string, userId string) error {
return s.ChannelStore.RemoveMember(channelId, userId) tries := 0
for {
err := s.ChannelStore.RemoveMember(channelId, userId)
if err == nil {
return nil
}
if !isRepeatableError(err) {
return err
}
tries++
if tries >= 3 {
err = errors.Wrap(err, "giving up after 3 consecutive repeatable transaction failures")
return err
}
}
} }
func (s *RetryLayerChannelStore) RemoveMembers(channelId string, userIds []string) *model.AppError { func (s *RetryLayerChannelStore) RemoveMembers(channelId string, userIds []string) error {
return s.ChannelStore.RemoveMembers(channelId, userIds) tries := 0
for {
err := s.ChannelStore.RemoveMembers(channelId, userIds)
if err == nil {
return nil
}
if !isRepeatableError(err) {
return err
}
tries++
if tries >= 3 {
err = errors.Wrap(err, "giving up after 3 consecutive repeatable transaction failures")
return err
}
}
} }
@@ -1408,15 +1688,43 @@ func (s *RetryLayerChannelStore) SaveDirectChannel(channel *model.Channel, membe
} }
func (s *RetryLayerChannelStore) SaveMember(member *model.ChannelMember) (*model.ChannelMember, *model.AppError) { func (s *RetryLayerChannelStore) SaveMember(member *model.ChannelMember) (*model.ChannelMember, error) {
return s.ChannelStore.SaveMember(member) tries := 0
for {
result, err := s.ChannelStore.SaveMember(member)
if err == nil {
return result, nil
}
if !isRepeatableError(err) {
return result, err
}
tries++
if tries >= 3 {
err = errors.Wrap(err, "giving up after 3 consecutive repeatable transaction failures")
return result, err
}
}
} }
func (s *RetryLayerChannelStore) SaveMultipleMembers(members []*model.ChannelMember) ([]*model.ChannelMember, *model.AppError) { func (s *RetryLayerChannelStore) SaveMultipleMembers(members []*model.ChannelMember) ([]*model.ChannelMember, error) {
return s.ChannelStore.SaveMultipleMembers(members) tries := 0
for {
result, err := s.ChannelStore.SaveMultipleMembers(members)
if err == nil {
return result, nil
}
if !isRepeatableError(err) {
return result, err
}
tries++
if tries >= 3 {
err = errors.Wrap(err, "giving up after 3 consecutive repeatable transaction failures")
return result, err
}
}
} }
@@ -1496,21 +1804,63 @@ func (s *RetryLayerChannelStore) Update(channel *model.Channel) (*model.Channel,
} }
func (s *RetryLayerChannelStore) UpdateLastViewedAt(channelIds []string, userId string) (map[string]int64, *model.AppError) { func (s *RetryLayerChannelStore) UpdateLastViewedAt(channelIds []string, userId string) (map[string]int64, error) {
return s.ChannelStore.UpdateLastViewedAt(channelIds, userId) tries := 0
for {
result, err := s.ChannelStore.UpdateLastViewedAt(channelIds, userId)
if err == nil {
return result, nil
}
if !isRepeatableError(err) {
return result, err
}
tries++
if tries >= 3 {
err = errors.Wrap(err, "giving up after 3 consecutive repeatable transaction failures")
return result, err
}
}
} }
func (s *RetryLayerChannelStore) UpdateLastViewedAtPost(unreadPost *model.Post, userID string, mentionCount int) (*model.ChannelUnreadAt, *model.AppError) { func (s *RetryLayerChannelStore) UpdateLastViewedAtPost(unreadPost *model.Post, userID string, mentionCount int) (*model.ChannelUnreadAt, error) {
return s.ChannelStore.UpdateLastViewedAtPost(unreadPost, userID, mentionCount) tries := 0
for {
result, err := s.ChannelStore.UpdateLastViewedAtPost(unreadPost, userID, mentionCount)
if err == nil {
return result, nil
}
if !isRepeatableError(err) {
return result, err
}
tries++
if tries >= 3 {
err = errors.Wrap(err, "giving up after 3 consecutive repeatable transaction failures")
return result, err
}
}
} }
func (s *RetryLayerChannelStore) UpdateMember(member *model.ChannelMember) (*model.ChannelMember, *model.AppError) { func (s *RetryLayerChannelStore) UpdateMember(member *model.ChannelMember) (*model.ChannelMember, error) {
return s.ChannelStore.UpdateMember(member) tries := 0
for {
result, err := s.ChannelStore.UpdateMember(member)
if err == nil {
return result, nil
}
if !isRepeatableError(err) {
return result, err
}
tries++
if tries >= 3 {
err = errors.Wrap(err, "giving up after 3 consecutive repeatable transaction failures")
return result, err
}
}
} }
@@ -1520,9 +1870,23 @@ func (s *RetryLayerChannelStore) UpdateMembersRole(channelID string, userIDs []s
} }
func (s *RetryLayerChannelStore) UpdateMultipleMembers(members []*model.ChannelMember) ([]*model.ChannelMember, *model.AppError) { func (s *RetryLayerChannelStore) UpdateMultipleMembers(members []*model.ChannelMember) ([]*model.ChannelMember, error) {
return s.ChannelStore.UpdateMultipleMembers(members) tries := 0
for {
result, err := s.ChannelStore.UpdateMultipleMembers(members)
if err == nil {
return result, nil
}
if !isRepeatableError(err) {
return result, err
}
tries++
if tries >= 3 {
err = errors.Wrap(err, "giving up after 3 consecutive repeatable transaction failures")
return result, err
}
}
} }

Просмотреть файл

@@ -63,7 +63,7 @@ func (c *SearchChannelStore) Update(channel *model.Channel) (*model.Channel, err
return updatedChannel, err return updatedChannel, err
} }
func (c *SearchChannelStore) UpdateMember(cm *model.ChannelMember) (*model.ChannelMember, *model.AppError) { func (c *SearchChannelStore) UpdateMember(cm *model.ChannelMember) (*model.ChannelMember, error) {
member, err := c.ChannelStore.UpdateMember(cm) member, err := c.ChannelStore.UpdateMember(cm)
if err == nil { if err == nil {
c.rootStore.indexUserFromID(cm.UserId) c.rootStore.indexUserFromID(cm.UserId)
@@ -77,7 +77,7 @@ func (c *SearchChannelStore) UpdateMember(cm *model.ChannelMember) (*model.Chann
return member, err return member, err
} }
func (c *SearchChannelStore) SaveMember(cm *model.ChannelMember) (*model.ChannelMember, *model.AppError) { func (c *SearchChannelStore) SaveMember(cm *model.ChannelMember) (*model.ChannelMember, error) {
member, err := c.ChannelStore.SaveMember(cm) member, err := c.ChannelStore.SaveMember(cm)
if err == nil { if err == nil {
c.rootStore.indexUserFromID(cm.UserId) c.rootStore.indexUserFromID(cm.UserId)
@@ -91,7 +91,7 @@ func (c *SearchChannelStore) SaveMember(cm *model.ChannelMember) (*model.Channel
return member, err return member, err
} }
func (c *SearchChannelStore) RemoveMember(channelId, userIdToRemove string) *model.AppError { func (c *SearchChannelStore) RemoveMember(channelId, userIdToRemove string) error {
err := c.ChannelStore.RemoveMember(channelId, userIdToRemove) err := c.ChannelStore.RemoveMember(channelId, userIdToRemove)
if err == nil { if err == nil {
c.rootStore.indexUserFromID(userIdToRemove) c.rootStore.indexUserFromID(userIdToRemove)
@@ -99,7 +99,7 @@ func (c *SearchChannelStore) RemoveMember(channelId, userIdToRemove string) *mod
return err return err
} }
func (c *SearchChannelStore) RemoveMembers(channelId string, userIds []string) *model.AppError { func (c *SearchChannelStore) RemoveMembers(channelId string, userIds []string) error {
if err := c.ChannelStore.RemoveMembers(channelId, userIds); err != nil { if err := c.ChannelStore.RemoveMembers(channelId, userIds); err != nil {
return err return err
} }
@@ -177,7 +177,7 @@ func (c *SearchChannelStore) searchAutocompleteChannels(engine searchengine.Sear
return &channelList, nil return &channelList, nil
} }
func (c *SearchChannelStore) PermanentDeleteMembersByUser(userId string) *model.AppError { func (c *SearchChannelStore) PermanentDeleteMembersByUser(userId string) error {
err := c.ChannelStore.PermanentDeleteMembersByUser(userId) err := c.ChannelStore.PermanentDeleteMembersByUser(userId)
if err == nil { if err == nil {
c.rootStore.indexUserFromID(userId) c.rootStore.indexUserFromID(userId)
@@ -202,7 +202,7 @@ func (c *SearchChannelStore) RemoveAllDeactivatedMembers(channelId string) *mode
return err return err
} }
func (c *SearchChannelStore) PermanentDeleteMembersByChannel(channelId string) *model.AppError { func (c *SearchChannelStore) PermanentDeleteMembersByChannel(channelId string) error {
profiles, errProfiles := c.rootStore.User().GetAllProfilesInChannel(channelId, true) profiles, errProfiles := c.rootStore.User().GetAllProfilesInChannel(channelId, true)
if errProfiles != nil { if errProfiles != nil {
mlog.Error("Encountered error indexing users for channel", mlog.String("channel_id", channelId), mlog.Err(errProfiles)) mlog.Error("Encountered error indexing users for channel", mlog.String("channel_id", channelId), mlog.Err(errProfiles))

Просмотреть файл

@@ -744,12 +744,12 @@ func (s SqlChannelStore) Get(id string, allowFromCache bool) (*model.Channel, er
return s.get(id, false, allowFromCache) return s.get(id, false, allowFromCache)
} }
func (s SqlChannelStore) GetPinnedPosts(channelId string) (*model.PostList, *model.AppError) { func (s SqlChannelStore) GetPinnedPosts(channelId string) (*model.PostList, error) {
pl := model.NewPostList() pl := model.NewPostList()
var posts []*model.Post var posts []*model.Post
if _, err := s.GetReplica().Select(&posts, "SELECT *, (SELECT count(Posts.Id) FROM Posts WHERE Posts.RootId = (CASE WHEN p.RootId = '' THEN p.Id ELSE p.RootId END) AND Posts.DeleteAt = 0) as ReplyCount FROM Posts p WHERE IsPinned = true AND ChannelId = :ChannelId AND DeleteAt = 0 ORDER BY CreateAt ASC", map[string]interface{}{"ChannelId": channelId}); err != nil { if _, err := s.GetReplica().Select(&posts, "SELECT *, (SELECT count(Posts.Id) FROM Posts WHERE Posts.RootId = (CASE WHEN p.RootId = '' THEN p.Id ELSE p.RootId END) AND Posts.DeleteAt = 0) as ReplyCount FROM Posts p WHERE IsPinned = true AND ChannelId = :ChannelId AND DeleteAt = 0 ORDER BY CreateAt ASC", map[string]interface{}{"ChannelId": channelId}); err != nil {
return nil, model.NewAppError("SqlPostStore.GetPinnedPosts", "store.sql_channel.pinned_posts.app_error", nil, err.Error(), http.StatusInternalServerError) return nil, errors.Wrap(err, "failed to find Posts")
} }
for _, post := range posts { for _, post := range posts {
pl.AddPost(post) pl.AddPost(post)
@@ -918,10 +918,10 @@ func (s SqlChannelStore) permanentDeleteT(transaction *gorp.Transaction, channel
return nil return nil
} }
func (s SqlChannelStore) PermanentDeleteMembersByChannel(channelId string) *model.AppError { func (s SqlChannelStore) PermanentDeleteMembersByChannel(channelId string) error {
_, err := s.GetMaster().Exec("DELETE FROM ChannelMembers WHERE ChannelId = :ChannelId", map[string]interface{}{"ChannelId": channelId}) _, err := s.GetMaster().Exec("DELETE FROM ChannelMembers WHERE ChannelId = :ChannelId", map[string]interface{}{"ChannelId": channelId})
if err != nil { if err != nil {
return model.NewAppError("SqlChannelStore.RemoveAllMembersByChannel", "store.sql_channel.remove_member.app_error", nil, "channel_id="+channelId+", "+err.Error(), http.StatusInternalServerError) return errors.Wrapf(err, "failed to delete Channel with channelId=%s", channelId)
} }
return nil return nil
@@ -1382,46 +1382,33 @@ var CHANNEL_MEMBERS_WITH_SCHEME_SELECT_QUERY = `
Schemes TeamScheme ON Teams.SchemeId = TeamScheme.Id Schemes TeamScheme ON Teams.SchemeId = TeamScheme.Id
` `
func (s SqlChannelStore) SaveMultipleMembers(members []*model.ChannelMember) ([]*model.ChannelMember, *model.AppError) { func (s SqlChannelStore) SaveMultipleMembers(members []*model.ChannelMember) ([]*model.ChannelMember, error) {
for _, member := range members { for _, member := range members {
defer s.InvalidateAllChannelMembersForUser(member.UserId) defer s.InvalidateAllChannelMembersForUser(member.UserId)
} }
transaction, err := s.GetMaster().Begin() transaction, err := s.GetMaster().Begin()
if err != nil { if err != nil {
return nil, model.NewAppError("SqlChannelStore.SaveMember", "store.sql_channel.save_member.open_transaction.app_error", nil, err.Error(), http.StatusInternalServerError) return nil, errors.Wrap(err, "begin_transaction")
} }
defer finalizeTransaction(transaction) defer finalizeTransaction(transaction)
newMembers, err := s.saveMultipleMembersT(transaction, members) newMembers, err := s.saveMultipleMembersT(transaction, members)
if err != nil { // TODO: this will go away once SaveMultipleMembers is migrated too. if err != nil {
var cErr *store.ErrConflict return nil, err
var appErr *model.AppError
switch {
case errors.As(err, &cErr):
switch cErr.Resource {
case "ChannelMembers":
return nil, model.NewAppError("CreateChannel", "store.sql_channel.save_member.exists.app_error", nil, cErr.Error(), http.StatusBadRequest)
}
case errors.As(err, &appErr): // in case we haven't converted to plain error.
return nil, appErr
default: // last fallback in case it doesn't map to an existing app error.
// TODO: This error key would go away once this store method is migrated to return plain errors
return nil, model.NewAppError("CreateDirectChannel", "app.channel.create_direct_channel.internal_error", nil, err.Error(), http.StatusInternalServerError)
}
} }
if err := transaction.Commit(); err != nil { if err := transaction.Commit(); err != nil {
return nil, model.NewAppError("SqlChannelStore.SaveMember", "store.sql_channel.save_member.commit_transaction.app_error", nil, err.Error(), http.StatusInternalServerError) return nil, errors.Wrap(err, "commit_transaction")
} }
return newMembers, nil return newMembers, nil
} }
func (s SqlChannelStore) SaveMember(member *model.ChannelMember) (*model.ChannelMember, *model.AppError) { func (s SqlChannelStore) SaveMember(member *model.ChannelMember) (*model.ChannelMember, error) {
newMembers, appErr := s.SaveMultipleMembers([]*model.ChannelMember{member}) newMembers, err := s.SaveMultipleMembers([]*model.ChannelMember{member})
if appErr != nil { if err != nil {
return nil, appErr return nil, err
} }
return newMembers[0], nil return newMembers[0], nil
} }
@@ -1575,7 +1562,7 @@ func (s SqlChannelStore) saveMemberT(transaction *gorp.Transaction, member *mode
return members[0], nil return members[0], nil
} }
func (s SqlChannelStore) UpdateMultipleMembers(members []*model.ChannelMember) ([]*model.ChannelMember, *model.AppError) { func (s SqlChannelStore) UpdateMultipleMembers(members []*model.ChannelMember) ([]*model.ChannelMember, error) {
for _, member := range members { for _, member := range members {
member.PreUpdate() member.PreUpdate()
@@ -1588,34 +1575,34 @@ func (s SqlChannelStore) UpdateMultipleMembers(members []*model.ChannelMember) (
var err error var err error
if transaction, err = s.GetMaster().Begin(); err != nil { if transaction, err = s.GetMaster().Begin(); err != nil {
return nil, model.NewAppError("SqlChannelStore.MigrateChannelMembers", "store.sql_channel.migrate_channel_members.open_transaction.app_error", nil, err.Error(), http.StatusInternalServerError) return nil, errors.Wrap(err, "begin_transaction")
} }
defer finalizeTransaction(transaction) defer finalizeTransaction(transaction)
updatedMembers := []*model.ChannelMember{} updatedMembers := []*model.ChannelMember{}
for _, member := range members { for _, member := range members {
if _, err := transaction.Update(NewChannelMemberFromModel(member)); err != nil { if _, err := transaction.Update(NewChannelMemberFromModel(member)); err != nil {
return nil, model.NewAppError("SqlChannelStore.UpdateMember", "store.sql_channel.update_member.app_error", nil, "channel_id="+member.ChannelId+", "+"user_id="+member.UserId+", "+err.Error(), http.StatusInternalServerError) return nil, errors.Wrap(err, "failed to update ChannelMember")
} }
// TODO: Get this out of the transaction when is possible // TODO: Get this out of the transaction when is possible
var dbMember channelMemberWithSchemeRoles var dbMember channelMemberWithSchemeRoles
if err := transaction.SelectOne(&dbMember, CHANNEL_MEMBERS_WITH_SCHEME_SELECT_QUERY+"WHERE ChannelMembers.ChannelId = :ChannelId AND ChannelMembers.UserId = :UserId", map[string]interface{}{"ChannelId": member.ChannelId, "UserId": member.UserId}); err != nil { if err := transaction.SelectOne(&dbMember, CHANNEL_MEMBERS_WITH_SCHEME_SELECT_QUERY+"WHERE ChannelMembers.ChannelId = :ChannelId AND ChannelMembers.UserId = :UserId", map[string]interface{}{"ChannelId": member.ChannelId, "UserId": member.UserId}); err != nil {
if err == sql.ErrNoRows { if err == sql.ErrNoRows {
return nil, model.NewAppError("SqlChannelStore.GetMember", store.MISSING_CHANNEL_MEMBER_ERROR, nil, "channel_id="+member.ChannelId+"user_id="+member.UserId+","+err.Error(), http.StatusNotFound) return nil, store.NewErrNotFound("ChannelMember", fmt.Sprintf("channelId=%s, userId=%s", member.ChannelId, member.UserId))
} }
return nil, model.NewAppError("SqlChannelStore.GetMember", "store.sql_channel.get_member.app_error", nil, "channel_id="+member.ChannelId+"user_id="+member.UserId+","+err.Error(), http.StatusInternalServerError) return nil, errors.Wrapf(err, "failed to get ChannelMember with channelId=%s and userId=%s", member.ChannelId, member.UserId)
} }
updatedMembers = append(updatedMembers, dbMember.ToModel()) updatedMembers = append(updatedMembers, dbMember.ToModel())
} }
if err := transaction.Commit(); err != nil { if err := transaction.Commit(); err != nil {
return nil, model.NewAppError("SqlChannelStore.MigrateChannelMembers", "store.sql_channel.migrate_channel_members.commit_transaction.app_error", nil, err.Error(), http.StatusInternalServerError) return nil, errors.Wrap(err, "commit_transaction")
} }
return updatedMembers, nil return updatedMembers, nil
} }
func (s SqlChannelStore) UpdateMember(member *model.ChannelMember) (*model.ChannelMember, *model.AppError) { func (s SqlChannelStore) UpdateMember(member *model.ChannelMember) (*model.ChannelMember, error) {
updatedMembers, err := s.UpdateMultipleMembers([]*model.ChannelMember{member}) updatedMembers, err := s.UpdateMultipleMembers([]*model.ChannelMember{member})
if err != nil { if err != nil {
return nil, err return nil, err
@@ -1623,17 +1610,17 @@ func (s SqlChannelStore) UpdateMember(member *model.ChannelMember) (*model.Chann
return updatedMembers[0], nil return updatedMembers[0], nil
} }
func (s SqlChannelStore) GetMembers(channelId string, offset, limit int) (*model.ChannelMembers, *model.AppError) { func (s SqlChannelStore) GetMembers(channelId string, offset, limit int) (*model.ChannelMembers, error) {
var dbMembers channelMemberWithSchemeRolesList var dbMembers channelMemberWithSchemeRolesList
_, err := s.GetReplica().Select(&dbMembers, CHANNEL_MEMBERS_WITH_SCHEME_SELECT_QUERY+"WHERE ChannelId = :ChannelId LIMIT :Limit OFFSET :Offset", map[string]interface{}{"ChannelId": channelId, "Limit": limit, "Offset": offset}) _, err := s.GetReplica().Select(&dbMembers, CHANNEL_MEMBERS_WITH_SCHEME_SELECT_QUERY+"WHERE ChannelId = :ChannelId LIMIT :Limit OFFSET :Offset", map[string]interface{}{"ChannelId": channelId, "Limit": limit, "Offset": offset})
if err != nil { if err != nil {
return nil, model.NewAppError("SqlChannelStore.GetMembers", "store.sql_channel.get_members.app_error", nil, "channel_id="+channelId+","+err.Error(), http.StatusInternalServerError) return nil, errors.Wrapf(err, "failed to get ChannelMembers with channelId=%s", channelId)
} }
return dbMembers.ToModel(), nil return dbMembers.ToModel(), nil
} }
func (s SqlChannelStore) GetChannelMembersTimezones(channelId string) ([]model.StringMap, *model.AppError) { func (s SqlChannelStore) GetChannelMembersTimezones(channelId string) ([]model.StringMap, error) {
var dbMembersTimezone []model.StringMap var dbMembersTimezone []model.StringMap
_, err := s.GetReplica().Select(&dbMembersTimezone, ` _, err := s.GetReplica().Select(&dbMembersTimezone, `
SELECT SELECT
@@ -1646,20 +1633,20 @@ func (s SqlChannelStore) GetChannelMembersTimezones(channelId string) ([]model.S
`, map[string]interface{}{"ChannelId": channelId}) `, map[string]interface{}{"ChannelId": channelId})
if err != nil { if err != nil {
return nil, model.NewAppError("SqlChannelStore.GetChannelMembersTimezones", "store.sql_channel.get_members.app_error", nil, "channel_id="+channelId+","+err.Error(), http.StatusInternalServerError) return nil, errors.Wrapf(err, "failed to find user timezones for users in channels with channelId=%s", channelId)
} }
return dbMembersTimezone, nil return dbMembersTimezone, nil
} }
func (s SqlChannelStore) GetMember(channelId string, userId string) (*model.ChannelMember, *model.AppError) { func (s SqlChannelStore) GetMember(channelId string, userId string) (*model.ChannelMember, error) {
var dbMember channelMemberWithSchemeRoles var dbMember channelMemberWithSchemeRoles
if err := s.GetReplica().SelectOne(&dbMember, CHANNEL_MEMBERS_WITH_SCHEME_SELECT_QUERY+"WHERE ChannelMembers.ChannelId = :ChannelId AND ChannelMembers.UserId = :UserId", map[string]interface{}{"ChannelId": channelId, "UserId": userId}); err != nil { if err := s.GetReplica().SelectOne(&dbMember, CHANNEL_MEMBERS_WITH_SCHEME_SELECT_QUERY+"WHERE ChannelMembers.ChannelId = :ChannelId AND ChannelMembers.UserId = :UserId", map[string]interface{}{"ChannelId": channelId, "UserId": userId}); err != nil {
if err == sql.ErrNoRows { if err == sql.ErrNoRows {
return nil, model.NewAppError("SqlChannelStore.GetMember", store.MISSING_CHANNEL_MEMBER_ERROR, nil, "channel_id="+channelId+"user_id="+userId+","+err.Error(), http.StatusNotFound) return nil, store.NewErrNotFound("ChannelMember", fmt.Sprintf("channelId=%s, userId=%s", channelId, userId))
} }
return nil, model.NewAppError("SqlChannelStore.GetMember", "store.sql_channel.get_member.app_error", nil, "channel_id="+channelId+"user_id="+userId+","+err.Error(), http.StatusInternalServerError) return nil, errors.Wrapf(err, "failed to get ChannelMember with channelId=%s and userId=%s", channelId, userId)
} }
return dbMember.ToModel(), nil return dbMember.ToModel(), nil
@@ -1702,7 +1689,7 @@ func (s SqlChannelStore) IsUserInChannelUseCache(userId string, channelId string
return false return false
} }
func (s SqlChannelStore) GetMemberForPost(postId string, userId string) (*model.ChannelMember, *model.AppError) { func (s SqlChannelStore) GetMemberForPost(postId string, userId string) (*model.ChannelMember, error) {
var dbMember channelMemberWithSchemeRoles var dbMember channelMemberWithSchemeRoles
query := ` query := `
SELECT SELECT
@@ -1730,12 +1717,12 @@ func (s SqlChannelStore) GetMemberForPost(postId string, userId string) (*model.
AND AND
Posts.Id = :PostId` Posts.Id = :PostId`
if err := s.GetReplica().SelectOne(&dbMember, query, map[string]interface{}{"UserId": userId, "PostId": postId}); err != nil { if err := s.GetReplica().SelectOne(&dbMember, query, map[string]interface{}{"UserId": userId, "PostId": postId}); err != nil {
return nil, model.NewAppError("SqlChannelStore.GetMemberForPost", "store.sql_channel.get_member_for_post.app_error", nil, "postId="+postId+", err="+err.Error(), http.StatusInternalServerError) return nil, errors.Wrapf(err, "failed to get ChannelMember with postId=%s and userId=%s", postId, userId)
} }
return dbMember.ToModel(), nil return dbMember.ToModel(), nil
} }
func (s SqlChannelStore) GetAllChannelMembersForUser(userId string, allowFromCache bool, includeDeleted bool) (map[string]string, *model.AppError) { func (s SqlChannelStore) GetAllChannelMembersForUser(userId string, allowFromCache bool, includeDeleted bool) (map[string]string, error) {
cache_key := userId cache_key := userId
if includeDeleted { if includeDeleted {
cache_key += "_deleted" cache_key += "_deleted"
@@ -1754,17 +1741,6 @@ func (s SqlChannelStore) GetAllChannelMembersForUser(userId string, allowFromCac
s.metrics.IncrementMemCacheMissCounter("All Channel Members for User") s.metrics.IncrementMemCacheMissCounter("All Channel Members for User")
} }
failure := func(err error) *model.AppError {
// TODO: This error key would go away once this store method is migrated to return plain errors
return model.NewAppError(
"SqlChannelStore.GetAllChannelMembersForUser",
"app.channel.get_channels.get.app_error",
nil,
"userId="+userId+", err="+err.Error(),
http.StatusInternalServerError,
)
}
query := s.getQueryBuilder(). query := s.getQueryBuilder().
Select(` Select(`
ChannelMembers.ChannelId, ChannelMembers.Roles, ChannelMembers.SchemeGuest, ChannelMembers.ChannelId, ChannelMembers.Roles, ChannelMembers.SchemeGuest,
@@ -1787,12 +1763,12 @@ func (s SqlChannelStore) GetAllChannelMembersForUser(userId string, allowFromCac
} }
queryString, args, err := query.ToSql() queryString, args, err := query.ToSql()
if err != nil { if err != nil {
return nil, failure(err) return nil, errors.Wrap(err, "channel_tosql")
} }
rows, err := s.GetReplica().Db.Query(queryString, args...) rows, err := s.GetReplica().Db.Query(queryString, args...)
if err != nil { if err != nil {
return nil, failure(err) return nil, errors.Wrap(err, "failed to find ChannelMembers, TeamScheme and ChannelScheme data")
} }
var data allChannelMembers var data allChannelMembers
@@ -1806,12 +1782,12 @@ func (s SqlChannelStore) GetAllChannelMembersForUser(userId string, allowFromCac
&cm.ChannelSchemeDefaultUserRole, &cm.ChannelSchemeDefaultAdminRole, &cm.ChannelSchemeDefaultUserRole, &cm.ChannelSchemeDefaultAdminRole,
) )
if err != nil { if err != nil {
return nil, failure(err) return nil, errors.Wrap(err, "unable to scan columns")
} }
data = append(data, cm) data = append(data, cm)
} }
if err = rows.Err(); err != nil { if err = rows.Err(); err != nil {
return nil, failure(err) return nil, errors.Wrap(err, "error while iterating over rows")
} }
ids := data.ToMapStringString() ids := data.ToMapStringString()
@@ -1833,7 +1809,7 @@ type allChannelMemberNotifyProps struct {
NotifyProps model.StringMap NotifyProps model.StringMap
} }
func (s SqlChannelStore) GetAllChannelMembersNotifyPropsForChannel(channelId string, allowFromCache bool) (map[string]model.StringMap, *model.AppError) { func (s SqlChannelStore) GetAllChannelMembersNotifyPropsForChannel(channelId string, allowFromCache bool) (map[string]model.StringMap, error) {
if allowFromCache { if allowFromCache {
var cacheItem map[string]model.StringMap var cacheItem map[string]model.StringMap
if err := allChannelMembersNotifyPropsForChannelCache.Get(channelId, &cacheItem); err == nil { if err := allChannelMembersNotifyPropsForChannelCache.Get(channelId, &cacheItem); err == nil {
@@ -1855,7 +1831,7 @@ func (s SqlChannelStore) GetAllChannelMembersNotifyPropsForChannel(channelId str
WHERE ChannelId = :ChannelId`, map[string]interface{}{"ChannelId": channelId}) WHERE ChannelId = :ChannelId`, map[string]interface{}{"ChannelId": channelId})
if err != nil { if err != nil {
return nil, model.NewAppError("SqlChannelStore.GetAllChannelMembersPropsForChannel", "store.sql_channel.get_members.app_error", nil, "channelId="+channelId+", err="+err.Error(), http.StatusInternalServerError) return nil, errors.Wrapf(err, "failed to find data from ChannelMembers with channelId=%s", channelId)
} }
props := make(map[string]model.StringMap) props := make(map[string]model.StringMap)
@@ -1876,7 +1852,7 @@ func (s SqlChannelStore) GetMemberCountFromCache(channelId string) int64 {
return count return count
} }
func (s SqlChannelStore) GetMemberCount(channelId string, allowFromCache bool) (int64, *model.AppError) { func (s SqlChannelStore) GetMemberCount(channelId string, allowFromCache bool) (int64, error) {
count, err := s.GetReplica().SelectInt(` count, err := s.GetReplica().SelectInt(`
SELECT SELECT
count(*) count(*)
@@ -1888,7 +1864,7 @@ func (s SqlChannelStore) GetMemberCount(channelId string, allowFromCache bool) (
AND ChannelMembers.ChannelId = :ChannelId AND ChannelMembers.ChannelId = :ChannelId
AND Users.DeleteAt = 0`, map[string]interface{}{"ChannelId": channelId}) AND Users.DeleteAt = 0`, map[string]interface{}{"ChannelId": channelId})
if err != nil { if err != nil {
return 0, model.NewAppError("SqlChannelStore.GetMemberCount", "store.sql_channel.get_member_count.app_error", nil, "channel_id="+channelId+", "+err.Error(), http.StatusInternalServerError) return 0, errors.Wrapf(err, "failed to count ChanenelMembers with channelId=%s", channelId)
} }
return count, nil return count, nil
@@ -1896,7 +1872,7 @@ func (s SqlChannelStore) GetMemberCount(channelId string, allowFromCache bool) (
// GetMemberCountsByGroup returns a slice of ChannelMemberCountByGroup for a given channel // GetMemberCountsByGroup returns a slice of ChannelMemberCountByGroup for a given channel
// which contains the number of channel members for each group and optionally the number of unique timezones present for each group in the channel // which contains the number of channel members for each group and optionally the number of unique timezones present for each group in the channel
func (s SqlChannelStore) GetMemberCountsByGroup(channelID string, includeTimezones bool) ([]*model.ChannelMemberCountByGroup, *model.AppError) { func (s SqlChannelStore) GetMemberCountsByGroup(channelID string, includeTimezones bool) ([]*model.ChannelMemberCountByGroup, error) {
selectStr := "GroupMembers.GroupId, COUNT(ChannelMembers.UserId) AS ChannelMemberCount" selectStr := "GroupMembers.GroupId, COUNT(ChannelMembers.UserId) AS ChannelMemberCount"
if includeTimezones { if includeTimezones {
@@ -1954,11 +1930,11 @@ func (s SqlChannelStore) GetMemberCountsByGroup(channelID string, includeTimezon
queryString, args, err := query.ToSql() queryString, args, err := query.ToSql()
if err != nil { if err != nil {
return nil, model.NewAppError("SqlChannelStore.GetMemberCountsByGroup", "store.sql.build_query.app_error", nil, err.Error(), http.StatusInternalServerError) return nil, errors.Wrap(err, "channel_tosql")
} }
var data []*model.ChannelMemberCountByGroup var data []*model.ChannelMemberCountByGroup
if _, err = s.GetReplica().Select(&data, queryString, args...); err != nil { if _, err = s.GetReplica().Select(&data, queryString, args...); err != nil {
return nil, model.NewAppError("SqlChannelStore.GetMemberCountsByGroup", "store.sql_channel.get_member_count.app_error", nil, "channel_id="+channelID+", "+err.Error(), http.StatusInternalServerError) return nil, errors.Wrapf(err, "failed to count ChannelMembers with channelId=%s", channelID)
} }
return data, nil return data, nil
@@ -1967,7 +1943,7 @@ func (s SqlChannelStore) GetMemberCountsByGroup(channelID string, includeTimezon
func (s SqlChannelStore) InvalidatePinnedPostCount(channelId string) { func (s SqlChannelStore) InvalidatePinnedPostCount(channelId string) {
} }
func (s SqlChannelStore) GetPinnedPostCount(channelId string, allowFromCache bool) (int64, *model.AppError) { func (s SqlChannelStore) GetPinnedPostCount(channelId string, allowFromCache bool) (int64, error) {
count, err := s.GetReplica().SelectInt(` count, err := s.GetReplica().SelectInt(`
SELECT count(*) SELECT count(*)
FROM Posts FROM Posts
@@ -1977,7 +1953,7 @@ func (s SqlChannelStore) GetPinnedPostCount(channelId string, allowFromCache boo
AND DeleteAt = 0`, map[string]interface{}{"ChannelId": channelId}) AND DeleteAt = 0`, map[string]interface{}{"ChannelId": channelId})
if err != nil { if err != nil {
return 0, model.NewAppError("SqlChannelStore.GetPinnedPostCount", "store.sql_channel.get_pinnedpost_count.app_error", nil, "channel_id="+channelId+", "+err.Error(), http.StatusInternalServerError) return 0, errors.Wrapf(err, "failed to count pinned Posts with channelId=%s", channelId)
} }
return count, nil return count, nil
@@ -1986,7 +1962,7 @@ func (s SqlChannelStore) GetPinnedPostCount(channelId string, allowFromCache boo
func (s SqlChannelStore) InvalidateGuestCount(channelId string) { func (s SqlChannelStore) InvalidateGuestCount(channelId string) {
} }
func (s SqlChannelStore) GetGuestCount(channelId string, allowFromCache bool) (int64, *model.AppError) { func (s SqlChannelStore) GetGuestCount(channelId string, allowFromCache bool) (int64, error) {
count, err := s.GetReplica().SelectInt(` count, err := s.GetReplica().SelectInt(`
SELECT SELECT
count(*) count(*)
@@ -1999,43 +1975,43 @@ func (s SqlChannelStore) GetGuestCount(channelId string, allowFromCache bool) (i
AND ChannelMembers.SchemeGuest = TRUE AND ChannelMembers.SchemeGuest = TRUE
AND Users.DeleteAt = 0`, map[string]interface{}{"ChannelId": channelId}) AND Users.DeleteAt = 0`, map[string]interface{}{"ChannelId": channelId})
if err != nil { if err != nil {
return 0, model.NewAppError("SqlChannelStore.GetGuestCount", "store.sql_channel.get_member_count.app_error", nil, "channel_id="+channelId+", "+err.Error(), http.StatusInternalServerError) return 0, errors.Wrapf(err, "failed to count Guests with channelId=%s", channelId)
} }
return count, nil return count, nil
} }
func (s SqlChannelStore) RemoveMembers(channelId string, userIds []string) *model.AppError { func (s SqlChannelStore) RemoveMembers(channelId string, userIds []string) error {
query := s.getQueryBuilder(). builder := s.getQueryBuilder().
Delete("ChannelMembers"). Delete("ChannelMembers").
Where(sq.Eq{"ChannelId": channelId}). Where(sq.Eq{"ChannelId": channelId}).
Where(sq.Eq{"UserId": userIds}) Where(sq.Eq{"UserId": userIds})
sql, args, err := query.ToSql() query, args, err := builder.ToSql()
if err != nil { if err != nil {
return model.NewAppError("SqlChannelStore.RemoveMember", "store.sql_channel.remove_member.app_error", nil, "channel_id="+channelId+", "+err.Error(), http.StatusInternalServerError) return errors.Wrap(err, "channel_tosql")
} }
_, err = s.GetMaster().Exec(sql, args...) _, err = s.GetMaster().Exec(query, args...)
if err != nil { if err != nil {
return model.NewAppError("SqlChannelStore.RemoveMember", "store.sql_channel.remove_member.app_error", nil, "channel_id="+channelId+", "+err.Error(), http.StatusInternalServerError) return errors.Wrap(err, "failed to delete ChannelMembers")
} }
// cleanup sidebarchannels table if the user is no longer a member of that channel // cleanup sidebarchannels table if the user is no longer a member of that channel
sql, args, err = s.getQueryBuilder(). query, args, err = s.getQueryBuilder().
Delete("SidebarChannels"). Delete("SidebarChannels").
Where(sq.And{ Where(sq.And{
sq.Eq{"ChannelId": channelId}, sq.Eq{"ChannelId": channelId},
sq.Eq{"UserId": userIds}, sq.Eq{"UserId": userIds},
}).ToSql() }).ToSql()
if err != nil { if err != nil {
return model.NewAppError("SqlChannelStore.RemoveMember", "store.sql_channel.remove_member.app_error", nil, "channel_id="+channelId+", "+err.Error(), http.StatusInternalServerError) return errors.Wrap(err, "channel_tosql")
} }
_, err = s.GetMaster().Exec(sql, args...) _, err = s.GetMaster().Exec(query, args...)
if err != nil { if err != nil {
return model.NewAppError("SqlChannelStore.RemoveMember", "store.sql_channel.remove_member.app_error", nil, "channel_id="+channelId+", "+err.Error(), http.StatusInternalServerError) return errors.Wrap(err, "failed to delete SidebarChannels")
} }
return nil return nil
} }
func (s SqlChannelStore) RemoveMember(channelId string, userId string) *model.AppError { func (s SqlChannelStore) RemoveMember(channelId string, userId string) error {
return s.RemoveMembers(channelId, []string{userId}) return s.RemoveMembers(channelId, []string{userId})
} }
@@ -2064,14 +2040,14 @@ func (s SqlChannelStore) RemoveAllDeactivatedMembers(channelId string) *model.Ap
return nil return nil
} }
func (s SqlChannelStore) PermanentDeleteMembersByUser(userId string) *model.AppError { func (s SqlChannelStore) PermanentDeleteMembersByUser(userId string) error {
if _, err := s.GetMaster().Exec("DELETE FROM ChannelMembers WHERE UserId = :UserId", map[string]interface{}{"UserId": userId}); err != nil { if _, err := s.GetMaster().Exec("DELETE FROM ChannelMembers WHERE UserId = :UserId", map[string]interface{}{"UserId": userId}); err != nil {
return model.NewAppError("SqlChannelStore.ChannelPermanentDeleteMembersByUser", "store.sql_channel.permanent_delete_members_by_user.app_error", nil, "user_id="+userId+", "+err.Error(), http.StatusInternalServerError) return errors.Wrapf(err, "failed to permanent delete ChannelMembers with userId=%s", userId)
} }
return nil return nil
} }
func (s SqlChannelStore) UpdateLastViewedAt(channelIds []string, userId string) (map[string]int64, *model.AppError) { func (s SqlChannelStore) UpdateLastViewedAt(channelIds []string, userId string) (map[string]int64, error) {
keys, props := MapStringsToQueryParams(channelIds, "Channel") keys, props := MapStringsToQueryParams(channelIds, "Channel")
props["UserId"] = userId props["UserId"] = userId
@@ -2101,21 +2077,12 @@ func (s SqlChannelStore) UpdateLastViewedAt(channelIds []string, userId string)
} }
_, err := s.GetMaster().Select(&lastPostAtTimes, query, props) _, err := s.GetMaster().Select(&lastPostAtTimes, query, props)
if err != nil || len(lastPostAtTimes) == 0 { if err != nil {
status := http.StatusInternalServerError return nil, errors.Wrapf(err, "failed to find ChannelMembers data with userId=%s and channelId in %v", userId, channelIds)
var extra string }
if err == nil {
status = http.StatusBadRequest
extra = "No channels found"
} else {
extra = err.Error()
}
return nil, model.NewAppError("SqlChannelStore.UpdateLastViewedAt", if len(lastPostAtTimes) == 0 {
"store.sql_channel.update_last_viewed_at.app_error", return nil, store.NewErrInvalidInput("Channel", "Id", fmt.Sprintf("%v", channelIds))
nil,
"channel_ids="+strings.Join(channelIds, ",")+", user_id="+userId+", "+extra,
status)
} }
times := map[string]int64{} times := map[string]int64{}
@@ -2152,14 +2119,14 @@ func (s SqlChannelStore) UpdateLastViewedAt(channelIds []string, userId string)
AND ChannelId IN ` + keys AND ChannelId IN ` + keys
if _, err := s.GetMaster().Exec(updateQuery, props); err != nil { if _, err := s.GetMaster().Exec(updateQuery, props); err != nil {
return nil, model.NewAppError("SqlChannelStore.UpdateLastViewedAt", "store.sql_channel.update_last_viewed_at.app_error", nil, "channel_ids="+strings.Join(channelIds, ",")+", user_id="+userId+", "+err.Error(), http.StatusInternalServerError) return nil, errors.Wrapf(err, "failed to update ChannelMembers with userId=%s and channelId in %v", userId, channelIds)
} }
return times, nil return times, nil
} }
// CountPostsAfter returns the number of posts in the given channel created after but not including the given timestamp. If given a non-empty user ID, only counts posts made by that user. // CountPostsAfter returns the number of posts in the given channel created after but not including the given timestamp. If given a non-empty user ID, only counts posts made by that user.
func (s SqlChannelStore) CountPostsAfter(channelId string, timestamp int64, userId string) (int, *model.AppError) { func (s SqlChannelStore) CountPostsAfter(channelId string, timestamp int64, userId string) (int, error) {
joinLeavePostTypes, params := MapStringsToQueryParams([]string{ joinLeavePostTypes, params := MapStringsToQueryParams([]string{
// These types correspond to the ones checked by Post.IsJoinLeaveMessage // These types correspond to the ones checked by Post.IsJoinLeaveMessage
model.POST_JOIN_LEAVE, model.POST_JOIN_LEAVE,
@@ -2194,7 +2161,7 @@ func (s SqlChannelStore) CountPostsAfter(channelId string, timestamp int64, user
unread, err := s.GetReplica().SelectInt(query, params) unread, err := s.GetReplica().SelectInt(query, params)
if err != nil { if err != nil {
return 0, model.NewAppError("SqlChannelStore.CountPostsAfter", "store.sql_channel.count_posts_since.app_error", nil, fmt.Sprintf("channel_id=%s, timestamp=%d, err=%s", channelId, timestamp, err), http.StatusInternalServerError) return 0, errors.Wrap(err, "failed to count Posts")
} }
return int(unread), nil return int(unread), nil
} }
@@ -2202,12 +2169,12 @@ func (s SqlChannelStore) CountPostsAfter(channelId string, timestamp int64, user
// UpdateLastViewedAtPost updates a ChannelMember as if the user last read the channel at the time of the given post. // UpdateLastViewedAtPost updates a ChannelMember as if the user last read the channel at the time of the given post.
// If the provided mentionCount is -1, the given post and all posts after it are considered to be mentions. Returns // If the provided mentionCount is -1, the given post and all posts after it are considered to be mentions. Returns
// an updated model.ChannelUnreadAt that can be returned to the client. // an updated model.ChannelUnreadAt that can be returned to the client.
func (s SqlChannelStore) UpdateLastViewedAtPost(unreadPost *model.Post, userID string, mentionCount int) (*model.ChannelUnreadAt, *model.AppError) { func (s SqlChannelStore) UpdateLastViewedAtPost(unreadPost *model.Post, userID string, mentionCount int) (*model.ChannelUnreadAt, error) {
unreadDate := unreadPost.CreateAt - 1 unreadDate := unreadPost.CreateAt - 1
unread, appErr := s.CountPostsAfter(unreadPost.ChannelId, unreadDate, "") unread, err := s.CountPostsAfter(unreadPost.ChannelId, unreadDate, "")
if appErr != nil { if err != nil {
return nil, appErr return nil, err
} }
params := map[string]interface{}{ params := map[string]interface{}{
@@ -2233,9 +2200,9 @@ func (s SqlChannelStore) UpdateLastViewedAtPost(unreadPost *model.Post, userID s
UserId = :userId UserId = :userId
AND ChannelId = :channelId AND ChannelId = :channelId
` `
_, err := s.GetMaster().Exec(setUnreadQuery, params) _, err = s.GetMaster().Exec(setUnreadQuery, params)
if err != nil { if err != nil {
return nil, model.NewAppError("SqlChannelStore.UpdateLastViewedAtPost", "store.sql_channel.update_last_viewed_at_post.app_error", params, "Error setting channel "+unreadPost.ChannelId+" as unread: "+err.Error(), http.StatusInternalServerError) return nil, errors.Wrap(err, "failed to update ChannelMembers")
} }
chanUnreadQuery := ` chanUnreadQuery := `
@@ -2257,12 +2224,12 @@ func (s SqlChannelStore) UpdateLastViewedAtPost(unreadPost *model.Post, userID s
` `
result := &model.ChannelUnreadAt{} result := &model.ChannelUnreadAt{}
if err = s.GetMaster().SelectOne(result, chanUnreadQuery, params); err != nil { if err = s.GetMaster().SelectOne(result, chanUnreadQuery, params); err != nil {
return nil, model.NewAppError("SqlChannelStore.UpdateLastViewedAtPost", "store.sql_channel.update_last_viewed_at_post.app_error", params, "Error retrieving unread status from channel "+unreadPost.ChannelId+", error was: "+err.Error(), http.StatusInternalServerError) return nil, errors.Wrapf(err, "failed to get ChannelMember with channelId=%s", unreadPost.ChannelId)
} }
return result, nil return result, nil
} }
func (s SqlChannelStore) IncrementMentionCount(channelId string, userId string) *model.AppError { func (s SqlChannelStore) IncrementMentionCount(channelId string, userId string) error {
_, err := s.GetMaster().Exec( _, err := s.GetMaster().Exec(
`UPDATE `UPDATE
ChannelMembers ChannelMembers
@@ -2274,7 +2241,7 @@ func (s SqlChannelStore) IncrementMentionCount(channelId string, userId string)
AND ChannelId = :ChannelId`, AND ChannelId = :ChannelId`,
map[string]interface{}{"ChannelId": channelId, "UserId": userId, "LastUpdateAt": model.GetMillis()}) map[string]interface{}{"ChannelId": channelId, "UserId": userId, "LastUpdateAt": model.GetMillis()})
if err != nil { if err != nil {
return model.NewAppError("SqlChannelStore.IncrementMentionCount", "store.sql_channel.increment_mention_count.app_error", nil, "channel_id="+channelId+", user_id="+userId+", "+err.Error(), http.StatusInternalServerError) return errors.Wrapf(err, "failed to Update ChannelMembers with channelId=%s and userId=%s", channelId, userId)
} }
return nil return nil
@@ -2325,7 +2292,7 @@ func (s SqlChannelStore) GetForPost(postId string) (*model.Channel, error) {
return channel, nil return channel, nil
} }
func (s SqlChannelStore) AnalyticsTypeCount(teamId string, channelType string) (int64, *model.AppError) { func (s SqlChannelStore) AnalyticsTypeCount(teamId string, channelType string) (int64, error) {
query := "SELECT COUNT(Id) AS Value FROM Channels WHERE Type = :ChannelType" query := "SELECT COUNT(Id) AS Value FROM Channels WHERE Type = :ChannelType"
if len(teamId) > 0 { if len(teamId) > 0 {
@@ -2334,7 +2301,7 @@ func (s SqlChannelStore) AnalyticsTypeCount(teamId string, channelType string) (
value, err := s.GetReplica().SelectInt(query, map[string]interface{}{"TeamId": teamId, "ChannelType": channelType}) value, err := s.GetReplica().SelectInt(query, map[string]interface{}{"TeamId": teamId, "ChannelType": channelType})
if err != nil { if err != nil {
return int64(0), model.NewAppError("SqlChannelStore.AnalyticsTypeCount", "store.sql_channel.analytics_type_count.app_error", nil, err.Error(), http.StatusInternalServerError) return int64(0), errors.Wrap(err, "failed to count Channels")
} }
return value, nil return value, nil
} }
@@ -2354,23 +2321,23 @@ func (s SqlChannelStore) AnalyticsDeletedTypeCount(teamId string, channelType st
return v, nil return v, nil
} }
func (s SqlChannelStore) GetMembersForUser(teamId string, userId string) (*model.ChannelMembers, *model.AppError) { func (s SqlChannelStore) GetMembersForUser(teamId string, userId string) (*model.ChannelMembers, error) {
var dbMembers channelMemberWithSchemeRolesList var dbMembers channelMemberWithSchemeRolesList
_, err := s.GetReplica().Select(&dbMembers, CHANNEL_MEMBERS_WITH_SCHEME_SELECT_QUERY+"WHERE ChannelMembers.UserId = :UserId AND (Teams.Id = :TeamId OR Teams.Id = '' OR Teams.Id IS NULL)", map[string]interface{}{"TeamId": teamId, "UserId": userId}) _, err := s.GetReplica().Select(&dbMembers, CHANNEL_MEMBERS_WITH_SCHEME_SELECT_QUERY+"WHERE ChannelMembers.UserId = :UserId AND (Teams.Id = :TeamId OR Teams.Id = '' OR Teams.Id IS NULL)", map[string]interface{}{"TeamId": teamId, "UserId": userId})
if err != nil { if err != nil {
return nil, model.NewAppError("SqlChannelStore.GetMembersForUser", "store.sql_channel.get_members.app_error", nil, "teamId="+teamId+", userId="+userId+", err="+err.Error(), http.StatusInternalServerError) return nil, errors.Wrapf(err, "failed to find ChannelMembers data with teamId=%s and userId=%s", teamId, userId)
} }
return dbMembers.ToModel(), nil return dbMembers.ToModel(), nil
} }
func (s SqlChannelStore) GetMembersForUserWithPagination(teamId, userId string, page, perPage int) (*model.ChannelMembers, *model.AppError) { func (s SqlChannelStore) GetMembersForUserWithPagination(teamId, userId string, page, perPage int) (*model.ChannelMembers, error) {
var dbMembers channelMemberWithSchemeRolesList var dbMembers channelMemberWithSchemeRolesList
offset := page * perPage offset := page * perPage
_, err := s.GetReplica().Select(&dbMembers, CHANNEL_MEMBERS_WITH_SCHEME_SELECT_QUERY+"WHERE ChannelMembers.UserId = :UserId Limit :Limit Offset :Offset", map[string]interface{}{"TeamId": teamId, "UserId": userId, "Limit": perPage, "Offset": offset}) _, err := s.GetReplica().Select(&dbMembers, CHANNEL_MEMBERS_WITH_SCHEME_SELECT_QUERY+"WHERE ChannelMembers.UserId = :UserId Limit :Limit Offset :Offset", map[string]interface{}{"TeamId": teamId, "UserId": userId, "Limit": perPage, "Offset": offset})
if err != nil { if err != nil {
return nil, model.NewAppError("SqlChannelStore.GetMembersForUserWithPagination", "store.sql_channel.get_members.app_error", nil, "teamId="+teamId+", userId="+userId+", err="+err.Error(), http.StatusInternalServerError) return nil, errors.Wrapf(err, "failed to find ChannelMembers data with teamId=%s and userId=%s", teamId, userId)
} }
return dbMembers.ToModel(), nil return dbMembers.ToModel(), nil
@@ -3175,7 +3142,7 @@ func (s SqlChannelStore) GetChannelMembersForExport(userId string, teamId string
map[string]interface{}{"TeamId": teamId, "UserId": userId}) map[string]interface{}{"TeamId": teamId, "UserId": userId})
if err != nil { if err != nil {
return nil, model.NewAppError("SqlChannelStore.GetChannelMembersForExport", "store.sql_channel.get_members.app_error", nil, "teamId="+teamId+", userId="+userId+", err="+err.Error(), http.StatusInternalServerError) return nil, model.NewAppError("SqlChannelStore.GetChannelMembersForExport", "app.channel.get_members.app_error", nil, "teamId="+teamId+", userId="+userId+", err="+err.Error(), http.StatusInternalServerError)
} }
return members, nil return members, nil

Просмотреть файл

@@ -162,39 +162,39 @@ type ChannelStore interface {
GetAll(teamId string) ([]*model.Channel, error) GetAll(teamId string) ([]*model.Channel, error)
GetChannelsByIds(channelIds []string, includeDeleted bool) ([]*model.Channel, error) GetChannelsByIds(channelIds []string, includeDeleted bool) ([]*model.Channel, error)
GetForPost(postId string) (*model.Channel, error) GetForPost(postId string) (*model.Channel, error)
SaveMultipleMembers(members []*model.ChannelMember) ([]*model.ChannelMember, *model.AppError) SaveMultipleMembers(members []*model.ChannelMember) ([]*model.ChannelMember, error)
SaveMember(member *model.ChannelMember) (*model.ChannelMember, *model.AppError) SaveMember(member *model.ChannelMember) (*model.ChannelMember, error)
UpdateMember(member *model.ChannelMember) (*model.ChannelMember, *model.AppError) UpdateMember(member *model.ChannelMember) (*model.ChannelMember, error)
UpdateMultipleMembers(members []*model.ChannelMember) ([]*model.ChannelMember, *model.AppError) UpdateMultipleMembers(members []*model.ChannelMember) ([]*model.ChannelMember, error)
GetMembers(channelId string, offset, limit int) (*model.ChannelMembers, *model.AppError) GetMembers(channelId string, offset, limit int) (*model.ChannelMembers, error)
GetMember(channelId string, userId string) (*model.ChannelMember, *model.AppError) GetMember(channelId string, userId string) (*model.ChannelMember, error)
GetChannelMembersTimezones(channelId string) ([]model.StringMap, *model.AppError) GetChannelMembersTimezones(channelId string) ([]model.StringMap, error)
GetAllChannelMembersForUser(userId string, allowFromCache bool, includeDeleted bool) (map[string]string, *model.AppError) GetAllChannelMembersForUser(userId string, allowFromCache bool, includeDeleted bool) (map[string]string, error)
InvalidateAllChannelMembersForUser(userId string) InvalidateAllChannelMembersForUser(userId string)
IsUserInChannelUseCache(userId string, channelId string) bool IsUserInChannelUseCache(userId string, channelId string) bool
GetAllChannelMembersNotifyPropsForChannel(channelId string, allowFromCache bool) (map[string]model.StringMap, *model.AppError) GetAllChannelMembersNotifyPropsForChannel(channelId string, allowFromCache bool) (map[string]model.StringMap, error)
InvalidateCacheForChannelMembersNotifyProps(channelId string) InvalidateCacheForChannelMembersNotifyProps(channelId string)
GetMemberForPost(postId string, userId string) (*model.ChannelMember, *model.AppError) GetMemberForPost(postId string, userId string) (*model.ChannelMember, error)
InvalidateMemberCount(channelId string) InvalidateMemberCount(channelId string)
GetMemberCountFromCache(channelId string) int64 GetMemberCountFromCache(channelId string) int64
GetMemberCount(channelId string, allowFromCache bool) (int64, *model.AppError) GetMemberCount(channelId string, allowFromCache bool) (int64, error)
GetMemberCountsByGroup(channelID string, includeTimezones bool) ([]*model.ChannelMemberCountByGroup, *model.AppError) GetMemberCountsByGroup(channelID string, includeTimezones bool) ([]*model.ChannelMemberCountByGroup, error)
InvalidatePinnedPostCount(channelId string) InvalidatePinnedPostCount(channelId string)
GetPinnedPostCount(channelId string, allowFromCache bool) (int64, *model.AppError) GetPinnedPostCount(channelId string, allowFromCache bool) (int64, error)
InvalidateGuestCount(channelId string) InvalidateGuestCount(channelId string)
GetGuestCount(channelId string, allowFromCache bool) (int64, *model.AppError) GetGuestCount(channelId string, allowFromCache bool) (int64, error)
GetPinnedPosts(channelId string) (*model.PostList, *model.AppError) GetPinnedPosts(channelId string) (*model.PostList, error)
RemoveMember(channelId string, userId string) *model.AppError RemoveMember(channelId string, userId string) error
RemoveMembers(channelId string, userIds []string) *model.AppError RemoveMembers(channelId string, userIds []string) error
PermanentDeleteMembersByUser(userId string) *model.AppError PermanentDeleteMembersByUser(userId string) error
PermanentDeleteMembersByChannel(channelId string) *model.AppError PermanentDeleteMembersByChannel(channelId string) error
UpdateLastViewedAt(channelIds []string, userId string) (map[string]int64, *model.AppError) UpdateLastViewedAt(channelIds []string, userId string) (map[string]int64, error)
UpdateLastViewedAtPost(unreadPost *model.Post, userID string, mentionCount int) (*model.ChannelUnreadAt, *model.AppError) UpdateLastViewedAtPost(unreadPost *model.Post, userID string, mentionCount int) (*model.ChannelUnreadAt, error)
CountPostsAfter(channelId string, timestamp int64, userId string) (int, *model.AppError) CountPostsAfter(channelId string, timestamp int64, userId string) (int, error)
IncrementMentionCount(channelId string, userId string) *model.AppError IncrementMentionCount(channelId string, userId string) error
AnalyticsTypeCount(teamId string, channelType string) (int64, *model.AppError) AnalyticsTypeCount(teamId string, channelType string) (int64, error)
GetMembersForUser(teamId string, userId string) (*model.ChannelMembers, *model.AppError) GetMembersForUser(teamId string, userId string) (*model.ChannelMembers, error)
GetMembersForUserWithPagination(teamId, userId string, page, perPage int) (*model.ChannelMembers, *model.AppError) GetMembersForUserWithPagination(teamId, userId string, page, perPage int) (*model.ChannelMembers, error)
AutocompleteInTeam(teamId string, term string, includeDeleted bool) (*model.ChannelList, *model.AppError) AutocompleteInTeam(teamId string, term string, includeDeleted bool) (*model.ChannelList, *model.AppError)
AutocompleteInTeamForSearch(teamId string, userId string, term string, includeDeleted bool) (*model.ChannelList, *model.AppError) AutocompleteInTeamForSearch(teamId string, userId string, term string, includeDeleted bool) (*model.ChannelList, *model.AppError)
SearchAllChannels(term string, opts ChannelSearchOpts) (*model.ChannelListWithTeamData, int64, *model.AppError) SearchAllChannels(term string, opts ChannelSearchOpts) (*model.ChannelListWithTeamData, int64, *model.AppError)

Просмотреть файл

@@ -198,8 +198,8 @@ func testChannelStoreSaveDirectChannel(t *testing.T, ss store.Store, s SqlSuppli
_, nErr = ss.Channel().SaveDirectChannel(&o1, &m1, &m2) _, nErr = ss.Channel().SaveDirectChannel(&o1, &m1, &m2)
require.Nil(t, nErr, "couldn't save direct channel", nErr) require.Nil(t, nErr, "couldn't save direct channel", nErr)
members, err := ss.Channel().GetMembers(o1.Id, 0, 100) members, nErr := ss.Channel().GetMembers(o1.Id, 0, 100)
require.Nil(t, err) require.Nil(t, nErr)
require.Len(t, *members, 2, "should have saved 2 members") require.Len(t, *members, 2, "should have saved 2 members")
_, nErr = ss.Channel().SaveDirectChannel(&o1, &m1, &m2) _, nErr = ss.Channel().SaveDirectChannel(&o1, &m1, &m2)
@@ -234,8 +234,8 @@ func testChannelStoreSaveDirectChannel(t *testing.T, ss store.Store, s SqlSuppli
_, nErr = ss.Channel().SaveDirectChannel(&o1, &m1, &m1) _, nErr = ss.Channel().SaveDirectChannel(&o1, &m1, &m1)
require.Nil(t, nErr, "couldn't save direct channel", nErr) require.Nil(t, nErr, "couldn't save direct channel", nErr)
members, err = ss.Channel().GetMembers(o1.Id, 0, 100) members, nErr = ss.Channel().GetMembers(o1.Id, 0, 100)
require.Nil(t, err) require.Nil(t, nErr)
require.Len(t, *members, 1, "should have saved just 1 member") require.Len(t, *members, 1, "should have saved just 1 member")
// Manually truncate Channels table until testlib can handle cleanups // Manually truncate Channels table until testlib can handle cleanups
@@ -266,8 +266,8 @@ func testChannelStoreCreateDirectChannel(t *testing.T, ss store.Store) {
ss.Channel().PermanentDelete(c1.Id) ss.Channel().PermanentDelete(c1.Id)
}() }()
members, err := ss.Channel().GetMembers(c1.Id, 0, 100) members, nErr := ss.Channel().GetMembers(c1.Id, 0, 100)
require.Nil(t, err) require.Nil(t, nErr)
require.Len(t, *members, 2, "should have saved 2 members") require.Len(t, *members, 2, "should have saved 2 members")
} }
@@ -838,25 +838,25 @@ func testChannelMemberStore(t *testing.T, ss store.Store) {
o1.ChannelId = c1.Id o1.ChannelId = c1.Id
o1.UserId = u1.Id o1.UserId = u1.Id
o1.NotifyProps = model.GetDefaultChannelNotifyProps() o1.NotifyProps = model.GetDefaultChannelNotifyProps()
_, err = ss.Channel().SaveMember(&o1) _, nErr = ss.Channel().SaveMember(&o1)
require.Nil(t, err) require.Nil(t, nErr)
o2 := model.ChannelMember{} o2 := model.ChannelMember{}
o2.ChannelId = c1.Id o2.ChannelId = c1.Id
o2.UserId = u2.Id o2.UserId = u2.Id
o2.NotifyProps = model.GetDefaultChannelNotifyProps() o2.NotifyProps = model.GetDefaultChannelNotifyProps()
_, err = ss.Channel().SaveMember(&o2) _, nErr = ss.Channel().SaveMember(&o2)
require.Nil(t, err) require.Nil(t, nErr)
c1t2, _ := ss.Channel().Get(c1.Id, false) c1t2, _ := ss.Channel().Get(c1.Id, false)
assert.EqualValues(t, 0, c1t2.ExtraUpdateAt, "ExtraUpdateAt should be 0") assert.EqualValues(t, 0, c1t2.ExtraUpdateAt, "ExtraUpdateAt should be 0")
count, err := ss.Channel().GetMemberCount(o1.ChannelId, true) count, nErr := ss.Channel().GetMemberCount(o1.ChannelId, true)
require.Nil(t, err) require.Nil(t, nErr)
require.EqualValues(t, 2, count, "should have saved 2 members") require.EqualValues(t, 2, count, "should have saved 2 members")
count, err = ss.Channel().GetMemberCount(o1.ChannelId, true) count, nErr = ss.Channel().GetMemberCount(o1.ChannelId, true)
require.Nil(t, err) require.Nil(t, nErr)
require.EqualValues(t, 2, count, "should have saved 2 members") require.EqualValues(t, 2, count, "should have saved 2 members")
require.EqualValues( require.EqualValues(
t, t,
@@ -870,15 +870,15 @@ func testChannelMemberStore(t *testing.T, ss store.Store) {
ss.Channel().GetMemberCountFromCache("junk"), ss.Channel().GetMemberCountFromCache("junk"),
"should have saved 0 members") "should have saved 0 members")
count, err = ss.Channel().GetMemberCount(o1.ChannelId, false) count, nErr = ss.Channel().GetMemberCount(o1.ChannelId, false)
require.Nil(t, err) require.Nil(t, nErr)
require.EqualValues(t, 2, count, "should have saved 2 members") require.EqualValues(t, 2, count, "should have saved 2 members")
err = ss.Channel().RemoveMember(o2.ChannelId, o2.UserId) nErr = ss.Channel().RemoveMember(o2.ChannelId, o2.UserId)
require.Nil(t, err) require.Nil(t, nErr)
count, err = ss.Channel().GetMemberCount(o1.ChannelId, false) count, nErr = ss.Channel().GetMemberCount(o1.ChannelId, false)
require.Nil(t, err) require.Nil(t, nErr)
require.EqualValues(t, 1, count, "should have removed 1 member") require.EqualValues(t, 1, count, "should have removed 1 member")
c1t3, _ := ss.Channel().Get(c1.Id, false) c1t3, _ := ss.Channel().Get(c1.Id, false)
@@ -887,8 +887,8 @@ func testChannelMemberStore(t *testing.T, ss store.Store) {
member, _ := ss.Channel().GetMember(o1.ChannelId, o1.UserId) member, _ := ss.Channel().GetMember(o1.ChannelId, o1.UserId)
require.Equal(t, o1.ChannelId, member.ChannelId, "should have go member") require.Equal(t, o1.ChannelId, member.ChannelId, "should have go member")
_, err = ss.Channel().SaveMember(&o1) _, nErr = ss.Channel().SaveMember(&o1)
require.NotNil(t, err, "should have been a duplicate") require.NotNil(t, nErr, "should have been a duplicate")
c1t4, _ := ss.Channel().Get(c1.Id, false) c1t4, _ := ss.Channel().Get(c1.Id, false)
assert.EqualValues(t, 0, c1t4.ExtraUpdateAt, "ExtraUpdateAt should be 0") assert.EqualValues(t, 0, c1t4.ExtraUpdateAt, "ExtraUpdateAt should be 0")
@@ -901,20 +901,22 @@ func testChannelSaveMember(t *testing.T, ss store.Store) {
t.Run("not valid channel member", func(t *testing.T) { t.Run("not valid channel member", func(t *testing.T) {
member := &model.ChannelMember{ChannelId: "wrong", UserId: u1.Id, NotifyProps: defaultNotifyProps} member := &model.ChannelMember{ChannelId: "wrong", UserId: u1.Id, NotifyProps: defaultNotifyProps}
_, err = ss.Channel().SaveMember(member) _, nErr := ss.Channel().SaveMember(member)
require.NotNil(t, err) require.NotNil(t, nErr)
require.Equal(t, "model.channel_member.is_valid.channel_id.app_error", err.Id) var appErr *model.AppError
require.True(t, errors.As(nErr, &appErr))
require.Equal(t, "model.channel_member.is_valid.channel_id.app_error", appErr.Id)
}) })
t.Run("duplicated entries should fail", func(t *testing.T) { t.Run("duplicated entries should fail", func(t *testing.T) {
channelID1 := model.NewId() channelID1 := model.NewId()
m1 := &model.ChannelMember{ChannelId: channelID1, UserId: u1.Id, NotifyProps: defaultNotifyProps} m1 := &model.ChannelMember{ChannelId: channelID1, UserId: u1.Id, NotifyProps: defaultNotifyProps}
_, err = ss.Channel().SaveMember(m1) _, nErr := ss.Channel().SaveMember(m1)
require.Nil(t, err) require.Nil(t, nErr)
m2 := &model.ChannelMember{ChannelId: channelID1, UserId: u1.Id, NotifyProps: defaultNotifyProps} m2 := &model.ChannelMember{ChannelId: channelID1, UserId: u1.Id, NotifyProps: defaultNotifyProps}
_, err = ss.Channel().SaveMember(m2) _, nErr = ss.Channel().SaveMember(m2)
require.NotNil(t, err) require.NotNil(t, nErr)
require.Equal(t, "store.sql_channel.save_member.exists.app_error", err.Id) require.IsType(t, &store.ErrConflict{}, nErr)
}) })
t.Run("insert member correctly (in channel without channel scheme and team without scheme)", func(t *testing.T) { t.Run("insert member correctly (in channel without channel scheme and team without scheme)", func(t *testing.T) {
@@ -1056,8 +1058,8 @@ func testChannelSaveMember(t *testing.T, ss store.Store) {
ExplicitRoles: tc.ExplicitRoles, ExplicitRoles: tc.ExplicitRoles,
NotifyProps: defaultNotifyProps, NotifyProps: defaultNotifyProps,
} }
member, err = ss.Channel().SaveMember(member) member, nErr = ss.Channel().SaveMember(member)
require.Nil(t, err) require.Nil(t, nErr)
defer ss.Channel().RemoveMember(channel.Id, u1.Id) defer ss.Channel().RemoveMember(channel.Id, u1.Id)
assert.Equal(t, tc.ExpectedRoles, member.Roles) assert.Equal(t, tc.ExpectedRoles, member.Roles)
assert.Equal(t, tc.ExpectedExplicitRoles, member.ExplicitRoles) assert.Equal(t, tc.ExpectedExplicitRoles, member.ExplicitRoles)
@@ -1217,8 +1219,8 @@ func testChannelSaveMember(t *testing.T, ss store.Store) {
ExplicitRoles: tc.ExplicitRoles, ExplicitRoles: tc.ExplicitRoles,
NotifyProps: defaultNotifyProps, NotifyProps: defaultNotifyProps,
} }
member, err = ss.Channel().SaveMember(member) member, nErr = ss.Channel().SaveMember(member)
require.Nil(t, err) require.Nil(t, nErr)
defer ss.Channel().RemoveMember(channel.Id, u1.Id) defer ss.Channel().RemoveMember(channel.Id, u1.Id)
assert.Equal(t, tc.ExpectedRoles, member.Roles) assert.Equal(t, tc.ExpectedRoles, member.Roles)
assert.Equal(t, tc.ExpectedExplicitRoles, member.ExplicitRoles) assert.Equal(t, tc.ExpectedExplicitRoles, member.ExplicitRoles)
@@ -1377,8 +1379,8 @@ func testChannelSaveMember(t *testing.T, ss store.Store) {
ExplicitRoles: tc.ExplicitRoles, ExplicitRoles: tc.ExplicitRoles,
NotifyProps: defaultNotifyProps, NotifyProps: defaultNotifyProps,
} }
member, err = ss.Channel().SaveMember(member) member, nErr = ss.Channel().SaveMember(member)
require.Nil(t, err) require.Nil(t, nErr)
defer ss.Channel().RemoveMember(channel.Id, u1.Id) defer ss.Channel().RemoveMember(channel.Id, u1.Id)
assert.Equal(t, tc.ExpectedRoles, member.Roles) assert.Equal(t, tc.ExpectedRoles, member.Roles)
assert.Equal(t, tc.ExpectedExplicitRoles, member.ExplicitRoles) assert.Equal(t, tc.ExpectedExplicitRoles, member.ExplicitRoles)
@@ -1400,18 +1402,20 @@ func testChannelSaveMultipleMembers(t *testing.T, ss store.Store) {
t.Run("any not valid channel member", func(t *testing.T) { t.Run("any not valid channel member", func(t *testing.T) {
m1 := &model.ChannelMember{ChannelId: "wrong", UserId: u1.Id, NotifyProps: defaultNotifyProps} m1 := &model.ChannelMember{ChannelId: "wrong", UserId: u1.Id, NotifyProps: defaultNotifyProps}
m2 := &model.ChannelMember{ChannelId: model.NewId(), UserId: u2.Id, NotifyProps: defaultNotifyProps} m2 := &model.ChannelMember{ChannelId: model.NewId(), UserId: u2.Id, NotifyProps: defaultNotifyProps}
_, err = ss.Channel().SaveMultipleMembers([]*model.ChannelMember{m1, m2}) _, nErr := ss.Channel().SaveMultipleMembers([]*model.ChannelMember{m1, m2})
require.NotNil(t, err) require.NotNil(t, nErr)
require.Equal(t, "model.channel_member.is_valid.channel_id.app_error", err.Id) var appErr *model.AppError
require.True(t, errors.As(nErr, &appErr))
require.Equal(t, "model.channel_member.is_valid.channel_id.app_error", appErr.Id)
}) })
t.Run("duplicated entries should fail", func(t *testing.T) { t.Run("duplicated entries should fail", func(t *testing.T) {
channelID1 := model.NewId() channelID1 := model.NewId()
m1 := &model.ChannelMember{ChannelId: channelID1, UserId: u1.Id, NotifyProps: defaultNotifyProps} m1 := &model.ChannelMember{ChannelId: channelID1, UserId: u1.Id, NotifyProps: defaultNotifyProps}
m2 := &model.ChannelMember{ChannelId: channelID1, UserId: u1.Id, NotifyProps: defaultNotifyProps} m2 := &model.ChannelMember{ChannelId: channelID1, UserId: u1.Id, NotifyProps: defaultNotifyProps}
_, err = ss.Channel().SaveMultipleMembers([]*model.ChannelMember{m1, m2}) _, nErr := ss.Channel().SaveMultipleMembers([]*model.ChannelMember{m1, m2})
require.NotNil(t, err) require.NotNil(t, nErr)
require.Equal(t, "store.sql_channel.save_member.exists.app_error", err.Id) require.IsType(t, &store.ErrConflict{}, nErr)
}) })
t.Run("insert members correctly (in channel without channel scheme and team without scheme)", func(t *testing.T) { t.Run("insert members correctly (in channel without channel scheme and team without scheme)", func(t *testing.T) {
@@ -1563,8 +1567,8 @@ func testChannelSaveMultipleMembers(t *testing.T, ss store.Store) {
NotifyProps: defaultNotifyProps, NotifyProps: defaultNotifyProps,
} }
var members []*model.ChannelMember var members []*model.ChannelMember
members, err = ss.Channel().SaveMultipleMembers([]*model.ChannelMember{member, otherMember}) members, nErr = ss.Channel().SaveMultipleMembers([]*model.ChannelMember{member, otherMember})
require.Nil(t, err) require.Nil(t, nErr)
require.Len(t, members, 2) require.Len(t, members, 2)
member = members[0] member = members[0]
defer ss.Channel().RemoveMember(channel.Id, u1.Id) defer ss.Channel().RemoveMember(channel.Id, u1.Id)
@@ -1738,8 +1742,8 @@ func testChannelSaveMultipleMembers(t *testing.T, ss store.Store) {
NotifyProps: defaultNotifyProps, NotifyProps: defaultNotifyProps,
} }
var members []*model.ChannelMember var members []*model.ChannelMember
members, err = ss.Channel().SaveMultipleMembers([]*model.ChannelMember{member, otherMember}) members, nErr = ss.Channel().SaveMultipleMembers([]*model.ChannelMember{member, otherMember})
require.Nil(t, err) require.Nil(t, nErr)
require.Len(t, members, 2) require.Len(t, members, 2)
member = members[0] member = members[0]
defer ss.Channel().RemoveMember(channel.Id, u1.Id) defer ss.Channel().RemoveMember(channel.Id, u1.Id)
@@ -1935,9 +1939,11 @@ func testChannelUpdateMember(t *testing.T, ss store.Store) {
t.Run("not valid channel member", func(t *testing.T) { t.Run("not valid channel member", func(t *testing.T) {
member := &model.ChannelMember{ChannelId: "wrong", UserId: u1.Id, NotifyProps: defaultNotifyProps} member := &model.ChannelMember{ChannelId: "wrong", UserId: u1.Id, NotifyProps: defaultNotifyProps}
_, err = ss.Channel().UpdateMember(member) _, nErr := ss.Channel().UpdateMember(member)
require.NotNil(t, err) require.NotNil(t, nErr)
require.Equal(t, "model.channel_member.is_valid.channel_id.app_error", err.Id) var appErr *model.AppError
require.True(t, errors.As(nErr, &appErr))
require.Equal(t, "model.channel_member.is_valid.channel_id.app_error", appErr.Id)
}) })
t.Run("insert member correctly (in channel without channel scheme and team without scheme)", func(t *testing.T) { t.Run("insert member correctly (in channel without channel scheme and team without scheme)", func(t *testing.T) {
@@ -1966,8 +1972,8 @@ func testChannelUpdateMember(t *testing.T, ss store.Store) {
UserId: u1.Id, UserId: u1.Id,
NotifyProps: defaultNotifyProps, NotifyProps: defaultNotifyProps,
} }
member, err = ss.Channel().SaveMember(member) member, nErr = ss.Channel().SaveMember(member)
require.Nil(t, err) require.Nil(t, nErr)
testCases := []struct { testCases := []struct {
Name string Name string
@@ -2082,8 +2088,8 @@ func testChannelUpdateMember(t *testing.T, ss store.Store) {
member.SchemeUser = tc.SchemeUser member.SchemeUser = tc.SchemeUser
member.SchemeAdmin = tc.SchemeAdmin member.SchemeAdmin = tc.SchemeAdmin
member.ExplicitRoles = tc.ExplicitRoles member.ExplicitRoles = tc.ExplicitRoles
member, err = ss.Channel().UpdateMember(member) member, nErr = ss.Channel().UpdateMember(member)
require.Nil(t, err) require.Nil(t, nErr)
assert.Equal(t, tc.ExpectedRoles, member.Roles) assert.Equal(t, tc.ExpectedRoles, member.Roles)
assert.Equal(t, tc.ExpectedExplicitRoles, member.ExplicitRoles) assert.Equal(t, tc.ExpectedExplicitRoles, member.ExplicitRoles)
assert.Equal(t, tc.ExpectedSchemeGuest, member.SchemeGuest) assert.Equal(t, tc.ExpectedSchemeGuest, member.SchemeGuest)
@@ -2129,8 +2135,8 @@ func testChannelUpdateMember(t *testing.T, ss store.Store) {
UserId: u1.Id, UserId: u1.Id,
NotifyProps: defaultNotifyProps, NotifyProps: defaultNotifyProps,
} }
member, err = ss.Channel().SaveMember(member) member, nErr = ss.Channel().SaveMember(member)
require.Nil(t, err) require.Nil(t, nErr)
testCases := []struct { testCases := []struct {
Name string Name string
@@ -2245,8 +2251,8 @@ func testChannelUpdateMember(t *testing.T, ss store.Store) {
member.SchemeUser = tc.SchemeUser member.SchemeUser = tc.SchemeUser
member.SchemeAdmin = tc.SchemeAdmin member.SchemeAdmin = tc.SchemeAdmin
member.ExplicitRoles = tc.ExplicitRoles member.ExplicitRoles = tc.ExplicitRoles
member, err = ss.Channel().UpdateMember(member) member, nErr = ss.Channel().UpdateMember(member)
require.Nil(t, err) require.Nil(t, nErr)
assert.Equal(t, tc.ExpectedRoles, member.Roles) assert.Equal(t, tc.ExpectedRoles, member.Roles)
assert.Equal(t, tc.ExpectedExplicitRoles, member.ExplicitRoles) assert.Equal(t, tc.ExpectedExplicitRoles, member.ExplicitRoles)
assert.Equal(t, tc.ExpectedSchemeGuest, member.SchemeGuest) assert.Equal(t, tc.ExpectedSchemeGuest, member.SchemeGuest)
@@ -2291,8 +2297,8 @@ func testChannelUpdateMember(t *testing.T, ss store.Store) {
UserId: u1.Id, UserId: u1.Id,
NotifyProps: defaultNotifyProps, NotifyProps: defaultNotifyProps,
} }
member, err = ss.Channel().SaveMember(member) member, nErr = ss.Channel().SaveMember(member)
require.Nil(t, err) require.Nil(t, nErr)
testCases := []struct { testCases := []struct {
Name string Name string
@@ -2407,8 +2413,8 @@ func testChannelUpdateMember(t *testing.T, ss store.Store) {
member.SchemeUser = tc.SchemeUser member.SchemeUser = tc.SchemeUser
member.SchemeAdmin = tc.SchemeAdmin member.SchemeAdmin = tc.SchemeAdmin
member.ExplicitRoles = tc.ExplicitRoles member.ExplicitRoles = tc.ExplicitRoles
member, err = ss.Channel().UpdateMember(member) member, nErr = ss.Channel().UpdateMember(member)
require.Nil(t, err) require.Nil(t, nErr)
assert.Equal(t, tc.ExpectedRoles, member.Roles) assert.Equal(t, tc.ExpectedRoles, member.Roles)
assert.Equal(t, tc.ExpectedExplicitRoles, member.ExplicitRoles) assert.Equal(t, tc.ExpectedExplicitRoles, member.ExplicitRoles)
assert.Equal(t, tc.ExpectedSchemeGuest, member.SchemeGuest) assert.Equal(t, tc.ExpectedSchemeGuest, member.SchemeGuest)
@@ -2429,18 +2435,20 @@ func testChannelUpdateMultipleMembers(t *testing.T, ss store.Store) {
t.Run("any not valid channel member", func(t *testing.T) { t.Run("any not valid channel member", func(t *testing.T) {
m1 := &model.ChannelMember{ChannelId: "wrong", UserId: u1.Id, NotifyProps: defaultNotifyProps} m1 := &model.ChannelMember{ChannelId: "wrong", UserId: u1.Id, NotifyProps: defaultNotifyProps}
m2 := &model.ChannelMember{ChannelId: model.NewId(), UserId: u2.Id, NotifyProps: defaultNotifyProps} m2 := &model.ChannelMember{ChannelId: model.NewId(), UserId: u2.Id, NotifyProps: defaultNotifyProps}
_, err = ss.Channel().SaveMultipleMembers([]*model.ChannelMember{m1, m2}) _, nErr := ss.Channel().SaveMultipleMembers([]*model.ChannelMember{m1, m2})
require.NotNil(t, err) require.NotNil(t, nErr)
require.Equal(t, "model.channel_member.is_valid.channel_id.app_error", err.Id) var appErr *model.AppError
require.True(t, errors.As(nErr, &appErr))
require.Equal(t, "model.channel_member.is_valid.channel_id.app_error", appErr.Id)
}) })
t.Run("duplicated entries should fail", func(t *testing.T) { t.Run("duplicated entries should fail", func(t *testing.T) {
channelID1 := model.NewId() channelID1 := model.NewId()
m1 := &model.ChannelMember{ChannelId: channelID1, UserId: u1.Id, NotifyProps: defaultNotifyProps} m1 := &model.ChannelMember{ChannelId: channelID1, UserId: u1.Id, NotifyProps: defaultNotifyProps}
m2 := &model.ChannelMember{ChannelId: channelID1, UserId: u1.Id, NotifyProps: defaultNotifyProps} m2 := &model.ChannelMember{ChannelId: channelID1, UserId: u1.Id, NotifyProps: defaultNotifyProps}
_, err = ss.Channel().SaveMultipleMembers([]*model.ChannelMember{m1, m2}) _, nErr := ss.Channel().SaveMultipleMembers([]*model.ChannelMember{m1, m2})
require.NotNil(t, err) require.NotNil(t, nErr)
require.Equal(t, "store.sql_channel.save_member.exists.app_error", err.Id) require.IsType(t, &store.ErrConflict{}, nErr)
}) })
t.Run("insert members correctly (in channel without channel scheme and team without scheme)", func(t *testing.T) { t.Run("insert members correctly (in channel without channel scheme and team without scheme)", func(t *testing.T) {
@@ -2467,8 +2475,8 @@ func testChannelUpdateMultipleMembers(t *testing.T, ss store.Store) {
member := &model.ChannelMember{ChannelId: channel.Id, UserId: u1.Id, NotifyProps: defaultNotifyProps} member := &model.ChannelMember{ChannelId: channel.Id, UserId: u1.Id, NotifyProps: defaultNotifyProps}
otherMember := &model.ChannelMember{ChannelId: channel.Id, UserId: u2.Id, NotifyProps: defaultNotifyProps} otherMember := &model.ChannelMember{ChannelId: channel.Id, UserId: u2.Id, NotifyProps: defaultNotifyProps}
var members []*model.ChannelMember var members []*model.ChannelMember
members, err = ss.Channel().SaveMultipleMembers([]*model.ChannelMember{member, otherMember}) members, nErr = ss.Channel().SaveMultipleMembers([]*model.ChannelMember{member, otherMember})
require.Nil(t, err) require.Nil(t, nErr)
defer ss.Channel().RemoveMember(channel.Id, u1.Id) defer ss.Channel().RemoveMember(channel.Id, u1.Id)
defer ss.Channel().RemoveMember(channel.Id, u2.Id) defer ss.Channel().RemoveMember(channel.Id, u2.Id)
require.Len(t, members, 2) require.Len(t, members, 2)
@@ -2589,8 +2597,8 @@ func testChannelUpdateMultipleMembers(t *testing.T, ss store.Store) {
member.SchemeAdmin = tc.SchemeAdmin member.SchemeAdmin = tc.SchemeAdmin
member.ExplicitRoles = tc.ExplicitRoles member.ExplicitRoles = tc.ExplicitRoles
var members []*model.ChannelMember var members []*model.ChannelMember
members, err = ss.Channel().UpdateMultipleMembers([]*model.ChannelMember{member, otherMember}) members, nErr = ss.Channel().UpdateMultipleMembers([]*model.ChannelMember{member, otherMember})
require.Nil(t, err) require.Nil(t, nErr)
require.Len(t, members, 2) require.Len(t, members, 2)
member = members[0] member = members[0]
@@ -2637,8 +2645,8 @@ func testChannelUpdateMultipleMembers(t *testing.T, ss store.Store) {
member := &model.ChannelMember{ChannelId: channel.Id, UserId: u1.Id, NotifyProps: defaultNotifyProps} member := &model.ChannelMember{ChannelId: channel.Id, UserId: u1.Id, NotifyProps: defaultNotifyProps}
otherMember := &model.ChannelMember{ChannelId: channel.Id, UserId: u2.Id, NotifyProps: defaultNotifyProps} otherMember := &model.ChannelMember{ChannelId: channel.Id, UserId: u2.Id, NotifyProps: defaultNotifyProps}
var members []*model.ChannelMember var members []*model.ChannelMember
members, err = ss.Channel().SaveMultipleMembers([]*model.ChannelMember{member, otherMember}) members, nErr = ss.Channel().SaveMultipleMembers([]*model.ChannelMember{member, otherMember})
require.Nil(t, err) require.Nil(t, nErr)
defer ss.Channel().RemoveMember(channel.Id, u1.Id) defer ss.Channel().RemoveMember(channel.Id, u1.Id)
defer ss.Channel().RemoveMember(channel.Id, u2.Id) defer ss.Channel().RemoveMember(channel.Id, u2.Id)
require.Len(t, members, 2) require.Len(t, members, 2)
@@ -2759,8 +2767,8 @@ func testChannelUpdateMultipleMembers(t *testing.T, ss store.Store) {
member.SchemeAdmin = tc.SchemeAdmin member.SchemeAdmin = tc.SchemeAdmin
member.ExplicitRoles = tc.ExplicitRoles member.ExplicitRoles = tc.ExplicitRoles
var members []*model.ChannelMember var members []*model.ChannelMember
members, err = ss.Channel().UpdateMultipleMembers([]*model.ChannelMember{member, otherMember}) members, nErr = ss.Channel().UpdateMultipleMembers([]*model.ChannelMember{member, otherMember})
require.Nil(t, err) require.Nil(t, nErr)
require.Len(t, members, 2) require.Len(t, members, 2)
member = members[0] member = members[0]
@@ -2956,34 +2964,34 @@ func testChannelRemoveMember(t *testing.T, ss store.Store) {
m2 := &model.ChannelMember{ChannelId: channelID, UserId: u2.Id, NotifyProps: defaultNotifyProps} m2 := &model.ChannelMember{ChannelId: channelID, UserId: u2.Id, NotifyProps: defaultNotifyProps}
m3 := &model.ChannelMember{ChannelId: channelID, UserId: u3.Id, NotifyProps: defaultNotifyProps} m3 := &model.ChannelMember{ChannelId: channelID, UserId: u3.Id, NotifyProps: defaultNotifyProps}
m4 := &model.ChannelMember{ChannelId: channelID, UserId: u4.Id, NotifyProps: defaultNotifyProps} m4 := &model.ChannelMember{ChannelId: channelID, UserId: u4.Id, NotifyProps: defaultNotifyProps}
_, err = ss.Channel().SaveMultipleMembers([]*model.ChannelMember{m1, m2, m3, m4}) _, nErr := ss.Channel().SaveMultipleMembers([]*model.ChannelMember{m1, m2, m3, m4})
require.Nil(t, err) require.Nil(t, nErr)
t.Run("remove member from not existing channel", func(t *testing.T) { t.Run("remove member from not existing channel", func(t *testing.T) {
err = ss.Channel().RemoveMember("not-existing-channel", u1.Id) nErr = ss.Channel().RemoveMember("not-existing-channel", u1.Id)
require.Nil(t, err) require.Nil(t, nErr)
var membersCount int64 var membersCount int64
membersCount, err = ss.Channel().GetMemberCount(channelID, false) membersCount, nErr = ss.Channel().GetMemberCount(channelID, false)
require.Nil(t, err) require.Nil(t, nErr)
require.Equal(t, int64(4), membersCount) require.Equal(t, int64(4), membersCount)
}) })
t.Run("remove not existing member from an existing channel", func(t *testing.T) { t.Run("remove not existing member from an existing channel", func(t *testing.T) {
err = ss.Channel().RemoveMember(channelID, model.NewId()) nErr = ss.Channel().RemoveMember(channelID, model.NewId())
require.Nil(t, err) require.Nil(t, nErr)
var membersCount int64 var membersCount int64
membersCount, err = ss.Channel().GetMemberCount(channelID, false) membersCount, nErr = ss.Channel().GetMemberCount(channelID, false)
require.Nil(t, err) require.Nil(t, nErr)
require.Equal(t, int64(4), membersCount) require.Equal(t, int64(4), membersCount)
}) })
t.Run("remove existing member from an existing channel", func(t *testing.T) { t.Run("remove existing member from an existing channel", func(t *testing.T) {
err = ss.Channel().RemoveMember(channelID, u1.Id) nErr = ss.Channel().RemoveMember(channelID, u1.Id)
require.Nil(t, err) require.Nil(t, nErr)
defer ss.Channel().SaveMember(m1) defer ss.Channel().SaveMember(m1)
var membersCount int64 var membersCount int64
membersCount, err = ss.Channel().GetMemberCount(channelID, false) membersCount, nErr = ss.Channel().GetMemberCount(channelID, false)
require.Nil(t, err) require.Nil(t, nErr)
require.Equal(t, int64(3), membersCount) require.Equal(t, int64(3), membersCount)
}) })
} }
@@ -3003,39 +3011,39 @@ func testChannelRemoveMembers(t *testing.T, ss store.Store) {
m2 := &model.ChannelMember{ChannelId: channelID, UserId: u2.Id, NotifyProps: defaultNotifyProps} m2 := &model.ChannelMember{ChannelId: channelID, UserId: u2.Id, NotifyProps: defaultNotifyProps}
m3 := &model.ChannelMember{ChannelId: channelID, UserId: u3.Id, NotifyProps: defaultNotifyProps} m3 := &model.ChannelMember{ChannelId: channelID, UserId: u3.Id, NotifyProps: defaultNotifyProps}
m4 := &model.ChannelMember{ChannelId: channelID, UserId: u4.Id, NotifyProps: defaultNotifyProps} m4 := &model.ChannelMember{ChannelId: channelID, UserId: u4.Id, NotifyProps: defaultNotifyProps}
_, err = ss.Channel().SaveMultipleMembers([]*model.ChannelMember{m1, m2, m3, m4}) _, nErr := ss.Channel().SaveMultipleMembers([]*model.ChannelMember{m1, m2, m3, m4})
require.Nil(t, err) require.Nil(t, nErr)
t.Run("remove members from not existing channel", func(t *testing.T) { t.Run("remove members from not existing channel", func(t *testing.T) {
err = ss.Channel().RemoveMembers("not-existing-channel", []string{u1.Id, u2.Id, u3.Id, u4.Id}) nErr = ss.Channel().RemoveMembers("not-existing-channel", []string{u1.Id, u2.Id, u3.Id, u4.Id})
require.Nil(t, err) require.Nil(t, nErr)
var membersCount int64 var membersCount int64
membersCount, err = ss.Channel().GetMemberCount(channelID, false) membersCount, nErr = ss.Channel().GetMemberCount(channelID, false)
require.Nil(t, err) require.Nil(t, nErr)
require.Equal(t, int64(4), membersCount) require.Equal(t, int64(4), membersCount)
}) })
t.Run("remove not existing members from an existing channel", func(t *testing.T) { t.Run("remove not existing members from an existing channel", func(t *testing.T) {
err = ss.Channel().RemoveMembers(channelID, []string{model.NewId(), model.NewId()}) nErr = ss.Channel().RemoveMembers(channelID, []string{model.NewId(), model.NewId()})
require.Nil(t, err) require.Nil(t, nErr)
var membersCount int64 var membersCount int64
membersCount, err = ss.Channel().GetMemberCount(channelID, false) membersCount, nErr = ss.Channel().GetMemberCount(channelID, false)
require.Nil(t, err) require.Nil(t, nErr)
require.Equal(t, int64(4), membersCount) require.Equal(t, int64(4), membersCount)
}) })
t.Run("remove not existing and not existing members from an existing channel", func(t *testing.T) { t.Run("remove not existing and not existing members from an existing channel", func(t *testing.T) {
err = ss.Channel().RemoveMembers(channelID, []string{u1.Id, u2.Id, model.NewId(), model.NewId()}) nErr = ss.Channel().RemoveMembers(channelID, []string{u1.Id, u2.Id, model.NewId(), model.NewId()})
require.Nil(t, err) require.Nil(t, nErr)
defer ss.Channel().SaveMultipleMembers([]*model.ChannelMember{m1, m2}) defer ss.Channel().SaveMultipleMembers([]*model.ChannelMember{m1, m2})
var membersCount int64 var membersCount int64
membersCount, err = ss.Channel().GetMemberCount(channelID, false) membersCount, nErr = ss.Channel().GetMemberCount(channelID, false)
require.Nil(t, err) require.Nil(t, nErr)
require.Equal(t, int64(2), membersCount) require.Equal(t, int64(2), membersCount)
}) })
t.Run("remove existing members from an existing channel", func(t *testing.T) { t.Run("remove existing members from an existing channel", func(t *testing.T) {
err = ss.Channel().RemoveMembers(channelID, []string{u1.Id, u2.Id, u3.Id}) nErr = ss.Channel().RemoveMembers(channelID, []string{u1.Id, u2.Id, u3.Id})
require.Nil(t, err) require.Nil(t, nErr)
defer ss.Channel().SaveMultipleMembers([]*model.ChannelMember{m1, m2, m3}) defer ss.Channel().SaveMultipleMembers([]*model.ChannelMember{m1, m2, m3})
membersCount, err := ss.Channel().GetMemberCount(channelID, false) membersCount, err := ss.Channel().GetMemberCount(channelID, false)
require.Nil(t, err) require.Nil(t, err)
@@ -3075,35 +3083,35 @@ func testChannelDeleteMemberStore(t *testing.T, ss store.Store) {
o1.ChannelId = c1.Id o1.ChannelId = c1.Id
o1.UserId = u1.Id o1.UserId = u1.Id
o1.NotifyProps = model.GetDefaultChannelNotifyProps() o1.NotifyProps = model.GetDefaultChannelNotifyProps()
_, err = ss.Channel().SaveMember(&o1) _, nErr = ss.Channel().SaveMember(&o1)
require.Nil(t, err) require.Nil(t, nErr)
o2 := model.ChannelMember{} o2 := model.ChannelMember{}
o2.ChannelId = c1.Id o2.ChannelId = c1.Id
o2.UserId = u2.Id o2.UserId = u2.Id
o2.NotifyProps = model.GetDefaultChannelNotifyProps() o2.NotifyProps = model.GetDefaultChannelNotifyProps()
_, err = ss.Channel().SaveMember(&o2) _, nErr = ss.Channel().SaveMember(&o2)
require.Nil(t, err) require.Nil(t, nErr)
c1t2, _ := ss.Channel().Get(c1.Id, false) c1t2, _ := ss.Channel().Get(c1.Id, false)
assert.EqualValues(t, 0, c1t2.ExtraUpdateAt, "ExtraUpdateAt should be 0") assert.EqualValues(t, 0, c1t2.ExtraUpdateAt, "ExtraUpdateAt should be 0")
count, err := ss.Channel().GetMemberCount(o1.ChannelId, false) count, nErr := ss.Channel().GetMemberCount(o1.ChannelId, false)
require.Nil(t, err) require.Nil(t, nErr)
require.EqualValues(t, 2, count, "should have saved 2 members") require.EqualValues(t, 2, count, "should have saved 2 members")
err = ss.Channel().PermanentDeleteMembersByUser(o2.UserId) nErr = ss.Channel().PermanentDeleteMembersByUser(o2.UserId)
require.Nil(t, err) require.Nil(t, nErr)
count, err = ss.Channel().GetMemberCount(o1.ChannelId, false) count, nErr = ss.Channel().GetMemberCount(o1.ChannelId, false)
require.Nil(t, err) require.Nil(t, nErr)
require.EqualValues(t, 1, count, "should have removed 1 member") require.EqualValues(t, 1, count, "should have removed 1 member")
err = ss.Channel().PermanentDeleteMembersByChannel(o1.ChannelId) nErr = ss.Channel().PermanentDeleteMembersByChannel(o1.ChannelId)
require.Nil(t, err, err) require.Nil(t, nErr)
count, err = ss.Channel().GetMemberCount(o1.ChannelId, false) count, nErr = ss.Channel().GetMemberCount(o1.ChannelId, false)
require.Nil(t, err) require.Nil(t, nErr)
require.EqualValues(t, 0, count, "should have removed all members") require.EqualValues(t, 0, count, "should have removed all members")
} }
@@ -4362,8 +4370,8 @@ func testGetMemberCount(t *testing.T, ss store.Store) {
UserId: u1.Id, UserId: u1.Id,
NotifyProps: model.GetDefaultChannelNotifyProps(), NotifyProps: model.GetDefaultChannelNotifyProps(),
} }
_, err = ss.Channel().SaveMember(&m1) _, nErr = ss.Channel().SaveMember(&m1)
require.Nil(t, err) require.Nil(t, nErr)
count, channelErr := ss.Channel().GetMemberCount(c1.Id, false) count, channelErr := ss.Channel().GetMemberCount(c1.Id, false)
require.Nilf(t, channelErr, "failed to get member count: %v", channelErr) require.Nilf(t, channelErr, "failed to get member count: %v", channelErr)
@@ -4383,8 +4391,8 @@ func testGetMemberCount(t *testing.T, ss store.Store) {
UserId: u2.Id, UserId: u2.Id,
NotifyProps: model.GetDefaultChannelNotifyProps(), NotifyProps: model.GetDefaultChannelNotifyProps(),
} }
_, err = ss.Channel().SaveMember(&m2) _, nErr = ss.Channel().SaveMember(&m2)
require.Nil(t, err) require.Nil(t, nErr)
count, channelErr = ss.Channel().GetMemberCount(c1.Id, false) count, channelErr = ss.Channel().GetMemberCount(c1.Id, false)
require.Nilf(t, channelErr, "failed to get member count: %v", channelErr) require.Nilf(t, channelErr, "failed to get member count: %v", channelErr)
@@ -4405,8 +4413,8 @@ func testGetMemberCount(t *testing.T, ss store.Store) {
UserId: u3.Id, UserId: u3.Id,
NotifyProps: model.GetDefaultChannelNotifyProps(), NotifyProps: model.GetDefaultChannelNotifyProps(),
} }
_, err = ss.Channel().SaveMember(&m3) _, nErr = ss.Channel().SaveMember(&m3)
require.Nil(t, err) require.Nil(t, nErr)
count, channelErr = ss.Channel().GetMemberCount(c1.Id, false) count, channelErr = ss.Channel().GetMemberCount(c1.Id, false)
require.Nilf(t, channelErr, "failed to get member count: %v", channelErr) require.Nilf(t, channelErr, "failed to get member count: %v", channelErr)
@@ -4427,11 +4435,11 @@ func testGetMemberCount(t *testing.T, ss store.Store) {
UserId: u4.Id, UserId: u4.Id,
NotifyProps: model.GetDefaultChannelNotifyProps(), NotifyProps: model.GetDefaultChannelNotifyProps(),
} }
_, err = ss.Channel().SaveMember(&m4) _, nErr = ss.Channel().SaveMember(&m4)
require.Nil(t, err) require.Nil(t, nErr)
count, err = ss.Channel().GetMemberCount(c1.Id, false) count, nErr = ss.Channel().GetMemberCount(c1.Id, false)
require.Nilf(t, err, "failed to get member count: %v", err) require.Nilf(t, nErr, "failed to get member count: %v", nErr)
require.EqualValuesf(t, 2, count, "got incorrect member count %v", count) require.EqualValuesf(t, 2, count, "got incorrect member count %v", count)
} }
@@ -4471,13 +4479,13 @@ func testGetMemberCountsByGroup(t *testing.T, ss store.Store) {
UserId: u1.Id, UserId: u1.Id,
NotifyProps: model.GetDefaultChannelNotifyProps(), NotifyProps: model.GetDefaultChannelNotifyProps(),
} }
_, err = ss.Channel().SaveMember(&m1) _, nErr = ss.Channel().SaveMember(&m1)
require.Nil(t, err) require.Nil(t, nErr)
t.Run("empty slice for channel with no groups", func(t *testing.T) { t.Run("empty slice for channel with no groups", func(t *testing.T) {
memberCounts, err = ss.Channel().GetMemberCountsByGroup(c1.Id, false) memberCounts, nErr = ss.Channel().GetMemberCountsByGroup(c1.Id, false)
expectedMemberCounts := []*model.ChannelMemberCountByGroup{} expectedMemberCounts := []*model.ChannelMemberCountByGroup{}
require.Nil(t, err) require.Nil(t, nErr)
require.Equal(t, expectedMemberCounts, memberCounts) require.Equal(t, expectedMemberCounts, memberCounts)
}) })
@@ -4485,7 +4493,7 @@ func testGetMemberCountsByGroup(t *testing.T, ss store.Store) {
require.Nil(t, err) require.Nil(t, err)
t.Run("returns memberCountsByGroup without timezones", func(t *testing.T) { t.Run("returns memberCountsByGroup without timezones", func(t *testing.T) {
memberCounts, err = ss.Channel().GetMemberCountsByGroup(c1.Id, false) memberCounts, nErr = ss.Channel().GetMemberCountsByGroup(c1.Id, false)
expectedMemberCounts := []*model.ChannelMemberCountByGroup{ expectedMemberCounts := []*model.ChannelMemberCountByGroup{
{ {
GroupId: g1.Id, GroupId: g1.Id,
@@ -4493,12 +4501,12 @@ func testGetMemberCountsByGroup(t *testing.T, ss store.Store) {
ChannelMemberTimezonesCount: 0, ChannelMemberTimezonesCount: 0,
}, },
} }
require.Nil(t, err) require.Nil(t, nErr)
require.Equal(t, expectedMemberCounts, memberCounts) require.Equal(t, expectedMemberCounts, memberCounts)
}) })
t.Run("returns memberCountsByGroup with timezones when no timezones set", func(t *testing.T) { t.Run("returns memberCountsByGroup with timezones when no timezones set", func(t *testing.T) {
memberCounts, err = ss.Channel().GetMemberCountsByGroup(c1.Id, true) memberCounts, nErr = ss.Channel().GetMemberCountsByGroup(c1.Id, true)
expectedMemberCounts := []*model.ChannelMemberCountByGroup{ expectedMemberCounts := []*model.ChannelMemberCountByGroup{
{ {
GroupId: g1.Id, GroupId: g1.Id,
@@ -4506,7 +4514,7 @@ func testGetMemberCountsByGroup(t *testing.T, ss store.Store) {
ChannelMemberTimezonesCount: 0, ChannelMemberTimezonesCount: 0,
}, },
} }
require.Nil(t, err) require.Nil(t, nErr)
require.Equal(t, expectedMemberCounts, memberCounts) require.Equal(t, expectedMemberCounts, memberCounts)
}) })
@@ -4542,8 +4550,8 @@ func testGetMemberCountsByGroup(t *testing.T, ss store.Store) {
UserId: u.Id, UserId: u.Id,
NotifyProps: model.GetDefaultChannelNotifyProps(), NotifyProps: model.GetDefaultChannelNotifyProps(),
} }
_, err = ss.Channel().SaveMember(&m) _, nErr = ss.Channel().SaveMember(&m)
require.Nil(t, err) require.Nil(t, nErr)
_, err = ss.Group().UpsertMember(g2.Id, u.Id) _, err = ss.Group().UpsertMember(g2.Id, u.Id)
require.Nil(t, err) require.Nil(t, err)
@@ -4593,15 +4601,15 @@ func testGetMemberCountsByGroup(t *testing.T, ss store.Store) {
UserId: u.Id, UserId: u.Id,
NotifyProps: model.GetDefaultChannelNotifyProps(), NotifyProps: model.GetDefaultChannelNotifyProps(),
} }
_, err = ss.Channel().SaveMember(&m) _, nErr = ss.Channel().SaveMember(&m)
require.Nil(t, err) require.Nil(t, nErr)
_, err = ss.Group().UpsertMember(g3.Id, u.Id) _, err = ss.Group().UpsertMember(g3.Id, u.Id)
require.Nil(t, err) require.Nil(t, err)
} }
t.Run("returns memberCountsByGroup for multiple groups with lots of users without timezones", func(t *testing.T) { t.Run("returns memberCountsByGroup for multiple groups with lots of users without timezones", func(t *testing.T) {
memberCounts, err = ss.Channel().GetMemberCountsByGroup(c1.Id, false) memberCounts, nErr = ss.Channel().GetMemberCountsByGroup(c1.Id, false)
expectedMemberCounts := []*model.ChannelMemberCountByGroup{ expectedMemberCounts := []*model.ChannelMemberCountByGroup{
{ {
GroupId: g1.Id, GroupId: g1.Id,
@@ -4619,12 +4627,12 @@ func testGetMemberCountsByGroup(t *testing.T, ss store.Store) {
ChannelMemberTimezonesCount: 0, ChannelMemberTimezonesCount: 0,
}, },
} }
require.Nil(t, err) require.Nil(t, nErr)
require.ElementsMatch(t, expectedMemberCounts, memberCounts) require.ElementsMatch(t, expectedMemberCounts, memberCounts)
}) })
t.Run("returns memberCountsByGroup for multiple groups with lots of users with timezones", func(t *testing.T) { t.Run("returns memberCountsByGroup for multiple groups with lots of users with timezones", func(t *testing.T) {
memberCounts, err = ss.Channel().GetMemberCountsByGroup(c1.Id, true) memberCounts, nErr = ss.Channel().GetMemberCountsByGroup(c1.Id, true)
expectedMemberCounts := []*model.ChannelMemberCountByGroup{ expectedMemberCounts := []*model.ChannelMemberCountByGroup{
{ {
GroupId: g1.Id, GroupId: g1.Id,
@@ -4642,7 +4650,7 @@ func testGetMemberCountsByGroup(t *testing.T, ss store.Store) {
ChannelMemberTimezonesCount: 3, ChannelMemberTimezonesCount: 3,
}, },
} }
require.Nil(t, err) require.Nil(t, nErr)
require.ElementsMatch(t, expectedMemberCounts, memberCounts) require.ElementsMatch(t, expectedMemberCounts, memberCounts)
}) })
} }
@@ -4685,8 +4693,8 @@ func testGetGuestCount(t *testing.T, ss store.Store) {
NotifyProps: model.GetDefaultChannelNotifyProps(), NotifyProps: model.GetDefaultChannelNotifyProps(),
SchemeGuest: false, SchemeGuest: false,
} }
_, err = ss.Channel().SaveMember(&m1) _, nErr = ss.Channel().SaveMember(&m1)
require.Nil(t, err) require.Nil(t, nErr)
count, channelErr := ss.Channel().GetGuestCount(c1.Id, false) count, channelErr := ss.Channel().GetGuestCount(c1.Id, false)
require.Nil(t, channelErr) require.Nil(t, channelErr)
@@ -4710,8 +4718,8 @@ func testGetGuestCount(t *testing.T, ss store.Store) {
NotifyProps: model.GetDefaultChannelNotifyProps(), NotifyProps: model.GetDefaultChannelNotifyProps(),
SchemeGuest: true, SchemeGuest: true,
} }
_, err = ss.Channel().SaveMember(&m2) _, nErr = ss.Channel().SaveMember(&m2)
require.Nil(t, err) require.Nil(t, nErr)
count, channelErr := ss.Channel().GetGuestCount(c1.Id, false) count, channelErr := ss.Channel().GetGuestCount(c1.Id, false)
require.Nil(t, channelErr) require.Nil(t, channelErr)
@@ -4735,8 +4743,8 @@ func testGetGuestCount(t *testing.T, ss store.Store) {
NotifyProps: model.GetDefaultChannelNotifyProps(), NotifyProps: model.GetDefaultChannelNotifyProps(),
SchemeGuest: true, SchemeGuest: true,
} }
_, err = ss.Channel().SaveMember(&m3) _, nErr = ss.Channel().SaveMember(&m3)
require.Nil(t, err) require.Nil(t, nErr)
count, channelErr := ss.Channel().GetGuestCount(c1.Id, false) count, channelErr := ss.Channel().GetGuestCount(c1.Id, false)
require.Nil(t, channelErr) require.Nil(t, channelErr)
@@ -4760,8 +4768,8 @@ func testGetGuestCount(t *testing.T, ss store.Store) {
NotifyProps: model.GetDefaultChannelNotifyProps(), NotifyProps: model.GetDefaultChannelNotifyProps(),
SchemeGuest: true, SchemeGuest: true,
} }
_, err = ss.Channel().SaveMember(&m4) _, nErr = ss.Channel().SaveMember(&m4)
require.Nil(t, err) require.Nil(t, nErr)
count, channelErr := ss.Channel().GetGuestCount(c1.Id, false) count, channelErr := ss.Channel().GetGuestCount(c1.Id, false)
require.Nil(t, channelErr) require.Nil(t, channelErr)
@@ -5554,12 +5562,12 @@ func testChannelStoreSearchGroupChannels(t *testing.T, ss store.Store) {
require.Nil(t, nErr) require.Nil(t, nErr)
for _, userId := range userIds { for _, userId := range userIds {
_, err = ss.Channel().SaveMember(&model.ChannelMember{ _, nErr = ss.Channel().SaveMember(&model.ChannelMember{
ChannelId: gc1.Id, ChannelId: gc1.Id,
UserId: userId, UserId: userId,
NotifyProps: model.GetDefaultChannelNotifyProps(), NotifyProps: model.GetDefaultChannelNotifyProps(),
}) })
require.Nil(t, err) require.Nil(t, nErr)
} }
userIds = []string{u1.Id, u4.Id} userIds = []string{u1.Id, u4.Id}

Просмотреть файл

@@ -535,12 +535,12 @@ func testGetSidebarCategory(t *testing.T, ss store.Store, s SqlSupplier) {
Type: model.CHANNEL_PRIVATE, Type: model.CHANNEL_PRIVATE,
}, 10) }, 10)
require.Nil(t, nErr) require.Nil(t, nErr)
_, err = ss.Channel().SaveMember(&model.ChannelMember{ _, nErr = ss.Channel().SaveMember(&model.ChannelMember{
UserId: userId, UserId: userId,
ChannelId: channel1.Id, ChannelId: channel1.Id,
NotifyProps: model.GetDefaultChannelNotifyProps(), NotifyProps: model.GetDefaultChannelNotifyProps(),
}) })
require.Nil(t, err) require.Nil(t, nErr)
channel2, nErr := ss.Channel().Save(&model.Channel{ channel2, nErr := ss.Channel().Save(&model.Channel{
Name: "channel2", Name: "channel2",
@@ -549,12 +549,12 @@ func testGetSidebarCategory(t *testing.T, ss store.Store, s SqlSupplier) {
Type: model.CHANNEL_OPEN, Type: model.CHANNEL_OPEN,
}, 10) }, 10)
require.Nil(t, nErr) require.Nil(t, nErr)
_, err = ss.Channel().SaveMember(&model.ChannelMember{ _, nErr = ss.Channel().SaveMember(&model.ChannelMember{
UserId: userId, UserId: userId,
ChannelId: channel2.Id, ChannelId: channel2.Id,
NotifyProps: model.GetDefaultChannelNotifyProps(), NotifyProps: model.GetDefaultChannelNotifyProps(),
}) })
require.Nil(t, err) require.Nil(t, nErr)
// Confirm that they're not in the Channels category in the DB // Confirm that they're not in the Channels category in the DB
count, countErr := s.GetMaster().SelectInt(` count, countErr := s.GetMaster().SelectInt(`
@@ -597,12 +597,12 @@ func testGetSidebarCategory(t *testing.T, ss store.Store, s SqlSupplier) {
}, 10) }, 10)
require.Nil(t, nErr) require.Nil(t, nErr)
_, err = ss.Channel().SaveMember(&model.ChannelMember{ _, nErr = ss.Channel().SaveMember(&model.ChannelMember{
UserId: userId, UserId: userId,
ChannelId: channel1.Id, ChannelId: channel1.Id,
NotifyProps: model.GetDefaultChannelNotifyProps(), NotifyProps: model.GetDefaultChannelNotifyProps(),
}) })
require.Nil(t, err) require.Nil(t, nErr)
// Ensure that no channels are returned // Ensure that no channels are returned
res, err := ss.Channel().GetSidebarCategory(channelsCategory.Id) res, err := ss.Channel().GetSidebarCategory(channelsCategory.Id)
@@ -636,12 +636,12 @@ func testGetSidebarCategory(t *testing.T, ss store.Store, s SqlSupplier) {
Type: model.CHANNEL_PRIVATE, Type: model.CHANNEL_PRIVATE,
}, 10) }, 10)
require.Nil(t, nErr) require.Nil(t, nErr)
_, err = ss.Channel().SaveMember(&model.ChannelMember{ _, nErr = ss.Channel().SaveMember(&model.ChannelMember{
UserId: userId, UserId: userId,
ChannelId: channel1.Id, ChannelId: channel1.Id,
NotifyProps: model.GetDefaultChannelNotifyProps(), NotifyProps: model.GetDefaultChannelNotifyProps(),
}) })
require.Nil(t, err) require.Nil(t, nErr)
channel2, nErr := ss.Channel().Save(&model.Channel{ channel2, nErr := ss.Channel().Save(&model.Channel{
Name: "channel2", Name: "channel2",
@@ -650,12 +650,12 @@ func testGetSidebarCategory(t *testing.T, ss store.Store, s SqlSupplier) {
Type: model.CHANNEL_OPEN, Type: model.CHANNEL_OPEN,
}, 10) }, 10)
require.Nil(t, nErr) require.Nil(t, nErr)
_, err = ss.Channel().SaveMember(&model.ChannelMember{ _, nErr = ss.Channel().SaveMember(&model.ChannelMember{
UserId: userId, UserId: userId,
ChannelId: channel2.Id, ChannelId: channel2.Id,
NotifyProps: model.GetDefaultChannelNotifyProps(), NotifyProps: model.GetDefaultChannelNotifyProps(),
}) })
require.Nil(t, err) require.Nil(t, nErr)
// And assign one to another category // And assign one to another category
_, err = ss.Channel().UpdateSidebarCategories(userId, teamId, []*model.SidebarCategoryWithChannels{ _, err = ss.Channel().UpdateSidebarCategories(userId, teamId, []*model.SidebarCategoryWithChannels{
@@ -735,12 +735,12 @@ func testGetSidebarCategory(t *testing.T, ss store.Store, s SqlSupplier) {
Type: model.CHANNEL_GROUP, Type: model.CHANNEL_GROUP,
}, 10) }, 10)
require.Nil(t, nErr) require.Nil(t, nErr)
_, err = ss.Channel().SaveMember(&model.ChannelMember{ _, nErr = ss.Channel().SaveMember(&model.ChannelMember{
UserId: userId, UserId: userId,
ChannelId: gmChannel.Id, ChannelId: gmChannel.Id,
NotifyProps: model.GetDefaultChannelNotifyProps(), NotifyProps: model.GetDefaultChannelNotifyProps(),
}) })
require.Nil(t, err) require.Nil(t, nErr)
// Ensure that the DM is returned // Ensure that the DM is returned
res, err := ss.Channel().GetSidebarCategory(dmsCategory.Id) res, err := ss.Channel().GetSidebarCategory(dmsCategory.Id)
@@ -989,12 +989,12 @@ func testUpdateSidebarCategories(t *testing.T, ss store.Store, s SqlSupplier) {
TeamId: teamId, TeamId: teamId,
}, 10) }, 10)
require.Nil(t, nErr) require.Nil(t, nErr)
_, err = ss.Channel().SaveMember(&model.ChannelMember{ _, nErr = ss.Channel().SaveMember(&model.ChannelMember{
UserId: userId, UserId: userId,
ChannelId: channel.Id, ChannelId: channel.Id,
NotifyProps: model.GetDefaultChannelNotifyProps(), NotifyProps: model.GetDefaultChannelNotifyProps(),
}) })
require.Nil(t, err) require.Nil(t, nErr)
// Assign it to favorites // Assign it to favorites
_, err = ss.Channel().UpdateSidebarCategories(userId, teamId, []*model.SidebarCategoryWithChannels{ _, err = ss.Channel().UpdateSidebarCategories(userId, teamId, []*model.SidebarCategoryWithChannels{
@@ -1229,18 +1229,18 @@ func testUpdateSidebarCategories(t *testing.T, ss store.Store, s SqlSupplier) {
TeamId: teamId, TeamId: teamId,
}, 10) }, 10)
require.Nil(t, nErr) require.Nil(t, nErr)
_, err = ss.Channel().SaveMember(&model.ChannelMember{ _, nErr = ss.Channel().SaveMember(&model.ChannelMember{
UserId: userId, UserId: userId,
ChannelId: channel.Id, ChannelId: channel.Id,
NotifyProps: model.GetDefaultChannelNotifyProps(), NotifyProps: model.GetDefaultChannelNotifyProps(),
}) })
require.Nil(t, err) require.Nil(t, nErr)
_, err = ss.Channel().SaveMember(&model.ChannelMember{ _, nErr = ss.Channel().SaveMember(&model.ChannelMember{
UserId: userId2, UserId: userId2,
ChannelId: channel.Id, ChannelId: channel.Id,
NotifyProps: model.GetDefaultChannelNotifyProps(), NotifyProps: model.GetDefaultChannelNotifyProps(),
}) })
require.Nil(t, err) require.Nil(t, nErr)
// Have user1 favorite it // Have user1 favorite it
_, err = ss.Channel().UpdateSidebarCategories(userId, teamId, []*model.SidebarCategoryWithChannels{ _, err = ss.Channel().UpdateSidebarCategories(userId, teamId, []*model.SidebarCategoryWithChannels{

Просмотреть файл

@@ -1875,12 +1875,12 @@ func testTeamMembersToRemove(t *testing.T, ss store.Store) {
require.Nil(t, res) require.Nil(t, res)
res = ss.Team().RemoveMember(data.ConstrainedTeam.Id, data.UserC.Id) res = ss.Team().RemoveMember(data.ConstrainedTeam.Id, data.UserC.Id)
require.Nil(t, res) require.Nil(t, res)
err = ss.Channel().RemoveMember(data.ConstrainedChannel.Id, data.UserA.Id) nErr = ss.Channel().RemoveMember(data.ConstrainedChannel.Id, data.UserA.Id)
require.Nil(t, err) require.Nil(t, nErr)
err = ss.Channel().RemoveMember(data.ConstrainedChannel.Id, data.UserB.Id) nErr = ss.Channel().RemoveMember(data.ConstrainedChannel.Id, data.UserB.Id)
require.Nil(t, err) require.Nil(t, nErr)
err = ss.Channel().RemoveMember(data.ConstrainedChannel.Id, data.UserC.Id) nErr = ss.Channel().RemoveMember(data.ConstrainedChannel.Id, data.UserC.Id)
require.Nil(t, err) require.Nil(t, nErr)
} }
func testTeamMembersToRemoveSingleTeam(t *testing.T, ss store.Store) { func testTeamMembersToRemoveSingleTeam(t *testing.T, ss store.Store) {
@@ -2027,12 +2027,12 @@ func testChannelMembersToRemove(t *testing.T, ss store.Store) {
require.Nil(t, res) require.Nil(t, res)
res = ss.Team().RemoveMember(data.ConstrainedTeam.Id, data.UserC.Id) res = ss.Team().RemoveMember(data.ConstrainedTeam.Id, data.UserC.Id)
require.Nil(t, res) require.Nil(t, res)
err = ss.Channel().RemoveMember(data.ConstrainedChannel.Id, data.UserA.Id) nErr = ss.Channel().RemoveMember(data.ConstrainedChannel.Id, data.UserA.Id)
require.Nil(t, err) require.Nil(t, nErr)
err = ss.Channel().RemoveMember(data.ConstrainedChannel.Id, data.UserB.Id) nErr = ss.Channel().RemoveMember(data.ConstrainedChannel.Id, data.UserB.Id)
require.Nil(t, err) require.Nil(t, nErr)
err = ss.Channel().RemoveMember(data.ConstrainedChannel.Id, data.UserC.Id) nErr = ss.Channel().RemoveMember(data.ConstrainedChannel.Id, data.UserC.Id)
require.Nil(t, err) require.Nil(t, nErr)
} }
func testChannelMembersToRemoveSingleChannel(t *testing.T, ss store.Store) { func testChannelMembersToRemoveSingleChannel(t *testing.T, ss store.Store) {
@@ -2076,20 +2076,20 @@ func testChannelMembersToRemoveSingleChannel(t *testing.T, ss store.Store) {
require.Nil(t, nErr) require.Nil(t, nErr)
for _, user := range []*model.User{user1, user2} { for _, user := range []*model.User{user1, user2} {
_, err = ss.Channel().SaveMember(&model.ChannelMember{ _, nErr = ss.Channel().SaveMember(&model.ChannelMember{
ChannelId: channel1.Id, ChannelId: channel1.Id,
UserId: user.Id, UserId: user.Id,
NotifyProps: model.GetDefaultChannelNotifyProps(), NotifyProps: model.GetDefaultChannelNotifyProps(),
}) })
require.Nil(t, err) require.Nil(t, nErr)
} }
_, err = ss.Channel().SaveMember(&model.ChannelMember{ _, nErr = ss.Channel().SaveMember(&model.ChannelMember{
ChannelId: channel2.Id, ChannelId: channel2.Id,
UserId: user3.Id, UserId: user3.Id,
NotifyProps: model.GetDefaultChannelNotifyProps(), NotifyProps: model.GetDefaultChannelNotifyProps(),
}) })
require.Nil(t, err) require.Nil(t, nErr)
channelMembers, err := ss.Group().ChannelMembersToRemove(nil) channelMembers, err := ss.Group().ChannelMembersToRemove(nil)
require.Nil(t, err) require.Nil(t, err)

Просмотреть файл

@@ -39,7 +39,7 @@ func (_m *ChannelStore) AnalyticsDeletedTypeCount(teamId string, channelType str
} }
// AnalyticsTypeCount provides a mock function with given fields: teamId, channelType // AnalyticsTypeCount provides a mock function with given fields: teamId, channelType
func (_m *ChannelStore) AnalyticsTypeCount(teamId string, channelType string) (int64, *model.AppError) { func (_m *ChannelStore) AnalyticsTypeCount(teamId string, channelType string) (int64, error) {
ret := _m.Called(teamId, channelType) ret := _m.Called(teamId, channelType)
var r0 int64 var r0 int64
@@ -49,13 +49,11 @@ func (_m *ChannelStore) AnalyticsTypeCount(teamId string, channelType string) (i
r0 = ret.Get(0).(int64) r0 = ret.Get(0).(int64)
} }
var r1 *model.AppError var r1 error
if rf, ok := ret.Get(1).(func(string, string) *model.AppError); ok { if rf, ok := ret.Get(1).(func(string, string) error); ok {
r1 = rf(teamId, channelType) r1 = rf(teamId, channelType)
} else { } else {
if ret.Get(1) != nil { r1 = ret.Error(1)
r1 = ret.Get(1).(*model.AppError)
}
} }
return r0, r1 return r0, r1
@@ -147,7 +145,7 @@ func (_m *ChannelStore) ClearSidebarOnTeamLeave(userId string, teamId string) er
} }
// CountPostsAfter provides a mock function with given fields: channelId, timestamp, userId // CountPostsAfter provides a mock function with given fields: channelId, timestamp, userId
func (_m *ChannelStore) CountPostsAfter(channelId string, timestamp int64, userId string) (int, *model.AppError) { func (_m *ChannelStore) CountPostsAfter(channelId string, timestamp int64, userId string) (int, error) {
ret := _m.Called(channelId, timestamp, userId) ret := _m.Called(channelId, timestamp, userId)
var r0 int var r0 int
@@ -157,13 +155,11 @@ func (_m *ChannelStore) CountPostsAfter(channelId string, timestamp int64, userI
r0 = ret.Get(0).(int) r0 = ret.Get(0).(int)
} }
var r1 *model.AppError var r1 error
if rf, ok := ret.Get(1).(func(string, int64, string) *model.AppError); ok { if rf, ok := ret.Get(1).(func(string, int64, string) error); ok {
r1 = rf(channelId, timestamp, userId) r1 = rf(channelId, timestamp, userId)
} else { } else {
if ret.Get(1) != nil { r1 = ret.Error(1)
r1 = ret.Get(1).(*model.AppError)
}
} }
return r0, r1 return r0, r1
@@ -322,7 +318,7 @@ func (_m *ChannelStore) GetAll(teamId string) ([]*model.Channel, error) {
} }
// GetAllChannelMembersForUser provides a mock function with given fields: userId, allowFromCache, includeDeleted // GetAllChannelMembersForUser provides a mock function with given fields: userId, allowFromCache, includeDeleted
func (_m *ChannelStore) GetAllChannelMembersForUser(userId string, allowFromCache bool, includeDeleted bool) (map[string]string, *model.AppError) { func (_m *ChannelStore) GetAllChannelMembersForUser(userId string, allowFromCache bool, includeDeleted bool) (map[string]string, error) {
ret := _m.Called(userId, allowFromCache, includeDeleted) ret := _m.Called(userId, allowFromCache, includeDeleted)
var r0 map[string]string var r0 map[string]string
@@ -334,20 +330,18 @@ func (_m *ChannelStore) GetAllChannelMembersForUser(userId string, allowFromCach
} }
} }
var r1 *model.AppError var r1 error
if rf, ok := ret.Get(1).(func(string, bool, bool) *model.AppError); ok { if rf, ok := ret.Get(1).(func(string, bool, bool) error); ok {
r1 = rf(userId, allowFromCache, includeDeleted) r1 = rf(userId, allowFromCache, includeDeleted)
} else { } else {
if ret.Get(1) != nil { r1 = ret.Error(1)
r1 = ret.Get(1).(*model.AppError)
}
} }
return r0, r1 return r0, r1
} }
// GetAllChannelMembersNotifyPropsForChannel provides a mock function with given fields: channelId, allowFromCache // GetAllChannelMembersNotifyPropsForChannel provides a mock function with given fields: channelId, allowFromCache
func (_m *ChannelStore) GetAllChannelMembersNotifyPropsForChannel(channelId string, allowFromCache bool) (map[string]model.StringMap, *model.AppError) { func (_m *ChannelStore) GetAllChannelMembersNotifyPropsForChannel(channelId string, allowFromCache bool) (map[string]model.StringMap, error) {
ret := _m.Called(channelId, allowFromCache) ret := _m.Called(channelId, allowFromCache)
var r0 map[string]model.StringMap var r0 map[string]model.StringMap
@@ -359,13 +353,11 @@ func (_m *ChannelStore) GetAllChannelMembersNotifyPropsForChannel(channelId stri
} }
} }
var r1 *model.AppError var r1 error
if rf, ok := ret.Get(1).(func(string, bool) *model.AppError); ok { if rf, ok := ret.Get(1).(func(string, bool) error); ok {
r1 = rf(channelId, allowFromCache) r1 = rf(channelId, allowFromCache)
} else { } else {
if ret.Get(1) != nil { r1 = ret.Error(1)
r1 = ret.Get(1).(*model.AppError)
}
} }
return r0, r1 return r0, r1
@@ -583,7 +575,7 @@ func (_m *ChannelStore) GetChannelMembersForExport(userId string, teamId string)
} }
// GetChannelMembersTimezones provides a mock function with given fields: channelId // GetChannelMembersTimezones provides a mock function with given fields: channelId
func (_m *ChannelStore) GetChannelMembersTimezones(channelId string) ([]model.StringMap, *model.AppError) { func (_m *ChannelStore) GetChannelMembersTimezones(channelId string) ([]model.StringMap, error) {
ret := _m.Called(channelId) ret := _m.Called(channelId)
var r0 []model.StringMap var r0 []model.StringMap
@@ -595,13 +587,11 @@ func (_m *ChannelStore) GetChannelMembersTimezones(channelId string) ([]model.St
} }
} }
var r1 *model.AppError var r1 error
if rf, ok := ret.Get(1).(func(string) *model.AppError); ok { if rf, ok := ret.Get(1).(func(string) error); ok {
r1 = rf(channelId) r1 = rf(channelId)
} else { } else {
if ret.Get(1) != nil { r1 = ret.Error(1)
r1 = ret.Get(1).(*model.AppError)
}
} }
return r0, r1 return r0, r1
@@ -821,7 +811,7 @@ func (_m *ChannelStore) GetFromMaster(id string) (*model.Channel, error) {
} }
// GetGuestCount provides a mock function with given fields: channelId, allowFromCache // GetGuestCount provides a mock function with given fields: channelId, allowFromCache
func (_m *ChannelStore) GetGuestCount(channelId string, allowFromCache bool) (int64, *model.AppError) { func (_m *ChannelStore) GetGuestCount(channelId string, allowFromCache bool) (int64, error) {
ret := _m.Called(channelId, allowFromCache) ret := _m.Called(channelId, allowFromCache)
var r0 int64 var r0 int64
@@ -831,20 +821,18 @@ func (_m *ChannelStore) GetGuestCount(channelId string, allowFromCache bool) (in
r0 = ret.Get(0).(int64) r0 = ret.Get(0).(int64)
} }
var r1 *model.AppError var r1 error
if rf, ok := ret.Get(1).(func(string, bool) *model.AppError); ok { if rf, ok := ret.Get(1).(func(string, bool) error); ok {
r1 = rf(channelId, allowFromCache) r1 = rf(channelId, allowFromCache)
} else { } else {
if ret.Get(1) != nil { r1 = ret.Error(1)
r1 = ret.Get(1).(*model.AppError)
}
} }
return r0, r1 return r0, r1
} }
// GetMember provides a mock function with given fields: channelId, userId // GetMember provides a mock function with given fields: channelId, userId
func (_m *ChannelStore) GetMember(channelId string, userId string) (*model.ChannelMember, *model.AppError) { func (_m *ChannelStore) GetMember(channelId string, userId string) (*model.ChannelMember, error) {
ret := _m.Called(channelId, userId) ret := _m.Called(channelId, userId)
var r0 *model.ChannelMember var r0 *model.ChannelMember
@@ -856,20 +844,18 @@ func (_m *ChannelStore) GetMember(channelId string, userId string) (*model.Chann
} }
} }
var r1 *model.AppError var r1 error
if rf, ok := ret.Get(1).(func(string, string) *model.AppError); ok { if rf, ok := ret.Get(1).(func(string, string) error); ok {
r1 = rf(channelId, userId) r1 = rf(channelId, userId)
} else { } else {
if ret.Get(1) != nil { r1 = ret.Error(1)
r1 = ret.Get(1).(*model.AppError)
}
} }
return r0, r1 return r0, r1
} }
// GetMemberCount provides a mock function with given fields: channelId, allowFromCache // GetMemberCount provides a mock function with given fields: channelId, allowFromCache
func (_m *ChannelStore) GetMemberCount(channelId string, allowFromCache bool) (int64, *model.AppError) { func (_m *ChannelStore) GetMemberCount(channelId string, allowFromCache bool) (int64, error) {
ret := _m.Called(channelId, allowFromCache) ret := _m.Called(channelId, allowFromCache)
var r0 int64 var r0 int64
@@ -879,13 +865,11 @@ func (_m *ChannelStore) GetMemberCount(channelId string, allowFromCache bool) (i
r0 = ret.Get(0).(int64) r0 = ret.Get(0).(int64)
} }
var r1 *model.AppError var r1 error
if rf, ok := ret.Get(1).(func(string, bool) *model.AppError); ok { if rf, ok := ret.Get(1).(func(string, bool) error); ok {
r1 = rf(channelId, allowFromCache) r1 = rf(channelId, allowFromCache)
} else { } else {
if ret.Get(1) != nil { r1 = ret.Error(1)
r1 = ret.Get(1).(*model.AppError)
}
} }
return r0, r1 return r0, r1
@@ -906,7 +890,7 @@ func (_m *ChannelStore) GetMemberCountFromCache(channelId string) int64 {
} }
// GetMemberCountsByGroup provides a mock function with given fields: channelID, includeTimezones // GetMemberCountsByGroup provides a mock function with given fields: channelID, includeTimezones
func (_m *ChannelStore) GetMemberCountsByGroup(channelID string, includeTimezones bool) ([]*model.ChannelMemberCountByGroup, *model.AppError) { func (_m *ChannelStore) GetMemberCountsByGroup(channelID string, includeTimezones bool) ([]*model.ChannelMemberCountByGroup, error) {
ret := _m.Called(channelID, includeTimezones) ret := _m.Called(channelID, includeTimezones)
var r0 []*model.ChannelMemberCountByGroup var r0 []*model.ChannelMemberCountByGroup
@@ -918,20 +902,18 @@ func (_m *ChannelStore) GetMemberCountsByGroup(channelID string, includeTimezone
} }
} }
var r1 *model.AppError var r1 error
if rf, ok := ret.Get(1).(func(string, bool) *model.AppError); ok { if rf, ok := ret.Get(1).(func(string, bool) error); ok {
r1 = rf(channelID, includeTimezones) r1 = rf(channelID, includeTimezones)
} else { } else {
if ret.Get(1) != nil { r1 = ret.Error(1)
r1 = ret.Get(1).(*model.AppError)
}
} }
return r0, r1 return r0, r1
} }
// GetMemberForPost provides a mock function with given fields: postId, userId // GetMemberForPost provides a mock function with given fields: postId, userId
func (_m *ChannelStore) GetMemberForPost(postId string, userId string) (*model.ChannelMember, *model.AppError) { func (_m *ChannelStore) GetMemberForPost(postId string, userId string) (*model.ChannelMember, error) {
ret := _m.Called(postId, userId) ret := _m.Called(postId, userId)
var r0 *model.ChannelMember var r0 *model.ChannelMember
@@ -943,20 +925,18 @@ func (_m *ChannelStore) GetMemberForPost(postId string, userId string) (*model.C
} }
} }
var r1 *model.AppError var r1 error
if rf, ok := ret.Get(1).(func(string, string) *model.AppError); ok { if rf, ok := ret.Get(1).(func(string, string) error); ok {
r1 = rf(postId, userId) r1 = rf(postId, userId)
} else { } else {
if ret.Get(1) != nil { r1 = ret.Error(1)
r1 = ret.Get(1).(*model.AppError)
}
} }
return r0, r1 return r0, r1
} }
// GetMembers provides a mock function with given fields: channelId, offset, limit // GetMembers provides a mock function with given fields: channelId, offset, limit
func (_m *ChannelStore) GetMembers(channelId string, offset int, limit int) (*model.ChannelMembers, *model.AppError) { func (_m *ChannelStore) GetMembers(channelId string, offset int, limit int) (*model.ChannelMembers, error) {
ret := _m.Called(channelId, offset, limit) ret := _m.Called(channelId, offset, limit)
var r0 *model.ChannelMembers var r0 *model.ChannelMembers
@@ -968,13 +948,11 @@ func (_m *ChannelStore) GetMembers(channelId string, offset int, limit int) (*mo
} }
} }
var r1 *model.AppError var r1 error
if rf, ok := ret.Get(1).(func(string, int, int) *model.AppError); ok { if rf, ok := ret.Get(1).(func(string, int, int) error); ok {
r1 = rf(channelId, offset, limit) r1 = rf(channelId, offset, limit)
} else { } else {
if ret.Get(1) != nil { r1 = ret.Error(1)
r1 = ret.Get(1).(*model.AppError)
}
} }
return r0, r1 return r0, r1
@@ -1006,7 +984,7 @@ func (_m *ChannelStore) GetMembersByIds(channelId string, userIds []string) (*mo
} }
// GetMembersForUser provides a mock function with given fields: teamId, userId // GetMembersForUser provides a mock function with given fields: teamId, userId
func (_m *ChannelStore) GetMembersForUser(teamId string, userId string) (*model.ChannelMembers, *model.AppError) { func (_m *ChannelStore) GetMembersForUser(teamId string, userId string) (*model.ChannelMembers, error) {
ret := _m.Called(teamId, userId) ret := _m.Called(teamId, userId)
var r0 *model.ChannelMembers var r0 *model.ChannelMembers
@@ -1018,20 +996,18 @@ func (_m *ChannelStore) GetMembersForUser(teamId string, userId string) (*model.
} }
} }
var r1 *model.AppError var r1 error
if rf, ok := ret.Get(1).(func(string, string) *model.AppError); ok { if rf, ok := ret.Get(1).(func(string, string) error); ok {
r1 = rf(teamId, userId) r1 = rf(teamId, userId)
} else { } else {
if ret.Get(1) != nil { r1 = ret.Error(1)
r1 = ret.Get(1).(*model.AppError)
}
} }
return r0, r1 return r0, r1
} }
// GetMembersForUserWithPagination provides a mock function with given fields: teamId, userId, page, perPage // GetMembersForUserWithPagination provides a mock function with given fields: teamId, userId, page, perPage
func (_m *ChannelStore) GetMembersForUserWithPagination(teamId string, userId string, page int, perPage int) (*model.ChannelMembers, *model.AppError) { func (_m *ChannelStore) GetMembersForUserWithPagination(teamId string, userId string, page int, perPage int) (*model.ChannelMembers, error) {
ret := _m.Called(teamId, userId, page, perPage) ret := _m.Called(teamId, userId, page, perPage)
var r0 *model.ChannelMembers var r0 *model.ChannelMembers
@@ -1043,13 +1019,11 @@ func (_m *ChannelStore) GetMembersForUserWithPagination(teamId string, userId st
} }
} }
var r1 *model.AppError var r1 error
if rf, ok := ret.Get(1).(func(string, string, int, int) *model.AppError); ok { if rf, ok := ret.Get(1).(func(string, string, int, int) error); ok {
r1 = rf(teamId, userId, page, perPage) r1 = rf(teamId, userId, page, perPage)
} else { } else {
if ret.Get(1) != nil { r1 = ret.Error(1)
r1 = ret.Get(1).(*model.AppError)
}
} }
return r0, r1 return r0, r1
@@ -1079,7 +1053,7 @@ func (_m *ChannelStore) GetMoreChannels(teamId string, userId string, offset int
} }
// GetPinnedPostCount provides a mock function with given fields: channelId, allowFromCache // GetPinnedPostCount provides a mock function with given fields: channelId, allowFromCache
func (_m *ChannelStore) GetPinnedPostCount(channelId string, allowFromCache bool) (int64, *model.AppError) { func (_m *ChannelStore) GetPinnedPostCount(channelId string, allowFromCache bool) (int64, error) {
ret := _m.Called(channelId, allowFromCache) ret := _m.Called(channelId, allowFromCache)
var r0 int64 var r0 int64
@@ -1089,20 +1063,18 @@ func (_m *ChannelStore) GetPinnedPostCount(channelId string, allowFromCache bool
r0 = ret.Get(0).(int64) r0 = ret.Get(0).(int64)
} }
var r1 *model.AppError var r1 error
if rf, ok := ret.Get(1).(func(string, bool) *model.AppError); ok { if rf, ok := ret.Get(1).(func(string, bool) error); ok {
r1 = rf(channelId, allowFromCache) r1 = rf(channelId, allowFromCache)
} else { } else {
if ret.Get(1) != nil { r1 = ret.Error(1)
r1 = ret.Get(1).(*model.AppError)
}
} }
return r0, r1 return r0, r1
} }
// GetPinnedPosts provides a mock function with given fields: channelId // GetPinnedPosts provides a mock function with given fields: channelId
func (_m *ChannelStore) GetPinnedPosts(channelId string) (*model.PostList, *model.AppError) { func (_m *ChannelStore) GetPinnedPosts(channelId string) (*model.PostList, error) {
ret := _m.Called(channelId) ret := _m.Called(channelId)
var r0 *model.PostList var r0 *model.PostList
@@ -1114,13 +1086,11 @@ func (_m *ChannelStore) GetPinnedPosts(channelId string) (*model.PostList, *mode
} }
} }
var r1 *model.AppError var r1 error
if rf, ok := ret.Get(1).(func(string) *model.AppError); ok { if rf, ok := ret.Get(1).(func(string) error); ok {
r1 = rf(channelId) r1 = rf(channelId)
} else { } else {
if ret.Get(1) != nil { r1 = ret.Error(1)
r1 = ret.Get(1).(*model.AppError)
}
} }
return r0, r1 return r0, r1
@@ -1317,16 +1287,14 @@ func (_m *ChannelStore) GroupSyncedChannelCount() (int64, *model.AppError) {
} }
// IncrementMentionCount provides a mock function with given fields: channelId, userId // IncrementMentionCount provides a mock function with given fields: channelId, userId
func (_m *ChannelStore) IncrementMentionCount(channelId string, userId string) *model.AppError { func (_m *ChannelStore) IncrementMentionCount(channelId string, userId string) error {
ret := _m.Called(channelId, userId) ret := _m.Called(channelId, userId)
var r0 *model.AppError var r0 error
if rf, ok := ret.Get(0).(func(string, string) *model.AppError); ok { if rf, ok := ret.Get(0).(func(string, string) error); ok {
r0 = rf(channelId, userId) r0 = rf(channelId, userId)
} else { } else {
if ret.Get(0) != nil { r0 = ret.Error(0)
r0 = ret.Get(0).(*model.AppError)
}
} }
return r0 return r0
@@ -1449,32 +1417,28 @@ func (_m *ChannelStore) PermanentDeleteByTeam(teamId string) error {
} }
// PermanentDeleteMembersByChannel provides a mock function with given fields: channelId // PermanentDeleteMembersByChannel provides a mock function with given fields: channelId
func (_m *ChannelStore) PermanentDeleteMembersByChannel(channelId string) *model.AppError { func (_m *ChannelStore) PermanentDeleteMembersByChannel(channelId string) error {
ret := _m.Called(channelId) ret := _m.Called(channelId)
var r0 *model.AppError var r0 error
if rf, ok := ret.Get(0).(func(string) *model.AppError); ok { if rf, ok := ret.Get(0).(func(string) error); ok {
r0 = rf(channelId) r0 = rf(channelId)
} else { } else {
if ret.Get(0) != nil { r0 = ret.Error(0)
r0 = ret.Get(0).(*model.AppError)
}
} }
return r0 return r0
} }
// PermanentDeleteMembersByUser provides a mock function with given fields: userId // PermanentDeleteMembersByUser provides a mock function with given fields: userId
func (_m *ChannelStore) PermanentDeleteMembersByUser(userId string) *model.AppError { func (_m *ChannelStore) PermanentDeleteMembersByUser(userId string) error {
ret := _m.Called(userId) ret := _m.Called(userId)
var r0 *model.AppError var r0 error
if rf, ok := ret.Get(0).(func(string) *model.AppError); ok { if rf, ok := ret.Get(0).(func(string) error); ok {
r0 = rf(userId) r0 = rf(userId)
} else { } else {
if ret.Get(0) != nil { r0 = ret.Error(0)
r0 = ret.Get(0).(*model.AppError)
}
} }
return r0 return r0
@@ -1497,32 +1461,28 @@ func (_m *ChannelStore) RemoveAllDeactivatedMembers(channelId string) *model.App
} }
// RemoveMember provides a mock function with given fields: channelId, userId // RemoveMember provides a mock function with given fields: channelId, userId
func (_m *ChannelStore) RemoveMember(channelId string, userId string) *model.AppError { func (_m *ChannelStore) RemoveMember(channelId string, userId string) error {
ret := _m.Called(channelId, userId) ret := _m.Called(channelId, userId)
var r0 *model.AppError var r0 error
if rf, ok := ret.Get(0).(func(string, string) *model.AppError); ok { if rf, ok := ret.Get(0).(func(string, string) error); ok {
r0 = rf(channelId, userId) r0 = rf(channelId, userId)
} else { } else {
if ret.Get(0) != nil { r0 = ret.Error(0)
r0 = ret.Get(0).(*model.AppError)
}
} }
return r0 return r0
} }
// RemoveMembers provides a mock function with given fields: channelId, userIds // RemoveMembers provides a mock function with given fields: channelId, userIds
func (_m *ChannelStore) RemoveMembers(channelId string, userIds []string) *model.AppError { func (_m *ChannelStore) RemoveMembers(channelId string, userIds []string) error {
ret := _m.Called(channelId, userIds) ret := _m.Called(channelId, userIds)
var r0 *model.AppError var r0 error
if rf, ok := ret.Get(0).(func(string, []string) *model.AppError); ok { if rf, ok := ret.Get(0).(func(string, []string) error); ok {
r0 = rf(channelId, userIds) r0 = rf(channelId, userIds)
} else { } else {
if ret.Get(0) != nil { r0 = ret.Error(0)
r0 = ret.Get(0).(*model.AppError)
}
} }
return r0 return r0
@@ -1605,7 +1565,7 @@ func (_m *ChannelStore) SaveDirectChannel(channel *model.Channel, member1 *model
} }
// SaveMember provides a mock function with given fields: member // SaveMember provides a mock function with given fields: member
func (_m *ChannelStore) SaveMember(member *model.ChannelMember) (*model.ChannelMember, *model.AppError) { func (_m *ChannelStore) SaveMember(member *model.ChannelMember) (*model.ChannelMember, error) {
ret := _m.Called(member) ret := _m.Called(member)
var r0 *model.ChannelMember var r0 *model.ChannelMember
@@ -1617,20 +1577,18 @@ func (_m *ChannelStore) SaveMember(member *model.ChannelMember) (*model.ChannelM
} }
} }
var r1 *model.AppError var r1 error
if rf, ok := ret.Get(1).(func(*model.ChannelMember) *model.AppError); ok { if rf, ok := ret.Get(1).(func(*model.ChannelMember) error); ok {
r1 = rf(member) r1 = rf(member)
} else { } else {
if ret.Get(1) != nil { r1 = ret.Error(1)
r1 = ret.Get(1).(*model.AppError)
}
} }
return r0, r1 return r0, r1
} }
// SaveMultipleMembers provides a mock function with given fields: members // SaveMultipleMembers provides a mock function with given fields: members
func (_m *ChannelStore) SaveMultipleMembers(members []*model.ChannelMember) ([]*model.ChannelMember, *model.AppError) { func (_m *ChannelStore) SaveMultipleMembers(members []*model.ChannelMember) ([]*model.ChannelMember, error) {
ret := _m.Called(members) ret := _m.Called(members)
var r0 []*model.ChannelMember var r0 []*model.ChannelMember
@@ -1642,13 +1600,11 @@ func (_m *ChannelStore) SaveMultipleMembers(members []*model.ChannelMember) ([]*
} }
} }
var r1 *model.AppError var r1 error
if rf, ok := ret.Get(1).(func([]*model.ChannelMember) *model.AppError); ok { if rf, ok := ret.Get(1).(func([]*model.ChannelMember) error); ok {
r1 = rf(members) r1 = rf(members)
} else { } else {
if ret.Get(1) != nil { r1 = ret.Error(1)
r1 = ret.Get(1).(*model.AppError)
}
} }
return r0, r1 return r0, r1
@@ -1849,7 +1805,7 @@ func (_m *ChannelStore) Update(channel *model.Channel) (*model.Channel, error) {
} }
// UpdateLastViewedAt provides a mock function with given fields: channelIds, userId // UpdateLastViewedAt provides a mock function with given fields: channelIds, userId
func (_m *ChannelStore) UpdateLastViewedAt(channelIds []string, userId string) (map[string]int64, *model.AppError) { func (_m *ChannelStore) UpdateLastViewedAt(channelIds []string, userId string) (map[string]int64, error) {
ret := _m.Called(channelIds, userId) ret := _m.Called(channelIds, userId)
var r0 map[string]int64 var r0 map[string]int64
@@ -1861,20 +1817,18 @@ func (_m *ChannelStore) UpdateLastViewedAt(channelIds []string, userId string) (
} }
} }
var r1 *model.AppError var r1 error
if rf, ok := ret.Get(1).(func([]string, string) *model.AppError); ok { if rf, ok := ret.Get(1).(func([]string, string) error); ok {
r1 = rf(channelIds, userId) r1 = rf(channelIds, userId)
} else { } else {
if ret.Get(1) != nil { r1 = ret.Error(1)
r1 = ret.Get(1).(*model.AppError)
}
} }
return r0, r1 return r0, r1
} }
// UpdateLastViewedAtPost provides a mock function with given fields: unreadPost, userID, mentionCount // UpdateLastViewedAtPost provides a mock function with given fields: unreadPost, userID, mentionCount
func (_m *ChannelStore) UpdateLastViewedAtPost(unreadPost *model.Post, userID string, mentionCount int) (*model.ChannelUnreadAt, *model.AppError) { func (_m *ChannelStore) UpdateLastViewedAtPost(unreadPost *model.Post, userID string, mentionCount int) (*model.ChannelUnreadAt, error) {
ret := _m.Called(unreadPost, userID, mentionCount) ret := _m.Called(unreadPost, userID, mentionCount)
var r0 *model.ChannelUnreadAt var r0 *model.ChannelUnreadAt
@@ -1886,20 +1840,18 @@ func (_m *ChannelStore) UpdateLastViewedAtPost(unreadPost *model.Post, userID st
} }
} }
var r1 *model.AppError var r1 error
if rf, ok := ret.Get(1).(func(*model.Post, string, int) *model.AppError); ok { if rf, ok := ret.Get(1).(func(*model.Post, string, int) error); ok {
r1 = rf(unreadPost, userID, mentionCount) r1 = rf(unreadPost, userID, mentionCount)
} else { } else {
if ret.Get(1) != nil { r1 = ret.Error(1)
r1 = ret.Get(1).(*model.AppError)
}
} }
return r0, r1 return r0, r1
} }
// UpdateMember provides a mock function with given fields: member // UpdateMember provides a mock function with given fields: member
func (_m *ChannelStore) UpdateMember(member *model.ChannelMember) (*model.ChannelMember, *model.AppError) { func (_m *ChannelStore) UpdateMember(member *model.ChannelMember) (*model.ChannelMember, error) {
ret := _m.Called(member) ret := _m.Called(member)
var r0 *model.ChannelMember var r0 *model.ChannelMember
@@ -1911,13 +1863,11 @@ func (_m *ChannelStore) UpdateMember(member *model.ChannelMember) (*model.Channe
} }
} }
var r1 *model.AppError var r1 error
if rf, ok := ret.Get(1).(func(*model.ChannelMember) *model.AppError); ok { if rf, ok := ret.Get(1).(func(*model.ChannelMember) error); ok {
r1 = rf(member) r1 = rf(member)
} else { } else {
if ret.Get(1) != nil { r1 = ret.Error(1)
r1 = ret.Get(1).(*model.AppError)
}
} }
return r0, r1 return r0, r1
@@ -1940,7 +1890,7 @@ func (_m *ChannelStore) UpdateMembersRole(channelID string, userIDs []string) *m
} }
// UpdateMultipleMembers provides a mock function with given fields: members // UpdateMultipleMembers provides a mock function with given fields: members
func (_m *ChannelStore) UpdateMultipleMembers(members []*model.ChannelMember) ([]*model.ChannelMember, *model.AppError) { func (_m *ChannelStore) UpdateMultipleMembers(members []*model.ChannelMember) ([]*model.ChannelMember, error) {
ret := _m.Called(members) ret := _m.Called(members)
var r0 []*model.ChannelMember var r0 []*model.ChannelMember
@@ -1952,13 +1902,11 @@ func (_m *ChannelStore) UpdateMultipleMembers(members []*model.ChannelMember) ([
} }
} }
var r1 *model.AppError var r1 error
if rf, ok := ret.Get(1).(func([]*model.ChannelMember) *model.AppError); ok { if rf, ok := ret.Get(1).(func([]*model.ChannelMember) error); ok {
r1 = rf(members) r1 = rf(members)
} else { } else {
if ret.Get(1) != nil { r1 = ret.Error(1)
r1 = ret.Get(1).(*model.AppError)
}
} }
return r0, r1 return r0, r1

Просмотреть файл

@@ -774,33 +774,33 @@ func testUserStoreGetProfilesInChannel(t *testing.T, ss store.Store) {
c2, nErr := ss.Channel().Save(ch2, -1) c2, nErr := ss.Channel().Save(ch2, -1)
require.Nil(t, nErr) require.Nil(t, nErr)
_, err = ss.Channel().SaveMember(&model.ChannelMember{ _, nErr = ss.Channel().SaveMember(&model.ChannelMember{
ChannelId: c1.Id, ChannelId: c1.Id,
UserId: u1.Id, UserId: u1.Id,
NotifyProps: model.GetDefaultChannelNotifyProps(), NotifyProps: model.GetDefaultChannelNotifyProps(),
}) })
require.Nil(t, err) require.Nil(t, nErr)
_, err = ss.Channel().SaveMember(&model.ChannelMember{ _, nErr = ss.Channel().SaveMember(&model.ChannelMember{
ChannelId: c1.Id, ChannelId: c1.Id,
UserId: u2.Id, UserId: u2.Id,
NotifyProps: model.GetDefaultChannelNotifyProps(), NotifyProps: model.GetDefaultChannelNotifyProps(),
}) })
require.Nil(t, err) require.Nil(t, nErr)
_, err = ss.Channel().SaveMember(&model.ChannelMember{ _, nErr = ss.Channel().SaveMember(&model.ChannelMember{
ChannelId: c1.Id, ChannelId: c1.Id,
UserId: u3.Id, UserId: u3.Id,
NotifyProps: model.GetDefaultChannelNotifyProps(), NotifyProps: model.GetDefaultChannelNotifyProps(),
}) })
require.Nil(t, err) require.Nil(t, nErr)
_, err = ss.Channel().SaveMember(&model.ChannelMember{ _, nErr = ss.Channel().SaveMember(&model.ChannelMember{
ChannelId: c2.Id, ChannelId: c2.Id,
UserId: u1.Id, UserId: u1.Id,
NotifyProps: model.GetDefaultChannelNotifyProps(), NotifyProps: model.GetDefaultChannelNotifyProps(),
}) })
require.Nil(t, err) require.Nil(t, nErr)
t.Run("get in channel 1, offset 0, limit 100", func(t *testing.T) { t.Run("get in channel 1, offset 0, limit 100", func(t *testing.T) {
users, err := ss.User().GetProfilesInChannel(c1.Id, 0, 100) users, err := ss.User().GetProfilesInChannel(c1.Id, 0, 100)
require.Nil(t, err) require.Nil(t, err)
@@ -879,33 +879,33 @@ func testUserStoreGetProfilesInChannelByStatus(t *testing.T, ss store.Store, s S
c2, nErr := ss.Channel().Save(ch2, -1) c2, nErr := ss.Channel().Save(ch2, -1)
require.Nil(t, nErr) require.Nil(t, nErr)
_, err = ss.Channel().SaveMember(&model.ChannelMember{ _, nErr = ss.Channel().SaveMember(&model.ChannelMember{
ChannelId: c1.Id, ChannelId: c1.Id,
UserId: u1.Id, UserId: u1.Id,
NotifyProps: model.GetDefaultChannelNotifyProps(), NotifyProps: model.GetDefaultChannelNotifyProps(),
}) })
require.Nil(t, err) require.Nil(t, nErr)
_, err = ss.Channel().SaveMember(&model.ChannelMember{ _, nErr = ss.Channel().SaveMember(&model.ChannelMember{
ChannelId: c1.Id, ChannelId: c1.Id,
UserId: u2.Id, UserId: u2.Id,
NotifyProps: model.GetDefaultChannelNotifyProps(), NotifyProps: model.GetDefaultChannelNotifyProps(),
}) })
require.Nil(t, err) require.Nil(t, nErr)
_, err = ss.Channel().SaveMember(&model.ChannelMember{ _, nErr = ss.Channel().SaveMember(&model.ChannelMember{
ChannelId: c1.Id, ChannelId: c1.Id,
UserId: u3.Id, UserId: u3.Id,
NotifyProps: model.GetDefaultChannelNotifyProps(), NotifyProps: model.GetDefaultChannelNotifyProps(),
}) })
require.Nil(t, err) require.Nil(t, nErr)
_, err = ss.Channel().SaveMember(&model.ChannelMember{ _, nErr = ss.Channel().SaveMember(&model.ChannelMember{
ChannelId: c2.Id, ChannelId: c2.Id,
UserId: u1.Id, UserId: u1.Id,
NotifyProps: model.GetDefaultChannelNotifyProps(), NotifyProps: model.GetDefaultChannelNotifyProps(),
}) })
require.Nil(t, err) require.Nil(t, nErr)
require.Nil(t, ss.Status().SaveOrUpdate(&model.Status{ require.Nil(t, ss.Status().SaveOrUpdate(&model.Status{
UserId: u1.Id, UserId: u1.Id,
Status: model.STATUS_DND, Status: model.STATUS_DND,
@@ -1055,35 +1055,33 @@ func testUserStoreGetAllProfilesInChannel(t *testing.T, ss store.Store) {
c2, nErr := ss.Channel().Save(ch2, -1) c2, nErr := ss.Channel().Save(ch2, -1)
require.Nil(t, nErr) require.Nil(t, nErr)
_, err = ss.Channel().SaveMember(&model.ChannelMember{ _, nErr = ss.Channel().SaveMember(&model.ChannelMember{
ChannelId: c1.Id, ChannelId: c1.Id,
UserId: u1.Id, UserId: u1.Id,
NotifyProps: model.GetDefaultChannelNotifyProps(), NotifyProps: model.GetDefaultChannelNotifyProps(),
}) })
if err != nil { require.Nil(t, nErr)
panic(err)
}
_, err = ss.Channel().SaveMember(&model.ChannelMember{ _, nErr = ss.Channel().SaveMember(&model.ChannelMember{
ChannelId: c1.Id, ChannelId: c1.Id,
UserId: u2.Id, UserId: u2.Id,
NotifyProps: model.GetDefaultChannelNotifyProps(), NotifyProps: model.GetDefaultChannelNotifyProps(),
}) })
require.Nil(t, err) require.Nil(t, nErr)
_, err = ss.Channel().SaveMember(&model.ChannelMember{ _, nErr = ss.Channel().SaveMember(&model.ChannelMember{
ChannelId: c1.Id, ChannelId: c1.Id,
UserId: u3.Id, UserId: u3.Id,
NotifyProps: model.GetDefaultChannelNotifyProps(), NotifyProps: model.GetDefaultChannelNotifyProps(),
}) })
require.Nil(t, err) require.Nil(t, nErr)
_, err = ss.Channel().SaveMember(&model.ChannelMember{ _, nErr = ss.Channel().SaveMember(&model.ChannelMember{
ChannelId: c2.Id, ChannelId: c2.Id,
UserId: u1.Id, UserId: u1.Id,
NotifyProps: model.GetDefaultChannelNotifyProps(), NotifyProps: model.GetDefaultChannelNotifyProps(),
}) })
require.Nil(t, err) require.Nil(t, nErr)
t.Run("all profiles in channel 1, no caching", func(t *testing.T) { t.Run("all profiles in channel 1, no caching", func(t *testing.T) {
var profiles map[string]*model.User var profiles map[string]*model.User
@@ -1205,35 +1203,34 @@ func testUserStoreGetProfilesNotInChannel(t *testing.T, ss store.Store) {
}, profiles) }, profiles)
}) })
_, err = ss.Channel().SaveMember(&model.ChannelMember{ _, nErr = ss.Channel().SaveMember(&model.ChannelMember{
ChannelId: c1.Id, ChannelId: c1.Id,
UserId: u1.Id, UserId: u1.Id,
NotifyProps: model.GetDefaultChannelNotifyProps(), NotifyProps: model.GetDefaultChannelNotifyProps(),
}) })
require.Nil(t, err) require.Nil(t, nErr)
_, err = ss.Channel().SaveMember(&model.ChannelMember{ _, nErr = ss.Channel().SaveMember(&model.ChannelMember{
ChannelId: c1.Id, ChannelId: c1.Id,
UserId: u2.Id, UserId: u2.Id,
NotifyProps: model.GetDefaultChannelNotifyProps(), NotifyProps: model.GetDefaultChannelNotifyProps(),
}) })
require.Nil(t, err) require.Nil(t, nErr)
_, err = ss.Channel().SaveMember(&model.ChannelMember{ _, nErr = ss.Channel().SaveMember(&model.ChannelMember{
ChannelId: c1.Id, ChannelId: c1.Id,
UserId: u3.Id, UserId: u3.Id,
NotifyProps: model.GetDefaultChannelNotifyProps(), NotifyProps: model.GetDefaultChannelNotifyProps(),
}) })
require.Nil(t, err) require.Nil(t, nErr)
_, err = ss.Channel().SaveMember(&model.ChannelMember{ _, nErr = ss.Channel().SaveMember(&model.ChannelMember{
ChannelId: c2.Id, ChannelId: c2.Id,
UserId: u1.Id, UserId: u1.Id,
NotifyProps: model.GetDefaultChannelNotifyProps(), NotifyProps: model.GetDefaultChannelNotifyProps(),
}) })
if err != nil { require.Nil(t, nErr)
panic(err)
}
t.Run("get team 1, channel 1, offset 0, limit 100, after update", func(t *testing.T) { t.Run("get team 1, channel 1, offset 0, limit 100, after update", func(t *testing.T) {
var profiles []*model.User var profiles []*model.User
profiles, err = ss.User().GetProfilesNotInChannel(teamId, c1.Id, false, 0, 100, nil) profiles, err = ss.User().GetProfilesNotInChannel(teamId, c1.Id, false, 0, 100, nil)
@@ -1413,12 +1410,12 @@ func testUserStoreGetProfileByGroupChannelIdsForUser(t *testing.T, ss store.Stor
require.Nil(t, nErr) require.Nil(t, nErr)
for _, uId := range []string{u1.Id, u2.Id, u3.Id} { for _, uId := range []string{u1.Id, u2.Id, u3.Id} {
_, err = ss.Channel().SaveMember(&model.ChannelMember{ _, nErr = ss.Channel().SaveMember(&model.ChannelMember{
ChannelId: gc1.Id, ChannelId: gc1.Id,
UserId: uId, UserId: uId,
NotifyProps: model.GetDefaultChannelNotifyProps(), NotifyProps: model.GetDefaultChannelNotifyProps(),
}) })
require.Nil(t, err) require.Nil(t, nErr)
} }
gc2, nErr := ss.Channel().Save(&model.Channel{ gc2, nErr := ss.Channel().Save(&model.Channel{
@@ -1429,12 +1426,12 @@ func testUserStoreGetProfileByGroupChannelIdsForUser(t *testing.T, ss store.Stor
require.Nil(t, nErr) require.Nil(t, nErr)
for _, uId := range []string{u1.Id, u3.Id, u4.Id} { for _, uId := range []string{u1.Id, u3.Id, u4.Id} {
_, err = ss.Channel().SaveMember(&model.ChannelMember{ _, nErr = ss.Channel().SaveMember(&model.ChannelMember{
ChannelId: gc2.Id, ChannelId: gc2.Id,
UserId: uId, UserId: uId,
NotifyProps: model.GetDefaultChannelNotifyProps(), NotifyProps: model.GetDefaultChannelNotifyProps(),
}) })
require.Nil(t, err) require.Nil(t, nErr)
} }
testCases := []struct { testCases := []struct {
@@ -2040,8 +2037,8 @@ func testUserUnreadCount(t *testing.T, ss store.Store) {
m2.UserId = u2.Id m2.UserId = u2.Id
m2.NotifyProps = model.GetDefaultChannelNotifyProps() m2.NotifyProps = model.GetDefaultChannelNotifyProps()
_, err = ss.Channel().SaveMember(&m2) _, nErr = ss.Channel().SaveMember(&m2)
require.Nil(t, err) require.Nil(t, nErr)
m1.ChannelId = c2.Id m1.ChannelId = c2.Id
m2.ChannelId = c2.Id m2.ChannelId = c2.Id
@@ -2057,8 +2054,8 @@ func testUserUnreadCount(t *testing.T, ss store.Store) {
// Post one message with mention to open channel // Post one message with mention to open channel
_, nErr = ss.Post().Save(&p1) _, nErr = ss.Post().Save(&p1)
require.Nil(t, nErr) require.Nil(t, nErr)
err = ss.Channel().IncrementMentionCount(c1.Id, u2.Id) nErr = ss.Channel().IncrementMentionCount(c1.Id, u2.Id)
require.Nil(t, err) require.Nil(t, nErr)
// Post 2 messages without mention to direct channel // Post 2 messages without mention to direct channel
p2 := model.Post{} p2 := model.Post{}
@@ -2068,8 +2065,8 @@ func testUserUnreadCount(t *testing.T, ss store.Store) {
_, nErr = ss.Post().Save(&p2) _, nErr = ss.Post().Save(&p2)
require.Nil(t, nErr) require.Nil(t, nErr)
err = ss.Channel().IncrementMentionCount(c2.Id, u2.Id) nErr = ss.Channel().IncrementMentionCount(c2.Id, u2.Id)
require.Nil(t, err) require.Nil(t, nErr)
p3 := model.Post{} p3 := model.Post{}
p3.ChannelId = c2.Id p3.ChannelId = c2.Id
@@ -2078,8 +2075,8 @@ func testUserUnreadCount(t *testing.T, ss store.Store) {
_, nErr = ss.Post().Save(&p3) _, nErr = ss.Post().Save(&p3)
require.Nil(t, nErr) require.Nil(t, nErr)
err = ss.Channel().IncrementMentionCount(c2.Id, u2.Id) nErr = ss.Channel().IncrementMentionCount(c2.Id, u2.Id)
require.Nil(t, err) require.Nil(t, nErr)
badge, unreadCountErr := ss.User().GetUnreadCount(u2.Id) badge, unreadCountErr := ss.User().GetUnreadCount(u2.Id)
require.Nil(t, unreadCountErr) require.Nil(t, unreadCountErr)
@@ -2523,24 +2520,24 @@ func testUserStoreSearchNotInChannel(t *testing.T, ss store.Store) {
c2, nErr := ss.Channel().Save(&ch2, -1) c2, nErr := ss.Channel().Save(&ch2, -1)
require.Nil(t, nErr) require.Nil(t, nErr)
_, err = ss.Channel().SaveMember(&model.ChannelMember{ _, nErr = ss.Channel().SaveMember(&model.ChannelMember{
ChannelId: c2.Id, ChannelId: c2.Id,
UserId: u1.Id, UserId: u1.Id,
NotifyProps: model.GetDefaultChannelNotifyProps(), NotifyProps: model.GetDefaultChannelNotifyProps(),
}) })
require.Nil(t, err) require.Nil(t, nErr)
_, err = ss.Channel().SaveMember(&model.ChannelMember{ _, nErr = ss.Channel().SaveMember(&model.ChannelMember{
ChannelId: c1.Id, ChannelId: c1.Id,
UserId: u3.Id, UserId: u3.Id,
NotifyProps: model.GetDefaultChannelNotifyProps(), NotifyProps: model.GetDefaultChannelNotifyProps(),
}) })
require.Nil(t, err) require.Nil(t, nErr)
_, err = ss.Channel().SaveMember(&model.ChannelMember{ _, nErr = ss.Channel().SaveMember(&model.ChannelMember{
ChannelId: c2.Id, ChannelId: c2.Id,
UserId: u2.Id, UserId: u2.Id,
NotifyProps: model.GetDefaultChannelNotifyProps(), NotifyProps: model.GetDefaultChannelNotifyProps(),
}) })
require.Nil(t, err) require.Nil(t, nErr)
testCases := []struct { testCases := []struct {
Description string Description string
@@ -2752,30 +2749,30 @@ func testUserStoreSearchInChannel(t *testing.T, ss store.Store) {
c2, nErr := ss.Channel().Save(&ch2, -1) c2, nErr := ss.Channel().Save(&ch2, -1)
require.Nil(t, nErr) require.Nil(t, nErr)
_, err = ss.Channel().SaveMember(&model.ChannelMember{ _, nErr = ss.Channel().SaveMember(&model.ChannelMember{
ChannelId: c1.Id, ChannelId: c1.Id,
UserId: u1.Id, UserId: u1.Id,
NotifyProps: model.GetDefaultChannelNotifyProps(), NotifyProps: model.GetDefaultChannelNotifyProps(),
SchemeAdmin: true, SchemeAdmin: true,
SchemeUser: true, SchemeUser: true,
}) })
require.Nil(t, err) require.Nil(t, nErr)
_, err = ss.Channel().SaveMember(&model.ChannelMember{ _, nErr = ss.Channel().SaveMember(&model.ChannelMember{
ChannelId: c2.Id, ChannelId: c2.Id,
UserId: u2.Id, UserId: u2.Id,
NotifyProps: model.GetDefaultChannelNotifyProps(), NotifyProps: model.GetDefaultChannelNotifyProps(),
SchemeAdmin: false, SchemeAdmin: false,
SchemeUser: true, SchemeUser: true,
}) })
require.Nil(t, err) require.Nil(t, nErr)
_, err = ss.Channel().SaveMember(&model.ChannelMember{ _, nErr = ss.Channel().SaveMember(&model.ChannelMember{
ChannelId: c1.Id, ChannelId: c1.Id,
UserId: u3.Id, UserId: u3.Id,
NotifyProps: model.GetDefaultChannelNotifyProps(), NotifyProps: model.GetDefaultChannelNotifyProps(),
SchemeAdmin: false, SchemeAdmin: false,
SchemeUser: true, SchemeUser: true,
}) })
require.Nil(t, err) require.Nil(t, nErr)
testCases := []struct { testCases := []struct {
Description string Description string
@@ -3361,8 +3358,8 @@ func testCount(t *testing.T, ss store.Store) {
defer func() { require.Nil(t, ss.User().PermanentDelete(regularUser.Id)) }() defer func() { require.Nil(t, ss.User().PermanentDelete(regularUser.Id)) }()
_, nErr := ss.Team().SaveMember(&model.TeamMember{TeamId: teamId, UserId: regularUser.Id, SchemeAdmin: false, SchemeUser: true}, -1) _, nErr := ss.Team().SaveMember(&model.TeamMember{TeamId: teamId, UserId: regularUser.Id, SchemeAdmin: false, SchemeUser: true}, -1)
require.Nil(t, nErr) require.Nil(t, nErr)
_, err = ss.Channel().SaveMember(&model.ChannelMember{UserId: regularUser.Id, ChannelId: channelId, SchemeAdmin: false, SchemeUser: true, NotifyProps: model.GetDefaultChannelNotifyProps()}) _, nErr = ss.Channel().SaveMember(&model.ChannelMember{UserId: regularUser.Id, ChannelId: channelId, SchemeAdmin: false, SchemeUser: true, NotifyProps: model.GetDefaultChannelNotifyProps()})
require.Nil(t, err) require.Nil(t, nErr)
guestUser := &model.User{} guestUser := &model.User{}
guestUser.Email = MakeEmail() guestUser.Email = MakeEmail()
@@ -3372,8 +3369,8 @@ func testCount(t *testing.T, ss store.Store) {
defer func() { require.Nil(t, ss.User().PermanentDelete(guestUser.Id)) }() defer func() { require.Nil(t, ss.User().PermanentDelete(guestUser.Id)) }()
_, nErr = ss.Team().SaveMember(&model.TeamMember{TeamId: teamId, UserId: guestUser.Id, SchemeAdmin: false, SchemeUser: false, SchemeGuest: true}, -1) _, nErr = ss.Team().SaveMember(&model.TeamMember{TeamId: teamId, UserId: guestUser.Id, SchemeAdmin: false, SchemeUser: false, SchemeGuest: true}, -1)
require.Nil(t, nErr) require.Nil(t, nErr)
_, err = ss.Channel().SaveMember(&model.ChannelMember{UserId: guestUser.Id, ChannelId: channelId, SchemeAdmin: false, SchemeUser: false, SchemeGuest: true, NotifyProps: model.GetDefaultChannelNotifyProps()}) _, nErr = ss.Channel().SaveMember(&model.ChannelMember{UserId: guestUser.Id, ChannelId: channelId, SchemeAdmin: false, SchemeUser: false, SchemeGuest: true, NotifyProps: model.GetDefaultChannelNotifyProps()})
require.Nil(t, err) require.Nil(t, nErr)
teamAdmin := &model.User{} teamAdmin := &model.User{}
teamAdmin.Email = MakeEmail() teamAdmin.Email = MakeEmail()
@@ -3383,8 +3380,8 @@ func testCount(t *testing.T, ss store.Store) {
defer func() { require.Nil(t, ss.User().PermanentDelete(teamAdmin.Id)) }() defer func() { require.Nil(t, ss.User().PermanentDelete(teamAdmin.Id)) }()
_, nErr = ss.Team().SaveMember(&model.TeamMember{TeamId: teamId, UserId: teamAdmin.Id, SchemeAdmin: true, SchemeUser: true}, -1) _, nErr = ss.Team().SaveMember(&model.TeamMember{TeamId: teamId, UserId: teamAdmin.Id, SchemeAdmin: true, SchemeUser: true}, -1)
require.Nil(t, nErr) require.Nil(t, nErr)
_, err = ss.Channel().SaveMember(&model.ChannelMember{UserId: teamAdmin.Id, ChannelId: channelId, SchemeAdmin: true, SchemeUser: true, NotifyProps: model.GetDefaultChannelNotifyProps()}) _, nErr = ss.Channel().SaveMember(&model.ChannelMember{UserId: teamAdmin.Id, ChannelId: channelId, SchemeAdmin: true, SchemeUser: true, NotifyProps: model.GetDefaultChannelNotifyProps()})
require.Nil(t, err) require.Nil(t, nErr)
sysAdmin := &model.User{} sysAdmin := &model.User{}
sysAdmin.Email = MakeEmail() sysAdmin.Email = MakeEmail()
@@ -3394,8 +3391,8 @@ func testCount(t *testing.T, ss store.Store) {
defer func() { require.Nil(t, ss.User().PermanentDelete(sysAdmin.Id)) }() defer func() { require.Nil(t, ss.User().PermanentDelete(sysAdmin.Id)) }()
_, nErr = ss.Team().SaveMember(&model.TeamMember{TeamId: teamId, UserId: sysAdmin.Id, SchemeAdmin: false, SchemeUser: true}, -1) _, nErr = ss.Team().SaveMember(&model.TeamMember{TeamId: teamId, UserId: sysAdmin.Id, SchemeAdmin: false, SchemeUser: true}, -1)
require.Nil(t, nErr) require.Nil(t, nErr)
_, err = ss.Channel().SaveMember(&model.ChannelMember{UserId: sysAdmin.Id, ChannelId: channelId, SchemeAdmin: true, SchemeUser: true, NotifyProps: model.GetDefaultChannelNotifyProps()}) _, nErr = ss.Channel().SaveMember(&model.ChannelMember{UserId: sysAdmin.Id, ChannelId: channelId, SchemeAdmin: true, SchemeUser: true, NotifyProps: model.GetDefaultChannelNotifyProps()})
require.Nil(t, err) require.Nil(t, nErr)
// Deleted // Deleted
deletedUser := &model.User{} deletedUser := &model.User{}
@@ -4522,8 +4519,8 @@ func testUserStorePromoteGuestToUser(t *testing.T, ss store.Store) {
Type: model.CHANNEL_OPEN, Type: model.CHANNEL_OPEN,
}, -1) }, -1)
require.Nil(t, nErr) require.Nil(t, nErr)
_, err = ss.Channel().SaveMember(&model.ChannelMember{ChannelId: channel.Id, UserId: user.Id, SchemeGuest: true, SchemeUser: false, NotifyProps: model.GetDefaultChannelNotifyProps()}) _, nErr = ss.Channel().SaveMember(&model.ChannelMember{ChannelId: channel.Id, UserId: user.Id, SchemeGuest: true, SchemeUser: false, NotifyProps: model.GetDefaultChannelNotifyProps()})
require.Nil(t, err) require.Nil(t, nErr)
err = ss.User().PromoteGuestToUser(user.Id) err = ss.User().PromoteGuestToUser(user.Id)
require.Nil(t, err) require.Nil(t, err)
@@ -4537,8 +4534,8 @@ func testUserStorePromoteGuestToUser(t *testing.T, ss store.Store) {
require.False(t, updatedTeamMember.SchemeGuest) require.False(t, updatedTeamMember.SchemeGuest)
require.True(t, updatedTeamMember.SchemeUser) require.True(t, updatedTeamMember.SchemeUser)
updatedChannelMember, err := ss.Channel().GetMember(channel.Id, user.Id) updatedChannelMember, nErr := ss.Channel().GetMember(channel.Id, user.Id)
require.Nil(t, err) require.Nil(t, nErr)
require.False(t, updatedChannelMember.SchemeGuest) require.False(t, updatedChannelMember.SchemeGuest)
require.True(t, updatedChannelMember.SchemeUser) require.True(t, updatedChannelMember.SchemeUser)
}) })
@@ -4568,8 +4565,8 @@ func testUserStorePromoteGuestToUser(t *testing.T, ss store.Store) {
Type: model.CHANNEL_OPEN, Type: model.CHANNEL_OPEN,
}, -1) }, -1)
require.Nil(t, nErr) require.Nil(t, nErr)
_, err = ss.Channel().SaveMember(&model.ChannelMember{ChannelId: channel.Id, UserId: user.Id, SchemeGuest: true, SchemeUser: false, NotifyProps: model.GetDefaultChannelNotifyProps()}) _, nErr = ss.Channel().SaveMember(&model.ChannelMember{ChannelId: channel.Id, UserId: user.Id, SchemeGuest: true, SchemeUser: false, NotifyProps: model.GetDefaultChannelNotifyProps()})
require.Nil(t, err) require.Nil(t, nErr)
err = ss.User().PromoteGuestToUser(user.Id) err = ss.User().PromoteGuestToUser(user.Id)
require.Nil(t, err) require.Nil(t, err)
@@ -4582,8 +4579,8 @@ func testUserStorePromoteGuestToUser(t *testing.T, ss store.Store) {
require.False(t, updatedTeamMember.SchemeGuest) require.False(t, updatedTeamMember.SchemeGuest)
require.True(t, updatedTeamMember.SchemeUser) require.True(t, updatedTeamMember.SchemeUser)
updatedChannelMember, err := ss.Channel().GetMember(channel.Id, user.Id) updatedChannelMember, nErr := ss.Channel().GetMember(channel.Id, user.Id)
require.Nil(t, err) require.Nil(t, nErr)
require.False(t, updatedChannelMember.SchemeGuest) require.False(t, updatedChannelMember.SchemeGuest)
require.True(t, updatedChannelMember.SchemeUser) require.True(t, updatedChannelMember.SchemeUser)
}) })
@@ -4664,8 +4661,8 @@ func testUserStorePromoteGuestToUser(t *testing.T, ss store.Store) {
Type: model.CHANNEL_OPEN, Type: model.CHANNEL_OPEN,
}, -1) }, -1)
require.Nil(t, nErr) require.Nil(t, nErr)
_, err = ss.Channel().SaveMember(&model.ChannelMember{ChannelId: channel.Id, UserId: user.Id, SchemeGuest: true, SchemeUser: false, NotifyProps: model.GetDefaultChannelNotifyProps()}) _, nErr = ss.Channel().SaveMember(&model.ChannelMember{ChannelId: channel.Id, UserId: user.Id, SchemeGuest: true, SchemeUser: false, NotifyProps: model.GetDefaultChannelNotifyProps()})
require.Nil(t, err) require.Nil(t, nErr)
err = ss.User().PromoteGuestToUser(user.Id) err = ss.User().PromoteGuestToUser(user.Id)
require.Nil(t, err) require.Nil(t, err)
@@ -4678,8 +4675,8 @@ func testUserStorePromoteGuestToUser(t *testing.T, ss store.Store) {
require.False(t, updatedTeamMember.SchemeGuest) require.False(t, updatedTeamMember.SchemeGuest)
require.True(t, updatedTeamMember.SchemeUser) require.True(t, updatedTeamMember.SchemeUser)
updatedChannelMember, err := ss.Channel().GetMember(channel.Id, user.Id) updatedChannelMember, nErr := ss.Channel().GetMember(channel.Id, user.Id)
require.Nil(t, err) require.Nil(t, nErr)
require.False(t, updatedChannelMember.SchemeGuest) require.False(t, updatedChannelMember.SchemeGuest)
require.True(t, updatedChannelMember.SchemeUser) require.True(t, updatedChannelMember.SchemeUser)
}) })
@@ -4709,8 +4706,8 @@ func testUserStorePromoteGuestToUser(t *testing.T, ss store.Store) {
Type: model.CHANNEL_OPEN, Type: model.CHANNEL_OPEN,
}, -1) }, -1)
require.Nil(t, nErr) require.Nil(t, nErr)
_, err = ss.Channel().SaveMember(&model.ChannelMember{ChannelId: channel.Id, UserId: user.Id, SchemeGuest: true, SchemeUser: false, NotifyProps: model.GetDefaultChannelNotifyProps()}) _, nErr = ss.Channel().SaveMember(&model.ChannelMember{ChannelId: channel.Id, UserId: user.Id, SchemeGuest: true, SchemeUser: false, NotifyProps: model.GetDefaultChannelNotifyProps()})
require.Nil(t, err) require.Nil(t, nErr)
err = ss.User().PromoteGuestToUser(user.Id) err = ss.User().PromoteGuestToUser(user.Id)
require.Nil(t, err) require.Nil(t, err)
@@ -4723,8 +4720,8 @@ func testUserStorePromoteGuestToUser(t *testing.T, ss store.Store) {
require.False(t, updatedTeamMember.SchemeGuest) require.False(t, updatedTeamMember.SchemeGuest)
require.True(t, updatedTeamMember.SchemeUser) require.True(t, updatedTeamMember.SchemeUser)
updatedChannelMember, err := ss.Channel().GetMember(channel.Id, user.Id) updatedChannelMember, nErr := ss.Channel().GetMember(channel.Id, user.Id)
require.Nil(t, err) require.Nil(t, nErr)
require.False(t, updatedChannelMember.SchemeGuest) require.False(t, updatedChannelMember.SchemeGuest)
require.True(t, updatedChannelMember.SchemeUser) require.True(t, updatedChannelMember.SchemeUser)
}) })
@@ -4755,8 +4752,8 @@ func testUserStorePromoteGuestToUser(t *testing.T, ss store.Store) {
}, -1) }, -1)
require.Nil(t, nErr) require.Nil(t, nErr)
_, err = ss.Channel().SaveMember(&model.ChannelMember{ChannelId: channel.Id, UserId: user1.Id, SchemeGuest: true, SchemeUser: false, NotifyProps: model.GetDefaultChannelNotifyProps()}) _, nErr = ss.Channel().SaveMember(&model.ChannelMember{ChannelId: channel.Id, UserId: user1.Id, SchemeGuest: true, SchemeUser: false, NotifyProps: model.GetDefaultChannelNotifyProps()})
require.Nil(t, err) require.Nil(t, nErr)
id = model.NewId() id = model.NewId()
user2, err := ss.User().Save(&model.User{ user2, err := ss.User().Save(&model.User{
@@ -4775,8 +4772,8 @@ func testUserStorePromoteGuestToUser(t *testing.T, ss store.Store) {
_, nErr = ss.Team().SaveMember(&model.TeamMember{TeamId: teamId2, UserId: user2.Id, SchemeGuest: true, SchemeUser: false}, 999) _, nErr = ss.Team().SaveMember(&model.TeamMember{TeamId: teamId2, UserId: user2.Id, SchemeGuest: true, SchemeUser: false}, 999)
require.Nil(t, nErr) require.Nil(t, nErr)
_, err = ss.Channel().SaveMember(&model.ChannelMember{ChannelId: channel.Id, UserId: user2.Id, SchemeGuest: true, SchemeUser: false, NotifyProps: model.GetDefaultChannelNotifyProps()}) _, nErr = ss.Channel().SaveMember(&model.ChannelMember{ChannelId: channel.Id, UserId: user2.Id, SchemeGuest: true, SchemeUser: false, NotifyProps: model.GetDefaultChannelNotifyProps()})
require.Nil(t, err) require.Nil(t, nErr)
err = ss.User().PromoteGuestToUser(user1.Id) err = ss.User().PromoteGuestToUser(user1.Id)
require.Nil(t, err) require.Nil(t, err)
@@ -4789,8 +4786,8 @@ func testUserStorePromoteGuestToUser(t *testing.T, ss store.Store) {
require.False(t, updatedTeamMember.SchemeGuest) require.False(t, updatedTeamMember.SchemeGuest)
require.True(t, updatedTeamMember.SchemeUser) require.True(t, updatedTeamMember.SchemeUser)
updatedChannelMember, err := ss.Channel().GetMember(channel.Id, user1.Id) updatedChannelMember, nErr := ss.Channel().GetMember(channel.Id, user1.Id)
require.Nil(t, err) require.Nil(t, nErr)
require.False(t, updatedChannelMember.SchemeGuest) require.False(t, updatedChannelMember.SchemeGuest)
require.True(t, updatedChannelMember.SchemeUser) require.True(t, updatedChannelMember.SchemeUser)
@@ -4803,8 +4800,8 @@ func testUserStorePromoteGuestToUser(t *testing.T, ss store.Store) {
require.True(t, notUpdatedTeamMember.SchemeGuest) require.True(t, notUpdatedTeamMember.SchemeGuest)
require.False(t, notUpdatedTeamMember.SchemeUser) require.False(t, notUpdatedTeamMember.SchemeUser)
notUpdatedChannelMember, err := ss.Channel().GetMember(channel.Id, user2.Id) notUpdatedChannelMember, nErr := ss.Channel().GetMember(channel.Id, user2.Id)
require.Nil(t, err) require.Nil(t, nErr)
require.True(t, notUpdatedChannelMember.SchemeGuest) require.True(t, notUpdatedChannelMember.SchemeGuest)
require.False(t, notUpdatedChannelMember.SchemeUser) require.False(t, notUpdatedChannelMember.SchemeUser)
}) })
@@ -4837,8 +4834,8 @@ func testUserStoreDemoteUserToGuest(t *testing.T, ss store.Store) {
Type: model.CHANNEL_OPEN, Type: model.CHANNEL_OPEN,
}, -1) }, -1)
require.Nil(t, nErr) require.Nil(t, nErr)
_, err = ss.Channel().SaveMember(&model.ChannelMember{ChannelId: channel.Id, UserId: user.Id, SchemeGuest: false, SchemeUser: true, NotifyProps: model.GetDefaultChannelNotifyProps()}) _, nErr = ss.Channel().SaveMember(&model.ChannelMember{ChannelId: channel.Id, UserId: user.Id, SchemeGuest: false, SchemeUser: true, NotifyProps: model.GetDefaultChannelNotifyProps()})
require.Nil(t, err) require.Nil(t, nErr)
err = ss.User().DemoteUserToGuest(user.Id) err = ss.User().DemoteUserToGuest(user.Id)
require.Nil(t, err) require.Nil(t, err)
@@ -4852,8 +4849,8 @@ func testUserStoreDemoteUserToGuest(t *testing.T, ss store.Store) {
require.True(t, updatedTeamMember.SchemeGuest) require.True(t, updatedTeamMember.SchemeGuest)
require.False(t, updatedTeamMember.SchemeUser) require.False(t, updatedTeamMember.SchemeUser)
updatedChannelMember, err := ss.Channel().GetMember(channel.Id, user.Id) updatedChannelMember, nErr := ss.Channel().GetMember(channel.Id, user.Id)
require.Nil(t, err) require.Nil(t, nErr)
require.True(t, updatedChannelMember.SchemeGuest) require.True(t, updatedChannelMember.SchemeGuest)
require.False(t, updatedChannelMember.SchemeUser) require.False(t, updatedChannelMember.SchemeUser)
}) })
@@ -4883,8 +4880,8 @@ func testUserStoreDemoteUserToGuest(t *testing.T, ss store.Store) {
Type: model.CHANNEL_OPEN, Type: model.CHANNEL_OPEN,
}, -1) }, -1)
require.Nil(t, nErr) require.Nil(t, nErr)
_, err = ss.Channel().SaveMember(&model.ChannelMember{ChannelId: channel.Id, UserId: user.Id, SchemeGuest: true, SchemeUser: false, NotifyProps: model.GetDefaultChannelNotifyProps()}) _, nErr = ss.Channel().SaveMember(&model.ChannelMember{ChannelId: channel.Id, UserId: user.Id, SchemeGuest: true, SchemeUser: false, NotifyProps: model.GetDefaultChannelNotifyProps()})
require.Nil(t, err) require.Nil(t, nErr)
err = ss.User().DemoteUserToGuest(user.Id) err = ss.User().DemoteUserToGuest(user.Id)
require.Nil(t, err) require.Nil(t, err)
@@ -4897,8 +4894,8 @@ func testUserStoreDemoteUserToGuest(t *testing.T, ss store.Store) {
require.True(t, updatedTeamMember.SchemeGuest) require.True(t, updatedTeamMember.SchemeGuest)
require.False(t, updatedTeamMember.SchemeUser) require.False(t, updatedTeamMember.SchemeUser)
updatedChannelMember, err := ss.Channel().GetMember(channel.Id, user.Id) updatedChannelMember, nErr := ss.Channel().GetMember(channel.Id, user.Id)
require.Nil(t, err) require.Nil(t, nErr)
require.True(t, updatedChannelMember.SchemeGuest) require.True(t, updatedChannelMember.SchemeGuest)
require.False(t, updatedChannelMember.SchemeUser) require.False(t, updatedChannelMember.SchemeUser)
}) })
@@ -4979,8 +4976,8 @@ func testUserStoreDemoteUserToGuest(t *testing.T, ss store.Store) {
Type: model.CHANNEL_OPEN, Type: model.CHANNEL_OPEN,
}, -1) }, -1)
require.Nil(t, nErr) require.Nil(t, nErr)
_, err = ss.Channel().SaveMember(&model.ChannelMember{ChannelId: channel.Id, UserId: user.Id, SchemeGuest: false, SchemeUser: true, NotifyProps: model.GetDefaultChannelNotifyProps()}) _, nErr = ss.Channel().SaveMember(&model.ChannelMember{ChannelId: channel.Id, UserId: user.Id, SchemeGuest: false, SchemeUser: true, NotifyProps: model.GetDefaultChannelNotifyProps()})
require.Nil(t, err) require.Nil(t, nErr)
err = ss.User().DemoteUserToGuest(user.Id) err = ss.User().DemoteUserToGuest(user.Id)
require.Nil(t, err) require.Nil(t, err)
@@ -4993,8 +4990,8 @@ func testUserStoreDemoteUserToGuest(t *testing.T, ss store.Store) {
require.True(t, updatedTeamMember.SchemeGuest) require.True(t, updatedTeamMember.SchemeGuest)
require.False(t, updatedTeamMember.SchemeUser) require.False(t, updatedTeamMember.SchemeUser)
updatedChannelMember, err := ss.Channel().GetMember(channel.Id, user.Id) updatedChannelMember, nErr := ss.Channel().GetMember(channel.Id, user.Id)
require.Nil(t, err) require.Nil(t, nErr)
require.True(t, updatedChannelMember.SchemeGuest) require.True(t, updatedChannelMember.SchemeGuest)
require.False(t, updatedChannelMember.SchemeUser) require.False(t, updatedChannelMember.SchemeUser)
}) })
@@ -5024,8 +5021,8 @@ func testUserStoreDemoteUserToGuest(t *testing.T, ss store.Store) {
Type: model.CHANNEL_OPEN, Type: model.CHANNEL_OPEN,
}, -1) }, -1)
require.Nil(t, nErr) require.Nil(t, nErr)
_, err = ss.Channel().SaveMember(&model.ChannelMember{ChannelId: channel.Id, UserId: user.Id, SchemeGuest: false, SchemeUser: true, NotifyProps: model.GetDefaultChannelNotifyProps()}) _, nErr = ss.Channel().SaveMember(&model.ChannelMember{ChannelId: channel.Id, UserId: user.Id, SchemeGuest: false, SchemeUser: true, NotifyProps: model.GetDefaultChannelNotifyProps()})
require.Nil(t, err) require.Nil(t, nErr)
err = ss.User().DemoteUserToGuest(user.Id) err = ss.User().DemoteUserToGuest(user.Id)
require.Nil(t, err) require.Nil(t, err)
@@ -5038,8 +5035,8 @@ func testUserStoreDemoteUserToGuest(t *testing.T, ss store.Store) {
require.True(t, updatedTeamMember.SchemeGuest) require.True(t, updatedTeamMember.SchemeGuest)
require.False(t, updatedTeamMember.SchemeUser) require.False(t, updatedTeamMember.SchemeUser)
updatedChannelMember, err := ss.Channel().GetMember(channel.Id, user.Id) updatedChannelMember, nErr := ss.Channel().GetMember(channel.Id, user.Id)
require.Nil(t, err) require.Nil(t, nErr)
require.True(t, updatedChannelMember.SchemeGuest) require.True(t, updatedChannelMember.SchemeGuest)
require.False(t, updatedChannelMember.SchemeUser) require.False(t, updatedChannelMember.SchemeUser)
}) })
@@ -5070,8 +5067,8 @@ func testUserStoreDemoteUserToGuest(t *testing.T, ss store.Store) {
}, -1) }, -1)
require.Nil(t, nErr) require.Nil(t, nErr)
_, err = ss.Channel().SaveMember(&model.ChannelMember{ChannelId: channel.Id, UserId: user1.Id, SchemeGuest: false, SchemeUser: true, NotifyProps: model.GetDefaultChannelNotifyProps()}) _, nErr = ss.Channel().SaveMember(&model.ChannelMember{ChannelId: channel.Id, UserId: user1.Id, SchemeGuest: false, SchemeUser: true, NotifyProps: model.GetDefaultChannelNotifyProps()})
require.Nil(t, err) require.Nil(t, nErr)
id = model.NewId() id = model.NewId()
user2, err := ss.User().Save(&model.User{ user2, err := ss.User().Save(&model.User{
@@ -5090,8 +5087,8 @@ func testUserStoreDemoteUserToGuest(t *testing.T, ss store.Store) {
_, nErr = ss.Team().SaveMember(&model.TeamMember{TeamId: teamId2, UserId: user2.Id, SchemeGuest: false, SchemeUser: true}, 999) _, nErr = ss.Team().SaveMember(&model.TeamMember{TeamId: teamId2, UserId: user2.Id, SchemeGuest: false, SchemeUser: true}, 999)
require.Nil(t, nErr) require.Nil(t, nErr)
_, err = ss.Channel().SaveMember(&model.ChannelMember{ChannelId: channel.Id, UserId: user2.Id, SchemeGuest: false, SchemeUser: true, NotifyProps: model.GetDefaultChannelNotifyProps()}) _, nErr = ss.Channel().SaveMember(&model.ChannelMember{ChannelId: channel.Id, UserId: user2.Id, SchemeGuest: false, SchemeUser: true, NotifyProps: model.GetDefaultChannelNotifyProps()})
require.Nil(t, err) require.Nil(t, nErr)
err = ss.User().DemoteUserToGuest(user1.Id) err = ss.User().DemoteUserToGuest(user1.Id)
require.Nil(t, err) require.Nil(t, err)
@@ -5104,8 +5101,8 @@ func testUserStoreDemoteUserToGuest(t *testing.T, ss store.Store) {
require.True(t, updatedTeamMember.SchemeGuest) require.True(t, updatedTeamMember.SchemeGuest)
require.False(t, updatedTeamMember.SchemeUser) require.False(t, updatedTeamMember.SchemeUser)
updatedChannelMember, err := ss.Channel().GetMember(channel.Id, user1.Id) updatedChannelMember, nErr := ss.Channel().GetMember(channel.Id, user1.Id)
require.Nil(t, err) require.Nil(t, nErr)
require.True(t, updatedChannelMember.SchemeGuest) require.True(t, updatedChannelMember.SchemeGuest)
require.False(t, updatedChannelMember.SchemeUser) require.False(t, updatedChannelMember.SchemeUser)
@@ -5118,8 +5115,8 @@ func testUserStoreDemoteUserToGuest(t *testing.T, ss store.Store) {
require.False(t, notUpdatedTeamMember.SchemeGuest) require.False(t, notUpdatedTeamMember.SchemeGuest)
require.True(t, notUpdatedTeamMember.SchemeUser) require.True(t, notUpdatedTeamMember.SchemeUser)
notUpdatedChannelMember, err := ss.Channel().GetMember(channel.Id, user2.Id) notUpdatedChannelMember, nErr := ss.Channel().GetMember(channel.Id, user2.Id)
require.Nil(t, err) require.Nil(t, nErr)
require.False(t, notUpdatedChannelMember.SchemeGuest) require.False(t, notUpdatedChannelMember.SchemeGuest)
require.True(t, notUpdatedChannelMember.SchemeUser) require.True(t, notUpdatedChannelMember.SchemeUser)
}) })
@@ -5311,40 +5308,40 @@ func testGetKnownUsers(t *testing.T, ss store.Store) {
c3, nErr := ss.Channel().Save(ch3, -1) c3, nErr := ss.Channel().Save(ch3, -1)
require.Nil(t, nErr) require.Nil(t, nErr)
_, err = ss.Channel().SaveMember(&model.ChannelMember{ _, nErr = ss.Channel().SaveMember(&model.ChannelMember{
ChannelId: c1.Id, ChannelId: c1.Id,
UserId: u1.Id, UserId: u1.Id,
NotifyProps: model.GetDefaultChannelNotifyProps(), NotifyProps: model.GetDefaultChannelNotifyProps(),
}) })
require.Nil(t, err) require.Nil(t, nErr)
_, err = ss.Channel().SaveMember(&model.ChannelMember{ _, nErr = ss.Channel().SaveMember(&model.ChannelMember{
ChannelId: c1.Id, ChannelId: c1.Id,
UserId: u2.Id, UserId: u2.Id,
NotifyProps: model.GetDefaultChannelNotifyProps(), NotifyProps: model.GetDefaultChannelNotifyProps(),
}) })
require.Nil(t, err) require.Nil(t, nErr)
_, err = ss.Channel().SaveMember(&model.ChannelMember{ _, nErr = ss.Channel().SaveMember(&model.ChannelMember{
ChannelId: c2.Id, ChannelId: c2.Id,
UserId: u3.Id, UserId: u3.Id,
NotifyProps: model.GetDefaultChannelNotifyProps(), NotifyProps: model.GetDefaultChannelNotifyProps(),
}) })
require.Nil(t, err) require.Nil(t, nErr)
_, err = ss.Channel().SaveMember(&model.ChannelMember{ _, nErr = ss.Channel().SaveMember(&model.ChannelMember{
ChannelId: c2.Id, ChannelId: c2.Id,
UserId: u1.Id, UserId: u1.Id,
NotifyProps: model.GetDefaultChannelNotifyProps(), NotifyProps: model.GetDefaultChannelNotifyProps(),
}) })
require.Nil(t, err) require.Nil(t, nErr)
_, err = ss.Channel().SaveMember(&model.ChannelMember{ _, nErr = ss.Channel().SaveMember(&model.ChannelMember{
ChannelId: c3.Id, ChannelId: c3.Id,
UserId: u4.Id, UserId: u4.Id,
NotifyProps: model.GetDefaultChannelNotifyProps(), NotifyProps: model.GetDefaultChannelNotifyProps(),
}) })
require.Nil(t, err) require.Nil(t, nErr)
t.Run("get know users sharing no channels", func(t *testing.T) { t.Run("get know users sharing no channels", func(t *testing.T) {
userIds, err := ss.User().GetKnownUsers(u4.Id) userIds, err := ss.User().GetKnownUsers(u4.Id)

Просмотреть файл

@@ -474,7 +474,7 @@ func (s *TimerLayerChannelStore) AnalyticsDeletedTypeCount(teamId string, channe
return result, err return result, err
} }
func (s *TimerLayerChannelStore) AnalyticsTypeCount(teamId string, channelType string) (int64, *model.AppError) { func (s *TimerLayerChannelStore) AnalyticsTypeCount(teamId string, channelType string) (int64, error) {
start := timemodule.Now() start := timemodule.Now()
result, err := s.ChannelStore.AnalyticsTypeCount(teamId, channelType) result, err := s.ChannelStore.AnalyticsTypeCount(teamId, channelType)
@@ -569,7 +569,7 @@ func (s *TimerLayerChannelStore) ClearSidebarOnTeamLeave(userId string, teamId s
return err return err
} }
func (s *TimerLayerChannelStore) CountPostsAfter(channelId string, timestamp int64, userId string) (int, *model.AppError) { func (s *TimerLayerChannelStore) CountPostsAfter(channelId string, timestamp int64, userId string) (int, error) {
start := timemodule.Now() start := timemodule.Now()
result, err := s.ChannelStore.CountPostsAfter(channelId, timestamp, userId) result, err := s.ChannelStore.CountPostsAfter(channelId, timestamp, userId)
@@ -713,7 +713,7 @@ func (s *TimerLayerChannelStore) GetAll(teamId string) ([]*model.Channel, error)
return result, err return result, err
} }
func (s *TimerLayerChannelStore) GetAllChannelMembersForUser(userId string, allowFromCache bool, includeDeleted bool) (map[string]string, *model.AppError) { func (s *TimerLayerChannelStore) GetAllChannelMembersForUser(userId string, allowFromCache bool, includeDeleted bool) (map[string]string, error) {
start := timemodule.Now() start := timemodule.Now()
result, err := s.ChannelStore.GetAllChannelMembersForUser(userId, allowFromCache, includeDeleted) result, err := s.ChannelStore.GetAllChannelMembersForUser(userId, allowFromCache, includeDeleted)
@@ -729,7 +729,7 @@ func (s *TimerLayerChannelStore) GetAllChannelMembersForUser(userId string, allo
return result, err return result, err
} }
func (s *TimerLayerChannelStore) GetAllChannelMembersNotifyPropsForChannel(channelId string, allowFromCache bool) (map[string]model.StringMap, *model.AppError) { func (s *TimerLayerChannelStore) GetAllChannelMembersNotifyPropsForChannel(channelId string, allowFromCache bool) (map[string]model.StringMap, error) {
start := timemodule.Now() start := timemodule.Now()
result, err := s.ChannelStore.GetAllChannelMembersNotifyPropsForChannel(channelId, allowFromCache) result, err := s.ChannelStore.GetAllChannelMembersNotifyPropsForChannel(channelId, allowFromCache)
@@ -889,7 +889,7 @@ func (s *TimerLayerChannelStore) GetChannelMembersForExport(userId string, teamI
return result, err return result, err
} }
func (s *TimerLayerChannelStore) GetChannelMembersTimezones(channelId string) ([]model.StringMap, *model.AppError) { func (s *TimerLayerChannelStore) GetChannelMembersTimezones(channelId string) ([]model.StringMap, error) {
start := timemodule.Now() start := timemodule.Now()
result, err := s.ChannelStore.GetChannelMembersTimezones(channelId) result, err := s.ChannelStore.GetChannelMembersTimezones(channelId)
@@ -1049,7 +1049,7 @@ func (s *TimerLayerChannelStore) GetFromMaster(id string) (*model.Channel, error
return result, err return result, err
} }
func (s *TimerLayerChannelStore) GetGuestCount(channelId string, allowFromCache bool) (int64, *model.AppError) { func (s *TimerLayerChannelStore) GetGuestCount(channelId string, allowFromCache bool) (int64, error) {
start := timemodule.Now() start := timemodule.Now()
result, err := s.ChannelStore.GetGuestCount(channelId, allowFromCache) result, err := s.ChannelStore.GetGuestCount(channelId, allowFromCache)
@@ -1065,7 +1065,7 @@ func (s *TimerLayerChannelStore) GetGuestCount(channelId string, allowFromCache
return result, err return result, err
} }
func (s *TimerLayerChannelStore) GetMember(channelId string, userId string) (*model.ChannelMember, *model.AppError) { func (s *TimerLayerChannelStore) GetMember(channelId string, userId string) (*model.ChannelMember, error) {
start := timemodule.Now() start := timemodule.Now()
result, err := s.ChannelStore.GetMember(channelId, userId) result, err := s.ChannelStore.GetMember(channelId, userId)
@@ -1081,7 +1081,7 @@ func (s *TimerLayerChannelStore) GetMember(channelId string, userId string) (*mo
return result, err return result, err
} }
func (s *TimerLayerChannelStore) GetMemberCount(channelId string, allowFromCache bool) (int64, *model.AppError) { func (s *TimerLayerChannelStore) GetMemberCount(channelId string, allowFromCache bool) (int64, error) {
start := timemodule.Now() start := timemodule.Now()
result, err := s.ChannelStore.GetMemberCount(channelId, allowFromCache) result, err := s.ChannelStore.GetMemberCount(channelId, allowFromCache)
@@ -1113,7 +1113,7 @@ func (s *TimerLayerChannelStore) GetMemberCountFromCache(channelId string) int64
return result return result
} }
func (s *TimerLayerChannelStore) GetMemberCountsByGroup(channelID string, includeTimezones bool) ([]*model.ChannelMemberCountByGroup, *model.AppError) { func (s *TimerLayerChannelStore) GetMemberCountsByGroup(channelID string, includeTimezones bool) ([]*model.ChannelMemberCountByGroup, error) {
start := timemodule.Now() start := timemodule.Now()
result, err := s.ChannelStore.GetMemberCountsByGroup(channelID, includeTimezones) result, err := s.ChannelStore.GetMemberCountsByGroup(channelID, includeTimezones)
@@ -1129,7 +1129,7 @@ func (s *TimerLayerChannelStore) GetMemberCountsByGroup(channelID string, includ
return result, err return result, err
} }
func (s *TimerLayerChannelStore) GetMemberForPost(postId string, userId string) (*model.ChannelMember, *model.AppError) { func (s *TimerLayerChannelStore) GetMemberForPost(postId string, userId string) (*model.ChannelMember, error) {
start := timemodule.Now() start := timemodule.Now()
result, err := s.ChannelStore.GetMemberForPost(postId, userId) result, err := s.ChannelStore.GetMemberForPost(postId, userId)
@@ -1145,7 +1145,7 @@ func (s *TimerLayerChannelStore) GetMemberForPost(postId string, userId string)
return result, err return result, err
} }
func (s *TimerLayerChannelStore) GetMembers(channelId string, offset int, limit int) (*model.ChannelMembers, *model.AppError) { func (s *TimerLayerChannelStore) GetMembers(channelId string, offset int, limit int) (*model.ChannelMembers, error) {
start := timemodule.Now() start := timemodule.Now()
result, err := s.ChannelStore.GetMembers(channelId, offset, limit) result, err := s.ChannelStore.GetMembers(channelId, offset, limit)
@@ -1177,7 +1177,7 @@ func (s *TimerLayerChannelStore) GetMembersByIds(channelId string, userIds []str
return result, err return result, err
} }
func (s *TimerLayerChannelStore) GetMembersForUser(teamId string, userId string) (*model.ChannelMembers, *model.AppError) { func (s *TimerLayerChannelStore) GetMembersForUser(teamId string, userId string) (*model.ChannelMembers, error) {
start := timemodule.Now() start := timemodule.Now()
result, err := s.ChannelStore.GetMembersForUser(teamId, userId) result, err := s.ChannelStore.GetMembersForUser(teamId, userId)
@@ -1193,7 +1193,7 @@ func (s *TimerLayerChannelStore) GetMembersForUser(teamId string, userId string)
return result, err return result, err
} }
func (s *TimerLayerChannelStore) GetMembersForUserWithPagination(teamId string, userId string, page int, perPage int) (*model.ChannelMembers, *model.AppError) { func (s *TimerLayerChannelStore) GetMembersForUserWithPagination(teamId string, userId string, page int, perPage int) (*model.ChannelMembers, error) {
start := timemodule.Now() start := timemodule.Now()
result, err := s.ChannelStore.GetMembersForUserWithPagination(teamId, userId, page, perPage) result, err := s.ChannelStore.GetMembersForUserWithPagination(teamId, userId, page, perPage)
@@ -1225,7 +1225,7 @@ func (s *TimerLayerChannelStore) GetMoreChannels(teamId string, userId string, o
return result, err return result, err
} }
func (s *TimerLayerChannelStore) GetPinnedPostCount(channelId string, allowFromCache bool) (int64, *model.AppError) { func (s *TimerLayerChannelStore) GetPinnedPostCount(channelId string, allowFromCache bool) (int64, error) {
start := timemodule.Now() start := timemodule.Now()
result, err := s.ChannelStore.GetPinnedPostCount(channelId, allowFromCache) result, err := s.ChannelStore.GetPinnedPostCount(channelId, allowFromCache)
@@ -1241,7 +1241,7 @@ func (s *TimerLayerChannelStore) GetPinnedPostCount(channelId string, allowFromC
return result, err return result, err
} }
func (s *TimerLayerChannelStore) GetPinnedPosts(channelId string) (*model.PostList, *model.AppError) { func (s *TimerLayerChannelStore) GetPinnedPosts(channelId string) (*model.PostList, error) {
start := timemodule.Now() start := timemodule.Now()
result, err := s.ChannelStore.GetPinnedPosts(channelId) result, err := s.ChannelStore.GetPinnedPosts(channelId)
@@ -1385,7 +1385,7 @@ func (s *TimerLayerChannelStore) GroupSyncedChannelCount() (int64, *model.AppErr
return result, err return result, err
} }
func (s *TimerLayerChannelStore) IncrementMentionCount(channelId string, userId string) *model.AppError { func (s *TimerLayerChannelStore) IncrementMentionCount(channelId string, userId string) error {
start := timemodule.Now() start := timemodule.Now()
err := s.ChannelStore.IncrementMentionCount(channelId, userId) err := s.ChannelStore.IncrementMentionCount(channelId, userId)
@@ -1586,7 +1586,7 @@ func (s *TimerLayerChannelStore) PermanentDeleteByTeam(teamId string) error {
return err return err
} }
func (s *TimerLayerChannelStore) PermanentDeleteMembersByChannel(channelId string) *model.AppError { func (s *TimerLayerChannelStore) PermanentDeleteMembersByChannel(channelId string) error {
start := timemodule.Now() start := timemodule.Now()
err := s.ChannelStore.PermanentDeleteMembersByChannel(channelId) err := s.ChannelStore.PermanentDeleteMembersByChannel(channelId)
@@ -1602,7 +1602,7 @@ func (s *TimerLayerChannelStore) PermanentDeleteMembersByChannel(channelId strin
return err return err
} }
func (s *TimerLayerChannelStore) PermanentDeleteMembersByUser(userId string) *model.AppError { func (s *TimerLayerChannelStore) PermanentDeleteMembersByUser(userId string) error {
start := timemodule.Now() start := timemodule.Now()
err := s.ChannelStore.PermanentDeleteMembersByUser(userId) err := s.ChannelStore.PermanentDeleteMembersByUser(userId)
@@ -1634,7 +1634,7 @@ func (s *TimerLayerChannelStore) RemoveAllDeactivatedMembers(channelId string) *
return err return err
} }
func (s *TimerLayerChannelStore) RemoveMember(channelId string, userId string) *model.AppError { func (s *TimerLayerChannelStore) RemoveMember(channelId string, userId string) error {
start := timemodule.Now() start := timemodule.Now()
err := s.ChannelStore.RemoveMember(channelId, userId) err := s.ChannelStore.RemoveMember(channelId, userId)
@@ -1650,7 +1650,7 @@ func (s *TimerLayerChannelStore) RemoveMember(channelId string, userId string) *
return err return err
} }
func (s *TimerLayerChannelStore) RemoveMembers(channelId string, userIds []string) *model.AppError { func (s *TimerLayerChannelStore) RemoveMembers(channelId string, userIds []string) error {
start := timemodule.Now() start := timemodule.Now()
err := s.ChannelStore.RemoveMembers(channelId, userIds) err := s.ChannelStore.RemoveMembers(channelId, userIds)
@@ -1730,7 +1730,7 @@ func (s *TimerLayerChannelStore) SaveDirectChannel(channel *model.Channel, membe
return result, err return result, err
} }
func (s *TimerLayerChannelStore) SaveMember(member *model.ChannelMember) (*model.ChannelMember, *model.AppError) { func (s *TimerLayerChannelStore) SaveMember(member *model.ChannelMember) (*model.ChannelMember, error) {
start := timemodule.Now() start := timemodule.Now()
result, err := s.ChannelStore.SaveMember(member) result, err := s.ChannelStore.SaveMember(member)
@@ -1746,7 +1746,7 @@ func (s *TimerLayerChannelStore) SaveMember(member *model.ChannelMember) (*model
return result, err return result, err
} }
func (s *TimerLayerChannelStore) SaveMultipleMembers(members []*model.ChannelMember) ([]*model.ChannelMember, *model.AppError) { func (s *TimerLayerChannelStore) SaveMultipleMembers(members []*model.ChannelMember) ([]*model.ChannelMember, error) {
start := timemodule.Now() start := timemodule.Now()
result, err := s.ChannelStore.SaveMultipleMembers(members) result, err := s.ChannelStore.SaveMultipleMembers(members)
@@ -1890,7 +1890,7 @@ func (s *TimerLayerChannelStore) Update(channel *model.Channel) (*model.Channel,
return result, err return result, err
} }
func (s *TimerLayerChannelStore) UpdateLastViewedAt(channelIds []string, userId string) (map[string]int64, *model.AppError) { func (s *TimerLayerChannelStore) UpdateLastViewedAt(channelIds []string, userId string) (map[string]int64, error) {
start := timemodule.Now() start := timemodule.Now()
result, err := s.ChannelStore.UpdateLastViewedAt(channelIds, userId) result, err := s.ChannelStore.UpdateLastViewedAt(channelIds, userId)
@@ -1906,7 +1906,7 @@ func (s *TimerLayerChannelStore) UpdateLastViewedAt(channelIds []string, userId
return result, err return result, err
} }
func (s *TimerLayerChannelStore) UpdateLastViewedAtPost(unreadPost *model.Post, userID string, mentionCount int) (*model.ChannelUnreadAt, *model.AppError) { func (s *TimerLayerChannelStore) UpdateLastViewedAtPost(unreadPost *model.Post, userID string, mentionCount int) (*model.ChannelUnreadAt, error) {
start := timemodule.Now() start := timemodule.Now()
result, err := s.ChannelStore.UpdateLastViewedAtPost(unreadPost, userID, mentionCount) result, err := s.ChannelStore.UpdateLastViewedAtPost(unreadPost, userID, mentionCount)
@@ -1922,7 +1922,7 @@ func (s *TimerLayerChannelStore) UpdateLastViewedAtPost(unreadPost *model.Post,
return result, err return result, err
} }
func (s *TimerLayerChannelStore) UpdateMember(member *model.ChannelMember) (*model.ChannelMember, *model.AppError) { func (s *TimerLayerChannelStore) UpdateMember(member *model.ChannelMember) (*model.ChannelMember, error) {
start := timemodule.Now() start := timemodule.Now()
result, err := s.ChannelStore.UpdateMember(member) result, err := s.ChannelStore.UpdateMember(member)
@@ -1954,7 +1954,7 @@ func (s *TimerLayerChannelStore) UpdateMembersRole(channelID string, userIDs []s
return err return err
} }
func (s *TimerLayerChannelStore) UpdateMultipleMembers(members []*model.ChannelMember) ([]*model.ChannelMember, *model.AppError) { func (s *TimerLayerChannelStore) UpdateMultipleMembers(members []*model.ChannelMember) ([]*model.ChannelMember, error) {
start := timemodule.Now() start := timemodule.Now()
result, err := s.ChannelStore.UpdateMultipleMembers(members) result, err := s.ChannelStore.UpdateMultipleMembers(members)