Migrate to idiomatic error handling the first half to the app/channel.go (#9413)
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
6c826e765f
Коммит
c2496911c0
153
app/channel.go
153
app/channel.go
@@ -38,11 +38,11 @@ func (a *App) JoinDefaultChannels(teamId string, user *model.User, shouldBeAdmin
|
|||||||
|
|
||||||
var requestor *model.User
|
var requestor *model.User
|
||||||
if userRequestorId != "" {
|
if userRequestorId != "" {
|
||||||
if u := <-a.Srv.Store.User().Get(userRequestorId); u.Err != nil {
|
u := <-a.Srv.Store.User().Get(userRequestorId)
|
||||||
|
if u.Err != nil {
|
||||||
return u.Err
|
return u.Err
|
||||||
} else {
|
|
||||||
requestor = u.Data.(*model.User)
|
|
||||||
}
|
}
|
||||||
|
requestor = u.Data.(*model.User)
|
||||||
}
|
}
|
||||||
|
|
||||||
defaultChannelList := []string{"town-square"}
|
defaultChannelList := []string{"town-square"}
|
||||||
@@ -130,13 +130,14 @@ func (a *App) CreateChannelWithUser(channel *model.Channel, userId string) (*mod
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Get total number of channels on current team
|
// Get total number of channels on current team
|
||||||
if count, err := a.GetNumberOfChannelsOnTeam(channel.TeamId); err != nil {
|
count, err := a.GetNumberOfChannelsOnTeam(channel.TeamId)
|
||||||
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
} else {
|
}
|
||||||
|
|
||||||
if int64(count+1) > *a.Config().TeamSettings.MaxChannelsPerTeam {
|
if int64(count+1) > *a.Config().TeamSettings.MaxChannelsPerTeam {
|
||||||
return nil, model.NewAppError("CreateChannelWithUser", "api.channel.create_channel.max_channel_limit.app_error", map[string]interface{}{"MaxChannelsPerTeam": *a.Config().TeamSettings.MaxChannelsPerTeam}, "", http.StatusBadRequest)
|
return nil, model.NewAppError("CreateChannelWithUser", "api.channel.create_channel.max_channel_limit.app_error", map[string]interface{}{"MaxChannelsPerTeam": *a.Config().TeamSettings.MaxChannelsPerTeam}, "", http.StatusBadRequest)
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
channel.CreatorId = userId
|
channel.CreatorId = userId
|
||||||
|
|
||||||
@@ -176,9 +177,11 @@ func (a *App) RenameChannel(channel *model.Channel, newChannelName string, newDi
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (a *App) CreateChannel(channel *model.Channel, addMember bool) (*model.Channel, *model.AppError) {
|
func (a *App) CreateChannel(channel *model.Channel, addMember bool) (*model.Channel, *model.AppError) {
|
||||||
if result := <-a.Srv.Store.Channel().Save(channel, *a.Config().TeamSettings.MaxChannelsPerTeam); result.Err != nil {
|
result := <-a.Srv.Store.Channel().Save(channel, *a.Config().TeamSettings.MaxChannelsPerTeam)
|
||||||
|
if result.Err != nil {
|
||||||
return nil, result.Err
|
return nil, result.Err
|
||||||
} else {
|
}
|
||||||
|
|
||||||
sc := result.Data.(*model.Channel)
|
sc := result.Data.(*model.Channel)
|
||||||
|
|
||||||
if addMember {
|
if addMember {
|
||||||
@@ -211,17 +214,17 @@ func (a *App) CreateChannel(channel *model.Channel, addMember bool) (*model.Chan
|
|||||||
}
|
}
|
||||||
|
|
||||||
return sc, nil
|
return sc, nil
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *App) CreateDirectChannel(userId string, otherUserId string) (*model.Channel, *model.AppError) {
|
func (a *App) CreateDirectChannel(userId string, otherUserId string) (*model.Channel, *model.AppError) {
|
||||||
if channel, err := a.createDirectChannel(userId, otherUserId); err != nil {
|
channel, err := a.createDirectChannel(userId, otherUserId)
|
||||||
|
if err != nil {
|
||||||
if err.Id == store.CHANNEL_EXISTS_ERROR {
|
if err.Id == store.CHANNEL_EXISTS_ERROR {
|
||||||
return channel, nil
|
return channel, nil
|
||||||
} else {
|
}
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
a.WaitForChannelMembership(channel.Id, userId)
|
a.WaitForChannelMembership(channel.Id, userId)
|
||||||
|
|
||||||
a.InvalidateCacheForUser(userId)
|
a.InvalidateCacheForUser(userId)
|
||||||
@@ -242,7 +245,6 @@ func (a *App) CreateDirectChannel(userId string, otherUserId string) (*model.Cha
|
|||||||
a.Publish(message)
|
a.Publish(message)
|
||||||
|
|
||||||
return channel, nil
|
return channel, nil
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *App) createDirectChannel(userId string, otherUserId string) (*model.Channel, *model.AppError) {
|
func (a *App) createDirectChannel(userId string, otherUserId string) (*model.Channel, *model.AppError) {
|
||||||
@@ -257,13 +259,14 @@ func (a *App) createDirectChannel(userId string, otherUserId string) (*model.Cha
|
|||||||
return nil, model.NewAppError("CreateDirectChannel", "api.channel.create_direct_channel.invalid_user.app_error", nil, otherUserId, http.StatusBadRequest)
|
return nil, model.NewAppError("CreateDirectChannel", "api.channel.create_direct_channel.invalid_user.app_error", nil, otherUserId, http.StatusBadRequest)
|
||||||
}
|
}
|
||||||
|
|
||||||
if result := <-a.Srv.Store.Channel().CreateDirectChannel(userId, otherUserId); result.Err != nil {
|
result := <-a.Srv.Store.Channel().CreateDirectChannel(userId, otherUserId)
|
||||||
|
if result.Err != nil {
|
||||||
if result.Err.Id == store.CHANNEL_EXISTS_ERROR {
|
if result.Err.Id == store.CHANNEL_EXISTS_ERROR {
|
||||||
return result.Data.(*model.Channel), result.Err
|
return result.Data.(*model.Channel), result.Err
|
||||||
} else {
|
}
|
||||||
return nil, result.Err
|
return nil, result.Err
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
channel := result.Data.(*model.Channel)
|
channel := result.Data.(*model.Channel)
|
||||||
|
|
||||||
if result := <-a.Srv.Store.ChannelMemberHistory().LogJoinEvent(userId, channel.Id, model.GetMillis()); result.Err != nil {
|
if result := <-a.Srv.Store.ChannelMemberHistory().LogJoinEvent(userId, channel.Id, model.GetMillis()); result.Err != nil {
|
||||||
@@ -274,11 +277,13 @@ func (a *App) createDirectChannel(userId string, otherUserId string) (*model.Cha
|
|||||||
}
|
}
|
||||||
|
|
||||||
return channel, nil
|
return channel, nil
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *App) WaitForChannelMembership(channelId string, userId string) {
|
func (a *App) WaitForChannelMembership(channelId string, userId string) {
|
||||||
if len(a.Config().SqlSettings.DataSourceReplicas) > 0 {
|
if len(a.Config().SqlSettings.DataSourceReplicas) == 0 {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
now := model.GetMillis()
|
now := model.GetMillis()
|
||||||
|
|
||||||
for model.GetMillis()-now < 12000 {
|
for model.GetMillis()-now < 12000 {
|
||||||
@@ -299,17 +304,17 @@ func (a *App) WaitForChannelMembership(channelId string, userId string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
mlog.Error(fmt.Sprintf("WaitForChannelMembership giving up channelId=%v userId=%v", channelId, userId), mlog.String("user_id", userId))
|
mlog.Error(fmt.Sprintf("WaitForChannelMembership giving up channelId=%v userId=%v", channelId, userId), mlog.String("user_id", userId))
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *App) CreateGroupChannel(userIds []string, creatorId string) (*model.Channel, *model.AppError) {
|
func (a *App) CreateGroupChannel(userIds []string, creatorId string) (*model.Channel, *model.AppError) {
|
||||||
if channel, err := a.createGroupChannel(userIds, creatorId); err != nil {
|
channel, err := a.createGroupChannel(userIds, creatorId)
|
||||||
|
if err != nil {
|
||||||
if err.Id == store.CHANNEL_EXISTS_ERROR {
|
if err.Id == store.CHANNEL_EXISTS_ERROR {
|
||||||
return channel, nil
|
return channel, nil
|
||||||
} else {
|
}
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
for _, userId := range userIds {
|
for _, userId := range userIds {
|
||||||
if userId == creatorId {
|
if userId == creatorId {
|
||||||
a.WaitForChannelMembership(channel.Id, creatorId)
|
a.WaitForChannelMembership(channel.Id, creatorId)
|
||||||
@@ -323,7 +328,6 @@ func (a *App) CreateGroupChannel(userIds []string, creatorId string) (*model.Cha
|
|||||||
a.Publish(message)
|
a.Publish(message)
|
||||||
|
|
||||||
return channel, nil
|
return channel, nil
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *App) createGroupChannel(userIds []string, creatorId string) (*model.Channel, *model.AppError) {
|
func (a *App) createGroupChannel(userIds []string, creatorId string) (*model.Channel, *model.AppError) {
|
||||||
@@ -331,12 +335,11 @@ func (a *App) createGroupChannel(userIds []string, creatorId string) (*model.Cha
|
|||||||
return nil, model.NewAppError("CreateGroupChannel", "api.channel.create_group.bad_size.app_error", nil, "", http.StatusBadRequest)
|
return nil, model.NewAppError("CreateGroupChannel", "api.channel.create_group.bad_size.app_error", nil, "", http.StatusBadRequest)
|
||||||
}
|
}
|
||||||
|
|
||||||
var users []*model.User
|
result := <-a.Srv.Store.User().GetProfileByIds(userIds, true)
|
||||||
if result := <-a.Srv.Store.User().GetProfileByIds(userIds, true); result.Err != nil {
|
if result.Err != nil {
|
||||||
return nil, result.Err
|
return nil, result.Err
|
||||||
} else {
|
|
||||||
users = result.Data.([]*model.User)
|
|
||||||
}
|
}
|
||||||
|
users := result.Data.([]*model.User)
|
||||||
|
|
||||||
if len(users) != len(userIds) {
|
if len(users) != len(userIds) {
|
||||||
return nil, model.NewAppError("CreateGroupChannel", "api.channel.create_group.bad_user.app_error", nil, "user_ids="+model.ArrayToJson(userIds), http.StatusBadRequest)
|
return nil, model.NewAppError("CreateGroupChannel", "api.channel.create_group.bad_user.app_error", nil, "user_ids="+model.ArrayToJson(userIds), http.StatusBadRequest)
|
||||||
@@ -348,13 +351,13 @@ func (a *App) createGroupChannel(userIds []string, creatorId string) (*model.Cha
|
|||||||
Type: model.CHANNEL_GROUP,
|
Type: model.CHANNEL_GROUP,
|
||||||
}
|
}
|
||||||
|
|
||||||
if result := <-a.Srv.Store.Channel().Save(group, *a.Config().TeamSettings.MaxChannelsPerTeam); result.Err != nil {
|
result = <-a.Srv.Store.Channel().Save(group, *a.Config().TeamSettings.MaxChannelsPerTeam)
|
||||||
|
if result.Err != nil {
|
||||||
if result.Err.Id == store.CHANNEL_EXISTS_ERROR {
|
if result.Err.Id == store.CHANNEL_EXISTS_ERROR {
|
||||||
return result.Data.(*model.Channel), result.Err
|
return result.Data.(*model.Channel), result.Err
|
||||||
} else {
|
}
|
||||||
return nil, result.Err
|
return nil, result.Err
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
channel := result.Data.(*model.Channel)
|
channel := result.Data.(*model.Channel)
|
||||||
|
|
||||||
for _, user := range users {
|
for _, user := range users {
|
||||||
@@ -374,7 +377,6 @@ func (a *App) createGroupChannel(userIds []string, creatorId string) (*model.Cha
|
|||||||
}
|
}
|
||||||
|
|
||||||
return channel, nil
|
return channel, nil
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *App) GetGroupChannel(userIds []string) (*model.Channel, *model.AppError) {
|
func (a *App) GetGroupChannel(userIds []string) (*model.Channel, *model.AppError) {
|
||||||
@@ -382,12 +384,11 @@ func (a *App) GetGroupChannel(userIds []string) (*model.Channel, *model.AppError
|
|||||||
return nil, model.NewAppError("GetGroupChannel", "api.channel.create_group.bad_size.app_error", nil, "", http.StatusBadRequest)
|
return nil, model.NewAppError("GetGroupChannel", "api.channel.create_group.bad_size.app_error", nil, "", http.StatusBadRequest)
|
||||||
}
|
}
|
||||||
|
|
||||||
var users []*model.User
|
result := <-a.Srv.Store.User().GetProfileByIds(userIds, true)
|
||||||
if result := <-a.Srv.Store.User().GetProfileByIds(userIds, true); result.Err != nil {
|
if result.Err != nil {
|
||||||
return nil, result.Err
|
return nil, result.Err
|
||||||
} else {
|
|
||||||
users = result.Data.([]*model.User)
|
|
||||||
}
|
}
|
||||||
|
users := result.Data.([]*model.User)
|
||||||
|
|
||||||
if len(users) != len(userIds) {
|
if len(users) != len(userIds) {
|
||||||
return nil, model.NewAppError("GetGroupChannel", "api.channel.create_group.bad_user.app_error", nil, "user_ids="+model.ArrayToJson(userIds), http.StatusBadRequest)
|
return nil, model.NewAppError("GetGroupChannel", "api.channel.create_group.bad_user.app_error", nil, "user_ids="+model.ArrayToJson(userIds), http.StatusBadRequest)
|
||||||
@@ -402,9 +403,11 @@ func (a *App) GetGroupChannel(userIds []string) (*model.Channel, *model.AppError
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (a *App) UpdateChannel(channel *model.Channel) (*model.Channel, *model.AppError) {
|
func (a *App) UpdateChannel(channel *model.Channel) (*model.Channel, *model.AppError) {
|
||||||
if result := <-a.Srv.Store.Channel().Update(channel); result.Err != nil {
|
result := <-a.Srv.Store.Channel().Update(channel)
|
||||||
|
if result.Err != nil {
|
||||||
return nil, result.Err
|
return nil, result.Err
|
||||||
} else {
|
}
|
||||||
|
|
||||||
a.InvalidateCacheForChannel(channel)
|
a.InvalidateCacheForChannel(channel)
|
||||||
|
|
||||||
messageWs := model.NewWebSocketEvent(model.WEBSOCKET_EVENT_CHANNEL_UPDATED, "", channel.Id, "", nil)
|
messageWs := model.NewWebSocketEvent(model.WEBSOCKET_EVENT_CHANNEL_UPDATED, "", channel.Id, "", nil)
|
||||||
@@ -412,7 +415,6 @@ func (a *App) UpdateChannel(channel *model.Channel) (*model.Channel, *model.AppE
|
|||||||
a.Publish(messageWs)
|
a.Publish(messageWs)
|
||||||
|
|
||||||
return channel, nil
|
return channel, nil
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *App) UpdateChannelScheme(channel *model.Channel) (*model.Channel, *model.AppError) {
|
func (a *App) UpdateChannelScheme(channel *model.Channel) (*model.Channel, *model.AppError) {
|
||||||
@@ -433,9 +435,11 @@ func (a *App) UpdateChannelScheme(channel *model.Channel) (*model.Channel, *mode
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (a *App) UpdateChannelPrivacy(oldChannel *model.Channel, user *model.User) (*model.Channel, *model.AppError) {
|
func (a *App) UpdateChannelPrivacy(oldChannel *model.Channel, user *model.User) (*model.Channel, *model.AppError) {
|
||||||
if channel, err := a.UpdateChannel(oldChannel); err != nil {
|
channel, err := a.UpdateChannel(oldChannel)
|
||||||
|
if err != nil {
|
||||||
return channel, err
|
return channel, err
|
||||||
} else {
|
}
|
||||||
|
|
||||||
if err := a.postChannelPrivacyMessage(user, channel); err != nil {
|
if err := a.postChannelPrivacyMessage(user, channel); err != nil {
|
||||||
if channel.Type == model.CHANNEL_OPEN {
|
if channel.Type == model.CHANNEL_OPEN {
|
||||||
channel.Type = model.CHANNEL_PRIVATE
|
channel.Type = model.CHANNEL_PRIVATE
|
||||||
@@ -454,7 +458,6 @@ func (a *App) UpdateChannelPrivacy(oldChannel *model.Channel, user *model.User)
|
|||||||
a.Publish(messageWs)
|
a.Publish(messageWs)
|
||||||
|
|
||||||
return channel, nil
|
return channel, nil
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *App) postChannelPrivacyMessage(user *model.User, channel *model.Channel) *model.AppError {
|
func (a *App) postChannelPrivacyMessage(user *model.User, channel *model.Channel) *model.AppError {
|
||||||
@@ -480,11 +483,11 @@ func (a *App) postChannelPrivacyMessage(user *model.User, channel *model.Channel
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (a *App) RestoreChannel(channel *model.Channel) (*model.Channel, *model.AppError) {
|
func (a *App) RestoreChannel(channel *model.Channel) (*model.Channel, *model.AppError) {
|
||||||
if result := <-a.Srv.Store.Channel().Restore(channel.Id, model.GetMillis()); result.Err != nil {
|
result := <-a.Srv.Store.Channel().Restore(channel.Id, model.GetMillis())
|
||||||
|
if result.Err != nil {
|
||||||
return nil, result.Err
|
return nil, result.Err
|
||||||
} else {
|
|
||||||
return channel, nil
|
|
||||||
}
|
}
|
||||||
|
return channel, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *App) PatchChannel(channel *model.Channel, patch *model.ChannelPatch, userId string) (*model.Channel, *model.AppError) {
|
func (a *App) PatchChannel(channel *model.Channel, patch *model.ChannelPatch, userId string) (*model.Channel, *model.AppError) {
|
||||||
@@ -528,11 +531,11 @@ func (a *App) GetSchemeRolesForChannel(channelId string) (string, string, *model
|
|||||||
}
|
}
|
||||||
|
|
||||||
if channel.SchemeId != nil && len(*channel.SchemeId) != 0 {
|
if channel.SchemeId != nil && len(*channel.SchemeId) != 0 {
|
||||||
if scheme, err := a.GetScheme(*channel.SchemeId); err != nil {
|
scheme, err := a.GetScheme(*channel.SchemeId)
|
||||||
|
if err != nil {
|
||||||
return "", "", err
|
return "", "", err
|
||||||
} else {
|
|
||||||
return scheme.DefaultChannelUserRole, scheme.DefaultChannelAdminRole, nil
|
|
||||||
}
|
}
|
||||||
|
return scheme.DefaultChannelUserRole, scheme.DefaultChannelAdminRole, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
var team *model.Team
|
var team *model.Team
|
||||||
@@ -542,11 +545,11 @@ func (a *App) GetSchemeRolesForChannel(channelId string) (string, string, *model
|
|||||||
}
|
}
|
||||||
|
|
||||||
if team.SchemeId != nil && len(*team.SchemeId) != 0 {
|
if team.SchemeId != nil && len(*team.SchemeId) != 0 {
|
||||||
if scheme, err := a.GetScheme(*team.SchemeId); err != nil {
|
scheme, err := a.GetScheme(*team.SchemeId)
|
||||||
|
if err != nil {
|
||||||
return "", "", err
|
return "", "", err
|
||||||
} else {
|
|
||||||
return scheme.DefaultChannelUserRole, scheme.DefaultChannelAdminRole, nil
|
|
||||||
}
|
}
|
||||||
|
return scheme.DefaultChannelUserRole, scheme.DefaultChannelAdminRole, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
return model.CHANNEL_USER_ROLE_ID, model.CHANNEL_ADMIN_ROLE_ID, nil
|
return model.CHANNEL_USER_ROLE_ID, model.CHANNEL_ADMIN_ROLE_ID, nil
|
||||||
@@ -569,10 +572,13 @@ func (a *App) UpdateChannelMemberRoles(channelId string, userId string, newRoles
|
|||||||
member.SchemeAdmin = false
|
member.SchemeAdmin = false
|
||||||
|
|
||||||
for _, roleName := range strings.Fields(newRoles) {
|
for _, roleName := range strings.Fields(newRoles) {
|
||||||
if role, err := a.GetRoleByName(roleName); err != nil {
|
role, err := a.GetRoleByName(roleName)
|
||||||
|
if err != nil {
|
||||||
err.StatusCode = http.StatusBadRequest
|
err.StatusCode = http.StatusBadRequest
|
||||||
return nil, err
|
return nil, err
|
||||||
} else if !role.SchemeManaged {
|
}
|
||||||
|
|
||||||
|
if !role.SchemeManaged {
|
||||||
// The role is not scheme-managed, so it's OK to apply it to the explicit roles field.
|
// The role is not scheme-managed, so it's OK to apply it to the explicit roles field.
|
||||||
newExplicitRoles = append(newExplicitRoles, roleName)
|
newExplicitRoles = append(newExplicitRoles, roleName)
|
||||||
} else {
|
} else {
|
||||||
@@ -591,11 +597,11 @@ func (a *App) UpdateChannelMemberRoles(channelId string, userId string, newRoles
|
|||||||
|
|
||||||
member.ExplicitRoles = strings.Join(newExplicitRoles, " ")
|
member.ExplicitRoles = strings.Join(newExplicitRoles, " ")
|
||||||
|
|
||||||
if result := <-a.Srv.Store.Channel().UpdateMember(member); result.Err != nil {
|
result := <-a.Srv.Store.Channel().UpdateMember(member)
|
||||||
|
if result.Err != nil {
|
||||||
return nil, result.Err
|
return nil, result.Err
|
||||||
} else {
|
|
||||||
member = result.Data.(*model.ChannelMember)
|
|
||||||
}
|
}
|
||||||
|
member = result.Data.(*model.ChannelMember)
|
||||||
|
|
||||||
a.InvalidateCacheForUser(userId)
|
a.InvalidateCacheForUser(userId)
|
||||||
return member, nil
|
return member, nil
|
||||||
@@ -615,11 +621,11 @@ func (a *App) UpdateChannelMemberSchemeRoles(channelId string, userId string, is
|
|||||||
member.ExplicitRoles = RemoveRoles([]string{model.CHANNEL_USER_ROLE_ID, model.CHANNEL_ADMIN_ROLE_ID}, member.ExplicitRoles)
|
member.ExplicitRoles = RemoveRoles([]string{model.CHANNEL_USER_ROLE_ID, model.CHANNEL_ADMIN_ROLE_ID}, member.ExplicitRoles)
|
||||||
}
|
}
|
||||||
|
|
||||||
if result := <-a.Srv.Store.Channel().UpdateMember(member); result.Err != nil {
|
result := <-a.Srv.Store.Channel().UpdateMember(member)
|
||||||
|
if result.Err != nil {
|
||||||
return nil, result.Err
|
return nil, result.Err
|
||||||
} else {
|
|
||||||
member = result.Data.(*model.ChannelMember)
|
|
||||||
}
|
}
|
||||||
|
member = result.Data.(*model.ChannelMember)
|
||||||
|
|
||||||
a.InvalidateCacheForUser(userId)
|
a.InvalidateCacheForUser(userId)
|
||||||
return member, nil
|
return member, nil
|
||||||
@@ -649,9 +655,11 @@ func (a *App) UpdateChannelMemberNotifyProps(data map[string]string, channelId s
|
|||||||
member.NotifyProps[model.PUSH_NOTIFY_PROP] = push
|
member.NotifyProps[model.PUSH_NOTIFY_PROP] = push
|
||||||
}
|
}
|
||||||
|
|
||||||
if result := <-a.Srv.Store.Channel().UpdateMember(member); result.Err != nil {
|
result := <-a.Srv.Store.Channel().UpdateMember(member)
|
||||||
|
if result.Err != nil {
|
||||||
return nil, result.Err
|
return nil, result.Err
|
||||||
} else {
|
}
|
||||||
|
|
||||||
a.InvalidateCacheForUser(userId)
|
a.InvalidateCacheForUser(userId)
|
||||||
a.InvalidateCacheForChannelMembersNotifyProps(channelId)
|
a.InvalidateCacheForChannelMembersNotifyProps(channelId)
|
||||||
// Notify the clients that the member notify props changed
|
// Notify the clients that the member notify props changed
|
||||||
@@ -659,7 +667,6 @@ func (a *App) UpdateChannelMemberNotifyProps(data map[string]string, channelId s
|
|||||||
evt.Add("channelMember", member.ToJson())
|
evt.Add("channelMember", member.ToJson())
|
||||||
a.Publish(evt)
|
a.Publish(evt)
|
||||||
return member, nil
|
return member, nil
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *App) DeleteChannel(channel *model.Channel, userId string) *model.AppError {
|
func (a *App) DeleteChannel(channel *model.Channel, userId string) *model.AppError {
|
||||||
@@ -676,11 +683,16 @@ func (a *App) DeleteChannel(channel *model.Channel, userId string) *model.AppErr
|
|||||||
user = uresult.Data.(*model.User)
|
user = uresult.Data.(*model.User)
|
||||||
}
|
}
|
||||||
|
|
||||||
if ihcresult := <-ihc; ihcresult.Err != nil {
|
ihcresult := <-ihc
|
||||||
|
if ihcresult.Err != nil {
|
||||||
return ihcresult.Err
|
return ihcresult.Err
|
||||||
} else if ohcresult := <-ohc; ohcresult.Err != nil {
|
}
|
||||||
|
|
||||||
|
ohcresult := <-ohc
|
||||||
|
if ohcresult.Err != nil {
|
||||||
return ohcresult.Err
|
return ohcresult.Err
|
||||||
} else {
|
}
|
||||||
|
|
||||||
incomingHooks := ihcresult.Data.([]*model.IncomingWebhook)
|
incomingHooks := ihcresult.Data.([]*model.IncomingWebhook)
|
||||||
outgoingHooks := ohcresult.Data.([]*model.OutgoingWebhook)
|
outgoingHooks := ohcresult.Data.([]*model.OutgoingWebhook)
|
||||||
|
|
||||||
@@ -737,7 +749,6 @@ func (a *App) DeleteChannel(channel *model.Channel, userId string) *model.AppErr
|
|||||||
message.Add("channel_id", channel.Id)
|
message.Add("channel_id", channel.Id)
|
||||||
message.Add("delete_at", deleteAt)
|
message.Add("delete_at", deleteAt)
|
||||||
a.Publish(message)
|
a.Publish(message)
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@@ -784,14 +795,14 @@ func (a *App) AddUserToChannel(user *model.User, channel *model.Channel) (*model
|
|||||||
tmchan := a.Srv.Store.Team().GetMember(channel.TeamId, user.Id)
|
tmchan := a.Srv.Store.Team().GetMember(channel.TeamId, user.Id)
|
||||||
var teamMember *model.TeamMember
|
var teamMember *model.TeamMember
|
||||||
|
|
||||||
if result := <-tmchan; result.Err != nil {
|
result := <-tmchan
|
||||||
|
if result.Err != nil {
|
||||||
return nil, result.Err
|
return nil, result.Err
|
||||||
} else {
|
}
|
||||||
teamMember = result.Data.(*model.TeamMember)
|
teamMember = result.Data.(*model.TeamMember)
|
||||||
if teamMember.DeleteAt > 0 {
|
if teamMember.DeleteAt > 0 {
|
||||||
return nil, model.NewAppError("AddUserToChannel", "api.channel.add_user.to.channel.failed.deleted.app_error", nil, "", http.StatusBadRequest)
|
return nil, model.NewAppError("AddUserToChannel", "api.channel.add_user.to.channel.failed.deleted.app_error", nil, "", http.StatusBadRequest)
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
newMember, err := a.addUserToChannel(user, channel, teamMember)
|
newMember, err := a.addUserToChannel(user, channel, teamMember)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -861,11 +872,11 @@ func (a *App) AddChannelMember(userId string, channel *model.Channel, userReques
|
|||||||
|
|
||||||
func (a *App) AddDirectChannels(teamId string, user *model.User) *model.AppError {
|
func (a *App) AddDirectChannels(teamId string, user *model.User) *model.AppError {
|
||||||
var profiles []*model.User
|
var profiles []*model.User
|
||||||
if result := <-a.Srv.Store.User().GetProfiles(teamId, 0, 100); result.Err != nil {
|
result := <-a.Srv.Store.User().GetProfiles(teamId, 0, 100)
|
||||||
|
if result.Err != nil {
|
||||||
return model.NewAppError("AddDirectChannels", "api.user.add_direct_channels_and_forget.failed.error", map[string]interface{}{"UserId": user.Id, "TeamId": teamId, "Error": result.Err.Error()}, "", http.StatusInternalServerError)
|
return model.NewAppError("AddDirectChannels", "api.user.add_direct_channels_and_forget.failed.error", map[string]interface{}{"UserId": user.Id, "TeamId": teamId, "Error": result.Err.Error()}, "", http.StatusInternalServerError)
|
||||||
} else {
|
|
||||||
profiles = result.Data.([]*model.User)
|
|
||||||
}
|
}
|
||||||
|
profiles = result.Data.([]*model.User)
|
||||||
|
|
||||||
var preferences model.Preferences
|
var preferences model.Preferences
|
||||||
|
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user