diff --git a/client/views/app/chatMessageDashboard.coffee b/client/views/app/chatMessageDashboard.coffee index f2f8af731811..ec639dce8f1f 100644 --- a/client/views/app/chatMessageDashboard.coffee +++ b/client/views/app/chatMessageDashboard.coffee @@ -15,6 +15,22 @@ Template.chatMessageDashboard.helpers return this._id is Session.get('editingMessageId') preProcessingMessage: -> + # temporary pre-1.0 image embed to support bot development - to be refactored + if _.trim(this.msg) isnt '' + msg = this.msg + + picmatch = msg.match(/^https?:\/\/(?:[a-z0-9\-]+\.)+[a-z0-9]{2,6}(?:\/[^\/#?]+)+\.(?:jpe?g|gif|png)$/i) + + if picmatch? + # inline style to limit code pollution + msg = "" + return msg + + mapmatch = msg.match(/^https?\:\/\/maps\.(google|googleapis)\.[a-z]+\/maps\/api.*format=png$/i) + if mapmatch? + msg = "" + return msg + # end of temporary pre-1.0 image embed to support bot development this.html = this.msg message = RocketChat.callbacks.run 'renderMessage', this @@ -36,7 +52,7 @@ Template.chatMessageDashboard.helpers newMessage: -> # @TODO pode melhorar, acho que colocando as salas abertas na sessão # if $('#chat-window-' + this.rid + '.opened').length == 0 - # return 'new' + # return 'new' preMD: Template 'preMD', -> self = this diff --git a/packages/rocketchat-tmpembed/package.js b/packages/rocketchat-tmpembed/package.js new file mode 100644 index 000000000000..e15a73497b9b --- /dev/null +++ b/packages/rocketchat-tmpembed/package.js @@ -0,0 +1,21 @@ +Package.describe({ + name: 'rocketchat:tmpembed', + version: '0.0.1', + summary: 'Message pre-processor that handles embedding of images and maps', + git: '' +}); + +Package.onUse(function(api) { + api.versionsFrom('1.0'); + + api.use([ + 'coffeescript', + 'rocketchat:lib@0.0.1' + ]); + + api.addFiles('tmpembed.coffee', ['server','client']); +}); + +Package.onTest(function(api) { + +}); diff --git a/packages/rocketchat-tmpembed/tmpembed.coffee b/packages/rocketchat-tmpembed/tmpembed.coffee new file mode 100644 index 000000000000..499bd2c50a49 --- /dev/null +++ b/packages/rocketchat-tmpembed/tmpembed.coffee @@ -0,0 +1,31 @@ +### +# ObjEmbedder is a temporary image and map embedder for bots development +# @param {Object} msg - The message object +# to be replaced by proper implementation in 1.0 +### + +class ObjEmbedder + constructor: (message) -> + console.log "in obj embedded" + if _.trim message.html + console.log("trim okay") + # temporary pre-1.0 image embed to support bot development - to be refactored + msg = message.html + picmatch = msg.match(/^https?:\/\/(?:[a-z0-9\-]+\.)+[a-z0-9]{2,6}(?:\/[^\/#?]+)+\.(?:jpe?g|gif|png)$/i) + + if picmatch? + # inline style to limit code pollution + console.log("match pic") + msg = "" + return msg + + mapmatch = msg.match(/^https?\:\/\/maps\.(google|googleapis)\.[a-z]+\/maps\/api.*format=png$/i) + if mapmatch? + console.log("match map") + msg = "" + return msg + + # end of temporary pre-1.0 image embed + return message + +RocketChat.callbacks.add 'renderMessage', ObjEmbedder, RocketChat.callbacks.priority.HIGH diff --git a/packages/rocketchat-tmpembed/tmpembed.js b/packages/rocketchat-tmpembed/tmpembed.js new file mode 100644 index 000000000000..5411da5879dd --- /dev/null +++ b/packages/rocketchat-tmpembed/tmpembed.js @@ -0,0 +1,37 @@ +// Generated by CoffeeScript 1.8.0 + +/* + * ObjEmbedder is a temporary image and map embedder for bots development + * @param {Object} msg - The message object + * to be replaced by proper implementation in 1.0 + */ +var ObjEmbedder; + +ObjEmbedder = (function() { + function ObjEmbedder(message) { + var mapmatch, msg, picmatch; + console.log("in obj embedded"); + if (_.trim(message.html)) { + console.log("trim okay"); + msg = message.html; + picmatch = msg.match(/^https?:\/\/(?:[a-z0-9\-]+\.)+[a-z0-9]{2,6}(?:\/[^\/#?]+)+\.(?:jpe?g|gif|png)$/i); + if (picmatch != null) { + console.log("match pic"); + msg = ""; + return msg; + } + mapmatch = msg.match(/^https?\:\/\/maps\.(google|googleapis)\.[a-z]+\/maps\/api.*format=png$/i); + if (mapmatch != null) { + console.log("match map"); + msg = ""; + return msg; + } + } + return message; + } + + return ObjEmbedder; + +})(); + +RocketChat.callbacks.add('renderMessage', ObjEmbedder, RocketChat.callbacks.priority.HIGH);