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/ui/client/lib/chatMessages.js

649 lines
18 KiB

import { Meteor } from 'meteor/meteor';
import { ReactiveVar } from 'meteor/reactive-var';
import { Random } from 'meteor/random';
import { Tracker } from 'meteor/tracker';
import { FlowRouter } from 'meteor/kadira:flow-router';
import { Session } from 'meteor/session';
import { TAPi18n } from 'meteor/tap:i18n';
import { t, getUserPreference, slashCommands, handleError } from '../../../utils';
import { MessageAction, messageProperties, MessageTypes, readMessage, modal } from '../../../ui-utils';
import { settings } from '../../../settings';
import { callbacks } from '../../../callbacks';
import { promises } from '../../../promises';
import { hasAtLeastOnePermission } from '../../../authorization';
import { Messages, Rooms, ChatMessage } from '../../../models';
import { emoji } from '../../../emoji';
Convert rocketchat:ui to main module structure (#13132) * Move rocketchat settings to specific package * WIP: Move models from rocketchat-lib to a specific package (server) * Move function from rocketchat:lib to rocketchat:utils to use it in rocketchat:models * Move client models from rocketchat:lib to rocketchat:models * Fix lint * Move rocketchat.info from lib to utils * Remove directly dependency between lib and migrations * Move statistics Model to rocketchat:models * Create rocketchat:metrics to be able to depacking rocketchat callbacks * Move callbacks to specific package * Remove unused dependency * Move rocketchat-notifications to a specific package * Move rocketchat-promises to a specific package * remove directly dependency from metrics and models * Move CachedCollection from lib to models * Move ui models/collections from ui to models * Move authorization client/ui models to rocketchat:models to be able to remove lib dependency * Creation of rocketchat:ui-utils to help decouple rocketchat:lib and rocketchat:authz * Move some common functions to rocketchat:utils * Change imports to dynamic imports to avoid directly dependency between some packages * Move authz models to rocketchat:models * Remove directly dependency between rocketchat:authz and rocketchat:lib * Move some functions from rocketchat:lib to rocketchat:utils * Add functions to settings package * Convert rocketchat:file-upload to main module structure * Import FileUpload where it is being used * Remove FileUpload and fileUploadHandler from globals eslintrc * Move some functions to rocketchat:ui-utils * Remove directly dependency between rocketchat:authorization and rocketchat:ui-utils * Remove dependency between lazy-load and lib * Change imports of renderMessageBody from ui-message to ui-utils * Add import of main ready from ui-utils * Convert rocketchat-ui-sidenav to main module structure * Add imports of toolbarSearch from ui-sidenav * Remove toolbarSearch from eslintrc globals * Move CachedCollection to a specific package * Change imports of CachedCollection to new package * Move some functions to rocketchat:ui-utils * Remove directly dependency between tooltip and lib * Remove directly dependency between settings and metrics * Move some settings client function from lib to settings * Convert rocketchat-ui-master to main module structure * Remove directly dependency between rocketchat:e2e and rocketchat:lib * Fix wrong import and lint * Convert rocketchat-webrtc to main module structure * Fix missing export * Remove directly dependency between rocketchat:emoji and lib * Add emoji dependencies inside RocketChat namespace * Merge branch 'develop' into globals/move-rocketchat-callbacks * Move some functions to utils * Fix lint * Move some ui functions to ui-utils * Fix import missed objects inside RocketChat namespace * Fix lint * Remove rocketchat:ui package dependency of RocketChat namespace * Remove lib dependency in rocketchat:ui-sidenav * Remove dependency between lib and ui-vrecord * Add logger dependency in file-upload * Convert rocketchat:ui to main module structure * import variables that was broken due to conversion of rocketchat:ui * Remove globals variables from eslintrc and add some to the eslintrc of livechat app * Revert commented test file * Add missed files * Fix lint
7 years ago
import { KonchatNotification } from './notification';
import { MsgTyping } from './msgTyping';
import _ from 'underscore';
import s from 'underscore.string';
9 years ago
import moment from 'moment';
import toastr from 'toastr';
let sendOnEnter = '';
Meteor.startup(() => {
Tracker.autorun(function() {
const user = Meteor.userId();
Remove dependency of RocketChat namespace inside rocketchat:ui (#13131) * Move rocketchat settings to specific package * WIP: Move models from rocketchat-lib to a specific package (server) * Move function from rocketchat:lib to rocketchat:utils to use it in rocketchat:models * Move client models from rocketchat:lib to rocketchat:models * Fix lint * Move rocketchat.info from lib to utils * Remove directly dependency between lib and migrations * Move statistics Model to rocketchat:models * Create rocketchat:metrics to be able to depacking rocketchat callbacks * Move callbacks to specific package * Remove unused dependency * Move rocketchat-notifications to a specific package * Move rocketchat-promises to a specific package * remove directly dependency from metrics and models * Move CachedCollection from lib to models * Move ui models/collections from ui to models * Move authorization client/ui models to rocketchat:models to be able to remove lib dependency * Creation of rocketchat:ui-utils to help decouple rocketchat:lib and rocketchat:authz * Move some common functions to rocketchat:utils * Change imports to dynamic imports to avoid directly dependency between some packages * Move authz models to rocketchat:models * Remove directly dependency between rocketchat:authz and rocketchat:lib * Move some functions from rocketchat:lib to rocketchat:utils * Add functions to settings package * Convert rocketchat:file-upload to main module structure * Import FileUpload where it is being used * Remove FileUpload and fileUploadHandler from globals eslintrc * Move some functions to rocketchat:ui-utils * Remove directly dependency between rocketchat:authorization and rocketchat:ui-utils * Remove dependency between lazy-load and lib * Change imports of renderMessageBody from ui-message to ui-utils * Add import of main ready from ui-utils * Convert rocketchat-ui-sidenav to main module structure * Add imports of toolbarSearch from ui-sidenav * Remove toolbarSearch from eslintrc globals * Move CachedCollection to a specific package * Change imports of CachedCollection to new package * Move some functions to rocketchat:ui-utils * Remove directly dependency between tooltip and lib * Remove directly dependency between settings and metrics * Move some settings client function from lib to settings * Convert rocketchat-ui-master to main module structure * Remove directly dependency between rocketchat:e2e and rocketchat:lib * Fix wrong import and lint * Convert rocketchat-webrtc to main module structure * Fix missing export * Remove directly dependency between rocketchat:emoji and lib * Add emoji dependencies inside RocketChat namespace * Merge branch 'develop' into globals/move-rocketchat-callbacks * Move some functions to utils * Fix lint * Move some ui functions to ui-utils * Fix import missed objects inside RocketChat namespace * Fix lint * Remove rocketchat:ui package dependency of RocketChat namespace * Remove lib dependency in rocketchat:ui-sidenav * Remove dependency between lib and ui-vrecord * Add logger dependency in file-upload * Revert commented test file
7 years ago
sendOnEnter = getUserPreference(user, 'sendOnEnter');
});
});
export const getPermaLinks = async(replies) => {
const promises = replies.map(async(reply) =>
MessageAction.getPermaLink(reply._id)
);
return Promise.all(promises);
};
export const mountReply = async(msg, input) => {
const replies = $(input).data('reply');
const mentionUser = $(input).data('mention-user') || false;
if (replies && replies.length) {
const permalinks = await getPermaLinks(replies);
replies.forEach(async(reply, replyIndex) => {
if (reply !== undefined) {
msg += `[ ](${ permalinks[replyIndex] }) `;
const roomInfo = Rooms.findOne(reply.rid, { fields: { t: 1 } });
if (roomInfo.t !== 'd' && reply.u.username !== Meteor.user().username && mentionUser) {
msg += `@${ reply.u.username } `;
}
}
});
}
return msg;
};
Convert rocketchat:ui to main module structure (#13132) * Move rocketchat settings to specific package * WIP: Move models from rocketchat-lib to a specific package (server) * Move function from rocketchat:lib to rocketchat:utils to use it in rocketchat:models * Move client models from rocketchat:lib to rocketchat:models * Fix lint * Move rocketchat.info from lib to utils * Remove directly dependency between lib and migrations * Move statistics Model to rocketchat:models * Create rocketchat:metrics to be able to depacking rocketchat callbacks * Move callbacks to specific package * Remove unused dependency * Move rocketchat-notifications to a specific package * Move rocketchat-promises to a specific package * remove directly dependency from metrics and models * Move CachedCollection from lib to models * Move ui models/collections from ui to models * Move authorization client/ui models to rocketchat:models to be able to remove lib dependency * Creation of rocketchat:ui-utils to help decouple rocketchat:lib and rocketchat:authz * Move some common functions to rocketchat:utils * Change imports to dynamic imports to avoid directly dependency between some packages * Move authz models to rocketchat:models * Remove directly dependency between rocketchat:authz and rocketchat:lib * Move some functions from rocketchat:lib to rocketchat:utils * Add functions to settings package * Convert rocketchat:file-upload to main module structure * Import FileUpload where it is being used * Remove FileUpload and fileUploadHandler from globals eslintrc * Move some functions to rocketchat:ui-utils * Remove directly dependency between rocketchat:authorization and rocketchat:ui-utils * Remove dependency between lazy-load and lib * Change imports of renderMessageBody from ui-message to ui-utils * Add import of main ready from ui-utils * Convert rocketchat-ui-sidenav to main module structure * Add imports of toolbarSearch from ui-sidenav * Remove toolbarSearch from eslintrc globals * Move CachedCollection to a specific package * Change imports of CachedCollection to new package * Move some functions to rocketchat:ui-utils * Remove directly dependency between tooltip and lib * Remove directly dependency between settings and metrics * Move some settings client function from lib to settings * Convert rocketchat-ui-master to main module structure * Remove directly dependency between rocketchat:e2e and rocketchat:lib * Fix wrong import and lint * Convert rocketchat-webrtc to main module structure * Fix missing export * Remove directly dependency between rocketchat:emoji and lib * Add emoji dependencies inside RocketChat namespace * Merge branch 'develop' into globals/move-rocketchat-callbacks * Move some functions to utils * Fix lint * Move some ui functions to ui-utils * Fix import missed objects inside RocketChat namespace * Fix lint * Remove rocketchat:ui package dependency of RocketChat namespace * Remove lib dependency in rocketchat:ui-sidenav * Remove dependency between lib and ui-vrecord * Add logger dependency in file-upload * Convert rocketchat:ui to main module structure * import variables that was broken due to conversion of rocketchat:ui * Remove globals variables from eslintrc and add some to the eslintrc of livechat app * Revert commented test file * Add missed files * Fix lint
7 years ago
export const ChatMessages = class ChatMessages {
constructor() {
this.saveTextMessageBox = _.debounce((rid, value) => {
const key = `messagebox_${ rid }`;
return value.length ? localStorage.setItem(key, value) : localStorage.removeItem(key);
}, 1000);
}
9 years ago
init(node) {
this.editing = {};
this.records = {};
Remove dependency of RocketChat namespace inside rocketchat:ui (#13131) * Move rocketchat settings to specific package * WIP: Move models from rocketchat-lib to a specific package (server) * Move function from rocketchat:lib to rocketchat:utils to use it in rocketchat:models * Move client models from rocketchat:lib to rocketchat:models * Fix lint * Move rocketchat.info from lib to utils * Remove directly dependency between lib and migrations * Move statistics Model to rocketchat:models * Create rocketchat:metrics to be able to depacking rocketchat callbacks * Move callbacks to specific package * Remove unused dependency * Move rocketchat-notifications to a specific package * Move rocketchat-promises to a specific package * remove directly dependency from metrics and models * Move CachedCollection from lib to models * Move ui models/collections from ui to models * Move authorization client/ui models to rocketchat:models to be able to remove lib dependency * Creation of rocketchat:ui-utils to help decouple rocketchat:lib and rocketchat:authz * Move some common functions to rocketchat:utils * Change imports to dynamic imports to avoid directly dependency between some packages * Move authz models to rocketchat:models * Remove directly dependency between rocketchat:authz and rocketchat:lib * Move some functions from rocketchat:lib to rocketchat:utils * Add functions to settings package * Convert rocketchat:file-upload to main module structure * Import FileUpload where it is being used * Remove FileUpload and fileUploadHandler from globals eslintrc * Move some functions to rocketchat:ui-utils * Remove directly dependency between rocketchat:authorization and rocketchat:ui-utils * Remove dependency between lazy-load and lib * Change imports of renderMessageBody from ui-message to ui-utils * Add import of main ready from ui-utils * Convert rocketchat-ui-sidenav to main module structure * Add imports of toolbarSearch from ui-sidenav * Remove toolbarSearch from eslintrc globals * Move CachedCollection to a specific package * Change imports of CachedCollection to new package * Move some functions to rocketchat:ui-utils * Remove directly dependency between tooltip and lib * Remove directly dependency between settings and metrics * Move some settings client function from lib to settings * Convert rocketchat-ui-master to main module structure * Remove directly dependency between rocketchat:e2e and rocketchat:lib * Fix wrong import and lint * Convert rocketchat-webrtc to main module structure * Fix missing export * Remove directly dependency between rocketchat:emoji and lib * Add emoji dependencies inside RocketChat namespace * Merge branch 'develop' into globals/move-rocketchat-callbacks * Move some functions to utils * Fix lint * Move some ui functions to ui-utils * Fix import missed objects inside RocketChat namespace * Fix lint * Remove rocketchat:ui package dependency of RocketChat namespace * Remove lib dependency in rocketchat:ui-sidenav * Remove dependency between lib and ui-vrecord * Add logger dependency in file-upload * Revert commented test file
7 years ago
this.messageMaxSize = settings.get('Message_MaxAllowedSize');
9 years ago
this.wrapper = $(node).find('.wrapper');
this.input = this.input || $(node).find('.js-input-message').get(0);
9 years ago
this.$input = $(this.input);
this.hasValue = new ReactiveVar(false);
this.bindEvents();
}
getEditingIndex(element) {
const msgs = this.wrapper.get(0).querySelectorAll('.own:not(.system)');
let index = 0;
for (const msg of Array.from(msgs)) {
if (msg === element) {
return index;
}
index++;
}
return -1;
}
recordInputAsDraft() {
const { id } = this.editing;
const message = this.getMessageById(id);
const record = this.records[id] || {};
const draft = this.input.value;
if (draft === message.msg) {
return this.clearCurrentDraft();
} else {
record.draft = draft;
return this.records[id] = record;
}
}
getMessageDraft(id) {
return this.records[id];
}
clearMessageDraft(id) {
return delete this.records[id];
}
clearCurrentDraft() {
return this.clearMessageDraft(this.editing.id);
}
resetToDraft(id) {
const message = this.getMessageById(id);
const old_value = this.input.value;
this.input.value = message.msg;
return old_value !== message.msg;
}
getMessageById(id) {
return ChatMessage.findOne(id);
}
toPrevMessage() {
const { index } = this.editing;
return this.editByIndex((index != null) ? index - 1 : undefined);
}
toNextMessage() {
const { index } = this.editing;
if (!this.editByIndex(index + 1)) { return this.clearEditing(); }
}
editByIndex(index) {
9 years ago
if (!this.editing.element && index) { return false; }
9 years ago
const msgs = this.wrapper.get(0).querySelectorAll('.own:not(.system)');
9 years ago
if (index == null) { index = msgs.length - 1; }
9 years ago
if (!msgs[index]) { return false; }
const element = msgs[index];
this.edit(element, index);
return true;
}
edit(element, index) {
9 years ago
index = index != null ? index : this.getEditingIndex(element);
9 years ago
const message = this.getMessageById(element.getAttribute('id'));
Remove dependency of RocketChat namespace inside rocketchat:ui (#13131) * Move rocketchat settings to specific package * WIP: Move models from rocketchat-lib to a specific package (server) * Move function from rocketchat:lib to rocketchat:utils to use it in rocketchat:models * Move client models from rocketchat:lib to rocketchat:models * Fix lint * Move rocketchat.info from lib to utils * Remove directly dependency between lib and migrations * Move statistics Model to rocketchat:models * Create rocketchat:metrics to be able to depacking rocketchat callbacks * Move callbacks to specific package * Remove unused dependency * Move rocketchat-notifications to a specific package * Move rocketchat-promises to a specific package * remove directly dependency from metrics and models * Move CachedCollection from lib to models * Move ui models/collections from ui to models * Move authorization client/ui models to rocketchat:models to be able to remove lib dependency * Creation of rocketchat:ui-utils to help decouple rocketchat:lib and rocketchat:authz * Move some common functions to rocketchat:utils * Change imports to dynamic imports to avoid directly dependency between some packages * Move authz models to rocketchat:models * Remove directly dependency between rocketchat:authz and rocketchat:lib * Move some functions from rocketchat:lib to rocketchat:utils * Add functions to settings package * Convert rocketchat:file-upload to main module structure * Import FileUpload where it is being used * Remove FileUpload and fileUploadHandler from globals eslintrc * Move some functions to rocketchat:ui-utils * Remove directly dependency between rocketchat:authorization and rocketchat:ui-utils * Remove dependency between lazy-load and lib * Change imports of renderMessageBody from ui-message to ui-utils * Add import of main ready from ui-utils * Convert rocketchat-ui-sidenav to main module structure * Add imports of toolbarSearch from ui-sidenav * Remove toolbarSearch from eslintrc globals * Move CachedCollection to a specific package * Change imports of CachedCollection to new package * Move some functions to rocketchat:ui-utils * Remove directly dependency between tooltip and lib * Remove directly dependency between settings and metrics * Move some settings client function from lib to settings * Convert rocketchat-ui-master to main module structure * Remove directly dependency between rocketchat:e2e and rocketchat:lib * Fix wrong import and lint * Convert rocketchat-webrtc to main module structure * Fix missing export * Remove directly dependency between rocketchat:emoji and lib * Add emoji dependencies inside RocketChat namespace * Merge branch 'develop' into globals/move-rocketchat-callbacks * Move some functions to utils * Fix lint * Move some ui functions to ui-utils * Fix import missed objects inside RocketChat namespace * Fix lint * Remove rocketchat:ui package dependency of RocketChat namespace * Remove lib dependency in rocketchat:ui-sidenav * Remove dependency between lib and ui-vrecord * Add logger dependency in file-upload * Revert commented test file
7 years ago
const hasPermission = hasAtLeastOnePermission('edit-message', message.rid);
const editAllowed = settings.get('Message_AllowEditing');
9 years ago
const editOwn = message && message.u && message.u._id === Meteor.userId();
if (!hasPermission && (!editAllowed || !editOwn)) { return; }
9 years ago
if (element.classList.contains('system')) { return; }
Remove dependency of RocketChat namespace inside rocketchat:ui (#13131) * Move rocketchat settings to specific package * WIP: Move models from rocketchat-lib to a specific package (server) * Move function from rocketchat:lib to rocketchat:utils to use it in rocketchat:models * Move client models from rocketchat:lib to rocketchat:models * Fix lint * Move rocketchat.info from lib to utils * Remove directly dependency between lib and migrations * Move statistics Model to rocketchat:models * Create rocketchat:metrics to be able to depacking rocketchat callbacks * Move callbacks to specific package * Remove unused dependency * Move rocketchat-notifications to a specific package * Move rocketchat-promises to a specific package * remove directly dependency from metrics and models * Move CachedCollection from lib to models * Move ui models/collections from ui to models * Move authorization client/ui models to rocketchat:models to be able to remove lib dependency * Creation of rocketchat:ui-utils to help decouple rocketchat:lib and rocketchat:authz * Move some common functions to rocketchat:utils * Change imports to dynamic imports to avoid directly dependency between some packages * Move authz models to rocketchat:models * Remove directly dependency between rocketchat:authz and rocketchat:lib * Move some functions from rocketchat:lib to rocketchat:utils * Add functions to settings package * Convert rocketchat:file-upload to main module structure * Import FileUpload where it is being used * Remove FileUpload and fileUploadHandler from globals eslintrc * Move some functions to rocketchat:ui-utils * Remove directly dependency between rocketchat:authorization and rocketchat:ui-utils * Remove dependency between lazy-load and lib * Change imports of renderMessageBody from ui-message to ui-utils * Add import of main ready from ui-utils * Convert rocketchat-ui-sidenav to main module structure * Add imports of toolbarSearch from ui-sidenav * Remove toolbarSearch from eslintrc globals * Move CachedCollection to a specific package * Change imports of CachedCollection to new package * Move some functions to rocketchat:ui-utils * Remove directly dependency between tooltip and lib * Remove directly dependency between settings and metrics * Move some settings client function from lib to settings * Convert rocketchat-ui-master to main module structure * Remove directly dependency between rocketchat:e2e and rocketchat:lib * Fix wrong import and lint * Convert rocketchat-webrtc to main module structure * Fix missing export * Remove directly dependency between rocketchat:emoji and lib * Add emoji dependencies inside RocketChat namespace * Merge branch 'develop' into globals/move-rocketchat-callbacks * Move some functions to utils * Fix lint * Move some ui functions to ui-utils * Fix import missed objects inside RocketChat namespace * Fix lint * Remove rocketchat:ui package dependency of RocketChat namespace * Remove lib dependency in rocketchat:ui-sidenav * Remove dependency between lib and ui-vrecord * Add logger dependency in file-upload * Revert commented test file
7 years ago
const blockEditInMinutes = settings.get('Message_AllowEditing_BlockEditInMinutes');
9 years ago
if (blockEditInMinutes && blockEditInMinutes !== 0) {
let currentTsDiff;
let msgTs;
if (message.ts != null) { msgTs = moment(message.ts); }
if (msgTs != null) { currentTsDiff = moment().diff(msgTs, 'minutes'); }
if (currentTsDiff > blockEditInMinutes) {
return;
}
}
const draft = this.getMessageDraft(message._id);
let msg = draft && draft.draft;
9 years ago
msg = msg || message.msg;
9 years ago
const editingNext = this.editing.index < index;
// const old_input = this.input.value;
this.clearEditing();
this.hasValue.set(true);
this.editing.element = element;
this.editing.index = index;
this.editing.id = message._id;
// TODO: stop set two elements
this.input.parentElement.classList.add('editing');
9 years ago
this.input.classList.add('editing');
element.classList.add('editing');
9 years ago
9 years ago
if (message.attachments && message.attachments[0].description) {
9 years ago
this.input.value = message.attachments[0].description;
} else {
this.input.value = msg;
}
8 years ago
$(this.input).trigger('change').trigger('input');
9 years ago
const cursor_pos = editingNext ? 0 : -1;
9 years ago
this.$input.setCursorPosition(cursor_pos);
this.input.focus();
return this.input;
9 years ago
}
clearEditing() {
if (this.editing.element) {
this.recordInputAsDraft();
// TODO: stop set two elements
this.input.classList.remove('editing');
this.input.parentElement.classList.remove('editing');
9 years ago
this.editing.element.classList.remove('editing');
delete this.editing.id;
delete this.editing.element;
delete this.editing.index;
this.input.value = this.editing.saved || '';
8 years ago
$(this.input).trigger('change').trigger('input');
9 years ago
const cursor_pos = this.editing.savedCursor != null ? this.editing.savedCursor : -1;
this.$input.setCursorPosition(cursor_pos);
return this.hasValue.set(this.input.value !== '');
}
this.editing.saved = this.input.value;
return this.editing.savedCursor = this.input.selectionEnd;
9 years ago
}
9 years ago
/**
* * @param {string} rim room ID
* * @param {Element} input DOM element
* * @param {function?} done callback
*/
async send(rid, input, done = function() {}) {
if (s.trim(input.value) !== '') {
9 years ago
readMessage.enable();
readMessage.readNow();
$('.message.first-unread').removeClass('first-unread');
let msg = '';
msg += await mountReply(msg, input);
msg += input.value;
$(input)
.removeData('reply')
.trigger('dataChange');
if (msg.slice(0, 2) === '+:') {
const reaction = msg.slice(1).trim();
Remove dependency of RocketChat namespace inside rocketchat:ui (#13131) * Move rocketchat settings to specific package * WIP: Move models from rocketchat-lib to a specific package (server) * Move function from rocketchat:lib to rocketchat:utils to use it in rocketchat:models * Move client models from rocketchat:lib to rocketchat:models * Fix lint * Move rocketchat.info from lib to utils * Remove directly dependency between lib and migrations * Move statistics Model to rocketchat:models * Create rocketchat:metrics to be able to depacking rocketchat callbacks * Move callbacks to specific package * Remove unused dependency * Move rocketchat-notifications to a specific package * Move rocketchat-promises to a specific package * remove directly dependency from metrics and models * Move CachedCollection from lib to models * Move ui models/collections from ui to models * Move authorization client/ui models to rocketchat:models to be able to remove lib dependency * Creation of rocketchat:ui-utils to help decouple rocketchat:lib and rocketchat:authz * Move some common functions to rocketchat:utils * Change imports to dynamic imports to avoid directly dependency between some packages * Move authz models to rocketchat:models * Remove directly dependency between rocketchat:authz and rocketchat:lib * Move some functions from rocketchat:lib to rocketchat:utils * Add functions to settings package * Convert rocketchat:file-upload to main module structure * Import FileUpload where it is being used * Remove FileUpload and fileUploadHandler from globals eslintrc * Move some functions to rocketchat:ui-utils * Remove directly dependency between rocketchat:authorization and rocketchat:ui-utils * Remove dependency between lazy-load and lib * Change imports of renderMessageBody from ui-message to ui-utils * Add import of main ready from ui-utils * Convert rocketchat-ui-sidenav to main module structure * Add imports of toolbarSearch from ui-sidenav * Remove toolbarSearch from eslintrc globals * Move CachedCollection to a specific package * Change imports of CachedCollection to new package * Move some functions to rocketchat:ui-utils * Remove directly dependency between tooltip and lib * Remove directly dependency between settings and metrics * Move some settings client function from lib to settings * Convert rocketchat-ui-master to main module structure * Remove directly dependency between rocketchat:e2e and rocketchat:lib * Fix wrong import and lint * Convert rocketchat-webrtc to main module structure * Fix missing export * Remove directly dependency between rocketchat:emoji and lib * Add emoji dependencies inside RocketChat namespace * Merge branch 'develop' into globals/move-rocketchat-callbacks * Move some functions to utils * Fix lint * Move some ui functions to ui-utils * Fix import missed objects inside RocketChat namespace * Fix lint * Remove rocketchat:ui package dependency of RocketChat namespace * Remove lib dependency in rocketchat:ui-sidenav * Remove dependency between lib and ui-vrecord * Add logger dependency in file-upload * Revert commented test file
7 years ago
if (emoji.list[reaction]) {
const lastMessage = ChatMessage.findOne({ rid }, { fields: { ts: 1 }, sort: { ts: -1 } });
Meteor.call('setReaction', reaction, lastMessage._id);
input.value = '';
8 years ago
$(input).trigger('change').trigger('input');
return;
}
}
9 years ago
9 years ago
// Run to allow local encryption, and maybe other client specific actions to be run before send
Remove dependency of RocketChat namespace inside rocketchat:ui (#13131) * Move rocketchat settings to specific package * WIP: Move models from rocketchat-lib to a specific package (server) * Move function from rocketchat:lib to rocketchat:utils to use it in rocketchat:models * Move client models from rocketchat:lib to rocketchat:models * Fix lint * Move rocketchat.info from lib to utils * Remove directly dependency between lib and migrations * Move statistics Model to rocketchat:models * Create rocketchat:metrics to be able to depacking rocketchat callbacks * Move callbacks to specific package * Remove unused dependency * Move rocketchat-notifications to a specific package * Move rocketchat-promises to a specific package * remove directly dependency from metrics and models * Move CachedCollection from lib to models * Move ui models/collections from ui to models * Move authorization client/ui models to rocketchat:models to be able to remove lib dependency * Creation of rocketchat:ui-utils to help decouple rocketchat:lib and rocketchat:authz * Move some common functions to rocketchat:utils * Change imports to dynamic imports to avoid directly dependency between some packages * Move authz models to rocketchat:models * Remove directly dependency between rocketchat:authz and rocketchat:lib * Move some functions from rocketchat:lib to rocketchat:utils * Add functions to settings package * Convert rocketchat:file-upload to main module structure * Import FileUpload where it is being used * Remove FileUpload and fileUploadHandler from globals eslintrc * Move some functions to rocketchat:ui-utils * Remove directly dependency between rocketchat:authorization and rocketchat:ui-utils * Remove dependency between lazy-load and lib * Change imports of renderMessageBody from ui-message to ui-utils * Add import of main ready from ui-utils * Convert rocketchat-ui-sidenav to main module structure * Add imports of toolbarSearch from ui-sidenav * Remove toolbarSearch from eslintrc globals * Move CachedCollection to a specific package * Change imports of CachedCollection to new package * Move some functions to rocketchat:ui-utils * Remove directly dependency between tooltip and lib * Remove directly dependency between settings and metrics * Move some settings client function from lib to settings * Convert rocketchat-ui-master to main module structure * Remove directly dependency between rocketchat:e2e and rocketchat:lib * Fix wrong import and lint * Convert rocketchat-webrtc to main module structure * Fix missing export * Remove directly dependency between rocketchat:emoji and lib * Add emoji dependencies inside RocketChat namespace * Merge branch 'develop' into globals/move-rocketchat-callbacks * Move some functions to utils * Fix lint * Move some ui functions to ui-utils * Fix import missed objects inside RocketChat namespace * Fix lint * Remove rocketchat:ui package dependency of RocketChat namespace * Remove lib dependency in rocketchat:ui-sidenav * Remove dependency between lib and ui-vrecord * Add logger dependency in file-upload * Revert commented test file
7 years ago
const msgObject = await promises.run('onClientBeforeSendMessage', { _id: Random.id(), rid, msg });
9 years ago
// checks for the final msgObject.msg size before actually sending the message
if (this.isMessageTooLong(msgObject.msg)) {
return toastr.error(t('Message_too_long'));
}
9 years ago
this.clearCurrentDraft();
9 years ago
if (this.editing.id) {
this.update(this.editing.id, rid, msgObject.msg);
return;
}
8 years ago
KonchatNotification.removeRoomNotification(rid);
input.value = '';
$(input).trigger('change').trigger('input');
if (typeof input.updateAutogrow === 'function') {
input.updateAutogrow();
}
this.hasValue.set(false);
this.stopTyping(rid);
if (this.processSlashCommand(msgObject)) {
return;
}
9 years ago
Meteor.call('sendMessage', msgObject);
this.saveTextMessageBox(rid, '');
return done();
9 years ago
9 years ago
// If edited message was emptied we ask for deletion
}
if (this.editing.element) {
9 years ago
const message = this.getMessageById(this.editing.id);
if (message.attachments && message.attachments[0] && message.attachments[0].description) {
return this.update(this.editing.id, rid, '', true);
}
9 years ago
// Restore original message in textbox in case delete is canceled
9 years ago
this.resetToDraft(this.editing.id);
return this.confirmDeleteMsg(message, done);
}
}
processSlashCommand(msgObject) {
// Check if message starts with /command
if (msgObject.msg[0] === '/') {
const match = msgObject.msg.match(/^\/([^\s]+)(?:\s+(.*))?$/m);
if (match) {
let command;
Remove dependency of RocketChat namespace inside rocketchat:ui (#13131) * Move rocketchat settings to specific package * WIP: Move models from rocketchat-lib to a specific package (server) * Move function from rocketchat:lib to rocketchat:utils to use it in rocketchat:models * Move client models from rocketchat:lib to rocketchat:models * Fix lint * Move rocketchat.info from lib to utils * Remove directly dependency between lib and migrations * Move statistics Model to rocketchat:models * Create rocketchat:metrics to be able to depacking rocketchat callbacks * Move callbacks to specific package * Remove unused dependency * Move rocketchat-notifications to a specific package * Move rocketchat-promises to a specific package * remove directly dependency from metrics and models * Move CachedCollection from lib to models * Move ui models/collections from ui to models * Move authorization client/ui models to rocketchat:models to be able to remove lib dependency * Creation of rocketchat:ui-utils to help decouple rocketchat:lib and rocketchat:authz * Move some common functions to rocketchat:utils * Change imports to dynamic imports to avoid directly dependency between some packages * Move authz models to rocketchat:models * Remove directly dependency between rocketchat:authz and rocketchat:lib * Move some functions from rocketchat:lib to rocketchat:utils * Add functions to settings package * Convert rocketchat:file-upload to main module structure * Import FileUpload where it is being used * Remove FileUpload and fileUploadHandler from globals eslintrc * Move some functions to rocketchat:ui-utils * Remove directly dependency between rocketchat:authorization and rocketchat:ui-utils * Remove dependency between lazy-load and lib * Change imports of renderMessageBody from ui-message to ui-utils * Add import of main ready from ui-utils * Convert rocketchat-ui-sidenav to main module structure * Add imports of toolbarSearch from ui-sidenav * Remove toolbarSearch from eslintrc globals * Move CachedCollection to a specific package * Change imports of CachedCollection to new package * Move some functions to rocketchat:ui-utils * Remove directly dependency between tooltip and lib * Remove directly dependency between settings and metrics * Move some settings client function from lib to settings * Convert rocketchat-ui-master to main module structure * Remove directly dependency between rocketchat:e2e and rocketchat:lib * Fix wrong import and lint * Convert rocketchat-webrtc to main module structure * Fix missing export * Remove directly dependency between rocketchat:emoji and lib * Add emoji dependencies inside RocketChat namespace * Merge branch 'develop' into globals/move-rocketchat-callbacks * Move some functions to utils * Fix lint * Move some ui functions to ui-utils * Fix import missed objects inside RocketChat namespace * Fix lint * Remove rocketchat:ui package dependency of RocketChat namespace * Remove lib dependency in rocketchat:ui-sidenav * Remove dependency between lib and ui-vrecord * Add logger dependency in file-upload * Revert commented test file
7 years ago
if (slashCommands.commands[match[1]]) {
const commandOptions = slashCommands.commands[match[1]];
command = match[1];
const param = match[2] || '';
Remove dependency of RocketChat namespace inside rocketchat:ui (#13131) * Move rocketchat settings to specific package * WIP: Move models from rocketchat-lib to a specific package (server) * Move function from rocketchat:lib to rocketchat:utils to use it in rocketchat:models * Move client models from rocketchat:lib to rocketchat:models * Fix lint * Move rocketchat.info from lib to utils * Remove directly dependency between lib and migrations * Move statistics Model to rocketchat:models * Create rocketchat:metrics to be able to depacking rocketchat callbacks * Move callbacks to specific package * Remove unused dependency * Move rocketchat-notifications to a specific package * Move rocketchat-promises to a specific package * remove directly dependency from metrics and models * Move CachedCollection from lib to models * Move ui models/collections from ui to models * Move authorization client/ui models to rocketchat:models to be able to remove lib dependency * Creation of rocketchat:ui-utils to help decouple rocketchat:lib and rocketchat:authz * Move some common functions to rocketchat:utils * Change imports to dynamic imports to avoid directly dependency between some packages * Move authz models to rocketchat:models * Remove directly dependency between rocketchat:authz and rocketchat:lib * Move some functions from rocketchat:lib to rocketchat:utils * Add functions to settings package * Convert rocketchat:file-upload to main module structure * Import FileUpload where it is being used * Remove FileUpload and fileUploadHandler from globals eslintrc * Move some functions to rocketchat:ui-utils * Remove directly dependency between rocketchat:authorization and rocketchat:ui-utils * Remove dependency between lazy-load and lib * Change imports of renderMessageBody from ui-message to ui-utils * Add import of main ready from ui-utils * Convert rocketchat-ui-sidenav to main module structure * Add imports of toolbarSearch from ui-sidenav * Remove toolbarSearch from eslintrc globals * Move CachedCollection to a specific package * Change imports of CachedCollection to new package * Move some functions to rocketchat:ui-utils * Remove directly dependency between tooltip and lib * Remove directly dependency between settings and metrics * Move some settings client function from lib to settings * Convert rocketchat-ui-master to main module structure * Remove directly dependency between rocketchat:e2e and rocketchat:lib * Fix wrong import and lint * Convert rocketchat-webrtc to main module structure * Fix missing export * Remove directly dependency between rocketchat:emoji and lib * Add emoji dependencies inside RocketChat namespace * Merge branch 'develop' into globals/move-rocketchat-callbacks * Move some functions to utils * Fix lint * Move some ui functions to ui-utils * Fix import missed objects inside RocketChat namespace * Fix lint * Remove rocketchat:ui package dependency of RocketChat namespace * Remove lib dependency in rocketchat:ui-sidenav * Remove dependency between lib and ui-vrecord * Add logger dependency in file-upload * Revert commented test file
7 years ago
if (!commandOptions.permission || hasAtLeastOnePermission(commandOptions.permission, Session.get('openedRoom'))) {
if (commandOptions.clientOnly) {
commandOptions.callback(command, param, msgObject);
} else {
Meteor.call('slashCommand', { cmd: command, params: param, msg: msgObject }, (err, result) => typeof commandOptions.result === 'function' && commandOptions.result(err, result, { cmd: command, params: param, msg: msgObject }));
}
return true;
}
}
Remove dependency of RocketChat namespace inside rocketchat:ui (#13131) * Move rocketchat settings to specific package * WIP: Move models from rocketchat-lib to a specific package (server) * Move function from rocketchat:lib to rocketchat:utils to use it in rocketchat:models * Move client models from rocketchat:lib to rocketchat:models * Fix lint * Move rocketchat.info from lib to utils * Remove directly dependency between lib and migrations * Move statistics Model to rocketchat:models * Create rocketchat:metrics to be able to depacking rocketchat callbacks * Move callbacks to specific package * Remove unused dependency * Move rocketchat-notifications to a specific package * Move rocketchat-promises to a specific package * remove directly dependency from metrics and models * Move CachedCollection from lib to models * Move ui models/collections from ui to models * Move authorization client/ui models to rocketchat:models to be able to remove lib dependency * Creation of rocketchat:ui-utils to help decouple rocketchat:lib and rocketchat:authz * Move some common functions to rocketchat:utils * Change imports to dynamic imports to avoid directly dependency between some packages * Move authz models to rocketchat:models * Remove directly dependency between rocketchat:authz and rocketchat:lib * Move some functions from rocketchat:lib to rocketchat:utils * Add functions to settings package * Convert rocketchat:file-upload to main module structure * Import FileUpload where it is being used * Remove FileUpload and fileUploadHandler from globals eslintrc * Move some functions to rocketchat:ui-utils * Remove directly dependency between rocketchat:authorization and rocketchat:ui-utils * Remove dependency between lazy-load and lib * Change imports of renderMessageBody from ui-message to ui-utils * Add import of main ready from ui-utils * Convert rocketchat-ui-sidenav to main module structure * Add imports of toolbarSearch from ui-sidenav * Remove toolbarSearch from eslintrc globals * Move CachedCollection to a specific package * Change imports of CachedCollection to new package * Move some functions to rocketchat:ui-utils * Remove directly dependency between tooltip and lib * Remove directly dependency between settings and metrics * Move some settings client function from lib to settings * Convert rocketchat-ui-master to main module structure * Remove directly dependency between rocketchat:e2e and rocketchat:lib * Fix wrong import and lint * Convert rocketchat-webrtc to main module structure * Fix missing export * Remove directly dependency between rocketchat:emoji and lib * Add emoji dependencies inside RocketChat namespace * Merge branch 'develop' into globals/move-rocketchat-callbacks * Move some functions to utils * Fix lint * Move some ui functions to ui-utils * Fix import missed objects inside RocketChat namespace * Fix lint * Remove rocketchat:ui package dependency of RocketChat namespace * Remove lib dependency in rocketchat:ui-sidenav * Remove dependency between lib and ui-vrecord * Add logger dependency in file-upload * Revert commented test file
7 years ago
if (!settings.get('Message_AllowUnrecognizedSlashCommand')) {
const invalidCommandMsg = {
_id: Random.id(),
rid: msgObject.rid,
ts: new Date,
msg: TAPi18n.__('No_such_command', { command: match[1] }),
u: {
Remove dependency of RocketChat namespace inside rocketchat:ui (#13131) * Move rocketchat settings to specific package * WIP: Move models from rocketchat-lib to a specific package (server) * Move function from rocketchat:lib to rocketchat:utils to use it in rocketchat:models * Move client models from rocketchat:lib to rocketchat:models * Fix lint * Move rocketchat.info from lib to utils * Remove directly dependency between lib and migrations * Move statistics Model to rocketchat:models * Create rocketchat:metrics to be able to depacking rocketchat callbacks * Move callbacks to specific package * Remove unused dependency * Move rocketchat-notifications to a specific package * Move rocketchat-promises to a specific package * remove directly dependency from metrics and models * Move CachedCollection from lib to models * Move ui models/collections from ui to models * Move authorization client/ui models to rocketchat:models to be able to remove lib dependency * Creation of rocketchat:ui-utils to help decouple rocketchat:lib and rocketchat:authz * Move some common functions to rocketchat:utils * Change imports to dynamic imports to avoid directly dependency between some packages * Move authz models to rocketchat:models * Remove directly dependency between rocketchat:authz and rocketchat:lib * Move some functions from rocketchat:lib to rocketchat:utils * Add functions to settings package * Convert rocketchat:file-upload to main module structure * Import FileUpload where it is being used * Remove FileUpload and fileUploadHandler from globals eslintrc * Move some functions to rocketchat:ui-utils * Remove directly dependency between rocketchat:authorization and rocketchat:ui-utils * Remove dependency between lazy-load and lib * Change imports of renderMessageBody from ui-message to ui-utils * Add import of main ready from ui-utils * Convert rocketchat-ui-sidenav to main module structure * Add imports of toolbarSearch from ui-sidenav * Remove toolbarSearch from eslintrc globals * Move CachedCollection to a specific package * Change imports of CachedCollection to new package * Move some functions to rocketchat:ui-utils * Remove directly dependency between tooltip and lib * Remove directly dependency between settings and metrics * Move some settings client function from lib to settings * Convert rocketchat-ui-master to main module structure * Remove directly dependency between rocketchat:e2e and rocketchat:lib * Fix wrong import and lint * Convert rocketchat-webrtc to main module structure * Fix missing export * Remove directly dependency between rocketchat:emoji and lib * Add emoji dependencies inside RocketChat namespace * Merge branch 'develop' into globals/move-rocketchat-callbacks * Move some functions to utils * Fix lint * Move some ui functions to ui-utils * Fix import missed objects inside RocketChat namespace * Fix lint * Remove rocketchat:ui package dependency of RocketChat namespace * Remove lib dependency in rocketchat:ui-sidenav * Remove dependency between lib and ui-vrecord * Add logger dependency in file-upload * Revert commented test file
7 years ago
username: settings.get('InternalHubot_Username'),
},
private: true,
};
ChatMessage.upsert({ _id: invalidCommandMsg._id }, invalidCommandMsg);
return true;
}
}
}
return false;
}
9 years ago
confirmDeleteMsg(message, done = function() {}) {
Remove dependency of RocketChat namespace inside rocketchat:ui (#13131) * Move rocketchat settings to specific package * WIP: Move models from rocketchat-lib to a specific package (server) * Move function from rocketchat:lib to rocketchat:utils to use it in rocketchat:models * Move client models from rocketchat:lib to rocketchat:models * Fix lint * Move rocketchat.info from lib to utils * Remove directly dependency between lib and migrations * Move statistics Model to rocketchat:models * Create rocketchat:metrics to be able to depacking rocketchat callbacks * Move callbacks to specific package * Remove unused dependency * Move rocketchat-notifications to a specific package * Move rocketchat-promises to a specific package * remove directly dependency from metrics and models * Move CachedCollection from lib to models * Move ui models/collections from ui to models * Move authorization client/ui models to rocketchat:models to be able to remove lib dependency * Creation of rocketchat:ui-utils to help decouple rocketchat:lib and rocketchat:authz * Move some common functions to rocketchat:utils * Change imports to dynamic imports to avoid directly dependency between some packages * Move authz models to rocketchat:models * Remove directly dependency between rocketchat:authz and rocketchat:lib * Move some functions from rocketchat:lib to rocketchat:utils * Add functions to settings package * Convert rocketchat:file-upload to main module structure * Import FileUpload where it is being used * Remove FileUpload and fileUploadHandler from globals eslintrc * Move some functions to rocketchat:ui-utils * Remove directly dependency between rocketchat:authorization and rocketchat:ui-utils * Remove dependency between lazy-load and lib * Change imports of renderMessageBody from ui-message to ui-utils * Add import of main ready from ui-utils * Convert rocketchat-ui-sidenav to main module structure * Add imports of toolbarSearch from ui-sidenav * Remove toolbarSearch from eslintrc globals * Move CachedCollection to a specific package * Change imports of CachedCollection to new package * Move some functions to rocketchat:ui-utils * Remove directly dependency between tooltip and lib * Remove directly dependency between settings and metrics * Move some settings client function from lib to settings * Convert rocketchat-ui-master to main module structure * Remove directly dependency between rocketchat:e2e and rocketchat:lib * Fix wrong import and lint * Convert rocketchat-webrtc to main module structure * Fix missing export * Remove directly dependency between rocketchat:emoji and lib * Add emoji dependencies inside RocketChat namespace * Merge branch 'develop' into globals/move-rocketchat-callbacks * Move some functions to utils * Fix lint * Move some ui functions to ui-utils * Fix import missed objects inside RocketChat namespace * Fix lint * Remove rocketchat:ui package dependency of RocketChat namespace * Remove lib dependency in rocketchat:ui-sidenav * Remove dependency between lib and ui-vrecord * Add logger dependency in file-upload * Revert commented test file
7 years ago
if (MessageTypes.isSystemMessage(message)) { return; }
const room = message.trid && Rooms.findOne({
_id: message.trid,
prid: { $exists: true },
});
modal.open({
9 years ago
title: t('Are_you_sure'),
text: room ? t('The_message_is_a_thread_you_will_not_be_able_to_recover') : t('You_will_not_be_able_to_recover'),
9 years ago
type: 'warning',
showCancelButton: true,
confirmButtonColor: '#DD6B55',
confirmButtonText: t('Yes_delete_it'),
cancelButtonText: t('Cancel'),
html: false,
9 years ago
}, () => {
modal.open({
9 years ago
title: t('Deleted'),
text: t('Your_entry_has_been_deleted'),
type: 'success',
timer: 1000,
showConfirmButton: false,
9 years ago
});
if (this.editing.id === message._id) {
this.clearEditing(message);
}
this.deleteMsg(message);
this.$input.focus();
return done();
});
}
deleteMsg(message) {
Remove dependency of RocketChat namespace inside rocketchat:ui (#13131) * Move rocketchat settings to specific package * WIP: Move models from rocketchat-lib to a specific package (server) * Move function from rocketchat:lib to rocketchat:utils to use it in rocketchat:models * Move client models from rocketchat:lib to rocketchat:models * Fix lint * Move rocketchat.info from lib to utils * Remove directly dependency between lib and migrations * Move statistics Model to rocketchat:models * Create rocketchat:metrics to be able to depacking rocketchat callbacks * Move callbacks to specific package * Remove unused dependency * Move rocketchat-notifications to a specific package * Move rocketchat-promises to a specific package * remove directly dependency from metrics and models * Move CachedCollection from lib to models * Move ui models/collections from ui to models * Move authorization client/ui models to rocketchat:models to be able to remove lib dependency * Creation of rocketchat:ui-utils to help decouple rocketchat:lib and rocketchat:authz * Move some common functions to rocketchat:utils * Change imports to dynamic imports to avoid directly dependency between some packages * Move authz models to rocketchat:models * Remove directly dependency between rocketchat:authz and rocketchat:lib * Move some functions from rocketchat:lib to rocketchat:utils * Add functions to settings package * Convert rocketchat:file-upload to main module structure * Import FileUpload where it is being used * Remove FileUpload and fileUploadHandler from globals eslintrc * Move some functions to rocketchat:ui-utils * Remove directly dependency between rocketchat:authorization and rocketchat:ui-utils * Remove dependency between lazy-load and lib * Change imports of renderMessageBody from ui-message to ui-utils * Add import of main ready from ui-utils * Convert rocketchat-ui-sidenav to main module structure * Add imports of toolbarSearch from ui-sidenav * Remove toolbarSearch from eslintrc globals * Move CachedCollection to a specific package * Change imports of CachedCollection to new package * Move some functions to rocketchat:ui-utils * Remove directly dependency between tooltip and lib * Remove directly dependency between settings and metrics * Move some settings client function from lib to settings * Convert rocketchat-ui-master to main module structure * Remove directly dependency between rocketchat:e2e and rocketchat:lib * Fix wrong import and lint * Convert rocketchat-webrtc to main module structure * Fix missing export * Remove directly dependency between rocketchat:emoji and lib * Add emoji dependencies inside RocketChat namespace * Merge branch 'develop' into globals/move-rocketchat-callbacks * Move some functions to utils * Fix lint * Move some ui functions to ui-utils * Fix import missed objects inside RocketChat namespace * Fix lint * Remove rocketchat:ui package dependency of RocketChat namespace * Remove lib dependency in rocketchat:ui-sidenav * Remove dependency between lib and ui-vrecord * Add logger dependency in file-upload * Revert commented test file
7 years ago
const forceDelete = hasAtLeastOnePermission('force-delete-message', message.rid);
const blockDeleteInMinutes = settings.get('Message_AllowDeleting_BlockDeleteInMinutes');
if (blockDeleteInMinutes && forceDelete === false) {
9 years ago
let msgTs;
if (message.ts != null) { msgTs = moment(message.ts); }
let currentTsDiff;
if (msgTs != null) { currentTsDiff = moment().diff(msgTs, 'minutes'); }
if (currentTsDiff > blockDeleteInMinutes) {
toastr.error(t('Message_deleting_blocked'));
return;
}
}
return Meteor.call('deleteMessage', { _id: message._id }, function(error) {
if (error) {
return handleError(error);
}
});
}
pinMsg(message) {
message.pinned = true;
return Meteor.call('pinMessage', message, function(error) {
if (error) {
return handleError(error);
}
});
}
unpinMsg(message) {
message.pinned = false;
return Meteor.call('unpinMessage', message, function(error) {
if (error) {
return handleError(error);
}
});
}
update(id, rid, msg, isDescription) {
if ((s.trim(msg) !== '') || (isDescription === true)) {
9 years ago
Meteor.call('updateMessage', { _id: id, msg, rid });
this.clearEditing();
return this.stopTyping(rid);
}
}
startTyping(rid, input) {
if (s.trim(input.value) === '') {
return this.stopTyping(rid);
9 years ago
}
return MsgTyping.start(rid);
9 years ago
}
stopTyping(rid) {
return MsgTyping.stop(rid);
}
bindEvents() {
9 years ago
if (this.wrapper && this.wrapper.length) {
$('.input-message').autogrow();
9 years ago
}
}
tryCompletion(input) {
const [value] = input.value.match(/[^\s]+$/) || [];
if (!value) { return; }
const re = new RegExp(value, 'i');
const user = Meteor.users.findOne({ username: re });
9 years ago
if (user) {
9 years ago
return input.value = input.value.replace(value, `@${ user.username } `);
}
}
insertNewLine(input) {
if (document.selection) {
input.focus();
const sel = document.selection.createRange();
sel.text = '\n';
} else if (input.selectionStart || input.selectionStart === 0) {
const newPosition = input.selectionStart + 1;
const before = input.value.substring(0, input.selectionStart);
const after = input.value.substring(input.selectionEnd, input.value.length);
input.value = `${ before }\n${ after }`;
input.selectionStart = input.selectionEnd = newPosition;
} else {
input.value += '\n';
}
input.blur();
input.focus();
typeof input.updateAutogrow === 'function' && input.updateAutogrow();
}
restoreText(rid) {
const text = localStorage.getItem(`messagebox_${ rid }`);
if (typeof text === 'string' && this.input) {
this.input.value = text;
this.$input.trigger('input');
}
const msgId = FlowRouter.getQueryParam('reply');
if (!msgId) {
return;
}
Remove dependency of RocketChat namespace inside rocketchat:ui (#13131) * Move rocketchat settings to specific package * WIP: Move models from rocketchat-lib to a specific package (server) * Move function from rocketchat:lib to rocketchat:utils to use it in rocketchat:models * Move client models from rocketchat:lib to rocketchat:models * Fix lint * Move rocketchat.info from lib to utils * Remove directly dependency between lib and migrations * Move statistics Model to rocketchat:models * Create rocketchat:metrics to be able to depacking rocketchat callbacks * Move callbacks to specific package * Remove unused dependency * Move rocketchat-notifications to a specific package * Move rocketchat-promises to a specific package * remove directly dependency from metrics and models * Move CachedCollection from lib to models * Move ui models/collections from ui to models * Move authorization client/ui models to rocketchat:models to be able to remove lib dependency * Creation of rocketchat:ui-utils to help decouple rocketchat:lib and rocketchat:authz * Move some common functions to rocketchat:utils * Change imports to dynamic imports to avoid directly dependency between some packages * Move authz models to rocketchat:models * Remove directly dependency between rocketchat:authz and rocketchat:lib * Move some functions from rocketchat:lib to rocketchat:utils * Add functions to settings package * Convert rocketchat:file-upload to main module structure * Import FileUpload where it is being used * Remove FileUpload and fileUploadHandler from globals eslintrc * Move some functions to rocketchat:ui-utils * Remove directly dependency between rocketchat:authorization and rocketchat:ui-utils * Remove dependency between lazy-load and lib * Change imports of renderMessageBody from ui-message to ui-utils * Add import of main ready from ui-utils * Convert rocketchat-ui-sidenav to main module structure * Add imports of toolbarSearch from ui-sidenav * Remove toolbarSearch from eslintrc globals * Move CachedCollection to a specific package * Change imports of CachedCollection to new package * Move some functions to rocketchat:ui-utils * Remove directly dependency between tooltip and lib * Remove directly dependency between settings and metrics * Move some settings client function from lib to settings * Convert rocketchat-ui-master to main module structure * Remove directly dependency between rocketchat:e2e and rocketchat:lib * Fix wrong import and lint * Convert rocketchat-webrtc to main module structure * Fix missing export * Remove directly dependency between rocketchat:emoji and lib * Add emoji dependencies inside RocketChat namespace * Merge branch 'develop' into globals/move-rocketchat-callbacks * Move some functions to utils * Fix lint * Move some ui functions to ui-utils * Fix import missed objects inside RocketChat namespace * Fix lint * Remove rocketchat:ui package dependency of RocketChat namespace * Remove lib dependency in rocketchat:ui-sidenav * Remove dependency between lib and ui-vrecord * Add logger dependency in file-upload * Revert commented test file
7 years ago
const message = Messages.findOne(msgId);
if (message) {
return this.$input.data('reply', message).trigger('dataChange');
}
Meteor.call('getSingleMessage', msgId, (err, msg) => !err && this.$input.data('reply', msg).trigger('dataChange'));
}
9 years ago
keyup(rid, event) {
let i;
const input = event.currentTarget;
const k = event.which;
const keyCodes = [
13, // Enter
20, // Caps lock
16, // Shift
9 years ago
9, // Tab
9 years ago
27, // Escape Key
17, // Control Key
91, // Windows Command Key
19, // Pause Break
18, // Alt Key
93, // Right Click Point Key
45, // Insert Key
34, // Page Down
35, // Page Up
144, // Num Lock
145, // Scroll Lock
9 years ago
];
for (i = 35; i <= 40; i++) { keyCodes.push(i); } // Home, End, Arrow Keys
for (i = 112; i <= 123; i++) { keyCodes.push(i); } // F1 - F12
if (!Array.from(keyCodes).includes(k)) {
this.startTyping(rid, input);
}
this.saveTextMessageBox(rid, input.value);
9 years ago
return this.hasValue.set(input.value !== '');
}
keydown(rid, event) {
const { currentTarget: input, which: k } = event;
9 years ago
if (k === 13 || k === 10) { // New line or carriage return
const sendOnEnterActive = sendOnEnter == null || sendOnEnter === 'normal' ||
(sendOnEnter === 'desktop' && Meteor.Device.isDesktop());
const withModifier = event.shiftKey || event.ctrlKey || event.altKey || event.metaKey;
const isSending = (sendOnEnterActive && !withModifier) || (!sendOnEnterActive && withModifier);
event.preventDefault();
event.stopPropagation();
if (isSending) {
this.send(rid, input);
} else {
this.insertNewLine(input);
9 years ago
}
return;
}
9 years ago
if (k === 9) { // Tab
event.preventDefault();
event.stopPropagation();
this.tryCompletion(input);
}
if (k === 27) { // Escape
if (this.editing.index != null) {
// const record = this.getMessageDraft(this.editing.id);
9 years ago
// If resetting did nothing then edited message is same as original
9 years ago
if (!this.resetToDraft(this.editing.id)) {
this.clearCurrentDraft();
this.clearEditing();
}
event.preventDefault();
event.stopPropagation();
return;
}
9 years ago
} else if (k === 38 || k === 40) { // Arrow Up or down
9 years ago
if (event.shiftKey) { return true; }
const cursor_pos = input.selectionEnd;
if (k === 38) { // Arrow Up
if (cursor_pos === 0) {
this.toPrevMessage();
} else if (!event.altKey) {
return true;
}
if (event.altKey) { this.$input.setCursorPosition(0); }
} else { // Arrow Down
if (cursor_pos === input.value.length) {
this.toNextMessage();
} else if (!event.altKey) {
return true;
}
if (event.altKey) { this.$input.setCursorPosition(-1); }
}
return false;
9 years ago
// ctrl (command) + shift + k -> clear room messages
9 years ago
}
9 years ago
// TODO
// else if (k === 75 && navigator && navigator.platform && event.shiftKey && (navigator.platform.indexOf('Mac') !== -1 ? event.metaKey : event.ctrlKey)) {
// return RoomHistoryManager.clear(rid);
// }
9 years ago
}
valueChanged(/* rid, event*/) {
9 years ago
if (this.input.value.length === 1) {
return this.determineInputDirection();
}
}
determineInputDirection() {
return this.input.dir = this.isMessageRtl(this.input.value) ? 'rtl' : 'ltr';
}
9 years ago
// http://stackoverflow.com/a/14824756
9 years ago
isMessageRtl(message) {
const ltrChars = 'A-Za-z\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u02B8\u0300-\u0590\u0800-\u1FFF\u2C00-\uFB1C\uFDFE-\uFE6F\uFEFD-\uFFFF';
const rtlChars = '\u0591-\u07FF\uFB1D-\uFDFD\uFE70-\uFEFC';
const rtlDirCheck = new RegExp(`^[^${ ltrChars }]*[${ rtlChars }]`);
return rtlDirCheck.test(message);
}
isMessageTooLong(message) {
Remove dependency of RocketChat namespace inside rocketchat:ui (#13131) * Move rocketchat settings to specific package * WIP: Move models from rocketchat-lib to a specific package (server) * Move function from rocketchat:lib to rocketchat:utils to use it in rocketchat:models * Move client models from rocketchat:lib to rocketchat:models * Fix lint * Move rocketchat.info from lib to utils * Remove directly dependency between lib and migrations * Move statistics Model to rocketchat:models * Create rocketchat:metrics to be able to depacking rocketchat callbacks * Move callbacks to specific package * Remove unused dependency * Move rocketchat-notifications to a specific package * Move rocketchat-promises to a specific package * remove directly dependency from metrics and models * Move CachedCollection from lib to models * Move ui models/collections from ui to models * Move authorization client/ui models to rocketchat:models to be able to remove lib dependency * Creation of rocketchat:ui-utils to help decouple rocketchat:lib and rocketchat:authz * Move some common functions to rocketchat:utils * Change imports to dynamic imports to avoid directly dependency between some packages * Move authz models to rocketchat:models * Remove directly dependency between rocketchat:authz and rocketchat:lib * Move some functions from rocketchat:lib to rocketchat:utils * Add functions to settings package * Convert rocketchat:file-upload to main module structure * Import FileUpload where it is being used * Remove FileUpload and fileUploadHandler from globals eslintrc * Move some functions to rocketchat:ui-utils * Remove directly dependency between rocketchat:authorization and rocketchat:ui-utils * Remove dependency between lazy-load and lib * Change imports of renderMessageBody from ui-message to ui-utils * Add import of main ready from ui-utils * Convert rocketchat-ui-sidenav to main module structure * Add imports of toolbarSearch from ui-sidenav * Remove toolbarSearch from eslintrc globals * Move CachedCollection to a specific package * Change imports of CachedCollection to new package * Move some functions to rocketchat:ui-utils * Remove directly dependency between tooltip and lib * Remove directly dependency between settings and metrics * Move some settings client function from lib to settings * Convert rocketchat-ui-master to main module structure * Remove directly dependency between rocketchat:e2e and rocketchat:lib * Fix wrong import and lint * Convert rocketchat-webrtc to main module structure * Fix missing export * Remove directly dependency between rocketchat:emoji and lib * Add emoji dependencies inside RocketChat namespace * Merge branch 'develop' into globals/move-rocketchat-callbacks * Move some functions to utils * Fix lint * Move some ui functions to ui-utils * Fix import missed objects inside RocketChat namespace * Fix lint * Remove rocketchat:ui package dependency of RocketChat namespace * Remove lib dependency in rocketchat:ui-sidenav * Remove dependency between lib and ui-vrecord * Add logger dependency in file-upload * Revert commented test file
7 years ago
const adjustedMessage = messageProperties.messageWithoutEmojiShortnames(message);
return messageProperties.length(adjustedMessage) > this.messageMaxSize && message;
9 years ago
}
isEmpty() {
return !this.hasValue.get();
}
};
Remove dependency of RocketChat namespace inside rocketchat:ui (#13131) * Move rocketchat settings to specific package * WIP: Move models from rocketchat-lib to a specific package (server) * Move function from rocketchat:lib to rocketchat:utils to use it in rocketchat:models * Move client models from rocketchat:lib to rocketchat:models * Fix lint * Move rocketchat.info from lib to utils * Remove directly dependency between lib and migrations * Move statistics Model to rocketchat:models * Create rocketchat:metrics to be able to depacking rocketchat callbacks * Move callbacks to specific package * Remove unused dependency * Move rocketchat-notifications to a specific package * Move rocketchat-promises to a specific package * remove directly dependency from metrics and models * Move CachedCollection from lib to models * Move ui models/collections from ui to models * Move authorization client/ui models to rocketchat:models to be able to remove lib dependency * Creation of rocketchat:ui-utils to help decouple rocketchat:lib and rocketchat:authz * Move some common functions to rocketchat:utils * Change imports to dynamic imports to avoid directly dependency between some packages * Move authz models to rocketchat:models * Remove directly dependency between rocketchat:authz and rocketchat:lib * Move some functions from rocketchat:lib to rocketchat:utils * Add functions to settings package * Convert rocketchat:file-upload to main module structure * Import FileUpload where it is being used * Remove FileUpload and fileUploadHandler from globals eslintrc * Move some functions to rocketchat:ui-utils * Remove directly dependency between rocketchat:authorization and rocketchat:ui-utils * Remove dependency between lazy-load and lib * Change imports of renderMessageBody from ui-message to ui-utils * Add import of main ready from ui-utils * Convert rocketchat-ui-sidenav to main module structure * Add imports of toolbarSearch from ui-sidenav * Remove toolbarSearch from eslintrc globals * Move CachedCollection to a specific package * Change imports of CachedCollection to new package * Move some functions to rocketchat:ui-utils * Remove directly dependency between tooltip and lib * Remove directly dependency between settings and metrics * Move some settings client function from lib to settings * Convert rocketchat-ui-master to main module structure * Remove directly dependency between rocketchat:e2e and rocketchat:lib * Fix wrong import and lint * Convert rocketchat-webrtc to main module structure * Fix missing export * Remove directly dependency between rocketchat:emoji and lib * Add emoji dependencies inside RocketChat namespace * Merge branch 'develop' into globals/move-rocketchat-callbacks * Move some functions to utils * Fix lint * Move some ui functions to ui-utils * Fix import missed objects inside RocketChat namespace * Fix lint * Remove rocketchat:ui package dependency of RocketChat namespace * Remove lib dependency in rocketchat:ui-sidenav * Remove dependency between lib and ui-vrecord * Add logger dependency in file-upload * Revert commented test file
7 years ago
callbacks.add('afterLogoutCleanUp', () => {
Object.keys(localStorage).forEach((item) => {
if (item.indexOf('messagebox_') === 0) {
localStorage.removeItem(item);
}
});
Remove dependency of RocketChat namespace inside rocketchat:ui (#13131) * Move rocketchat settings to specific package * WIP: Move models from rocketchat-lib to a specific package (server) * Move function from rocketchat:lib to rocketchat:utils to use it in rocketchat:models * Move client models from rocketchat:lib to rocketchat:models * Fix lint * Move rocketchat.info from lib to utils * Remove directly dependency between lib and migrations * Move statistics Model to rocketchat:models * Create rocketchat:metrics to be able to depacking rocketchat callbacks * Move callbacks to specific package * Remove unused dependency * Move rocketchat-notifications to a specific package * Move rocketchat-promises to a specific package * remove directly dependency from metrics and models * Move CachedCollection from lib to models * Move ui models/collections from ui to models * Move authorization client/ui models to rocketchat:models to be able to remove lib dependency * Creation of rocketchat:ui-utils to help decouple rocketchat:lib and rocketchat:authz * Move some common functions to rocketchat:utils * Change imports to dynamic imports to avoid directly dependency between some packages * Move authz models to rocketchat:models * Remove directly dependency between rocketchat:authz and rocketchat:lib * Move some functions from rocketchat:lib to rocketchat:utils * Add functions to settings package * Convert rocketchat:file-upload to main module structure * Import FileUpload where it is being used * Remove FileUpload and fileUploadHandler from globals eslintrc * Move some functions to rocketchat:ui-utils * Remove directly dependency between rocketchat:authorization and rocketchat:ui-utils * Remove dependency between lazy-load and lib * Change imports of renderMessageBody from ui-message to ui-utils * Add import of main ready from ui-utils * Convert rocketchat-ui-sidenav to main module structure * Add imports of toolbarSearch from ui-sidenav * Remove toolbarSearch from eslintrc globals * Move CachedCollection to a specific package * Change imports of CachedCollection to new package * Move some functions to rocketchat:ui-utils * Remove directly dependency between tooltip and lib * Remove directly dependency between settings and metrics * Move some settings client function from lib to settings * Convert rocketchat-ui-master to main module structure * Remove directly dependency between rocketchat:e2e and rocketchat:lib * Fix wrong import and lint * Convert rocketchat-webrtc to main module structure * Fix missing export * Remove directly dependency between rocketchat:emoji and lib * Add emoji dependencies inside RocketChat namespace * Merge branch 'develop' into globals/move-rocketchat-callbacks * Move some functions to utils * Fix lint * Move some ui functions to ui-utils * Fix import missed objects inside RocketChat namespace * Fix lint * Remove rocketchat:ui package dependency of RocketChat namespace * Remove lib dependency in rocketchat:ui-sidenav * Remove dependency between lib and ui-vrecord * Add logger dependency in file-upload * Revert commented test file
7 years ago
}, callbacks.priority.MEDIUM, 'chatMessages-after-logout-cleanup');