Skip to content

Commit

Permalink
Merge pull request #750 from RocketChat/archive-channels-groups
Browse files Browse the repository at this point in the history
Adding archive / unarchive methods.
  • Loading branch information
engelgabriel committed Sep 10, 2015
2 parents 3d4a64e + 3a47283 commit 8fdb3db
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 0 deletions.
29 changes: 29 additions & 0 deletions server/methods/archiveRoom.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
Meteor.methods
archiveRoom: (rid) ->
if not Meteor.userId()
throw new Meteor.Error 'invalid-user', '[methods] archiveRoom -> Invalid user'

console.log '[methods] archiveRoom -> '.green, 'userId:', Meteor.userId(), 'arguments:', arguments

room = ChatRoom.findOne rid

if room.u? and room.u._id is Meteor.userId() or Meteor.user().admin?
update =
$set:
archived: true

ChatRoom.update rid, update

for username in room.usernames
member = Meteor.users.findOne({ username: username },{ fields: { username: 1 }})
if not member?
continue

ChatSubscription.update
rid: rid
'u._id': member._id
,
$set:
alert: false
open: false
archived: true
29 changes: 29 additions & 0 deletions server/methods/unarchiveRoom.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
Meteor.methods
unArchiveRoom: (rid) ->
if not Meteor.userId()
throw new Meteor.Error 'invalid-user', '[methods] unArchiveRoom -> Invalid user'

console.log '[methods] unArchiveRoom -> '.green, 'userId:', Meteor.userId(), 'arguments:', arguments

room = ChatRoom.findOne rid

if room.u? and room.u._id is Meteor.userId() or Meteor.user().admin?
update =
$set:
archived: false

ChatRoom.update rid, update

for username in room.usernames
member = Meteor.users.findOne({ username: username },{ fields: { username: 1 }})
if not member?
continue

ChatSubscription.update
rid: rid
'u._id': member._id
,
$set:
alert: false
open: false
archived: false

0 comments on commit 8fdb3db

Please sign in to comment.