diff --git a/app/models/o_embed_cache.rb b/app/models/o_embed_cache.rb index 17c4bfe6eab39eebfe5e4085b328fe43cd2431ee..dd1e70cbd02a0cb0b5ad87f279686c9f7bb8843e 100644 --- a/app/models/o_embed_cache.rb +++ b/app/models/o_embed_cache.rb @@ -5,6 +5,12 @@ class OEmbedCache < ActiveRecord::Base has_many :posts + # NOTE API V1 to be extracted + acts_as_api + api_accessible :backbone do |t| + t.add :data + end + def self.find_or_create_by_url(url) cache = OEmbedCache.find_or_initialize_by_url(url) return cache if cache.persisted? diff --git a/app/models/reshare.rb b/app/models/reshare.rb index b4559b8fca970faa7b182735c4d98987aae97241..f5468a5b2216cd87c8a3abe6e07fa39a5c760227 100644 --- a/app/models/reshare.rb +++ b/app/models/reshare.rb @@ -29,6 +29,10 @@ class Reshare < Post self.root.author.diaspora_handle end + def o_embed_cache + self.root ? root.o_embed_cache : super + end + def raw_message self.root ? root.raw_message : super end diff --git a/app/views/templates/reshare.jst b/app/views/templates/reshare.jst index 3513e4f19368c01049c4e344fccf95ad9d99cec5..95716f6d8457415b936bc97f919d5446b7af8122 100644 --- a/app/views/templates/reshare.jst +++ b/app/views/templates/reshare.jst @@ -39,9 +39,7 @@ <%= text %> - <% if(o_embed_cache) { %> - <%= root.o_embed_cache.posts.data.html %> - <% } %> + <%= o_embed_html %> <!-- end duplication --> </div> diff --git a/app/views/templates/status_message.jst b/app/views/templates/status_message.jst index eb4e306d6fb5485a4a1dcf0886e8b111df00bfc0..06d04dd4d9fc6e481145eb0d497a420cf91f1ebf 100644 --- a/app/views/templates/status_message.jst +++ b/app/views/templates/status_message.jst @@ -14,6 +14,4 @@ <%= text %> -<% if(o_embed_cache) { %> - <%= o_embed_cache.posts.data.html %> -<% } %> +<%= o_embed_html %> diff --git a/public/javascripts/app/views/content_view.js b/public/javascripts/app/views/content_view.js index fee5cb09da9311c5fd992af9ba29d3ba48092af2..1d321d5907e9fd225ef5f805c03f7532b35e4a49 100644 --- a/public/javascripts/app/views/content_view.js +++ b/public/javascripts/app/views/content_view.js @@ -2,7 +2,8 @@ app.views.Content = app.views.StreamObject.extend({ presenter : function(){ var model = this.model return _.extend(this.defaultPresenter(), { - text : metafyText(model.get("text")) + text : metafyText(model.get("text")), + o_embed_html : embedHTML(model) }) function metafyText(text) { @@ -48,6 +49,11 @@ app.views.Content = app.views.StreamObject.extend({ return "<a href='" + protocol + url + "' target=_blank>" + url + "</a>" }) } + + function embedHTML(model){ + if(!model.get("o_embed_cache")) { return ""; } + return model.get("o_embed_cache").data.html + } } }) diff --git a/spec/javascripts/app/views/post_view_spec.js b/spec/javascripts/app/views/post_view_spec.js index 93f3924110a8b4cc121ad22e31cb9572abffdd77..6dd2678dc2e61123ee00d02c5fdf940727cbda6f 100644 --- a/spec/javascripts/app/views/post_view_spec.js +++ b/spec/javascripts/app/views/post_view_spec.js @@ -167,6 +167,26 @@ describe("app.views.Post", function(){ }) }) + context("embed_html", function(){ + it("provides oembed html from the model response", function(){ + this.statusMessage.set({"o_embed_cache" : { + "data" : { + "html" : "some html" + } + }}) + + var view = new app.views.Content({model : this.statusMessage}); + expect(view.presenter().o_embed_html).toContain("some html") + }) + + it("does not provide oembed html from the model response if none is present", function(){ + this.statusMessage.set({"o_embed_cache" : null}) + + var view = new app.views.Content({model : this.statusMessage}); + expect(view.presenter().o_embed_html).toBe(""); + }) + }) + context("user not signed in", function(){ it("does not provide a Feedback view", function(){ logout()