comparison libpurple/protocols/jabber/buddy.c @ 27946:e0bcdc2bad7d

propagate from branch 'im.pidgin.pidgin' (head 70ee1de1cc79688256a3dd6ac1a519e24c00a12c) to branch 'im.pidgin.pidgin.yaz' (head 48181b0dbca52e9e9bd367a1dcc01fe5f9a678a1)
author Yoshiki Yazawa <yaz@honeyplanet.jp>
date Mon, 11 May 2009 02:18:47 +0000
parents 1ef01afd08bc
children eeee4309d3d8
comparison
equal deleted inserted replaced
27945:cc45ac2782cc 27946:e0bcdc2bad7d
48 GSList *ids; 48 GSList *ids;
49 GHashTable *resources; 49 GHashTable *resources;
50 int timeout_handle; 50 int timeout_handle;
51 GSList *vcard_imgids; 51 GSList *vcard_imgids;
52 PurpleNotifyUserInfo *user_info; 52 PurpleNotifyUserInfo *user_info;
53 long last_seconds;
54 gchar *last_message;
53 } JabberBuddyInfo; 55 } JabberBuddyInfo;
54 56
55 void jabber_buddy_free(JabberBuddy *jb) 57 void jabber_buddy_free(JabberBuddy *jb)
56 { 58 {
57 g_return_if_fail(jb != NULL); 59 g_return_if_fail(jb != NULL);
640 if (jbi->timeout_handle > 0) 642 if (jbi->timeout_handle > 0)
641 purple_timeout_remove(jbi->timeout_handle); 643 purple_timeout_remove(jbi->timeout_handle);
642 644
643 g_free(jbi->jid); 645 g_free(jbi->jid);
644 g_hash_table_destroy(jbi->resources); 646 g_hash_table_destroy(jbi->resources);
647 g_free(jbi->last_message);
645 purple_notify_user_info_destroy(jbi->user_info); 648 purple_notify_user_info_destroy(jbi->user_info);
646 g_free(jbi); 649 g_free(jbi);
647 } 650 }
648 651
649 static void jabber_buddy_info_show_if_ready(JabberBuddyInfo *jbi) 652 static void jabber_buddy_info_show_if_ready(JabberBuddyInfo *jbi)
850 char *purdy = NULL; 853 char *purdy = NULL;
851 const char *status_name = NULL; 854 const char *status_name = NULL;
852 855
853 jbr = resources->data; 856 jbr = resources->data;
854 857
858 /* put a section break between resources, this is not needed if
859 we are at the first, because one was already added for the vcard
860 section */
861 if (resources != jbi->jb->resources) {
862 purple_notify_user_info_prepend_section_break(user_info);
863 }
864
855 if(jbr->client.name) { 865 if(jbr->client.name) {
856 tmp = g_strdup_printf("%s%s%s", jbr->client.name, 866 tmp = g_strdup_printf("%s%s%s", jbr->client.name,
857 (jbr->client.version ? " " : ""), 867 (jbr->client.version ? " " : ""),
858 (jbr->client.version ? jbr->client.version : "")); 868 (jbr->client.version ? jbr->client.version : ""));
859 purple_notify_user_info_prepend_pair(user_info, 869 purple_notify_user_info_prepend_pair(user_info,
1030 } 1040 }
1031 #endif 1041 #endif
1032 } 1042 }
1033 } 1043 }
1034 1044
1045 if (!jbi->jb->resources) {
1046 /* the buddy is offline */
1047 gchar *status =
1048 g_strdup_printf("%s%s%s", _("Offline"),
1049 jbi->last_message ? ": " : "",
1050 jbi->last_message ? jbi->last_message : "");
1051 if (jbi->last_seconds > 0) {
1052 char *last = purple_str_seconds_to_string(jbi->last_seconds);
1053 gchar *message = g_strdup_printf(_("%s ago"), last);
1054 purple_notify_user_info_prepend_pair(user_info,
1055 _("Logged off"), message);
1056 g_free(last);
1057 g_free(message);
1058 }
1059 purple_notify_user_info_prepend_pair(user_info, _("Status"), status);
1060 g_free(status);
1061 }
1062
1035 g_free(resource_name); 1063 g_free(resource_name);
1036 1064
1037 purple_notify_userinfo(jbi->js->gc, jbi->jid, user_info, NULL, NULL); 1065 purple_notify_userinfo(jbi->js->gc, jbi->jid, user_info, NULL, NULL);
1038 1066
1039 while(jbi->vcard_imgids) { 1067 while(jbi->vcard_imgids) {
1482 } 1510 }
1483 1511
1484 jabber_buddy_info_show_if_ready(jbi); 1512 jabber_buddy_info_show_if_ready(jbi);
1485 } 1513 }
1486 1514
1515 static void jabber_last_offline_parse(JabberStream *js, const char *from,
1516 JabberIqType type, const char *id,
1517 xmlnode *packet, gpointer data)
1518 {
1519 JabberBuddyInfo *jbi = data;
1520 xmlnode *query;
1521 const char *seconds;
1522
1523 g_return_if_fail(jbi != NULL);
1524
1525 jabber_buddy_info_remove_id(jbi, id);
1526
1527 if(!from)
1528 return;
1529
1530 if (type == JABBER_IQ_RESULT) {
1531 if((query = xmlnode_get_child(packet, "query"))) {
1532 seconds = xmlnode_get_attrib(query, "seconds");
1533 if(seconds) {
1534 char *end = NULL;
1535 long sec = strtol(seconds, &end, 10);
1536 if(end != seconds) {
1537 jbi->last_seconds = sec;
1538 }
1539 }
1540 jbi->last_message = xmlnode_get_data(query);
1541 }
1542 }
1543
1544 jabber_buddy_info_show_if_ready(jbi);
1545 }
1546
1487 static void jabber_time_parse(JabberStream *js, const char *from, 1547 static void jabber_time_parse(JabberStream *js, const char *from,
1488 JabberIqType type, const char *id, 1548 JabberIqType type, const char *id,
1489 xmlnode *packet, gpointer data) 1549 xmlnode *packet, gpointer data)
1490 { 1550 {
1491 JabberBuddyInfo *jbi = data; 1551 JabberBuddyInfo *jbi = data;
1679 } 1739 }
1680 1740
1681 g_free(full_jid); 1741 g_free(full_jid);
1682 } 1742 }
1683 1743
1744 if (!jb->resources && strchr(jid, '/') == NULL) {
1745 /* user is offline, send a jabber:iq:last to find out last time online */
1746 iq = jabber_iq_new_query(js, JABBER_IQ_GET, "jabber:iq:last");
1747 xmlnode_set_attrib(iq->node, "to", jid);
1748 jabber_iq_set_callback(iq, jabber_last_offline_parse, jbi);
1749 jbi->ids = g_slist_prepend(jbi->ids, g_strdup(iq->id));
1750 jabber_iq_send(iq);
1751 }
1752
1684 js->pending_buddy_info_requests = g_slist_prepend(js->pending_buddy_info_requests, jbi); 1753 js->pending_buddy_info_requests = g_slist_prepend(js->pending_buddy_info_requests, jbi);
1685 jbi->timeout_handle = purple_timeout_add_seconds(30, jabber_buddy_get_info_timeout, jbi); 1754 jbi->timeout_handle = purple_timeout_add_seconds(30, jabber_buddy_get_info_timeout, jbi);
1686 } 1755 }
1687 1756
1688 void jabber_buddy_get_info(PurpleConnection *gc, const char *who) 1757 void jabber_buddy_get_info(PurpleConnection *gc, const char *who)