adium-1.4 2790:6de98889c273: If we try to update icons while the...

commits at adium.im commits at adium.im
Mon Nov 23 02:02:58 UTC 2009


details:	http://hg.adium.im/adium-1.4/rev/6de98889c273
revision:	2790:6de98889c273
author:		Evan Schoenberg
date:		Sun Nov 22 20:06:12 2009 -0600

If we try to update icons while the webview doesn't have an accessible documentFrame (e.g. while it is still working on loading its initial HTML), try again after a second. This fixes icons which are part of the initial bolus of information presented by a webview that change shortly after it loads, which can most noticeably happen when restoring a chat using a webview with icons in its header but could also occur if a user icon changed as we opened a chat window.

Fixes #12696
(transplanted from 9f11b96baf1deb5120072bcfae33620b0cbacc51)

diffs (122 lines):

diff -r 15a52a331071 -r 6de98889c273 Plugins/WebKit Message View/AIWebKitMessageViewController.m
--- a/Plugins/WebKit Message View/AIWebKitMessageViewController.m	Sun Nov 22 16:57:25 2009 -0600
+++ b/Plugins/WebKit Message View/AIWebKitMessageViewController.m	Sun Nov 22 20:06:12 2009 -0600
@@ -1250,9 +1250,9 @@
 			webKitUserIcon = userIcon;
 		}
 
-		oldWebKitUserIconPath = [objectIconPathDict objectForKey:iconSourceObject.internalObjectID];
+		oldWebKitUserIconPath = [objectIconPathDict objectForKey:iconSourceObject.internalObjectID];		
 		webKitUserIconPath = [iconSourceObject valueForProperty:KEY_WEBKIT_USER_ICON];
-
+		
 		if (!webKitUserIconPath) {
 			/* If the image doesn't know a path to use, write it out and set it.
 			 *
@@ -1266,8 +1266,10 @@
 													 atomically:YES]) {
 				[iconSourceObject setValue:webKitUserIconPath
 										   forProperty:KEY_WEBKIT_USER_ICON
-										   notify:NO];				
-			}			
+										   notify:NO];
+			} else {
+				AILogWithSignature(@"Warning: Could not write out icon to %@", webKitUserIconPath);
+			}
 		}
 
 		//Make sure it's known that this user has been handled
@@ -1282,27 +1284,35 @@
 		
 		if (!webKitUserIconPath) webKitUserIconPath = @"";
 
-		//Update existing images
-		AILogWithSignature(@"Updating %@ to %@", oldWebKitUserIconPath, webKitUserIconPath);
+		if ([webView mainFrameDocument]) {
+			//Update existing images if the webView has loaded and has a main frame
+			if (oldWebKitUserIconPath &&
+				![oldWebKitUserIconPath isEqualToString:webKitUserIconPath]) {
+				
+				DOMNodeList  *images = [[webView mainFrameDocument] getElementsByTagName:@"img"];
+				NSUInteger imagesCount = [images length];
 
-		if (oldWebKitUserIconPath &&
-			![oldWebKitUserIconPath isEqualToString:webKitUserIconPath]) {
-			DOMNodeList  *images = [[webView mainFrameDocument] getElementsByTagName:@"img"];
-			NSUInteger imagesCount = [images length];
+				webKitUserIconPath = [[webKitUserIconPath copy] autorelease];
 
-			webKitUserIconPath = [[webKitUserIconPath copy] autorelease];
-
-			for (NSInteger i = 0; i < imagesCount; i++) {
-				DOMHTMLImageElement *img = (DOMHTMLImageElement *)[images item:i];
-				NSString *currentSrc = [img getAttribute:@"src"];
-				if (currentSrc && ([currentSrc rangeOfString:oldWebKitUserIconPath].location != NSNotFound)) {
-					[img setSrc:webKitUserIconPath];
+				for (NSInteger i = 0; i < imagesCount; i++) {
+					DOMHTMLImageElement *img = (DOMHTMLImageElement *)[images item:i];
+					NSString *currentSrc = [img getAttribute:@"src"];
+					if (currentSrc && ([currentSrc rangeOfString:oldWebKitUserIconPath].location != NSNotFound)) {
+						[img setSrc:webKitUserIconPath];
+					}
 				}
 			}
+			
+			[objectIconPathDict setObject:webKitUserIconPath
+								   forKey:iconSourceObject.internalObjectID];
+		} else {
+			/* Otherwise, try to again in a moment. We've already done the heavy lifting
+			 * such as writing out the icon, so it's cheap to recurse.
+			 */			
+			[self performSelector:@selector(updateUserIconForObject:)
+					   withObject:inObject
+					   afterDelay:1];
 		}
-
-		[objectIconPathDict setObject:webKitUserIconPath
-							   forKey:iconSourceObject.internalObjectID];
 	}
 }
 
diff -r 15a52a331071 -r 6de98889c273 Plugins/WebKit Message View/AIWebkitMessageViewStyle.m
--- a/Plugins/WebKit Message View/AIWebkitMessageViewStyle.m	Sun Nov 22 16:57:25 2009 -0600
+++ b/Plugins/WebKit Message View/AIWebkitMessageViewStyle.m	Sun Nov 22 20:06:12 2009 -0600
@@ -1168,25 +1168,32 @@
 	
 	if (listObject) {
 		iconPath = [listObject valueForProperty:KEY_WEBKIT_USER_ICON];
-		if (!iconPath) {
+		if (!iconPath)
 			iconPath = [listObject valueForProperty:@"UserIconPath"];
-		}
+		
+		/* We couldn't get an icon... but perhaps we can for a parent contact */
+		if (!iconPath &&
+			[listObject isKindOfClass:[AIListContact class]] &&
+			([(AIListContact *)listObject parentContact] != listObject)) {
+			iconPath = [[(AIListContact *)listObject parentContact] valueForProperty:KEY_WEBKIT_USER_ICON];
+			if (!iconPath)
+				iconPath = [[(AIListContact *)listObject parentContact] valueForProperty:@"UserIconPath"];			
+		}		
 	}
 	[inString replaceKeyword:@"%incomingIconPath%"
 				  withString:(iconPath ? iconPath : @"incoming_icon.png")];
-	
+
 	AIListObject	*account = chat.account;
 	iconPath = nil;
 	
 	if (account) {
 		iconPath = [account valueForProperty:KEY_WEBKIT_USER_ICON];
-		if (!iconPath) {
+		if (!iconPath)
 			iconPath = [account valueForProperty:@"UserIconPath"];
-		}
 	}
 	[inString replaceKeyword:@"%outgoingIconPath%"
 				  withString:(iconPath ? iconPath : @"outgoing_icon.png")];
-	
+
 	NSString *serviceIconPath = [AIServiceIcons pathForServiceIconForServiceID:account.service.serviceID
 																		  type:AIServiceIconLarge];
 	




More information about the commits mailing list