adium 2283:1d7bfd76c57f: Hide the Twitter control links in Growl...

commits at adium.im commits at adium.im
Sat May 23 20:14:32 UTC 2009


details:	http://hg.adium.im/adium/rev/1d7bfd76c57f
revision:	2283:1d7bfd76c57f
author:		Zachary West <zacw at adium.im>
date:		Sat May 23 16:14:25 2009 -0400

Hide the Twitter control links in Growl notifications (or any other events). Fixes #11811.

diffstat:

 Frameworks/Adium Framework/Source/AIContentControllerProtocol.h |   3 +
 Plugins/Twitter Plugin/AITwitterAccount.m                       |  14 ++--
 Source/AdiumMessageEvents.m                                     |  35 +++++++++++-
 3 files changed, 44 insertions(+), 8 deletions(-)

diffs (103 lines):

diff -r 1d32db0c6281 -r 1d7bfd76c57f Frameworks/Adium Framework/Source/AIContentControllerProtocol.h
--- a/Frameworks/Adium Framework/Source/AIContentControllerProtocol.h	Sat May 23 15:53:47 2009 -0400
+++ b/Frameworks/Adium Framework/Source/AIContentControllerProtocol.h	Sat May 23 16:14:25 2009 -0400
@@ -19,6 +19,9 @@
 #define KEY_FORMATTING_TEXT_COLOR			@"Default Text Color"
 #define KEY_FORMATTING_BACKGROUND_COLOR		@"Default Background Color"
 
+// Used to hide from events' descriptions parts of messages
+#define AIHiddenMessagePartAttributeName	@"AIHiddenMessagePart"
+
 //Not displayed, but used for internal identification of the encryption menu
 #define ENCRYPTION_MENU_TITLE						@"Encryption Menu"
 
diff -r 1d32db0c6281 -r 1d7bfd76c57f Plugins/Twitter Plugin/AITwitterAccount.m
--- a/Plugins/Twitter Plugin/AITwitterAccount.m	Sat May 23 15:53:47 2009 -0400
+++ b/Plugins/Twitter Plugin/AITwitterAccount.m	Sat May 23 16:14:25 2009 -0400
@@ -1440,9 +1440,10 @@
 	
 		[mutableMessage appendString:@")" withAttributes:nil];
 		
-		[mutableMessage addAttribute:AITwitterActionLinksAttributeName
-							   value:[NSNumber numberWithBool:YES]
-							   range:NSMakeRange(startIndex, mutableMessage.length - startIndex)];
+		[mutableMessage addAttributes:[NSDictionary dictionaryWithObjectsAndKeys:
+									   [NSNumber numberWithBool:YES], AITwitterActionLinksAttributeName,
+									   [NSNumber numberWithBool:YES], AIHiddenMessagePartAttributeName, nil]
+								range:NSMakeRange(startIndex, mutableMessage.length - startIndex)];
 	
 		return mutableMessage;
 	} else {
@@ -1480,9 +1481,10 @@
 	
 	[mutableMessage appendString:@")" withAttributes:nil];
 	
-	[mutableMessage addAttribute:AITwitterActionLinksAttributeName
-						   value:[NSNumber numberWithBool:YES]
-						   range:NSMakeRange(startIndex, mutableMessage.length - startIndex)];
+	[mutableMessage addAttributes:[NSDictionary dictionaryWithObjectsAndKeys:
+								   [NSNumber numberWithBool:YES], AITwitterActionLinksAttributeName,
+								   [NSNumber numberWithBool:YES], AIHiddenMessagePartAttributeName, nil]
+							range:NSMakeRange(startIndex, mutableMessage.length - startIndex)];
 	
 	return mutableMessage;
 }
diff -r 1d32db0c6281 -r 1d7bfd76c57f Source/AdiumMessageEvents.m
--- a/Source/AdiumMessageEvents.m	Sat May 23 15:53:47 2009 -0400
+++ b/Source/AdiumMessageEvents.m	Sat May 23 16:14:25 2009 -0400
@@ -24,6 +24,10 @@
 #import <AIUtilities/AIImageAdditions.h>
 #import <Adium/AIListGroup.h>
 
+ at interface AdiumMessageEvents()
+- (NSString *)stringFromMessageAttributedString:(NSAttributedString *)attributedString;
+ at end
+
 @implementation AdiumMessageEvents
 
 - (id)init
@@ -303,8 +307,8 @@
 	NSParameterAssert([userInfo isKindOfClass:[NSDictionary class]]);
 	
 	contentObject = [(NSDictionary *)userInfo objectForKey:@"AIContentObject"];
-	messageText = [[[contentObject message] attributedStringByConvertingAttachmentsToStrings] string];
-	
+	messageText = [self stringFromMessageAttributedString:contentObject.message];
+
 	if (includeSubject) {
 		
 		if ([eventID isEqualToString:CONTENT_MESSAGE_SENT]) {
@@ -365,6 +369,33 @@
 	return description;
 }
 
+/*!
+ * @brief Return a string fit for display.
+ *
+ * @param attributedString A message's attributed string.
+ * @return A string with any elements not fit for display in reference to the event removed.
+ */
+- (NSString *)stringFromMessageAttributedString:(NSAttributedString *)attributedString
+{
+	NSMutableAttributedString *mutableMessage = [[[attributedString attributedStringByConvertingAttachmentsToStrings] mutableCopy] autorelease];
+
+	NSRange messageRange = NSMakeRange(0, 0);
+	NSUInteger stringLength = attributedString.length;
+	
+	for (NSUInteger i = 0; i < stringLength; i+= messageRange.length) {
+		if ([mutableMessage attribute:AIHiddenMessagePartAttributeName
+							  atIndex:i
+				longestEffectiveRange:&messageRange
+							  inRange:NSMakeRange(i, stringLength - i)]) {
+			[mutableMessage deleteCharactersInRange:messageRange];
+			stringLength -= messageRange.length;
+			messageRange.length = 0;
+		}
+	}
+	
+	return [mutableMessage string];
+}
+
 - (NSImage *)imageForEventID:(NSString *)eventID
 {
 	static NSImage	*eventImage = nil;




More information about the commits mailing list