changeset 15946:e058328dc954

Patch from Zac West which (1) adds a message flag, PURPLE_MESSAGE_NOTIFY, used to indicate that a message is a protocol-level notification from a user ('buzz' in yahoo, 'nudge' in msn, for example) and (2) uses it along with improving the text displayed when sending/receiving buzzes and nudges. The addition of this flag means that a plugin could implement custom behavior, such as playing a sound or triggerring some other event, reliably and easily.
author Evan Schoenberg <evan.s@dreskin.net>
date Tue, 27 Mar 2007 03:06:35 +0000
parents 8bea220c0997
children a0f24a614a9d
files libpurple/conversation.h libpurple/protocols/msn/switchboard.c libpurple/protocols/yahoo/yahoo.c
diffstat 3 files changed, 23 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/libpurple/conversation.h	Sun Mar 25 20:22:52 2007 +0000
+++ b/libpurple/conversation.h	Tue Mar 27 03:06:35 2007 +0000
@@ -115,7 +115,8 @@
 	PURPLE_MESSAGE_DELAYED     = 0x0400, /**< Delayed message.         */
 	PURPLE_MESSAGE_RAW         = 0x0800, /**< "Raw" message - don't
 	                                        apply formatting         */
-	PURPLE_MESSAGE_IMAGES      = 0x1000  /**< Message contains images  */
+	PURPLE_MESSAGE_IMAGES      = 0x1000, /**< Message contains images  */
+	PURPLE_MESSAGE_NOTIFY      = 0x2000  /**< Message is a notification */
 
 } PurpleMessageFlags;
 
--- a/libpurple/protocols/msn/switchboard.c	Sun Mar 25 20:22:52 2007 +0000
+++ b/libpurple/protocols/msn/switchboard.c	Tue Mar 27 03:06:35 2007 +0000
@@ -955,7 +955,7 @@
 
 	str = g_strdup_printf(_("%s just sent you a Nudge!"), username);
 	g_free(username);
-	msn_switchboard_report_user(swboard, PURPLE_MESSAGE_SYSTEM, str);
+	msn_switchboard_report_user(swboard, PURPLE_MESSAGE_SYSTEM|PURPLE_MESSAGE_NOTIFY, str);
 	g_free(str);
 }
 
--- a/libpurple/protocols/yahoo/yahoo.c	Sun Mar 25 20:22:52 2007 +0000
+++ b/libpurple/protocols/yahoo/yahoo.c	Tue Mar 27 03:06:35 2007 +0000
@@ -859,10 +859,25 @@
 		purple_util_chrreplace(m, '\r', '\n');
 
 		if (!strcmp(m, "<ding>")) {
-			PurpleConversation *c = purple_conversation_new(PURPLE_CONV_TYPE_IM,
-			                                            purple_connection_get_account(gc), im->from);
-			purple_conv_im_write(PURPLE_CONV_IM(c), "", _("Buzz!!"), PURPLE_MESSAGE_NICK|PURPLE_MESSAGE_RECV,
-			                   im->time);
+			PurpleBuddy *buddy;
+			PurpleAccount *account;
+			PurpleConversation *c;
+			char *username, *str;
+			
+			account = purple_connection_get_account(gc);
+			c = purple_conversation_new(PURPLE_CONV_TYPE_IM, account, im->from);
+			
+			if ((buddy = purple_find_buddy(account, im->from)) != NULL)
+				username = g_markup_escape_text(purple_buddy_get_alias(buddy), -1);
+			else
+				username = g_markup_escape_text(im->from, -1);
+			
+			str = g_strdup_printf(_("%s just sent you a Buzz!"), username);
+			
+			purple_conversation_write(c, NULL, str, PURPLE_MESSAGE_SYSTEM|PURPLE_MESSAGE_NOTIFY, im->time);
+
+			g_free(username);
+			g_free(str);
 			g_free(m);
 			g_free(im);
 			continue;
@@ -3737,7 +3752,7 @@
 	purple_debug(PURPLE_DEBUG_INFO, "yahoo",
 	           "Sending <ding> on account %s to buddy %s.\n", username, c->name);
 	purple_conv_im_send(PURPLE_CONV_IM(c), "<ding>");
-	purple_conv_im_write(PURPLE_CONV_IM(c), "", _("Buzz!!"), PURPLE_MESSAGE_NICK|PURPLE_MESSAGE_SEND, time(NULL));
+	purple_conversation_write(c, NULL, _("You have just sent a Buzz!"), PURPLE_MESSAGE_SYSTEM, time(NULL));
 	return PURPLE_CMD_RET_OK;
 }