Skip to content

Commit

Permalink
Merge pull request #8915 from RocketChat/add-options-to-room-menu
Browse files Browse the repository at this point in the history
[NEW]  Add "Favorites" and "Mark as read" options to the room list
  • Loading branch information
rodrigok authored Dec 8, 2017
2 parents 683792a + 5adb855 commit 73e4cc7
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 14 deletions.
20 changes: 10 additions & 10 deletions packages/rocketchat-livechat/app/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@
fill: var(--rc-color-error);
}
}

&--star-filled .rc-icon {
fill: currentColor;
}
}

&__icon {
Expand Down
34 changes: 33 additions & 1 deletion packages/rocketchat-ui-sidenav/client/sidebarItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,20 +74,51 @@ Template.sidebarItem.events({
return menu.close();
},
'click .sidebar-item__menu'(e) {
e.preventDefault();

const canLeave = () => {
const roomData = Session.get(`roomData${ this.rid }`);

if (!roomData) { return false; }

return !(((roomData.cl != null) && !roomData.cl) || (['d', 'l'].includes(roomData.t)));
};
e.preventDefault();

const canFavorite = RocketChat.settings.get('Favorite_Rooms') && ChatSubscription.find({ rid: this.rid }).count() > 0;
const isFavorite = () => {
const sub = ChatSubscription.findOne({ rid: this.rid }, { fields: { f: 1 } });
if (((sub != null ? sub.f : undefined) != null) && sub.f) {
return true;
}
return false;
};

const items = [{
icon: 'eye-off',
name: t('Hide_room'),
type: 'sidebar-item',
id: 'hide'
}];

if (this.alert) {
items.push({
icon: 'flag',
name: t('Mark_as_read'),
type: 'sidebar-item',
id: 'read'
});
}

if (canFavorite) {
items.push({
icon: 'star',
name: t(isFavorite() ? 'Unfavorite' : 'Favorite'),
modifier: isFavorite() ? 'star-filled' : 'star',
type: 'sidebar-item',
id: 'favorite'
});
}

if (canLeave()) {
items.push({
icon: 'sign-out',
Expand All @@ -97,6 +128,7 @@ Template.sidebarItem.events({
modifier: 'error'
});
}

const config = {
popoverClass: 'sidebar-item',
columns: [
Expand Down
34 changes: 31 additions & 3 deletions packages/rocketchat-ui/client/views/app/popover.js
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ Template.popover.events({
if (e.currentTarget.dataset.id === 'hide') {
const warnText = RocketChat.roomTypes.roomTypes[template].getUiText(UiTextContext.HIDE_WARNING);

return swal({
swal({
title: t('Are_you_sure'),
text: warnText ? t(warnText, name) : '',
type: 'warning',
Expand All @@ -210,8 +210,18 @@ Template.popover.events({
}
});
});
} else {
const warnText = RocketChat.roomTypes.roomTypes[template].getUiText(UiTextContext.LEAVE_WARNING);

return false;
}

if (e.currentTarget.dataset.id === 'leave') {
let warnText;
switch (template) {
case 'c': warnText = 'Leave_Room_Warning'; break;
case 'p': warnText = 'Leave_Group_Warning'; break;
case 'd': warnText = 'Leave_Private_Warning'; break;
case 'l': warnText = 'Hide_Livechat_Warning'; break;
}

swal({
title: t('Are_you_sure'),
Expand Down Expand Up @@ -246,6 +256,24 @@ Template.popover.events({
swal.close();
}
});

return false;
}

if (e.currentTarget.dataset.id === 'read') {
Meteor.call('readMessages', rid);
return false;
}

if (e.currentTarget.dataset.id === 'favorite') {
Meteor.call('toggleFavorite', rid, !$(e.currentTarget).hasClass('rc-popover__item--star-filled'), function(err) {
popover.close();
if (err) {
handleError(err);
}
});

return false;
}
}
});

0 comments on commit 73e4cc7

Please sign in to comment.