diff --git a/app/assets/javascripts/backbone/plugins/image_embed.js.coffee b/app/assets/javascripts/backbone/plugins/image_embed.js.coffee index 6d999bd6..7d3ffd23 100644 --- a/app/assets/javascripts/backbone/plugins/image_embed.js.coffee +++ b/app/assets/javascripts/backbone/plugins/image_embed.js.coffee @@ -1,21 +1,27 @@ class Kandan.Plugins.ImageEmbed - @image_regex: /^http.*\.(jpg|jpeg|gif|png)/i - + @image_regex: /http.*\.(jpg|jpeg|gif|png)/i @image_template: _.template '''
-
<%= name %>
+
<%= subtitle %>
''' @init: ()-> - Kandan.Modifiers.register @image_regex, (message, state)=> - file_name = message.content.split("/").pop() + Kandan.Modifiers.register @image_regex, (message, state) => + url = message.content.match(@image_regex)[0] + fileName = url.split("/").pop() + comment = $.trim(message.content.split(url).join("")) + subtitle = null + subtitle = comment if comment.length > 0 + subtitle ||= fileName + message.content = @image_template({ - image_url: message.content, - name: file_name + image_url: url, + subtitle: subtitle }) - return Kandan.Helpers.Activities.build_from_message_template(message) \ No newline at end of file + + return Kandan.Helpers.Activities.build_from_message_template(message) diff --git a/app/assets/javascripts/backbone/plugins/me_announce.js.coffee b/app/assets/javascripts/backbone/plugins/me_announce.js.coffee index 52a04514..30c89737 100644 --- a/app/assets/javascripts/backbone/plugins/me_announce.js.coffee +++ b/app/assets/javascripts/backbone/plugins/me_announce.js.coffee @@ -1,10 +1,11 @@ class Kandan.Plugins.MeAnnounce - @regex: /^\/me / + @regex: /^/me / @init: ()-> - Kandan.Modifiers.register @regex, (message, state)=> + Kandan.Modifiers.register @regex, (message, state) => + actor = message.user.first_name || message.user.email message.content = message.content.replace @regex, "#{message.user.first_name} " return Kandan.Helpers.Activities.build_from_base_template(message) -# Kandan.Plugins.register "Kandan.Plugins.MeAnnounce" \ No newline at end of file +# Kandan.Plugins.register "Kandan.Plugins.MeAnnounce" diff --git a/app/assets/javascripts/backbone/plugins/youtube_embed.js.coffee b/app/assets/javascripts/backbone/plugins/youtube_embed.js.coffee index cf1d5236..9baea9e3 100644 --- a/app/assets/javascripts/backbone/plugins/youtube_embed.js.coffee +++ b/app/assets/javascripts/backbone/plugins/youtube_embed.js.coffee @@ -1,6 +1,6 @@ class Kandan.Plugins.YouTubeEmbed - @youtube_regex: /^http(s)?:\/\/www.youtube.com\/watch/i + @youtube_regex: /^http(s)?.+www.youtube.com.+watch/i @youtube_id_regex: /\Wv=([\w|\-]*)/ @youtube_embed_template: _.template ''' @@ -8,15 +8,32 @@ class Kandan.Plugins.YouTubeEmbed +
<%= subtitle %>
''' @init: ()-> - Kandan.Modifiers.register @youtube_regex, (message, state)=> + Kandan.Modifiers.register @youtube_regex, (message, state) => + comment = null + + # No spaces in message content indicates just a link + if message.content.indexOf(" ") == -1 + video_url = message.content + else + # Spaces indicate a subtitle + comment = $.trim(message.content.substr(message.content.indexOf(" ") + 1)); + video_url = message.content.split(" ")[0] + video_id = message.content.match(@youtube_id_regex)[1] thumb_url = "http://img.youtube.com/vi/#{ video_id }/0.jpg" + + subtitle = null + subtitle = "Youtube: #{comment}" if comment? and comment.length > 0 + subtitle ||= video_url + message.content = @youtube_embed_template({ - video_url: message.content, - thumb_url: thumb_url + video_url: video_url, + thumb_url: thumb_url, + subtitle: subtitle }) - return Kandan.Helpers.Activities.build_from_message_template(message) \ No newline at end of file + return Kandan.Helpers.Activities.build_from_message_template(message) diff --git a/app/assets/javascripts/backbone/views/show_activity.js.coffee b/app/assets/javascripts/backbone/views/show_activity.js.coffee index 13e5abf1..2df99500 100644 --- a/app/assets/javascripts/backbone/views/show_activity.js.coffee +++ b/app/assets/javascripts/backbone/views/show_activity.js.coffee @@ -6,6 +6,9 @@ class Kandan.Views.ShowActivity extends Backbone.View render: ()-> activity = @options.activity.toJSON() activity.created_at = Kandan.Helpers.Utils.time_to_string(new Date(activity.created_at)) + console.log("Rendering activity:") + activity.content = _.escape(activity.content) + console.log(activity) if activity.action != "message" @compiled_template = JST['user_notification']({activity: activity}) else @@ -13,7 +16,7 @@ class Kandan.Views.ShowActivity extends Backbone.View if modified_message != false @compiled_template = modified_message else - @compiled_template = Kandan.Helpers.Activities.build_from_message_template $.extend(activity, {content: _.escape(activity.content)}) + @compiled_template = Kandan.Helpers.Activities.build_from_message_template activity $(@el).data('activity_id', activity.id) $(@el).attr('id', "activity-#{activity.id}") diff --git a/app/assets/templates/user_notification.jst.eco b/app/assets/templates/user_notification.jst.eco index 84ad31e4..b5a6218e 100644 --- a/app/assets/templates/user_notification.jst.eco +++ b/app/assets/templates/user_notification.jst.eco @@ -5,7 +5,7 @@ Kandan bot - <%= @activity.user.first_name %> <%= @activity.action %>ed <%- "#{@activity.content}" if @activity.action == "upload" %> + <%= @activity.user.first_name || @activity.user.email %> <%= @activity.action %>ed <%- "#{@activity.content}" if @activity.action == "upload" %> diff --git a/app/controllers/channels_controller.rb b/app/controllers/channels_controller.rb index c7997b25..bc37a578 100644 --- a/app/controllers/channels_controller.rb +++ b/app/controllers/channels_controller.rb @@ -12,7 +12,7 @@ def index more_activities = (channel.activities.count > Kandan::Config.options[:per_page]) channel.activities.order('id DESC').includes(:user).page.each do |activity| activities.push activity.attributes.merge({ - :user => activity.user.as_json(:only => [:id, :ido_id, :first_name, :last_name, :gravatar_hash, :active, :locale]) + :user => activity.user.as_json(:only => [:id, :ido_id, :email, :first_name, :last_name, :gravatar_hash, :active, :locale]) }) end diff --git a/app/models/activity_observer.rb b/app/models/activity_observer.rb index 139452cc..41ac8ac4 100644 --- a/app/models/activity_observer.rb +++ b/app/models/activity_observer.rb @@ -11,7 +11,7 @@ def after_save(activity) def message_broadcast_data(activity) faye_channel = "/channels/#{activity.channel.to_param}" broadcast_data = activity.attributes.merge({ - :user => activity.user.attributes, + :user => activity.user.as_json(:only => [:id, :ido_id, :email, :first_name, :last_name, :gravatar_hash, :active, :locale]), :channel => activity.channel.attributes }) [faye_channel, broadcast_data] @@ -22,7 +22,7 @@ def upload_broadcast_data(activity) broadcast_data = { :event => "attachment#upload", :entity => activity.attributes.merge({ - :user => activity.user.attributes, + :user => activity.user.as_json(:only => [:id, :ido_id, :email, :first_name, :last_name, :gravatar_hash, :active, :locale]), :channel => activity.channel.attributes }), :extra => {