Getting the status of another user from libpurple (the IM library underlying Pidgin)

I am trying to display the current status of another person on the SIMPLE network (Microsoft Office Communicator). I use libpurple, built a C ++ wrapper around libpurple, and I can send / receive IM with other users on the SIMPLE network. I still need to get the current status of other users.

Here is my current attempt to restore the status of another user.
Previously defined and initialized:

PurpleAccount * CommonIM :: m_account β†’ I can send messages using this account

// the username of the person I want to get the status of, eg username = "sip: blah@blah.blah.com "; //TEST instance 1 PurpleBuddy* newbody1 = purple_buddy_new(m_account, username.c_str(), NULL); sleep(5); PurplePresence *p1 = purple_buddy_get_presence(newbody1); PurpleStatus *status1 = purple_presence_get_active_status(p1); PurpleStatusType *statusType1 = purple_status_get_type(status1); PurpleStatusPrimitive prim1 = purple_status_type_get_primitive(statusType1); switch(prim1) { case PURPLE_STATUS_UNSET: { status = "unset"; } break; case PURPLE_STATUS_OFFLINE: { status = "offline"; } break; case PURPLE_STATUS_AVAILABLE: { status = "available"; } break; case PURPLE_STATUS_UNAVAILABLE: { status = "unavailable"; } break; case PURPLE_STATUS_INVISIBLE: { status = "invisible"; } break; case PURPLE_STATUS_AWAY: { status = "away"; } break; case PURPLE_STATUS_EXTENDED_AWAY: { status = "extended away"; } break; case PURPLE_STATUS_MOBILE: { status = "mobile"; } break; case PURPLE_STATUS_TUNE: { status = "tune"; } break; case PURPLE_STATUS_NUM_PRIMITIVES: default: { status = "unknown"; } break; } //TEST instance 1 complete cout << _TAG << "Test instance 1: Status for " << username << " is reported as " << status << endl; 

This code always returns offline status. As if purple does not update a buddy after creating a new instance, it always remains "autonomous". I dived into libpurple and pidgin to try to find this over the last few days, but cannot find the β€œright” way to get the status.

+4
source share
1 answer

For some reason, calling this from a signed-on signal does not work.

Calling it from a buddy-signed-on signal works for me. Of course, in this case it will be called once for each signed friend ...

sample function to be called from the friend-signature signal:

 static void buddy_signed_on(PurpleBuddy *buddy) { GSList *buddies = purple_blist_get_buddies(); for(; buddies; buddies = buddies->next) { PurpleBuddy *b = (PurpleBuddy *) buddies->data; PurplePresence *presence = purple_buddy_get_presence(b); PurpleStatus *status = purple_presence_get_active_status(presence); printf("%s is now %s\n", b->name, purple_status_get_id(status)); } } 

Connect the signal:

 purple_signal_connect(purple_blist_get_handle(), "buddy-signed-on", &handle, PURPLE_CALLBACK(buddy_signed_on), NULL); 
+1
source

All Articles