Mercurial > pidgin
comparison libpurple/protocols/jabber/jabber.c @ 25136:a64d90cff01f
Allow the /buzz command without argument (sends attention to the JID of the
current conversation).
Use functions in buddy.h to determine support.
Allow attention in all statuses except "unavailabe/dnd"
author | Marcus Lundblad <ml@update.uu.se> |
---|---|
date | Sun, 12 Oct 2008 17:38:32 +0000 |
parents | f763be370afb |
children | b3ab1c23cdf6 ff0470db521d |
comparison
equal
deleted
inserted
replaced
25135:6baa6a829a90 | 25136:a64d90cff01f |
---|---|
1682 "priority", _("Priority"), priority_value, | 1682 "priority", _("Priority"), priority_value, |
1683 "message", _("Message"), purple_value_new(PURPLE_TYPE_STRING), | 1683 "message", _("Message"), purple_value_new(PURPLE_TYPE_STRING), |
1684 "mood", _("Mood"), purple_value_new(PURPLE_TYPE_STRING), | 1684 "mood", _("Mood"), purple_value_new(PURPLE_TYPE_STRING), |
1685 "moodtext", _("Mood Text"), purple_value_new(PURPLE_TYPE_STRING), | 1685 "moodtext", _("Mood Text"), purple_value_new(PURPLE_TYPE_STRING), |
1686 "nick", _("Nickname"), purple_value_new(PURPLE_TYPE_STRING), | 1686 "nick", _("Nickname"), purple_value_new(PURPLE_TYPE_STRING), |
1687 "buzz", _("Allow Buzz"), buzz_enabled, | |
1687 NULL); | 1688 NULL); |
1688 types = g_list_append(types, type); | 1689 types = g_list_append(types, type); |
1689 | 1690 |
1690 priority_value = purple_value_new(PURPLE_TYPE_INT); | 1691 priority_value = purple_value_new(PURPLE_TYPE_INT); |
1691 purple_value_set_int(priority_value, 0); | 1692 purple_value_set_int(priority_value, 0); |
1695 "priority", _("Priority"), priority_value, | 1696 "priority", _("Priority"), priority_value, |
1696 "message", _("Message"), purple_value_new(PURPLE_TYPE_STRING), | 1697 "message", _("Message"), purple_value_new(PURPLE_TYPE_STRING), |
1697 "mood", _("Mood"), purple_value_new(PURPLE_TYPE_STRING), | 1698 "mood", _("Mood"), purple_value_new(PURPLE_TYPE_STRING), |
1698 "moodtext", _("Mood Text"), purple_value_new(PURPLE_TYPE_STRING), | 1699 "moodtext", _("Mood Text"), purple_value_new(PURPLE_TYPE_STRING), |
1699 "nick", _("Nickname"), purple_value_new(PURPLE_TYPE_STRING), | 1700 "nick", _("Nickname"), purple_value_new(PURPLE_TYPE_STRING), |
1701 "buzz", _("Allow Buzz"), buzz_enabled, | |
1700 NULL); | 1702 NULL); |
1701 types = g_list_append(types, type); | 1703 types = g_list_append(types, type); |
1702 | 1704 |
1703 priority_value = purple_value_new(PURPLE_TYPE_INT); | 1705 priority_value = purple_value_new(PURPLE_TYPE_INT); |
1704 purple_value_set_int(priority_value, 0); | 1706 purple_value_set_int(priority_value, 0); |
2290 | 2292 |
2291 static gboolean _jabber_send_buzz(JabberStream *js, const char *username, char **error) { | 2293 static gboolean _jabber_send_buzz(JabberStream *js, const char *username, char **error) { |
2292 | 2294 |
2293 JabberBuddy *jb; | 2295 JabberBuddy *jb; |
2294 JabberBuddyResource *jbr; | 2296 JabberBuddyResource *jbr; |
2295 GList *iter; | 2297 PurpleConnection *gc = js->gc; |
2296 | 2298 PurpleAccount *account = purple_connection_get_account(gc); |
2299 PurpleConversation *conv = | |
2300 purple_find_conversation_with_account(PURPLE_CONV_TYPE_ANY, username, | |
2301 account); | |
2302 gchar *str; | |
2303 | |
2297 if(!username) | 2304 if(!username) |
2298 return FALSE; | 2305 return FALSE; |
2299 | 2306 |
2300 jb = jabber_buddy_find(js, username, FALSE); | 2307 jb = jabber_buddy_find(js, username, FALSE); |
2301 if(!jb) { | 2308 if(!jb) { |
2302 *error = g_strdup_printf(_("Unable to buzz, because there is nothing known about user %s."), username); | 2309 *error = g_strdup_printf(_("Unable to buzz, because there is nothing known about user %s."), username); |
2303 return FALSE; | 2310 return FALSE; |
2304 } | 2311 } |
2305 | 2312 |
2306 jbr = jabber_buddy_find_resource(jb, NULL); | 2313 jbr = jabber_buddy_find_resource(jb, NULL); |
2307 if(!jbr) { | 2314 if (!jbr) { |
2308 *error = g_strdup_printf(_("Unable to buzz, because user %s might be offline."), username); | 2315 *error = g_strdup_printf(_("Unable to buzz, because user %s might be offline."), |
2316 username); | |
2309 return FALSE; | 2317 return FALSE; |
2310 } | 2318 } |
2311 | 2319 |
2312 if(!jbr->caps) { | 2320 if (jabber_resource_has_capability(jbr, XEP_0224_NAMESPACE)) { |
2313 *error = g_strdup_printf(_("Unable to buzz, because there is nothing known about user %s."), username); | 2321 xmlnode *buzz, *msg = xmlnode_new("message"); |
2322 gchar *to; | |
2323 | |
2324 to = g_strdup_printf("%s/%s", username, jbr->name); | |
2325 xmlnode_set_attrib(msg, "to", to); | |
2326 g_free(to); | |
2327 | |
2328 /* avoid offline storage */ | |
2329 xmlnode_set_attrib(msg, "type", "headline"); | |
2330 | |
2331 buzz = xmlnode_new_child(msg, "attention"); | |
2332 xmlnode_set_namespace(buzz, XEP_0224_NAMESPACE); | |
2333 | |
2334 jabber_send(js, msg); | |
2335 xmlnode_free(msg); | |
2336 | |
2337 str = g_strdup_printf(_("Buzzing %s..."), username); | |
2338 purple_conversation_write(conv, NULL, str, | |
2339 PURPLE_MESSAGE_SYSTEM|PURPLE_MESSAGE_NOTIFY, time(NULL)); | |
2340 g_free(str); | |
2341 | |
2342 return TRUE; | |
2343 } else { | |
2344 *error = g_strdup_printf(_("Unable to buzz, because the user %s does not support it."), username); | |
2314 return FALSE; | 2345 return FALSE; |
2315 } | 2346 } |
2316 | |
2317 for(iter = jbr->caps->features; iter; iter = g_list_next(iter)) { | |
2318 if(!strcmp(iter->data, XEP_0224_NAMESPACE)) { | |
2319 xmlnode *buzz, *msg = xmlnode_new("message"); | |
2320 gchar *to; | |
2321 | |
2322 to = g_strdup_printf("%s/%s", username, jbr->name); | |
2323 xmlnode_set_attrib(msg, "to", to); | |
2324 g_free(to); | |
2325 | |
2326 /* avoid offline storage */ | |
2327 xmlnode_set_attrib(msg, "type", "headline"); | |
2328 | |
2329 buzz = xmlnode_new_child(msg, "attention"); | |
2330 xmlnode_set_namespace(buzz, XEP_0224_NAMESPACE); | |
2331 | |
2332 jabber_send(js, msg); | |
2333 xmlnode_free(msg); | |
2334 | |
2335 return TRUE; | |
2336 } | |
2337 } | |
2338 | |
2339 *error = g_strdup_printf(_("Unable to buzz, because the user %s does not support it."), username); | |
2340 return FALSE; | |
2341 } | 2347 } |
2342 | 2348 |
2343 static PurpleCmdRet jabber_cmd_buzz(PurpleConversation *conv, | 2349 static PurpleCmdRet jabber_cmd_buzz(PurpleConversation *conv, |
2344 const char *cmd, char **args, char **error, void *data) | 2350 const char *cmd, char **args, char **error, void *data) |
2345 { | 2351 { |
2346 JabberStream *js = conv->account->gc->proto_data; | 2352 JabberStream *js = conv->account->gc->proto_data; |
2347 | 2353 const gchar *who; |
2348 if(!args || !args[0]) | 2354 gboolean result; |
2349 return PURPLE_CMD_RET_FAILED; | 2355 |
2350 | 2356 if (!args || !args[0]) { |
2351 return _jabber_send_buzz(js, args[0], error) ? PURPLE_CMD_RET_OK : PURPLE_CMD_RET_FAILED; | 2357 /* use the buddy from conversation, if it's a one-to-one conversation */ |
2358 if (purple_conversation_get_type(conv) == PURPLE_CONV_TYPE_IM) { | |
2359 who = purple_conversation_get_name(conv); | |
2360 } else { | |
2361 return PURPLE_CMD_RET_FAILED; | |
2362 } | |
2363 } else { | |
2364 who = args[0]; | |
2365 } | |
2366 | |
2367 return _jabber_send_buzz(js, who, error) ? PURPLE_CMD_RET_OK : PURPLE_CMD_RET_FAILED; | |
2352 } | 2368 } |
2353 | 2369 |
2354 GList *jabber_attention_types(PurpleAccount *account) | 2370 GList *jabber_attention_types(PurpleAccount *account) |
2355 { | 2371 { |
2356 static GList *types = NULL; | 2372 static GList *types = NULL; |
2463 NULL); | 2479 NULL); |
2464 purple_cmd_register("buzz", "s", PURPLE_CMD_P_PRPL, | 2480 purple_cmd_register("buzz", "s", PURPLE_CMD_P_PRPL, |
2465 PURPLE_CMD_FLAG_IM | PURPLE_CMD_FLAG_PRPL_ONLY, | 2481 PURPLE_CMD_FLAG_IM | PURPLE_CMD_FLAG_PRPL_ONLY, |
2466 "prpl-jabber", jabber_cmd_buzz, | 2482 "prpl-jabber", jabber_cmd_buzz, |
2467 _("buzz: Buzz a user to get their attention"), NULL); | 2483 _("buzz: Buzz a user to get their attention"), NULL); |
2484 purple_cmd_register("buzz", "", PURPLE_CMD_P_PRPL, | |
2485 PURPLE_CMD_FLAG_IM | PURPLE_CMD_FLAG_PRPL_ONLY, | |
2486 "prpl-jabber", jabber_cmd_buzz, | |
2487 _("buzz: Buzz a user to get their attention"), NULL); | |
2468 } | 2488 } |
2469 | 2489 |
2470 void | 2490 void |
2471 jabber_init_plugin(PurplePlugin *plugin) | 2491 jabber_init_plugin(PurplePlugin *plugin) |
2472 { | 2492 { |