diff libpurple/protocols/yahoo/yahoo.c @ 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 32c366eeeb99
children e0c9a46b459f 08db93bbd798 ac9d28bba272 be098f796b32
line wrap: on
line diff
--- 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;
 }