diff --git a/app/channel.go b/app/channel.go index 8db29b4796..fb0f22137f 100644 --- a/app/channel.go +++ b/app/channel.go @@ -1916,8 +1916,8 @@ func (a *App) PermanentDeleteChannel(channel *model.Channel) *model.AppError { return err } - if result := <-a.Srv.Store.Channel().PermanentDeleteMembersByChannel(channel.Id); result.Err != nil { - return result.Err + if err := a.Srv.Store.Channel().PermanentDeleteMembersByChannel(channel.Id); err != nil { + return err } if err := a.Srv.Store.Webhook().PermanentDeleteIncomingByChannel(channel.Id); err != nil { diff --git a/cmd/mattermost/commands/channel.go b/cmd/mattermost/commands/channel.go index 781a737e06..530c8454ed 100644 --- a/cmd/mattermost/commands/channel.go +++ b/cmd/mattermost/commands/channel.go @@ -265,8 +265,8 @@ func removeUserFromChannel(a *app.App, channel *model.Channel, user *model.User, } func removeAllUsersFromChannel(a *app.App, channel *model.Channel) { - if result := <-a.Srv.Store.Channel().PermanentDeleteMembersByChannel(channel.Id); result.Err != nil { - CommandPrintErrorln("Unable to remove all users from " + channel.Name + ". Error: " + result.Err.Error()) + if err := a.Srv.Store.Channel().PermanentDeleteMembersByChannel(channel.Id); err != nil { + CommandPrintErrorln("Unable to remove all users from " + channel.Name + ". Error: " + err.Error()) } } diff --git a/store/sqlstore/channel_store.go b/store/sqlstore/channel_store.go index 35cc3ad018..6db25e2333 100644 --- a/store/sqlstore/channel_store.go +++ b/store/sqlstore/channel_store.go @@ -920,13 +920,13 @@ func (s SqlChannelStore) permanentDeleteT(transaction *gorp.Transaction, channel return result } -func (s SqlChannelStore) PermanentDeleteMembersByChannel(channelId string) store.StoreChannel { - return store.Do(func(result *store.StoreResult) { - _, err := s.GetMaster().Exec("DELETE FROM ChannelMembers WHERE ChannelId = :ChannelId", map[string]interface{}{"ChannelId": channelId}) - if err != nil { - result.Err = model.NewAppError("SqlChannelStore.RemoveAllMembersByChannel", "store.sql_channel.remove_member.app_error", nil, "channel_id="+channelId+", "+err.Error(), http.StatusInternalServerError) - } - }) +func (s SqlChannelStore) PermanentDeleteMembersByChannel(channelId string) *model.AppError { + _, err := s.GetMaster().Exec("DELETE FROM ChannelMembers WHERE ChannelId = :ChannelId", map[string]interface{}{"ChannelId": channelId}) + if err != nil { + return model.NewAppError("SqlChannelStore.RemoveAllMembersByChannel", "store.sql_channel.remove_member.app_error", nil, "channel_id="+channelId+", "+err.Error(), http.StatusInternalServerError) + } + + return nil } func (s SqlChannelStore) GetChannels(teamId string, userId string, includeDeleted bool) store.StoreChannel { diff --git a/store/store.go b/store/store.go index 08ea7da56b..407de32506 100644 --- a/store/store.go +++ b/store/store.go @@ -174,7 +174,7 @@ type ChannelStore interface { GetPinnedPosts(channelId string) StoreChannel RemoveMember(channelId string, userId string) StoreChannel PermanentDeleteMembersByUser(userId string) StoreChannel - PermanentDeleteMembersByChannel(channelId string) StoreChannel + PermanentDeleteMembersByChannel(channelId string) *model.AppError UpdateLastViewedAt(channelIds []string, userId string) StoreChannel IncrementMentionCount(channelId string, userId string) StoreChannel AnalyticsTypeCount(teamId string, channelType string) (int64, *model.AppError) diff --git a/store/storetest/channel_store.go b/store/storetest/channel_store.go index eb4962764b..cb34397438 100644 --- a/store/storetest/channel_store.go +++ b/store/storetest/channel_store.go @@ -223,7 +223,7 @@ func testChannelStoreCreateDirectChannel(t *testing.T, ss store.Store) { t.Fatal("couldn't create direct channel", err) } defer func() { - <-ss.Channel().PermanentDeleteMembersByChannel(c1.Id) + ss.Channel().PermanentDeleteMembersByChannel(c1.Id) <-ss.Channel().PermanentDelete(c1.Id) }() @@ -984,8 +984,8 @@ func testChannelDeleteMemberStore(t *testing.T, ss store.Store) { t.Fatal("should have removed 1 member") } - if r1 := <-ss.Channel().PermanentDeleteMembersByChannel(o1.ChannelId); r1.Err != nil { - t.Fatal(r1.Err) + if err := ss.Channel().PermanentDeleteMembersByChannel(o1.ChannelId); err != nil { + t.Fatal(err) } count = (<-ss.Channel().GetMemberCount(o1.ChannelId, false)).Data.(int64) @@ -2750,7 +2750,7 @@ func testChannelStoreAnalyticsDeletedTypeCount(t *testing.T, ss store.Store) { t.Fatalf(err.Error()) } defer func() { - <-ss.Channel().PermanentDeleteMembersByChannel(d4.Id) + ss.Channel().PermanentDeleteMembersByChannel(d4.Id) <-ss.Channel().PermanentDelete(d4.Id) }() diff --git a/store/storetest/mocks/ChannelStore.go b/store/storetest/mocks/ChannelStore.go index 60a087fe1c..7ec5d52238 100644 --- a/store/storetest/mocks/ChannelStore.go +++ b/store/storetest/mocks/ChannelStore.go @@ -930,15 +930,15 @@ func (_m *ChannelStore) PermanentDeleteByTeam(teamId string) store.StoreChannel } // PermanentDeleteMembersByChannel provides a mock function with given fields: channelId -func (_m *ChannelStore) PermanentDeleteMembersByChannel(channelId string) store.StoreChannel { +func (_m *ChannelStore) PermanentDeleteMembersByChannel(channelId string) *model.AppError { ret := _m.Called(channelId) - var r0 store.StoreChannel - if rf, ok := ret.Get(0).(func(string) store.StoreChannel); ok { + var r0 *model.AppError + if rf, ok := ret.Get(0).(func(string) *model.AppError); ok { r0 = rf(channelId) } else { if ret.Get(0) != nil { - r0 = ret.Get(0).(store.StoreChannel) + r0 = ret.Get(0).(*model.AppError) } }