Obtaining the online state of a participant in an IM session
Another frequently asked query I run into is how to find the state of an IAccParticipant (Online, offline or idle)? Some DAccEvent callbacks like BeforeImSend pass in an IAccParticipant and not an IAccUser.
You can use the get_User method to get an IAccUser object for the participant and then get the state…
IAccParticipant* pPart;
IAccUser* pUser;
HRESULT res = pPart->get_User(&pUser);
if (pUser) // check result too
{
CComVariant st;
pUser->get_Property(AccUserProp_State, &st);
xp_int state = st.intVal;
switch (state)
{
case AccUserState_Away:
case AccUserState_Idle:
case AccUserState_Online:
// do what you need
break;
case AccUserState_Offline:
break;
}
}

Bug: HRESULT res = pPart->get_User(&pPart); <– should be &pUser
Don’t forget that the pUser is an owned reference so you either need to use ATL’s CComPtr rather than IAccUser* or call pUser->Release() before the returning.
One more tip is that AIMcc provides C++ helper functions to retrieve properties. To read state use:
AccUserState state;
AIMCC::get_State(pUser, &state);
instead of using variants directly:
CComVariant st;
pUser->get_Property(AccUserProp_State, &st);
xp_int state = st.intVal;
Thanks for the catch Maurizio! I will fix it now. Thanks Gus, good tip.
My comment isn’t related to this code. But is to the general idea we are discussing here. (user presence)
I was wondering if there is any method to have custom presence for each user on a user’s buddy list.
i.e. it possible to be away for one user, invisible for another, and available to a 3rd all at the same time? [I don't think this is possible with the OSCAR protocol?]
—-
Also I will be in Washington DC in 2 weeks, does AOL ever host in person developer events?
Thanks,
Ben
Unfortunately there is no way to do per user presence with OSCAR.
Also, AOL has not hosted in person developer events in the recent past, but I certainly hope that they will start to do so!
Gowri
What about if you Block and UnBlock users? You could at least do per-user Online or per user Offline?
Yeah you could do that, but it is somewhat drastic in that once you block someone, you are invisible to them until you unblock them explicitly.