The communications platform that puts data protection first.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
Rocket.Chat/packages/rocketchat-message-star/client/actionButton.js

103 lines
2.7 KiB

import { Meteor } from 'meteor/meteor';
import { Template } from 'meteor/templating';
import { TAPi18n } from 'meteor/tap:i18n';
import { handleError } from 'meteor/rocketchat:utils';
import { Subscriptions } from 'meteor/rocketchat:models';
import { settings } from 'meteor/rocketchat:settings';
import { RoomHistoryManager, MessageAction } from 'meteor/rocketchat:ui-utils';
import toastr from 'toastr';
Meteor.startup(function() {
MessageAction.addButton({
id: 'star-message',
icon: 'star',
label: 'Star_Message',
context: ['starred', 'message', 'message-mobile'],
action() {
const message = this._arguments[1];
message.starred = Meteor.userId();
Meteor.call('starMessage', message, function(error) {
if (error) {
return handleError(error);
}
});
},
condition(message) {
if (Subscriptions.findOne({ rid: message.rid }) == null && settings.get('Message_AllowStarring')) {
return false;
}
return !message.starred || !message.starred.find((star) => star._id === Meteor.userId());
},
order: 10,
group: 'menu',
});
MessageAction.addButton({
id: 'unstar-message',
icon: 'star',
label: 'Unstar_Message',
context: ['starred', 'message', 'message-mobile'],
action() {
const message = this._arguments[1];
message.starred = false;
Meteor.call('starMessage', message, function(error) {
if (error) {
handleError(error);
}
});
},
condition(message) {
if (Subscriptions.findOne({ rid: message.rid }) == null && settings.get('Message_AllowStarring')) {
return false;
}
return message.starred && message.starred.find((star) => star._id === Meteor.userId());
},
order: 10,
group: 'menu',
});
MessageAction.addButton({
id: 'jump-to-star-message',
icon: 'jump',
label: 'Jump_to_message',
context: ['starred'],
action() {
const message = this._arguments[1];
if (window.matchMedia('(max-width: 500px)').matches) {
Template.instance().tabBar.close();
}
RoomHistoryManager.getSurroundingMessages(message, 50);
},
condition(message) {
if (Subscriptions.findOne({ rid: message.rid }) == null) {
return false;
}
return true;
},
order: 100,
group: 'menu',
});
MessageAction.addButton({
id: 'permalink-star',
icon: 'permalink',
label: 'Permalink',
classes: 'clipboard',
context: ['starred'],
async action(event) {
const message = this._arguments[1];
$(event.currentTarget).attr('data-clipboard-text', await MessageAction.getPermaLink(message._id));
toastr.success(TAPi18n.__('Copied'));
},
condition(message) {
if (Subscriptions.findOne({ rid: message.rid }) == null) {
return false;
}
return true;
},
order: 101,
group: 'menu',
});
});