adium 3484:8e7c971af12a: Special case '/say' to send raw text. R...

commits at adium.im commits at adium.im
Mon Nov 1 23:42:07 UTC 2010


details:	http://hg.adium.im/adium/rev/8e7c971af12a
revision:	3484:8e7c971af12a
author:		Evan Schoenberg
date:		Mon Nov 01 18:39:31 2010 -0500

Special case '/say' to send raw text. Remaining problem is that '/say ' is still shown in the message on the sender's side; fixing this is far too nontrivial to interest me, and I believe that making it possible would require some deep architectural changes
(transplanted from ae74443037560c9020d8428c616ba952871dd1ca)

diffs (60 lines):

diff -r d5fbf9b47b6f -r 8e7c971af12a Plugins/Purple Service/ESIRCAccount.m
--- a/Plugins/Purple Service/ESIRCAccount.m	Mon Nov 01 18:41:38 2010 -0500
+++ b/Plugins/Purple Service/ESIRCAccount.m	Mon Nov 01 18:39:31 2010 -0500
@@ -173,20 +173,35 @@
 {
 
 	NSString	*encodedString = nil;
-	BOOL		didCommand = [self.purpleAdapter attemptPurpleCommandOnMessage:inContentMessage.message.string
+	NSString	*messageString = inContentMessage.message.string;
+	BOOL		didCommand = [self.purpleAdapter attemptPurpleCommandOnMessage:messageString
 																   fromAccount:(AIAccount *)inContentMessage.source
 																	    inChat:inContentMessage.chat];
 	
-	NSRange meRange = [inContentMessage.message.string rangeOfString:@"/me " options:NSCaseInsensitiveSearch];
-
-	if (!didCommand || meRange.location == 0) {
-		if (meRange.location == 0) {
+	BOOL hasSlashMe = ([messageString rangeOfString:@"/me " options:(NSCaseInsensitiveSearch | NSAnchoredSearch)].location == 0);
+	
+	/* /say is a special case; it's not actually a command, but an instruction to display the following text (even if
+	 * that text would normally be a command itself).
+	 */
+	BOOL hasSlashSay = ([messageString rangeOfString:@"/say " options:(NSCaseInsensitiveSearch | NSAnchoredSearch)].location == 0);
+	
+	if (!didCommand || hasSlashMe) {
+		if (hasSlashMe) {
 			inContentMessage.sendContent = NO;
 		}
-		/* If we're sending a message on an encryption chat (can this even happen on irc?), we can encode the HTML normally, as links will go through fine.
-		 * If we're sending a message normally, IRC will drop the title of any link, so we preprocess it to be in the form "title (link)"
+		/* If we're sending a message on an encrypted direct msg, we can encode the HTML normally, as links will go through fine.
+		 * However, in all other cases, IRC will drop the title of any link, so we preprocess it to be in the form "title (link)"
 		 */
-		encodedString = [AIHTMLDecoder encodeHTML:(inContentMessage.chat.isSecure ? inContentMessage.message : [inContentMessage.message attributedStringByConvertingLinksToURLStrings])
+		NSAttributedString *messageAttributedString = inContentMessage.message;
+		
+		/* Remove the "/say" */
+		if (hasSlashSay)
+			messageAttributedString = [messageAttributedString attributedSubstringFromRange:NSMakeRange(@"/say ".length, 
+																										messageAttributedString.length - @"/say ".length)];
+		
+		encodedString = [AIHTMLDecoder encodeHTML:(inContentMessage.chat.isSecure ? 
+												   messageAttributedString :
+												   [messageAttributedString attributedStringByConvertingLinksToURLStrings])
 										  headers:NO
 										 fontTags:YES
 							   includingColorTags:YES
@@ -203,9 +218,10 @@
 							  allowJavascriptURLs:YES];
 	}
 	
-	if (!didCommand && [inContentMessage.message.string hasPrefix:@"/"]) {
+	
+	if (!didCommand && !hasSlashSay && [messageString hasPrefix:@"/"]) {
 		// Try to send it to the server, if we don't know what it is; definitely don't display.
-		[self sendRawCommand:[inContentMessage.message.string substringFromIndex:1]];
+		[self sendRawCommand:[messageString substringFromIndex:1]];
 		return nil;
 	} else {
 		return encodedString;




More information about the commits mailing list