diff --git a/packages/rocketchat-ui-message/client/message.coffee b/packages/rocketchat-ui-message/client/message.coffee deleted file mode 100644 index 2684dfd9c0a..00000000000 --- a/packages/rocketchat-ui-message/client/message.coffee +++ /dev/null @@ -1,254 +0,0 @@ -import moment from 'moment' - -Template.message.helpers - encodeURI: (text) -> - return encodeURI(text) - isBot: -> - return 'bot' if this.bot? - roleTags: -> - if not RocketChat.settings.get('UI_DisplayRoles') or Meteor.user()?.settings?.preferences?.hideRoles - return [] - roles = _.union(UserRoles.findOne(this.u?._id)?.roles, RoomRoles.findOne({'u._id': this.u?._id, rid: this.rid })?.roles) - return RocketChat.models.Roles.find({ _id: { $in: roles }, description: { $exists: 1, $ne: '' } }, { fields: { description: 1 } }) - isGroupable: -> - return 'false' if this.groupable is false - isSequential: -> - return 'sequential' if this.groupable isnt false - avatarFromUsername: -> - if this.avatar? and this.avatar[0] is '@' - return this.avatar.replace(/^@/, '') - getEmoji: (emoji) -> - return renderEmoji emoji - getName: -> - if this.alias - return this.alias - if RocketChat.settings.get('UI_Use_Real_Name') and this.u?.name - return this.u.name - return this.u?.username - showUsername: -> - return this.alias or (RocketChat.settings.get('UI_Use_Real_Name') and this.u?.name) - own: -> - return 'own' if this.u?._id is Meteor.userId() - timestamp: -> - return +this.ts - chatops: -> - return 'chatops-message' if this.u?.username is RocketChat.settings.get('Chatops_Username') - time: -> - return moment(this.ts).format(RocketChat.settings.get('Message_TimeFormat')) - date: -> - return moment(this.ts).format(RocketChat.settings.get('Message_DateFormat')) - isTemp: -> - if @temp is true - return 'temp' - body: -> - return Template.instance().body - system: (returnClass) -> - if RocketChat.MessageTypes.isSystemMessage(this) - if returnClass - return 'color-info-font-color' - - return 'system' - - showTranslated: -> - if RocketChat.settings.get('AutoTranslate_Enabled') and this.u?._id isnt Meteor.userId() and !RocketChat.MessageTypes.isSystemMessage(this) - subscription = RocketChat.models.Subscriptions.findOne({ rid: this.rid, 'u._id': Meteor.userId() }, { fields: { autoTranslate: 1, autoTranslateLanguage: 1 } }); - language = RocketChat.AutoTranslate.getLanguage(this.rid); - return this.autoTranslateFetching || (subscription?.autoTranslate isnt this.autoTranslateShowInverse && this.translations && this.translations[language]) # || _.find(this.attachments, (attachment) -> attachment.translations && attachment.translations[language] && attachment.author_name isnt Meteor.user().username ) - - edited: -> - return Template.instance().wasEdited - - editTime: -> - if Template.instance().wasEdited - return moment(@editedAt).format(RocketChat.settings.get('Message_DateFormat') + ' ' + RocketChat.settings.get('Message_TimeFormat')) - editedBy: -> - return "" unless Template.instance().wasEdited - # try to return the username of the editor, - # otherwise a special "?" character that will be - # rendered as a special avatar - return @editedBy?.username or "?" - canEdit: -> - hasPermission = RocketChat.authz.hasAtLeastOnePermission('edit-message', this.rid) - isEditAllowed = RocketChat.settings.get 'Message_AllowEditing' - editOwn = this.u?._id is Meteor.userId() - - return unless hasPermission or (isEditAllowed and editOwn) - - blockEditInMinutes = RocketChat.settings.get 'Message_AllowEditing_BlockEditInMinutes' - if blockEditInMinutes? and blockEditInMinutes isnt 0 - msgTs = moment(this.ts) if this.ts? - currentTsDiff = moment().diff(msgTs, 'minutes') if msgTs? - return currentTsDiff < blockEditInMinutes - else - return true - - canDelete: -> - hasPermission = RocketChat.authz.hasAtLeastOnePermission('delete-message', this.rid ) - isDeleteAllowed = RocketChat.settings.get('Message_AllowDeleting') - deleteOwn = this.u?._id is Meteor.userId() - - return unless hasPermission or (isDeleteAllowed and deleteOwn) - - blockDeleteInMinutes = RocketChat.settings.get 'Message_AllowDeleting_BlockDeleteInMinutes' - if blockDeleteInMinutes? and blockDeleteInMinutes isnt 0 - msgTs = moment(this.ts) if this.ts? - currentTsDiff = moment().diff(msgTs, 'minutes') if msgTs? - return currentTsDiff < blockDeleteInMinutes - else - return true - - showEditedStatus: -> - return RocketChat.settings.get 'Message_ShowEditedStatus' - label: -> - if @i18nLabel - return t(@i18nLabel) - else if @label - return @label - - hasOembed: -> - return false unless this.urls?.length > 0 and Template.oembedBaseWidget? and RocketChat.settings.get 'API_Embed' - - return false unless this.u?.username not in RocketChat.settings.get('API_EmbedDisabledFor')?.split(',').map (username) -> username.trim() - - return true - - reactions: -> - msgReactions = [] - userUsername = Meteor.user()?.username - - for emoji, reaction of @reactions - total = reaction.usernames.length - usernames = '@' + reaction.usernames.slice(0, 15).join(', @') - - usernames = usernames.replace('@'+userUsername, t('You').toLowerCase()) - - if total > 15 - usernames = usernames + ' ' + t('And_more', { length: total - 15 }).toLowerCase() - else - usernames = usernames.replace(/,([^,]+)$/, ' '+t('and')+'$1') - - if usernames[0] isnt '@' - usernames = usernames[0].toUpperCase() + usernames.substr(1) - - msgReactions.push - emoji: emoji - count: reaction.usernames.length - usernames: usernames - reaction: ' ' + t('Reacted_with').toLowerCase() + ' ' + emoji - userReacted: reaction.usernames.indexOf(userUsername) > -1 - - return msgReactions - - markUserReaction: (reaction) -> - if reaction.userReacted - return { - class: 'selected' - } - - hideReactions: -> - return 'hidden' if _.isEmpty(@reactions) - - actionLinks: -> - # remove 'method_id' and 'params' properties - return _.map(@actionLinks, (actionLink, key) -> _.extend({ id: key }, _.omit(actionLink, 'method_id', 'params'))) - - hideActionLinks: -> - return 'hidden' if _.isEmpty(@actionLinks) - - injectIndex: (data, index) -> - data.index = index - return - - hideCog: -> - subscription = RocketChat.models.Subscriptions.findOne({ rid: this.rid }); - return 'hidden' if not subscription? - - hideUsernames: -> - prefs = Meteor.user()?.settings?.preferences - return if prefs?.hideUsernames - -Template.message.onCreated -> - msg = Template.currentData() - - @wasEdited = msg.editedAt? and not RocketChat.MessageTypes.isSystemMessage(msg) - - @body = do -> - isSystemMessage = RocketChat.MessageTypes.isSystemMessage(msg) - messageType = RocketChat.MessageTypes.getType(msg) - if messageType?.render? - msg = messageType.render(msg) - else if messageType?.template? - # render template - else if messageType?.message? - if messageType.data?(msg)? - msg = TAPi18n.__(messageType.message, messageType.data(msg)) - else - msg = TAPi18n.__(messageType.message) - else - if msg.u?.username is RocketChat.settings.get('Chatops_Username') - msg.html = msg.msg - msg = RocketChat.callbacks.run 'renderMentions', msg - # console.log JSON.stringify message - msg = msg.html - else - msg = renderMessageBody msg - - if isSystemMessage - msg.html = RocketChat.Markdown.parse msg.html - - return msg - -Template.message.onViewRendered = (context) -> - view = this - this._domrange.onAttached (domRange) -> - currentNode = domRange.lastNode() - currentDataset = currentNode.dataset - previousNode = currentNode.previousElementSibling - nextNode = currentNode.nextElementSibling - $currentNode = $(currentNode) - $nextNode = $(nextNode) - - unless previousNode? - $currentNode.addClass('new-day').removeClass('sequential') - - else if previousNode?.dataset? - previousDataset = previousNode.dataset - previousMessageDate = new Date(parseInt(previousDataset.timestamp)) - currentMessageDate = new Date(parseInt(currentDataset.timestamp)) - - if previousMessageDate.toDateString() isnt currentMessageDate.toDateString() - $currentNode.addClass('new-day').removeClass('sequential') - else - $currentNode.removeClass('new-day') - - if previousDataset.groupable is 'false' or currentDataset.groupable is 'false' - $currentNode.removeClass('sequential') - else - if previousDataset.username isnt currentDataset.username or parseInt(currentDataset.timestamp) - parseInt(previousDataset.timestamp) > RocketChat.settings.get('Message_GroupingPeriod') * 1000 - $currentNode.removeClass('sequential') - else if not $currentNode.hasClass 'new-day' - $currentNode.addClass('sequential') - - if nextNode?.dataset? - nextDataset = nextNode.dataset - - if nextDataset.date isnt currentDataset.date - $nextNode.addClass('new-day').removeClass('sequential') - else - $nextNode.removeClass('new-day') - - if nextDataset.groupable isnt 'false' - if nextDataset.username isnt currentDataset.username or parseInt(nextDataset.timestamp) - parseInt(currentDataset.timestamp) > RocketChat.settings.get('Message_GroupingPeriod') * 1000 - $nextNode.removeClass('sequential') - else if not $nextNode.hasClass 'new-day' - $nextNode.addClass('sequential') - - if not nextNode? - templateInstance = if $('#chat-window-' + context.rid)[0] then Blaze.getView($('#chat-window-' + context.rid)[0])?.templateInstance() else null - - if currentNode.classList.contains('own') is true - templateInstance?.atBottom = true - else - if templateInstance?.firstNode && templateInstance?.atBottom is false - newMessage = templateInstance?.find(".new-message") - newMessage?.className = "new-message background-primary-action-color color-content-background-color " diff --git a/packages/rocketchat-ui-message/client/message.js b/packages/rocketchat-ui-message/client/message.js index 9129677d94f..ae7997d5830 100644 --- a/packages/rocketchat-ui-message/client/message.js +++ b/packages/rocketchat-ui-message/client/message.js @@ -1,6 +1,10 @@ +/* globals renderEmoji renderMessageBody*/ import moment from 'moment'; Template.message.helpers({ + encodeURI(text) { + return encodeURI(text); + }, isBot() { if (this.bot != null) { return 'bot'; @@ -103,8 +107,8 @@ Template.message.helpers({ } }, showTranslated() { - if (RocketChat.settings.get('AutoTranslate_Enabled') && ((ref = this.u) != null ? ref._id : void 0) !== Meteor.userId() && !RocketChat.MessageTypes.isSystemMessage(this)) { - subscription = RocketChat.models.Subscriptions.findOne({ + if (RocketChat.settings.get('AutoTranslate_Enabled') && this.u && this.u._id !== Meteor.userId() && !RocketChat.MessageTypes.isSystemMessage(this)) { + const subscription = RocketChat.models.Subscriptions.findOne({ rid: this.rid, 'u._id': Meteor.userId() }, { @@ -114,7 +118,7 @@ Template.message.helpers({ } }); const language = RocketChat.AutoTranslate.getLanguage(this.rid); - return this.autoTranslateFetching || ((subscription != null ? subscription.autoTranslate : void 0) !== this.autoTranslateShowInverse && this.translations && this.translations[language]); + return this.autoTranslateFetching || subscription && subscription.autoTranslate !== this.autoTranslateShowInverse && this.translations && this.translations[language]; } }, edited() { @@ -137,15 +141,17 @@ Template.message.helpers({ canEdit() { const hasPermission = RocketChat.authz.hasAtLeastOnePermission('edit-message', this.rid); const isEditAllowed = RocketChat.settings.get('Message_AllowEditing'); - const editOwn = ((ref = this.u) != null ? ref._id : void 0) === Meteor.userId(); + const editOwn = this.u && this.u._id === Meteor.userId(); if (!(hasPermission || (isEditAllowed && editOwn))) { return; } const blockEditInMinutes = RocketChat.settings.get('Message_AllowEditing_BlockEditInMinutes'); - if ((blockEditInMinutes != null) && blockEditInMinutes !== 0) { + if (blockEditInMinutes) { + let msgTs; if (this.ts != null) { msgTs = moment(this.ts); } + let currentTsDiff; if (msgTs != null) { currentTsDiff = moment().diff(msgTs, 'minutes'); } @@ -155,18 +161,19 @@ Template.message.helpers({ } }, canDelete() { - let blockDeleteInMinutes, currentTsDiff, deleteOwn, hasPermission, isDeleteAllowed, msgTs, ref; - hasPermission = RocketChat.authz.hasAtLeastOnePermission('delete-message', this.rid); - isDeleteAllowed = RocketChat.settings.get('Message_AllowDeleting'); - deleteOwn = ((ref = this.u) != null ? ref._id : void 0) === Meteor.userId(); + const hasPermission = RocketChat.authz.hasAtLeastOnePermission('delete-message', this.rid); + const isDeleteAllowed = RocketChat.settings.get('Message_AllowDeleting'); + const deleteOwn = this.u && this.u._id === Meteor.userId(); if (!(hasPermission || (isDeleteAllowed && deleteOwn))) { return; } - blockDeleteInMinutes = RocketChat.settings.get('Message_AllowDeleting_BlockDeleteInMinutes'); - if ((blockDeleteInMinutes != null) && blockDeleteInMinutes !== 0) { + const blockDeleteInMinutes = RocketChat.settings.get('Message_AllowDeleting_BlockDeleteInMinutes'); + if (blockDeleteInMinutes) { + let msgTs; if (this.ts != null) { msgTs = moment(this.ts); } + let currentTsDiff; if (msgTs != null) { currentTsDiff = moment().diff(msgTs, 'minutes'); } @@ -186,27 +193,20 @@ Template.message.helpers({ } }, hasOembed() { - let ref, ref1, ref2, ref3; - if (!(((ref = this.urls) != null ? ref.length : void 0) > 0 && (Template.oembedBaseWidget != null) && RocketChat.settings.get('API_Embed'))) { + if (!(this.urls && this.urls.length > 0 && Template.oembedBaseWidget != null && RocketChat.settings.get('API_Embed'))) { return false; } - if (ref1 = (ref2 = this.u) != null ? ref2.username : void 0, indexOf.call((ref3 = RocketChat.settings.get('API_EmbedDisabledFor')) != null ? ref3.split(',').map(function(username) { - return username.trim(); - }) : void 0, ref1) >= 0) { + if (!(RocketChat.settings.get('API_EmbedDisabledFor')||'').split(',').map(username => username.trim()).includes(this.u && this.u.username)) { return false; } return true; }, reactions() { - let emoji, msgReactions, reaction, ref, total, userUsername, usernames; - msgReactions = []; - userUsername = Meteor.user().username; - ref = this.reactions; - for (emoji in ref) { - reaction = ref[emoji]; - total = reaction.usernames.length; - usernames = `@${ reaction.usernames.slice(0, 15).join(', @') }`; - usernames = usernames.replace(`@${ userUsername }`, t('You').toLowerCase()); + const userUsername = Meteor.user().username; + return Object.keys(this.reactions||{}).map(emoji => { + const reaction = this.reactions[emoji]; + const total = reaction.usernames.length; + let usernames = `@${ reaction.usernames.slice(0, 15).join(', @') }`.replace(`@${ userUsername }`, t('You').toLowerCase()); if (total > 15) { usernames = `${ usernames } ${ t('And_more', { length: total - 15 @@ -217,15 +217,14 @@ Template.message.helpers({ if (usernames[0] !== '@') { usernames = usernames[0].toUpperCase() + usernames.substr(1); } - msgReactions.push({ + return { emoji, count: reaction.usernames.length, usernames, reaction: ` ${ t('Reacted_with').toLowerCase() } ${ emoji }`, userReacted: reaction.usernames.indexOf(userUsername) > -1 - }); - } - return msgReactions; + }; + }); }, markUserReaction(reaction) { if (reaction.userReacted) { @@ -256,73 +255,63 @@ Template.message.helpers({ data.index = index; }, hideCog() { - let subscription; - subscription = RocketChat.models.Subscriptions.findOne({ + const subscription = RocketChat.models.Subscriptions.findOne({ rid: this.rid }); if (subscription == null) { return 'hidden'; } - }, - hideUsernames() { - let prefs, ref, ref1; - prefs = (ref = Meteor.user()) != null ? (ref1 = ref.settings) != null ? ref1.preferences : void 0 : void 0; - if (prefs != null ? prefs.hideUsernames : void 0) { - - } } }); Template.message.onCreated(function() { - let msg; - msg = Template.currentData(); + let msg = Template.currentData(); + this.wasEdited = (msg.editedAt != null) && !RocketChat.MessageTypes.isSystemMessage(msg); - return this.body = (function() { - let isSystemMessage, messageType, ref; - isSystemMessage = RocketChat.MessageTypes.isSystemMessage(msg); - messageType = RocketChat.MessageTypes.getType(msg); - if ((messageType != null ? messageType.render : void 0) != null) { - msg = messageType.render(msg); - } else if ((messageType != null ? messageType.template : void 0) != null) { - } else if ((messageType != null ? messageType.message : void 0) != null) { - if ((typeof messageType.data === 'function' ? messageType.data(msg) : void 0) != null) { + return this.body = (() => { + const isSystemMessage = RocketChat.MessageTypes.isSystemMessage(msg); + const messageType = RocketChat.MessageTypes.getType(msg)||{}; + if (messageType.render) { + msg = messageType.render(msg); + } else if (messageType.template) { + // render template + } else if (messageType.message) { + if (typeof messageType.data === 'function' && messageType.data(msg)) { msg = TAPi18n.__(messageType.message, messageType.data(msg)); } else { msg = TAPi18n.__(messageType.message); } - } else if (((ref = msg.u) != null ? ref.username : void 0) === RocketChat.settings.get('Chatops_Username')) { + } else if (msg.u && msg.u.username === RocketChat.settings.get('Chatops_Username')) { msg.html = msg.msg; msg = RocketChat.callbacks.run('renderMentions', msg); + // console.log JSON.stringify message msg = msg.html; } else { msg = renderMessageBody(msg); } + if (isSystemMessage) { - return RocketChat.Markdown(msg); - } else { - return msg; + msg.html = RocketChat.Markdown.parse(msg.html); } - }()); + return msg; + })(); }); Template.message.onViewRendered = function(context) { - let view; - view = this; return this._domrange.onAttached(function(domRange) { - let $currentNode, $nextNode, currentDataset, currentMessageDate, currentNode, newMessage, nextDataset, nextNode, previousDataset, previousMessageDate, previousNode, ref, templateInstance; - currentNode = domRange.lastNode(); - currentDataset = currentNode.dataset; - previousNode = currentNode.previousElementSibling; - nextNode = currentNode.nextElementSibling; - $currentNode = $(currentNode); - $nextNode = $(nextNode); + const currentNode = domRange.lastNode(); + const currentDataset = currentNode.dataset; + const previousNode = currentNode.previousElementSibling; + const nextNode = currentNode.nextElementSibling; + const $currentNode = $(currentNode); + const $nextNode = $(nextNode); if (previousNode == null) { $currentNode.addClass('new-day').removeClass('sequential'); - } else if ((previousNode != null ? previousNode.dataset : void 0) != null) { - previousDataset = previousNode.dataset; - previousMessageDate = new Date(parseInt(previousDataset.timestamp)); - currentMessageDate = new Date(parseInt(currentDataset.timestamp)); + } else if (previousNode.dataset) { + const previousDataset = previousNode.dataset; + const previousMessageDate = new Date(parseInt(previousDataset.timestamp)); + const currentMessageDate = new Date(parseInt(currentDataset.timestamp)); if (previousMessageDate.toDateString() !== currentMessageDate.toDateString()) { $currentNode.addClass('new-day').removeClass('sequential'); } else { @@ -336,8 +325,8 @@ Template.message.onViewRendered = function(context) { $currentNode.addClass('sequential'); } } - if ((nextNode != null ? nextNode.dataset : void 0) != null) { - nextDataset = nextNode.dataset; + if (nextNode && nextNode.dataset) { + const nextDataset = nextNode.dataset; if (nextDataset.date !== currentDataset.date) { $nextNode.addClass('new-day').removeClass('sequential'); } else { @@ -352,12 +341,17 @@ Template.message.onViewRendered = function(context) { } } if (nextNode == null) { - templateInstance = $(`#chat-window-${ context.rid }`)[0] ? (ref = Blaze.getView($(`#chat-window-${ context.rid }`)[0])) != null ? ref.templateInstance() : void 0 : null; + const [el] = $(`#chat-window-${ context.rid }`); + const view = el && Blaze.getView(el); + const templateInstance = view && view.templateInstance(); + if (!templateInstance) { + return; + } if (currentNode.classList.contains('own') === true) { - return templateInstance != null ? templateInstance.atBottom = true : void 0; - } else if ((templateInstance != null ? templateInstance.firstNode : void 0) && (templateInstance != null ? templateInstance.atBottom : void 0) === false) { - newMessage = templateInstance != null ? templateInstance.find('.new-message') : void 0; - return newMessage != null ? newMessage.className = 'new-message background-primary-action-color color-content-background-color ' : void 0; + return (templateInstance.atBottom = true); + } else if (templateInstance.firstNode && templateInstance.atBottom === false) { + const newMessage = templateInstance.find('.new-message'); + return newMessage && (newMessage.className = 'new-message background-primary-action-color color-content-background-color '); } } }); diff --git a/packages/rocketchat-ui-message/client/messageBox.coffee b/packages/rocketchat-ui-message/client/messageBox.coffee deleted file mode 100644 index 2587fda0c30..00000000000 --- a/packages/rocketchat-ui-message/client/messageBox.coffee +++ /dev/null @@ -1,391 +0,0 @@ -import toastr from 'toastr' -import mime from 'mime-type/with-db' -import moment from 'moment' -import {VRecDialog} from 'meteor/rocketchat:ui-vrecord' - -katexSyntax = -> - if RocketChat.katex.katex_enabled() - return "$$KaTeX$$" if RocketChat.katex.dollar_syntax_enabled() - return "\\[KaTeX\\]" if RocketChat.katex.parenthesis_syntax_enabled() - - return false - -Template.messageBox.helpers - roomName: -> - roomData = Session.get('roomData' + this._id) - return '' unless roomData - - if roomData.t is 'd' - return ChatSubscription.findOne({ rid: this._id }, { fields: { name: 1 } })?.name - else - return roomData.name - showMarkdown: -> - return RocketChat.Markdown - showMarkdownCode: -> - return RocketChat.MarkdownCode - showKatex: -> - return RocketChat.katex - katexSyntax: -> - return katexSyntax() - showFormattingTips: -> - return RocketChat.settings.get('Message_ShowFormattingTips') and (RocketChat.Markdown or RocketChat.MarkdownCode or katexSyntax()) - canJoin: -> - return Meteor.userId()? and RocketChat.roomTypes.verifyShowJoinLink @_id - joinCodeRequired: -> - return Session.get('roomData' + this._id)?.joinCodeRequired - subscribed: -> - return RocketChat.roomTypes.verifyCanSendMessage @_id - allowedToSend: -> - if RocketChat.roomTypes.readOnly @_id, Meteor.user() - return false - - if RocketChat.roomTypes.archived @_id - return false - - roomData = Session.get('roomData' + this._id) - if roomData?.t is 'd' - subscription = ChatSubscription.findOne({ rid: this._id }, { fields: { archived: 1, blocked: 1, blocker: 1 } }) - if subscription and (subscription.archived or subscription.blocked or subscription.blocker) - return false - - return true - isBlockedOrBlocker: -> - roomData = Session.get('roomData' + this._id) - if roomData?.t is 'd' - subscription = ChatSubscription.findOne({ rid: this._id }, { fields: { blocked: 1, blocker: 1 } }) - if subscription and (subscription.blocked or subscription.blocker) - return true - - getPopupConfig: -> - template = Template.instance() - return { - getInput: -> - return template.find('.input-message') - } - usersTyping: -> - users = MsgTyping.get @_id - if users.length is 0 - return - if users.length is 1 - return { - multi: false - selfTyping: MsgTyping.selfTyping.get() - users: users[0] - } - # usernames = _.map messages, (message) -> return message.u.username - last = users.pop() - if users.length > 4 - last = t('others') - # else - usernames = users.join(', ') - usernames = [usernames, last] - return { - multi: true - selfTyping: MsgTyping.selfTyping.get() - users: usernames.join " #{t 'and'} " - } - - groupAttachHidden: -> - return 'hidden' if RocketChat.settings.get('Message_Attachments_GroupAttach') - - fileUploadEnabled: -> - return RocketChat.settings.get('FileUpload_Enabled') - - fileUploadAllowedMediaTypes: -> - return RocketChat.settings.get('FileUpload_MediaTypeWhiteList') - - showFileUpload: -> - if (RocketChat.settings.get('FileUpload_Enabled')) - roomData = Session.get('roomData' + this._id) - if roomData?.t is 'd' - return RocketChat.settings.get('FileUpload_Enabled_Direct') - else - return true - else - return RocketChat.settings.get('FileUpload_Enabled') - - - showMic: -> - return Template.instance().showMicButton.get() - - showVRec: -> - return Template.instance().showVideoRec.get() - - showSend: -> - if not Template.instance().isMessageFieldEmpty.get() - return 'show-send' - - showLocation: -> - return RocketChat.Geolocation.get() isnt false - - notSubscribedTpl: -> - return RocketChat.roomTypes.getNotSubscribedTpl @_id - - showSandstorm: -> - return Meteor.settings.public.sandstorm && !Meteor.isCordova - - anonymousRead: -> - return not Meteor.userId()? and RocketChat.settings.get('Accounts_AllowAnonymousRead') is true - - anonymousWrite: -> - return not Meteor.userId()? and RocketChat.settings.get('Accounts_AllowAnonymousRead') is true and RocketChat.settings.get('Accounts_AllowAnonymousWrite') is true - -firefoxPasteUpload = (fn) -> - user = navigator.userAgent.match(/Firefox\/(\d+)\.\d/) - if !user or user[1] > 49 - return fn - return (event, instance) -> - if (event.originalEvent.ctrlKey or event.originalEvent.metaKey) and (event.keyCode == 86) - textarea = instance.find("textarea") - selectionStart = textarea.selectionStart - selectionEnd = textarea.selectionEnd - contentEditableDiv = instance.find('#msg_contenteditable') - contentEditableDiv.focus() - Meteor.setTimeout -> - pastedImg = contentEditableDiv.querySelector 'img' - textareaContent = textarea.value - startContent = textareaContent.substring(0, selectionStart) - endContent = textareaContent.substring(selectionEnd) - restoreSelection = (pastedText) -> - textarea.value = startContent + pastedText + endContent - textarea.selectionStart = selectionStart + pastedText.length - textarea.selectionEnd = textarea.selectionStart - contentEditableDiv.innerHTML = '' if pastedImg - textarea.focus - return if (!pastedImg || contentEditableDiv.innerHTML.length > 0) - [].slice.call(contentEditableDiv.querySelectorAll("br")).forEach (el) -> - contentEditableDiv.replaceChild(new Text("\n") , el) - restoreSelection(contentEditableDiv.innerText) - imageSrc = pastedImg.getAttribute("src") - if imageSrc.match(/^data:image/) - fetch(imageSrc) - .then((img)-> - return img.blob()) - .then (blob)-> - fileUpload [{ - file: blob - name: 'Clipboard' - }] - , 150 - fn?.apply @, arguments - - -Template.messageBox.events - 'click .join': (event) -> - event.stopPropagation() - event.preventDefault() - Meteor.call 'joinRoom', @_id, Template.instance().$('[name=joinCode]').val(), (err) => - if err? - toastr.error t(err.reason) - - if RocketChat.authz.hasAllPermission('preview-c-room') is false and RoomHistoryManager.getRoom(@_id).loaded is 0 - RoomManager.getOpenedRoomByRid(@_id).streamActive = false - RoomManager.getOpenedRoomByRid(@_id).ready = false - RoomHistoryManager.getRoom(@_id).loaded = undefined - RoomManager.computation.invalidate() - - 'click .register': (event) -> - event.stopPropagation() - event.preventDefault() - Session.set('forceLogin', true) - - 'click .register-anonymous': (event) -> - event.stopPropagation() - event.preventDefault() - - Meteor.call 'registerUser', {}, (error, loginData) -> - if loginData && loginData.token - Meteor.loginWithToken loginData.token - - - 'focus .input-message': (event, instance) -> - KonchatNotification.removeRoomNotification @_id - chatMessages[@_id].input = instance.find('.input-message') - - 'click .send-button': (event, instance) -> - input = instance.find('.input-message') - chatMessages[@_id].send(@_id, input, => - # fixes https://github.com/RocketChat/Rocket.Chat/issues/3037 - # at this point, the input is cleared and ready for autogrow - input.updateAutogrow() - instance.isMessageFieldEmpty.set(chatMessages[@_id].isEmpty()) - ) - input.focus() - - 'keyup .input-message': (event, instance) -> - chatMessages[@_id].keyup(@_id, event, instance) - instance.isMessageFieldEmpty.set(chatMessages[@_id].isEmpty()) - - 'paste .input-message': (e, instance) -> - Meteor.setTimeout -> - input = instance.find('.input-message') - input.updateAutogrow?() - , 50 - - if not e.originalEvent.clipboardData? - return - items = e.originalEvent.clipboardData.items - files = [] - for item in items - if item.kind is 'file' and item.type.indexOf('image/') isnt -1 - e.preventDefault() - files.push - file: item.getAsFile() - name: 'Clipboard - ' + moment().format(RocketChat.settings.get('Message_TimeAndDateFormat')) - - if files.length - fileUpload files - else - instance.isMessageFieldEmpty.set(false) - - 'keydown .input-message': firefoxPasteUpload((event, instance) -> - chatMessages[@_id].keydown(@_id, event, Template.instance())) - - 'input .input-message': (event) -> - chatMessages[@_id].valueChanged(@_id, event, Template.instance()) - - 'propertychange .input-message': (event) -> - if event.originalEvent.propertyName is 'value' - chatMessages[@_id].valueChanged(@_id, event, Template.instance()) - - "click .editing-commands-cancel > button": (e) -> - chatMessages[@_id].clearEditing() - - "click .editing-commands-save > button": (e) -> - chatMessages[@_id].send(@_id, chatMessages[@_id].input) - - 'change .message-form input[type=file]': (event, template) -> - e = event.originalEvent or event - files = e.target.files - if not files or files.length is 0 - files = e.dataTransfer?.files or [] - - filesToUpload = [] - for file in files - # `file.type = mime.lookup(file.name)` does not work. - Object.defineProperty(file, 'type', { value: mime.lookup(file.name) }) - filesToUpload.push - file: file - name: file.name - - fileUpload filesToUpload - - "click .message-buttons.share": (e, t) -> - t.$('.share-items').toggleClass('hidden') - t.$('.message-buttons.share').toggleClass('active') - - 'click .message-form .message-buttons.location': (event, instance) -> - roomId = @_id - - position = RocketChat.Geolocation.get() - - latitude = position.coords.latitude - longitude = position.coords.longitude - - text = """ -