From f810e39f5257edcd5ca20d8fe6d38eaa5a2b28d1 Mon Sep 17 00:00:00 2001 From: Steffen van Bergerem Date: Fri, 14 Jun 2013 14:38:09 +0200 Subject: [PATCH 1/2] Change image to ajax-loader when closing lightbox --- Changelog.md | 1 + app/assets/javascripts/widgets/lightbox.js | 2 ++ 2 files changed, 3 insertions(+) diff --git a/Changelog.md b/Changelog.md index 77376c5d0..c4136404e 100644 --- a/Changelog.md +++ b/Changelog.md @@ -20,6 +20,7 @@ * Fix deleting a post from Facebook [#4290](https://github.com/diaspora/diaspora/pull/4290) * Display notices a little bit longer to help on sign up errors [#4274](https://github.com/diaspora/diaspora/issues/4274) * Fix user contact sharing/receiving [#4163](https://github.com/diaspora/diaspora/issues/4163) +* Change image to ajax-loader when closing lightbox [#3229](https://github.com/diaspora/diaspora/issues/3229) ## Features * Admin: add option to find users under 13 (COPPA) [#4252](https://github.com/diaspora/diaspora/pull/4252) diff --git a/app/assets/javascripts/widgets/lightbox.js b/app/assets/javascripts/widgets/lightbox.js index 30c969845..6152762de 100644 --- a/app/assets/javascripts/widgets/lightbox.js +++ b/app/assets/javascripts/widgets/lightbox.js @@ -151,6 +151,8 @@ jQuery.fn.center = (function() { this.resetLightbox = function() { self.lightbox.hide(); self.body.removeClass("lightboxed"); + self.image.attr("src", "assets/ajax-loader2.gif"); + self.imageset.html(""); }; this.set = function(opts) { From 7d40fd1add977d9cb890cd4a0d49042072306022 Mon Sep 17 00:00:00 2001 From: Meitar Moscovitz Date: Sat, 27 Jul 2013 15:55:09 -0400 Subject: [PATCH 2/2] Delete cross-posted Tumblr posts when user deletes their Diaspora post. --- app/models/services/tumblr.rb | 33 ++++++++++++++++--- ...0801063213_add_tumblr_post_ids_to_posts.rb | 5 +++ db/schema.rb | 5 +-- spec/models/services/tumblr_spec.rb | 25 +++++++++++--- 4 files changed, 57 insertions(+), 11 deletions(-) create mode 100644 db/migrate/20130801063213_add_tumblr_post_ids_to_posts.rb diff --git a/app/models/services/tumblr.rb b/app/models/services/tumblr.rb index 203d1a349..6fef57617 100644 --- a/app/models/services/tumblr.rb +++ b/app/models/services/tumblr.rb @@ -17,14 +17,17 @@ class Services::Tumblr < Service end def post(post, url='') - consumer = OAuth::Consumer.new(consumer_key, consumer_secret, :site => 'http://api.tumblr.com') - access = OAuth::AccessToken.new(consumer, self.access_token, self.access_secret) - body = build_tumblr_post(post, url) - user_info = JSON.parse(access.get("/v2/user/info").body) + user_info = JSON.parse(client.get("/v2/user/info").body) blogs = user_info["response"]["user"]["blogs"].map { |blog| URI.parse(blog['url']) } + tumblr_ids = {} blogs.each do |blog| - access.post("/v2/blog/#{blog.host}/post", body) + resp = client.post("/v2/blog/#{blog.host}/post", body) + if resp.code == "201" + tumblr_ids[blog.host.to_s] = JSON.parse(resp.body)["response"]["id"] + end + post.tumblr_ids = tumblr_ids.to_json + post.save end end @@ -40,5 +43,25 @@ class Services::Tumblr < Service html += post.text html += "\n\n[original post](#{url})" end + + def delete_post(post) + if post.present? && post.tumblr_ids.present? + Rails.logger.debug("event=delete_from_service type=tumblr sender_id=#{self.user_id}") + tumblr_posts = JSON.parse(post.tumblr_ids) + tumblr_posts.each do |blog_name,post_id| + delete_from_tumblr(blog_name, post_id) + end + end + end + + def delete_from_tumblr(blog_name, service_post_id) + client.post("/v2/blog/#{blog_name}/post/delete", "id" => service_post_id) + end + + private + def client + @consumer ||= OAuth::Consumer.new(consumer_key, consumer_secret, :site => 'http://api.tumblr.com') + @client ||= OAuth::AccessToken.new(@consumer, self.access_token, self.access_secret) + end end diff --git a/db/migrate/20130801063213_add_tumblr_post_ids_to_posts.rb b/db/migrate/20130801063213_add_tumblr_post_ids_to_posts.rb new file mode 100644 index 000000000..e8ddb4877 --- /dev/null +++ b/db/migrate/20130801063213_add_tumblr_post_ids_to_posts.rb @@ -0,0 +1,5 @@ +class AddTumblrPostIdsToPosts < ActiveRecord::Migration + def change + add_column :posts, :tumblr_ids, :text + end +end diff --git a/db/schema.rb b/db/schema.rb index b92103eb5..cbbfa94c2 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended to check this file into your version control system. -ActiveRecord::Schema.define(:version => 20130717104359) do +ActiveRecord::Schema.define(:version => 20130801063213) do create_table "account_deletions", :force => true do |t| t.string "diaspora_handle" @@ -213,7 +213,7 @@ ActiveRecord::Schema.define(:version => 20130717104359) do t.text "data", :null => false end - add_index "o_embed_caches", ["url"], :name => "index_o_embed_caches_on_url", :length => {"url"=>767} + add_index "o_embed_caches", ["url"], :name => "index_o_embed_caches_on_url", :length => {"url"=>255} create_table "participations", :force => true do |t| t.string "guid" @@ -308,6 +308,7 @@ ActiveRecord::Schema.define(:version => 20130717104359) do t.boolean "favorite", :default => false t.string "facebook_id" t.string "tweet_id" + t.text "tumblr_ids" end add_index "posts", ["author_id", "root_guid"], :name => "index_posts_on_author_id_and_root_guid", :unique => true diff --git a/spec/models/services/tumblr_spec.rb b/spec/models/services/tumblr_spec.rb index 83d2ad78e..6e58092c7 100644 --- a/spec/models/services/tumblr_spec.rb +++ b/spec/models/services/tumblr_spec.rb @@ -10,13 +10,30 @@ describe Services::Tumblr do end describe '#post' do - it 'posts a status message to tumblr' do - response = mock - response.stub(:body).and_return('{"response": {"user": {"blogs": [{"url": "http://foo.tumblr.com"}]}}}') - OAuth::AccessToken.any_instance.should_receive(:get).with("/v2/user/info").and_return(response) + it 'posts a status message to tumblr and saves the returned ids' do + response = mock(body: '{"response": {"user": {"blogs": [{"url": "http://foo.tumblr.com"}]}}}') + OAuth::AccessToken.any_instance.should_receive(:get) + .with("/v2/user/info") + .and_return(response) + + response = mock(code: "201", body: '{"response": {"id": "bla"}}') OAuth::AccessToken.any_instance.should_receive(:post) + .with("/v2/blog/foo.tumblr.com/post", @service.build_tumblr_post(@post, '')) + .and_return(response) + + @post.should_receive(:tumblr_ids=).with({"foo.tumblr.com" => "bla"}.to_json) + @service.post(@post) end end + + describe '#delete_post' do + it 'removes posts from tumblr' do + stub_request(:post, "http://api.tumblr.com/v2/blog/foodbar.tumblr.com/post/delete"). + to_return(:status => 200) + + @service.delete_post(@post) + end + end end