开发者

Retrieving the status of another user from libpurple (the IM library underpinning Pidgin)

I'm trying to pull the current status of another person on a SIMPLE network (Microsoft Office Communicator). I'm using libpurple, built a c++ wrapper around libpurple, and I can send/receive IMs wit开发者_开发问答h other users on the SIMPLE network. What I still need is to get the current status of other users

Here's my current attempt at retrieving 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, e.g. 
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 as the status. It's as if purple doesn't refresh the buddy after creating a new instance, it always remains as "offline". I've dived into libpurple and pidgin to try to find this for the past few days but can't find the 'proper' way of retrieving status.


For some reason, calling this from the signed-on signal doesn't work.

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

sample function to be called from the "buddy-signed-on" 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);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜