Skip to content

Commit

Permalink
Closes #1367; Add ability to delete files
Browse files Browse the repository at this point in the history
  • Loading branch information
rodrigok committed Feb 3, 2016
1 parent 63cef43 commit 0656054
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
9 changes: 8 additions & 1 deletion server/methods/deleteMessage.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Meteor.methods
if not Meteor.userId()
throw new Meteor.Error('invalid-user', "[methods] deleteMessage -> Invalid user")

originalMessage = RocketChat.models.Messages.findOneById message._id, {fields: {u: 1, rid: 1}}
originalMessage = RocketChat.models.Messages.findOneById message._id, {fields: {u: 1, rid: 1, file: 1}}
if not originalMessage?
throw new Meteor.Error 'message-deleting-not-allowed', "[methods] deleteMessage -> Message with id [#{message._id} dos not exists]"

Expand All @@ -24,10 +24,17 @@ Meteor.methods
else
RocketChat.models.Messages.setHiddenById originalMessage._id, true

if originalMessage.file?._id?
fileCollection.update originalMessage.file._id, {$set: {_hidden: true}}

else
if not showDeletedStatus
RocketChat.models.Messages.removeById originalMessage._id

if originalMessage.file?._id?
fileCollection.remove originalMessage.file._id
Meteor.fileStore.delete originalMessage.file._id

if showDeletedStatus
RocketChat.models.Messages.setAsDeletedById originalMessage._id
else
Expand Down
2 changes: 2 additions & 0 deletions server/publications/roomFiles.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ Meteor.publish 'roomFiles', (rid, limit = 50) ->
rid: rid
complete: true
uploading: false
_hidden:
$ne: true

fileOptions =
limit: limit
Expand Down

0 comments on commit 0656054

Please sign in to comment.