Mercurial > pidgin.yaz
comparison libpurple/server.c @ 19461:1b5e786d137a
In the attention API, use the PURPLE_NOTIFY_MESSAGE flag to serv_got_im()
instead of manually writing to the conversation window, as suggested by sadrul
at http://pidgin.im/pipermail/devel/2007-August/002935.html. Yahoo and MSN
already use this flag to indicate an attention/notify-type message.
Also split off half of serv_got_attention() into serv_send_attention(), see
http://pidgin.im/pipermail/devel/2007-August/002940.html.
Now the attention API integrates well with the patch to add
PURPLE_MESSAGE_NOTIFY at http://hiks.net/drop/adium/libgaim.diff.
See also: https://sourceforge.net/tracker/?func=detail&atid=300235&aid=1672389&group_id=235
author | Jeffrey Connelly <jaconnel@calpoly.edu> |
---|---|
date | Mon, 27 Aug 2007 01:36:21 +0000 |
parents | 3ad938b84843 |
children | 3f6f84d11ce2 |
comparison
equal
deleted
inserted
replaced
19460:e5f73cebcb36 | 19461:1b5e786d137a |
---|---|
240 g_free(tmp); | 240 g_free(tmp); |
241 } | 241 } |
242 } | 242 } |
243 } | 243 } |
244 | 244 |
245 /** Indicate that an attention message was sent or received. */ | 245 PurpleAttentionType *purple_get_attention_type_from_code(PurpleAccount *account, guint type_code) |
246 { | |
247 PurplePlugin *prpl; | |
248 PurpleAttentionType* attn; | |
249 GList *(*function)(PurpleAccount *); | |
250 | |
251 g_return_val_if_fail(account != NULL, NULL); | |
252 | |
253 prpl = purple_find_prpl(purple_account_get_protocol_id(account)); | |
254 | |
255 /* Lookup the attention type in the protocol's attention_types list, if any. */ | |
256 function = PURPLE_PLUGIN_PROTOCOL_INFO(prpl)->attention_types; | |
257 if (function) { | |
258 GList *attention_types; | |
259 | |
260 attention_types = function(account); | |
261 attn = (PurpleAttentionType *)g_list_nth_data(attention_types, type_code); | |
262 } else { | |
263 attn = NULL; | |
264 } | |
265 | |
266 return attn; | |
267 } | |
268 | |
246 void | 269 void |
247 serv_got_attention(PurpleConnection *gc, const char *who, PurpleAttentionType *attn, gboolean incoming) | 270 serv_send_attention(PurpleConnection *gc, const char *who, guint type_code) |
248 { | 271 { |
249 PurpleConversation *conv; | 272 PurpleAttentionType *attn; |
250 PurpleMessageFlags flags; | 273 PurpleMessageFlags flags; |
251 gchar *description; | 274 gchar *description; |
252 int plugin_return; | 275 time_t mtime; |
253 | 276 |
254 | 277 g_return_if_fail(gc != NULL); |
255 /* For incoming messages, block the attention message if requested (privacy) */ | 278 g_return_if_fail(who != NULL); |
256 if (incoming) { | 279 |
257 gchar *who_copy; | 280 mtime = time(NULL); |
258 | 281 |
259 if (PURPLE_PLUGIN_PROTOCOL_INFO(gc->prpl)->set_permit_deny == NULL) | 282 attn = purple_get_attention_type_from_code(gc->account, type_code); |
260 if (!purple_privacy_check(gc->account, who)) | 283 |
261 return; | 284 if (attn && attn->outgoing_description) { |
262 | 285 description = g_strdup_printf(_("Attention! %s %s."), attn->outgoing_description, who); |
263 conv = purple_find_conversation_with_account(PURPLE_CONV_TYPE_IM, who, gc->account); | 286 } else { |
264 | 287 description = g_strdup(_("Attention!")); |
265 who_copy = g_strdup(who); | 288 } |
266 | 289 |
267 plugin_return = GPOINTER_TO_INT( | 290 flags = PURPLE_MESSAGE_SEND | PURPLE_MESSAGE_NOTIFY | PURPLE_MESSAGE_SYSTEM; |
268 purple_signal_emit_return_1(purple_conversations_get_handle(), | 291 |
269 "receiving-im-attention", gc->account, | 292 /* TODO: icons, sound, shaking... same as serv_got_attention(). */ |
270 &who_copy, attn->icon_name, attn->name, | 293 |
271 attn->incoming_description, | 294 serv_got_im(gc, who, description, flags, mtime); |
272 attn->outgoing_description, conv)); | 295 |
273 | 296 g_free(description); |
274 if (!attn || !who_copy || plugin_return) { | 297 } |
275 g_free(who_copy); | 298 |
276 return; | 299 void |
277 } | 300 serv_got_attention(PurpleConnection *gc, const char *who, guint type_code) |
278 | 301 { |
279 purple_signal_emit(purple_conversations_get_handle(), "received-im-attention", gc->account, | 302 PurpleMessageFlags flags; |
280 who, attn->icon_name, attn->name, | 303 PurpleAttentionType *attn; |
281 attn->incoming_description, attn->outgoing_description, conv); | 304 gchar *description; |
282 } | 305 time_t mtime; |
283 | 306 |
284 /* The attention message was allowed. Create a string representing the message. */ | 307 mtime = time(NULL); |
285 flags = PURPLE_MESSAGE_SYSTEM; | 308 |
309 attn = purple_get_attention_type_from_code(gc->account, type_code); | |
310 | |
311 /* PURPLE_MESSAGE_NOTIFY is for attention messages. */ | |
312 flags = PURPLE_MESSAGE_SYSTEM | PURPLE_MESSAGE_NOTIFY | PURPLE_MESSAGE_RECV; | |
286 | 313 |
287 /* TODO: if (attn->icon_name) is non-null, use it to lookup an emoticon and display | 314 /* TODO: if (attn->icon_name) is non-null, use it to lookup an emoticon and display |
288 * it next to the attention command. And if it is null, display a generic icon. */ | 315 * it next to the attention command. And if it is null, display a generic icon. */ |
289 | 316 |
290 if (incoming) { | 317 if (attn && attn->incoming_description) { |
291 if (attn->incoming_description) { | 318 description = g_strdup_printf(_("Attention! You have been %s."), attn->incoming_description); |
292 description = g_strdup_printf(_("Attention! You have been %s."), attn->incoming_description); | |
293 } else { | |
294 description = g_strdup(_("Attention!")); | |
295 } | |
296 flags |= PURPLE_MESSAGE_RECV; | |
297 } else { | 319 } else { |
298 if (attn->outgoing_description) { | 320 description = g_strdup(_("Attention!")); |
299 description = g_strdup_printf(_("Attention! %s %s."), attn->outgoing_description, who); | 321 } |
300 } else { | 322 |
301 description = g_strdup(_("Attention!")); | 323 serv_got_im(gc, who, description, flags, mtime); |
302 } | 324 |
303 flags |= PURPLE_MESSAGE_SEND; | 325 /* TODO: sounds (depending on PurpleAttentionType), shaking, etc. */ |
304 } | |
305 | |
306 /* Display it in the conversation window to the user. */ | |
307 conv = purple_find_conversation_with_account(PURPLE_CONV_TYPE_IM, who, gc->account); | |
308 if (!conv) | |
309 conv = purple_conversation_new(PURPLE_CONV_TYPE_IM, gc->account, who); | |
310 | |
311 purple_conv_im_write(PURPLE_CONV_IM(conv), NULL, description, flags, time(NULL)); | |
312 | 326 |
313 g_free(description); | 327 g_free(description); |
314 } | 328 } |
315 | 329 |
316 | 330 |