Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add temporary img and map embed for bots - closes #177 #178

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion client/views/app/chatMessageDashboard.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "<img style='width:400px;height:auto;' src='" + msg + "'></img>"
return msg

mapmatch = msg.match(/^https?\:\/\/maps\.(google|googleapis)\.[a-z]+\/maps\/api.*format=png$/i)
if mapmatch?
msg = "<img style='width:400px;height:auto;' src='" + msg + "'></img>"
return msg
# end of temporary pre-1.0 image embed to support bot development

this.html = this.msg
message = RocketChat.callbacks.run 'renderMessage', this
Expand All @@ -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
Expand Down
21 changes: 21 additions & 0 deletions packages/rocketchat-tmpembed/package.js
Original file line number Diff line number Diff line change
@@ -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) {

});
31 changes: 31 additions & 0 deletions packages/rocketchat-tmpembed/tmpembed.coffee
Original file line number Diff line number Diff line change
@@ -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 = "<img style='width:400px;height:auto;' src='" + msg + "'></img>"
return msg

mapmatch = msg.match(/^https?\:\/\/maps\.(google|googleapis)\.[a-z]+\/maps\/api.*format=png$/i)
if mapmatch?
console.log("match map")
msg = "<img style='width:400px;height:auto;' src='" + msg + "'></img>"
return msg

# end of temporary pre-1.0 image embed
return message

RocketChat.callbacks.add 'renderMessage', ObjEmbedder, RocketChat.callbacks.priority.HIGH
37 changes: 37 additions & 0 deletions packages/rocketchat-tmpembed/tmpembed.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.