从libpurple(支持Pidgin的IM库)检索另一个用户的状态



我试图在一个简单的网络(Microsoft Office Communicator)上拉另一个人的当前状态。我使用libpurple,在libpurple周围构建了一个c++包装器,我可以在SIMPLE网络上与其他用户发送/接收im。我还需要的是获取其他用户的当前状态

这是我当前尝试检索另一个用户的状态。
先前定义和初始化:

PurpleAccount *CommonIM::m_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;

这段代码总是返回离线状态。就好像紫色在创建新实例后不会刷新好友一样,它总是保持"脱机"状态。在过去的几天里,我潜入libpurple和pidgin试图找到这个,但找不到检索状态的"适当"方式。

由于某种原因,从signed-on信号调用此操作不起作用。

buddy-signed-on信号调用它对我有效。当然,在这种情况下,它将为每个已登录的伙伴调用一次…

从"buddy-signed-on"信号调用的示例函数:

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 %sn", b->name, purple_status_get_id(status));
    }
}

连接信号:

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

相关内容

  • 没有找到相关文章

最新更新