adium 4848:3e1b102439a8: Log /me messages as <action/> tags as ...

commits at adium.im commits at adium.im
Mon Jun 4 15:00:40 UTC 2012


details:	http://hg.adium.im/adium/rev/3e1b102439a8
revision:	4848:3e1b102439a8
branch:		(none)
author:		Frank Dowsett <wixardy at adium.im>
date:		Mon Jun 04 00:44:32 2012 -0400

Log /me messages as <action/> tags  as suggested in #13330. Some cleanup in the area also remedies #14079 by not relying on adding asterisks. Fixes #13330 and 14079.

diffs (126 lines):

diff -r 3860ca6e903c -r 3e1b102439a8 Source/AILoggerPlugin.m
--- a/Source/AILoggerPlugin.m	Sun Jun 03 00:45:17 2012 -0400
+++ b/Source/AILoggerPlugin.m	Mon Jun 04 00:44:32 2012 -0400
@@ -1057,7 +1057,12 @@
 					[attributeValues addObject:displayName];
 				}
 				
-				AIXMLElement *messageElement = [[[AIXMLElement alloc] initWithName:@"message"] autorelease];
+				AIXMLElement *messageElement;
+				if ([[content displayClasses] containsObject:@"action"]) {
+					messageElement = [[[AIXMLElement alloc] initWithName:@"action"] autorelease];
+				} else {
+					messageElement = [[[AIXMLElement alloc] initWithName:@"message"] autorelease];
+				}
 				
 				[messageElement addEscapedObject:[xhtmlDecoder encodeHTML:[content message]
 															   imagesPath:[appender.path stringByDeletingLastPathComponent]]];
diff -r 3860ca6e903c -r 3e1b102439a8 Source/AIXMLChatlogConverter.m
--- a/Source/AIXMLChatlogConverter.m	Sun Jun 03 00:45:17 2012 -0400
+++ b/Source/AIXMLChatlogConverter.m	Mon Jun 04 00:44:32 2012 -0400
@@ -197,7 +197,7 @@
         }
     }    
         
-    NSArray *elements = [xmlDoc nodesForXPath:@"//message | //status" error:&err];
+    NSArray *elements = [xmlDoc nodesForXPath:@"//message | //action | //status" error:&err];
     if (!elements) {
         goto ohno;
     }
@@ -207,7 +207,7 @@
      
         NSDictionary *attributes = [element AIAttributesAsDictionary];
         
-        if ([type isEqualToString:@"message"]) {
+        if ([type isEqualToString:@"message"] || [type isEqualToString:@"action"]) {
             NSString *senderAlias = [[attributes objectForKey:@"alias"] stringValue];
             NSString *dateStr = [[attributes objectForKey:@"time"] stringValue];
             NSDate *date = dateStr ? [NSCalendarDate calendarDateWithString:dateStr] : nil;
@@ -284,7 +284,16 @@
                                                                           direction:(sentMessage ? AIFilterOutgoing : AIFilterIncoming)
                                                                             context:nil];				
             }
-            [output appendAttributedString:attributedMessage];
+			
+			if ([type isEqualToString:@"action"]) {
+				NSMutableAttributedString *ourAttributedString = [[attributedMessage mutableCopy] autorelease];
+				[ourAttributedString replaceCharactersInRange:NSMakeRange(0, 0) withString:@"*"];
+				[ourAttributedString replaceCharactersInRange:NSMakeRange([ourAttributedString length], 0) withString:@"*"];
+				[output appendAttributedString:ourAttributedString];
+			} else {
+				[output appendAttributedString:attributedMessage];
+			}
+			
             [output appendAttributedString:newlineAttributedString];
         } else if ([type isEqualToString:@"status"]) {
             NSString *dateStr = [[attributes objectForKey:@"time"] stringValue];
diff -r 3860ca6e903c -r 3e1b102439a8 Source/CBActionSupportPlugin.m
--- a/Source/CBActionSupportPlugin.m	Sun Jun 03 00:45:17 2012 -0400
+++ b/Source/CBActionSupportPlugin.m	Mon Jun 04 00:44:32 2012 -0400
@@ -55,10 +55,8 @@
 	    [[inAttributedString string] rangeOfString:@"/me "
 										   options:NSCaseInsensitiveSearch].location == 0 ) {
 		NSMutableAttributedString *ourAttributedString = [[inAttributedString mutableCopy] autorelease];
-		NSAttributedString *dots = [[[NSAttributedString alloc] initWithString:@"*" attributes:[ourAttributedString attributesAtIndex:[ourAttributedString length] - 1 effectiveRange:NULL]] autorelease];
 		[ourAttributedString replaceCharactersInRange:NSMakeRange(0, 4)
-										   withString:@"*"];
-		[ourAttributedString appendAttributedString:dots];
+										   withString:@""];
 		[ourAttributedString addAttribute:AIActionMessageAttributeName
 									value:[NSNumber numberWithBool:YES]
 									range:NSMakeRange(0, [ourAttributedString length])];
@@ -73,7 +71,7 @@
 }
 
 /*!
- * @brief Transform the HTML from *foo* to the proper span structure
+ * @brief Transform the HTML from an action to the proper span structure
  */
 - (NSString *)filterHTMLString:(NSString *)inHTMLString content:(AIContentObject*)content;
 {	
@@ -81,11 +79,7 @@
 		AIContentMessage *message = (AIContentMessage *)content;
 		if([[[message message] attribute:AIActionMessageAttributeName atIndex:0 effectiveRange:NULL] boolValue]) {
 
-			NSMutableString *mutableHTML = [[inHTMLString mutableCopy] autorelease];
-			NSString *replaceString = [NSString stringWithFormat:@"<span class='actionMessageUserName'>%@</span><span class='actionMessageBody'>", [[content source] displayName]];
-			[mutableHTML replaceCharactersInRange:[mutableHTML rangeOfString:@"*"] withString:replaceString];
-			[mutableHTML replaceCharactersInRange:[mutableHTML rangeOfString:@"*" options:NSBackwardsSearch] withString:@"</span>"];
-			return mutableHTML;
+			return [NSString stringWithFormat:@"<span class='actionMessageUserName'>%@</span><span class='actionMessageBody'>%@</span>", [[content source] displayName], inHTMLString];
 		}
 	}
 	return inHTMLString;
diff -r 3860ca6e903c -r 3e1b102439a8 Source/DCMessageContextDisplayPlugin.m
--- a/Source/DCMessageContextDisplayPlugin.m	Sun Jun 03 00:45:17 2012 -0400
+++ b/Source/DCMessageContextDisplayPlugin.m	Mon Jun 04 00:44:32 2012 -0400
@@ -338,7 +338,8 @@
 	NSMutableDictionary *contextInfo = [parser contextInfo];
 	NSMutableArray *elementStack = [contextInfo objectForKey:@"ElementStack"];
 	
-	if ([elementName isEqualToString:@"message"] || ([[contextInfo valueForKey:@"AlsoAllowStatus"] boolValue] && [elementName isEqualToString:@"status"])) {
+	if ([elementName isEqualToString:@"message"] || [elementName isEqualToString:@"action"] ||
+		([[contextInfo valueForKey:@"AlsoAllowStatus"] boolValue] && [elementName isEqualToString:@"status"])) {
 		[elementStack insertObject:[AIXMLElement elementWithName:elementName] atIndex:0U];
 	}
 	else if ([elementStack count]) {
@@ -371,7 +372,7 @@
 		NSMutableArray	*foundMessages = [contextInfo objectForKey:@"FoundMessages"];
 		NSInteger	 *linesLeftToFind = [[contextInfo objectForKey:@"LinesLeftToFindValue"] pointerValue];
 		
-		if ([elementName isEqualToString:@"message"]) {
+		if ([elementName isEqualToString:@"message"] || [elementName isEqualToString:@"action"]) {
 			//A message element has started!
 			//This means that we have all of this message now, and therefore can create a single content object from the AIXMLElement tree and then throw away that tree.
 			//This saves memory when a message element contains many elements (since each one is represented by an AIXMLElement sub-tree in the AIXMLElement tree, as opposed to a simple NSAttributeRun in the NSAttributedString of the content object).
@@ -413,6 +414,10 @@
 																message:[[contextInfo objectForKey:@"AIHTMLDecoder"] decodeHTML:[element contentsAsXMLString]]
 															  autoreply:(autoreplyAttribute && [autoreplyAttribute caseInsensitiveCompare:@"true"] == NSOrderedSame)];
 				
+				//Properly style /me-type messages
+				if ([elementName isEqualToString:@"action"])
+					[message addDisplayClass:@"action"];
+				
 				//Don't log this object
 				[message setPostProcessContent:NO];
 				[message setTrackContent:NO];




More information about the commits mailing list