From 06560541ec3959fb0e5abd811cc23b44e7d981aa Mon Sep 17 00:00:00 2001 From: Rodrigo Nascimento Date: Wed, 3 Feb 2016 13:45:43 -0200 Subject: [PATCH] Closes #1367; Add ability to delete files --- server/methods/deleteMessage.coffee | 9 ++++++++- server/publications/roomFiles.coffee | 2 ++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/server/methods/deleteMessage.coffee b/server/methods/deleteMessage.coffee index 5e96a7cc4abe..5b28f11bcc62 100644 --- a/server/methods/deleteMessage.coffee +++ b/server/methods/deleteMessage.coffee @@ -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]" @@ -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 diff --git a/server/publications/roomFiles.coffee b/server/publications/roomFiles.coffee index e905e740d22f..f83702f4a448 100644 --- a/server/publications/roomFiles.coffee +++ b/server/publications/roomFiles.coffee @@ -8,6 +8,8 @@ Meteor.publish 'roomFiles', (rid, limit = 50) -> rid: rid complete: true uploading: false + _hidden: + $ne: true fileOptions = limit: limit