# HG changeset patch # User Jeffrey Connelly # Date 1188081220 0 # Node ID 6395c2e96bc2ab8d9a92d418c9d9786cf2a46c13 # Parent 4fced00fdc9f630f9d63cebb4e0d37d4bea490d9 Attention API for nudges/buzzes/zaps of various protocols. (This API addition can now be committed since it we're in 2.2.0.) Patch also available at http://msimprpl.darkthoughts.net/attention3.diff. Closes #2662. diff -r 4fced00fdc9f -r 6395c2e96bc2 libpurple/prpl.h --- a/libpurple/prpl.h Sat Aug 25 05:41:25 2007 +0000 +++ b/libpurple/prpl.h Sat Aug 25 22:33:40 2007 +0000 @@ -30,6 +30,7 @@ #define _PURPLE_PRPL_H_ typedef struct _PurplePluginProtocolInfo PurplePluginProtocolInfo; +typedef struct _PurpleAttentionType PurpleAttentionType; /**************************************************************************/ /** @name Basic Protocol Information */ @@ -91,6 +92,14 @@ gboolean secret; }; +struct _PurpleAttentionType +{ + const char *icon_name; /**< Icon to display (optional) */ + const char *name; /**< Shown in GUI elements */ + const char *incoming_description; /**< Shown when sent */ + const char *outgoing_description; /**< Shown when receied */ +}; + /** * Protocol options * @@ -332,8 +341,10 @@ /* room list serialize */ char *(*roomlist_room_serialize)(PurpleRoomlistRoom *room); - void (*_purple_reserved1)(void); - void (*_purple_reserved2)(void); + /* Attention API for sending & receiving zaps/nudges/buzzes etc. */ + gboolean (*send_attention)(PurpleConnection *gc, + const char *username, guint type); + GList *(*attention_types)(PurpleAccount *acct); void (*_purple_reserved3)(void); void (*_purple_reserved4)(void); }; diff -r 4fced00fdc9f -r 6395c2e96bc2 libpurple/server.c --- a/libpurple/server.c Sat Aug 25 05:41:25 2007 +0000 +++ b/libpurple/server.c Sat Aug 25 22:33:40 2007 +0000 @@ -242,6 +242,75 @@ } } +/** Indicate that an attention message was sent or received. */ +void +serv_got_attention(PurpleConnection *gc, const char *who, PurpleAttentionType *attn, gboolean incoming) +{ + PurpleConversation *conv; + PurpleMessageFlags flags; + gchar *description; + int plugin_return; + + + /* For incoming messages, block the attention message if requested (privacy) */ + if (incoming) { + gchar *who_copy; + + if (PURPLE_PLUGIN_PROTOCOL_INFO(gc->prpl)->set_permit_deny == NULL) + if (!purple_privacy_check(gc->account, who)) + return; + + conv = purple_find_conversation_with_account(PURPLE_CONV_TYPE_IM, who, gc->account); + + who_copy = g_strdup(who); + + plugin_return = GPOINTER_TO_INT( + purple_signal_emit_return_1(purple_conversations_get_handle(), + "receiving-im-msg", gc->account, + &who_copy, &attn, conv)); + + if (!attn || !who_copy || plugin_return) { + g_free(who_copy); + return; + } + + purple_signal_emit(purple_conversations_get_handle(), "received-im-msg", gc->account, + who, attn, conv); + } + + /* The attention message was allowed. Create a string representing the message. */ + flags = PURPLE_MESSAGE_SYSTEM; + + /* TODO: if (attn->icon_name) is non-null, use it to lookup an emoticon and display + * it next to the attention command. And if it is null, display a generic icon. */ + + if (incoming) { + if (attn->incoming_description) { + description = g_strdup_printf(_("Attention! You have been %s."), attn->incoming_description); + } else { + description = g_strdup(_("Attention!")); + } + flags |= PURPLE_MESSAGE_RECV; + } else { + if (attn->outgoing_description) { + description = g_strdup_printf(_("Attention! %s %s."), attn->outgoing_description, who); + } else { + description = g_strdup(_("Attention!")); + } + flags |= PURPLE_MESSAGE_SEND; + } + + /* Display it in the conversation window to the user. */ + conv = purple_find_conversation_with_account(PURPLE_CONV_TYPE_IM, who, gc->account); + if (!conv) + conv = purple_conversation_new(PURPLE_CONV_TYPE_IM, gc->account, who); + + purple_conv_im_write(PURPLE_CONV_IM(conv), NULL, description, flags, time(NULL)); + + g_free(description); +} + + /* * Move a buddy from one group to another on server. * diff -r 4fced00fdc9f -r 6395c2e96bc2 libpurple/server.h --- a/libpurple/server.h Sat Aug 25 05:41:25 2007 +0000 +++ b/libpurple/server.h Sat Aug 25 22:33:40 2007 +0000 @@ -67,6 +67,7 @@ int serv_chat_send(PurpleConnection *, int, const char *, PurpleMessageFlags flags); void serv_alias_buddy(PurpleBuddy *); void serv_got_alias(PurpleConnection *gc, const char *who, const char *alias); +void serv_got_attention(PurpleConnection *gc, const char *who, struct _PurpleAttentionType *attn, gboolean incoming); /** * Receive a typing message from a remote user. Either PURPLE_TYPING