adium 5514:35741452f610: Store the URL of Twitter avatars to pre...

commits at adium.im commits at adium.im
Sun May 26 14:26:58 UTC 2013


details:	http://hg.adium.im/adium/rev/35741452f610
revision:	5514:35741452f610
branch:		adium-1.5.7
author:		Frank Dowsett <wixardy at adium.im>
date:		Sun May 12 13:43:38 2013 -0400

Store the URL of Twitter avatars to prevent requesting ones that we already have.
(transplanted from ba73efba03535135368adf2c06a051a2ba09a69e)
Subject: adium 5515:878a85a40504: Show retweets as being from the original tweeter. Fixes #16242

details:	http://hg.adium.im/adium/rev/878a85a40504
revision:	5515:878a85a40504
branch:		adium-1.5.7
author:		Frank Dowsett <wixardy at adium.im>
date:		Thu May 23 11:28:15 2013 -0400

Show retweets as being from the original tweeter. Fixes #16242

If someone has a better way to identify the retweeter, that'd be awesome.
(transplanted from 15c77b70f583dd3a6104e639687350c0433465cf)

diffs (161 lines):

diff -r bff389662124 -r 878a85a40504 Plugins/Twitter Plugin/AITwitterAccount.h
--- a/Plugins/Twitter Plugin/AITwitterAccount.h	Sat May 11 23:04:13 2013 -0400
+++ b/Plugins/Twitter Plugin/AITwitterAccount.h	Thu May 23 11:28:15 2013 -0400
@@ -95,6 +95,7 @@
 #define TWITTER_TIMELINE_NAME				@"Timeline (%@)"
 
 #define TWITTER_PROPERTY_REQUESTED_USER_ICON	@"Twitter Requested User Icon"
+#define TWITTER_PROPERTY_USER_ICON_URL			@"Twitter User Icon URL"
 
 #define TWITTER_PREFERENCE_UPDATE_AFTER_SEND		@"Update After Send"
 #define TWITTER_PREFERENCE_UPDATE_GLOBAL			@"Update Global Status"
diff -r bff389662124 -r 878a85a40504 Plugins/Twitter Plugin/AITwitterAccount.m
--- a/Plugins/Twitter Plugin/AITwitterAccount.m	Sat May 11 23:04:13 2013 -0400
+++ b/Plugins/Twitter Plugin/AITwitterAccount.m	Thu May 23 11:28:15 2013 -0400
@@ -1027,6 +1027,9 @@
 {
 	// If we don't already have an icon for the user...
 	if(![listContact boolValueForProperty:TWITTER_PROPERTY_REQUESTED_USER_ICON]) {
+		if ([[listContact valueForKey:TWITTER_PROPERTY_USER_ICON_URL] isEqualToString:url])
+			return;
+		
 		[listContact setValue:[NSNumber numberWithBool:YES] forProperty:TWITTER_PROPERTY_REQUESTED_USER_ICON notify:NotifyNever];
 		
 		// Grab the user icon and set it as their serverside icon.
@@ -1044,6 +1047,7 @@
 												notify:NotifyLater];
 					
 					[listContact setValue:nil forProperty:TWITTER_PROPERTY_REQUESTED_USER_ICON notify:NotifyNever];
+					[listContact setValue:url forProperty:TWITTER_PROPERTY_USER_ICON_URL afterDelay:NotifyNever];
 				});
 			} else {
 				[self requestFailed:AITwitterUserIconPull withError:error userInfo:@{ @"ListContact" : listContact }];
@@ -1053,6 +1057,25 @@
 }
 
 /*!
+ * @brief Update the display name, icon, and status of the list contact.
+ */
+- (void)updateContact:(AIListContact *)listContact withInfo:(NSDictionary *)userInfo andStatusMessage:(NSAttributedString *)message
+{
+	// Grab the Twitter display name and set it as the remote alias.
+	NSString *displayName = [userInfo objectForKey:TWITTER_INFO_DISPLAY_NAME];
+	if (![[listContact valueForProperty:@"serverDisplayName"] isEqualToString:displayName]) {
+		[listContact setServersideAlias:displayName
+							   silently:silentAndDelayed];
+	}
+	
+	// Update the user's status message
+	[listContact setStatusMessage:message
+						   notify:NotifyLater];
+	
+	[self updateUserIcon:[userInfo objectForKey:TWITTER_INFO_ICON] forContact:listContact];
+}
+
+/*!
  * @brief Unfollow the requested contacts.
  */
 - (void)removeContacts:(NSArray *)objects fromGroups:(NSArray *)groups
@@ -1520,19 +1543,8 @@
 					  inReplyToUser:(NSString *)replyUserID
 				   inReplyToTweetID:(NSString *)replyTweetID
 {
-	NSMutableAttributedString *mutableMessage;
-	NSDictionary    *retweet = [inStatus objectForKey:TWITTER_STATUS_RETWEET];
-	
-	if (retweet && [retweet isKindOfClass:[NSDictionary class]]) {
-		NSString *text = [[retweet objectForKey:TWITTER_STATUS_TEXT] stringByUnescapingFromXMLWithEntities:nil];
-		mutableMessage = [[NSMutableAttributedString alloc] initWithString:text];
-		[mutableMessage replaceCharactersInRange:NSMakeRange(0, 0)
-									  withString:[NSString stringWithFormat:@"RT @%@: ",
-										[[retweet objectForKey:TWITTER_STATUS_USER] objectForKey:TWITTER_STATUS_UID]]];
-	} else {
-		NSString *text = [[inStatus objectForKey:TWITTER_STATUS_TEXT] stringByUnescapingFromXMLWithEntities:nil];
-		mutableMessage = [[NSMutableAttributedString alloc] initWithString:text];
-	}
+	NSString *text = [[inStatus objectForKey:TWITTER_STATUS_TEXT] stringByUnescapingFromXMLWithEntities:nil];
+	NSMutableAttributedString *mutableMessage = [[NSMutableAttributedString alloc] initWithString:text];
 	
 	//Extract hashtags, users, and URLs
 	NSDictionary *entities = [inStatus objectForKey:@"entities"];
@@ -1817,6 +1829,15 @@
 		[[AIContactObserverManager sharedManager] delayListObjectNotifications];
 		
 		for (NSDictionary *status in sortedQueuedUpdates) {
+			NSDate *date = [status objectForKey:TWITTER_STATUS_CREATED];
+			
+			NSDictionary    *retweet = [status objectForKey:TWITTER_STATUS_RETWEET];
+			NSString *retweeter = nil;
+			if (retweet && [retweet isKindOfClass:[NSDictionary class]]) {
+				retweeter = [[status objectForKey:TWITTER_STATUS_USER] objectForKey:TWITTER_STATUS_UID];
+				status = retweet;
+			}
+			
 			NSString *contactUID = [[status objectForKey:TWITTER_STATUS_USER] objectForKey:TWITTER_STATUS_UID];
 			NSAttributedString *message = [self parseStatus:status
 													tweetID:[status objectForKey:TWITTER_STATUS_ID]
@@ -1824,18 +1845,26 @@
 											  inReplyToUser:[status objectForKey:TWITTER_STATUS_REPLY_UID]
 										   inReplyToTweetID:[status objectForKey:TWITTER_STATUS_REPLY_ID]];
 			
-			NSDate			*date = [status objectForKey:TWITTER_STATUS_CREATED];
+			//Add a link to the retweeter
+			if (retweeter) {
+				NSMutableAttributedString *m = [[message mutableCopy] autorelease];
+				NSString *linkURL = [self addressForLinkType:AITwitterLinkUserPage
+													  userID:retweeter
+													statusID:nil
+													 context:nil];
+				NSAttributedString *rt = [NSAttributedString attributedStringWithString:[NSString stringWithFormat:@" [@%@]", retweeter]
+																			  linkRange:NSMakeRange(2, retweeter.length+1)
+																		linkDestination:linkURL];
+				[m appendAttributedString:rt];
+				message = m;
+			}
 			
 			id fromObject = nil;
 			
 			if (![self.UID isCaseInsensitivelyEqualToString:contactUID]) {
 				AIListContact *listContact = [self contactWithUID:contactUID];
 				
-				// Update the user's status message
-				[listContact setStatusMessage:message
-									   notify:NotifyNow];
-				
-				[self updateUserIcon:[[status objectForKey:TWITTER_STATUS_USER] objectForKey:TWITTER_INFO_ICON] forContact:listContact];
+				[self updateContact:listContact withInfo:[status objectForKey:TWITTER_STATUS_USER] andStatusMessage:message];
 				
 				[timelineChat addParticipatingListObject:listContact notify:NotifyNow];
 				
@@ -2205,26 +2234,17 @@
 					[listContact addRemoteGroupName:self.timelineGroupName];
 				}
 				
-				// Grab the Twitter display name and set it as the remote alias.
-				if (![[listContact valueForProperty:@"serverDisplayName"] isEqualToString:[user objectForKey:TWITTER_INFO_DISPLAY_NAME]]) {
-					[listContact setServersideAlias:[user objectForKey:TWITTER_INFO_DISPLAY_NAME]
-										   silently:silentAndDelayed];
-				}
-				
-				// Grab the user icon and set it as their serverside icon.
-				[self updateUserIcon:[user objectForKey:TWITTER_INFO_ICON] forContact:listContact];
+				// Set the user's status message to their current twitter status text
+				NSString *statusText = [[user objectForKey:TWITTER_INFO_STATUS] objectForKey:TWITTER_INFO_STATUS_TEXT] ?: @"";
+				[self updateContact:listContact
+						   withInfo:user
+				   andStatusMessage:[NSAttributedString stringWithString:[statusText stringByUnescapingFromXMLWithEntities:nil]]];
 				
 				// Set the user as available.
 				[listContact setStatusWithName:nil
 									statusType:AIAvailableStatusType
 										notify:NotifyLater];
 				
-				// Set the user's status message to their current twitter status text
-				NSString *statusText = [[user objectForKey:TWITTER_INFO_STATUS] objectForKey:TWITTER_INFO_STATUS_TEXT];
-				if (!statusText) //nil if they've never tweeted
-					statusText = @"";
-				[listContact setStatusMessage:[NSAttributedString stringWithString:[statusText stringByUnescapingFromXMLWithEntities:nil]] notify:NotifyLater];
-				
 				// Set the user as online.
 				[listContact setOnline:YES notify:NotifyLater silently:silentAndDelayed];
 				




More information about the commits mailing list