adium 2110:50283739d46c: Abstraction++; When a buddy doesn't hav...

commits at adium.im commits at adium.im
Thu May 7 03:17:58 UTC 2009


details:	http://hg.adium.im/adium/rev/50283739d46c
revision:	2110:50283739d46c
author:		Zachary West <zacw at adium.im>
date:		Wed May 06 23:17:51 2009 -0400

Abstraction++; When a buddy doesn't have a status message, grab the status text the prpl specifies for it.

This lets us not have to specialize the Jabber account to display "Not authorized" or errors. Instead, the prpl does it for us.

diffstat:

 Plugins/Purple Service/CBPurpleAccount.m       |  17 ++++++++-
 Plugins/Purple Service/ESPurpleJabberAccount.m |  32 ----------------
 2 files changed, 16 insertions(+), 33 deletions(-)

diffs (69 lines):

diff -r c589f88bd6d7 -r 50283739d46c Plugins/Purple Service/CBPurpleAccount.m
--- a/Plugins/Purple Service/CBPurpleAccount.m	Wed May 06 22:49:25 2009 -0400
+++ b/Plugins/Purple Service/CBPurpleAccount.m	Wed May 06 23:17:51 2009 -0400
@@ -255,7 +255,22 @@
 	PurpleStatus		*status = (presence ? purple_presence_get_active_status(presence) : NULL);
 	const char			*message = (status ? purple_status_get_attr_string(status, "message") : NULL);
 	
-	return (message ? [AIHTMLDecoder decodeHTML:[NSString stringWithUTF8String:message]] : nil);
+	// Get the plugin's status message for this buddy if they don't have a status message
+	if (!message) {
+		PurplePlugin				*prpl;
+		PurplePluginProtocolInfo  *prpl_info = ((prpl = purple_find_prpl(purple_account_get_protocol_id(account))) ?
+												PURPLE_PLUGIN_PROTOCOL_INFO(prpl) :
+												NULL);
+		
+		if (prpl_info && prpl_info->status_text) {
+			message = (prpl_info->status_text)(buddy);
+		}
+		
+		// These are HTML-stripped messages.
+		return message ? [NSAttributedString stringWithString:[NSString stringWithUTF8String:message]] : nil;
+	} else {
+		return [AIHTMLDecoder decodeHTML:[NSString stringWithUTF8String:message]];
+	}
 }
 
 /*!
diff -r c589f88bd6d7 -r 50283739d46c Plugins/Purple Service/ESPurpleJabberAccount.m
--- a/Plugins/Purple Service/ESPurpleJabberAccount.m	Wed May 06 22:49:25 2009 -0400
+++ b/Plugins/Purple Service/ESPurpleJabberAccount.m	Wed May 06 23:17:51 2009 -0400
@@ -476,38 +476,6 @@
 }
 
 #pragma mark Status Messages
-- (NSAttributedString *)statusMessageForPurpleBuddy:(PurpleBuddy *)b
-{
-	NSAttributedString *statusMessage = nil;
-	
-	JabberBuddy *jb = NULL;
-	PurpleConnection *gc = purple_account_get_connection(account);
-	const char *msg = NULL;
-	
-	if (gc && gc->proto_data) {
-		jb = jabber_buddy_find(gc->proto_data, purple_buddy_get_name(b), FALSE);
-	
-		if(jb && !PURPLE_BUDDY_IS_ONLINE(b) && (jb->subscription & JABBER_SUB_PENDING || !(jb->subscription & JABBER_SUB_TO))) {
-			msg = _("Not Authorized");
-		} else if(jb && !PURPLE_BUDDY_IS_ONLINE(b) && jb->error_msg) {
-			msg = jb->error_msg;
-		}
-	}
-	
-	if (msg) {
-		NSString *statusMessageString = [NSString stringWithUTF8String:msg];
-		
-		if (statusMessageString.length) {
-			statusMessage = [NSAttributedString stringWithString:statusMessageString];
-		}
-		
-	} else {
-		statusMessage = [super statusMessageForPurpleBuddy:b];
-	}
-	
-	return statusMessage;
-}
-
 - (NSString *)statusNameForPurpleBuddy:(PurpleBuddy *)buddy
 {
 	NSString		*statusName = nil;




More information about the commits mailing list