summaryrefslogtreecommitdiffstats
path: root/store/sqlstore/channel_store.go
diff options
context:
space:
mode:
authorGeorge Goldberg <george@gberg.me>2018-10-08 16:39:03 +0100
committerGitHub <noreply@github.com>2018-10-08 16:39:03 +0100
commit9a4f3ce1e5b22a297eeb00b2aaff44f88304ae8c (patch)
tree8841d645463b21a175036399e78ecae647922e55 /store/sqlstore/channel_store.go
parent7b338c161bce8bdede54d85a5df5a0efe34eb874 (diff)
downloadchat-9a4f3ce1e5b22a297eeb00b2aaff44f88304ae8c.tar.gz
chat-9a4f3ce1e5b22a297eeb00b2aaff44f88304ae8c.tar.bz2
chat-9a4f3ce1e5b22a297eeb00b2aaff44f88304ae8c.zip
MM-12251: Add flag to MoveChannel to remove all deactivated users. (#9515)
Diffstat (limited to 'store/sqlstore/channel_store.go')
-rw-r--r--store/sqlstore/channel_store.go26
1 files changed, 26 insertions, 0 deletions
diff --git a/store/sqlstore/channel_store.go b/store/sqlstore/channel_store.go
index 7a9e4e687..b1886c428 100644
--- a/store/sqlstore/channel_store.go
+++ b/store/sqlstore/channel_store.go
@@ -1478,6 +1478,32 @@ func (s SqlChannelStore) RemoveMember(channelId string, userId string) store.Sto
})
}
+func (s SqlChannelStore) RemoveAllDeactivatedMembers(channelId string) store.StoreChannel {
+ return store.Do(func(result *store.StoreResult) {
+ query := `
+ DELETE
+ FROM
+ ChannelMembers
+ WHERE
+ UserId IN (
+ SELECT
+ Id
+ FROM
+ Users
+ WHERE
+ Users.DeleteAt != 0
+ )
+ AND
+ ChannelMembers.ChannelId = :ChannelId
+ `
+
+ _, err := s.GetMaster().Exec(query, map[string]interface{}{"ChannelId": channelId})
+ if err != nil {
+ result.Err = model.NewAppError("SqlChannelStore.RemoveAllDeactivatedMembers", "store.sql_channel.remove_all_deactivated_members.app_error", nil, "channel_id="+channelId+", "+err.Error(), http.StatusInternalServerError)
+ }
+ })
+}
+
func (s SqlChannelStore) PermanentDeleteMembersByUser(userId string) store.StoreChannel {
return store.Do(func(result *store.StoreResult) {
if _, err := s.GetMaster().Exec("DELETE FROM ChannelMembers WHERE UserId = :UserId", map[string]interface{}{"UserId": userId}); err != nil {