adium 5504:7f22572f0ffc: Modify the user icon updating for chats...

commits at adium.im commits at adium.im
Wed May 15 16:30:30 UTC 2013


details:	http://hg.adium.im/adium/rev/7f22572f0ffc
revision:	5504:7f22572f0ffc
branch:		adium-1.6
author:		Frank Dowsett <wixardy at adium.im>
date:		Wed May 15 12:30:12 2013 -0400

Modify the user icon updating for chats fixing #14446 and #16385.

diffs (63 lines):

diff -r 6ce9b9ca54fe -r 7f22572f0ffc Plugins/WebKit Message View/AIWebKitMessageViewController.m
--- a/Plugins/WebKit Message View/AIWebKitMessageViewController.m	Wed May 15 12:14:06 2013 -0400
+++ b/Plugins/WebKit Message View/AIWebKitMessageViewController.m	Wed May 15 12:30:12 2013 -0400
@@ -1363,7 +1363,7 @@
 			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.
@@ -1398,28 +1398,13 @@
 		}
 		
 		if (!webKitUserIconPath) webKitUserIconPath = @"";
-
-		/* We previously updated existing images with the below code.  There's a bug somewhere, and it results
-		 * in images being replaced with unknown-image question marks sometimes... though new images work fine.
-		 */
-#if 0
+		
+		//Update the icon in the chat
 		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];
-
-				webKitUserIconPath = [[webKitUserIconPath copy] autorelease];
-
-				for (unsigned 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];
-					}
-				}
+				[webView stringByEvaluatingJavaScriptFromString:[NSString stringWithFormat:@"document.body.innerHTML=document.body.innerHTML.replace(new RegExp('%@', 'g'), '%@');", oldWebKitUserIconPath, webKitUserIconPath]];
 			}
 			
 			[objectIconPathDict setObject:webKitUserIconPath
@@ -1427,16 +1412,12 @@
 		} 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];
 		}
-#else
-	[objectIconPathDict setObject:webKitUserIconPath
-						   forKey:iconSourceObject.internalObjectID];
-#endif
-    }
+	}
 }
 
 - (void)updateServiceIcon




More information about the commits mailing list