Skip to content
Snippets Groups Projects
Commit 8a802c23 authored by Gabriel Engel's avatar Gabriel Engel
Browse files

Merge pull request #1393 from RocketChat/fix_delete_user_subscriptions

Remove direct message subscription for both users when one is deleted
parents 152aabd0 260b3b77
No related branches found
No related tags found
No related merge requests found
......@@ -332,6 +332,6 @@ RocketChat.models.Rooms = new class extends RocketChat.models._Base
removeByTypeContainingUsername: (type, username) ->
query =
t: type
username: username
usernames: username
return @remove query
......@@ -18,13 +18,12 @@ Meteor.methods
room = RocketChat.models.Rooms.findOneById subscription.rid
if room.t isnt 'c' and room.usernames.length is 1
RocketChat.models.Rooms.removeById subscription.rid # Remove non-channel rooms with only 1 user (the one being deleted)
if room.t is 'd'
RocketChat.models.Subscriptions.removeByRoomId subscription.rid
RocketChat.models.Messages.removeByRoomId subscription.rid
RocketChat.models.Subscriptions.removeByUserId userId # Remove user subscriptions
rooms = RocketChat.models.Rooms.findByUserId(userId).fetch()
RocketChat.models.Rooms.removeByTypeContainingUsername 'd', user.username # Remove direct rooms with the user
RocketChat.models.Rooms.removeUsernameFromAll user.username # Remove user from all other rooms
RocketChat.models.Users.removeById userId # Remove user from users database
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment