Mercurial > pidgin.yaz
comparison libpurple/protocols/jabber/jabber.c @ 24204:ff0470db521d
propagate from branch 'im.pidgin.pidgin' (head 50ca054a04cd66fc08b411e7237a486ebb13fe4d)
to branch 'im.pidgin.cpw.malu.xmpp.attention' (head 62b78e9093c7b054a98175b8211ac321c9b50756)
author | Marcus Lundblad <ml@update.uu.se> |
---|---|
date | Thu, 16 Oct 2008 19:26:15 +0000 |
parents | a61c017d3a99 a64d90cff01f |
children | de3e32bb942a |
comparison
equal
deleted
inserted
replaced
24173:499739e4c5d5 | 24204:ff0470db521d |
---|---|
1643 GList *jabber_status_types(PurpleAccount *account) | 1643 GList *jabber_status_types(PurpleAccount *account) |
1644 { | 1644 { |
1645 PurpleStatusType *type; | 1645 PurpleStatusType *type; |
1646 GList *types = NULL; | 1646 GList *types = NULL; |
1647 PurpleValue *priority_value; | 1647 PurpleValue *priority_value; |
1648 PurpleValue *buzz_enabled; | |
1648 | 1649 |
1649 priority_value = purple_value_new(PURPLE_TYPE_INT); | 1650 priority_value = purple_value_new(PURPLE_TYPE_INT); |
1650 purple_value_set_int(priority_value, 1); | 1651 purple_value_set_int(priority_value, 1); |
1652 buzz_enabled = purple_value_new(PURPLE_TYPE_BOOLEAN); | |
1653 purple_value_set_boolean(buzz_enabled, TRUE); | |
1651 type = purple_status_type_new_with_attrs(PURPLE_STATUS_AVAILABLE, | 1654 type = purple_status_type_new_with_attrs(PURPLE_STATUS_AVAILABLE, |
1652 jabber_buddy_state_get_status_id(JABBER_BUDDY_STATE_ONLINE), | 1655 jabber_buddy_state_get_status_id(JABBER_BUDDY_STATE_ONLINE), |
1653 NULL, TRUE, TRUE, FALSE, | 1656 NULL, TRUE, TRUE, FALSE, |
1654 "priority", _("Priority"), priority_value, | 1657 "priority", _("Priority"), priority_value, |
1655 "message", _("Message"), purple_value_new(PURPLE_TYPE_STRING), | 1658 "message", _("Message"), purple_value_new(PURPLE_TYPE_STRING), |
1656 "mood", _("Mood"), purple_value_new(PURPLE_TYPE_STRING), | 1659 "mood", _("Mood"), purple_value_new(PURPLE_TYPE_STRING), |
1657 "moodtext", _("Mood Text"), purple_value_new(PURPLE_TYPE_STRING), | 1660 "moodtext", _("Mood Text"), purple_value_new(PURPLE_TYPE_STRING), |
1658 "nick", _("Nickname"), purple_value_new(PURPLE_TYPE_STRING), | 1661 "nick", _("Nickname"), purple_value_new(PURPLE_TYPE_STRING), |
1659 "buzz", _("Allow Buzz"), purple_value_new(PURPLE_TYPE_BOOLEAN), | 1662 "buzz", _("Allow Buzz"), buzz_enabled, |
1660 NULL); | 1663 NULL); |
1661 types = g_list_append(types, type); | 1664 types = g_list_append(types, type); |
1662 | 1665 |
1663 priority_value = purple_value_new(PURPLE_TYPE_INT); | 1666 priority_value = purple_value_new(PURPLE_TYPE_INT); |
1664 purple_value_set_int(priority_value, 1); | 1667 purple_value_set_int(priority_value, 1); |
1668 "priority", _("Priority"), priority_value, | 1671 "priority", _("Priority"), priority_value, |
1669 "message", _("Message"), purple_value_new(PURPLE_TYPE_STRING), | 1672 "message", _("Message"), purple_value_new(PURPLE_TYPE_STRING), |
1670 "mood", _("Mood"), purple_value_new(PURPLE_TYPE_STRING), | 1673 "mood", _("Mood"), purple_value_new(PURPLE_TYPE_STRING), |
1671 "moodtext", _("Mood Text"), purple_value_new(PURPLE_TYPE_STRING), | 1674 "moodtext", _("Mood Text"), purple_value_new(PURPLE_TYPE_STRING), |
1672 "nick", _("Nickname"), purple_value_new(PURPLE_TYPE_STRING), | 1675 "nick", _("Nickname"), purple_value_new(PURPLE_TYPE_STRING), |
1673 "buzz", _("Allow Buzz"), purple_value_new(PURPLE_TYPE_BOOLEAN), | 1676 "buzz", _("Allow Buzz"), buzz_enabled, |
1674 NULL); | 1677 NULL); |
1675 types = g_list_append(types, type); | 1678 types = g_list_append(types, type); |
1676 | 1679 |
1677 priority_value = purple_value_new(PURPLE_TYPE_INT); | 1680 priority_value = purple_value_new(PURPLE_TYPE_INT); |
1678 purple_value_set_int(priority_value, 0); | 1681 purple_value_set_int(priority_value, 0); |
1682 "priority", _("Priority"), priority_value, | 1685 "priority", _("Priority"), priority_value, |
1683 "message", _("Message"), purple_value_new(PURPLE_TYPE_STRING), | 1686 "message", _("Message"), purple_value_new(PURPLE_TYPE_STRING), |
1684 "mood", _("Mood"), purple_value_new(PURPLE_TYPE_STRING), | 1687 "mood", _("Mood"), purple_value_new(PURPLE_TYPE_STRING), |
1685 "moodtext", _("Mood Text"), purple_value_new(PURPLE_TYPE_STRING), | 1688 "moodtext", _("Mood Text"), purple_value_new(PURPLE_TYPE_STRING), |
1686 "nick", _("Nickname"), purple_value_new(PURPLE_TYPE_STRING), | 1689 "nick", _("Nickname"), purple_value_new(PURPLE_TYPE_STRING), |
1687 "buzz", _("Allow Buzz"), purple_value_new(PURPLE_TYPE_BOOLEAN), | 1690 "buzz", _("Allow Buzz"), buzz_enabled, |
1688 NULL); | 1691 NULL); |
1689 types = g_list_append(types, type); | 1692 types = g_list_append(types, type); |
1690 | 1693 |
1691 priority_value = purple_value_new(PURPLE_TYPE_INT); | 1694 priority_value = purple_value_new(PURPLE_TYPE_INT); |
1692 purple_value_set_int(priority_value, 0); | 1695 purple_value_set_int(priority_value, 0); |
1696 "priority", _("Priority"), priority_value, | 1699 "priority", _("Priority"), priority_value, |
1697 "message", _("Message"), purple_value_new(PURPLE_TYPE_STRING), | 1700 "message", _("Message"), purple_value_new(PURPLE_TYPE_STRING), |
1698 "mood", _("Mood"), purple_value_new(PURPLE_TYPE_STRING), | 1701 "mood", _("Mood"), purple_value_new(PURPLE_TYPE_STRING), |
1699 "moodtext", _("Mood Text"), purple_value_new(PURPLE_TYPE_STRING), | 1702 "moodtext", _("Mood Text"), purple_value_new(PURPLE_TYPE_STRING), |
1700 "nick", _("Nickname"), purple_value_new(PURPLE_TYPE_STRING), | 1703 "nick", _("Nickname"), purple_value_new(PURPLE_TYPE_STRING), |
1701 "buzz", _("Allow Buzz"), purple_value_new(PURPLE_TYPE_BOOLEAN), | 1704 "buzz", _("Allow Buzz"), buzz_enabled, |
1702 NULL); | 1705 NULL); |
1703 types = g_list_append(types, type); | 1706 types = g_list_append(types, type); |
1704 | 1707 |
1705 priority_value = purple_value_new(PURPLE_TYPE_INT); | 1708 priority_value = purple_value_new(PURPLE_TYPE_INT); |
1706 purple_value_set_int(priority_value, 0); | 1709 purple_value_set_int(priority_value, 0); |
1710 "priority", _("Priority"), priority_value, | 1713 "priority", _("Priority"), priority_value, |
1711 "message", _("Message"), purple_value_new(PURPLE_TYPE_STRING), | 1714 "message", _("Message"), purple_value_new(PURPLE_TYPE_STRING), |
1712 "mood", _("Mood"), purple_value_new(PURPLE_TYPE_STRING), | 1715 "mood", _("Mood"), purple_value_new(PURPLE_TYPE_STRING), |
1713 "moodtext", _("Mood Text"), purple_value_new(PURPLE_TYPE_STRING), | 1716 "moodtext", _("Mood Text"), purple_value_new(PURPLE_TYPE_STRING), |
1714 "nick", _("Nickname"), purple_value_new(PURPLE_TYPE_STRING), | 1717 "nick", _("Nickname"), purple_value_new(PURPLE_TYPE_STRING), |
1715 "buzz", _("Allow Buzz"), purple_value_new(PURPLE_TYPE_BOOLEAN), | |
1716 NULL); | 1718 NULL); |
1717 types = g_list_append(types, type); | 1719 types = g_list_append(types, type); |
1718 | 1720 |
1719 /* | 1721 /* |
1720 if(js->protocol_version == JABBER_PROTO_0_9) | 1722 if(js->protocol_version == JABBER_PROTO_0_9) |
2293 | 2295 |
2294 static gboolean _jabber_send_buzz(JabberStream *js, const char *username, char **error) { | 2296 static gboolean _jabber_send_buzz(JabberStream *js, const char *username, char **error) { |
2295 | 2297 |
2296 JabberBuddy *jb; | 2298 JabberBuddy *jb; |
2297 JabberBuddyResource *jbr; | 2299 JabberBuddyResource *jbr; |
2298 GList *iter; | 2300 PurpleConnection *gc = js->gc; |
2299 | 2301 PurpleAccount *account = purple_connection_get_account(gc); |
2302 PurpleConversation *conv = | |
2303 purple_find_conversation_with_account(PURPLE_CONV_TYPE_ANY, username, | |
2304 account); | |
2305 gchar *str; | |
2306 | |
2300 if(!username) | 2307 if(!username) |
2301 return FALSE; | 2308 return FALSE; |
2302 | 2309 |
2303 jb = jabber_buddy_find(js, username, FALSE); | 2310 jb = jabber_buddy_find(js, username, FALSE); |
2304 if(!jb) { | 2311 if(!jb) { |
2305 *error = g_strdup_printf(_("Unable to buzz, because there is nothing known about user %s."), username); | 2312 *error = g_strdup_printf(_("Unable to buzz, because there is nothing known about user %s."), username); |
2306 return FALSE; | 2313 return FALSE; |
2307 } | 2314 } |
2308 | 2315 |
2309 jbr = jabber_buddy_find_resource(jb, NULL); | 2316 jbr = jabber_buddy_find_resource(jb, NULL); |
2310 if(!jbr) { | 2317 if (!jbr) { |
2311 *error = g_strdup_printf(_("Unable to buzz, because user %s might be offline."), username); | 2318 *error = g_strdup_printf(_("Unable to buzz, because user %s might be offline."), |
2319 username); | |
2312 return FALSE; | 2320 return FALSE; |
2313 } | 2321 } |
2314 | 2322 |
2315 if(!jbr->caps) { | 2323 if (jabber_resource_has_capability(jbr, XEP_0224_NAMESPACE)) { |
2316 *error = g_strdup_printf(_("Unable to buzz, because there is nothing known about user %s."), username); | 2324 xmlnode *buzz, *msg = xmlnode_new("message"); |
2325 gchar *to; | |
2326 | |
2327 to = g_strdup_printf("%s/%s", username, jbr->name); | |
2328 xmlnode_set_attrib(msg, "to", to); | |
2329 g_free(to); | |
2330 | |
2331 /* avoid offline storage */ | |
2332 xmlnode_set_attrib(msg, "type", "headline"); | |
2333 | |
2334 buzz = xmlnode_new_child(msg, "attention"); | |
2335 xmlnode_set_namespace(buzz, XEP_0224_NAMESPACE); | |
2336 | |
2337 jabber_send(js, msg); | |
2338 xmlnode_free(msg); | |
2339 | |
2340 str = g_strdup_printf(_("Buzzing %s..."), username); | |
2341 purple_conversation_write(conv, NULL, str, | |
2342 PURPLE_MESSAGE_SYSTEM|PURPLE_MESSAGE_NOTIFY, time(NULL)); | |
2343 g_free(str); | |
2344 | |
2345 return TRUE; | |
2346 } else { | |
2347 *error = g_strdup_printf(_("Unable to buzz, because the user %s does not support it."), username); | |
2317 return FALSE; | 2348 return FALSE; |
2318 } | 2349 } |
2319 | |
2320 for(iter = jbr->caps->features; iter; iter = g_list_next(iter)) { | |
2321 if(!strcmp(iter->data, "http://www.xmpp.org/extensions/xep-0224.html#ns")) { | |
2322 xmlnode *buzz, *msg = xmlnode_new("message"); | |
2323 gchar *to; | |
2324 | |
2325 to = g_strdup_printf("%s/%s", username, jbr->name); | |
2326 xmlnode_set_attrib(msg, "to", to); | |
2327 g_free(to); | |
2328 | |
2329 /* avoid offline storage */ | |
2330 xmlnode_set_attrib(msg, "type", "headline"); | |
2331 | |
2332 buzz = xmlnode_new_child(msg, "attention"); | |
2333 xmlnode_set_namespace(buzz, "http://www.xmpp.org/extensions/xep-0224.html#ns"); | |
2334 | |
2335 jabber_send(js, msg); | |
2336 xmlnode_free(msg); | |
2337 | |
2338 return TRUE; | |
2339 } | |
2340 } | |
2341 | |
2342 *error = g_strdup_printf(_("Unable to buzz, because the user %s does not support it."), username); | |
2343 return FALSE; | |
2344 } | 2350 } |
2345 | 2351 |
2346 static PurpleCmdRet jabber_cmd_buzz(PurpleConversation *conv, | 2352 static PurpleCmdRet jabber_cmd_buzz(PurpleConversation *conv, |
2347 const char *cmd, char **args, char **error, void *data) | 2353 const char *cmd, char **args, char **error, void *data) |
2348 { | 2354 { |
2349 JabberStream *js = conv->account->gc->proto_data; | 2355 JabberStream *js = conv->account->gc->proto_data; |
2350 | 2356 const gchar *who; |
2351 if(!args || !args[0]) | 2357 gboolean result; |
2352 return PURPLE_CMD_RET_FAILED; | 2358 |
2353 | 2359 if (!args || !args[0]) { |
2354 return _jabber_send_buzz(js, args[0], error) ? PURPLE_CMD_RET_OK : PURPLE_CMD_RET_FAILED; | 2360 /* use the buddy from conversation, if it's a one-to-one conversation */ |
2361 if (purple_conversation_get_type(conv) == PURPLE_CONV_TYPE_IM) { | |
2362 who = purple_conversation_get_name(conv); | |
2363 } else { | |
2364 return PURPLE_CMD_RET_FAILED; | |
2365 } | |
2366 } else { | |
2367 who = args[0]; | |
2368 } | |
2369 | |
2370 return _jabber_send_buzz(js, who, error) ? PURPLE_CMD_RET_OK : PURPLE_CMD_RET_FAILED; | |
2355 } | 2371 } |
2356 | 2372 |
2357 GList *jabber_attention_types(PurpleAccount *account) | 2373 GList *jabber_attention_types(PurpleAccount *account) |
2358 { | 2374 { |
2359 static GList *types = NULL; | 2375 static GList *types = NULL; |
2466 NULL); | 2482 NULL); |
2467 purple_cmd_register("buzz", "s", PURPLE_CMD_P_PRPL, | 2483 purple_cmd_register("buzz", "s", PURPLE_CMD_P_PRPL, |
2468 PURPLE_CMD_FLAG_IM | PURPLE_CMD_FLAG_PRPL_ONLY, | 2484 PURPLE_CMD_FLAG_IM | PURPLE_CMD_FLAG_PRPL_ONLY, |
2469 "prpl-jabber", jabber_cmd_buzz, | 2485 "prpl-jabber", jabber_cmd_buzz, |
2470 _("buzz: Buzz a user to get their attention"), NULL); | 2486 _("buzz: Buzz a user to get their attention"), NULL); |
2487 purple_cmd_register("buzz", "", PURPLE_CMD_P_PRPL, | |
2488 PURPLE_CMD_FLAG_IM | PURPLE_CMD_FLAG_PRPL_ONLY, | |
2489 "prpl-jabber", jabber_cmd_buzz, | |
2490 _("buzz: Buzz a user to get their attention"), NULL); | |
2471 } | 2491 } |
2472 | 2492 |
2473 void | 2493 void |
2474 jabber_init_plugin(PurplePlugin *plugin) | 2494 jabber_init_plugin(PurplePlugin *plugin) |
2475 { | 2495 { |