Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[NEW] Delete all Attachments / Files from a Channel /Chat #7383

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions packages/rocketchat-i18n/i18n/en.i18n.json
Original file line number Diff line number Diff line change
Expand Up @@ -1687,6 +1687,7 @@
"Yes_unarchive_it": "Yes, unarchive it!",
"Yes_clear_all": "Yes, clear all!",
"Yes_delete_it": "Yes, delete it!",
"Yes_delete_them_all": "Yes, delete them all!",
"Yes_hide_it": "Yes, hide it!",
"Yes_leave_it": "Yes, leave it!",
"Yes_mute_user": "Yes, mute user!",
Expand Down Expand Up @@ -1716,10 +1717,12 @@
"You_should_name_it_to_easily_manage_your_integrations": "You should name it to easily manage your integrations.",
"You_will_not_be_able_to_recover": "You will not be able to recover this message!",
"You_will_not_be_able_to_recover_file": "You will not be able to recover this file!",
"You_will_not_be_able_to_recover_these_files": "You will not be able to recover these files.",
"You_wont_receive_email_notifications_because_you_have_not_verified_your_email": "You won't receive email notifications because you have not verified your email.",
"Your_email_has_been_queued_for_sending": "Your email has been queued for sending",
"Your_entry_has_been_deleted": "Your entry has been deleted.",
"Your_file_has_been_deleted": "Your file has been deleted.",
"Your_files_are_being_deleted": "Your files are being deleted.",
"Your_mail_was_sent_to_s": "Your mail was sent to %s",
"your_message": "your message",
"your_message_optional": "your message (optional)",
Expand Down
3 changes: 2 additions & 1 deletion packages/rocketchat-theme/client/imports/base.css
Original file line number Diff line number Diff line change
Expand Up @@ -3264,7 +3264,8 @@ body:not(.is-cordova) {
font-weight: 600;
}

& .see-all {
& .see-all,
& .delete-all {
float: right;
border-width: 0;
text-decoration: underline;
Expand Down
68 changes: 41 additions & 27 deletions packages/rocketchat-ui-flextab/client/tabs/uploadedFilesList.html
Original file line number Diff line number Diff line change
@@ -1,35 +1,49 @@
<template name="uploadedFilesList">
<div class="content">
<div class="list-view uploaded-files-list">
<div class="title">
<h2>{{_ "Room_uploaded_file_list"}}</h2>
</div>
<ul class="list clearfix lines">
{{#each files}}
<li>
{{#if canDelete}}
<i class="icon-trash file-delete"></i>
{{#with uploadedFiles}}
<div class="title">
<h2>{{_ "Room_uploaded_file_list"}}</h2>
{{#if Template.subscriptionsReady}}
{{#unless files}}
{{else}}
<p>
Showing: {{totalFiles}} files
{{#if showDeleteAll}}
<button class="delete-all icon-trash">Delete All</button>
{{/if}}
<a title="{{escapedName}}" href="{{fixCordova url}}" target="_blank" class="file-download" download="">
<i class="icon-download file-download"></i>
</a>
<a title="{{escapedName}}" href="{{fixCordova url}}" target="_blank" class="room-file-item file-name {{customClassForFileType}}">
<i class="{{getFileIcon type}}"></i>
<p>{{name}}</p>
</a>
</li>
{{/each}}
</ul>
{{#if hasMore}}
<div class="load-more">
{{> loading}}
</p>

{{/unless}}
{{/if}}
</div>
{{/if}}
{{#if Template.subscriptionsReady}}
{{#unless hasFiles}}
<h2>{{_ "Room_uploaded_file_list_empty"}}</h2>
{{/unless}}
{{/if}}
<ul class="list clearfix lines">
{{#each files}}
<li>
{{#if canDelete}}
<i class="icon-trash file-delete"></i>
{{/if}}
<a title="{{escapedName}}" href="{{fixCordova url}}" target="_blank" class="file-download" download="">
<i class="icon-download file-download"></i>
</a>
<a title="{{escapedName}}" href="{{fixCordova url}}" target="_blank" class="room-file-item file-name {{customClassForFileType}}">
<i class="{{getFileIcon type}}"></i>
<p>{{name}}</p>
</a>
</li>
{{/each}}
</ul>
{{#if hasMore}}
<div class="load-more">
{{> loading}}
</div>
{{/if}}
{{#if Template.subscriptionsReady}}
{{#unless files}}
<h2>{{_ "Room_uploaded_file_list_empty"}}</h2>
{{/unless}}
{{/if}}
{{/with}}
</div>
</div>
</template>
61 changes: 44 additions & 17 deletions packages/rocketchat-ui-flextab/client/tabs/uploadedFilesList.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,31 @@
/* globals chatMessages*/
const roomFiles = new Mongo.Collection('room_files');

const removeFiles = (upload, msg) => {
RocketChat.models.Uploads.remove(upload._id, function() {
if (msg) {
return chatMessages[Session.get('openedRoom')].deleteMsg(msg);
} else {
return Meteor.call('deleteFileMessage', upload._id, function(error) {
if (error) {
return handleError(error);
}
});
}
});
};

Template.uploadedFilesList.helpers({
files() {
return roomFiles.find({ rid: this.rid }, { sort: { uploadedAt: -1 } });

uploadedFiles() {
const files = roomFiles.find({ rid: this.rid }, { sort: { uploadedAt: -1 } });
const totalFiles = files.count();
const showDeleteAll = totalFiles > 1 ;
return {
totalFiles,
showDeleteAll,
files
};
},

hasFiles() {
Expand Down Expand Up @@ -74,38 +96,43 @@ Template.uploadedFilesList.events({

'click .icon-trash'() {
const self = this;
const deleteText = self._id ?
TAPi18n.__('You_will_not_be_able_to_recover_file') :
TAPi18n.__('You_will_not_be_able_to_recover_these_files');
const deleteConfirm = self._id ?
TAPi18n.__('Yes_delete_it') :
TAPi18n.__('Yes_delete_them_all');
const successText = self._id ?
TAPi18n.__('Your_file_has_been_deleted') :
TAPi18n.__('Your_files_are_being_deleted');
return swal({
title: TAPi18n.__('Are_you_sure'),
text: TAPi18n.__('You_will_not_be_able_to_recover_file'),
text: deleteText,
type: 'warning',
showCancelButton: true,
confirmButtonColor: '#DD6B55',
confirmButtonText: TAPi18n.__('Yes_delete_it'),
confirmButtonText: deleteConfirm,
cancelButtonText: TAPi18n.__('Cancel'),
closeOnConfirm: false,
html: false
}, function() {
swal({
title: TAPi18n.__('Deleted'),
text: TAPi18n.__('Your_file_has_been_deleted'),
text: successText,
type: 'success',
timer: 1000,
showConfirmButton: false
});

// Check if the upload message for this file is currently loaded
const msg = ChatMessage.findOne({ file: { _id: self._id } });
return RocketChat.models.Uploads.remove(self._id, function() {
if (msg) {
return chatMessages[Session.get('openedRoom')].deleteMsg(msg);
} else {
return Meteor.call('deleteFileMessage', self._id, function(error) {
if (error) {
return handleError(error);
}
});
}
});
if (!self._id) {

self.files.map((file) => {
return removeFiles(file, msg);
});
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.map is synchronous. So you could actually put that swal for success on multiple here.

As far as that goes... the swal for success really shouldn't be being shown until its actually finished. So might just move the swal below this whole block. And remove the text for TAPi18n.__('Your_files_are_being_deleted');

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The map function run very fast b/c the RocketChat.models.Uploads.remove is asynchronous. I tried to use the Meteor.wrapAsync without succes. move the swal to de end of the block doesn't delay the success message

} else {
return removeFiles(self, msg);
}
});
},

Expand Down