comparison libpurple/protocols/jabber/presence.c @ 21229:0b67d509a305

merge of '1bcf84e26d11f259b3c5ec663e3fecc2f01aed33' and 'ce13b5ca4994abbd4934b3bc568c8b115335c426'
author Richard Laager <rlaager@wiktel.com>
date Sun, 14 Oct 2007 02:41:00 +0000
parents fdefa5eb46e2 b1fa7765ca4b
children b9680933c2c6
comparison
equal deleted inserted replaced
21098:7e200a629109 21229:0b67d509a305
31 #include "util.h" 31 #include "util.h"
32 #include "xmlnode.h" 32 #include "xmlnode.h"
33 33
34 #include "buddy.h" 34 #include "buddy.h"
35 #include "chat.h" 35 #include "chat.h"
36 #include "google.h"
36 #include "presence.h" 37 #include "presence.h"
37 #include "iq.h" 38 #include "iq.h"
38 #include "jutil.h" 39 #include "jutil.h"
39 #include "adhoccommands.h" 40 #include "adhoccommands.h"
40 41
102 int primitive; 103 int primitive;
103 xmlnode *presence, *x, *photo; 104 xmlnode *presence, *x, *photo;
104 char *stripped = NULL; 105 char *stripped = NULL;
105 JabberBuddyState state; 106 JabberBuddyState state;
106 int priority; 107 int priority;
107 const char *artist, *title, *source, *uri, *track; 108 const char *artist = NULL, *title = NULL, *source = NULL, *uri = NULL, *track = NULL;
108 int length; 109 int length = -1;
109 gboolean allowBuzz; 110 gboolean allowBuzz;
110 111 PurplePresence *p = purple_account_get_presence(account);
111 if(NULL == status) { 112 PurpleStatus *tune;
112 PurplePresence *gpresence = purple_account_get_presence(account); 113
113 status = purple_presence_get_active_status(gpresence); 114 if (NULL == status) {
115 status = purple_presence_get_active_status(p);
114 } 116 }
115 117
116 if(!purple_status_is_active(status)) 118 if(!purple_status_is_active(status))
117 return; 119 return;
118 120
142 (a && !b) || (a && a[0] != '\0' && b && b[0] == '\0') || (a && b && strcmp(a,b))) 144 (a && !b) || (a && a[0] != '\0' && b && b[0] == '\0') || (a && b && strcmp(a,b)))
143 /* check if there are any differences to the <presence> and send them in that case */ 145 /* check if there are any differences to the <presence> and send them in that case */
144 if (allowBuzz != js->allowBuzz || js->old_state != state || CHANGED(js->old_msg, stripped) || 146 if (allowBuzz != js->allowBuzz || js->old_state != state || CHANGED(js->old_msg, stripped) ||
145 js->old_priority != priority || CHANGED(js->old_avatarhash, js->avatar_hash)) { 147 js->old_priority != priority || CHANGED(js->old_avatarhash, js->avatar_hash)) {
146 js->allowBuzz = allowBuzz; 148 js->allowBuzz = allowBuzz;
149
150 if (js->googletalk && stripped == NULL && purple_presence_is_status_primitive_active(p, PURPLE_STATUS_TUNE)) {
151 tune = purple_presence_get_status(p, "tune");
152 stripped = jabber_google_presence_outgoing(tune);
153 }
154
147 presence = jabber_presence_create_js(js, state, stripped, priority); 155 presence = jabber_presence_create_js(js, state, stripped, priority);
148 156
149 if(js->avatar_hash) { 157 if(js->avatar_hash) {
150 x = xmlnode_new_child(presence, "x"); 158 x = xmlnode_new_child(presence, "x");
151 xmlnode_set_namespace(x, "vcard-temp:x:update"); 159 xmlnode_set_namespace(x, "vcard-temp:x:update");
170 js->old_priority = priority; 178 js->old_priority = priority;
171 g_free(stripped); 179 g_free(stripped);
172 } 180 }
173 181
174 /* next, check if there are any changes to the tune values */ 182 /* next, check if there are any changes to the tune values */
175 artist = purple_status_get_attr_string(status, PURPLE_TUNE_ARTIST); 183 tune = purple_presence_get_status(p, "tune");
176 title = purple_status_get_attr_string(status, PURPLE_TUNE_TITLE); 184 if (tune && purple_status_is_active(tune)) {
177 source = purple_status_get_attr_string(status, PURPLE_TUNE_ALBUM); 185 artist = purple_status_get_attr_string(tune, PURPLE_TUNE_ARTIST);
178 uri = purple_status_get_attr_string(status, PURPLE_TUNE_URL); 186 title = purple_status_get_attr_string(tune, PURPLE_TUNE_TITLE);
179 track = purple_status_get_attr_string(status, PURPLE_TUNE_TRACK); 187 source = purple_status_get_attr_string(tune, PURPLE_TUNE_ALBUM);
180 length = (!purple_status_get_attr_value(status, PURPLE_TUNE_TIME))?-1:purple_status_get_attr_int(status, PURPLE_TUNE_TIME); 188 uri = purple_status_get_attr_string(tune, PURPLE_TUNE_URL);
189 track = purple_status_get_attr_string(tune, PURPLE_TUNE_TRACK);
190 length = (!purple_status_get_attr_value(tune, PURPLE_TUNE_TIME)) ? -1 :
191 purple_status_get_attr_int(tune, PURPLE_TUNE_TIME);
192 }
181 193
182 if(CHANGED(artist, js->old_artist) || CHANGED(title, js->old_title) || CHANGED(source, js->old_source) || 194 if(CHANGED(artist, js->old_artist) || CHANGED(title, js->old_title) || CHANGED(source, js->old_source) ||
183 CHANGED(uri, js->old_uri) || CHANGED(track, js->old_track) || (length != js->old_length)) { 195 CHANGED(uri, js->old_uri) || CHANGED(track, js->old_track) || (length != js->old_length)) {
184 PurpleJabberTuneInfo tuneinfo = { 196 PurpleJabberTuneInfo tuneinfo = {
185 (char*)artist, 197 (char*)artist,
729 } 741 }
730 } 742 }
731 } 743 }
732 744
733 if((found_jbr = jabber_buddy_find_resource(jb, NULL))) { 745 if((found_jbr = jabber_buddy_find_resource(jb, NULL))) {
734 purple_prpl_got_user_status(js->gc->account, buddy_name, jabber_buddy_state_get_status_id(found_jbr->state), "priority", found_jbr->priority, found_jbr->status ? "message" : NULL, found_jbr->status, NULL); 746 jabber_google_presence_incoming(js, buddy_name, found_jbr);
747 purple_prpl_got_user_status(js->gc->account, buddy_name, jabber_buddy_state_get_status_id(found_jbr->state), "priority", found_jbr->priority, "message", found_jbr->status, NULL);
735 } else { 748 } else {
736 purple_prpl_got_user_status(js->gc->account, buddy_name, "offline", status ? "message" : NULL, status, NULL); 749 purple_prpl_got_user_status(js->gc->account, buddy_name, "offline", status ? "message" : NULL, status, NULL);
737 } 750 }
738 g_free(buddy_name); 751 g_free(buddy_name);
739 } 752 }