Twitter service removes status from twitter when post is revoked

This commit is contained in:
Ruxton 2013-04-29 21:19:11 +08:00
parent a8655e2e8d
commit ba0e2509c9
4 changed files with 30 additions and 8 deletions

View file

@ -10,6 +10,7 @@
## Features
* Deleting a post that was shared to Twitter now deletes it from Twitter too [#4135](https://github.com/diaspora/diaspora/pull/4135)
# 0.1.0.0
@ -139,7 +140,7 @@ everything is set up.
* Fix reshares in single post-view [#4056](https://github.com/diaspora/diaspora/issues/4056)
* Fix mobile view of deleted reshares. [#4063](https://github.com/diaspora/diaspora/issues/4063)
* Hide comment button in the mobile view when not signed in. [#4065](https://github.com/diaspora/diaspora/issues/4065)
* Send profile alongside notification [#3976] (https://github.com/diaspora/diaspora/issues/3976)
* Send profile alongside notification [#3976](https://github.com/diaspora/diaspora/issues/3976)
* Fix off-center close button image on intro popovers [#3841](https://github.com/diaspora/diaspora/pull/3841)
* Remove unnecessary dotted CSS borders. [#2940](https://github.com/diaspora/diaspora/issues/2940)
* Fix default image url in profiles table. [#3795](https://github.com/diaspora/diaspora/issues/3795)
@ -159,7 +160,7 @@ everything is set up.
## Features
* Deleting a post that was shared to Facebook now deletes it from Facebook too [#3980]( https://github.com/diaspora/diaspora/pull/3980)
* Deleting a post that was shared to Facebook now deletes it from Facebook too [#3980](https://github.com/diaspora/diaspora/pull/3980)
* Include reshares in a users public atom feed [#1781](https://github.com/diaspora/diaspora/issues/1781)
* Add the ability to upload photos from the mobile site. [#4004](https://github.com/diaspora/diaspora/issues/4004)
* Show timestamp when hovering on comment time-ago string. [#4042](https://github.com/diaspora/diaspora/issues/4042)
@ -212,7 +213,6 @@ everything is set up.
* uglifier 1.3.0 -> 2.0.1
* unicorn 4.6.0 -> 4.6.2
# 0.0.3.4
* Bump Rails to 3.2.13, fixes CVE-2013-1854, CVE-2013-1855, CVE-2013-1856 and CVE-2013-1857. [Read more](http://weblog.rubyonrails.org/2013/3/18/SEC-ANN-Rails-3-2-13-3-1-12-and-2-3-18-have-been-released/)

View file

@ -9,8 +9,9 @@ class Services::Twitter < Service
def post(post, url='')
Rails.logger.debug("event=post_to_service type=twitter sender_id=#{self.user_id}")
message = public_message(post, url)
client.update(message)
tweet = client.update(message)
post.tweet_id = tweet.id
post.save
end
@ -28,6 +29,15 @@ class Services::Twitter < Service
client.user(nickname).profile_image_url_https("original")
end
def delete_post(service_post_id)
Rails.logger.debug("event=delete_from_service type=twitter sender_id=#{self.user_id}")
delete_from_twitter(service_post_id)
end
def delete_from_twitter(service_post_id)
client.status_destroy(service_post_id)
end
private
def client
@client ||= Twitter::Client.new(

View file

@ -151,9 +151,12 @@ class Postzord::Dispatcher
end
end
if @object.instance_of?(SignedRetraction)
services.select { |service| service.respond_to? :delete_post }.each do |service|
services.select { |service| service.provider == "facebook" }.each do |service|
Workers::DeletePostFromService.perform_async(service.id, @object.target.facebook_id)
end
services.select { |service| service.provider == "twitter" }.each do |service|
Workers::DeletePostFromService.perform_async(service.id, @object.target.tweet_id)
end
end
end

View file

@ -10,19 +10,28 @@ describe Services::Twitter do
end
describe '#post' do
before do
Twitter::Client.any_instance.stub(:update) { Twitter::Tweet.new(id: "1234") }
end
it 'posts a status message to twitter' do
Twitter::Client.any_instance.should_receive(:update).with(instance_of(String))
@service.post(@post)
end
it 'swallows exception raised by twitter always being down' do
it 'sets the tweet_id on the post' do
@service.post(@post)
@post.tweet_id.should match "1234"
end
it 'swallows exception raised by twitter always being down' do
pending
Twitter::Client.any_instance.should_receive(:update).and_raise(StandardError)
@service.post(@post)
end
it 'should call public message' do
Twitter::Client.any_instance.stub(:update)
url = "foo"
@service.should_receive(:public_message).with(@post, url)
@service.post(@post, url)