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

69 lines
2.0 KiB

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