Merge pull request #4331 from meitar/tumblr-delete-deleted
Tumblr posts should be deleted when users delete their originating Diaspora post.
This commit is contained in:
commit
9d6ac1abe5
6 changed files with 61 additions and 11 deletions
|
|
@ -21,6 +21,7 @@
|
||||||
* Fix deleting a post from Facebook [#4290](https://github.com/diaspora/diaspora/pull/4290)
|
* 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)
|
* 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)
|
* 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
|
## Features
|
||||||
* Admin: add option to find users under 13 (COPPA) [#4252](https://github.com/diaspora/diaspora/pull/4252)
|
* Admin: add option to find users under 13 (COPPA) [#4252](https://github.com/diaspora/diaspora/pull/4252)
|
||||||
|
|
@ -29,6 +30,7 @@
|
||||||
* Follow DiasporaHQ upon account creation is now configurable to another account [#4278](https://github.com/diaspora/diaspora/pull/4278)
|
* Follow DiasporaHQ upon account creation is now configurable to another account [#4278](https://github.com/diaspora/diaspora/pull/4278)
|
||||||
* Use first header as title in the single post view, when possible [#4256](https://github.com/diaspora/diaspora/pull/4256)
|
* Use first header as title in the single post view, when possible [#4256](https://github.com/diaspora/diaspora/pull/4256)
|
||||||
* Close publisher when clicking on the page outside of it [#4282](https://github.com/diaspora/diaspora/pull/4282)
|
* Close publisher when clicking on the page outside of it [#4282](https://github.com/diaspora/diaspora/pull/4282)
|
||||||
|
* Deleting a post deletes it from Tumblr too [#4331](https://github.com/diaspora/diaspora/pull/4331)
|
||||||
|
|
||||||
# 0.1.1.0
|
# 0.1.1.0
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -151,6 +151,8 @@ jQuery.fn.center = (function() {
|
||||||
this.resetLightbox = function() {
|
this.resetLightbox = function() {
|
||||||
self.lightbox.hide();
|
self.lightbox.hide();
|
||||||
self.body.removeClass("lightboxed");
|
self.body.removeClass("lightboxed");
|
||||||
|
self.image.attr("src", "assets/ajax-loader2.gif");
|
||||||
|
self.imageset.html("");
|
||||||
};
|
};
|
||||||
|
|
||||||
this.set = function(opts) {
|
this.set = function(opts) {
|
||||||
|
|
|
||||||
|
|
@ -17,14 +17,17 @@ class Services::Tumblr < Service
|
||||||
end
|
end
|
||||||
|
|
||||||
def post(post, url='')
|
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)
|
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']) }
|
blogs = user_info["response"]["user"]["blogs"].map { |blog| URI.parse(blog['url']) }
|
||||||
|
tumblr_ids = {}
|
||||||
blogs.each do |blog|
|
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
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -40,5 +43,25 @@ class Services::Tumblr < Service
|
||||||
html += post.text
|
html += post.text
|
||||||
html += "\n\n[original post](#{url})"
|
html += "\n\n[original post](#{url})"
|
||||||
end
|
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
|
end
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,5 @@
|
||||||
|
class AddTumblrPostIdsToPosts < ActiveRecord::Migration
|
||||||
|
def change
|
||||||
|
add_column :posts, :tumblr_ids, :text
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
@ -11,7 +11,7 @@
|
||||||
#
|
#
|
||||||
# It's strongly recommended to check this file into your version control system.
|
# 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|
|
create_table "account_deletions", :force => true do |t|
|
||||||
t.string "diaspora_handle"
|
t.string "diaspora_handle"
|
||||||
|
|
@ -213,7 +213,7 @@ ActiveRecord::Schema.define(:version => 20130717104359) do
|
||||||
t.text "data", :null => false
|
t.text "data", :null => false
|
||||||
end
|
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|
|
create_table "participations", :force => true do |t|
|
||||||
t.string "guid"
|
t.string "guid"
|
||||||
|
|
@ -308,6 +308,7 @@ ActiveRecord::Schema.define(:version => 20130717104359) do
|
||||||
t.boolean "favorite", :default => false
|
t.boolean "favorite", :default => false
|
||||||
t.string "facebook_id"
|
t.string "facebook_id"
|
||||||
t.string "tweet_id"
|
t.string "tweet_id"
|
||||||
|
t.text "tumblr_ids"
|
||||||
end
|
end
|
||||||
|
|
||||||
add_index "posts", ["author_id", "root_guid"], :name => "index_posts_on_author_id_and_root_guid", :unique => true
|
add_index "posts", ["author_id", "root_guid"], :name => "index_posts_on_author_id_and_root_guid", :unique => true
|
||||||
|
|
|
||||||
|
|
@ -10,13 +10,30 @@ describe Services::Tumblr do
|
||||||
end
|
end
|
||||||
|
|
||||||
describe '#post' do
|
describe '#post' do
|
||||||
it 'posts a status message to tumblr' do
|
it 'posts a status message to tumblr and saves the returned ids' do
|
||||||
response = mock
|
response = mock(body: '{"response": {"user": {"blogs": [{"url": "http://foo.tumblr.com"}]}}}')
|
||||||
response.stub(:body).and_return('{"response": {"user": {"blogs": [{"url": "http://foo.tumblr.com"}]}}}')
|
OAuth::AccessToken.any_instance.should_receive(:get)
|
||||||
OAuth::AccessToken.any_instance.should_receive(:get).with("/v2/user/info").and_return(response)
|
.with("/v2/user/info")
|
||||||
|
.and_return(response)
|
||||||
|
|
||||||
|
response = mock(code: "201", body: '{"response": {"id": "bla"}}')
|
||||||
OAuth::AccessToken.any_instance.should_receive(:post)
|
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)
|
@service.post(@post)
|
||||||
end
|
end
|
||||||
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
|
end
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue