Skip to content

Commit

Permalink
Merge pull request #7988 from RocketChat/action=messages
Browse files Browse the repository at this point in the history
[FIX] Vertical menu on flex-tab
# Conflicts:
#	packages/rocketchat-ui-master/public/icons.svg
  • Loading branch information
rodrigok committed Sep 5, 2017
1 parent 678fe0b commit 7e39818
Show file tree
Hide file tree
Showing 20 changed files with 104 additions and 180 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ Meteor.startup(function() {
action() {
const message = this._arguments[1];
const language = RocketChat.AutoTranslate.getLanguage(message.rid);
RocketChat.MessageAction.hideDropDown();
if ((!message.translations || !message.translations[language])) { //} && !_.find(message.attachments, attachment => { return attachment.translations && attachment.translations[language]; })) {
RocketChat.AutoTranslate.messageIdsToWait[message._id] = true;
RocketChat.models.Messages.update({ _id: message._id }, { $set: { autoTranslateFetching: true } });
Expand Down

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

13 changes: 4 additions & 9 deletions packages/rocketchat-lib/client/MessageAction.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,23 +59,22 @@ RocketChat.MessageAction = new class {
}

getButtons(message, context, group) {
const allButtons = _.toArray(this.buttons.get());
let allowedButtons = allButtons;
let allButtons = _.toArray(this.buttons.get());

if (group) {
allowedButtons = allowedButtons.filter(button => button.group === group);
allButtons = allButtons.filter(button => button.group === group);
}

if (message) {
allowedButtons = _.compact(_.map(allowedButtons, function(button) {
allButtons = _.compact(_.map(allButtons, function(button) {
if (button.context == null || button.context.includes(context)) {
if (button.condition == null || button.condition(message, context)) {
return button;
}
}
}));
}
return _.sortBy(allowedButtons, 'order');
return _.sortBy(allButtons, 'order');
}

resetButtons() {
Expand All @@ -96,10 +95,6 @@ RocketChat.MessageAction = new class {
closePopover() {
popover.close();
}

hideDropDown() {
$('.message-dropdown:visible').hide();
}
};

Meteor.startup(function() {
Expand Down
3 changes: 1 addition & 2 deletions packages/rocketchat-mentions-flextab/client/actionButton.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
Meteor.startup(function() {
RocketChat.MessageAction.addButton({
id: 'jump-to-message',
icon: 'right-hand',
icon: 'jump',
label: 'Jump_to_message',
context: ['mentions'],
action() {
const message = this._arguments[1];
RocketChat.MessageAction.hideDropDown();
if (window.matchMedia('(max-width: 500px)').matches) {
Template.instance().tabBar.close();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@ Template.mentionsFlexTab.helpers({
});
},
message() {
return _.extend(this, {
customClass: 'mentions'
});
return _.extend(this, { customClass: 'mentions', actionContext: 'mentions'});
},
hasMore() {
return Template.instance().hasMore.get();
Expand All @@ -42,21 +40,6 @@ Template.mentionsFlexTab.onCreated(function() {
});

Template.mentionsFlexTab.events({
'click .message-cog'(e, t) {
e.stopPropagation();
e.preventDefault();
const message_id = $(e.currentTarget).closest('.message').attr('id');
RocketChat.MessageAction.hideDropDown();
t.$(`\#${ message_id } .message-dropdown`).remove();
const message = MentionedMessage.findOne(message_id);
const actions = RocketChat.MessageAction.getButtons(message, 'mentions');
const el = Blaze.toHTMLWithData(Template.messageDropdown, {
actions
});
t.$(`\#${ message_id } .message-cog-container`).append(el);
const dropDown = t.$(`\#${ message_id } .message-dropdown`);
return dropDown.show();
},
'scroll .js-list': _.throttle(function(e, instance) {
if (e.target.scrollTop >= e.target.scrollHeight - e.target.clientHeight && instance.hasMore.get()) {
return instance.limit.set(instance.limit.get() + 50);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ Meteor.startup(() => {
context: ['message', 'message-mobile'],
action() {
const message = this._arguments[1];
RocketChat.MessageAction.hideDropDown();
return Meteor.call('unreadMessages', message, function(error) {
if (error) {
return handleError(error);
Expand Down
23 changes: 10 additions & 13 deletions packages/rocketchat-message-pin/client/actionButton.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,17 @@ Meteor.startup(function() {
action() {
const message = this._arguments[1];
message.pinned = true;
return Meteor.call('pinMessage', message, function(error) {
Meteor.call('pinMessage', message, function(error) {
if (error) {
return handleError(error);
}
});
},
condition(message) {
if (RocketChat.models.Subscriptions.findOne({ rid: message.rid }) == null) {
return false;
} else if (message.pinned || !RocketChat.settings.get('Message_AllowPinning')) {
if (!RocketChat.settings.get('Message_AllowPinning') || message.pinned || !RocketChat.models.Subscriptions.findOne({ rid: message.rid }, {fields: {_id: 1}})) {
return false;
}

return RocketChat.authz.hasAtLeastOnePermission('pin-message', message.rid);
},
order: 20,
Expand All @@ -35,38 +34,37 @@ Meteor.startup(function() {
action() {
const message = this._arguments[1];
message.pinned = false;
return Meteor.call('unpinMessage', message, function(error) {
Meteor.call('unpinMessage', message, function(error) {
if (error) {
return handleError(error);
}
});
},
condition(message) {
if ((RocketChat.models.Subscriptions.findOne({ rid: message.rid }) == null) && (!message.pinned || !RocketChat.settings.get('Message_AllowPinning'))) {
if (!RocketChat.settings.get('Message_AllowPinning') || !message.pinned || !RocketChat.models.Subscriptions.findOne({ rid: message.rid }, {fields: {_id: 1}})) {
return false;
}

RocketChat.authz.hasAtLeastOnePermission('pin-message', message.rid);
return RocketChat.authz.hasAtLeastOnePermission('pin-message', message.rid);
},
order: 21,
group: 'menu'
});

RocketChat.MessageAction.addButton({
id: 'jump-to-pin-message',
icon: 'right-hand',
icon: 'jump',
label: 'Jump_to_message',
context: ['pinned'],
action() {
const message = this._arguments[1];
RocketChat.MessageAction.hideDropDown();
if (window.matchMedia('(max-width: 500px)').matches) {
Template.instance().tabBar.close();
}
return RoomHistoryManager.getSurroundingMessages(message, 50);
},
condition(message) {
if (RocketChat.models.Subscriptions.findOne({ rid: message.rid }) == null) {
if (!RocketChat.models.Subscriptions.findOne({ rid: message.rid }, {fields: {_id: 1}})) {
return false;
}
return true;
Expand All @@ -77,18 +75,17 @@ Meteor.startup(function() {

RocketChat.MessageAction.addButton({
id: 'permalink-pinned',
icon: 'link',
icon: 'permalink',
label: 'Permalink',
classes: 'clipboard',
context: ['pinned'],
action(event) {
const message = this._arguments[1];
RocketChat.MessageAction.hideDropDown();
$(event.currentTarget).attr('data-clipboard-text', RocketChat.MessageAction.getPermaLink(message._id));
toastr.success(TAPi18n.__('Copied'));
},
condition(message) {
if (RocketChat.models.Subscriptions.findOne({ rid: message.rid }) == null) {
if (!RocketChat.models.Subscriptions.findOne({ rid: message.rid }, {fields: {_id: 1}})) {
return false;
}
return true;
Expand Down
19 changes: 1 addition & 18 deletions packages/rocketchat-message-pin/client/views/pinnedMessages.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@ Template.pinnedMessages.helpers({
});
},
message() {
return _.extend(this, {
customClass: 'pinned'
});
return _.extend(this, { customClass: 'pinned', actionContext: 'pinned'});
},
hasMore() {
return Template.instance().hasMore.get();
Expand All @@ -44,21 +42,6 @@ Template.pinnedMessages.onCreated(function() {
});

Template.pinnedMessages.events({
'click .message-cog'(e, t) {
e.stopPropagation();
e.preventDefault();
const message_id = $(e.currentTarget).closest('.message').attr('id');
RocketChat.MessageAction.hideDropDown();
t.$(`\#${ message_id } .message-dropdown`).remove();
const message = PinnedMessage.findOne(message_id);
const actions = RocketChat.MessageAction.getButtons(message, 'pinned');
const el = Blaze.toHTMLWithData(Template.messageDropdown, {
actions
});
t.$(`\#${ message_id } .message-cog-container`).append(el);
const dropDown = t.$(`\#${ message_id } .message-dropdown`);
return dropDown.show();
},
'scroll .js-list': _.throttle(function(e, instance) {
if (e.target.scrollTop >= e.target.scrollHeight - e.target.clientHeight && instance.hasMore.get()) {
return instance.limit.set(instance.limit.get() + 50);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Template.snippetedMessages.helpers({
return SnippetedMessages.find({ snippeted: true, rid: this.rid }, { sort: { ts: -1 } });
},
message() {
return _.extend(this, { customClass: 'snippeted' });
return _.extend(this, { customClass: 'snippeted', actionContext: 'snippeted'});
},
hasMore() {
return Template.instance().hasMore.get();
Expand Down
6 changes: 2 additions & 4 deletions packages/rocketchat-message-star/client/actionButton.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,11 @@ Meteor.startup(function() {

RocketChat.MessageAction.addButton({
id: 'jump-to-star-message',
icon: 'right-hand',
icon: 'jump',
label: 'Jump_to_message',
context: ['starred'],
action() {
const message = this._arguments[1];
RocketChat.MessageAction.hideDropDown();
if (window.matchMedia('(max-width: 500px)').matches) {
Template.instance().tabBar.close();
}
Expand All @@ -75,13 +74,12 @@ Meteor.startup(function() {

RocketChat.MessageAction.addButton({
id: 'permalink-star',
icon: 'link',
icon: 'permalink',
label: 'Permalink',
classes: 'clipboard',
context: ['starred'],
action(event) {
const message = this._arguments[1];
RocketChat.MessageAction.hideDropDown();
$(event.currentTarget).attr('data-clipboard-text', RocketChat.MessageAction.getPermaLink(message._id));
toastr.success(TAPi18n.__('Copied'));
},
Expand Down
19 changes: 1 addition & 18 deletions packages/rocketchat-message-star/client/views/starredMessages.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@ Template.starredMessages.helpers({
});
},
message() {
return _.extend(this, {
customClass: 'starred'
});
return _.extend(this, { customClass: 'starred', actionContext: 'starred'});
},
hasMore() {
return Template.instance().hasMore.get();
Expand All @@ -43,21 +41,6 @@ Template.starredMessages.onCreated(function() {
});

Template.starredMessages.events({
'click .message-cog'(e, t) {
e.stopPropagation();
e.preventDefault();
const message_id = $(e.currentTarget).closest('.message').attr('id');
RocketChat.MessageAction.hideDropDown();
t.$(`\#${ message_id } .message-dropdown`).remove();
const message = StarredMessage.findOne(message_id);
const actions = RocketChat.MessageAction.getButtons(message, 'starred');
const el = Blaze.toHTMLWithData(Template.messageDropdown, {
actions
});
t.$(`\#${ message_id } .message-cog-container`).append(el);
const dropDown = t.$(`\#${ message_id } .message-dropdown`);
return dropDown.show();
},
'scroll .js-list': _.throttle(function(e, instance) {
if (e.target.scrollTop >= e.target.scrollHeight - e.target.clientHeight) {
return instance.limit.set(instance.limit.get() + 50);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,10 @@

&__icon-element {
font-size: 18px;

&--star {
fill: none;
}
}

&__item-text {
Expand All @@ -118,6 +122,10 @@
}
}

[data-message-action="unstar-message"] .rc-popover__icon-element--star {
fill: currentColor;
}

@keyframes dropdown-show {
0% {
transform: translate(0, -2%);
Expand Down
8 changes: 7 additions & 1 deletion packages/rocketchat-theme/client/imports/general/base.css
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,15 @@ button {
}

& .tab-button-icon {
font-size: 1.125rem;
color: var(--color-dark-medium);

font-size: 1.125rem;

fill: var(--color-dark-medium);

&--star {
fill: none;
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ <h2>{{_ "No_results_found"}}</h2>
<div class="flex-tab__result js-list">
<ul class="list clearfix">
{{#each searchResultMessages}}
{{#nrr nrrargs 'message' message}}{{/nrr}}
{{#nrr nrrargs 'message' message}}{{/nrr}}
{{/each}}
</ul>
{{#if hasMore}}
Expand Down
Loading

0 comments on commit 7e39818

Please sign in to comment.