adium 2907:68b337afb9d4: Implement the Retweet API. This means c...

commits at adium.im commits at adium.im
Fri Nov 20 02:12:49 UTC 2009


details:	http://hg.adium.im/adium/rev/68b337afb9d4
revision:	2907:68b337afb9d4
author:		Zachary West <zacw at adium.im>
date:		Thu Nov 19 21:12:23 2009 -0500

Implement the Retweet API. This means checking home_timeline and sending proper retweet messages. Fixes #12556.

On an annoying note, home_timeline (despite saying "Returns the 20 most recent statuses, including retweets, posted by the authenticating user and that user's friends") does not include outgoing retweets. This will either be fixed by Twitter quickly, or not. I'm tired of Twitter's inconsistent and buggy API. So, as such, there's currently no way to remove a retweet done by yourself.
(transplanted from 85857106a45eb140cb1c6fb3e38f6456570e0045)

diffs (193 lines):

diff -r c759d36f6f23 -r 68b337afb9d4 Plugins/Twitter Plugin/AITwitterAccount.h
--- a/Plugins/Twitter Plugin/AITwitterAccount.h	Wed Nov 11 22:27:35 2009 -0500
+++ b/Plugins/Twitter Plugin/AITwitterAccount.h	Thu Nov 19 21:12:23 2009 -0500
@@ -182,6 +182,7 @@
 			  location:(NSString *)location
 		   description:(NSString *)description;
 
+- (void)retweetTweet:(NSString *)tweetID;
 - (void)toggleFavoriteTweet:(NSString *)tweetID;
 - (void)destroyTweet:(NSString *)tweetID;
 - (void)destroyDirectMessage:(NSString *)messageID
diff -r c759d36f6f23 -r 68b337afb9d4 Plugins/Twitter Plugin/AITwitterAccount.m
--- a/Plugins/Twitter Plugin/AITwitterAccount.m	Wed Nov 11 22:27:35 2009 -0500
+++ b/Plugins/Twitter Plugin/AITwitterAccount.m	Thu Nov 19 21:12:23 2009 -0500
@@ -1195,6 +1195,25 @@
 }
 
 /*!
+ * @brief Retweet the selected tweet.
+ *
+ * Attempts to retweet a tweet.
+ * Prints a status message in the chat on success/failure, behaves identical to sending a new tweet.
+ */
+- (void)retweetTweet:(NSString *)tweetID
+{
+	NSString *requestID = [twitterEngine retweetUpdate:tweetID];
+	
+	if (requestID) {
+		[self setRequestType:AITwitterSendUpdate
+				forRequestID:requestID
+			  withDictionary:[NSDictionary dictionaryWithObjectsAndKeys:tweetID, @"tweetID", nil]];
+	} else {
+		[self.timelineChat receivedError:[NSNumber numberWithInt:AIChatMessageSendingConnectionError]];
+	}
+}
+
+/*!
  * @brief Toggle the favorite status for a tweet.
  *
  * Attempts to favorite a tweet. If that fails, it removes favorite status.
@@ -1708,7 +1727,7 @@
 			AIChat	*chat = [[self dictionaryForRequestID:identifier] objectForKey:@"Chat"];
 			
 			if (chat) {
-				[chat receivedError:[NSNumber numberWithInt:AIChatUnknownError]];
+				[chat receivedError:[NSNumber numberWithInt:AIChatMessageSendingConnectionError]];
 				
 				AILogWithSignature(@"%@ Chat send error on %@", self, chat);
 			}
@@ -1896,7 +1915,7 @@
  * @brief Status updates received
  */
 - (void)statusesReceived:(NSArray *)statuses forRequest:(NSString *)identifier
-{		
+{
 	if([self requestTypeForRequestID:identifier] == AITwitterUpdateFollowedTimeline ||
 	   [self requestTypeForRequestID:identifier] == AITwitterUpdateReplies) {
 		NSString *lastID;
diff -r c759d36f6f23 -r 68b337afb9d4 Plugins/Twitter Plugin/AITwitterURLHandler.m
--- a/Plugins/Twitter Plugin/AITwitterURLHandler.m	Wed Nov 11 22:27:35 2009 -0500
+++ b/Plugins/Twitter Plugin/AITwitterURLHandler.m	Thu Nov 19 21:12:23 2009 -0500
@@ -98,8 +98,10 @@
 		// No exact match. Fail.
 		return;
 	}
-
-	if ([inAction isEqualToString:@"reply"] || [inAction isEqualToString:@"retweet"]) {
+	
+	if ([inAction isEqualToString:@"retweet"]) {
+		[account retweetTweet:inTweet];
+	} else if ([inAction isEqualToString:@"reply"]) {
 		AIChat *timelineChat = [adium.chatController existingChatWithName:account.timelineChatName
 																onAccount:account];
 		
@@ -120,13 +122,7 @@
 		AIMessageEntryTextView *textView = ((AIMessageTabViewItem *)[timelineChat valueForProperty:@"MessageTabViewItem"]).messageViewController.textEntryView;
 
 		// Insert the @reply text
-		NSString *prefix = nil;
-		
-		if (inMessage) {
-			prefix = [NSString stringWithFormat:@"RT @%@ %@", inUser, [inMessage stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
-		} else {
-			prefix = [NSString stringWithFormat:@"@%@ ", inUser];
-		}
+		NSString *prefix = [NSString stringWithFormat:@"@%@ ", inUser];
 		
 		if (![textView.string hasPrefix:prefix]) {
 			NSMutableAttributedString *newString;
diff -r c759d36f6f23 -r 68b337afb9d4 Plugins/Twitter Plugin/MGTwitterEngine/MGTwitterEngine.h
--- a/Plugins/Twitter Plugin/MGTwitterEngine/MGTwitterEngine.h	Wed Nov 11 22:27:35 2009 -0500
+++ b/Plugins/Twitter Plugin/MGTwitterEngine/MGTwitterEngine.h	Thu Nov 19 21:12:23 2009 -0500
@@ -128,6 +128,7 @@
 - (NSString *)sendUpdate:(NSString *)status inReplyTo:(NSString *)updateID;
 - (NSString *)deleteUpdate:(NSString *)updateID;                 // this user must be the AUTHOR
 - (NSString *)markUpdate:(NSString *)updateID asFavorite:(BOOL)flag;
+- (NSString *)retweetUpdate:(NSString *)updateID;
 
 // Sending and editing direct messages
 - (NSString *)sendDirectMessage:(NSString *)message to:(NSString *)username;
diff -r c759d36f6f23 -r 68b337afb9d4 Plugins/Twitter Plugin/MGTwitterEngine/MGTwitterEngine.m
--- a/Plugins/Twitter Plugin/MGTwitterEngine/MGTwitterEngine.m	Wed Nov 11 22:27:35 2009 -0500
+++ b/Plugins/Twitter Plugin/MGTwitterEngine/MGTwitterEngine.m	Thu Nov 19 21:12:23 2009 -0500
@@ -934,7 +934,7 @@
 
 - (NSString *)getFollowedTimelineFor:(NSString *)username since:(NSDate *)date startingAtPage:(int)pageNum count:(int)count
 {
-	NSString *path = @"statuses/friends_timeline.xml";
+	NSString *path = @"statuses/home_timeline.xml";
     
     NSMutableDictionary *params = [NSMutableDictionary dictionaryWithCapacity:0];
     if (date) {
@@ -944,7 +944,7 @@
         [params setObject:[NSString stringWithFormat:@"%d", pageNum] forKey:@"page"];
     }
     if (username) {
-        path = [NSString stringWithFormat:@"statuses/friends_timeline/%@.xml", username];
+        path = [NSString stringWithFormat:@"statuses/home_timeline/%@.xml", username];
     }
 	int tweetCount = DEFAULT_TWEET_COUNT;
 	if (count > 0) {
@@ -960,7 +960,7 @@
 
 - (NSString *)getFollowedTimelineFor:(NSString *)username sinceID:(NSString *)updateID startingAtPage:(int)pageNum count:(int)count
 {
-	NSString *path = @"statuses/friends_timeline.xml";
+	NSString *path = @"statuses/home_timeline.xml";
     
     NSMutableDictionary *params = [NSMutableDictionary dictionaryWithCapacity:0];
     if (updateID > 0) {
@@ -970,14 +970,14 @@
         [params setObject:[NSString stringWithFormat:@"%d", pageNum] forKey:@"page"];
     }
     if (username) {
-        path = [NSString stringWithFormat:@"statuses/friends_timeline/%@.xml", username];
+        path = [NSString stringWithFormat:@"statuses/home_timeline/%@.xml", username];
     }
 	int tweetCount = DEFAULT_TWEET_COUNT;
 	if (count > 0) {
 		tweetCount = count;
 	}
 	[params setObject:[NSString stringWithFormat:@"%d", tweetCount] forKey:@"count"];
-    
+	
     return [self _sendRequestWithMethod:nil path:path queryParameters:params body:nil 
                             requestType:MGTwitterStatusesRequest 
                            responseType:MGTwitterStatuses];
@@ -1318,6 +1318,14 @@
                            responseType:MGTwitterStatus];
 }
 
+- (NSString *)retweetUpdate:(NSString *)updateID
+{
+    NSString *path = [NSString stringWithFormat:@"statuses/retweet/%@.xml", updateID];
+    
+    return [self _sendRequestWithMethod:HTTP_POST_METHOD path:path queryParameters:nil body:nil 
+                            requestType:MGTwitterAccountRequest 
+                           responseType:MGTwitterStatus];	
+}
 
 #pragma mark Sending and editing direct messages
 
diff -r c759d36f6f23 -r 68b337afb9d4 Plugins/Twitter Plugin/MGTwitterEngine/MGTwitterStatusesParser.m
--- a/Plugins/Twitter Plugin/MGTwitterEngine/MGTwitterStatusesParser.m	Wed Nov 11 22:27:35 2009 -0500
+++ b/Plugins/Twitter Plugin/MGTwitterEngine/MGTwitterStatusesParser.m	Thu Nov 19 21:12:23 2009 -0500
@@ -26,12 +26,17 @@
         // Make new entry in parsedObjects.
         NSMutableDictionary *newNode = [NSMutableDictionary dictionaryWithCapacity:0];
         [parsedObjects addObject:newNode];
-        currentNode = newNode;
+        currentNode = newNode;		
     } else if ([elementName isEqualToString:@"user"]) {
         // Add a 'user' dictionary to current node.
         NSMutableDictionary *newNode = [NSMutableDictionary dictionaryWithCapacity:0];
         [currentNode setObject:newNode forKey:elementName];
         currentNode = newNode;
+	} else if ([elementName isEqualToString:@"retweeted_status"]) {
+        // Add a 'retweeted_status' dictionary to current node.
+        NSMutableDictionary *newNode = [NSMutableDictionary dictionaryWithCapacity:0];
+        [currentNode setObject:newNode forKey:elementName];
+        currentNode = newNode;		
     } else if (currentNode) {
         // Create relevant name-value pair.
         [currentNode setObject:[NSMutableString string] forKey:elementName];
@@ -54,7 +59,7 @@
 {
     [super parser:theParser didEndElement:elementName namespaceURI:namespaceURI qualifiedName:qName];
     
-    if ([elementName isEqualToString:@"user"]) {
+    if ([elementName isEqualToString:@"user"] || [elementName isEqualToString:@"retweeted_status"]) {
         currentNode = [parsedObjects lastObject];
     } else if ([elementName isEqualToString:@"status"]) {
         [self addSource];




More information about the commits mailing list