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/app/message-pin/client/pinMessage.js

63 lines
1.6 KiB

import { Meteor } from 'meteor/meteor';
import toastr from 'toastr';
import { TAPi18n } from 'meteor/rocketchat:tap-i18n';
import { settings } from '../../settings';
import { ChatMessage, Subscriptions } from '../../models';
Meteor.methods({
pinMessage(message) {
if (!Meteor.userId()) {
toastr.error(TAPi18n.__('error-not-authorized'));
return false;
}
if (!settings.get('Message_AllowPinning')) {
toastr.error(TAPi18n.__('pinning-not-allowed'));
return false;
}
if (Subscriptions.findOne({ rid: message.rid }) == null) {
toastr.error(TAPi18n.__('error-pinning-message'));
return false;
}
if (typeof message._id !== 'string') {
toastr.error(TAPi18n.__('error-pinning-message'));
return false;
}
toastr.success(TAPi18n.__('Message_has_been_pinned'));
return ChatMessage.update({
_id: message._id,
rid: message.rid,
}, {
$set: {
pinned: true,
},
});
},
unpinMessage(message) {
if (!Meteor.userId()) {
toastr.error(TAPi18n.__('error-not-authorized'));
return false;
}
if (!settings.get('Message_AllowPinning')) {
toastr.error(TAPi18n.__('unpinning-not-allowed'));
return false;
}
if (Subscriptions.findOne({ rid: message.rid }) == null) {
toastr.error(TAPi18n.__('error-unpinning-message'));
return false;
}
if (typeof message._id !== 'string') {
toastr.error(TAPi18n.__('error-unpinning-message'));
return false;
}
toastr.success(TAPi18n.__('Message_has_been_unpinned'));
return ChatMessage.update({
_id: message._id,
rid: message.rid,
}, {
$set: {
pinned: false,
},
});
},
});