我正在尝试在SIMPLE网络(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试图在过去几天找到这个,但找不到“正确”的检索状态的方法。
答案 0 :(得分:1)
出于某种原因,从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 %s\n", b->name, purple_status_get_id(status));
}
}
连接信号:
purple_signal_connect(purple_blist_get_handle(), "buddy-signed-on", &handle,
PURPLE_CALLBACK(buddy_signed_on), NULL);