Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
7 changes: 6 additions & 1 deletion app/livechat/client/stylesheets/livechat.less
Original file line number Diff line number Diff line change
Expand Up @@ -549,6 +549,11 @@
margin-top: 26px;
padding-left: 30px;
border-left: 1px solid #cccccc;

& > .rc-button__group {
margin: 0 5px;
}

}

.livechat-current-chats-tag-filter-wrapper {
Expand All @@ -558,4 +563,4 @@
margin-top: auto;
margin-bottom: auto;
}
}
}
8 changes: 6 additions & 2 deletions app/livechat/client/views/app/livechatCurrentChats.html
Original file line number Diff line number Diff line change
Expand Up @@ -106,12 +106,16 @@
</div>

<div class="livechat-current-chats-filters-buttons">
<div class="form-group">
<div class="rc-button__group">
<button class="rc-button rc-button--primary">{{_ "Filter"}}</button>
{{#if hasPopoverPermissions}}
<button class="livechat-current-chats-extra-actions">
{{> icon icon="menu" block="rc-icon--default-size"}}
</button>
{{/if}}
</div>
</div>
</div>

</form>
</fieldset>
<div class="rc-table-content">
Expand Down
72 changes: 70 additions & 2 deletions app/livechat/client/views/app/livechatCurrentChats.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,13 @@ import { FlowRouter } from 'meteor/kadira:flow-router';
import { Template } from 'meteor/templating';
import { Meteor } from 'meteor/meteor';
import { Random } from 'meteor/random';
import toastr from 'toastr';
import { TAPi18n } from 'meteor/rocketchat:tap-i18n';

import { modal, call, popover } from '../../../../ui-utils';
import { t, APIClient } from '../../../../utils/client';
import { t, handleError, APIClient } from '../../../../utils/client';
import { LivechatRoom } from '../../collections/LivechatRoom';
import { hasRole, hasPermission, hasAtLeastOnePermission } from '../../../../authorization';
import './livechatCurrentChats.html';

Template.livechatCurrentChats.helpers({
Expand All @@ -19,7 +22,7 @@ Template.livechatCurrentChats.helpers({
return Template.instance().ready.get();
},
livechatRoom() {
return LivechatRoom.find({ t: 'l' }, { sort: { ts: -1 } });
return Template.instance().livechatRoom.get();
},
startedAt() {
return moment(this.ts).format('L LTS');
Expand Down Expand Up @@ -63,6 +66,9 @@ Template.livechatCurrentChats.helpers({
tagId() {
return this;
},
hasPopoverPermissions() {
return hasAtLeastOnePermission(['remove-closed-livechat-rooms']);
},
});

Template.livechatCurrentChats.events({
Expand Down Expand Up @@ -130,6 +136,65 @@ Template.livechatCurrentChats.events({

popover.open(config);
},
'click .livechat-current-chats-extra-actions'(event, instance) {
event.preventDefault();
event.stopPropagation();
const { currentTarget } = event;

const canRemoveAllClosedRooms = hasPermission('remove-closed-livechat-rooms');
const allowedDepartments = () => {
if (hasRole(Meteor.userId(), ['admin', 'livechat-manager'])) {
return;
}

const departments = instance.departments.get();
return departments && departments.map((d) => d._id);
};

const config = {
popoverClass: 'livechat-current-chats-add-filter',
columns: [{
groups: [
{
items: [
canRemoveAllClosedRooms
&& {
icon: 'trash',
name: t('Delete_all_closed_chats'),
modifier: 'alert',
action: () => {
modal.open({
title: t('Are_you_sure'),
type: 'warning',
showCancelButton: true,
confirmButtonColor: '#DD6B55',
confirmButtonText: t('Yes'),
cancelButtonText: t('Cancel'),
closeOnConfirm: true,
html: false,
}, () => {
Meteor.call('livechat:removeAllClosedRooms', allowedDepartments(), (err, result) => {
if (err) {
return handleError(err);
}

if (result) {
toastr.success(TAPi18n.__('All_closed_chats_have_been_removed'));
}
});
});
},
},
],
},
],
}],
currentTarget,
offsetVertical: currentTarget.clientHeight,
};

popover.open(config);
},
'click .remove-livechat-tags-filter'(event, instance) {
event.preventDefault();

Expand Down Expand Up @@ -250,6 +315,7 @@ Template.livechatCurrentChats.onCreated(async function() {
this.ready = new ReactiveVar(false);
this.limit = new ReactiveVar(20);
this.filter = new ReactiveVar({});
this.livechatRoom = new ReactiveVar([]);
this.selectedAgents = new ReactiveVar([]);
this.customFilters = new ReactiveVar([]);
this.customFields = new ReactiveVar([]);
Expand All @@ -276,6 +342,8 @@ Template.livechatCurrentChats.onCreated(async function() {
this.customFields.set(customFields);
}
});

this.livechatRoom.set(LivechatRoom.find({ t: 'l' }, { sort: { ts: -1 } }));
});

Template.livechatCurrentChats.onRendered(function() {
Expand Down
1 change: 1 addition & 0 deletions app/livechat/server/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import './methods/loginByToken';
import './methods/pageVisited';
import './methods/registerGuest';
import './methods/removeAgent';
import './methods/removeAllClosedRooms';
import './methods/removeCustomField';
import './methods/removeDepartment';
import './methods/removeManager';
Expand Down
23 changes: 23 additions & 0 deletions app/livechat/server/methods/removeAllClosedRooms.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { Meteor } from 'meteor/meteor';

import { hasPermission } from '../../../authorization';
import { LivechatRooms, Messages, Subscriptions } from '../../../models';

Meteor.methods({
'livechat:removeAllClosedRooms'(departmentIds) {
if (!Meteor.userId() || !hasPermission(Meteor.userId(), 'remove-closed-livechat-rooms')) {
throw new Meteor.Error('error-not-allowed', 'Not allowed', { method: 'livechat:removeAllClosedRoom' });
}

let count = 0;
LivechatRooms.findClosedRooms(departmentIds).forEach(({ _id }) => {
Messages.removeByRoomId(_id);
Subscriptions.removeByRoomId(_id);
LivechatRooms.removeById(_id);

count++;
});

return count;
},
});
11 changes: 11 additions & 0 deletions app/models/server/models/LivechatRooms.js
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,17 @@ export class LivechatRooms extends Base {
return this.findOne(query, options);
}

findClosedRooms(departmentIds, options) {
const query = {
t: 'l',
open: { $exists: false },
closedAt: { $exists: true },
...Array.isArray(departmentIds) && departmentIds.length > 0 && { departmentId: { $in: departmentIds } },
};

return this.find(query, options);
}

setResponseByRoomId(roomId, response) {
return this.update({
_id: roomId,
Expand Down
4 changes: 3 additions & 1 deletion packages/rocketchat-i18n/i18n/en.i18n.json
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,7 @@
"All": "All",
"All_added_tokens_will_be_required_by_the_user": "All added tokens will be required by the user",
"All_channels": "All channels",
"All_closed_chats_have_been_removed": "All closed chats have been removed",
"All_logs": "All logs",
"All_messages": "All messages",
"All_users": "All users",
Expand Down Expand Up @@ -1036,6 +1037,7 @@
"Decode_Key": "Decode Key",
"Default": "Default",
"Delete": "Delete",
"Delete_all_closed_chats": "Delete all closed chats",
"delete-c": "Delete Public Channels",
"delete-c_description": "Permission to delete public channels",
"delete-d": "Delete Direct Messages",
Expand Down Expand Up @@ -3423,4 +3425,4 @@
"Your_question": "Your question",
"Your_server_link": "Your server link",
"Your_workspace_is_ready": "Your workspace is ready to use 🎉"
}
}
3 changes: 2 additions & 1 deletion packages/rocketchat-i18n/i18n/pt-BR.i18n.json
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,7 @@
"All": "Todos",
"All_added_tokens_will_be_required_by_the_user": "Todos os tokens adicionados ser exigidos ao usuário",
"All_channels": "Todos os canais",
"All_closed_chats_have_been_removed": "Todas as salas fechadas foram removidas",
"All_logs": "Todos os logs",
"All_messages": "Todas as mensagens",
"All_users": "Todos usuários",
Expand Down Expand Up @@ -3235,4 +3236,4 @@
"Your_question": "A sua pergunta",
"Your_server_link": "O link do seu servidor",
"Your_workspace_is_ready": "O seu espaço de trabalho está pronto a usar 🎉"
}
}