From 8cef81c096966af5775861220e67432648a29a7e Mon Sep 17 00:00:00 2001 From: George Hazan Date: Fri, 6 Aug 2021 22:19:50 +0300 Subject: ICQ: same idea for presence packets --- protocols/ICQ-WIM/src/poll.cpp | 39 ++++++++++++++++++++++----------------- 1 file changed, 22 insertions(+), 17 deletions(-) (limited to 'protocols/ICQ-WIM/src') diff --git a/protocols/ICQ-WIM/src/poll.cpp b/protocols/ICQ-WIM/src/poll.cpp index bbf0792cc9..918782e5cc 100644 --- a/protocols/ICQ-WIM/src/poll.cpp +++ b/protocols/ICQ-WIM/src/poll.cpp @@ -321,26 +321,31 @@ void CIcqProto::ProcessPresence(const JSONNode &ev) CMStringW aimId = ev["aimId"].as_mstring(); IcqCacheItem *pCache = FindContactByUIN(aimId); - if (pCache) { - int iNewStatus = StatusFromString(ev["state"].as_mstring()); - - // major crutch dedicated to the official client behaviour to go offline - // when its window gets closed. we change the status of a contact to the - // first chosen one from options and initialize a timer - if (iNewStatus == ID_STATUS_OFFLINE) { - if (m_iTimeDiff1) { - iNewStatus = m_iStatus1; - pCache->m_timer1 = time(0); - } - } - // if a client returns back online, we clear timers not to play with statuses anymore - else pCache->m_timer1 = pCache->m_timer2 = 0; + if (pCache == nullptr) + return; - setWord(pCache->m_hContact, "Status", iNewStatus); + int iNewStatus = StatusFromString(ev["state"].as_mstring()); - Json2string(pCache->m_hContact, ev, "friendly", "Nick"); - CheckAvatarChange(pCache->m_hContact, ev); + int iLastSeen = ev["lastseen"].as_int(); + if (iLastSeen == 0) + iNewStatus = ID_STATUS_ONLINE; + + // major crutch dedicated to the official client behaviour to go offline + // when its window gets closed. we change the status of a contact to the + // first chosen one from options and initialize a timer + if (iNewStatus == ID_STATUS_OFFLINE) { + if (m_iTimeDiff1) { + iNewStatus = m_iStatus1; + pCache->m_timer1 = time(0); + } } + // if a client returns back online, we clear timers not to play with statuses anymore + else pCache->m_timer1 = pCache->m_timer2 = 0; + + setWord(pCache->m_hContact, "Status", iNewStatus); + + Json2string(pCache->m_hContact, ev, "friendly", "Nick"); + CheckAvatarChange(pCache->m_hContact, ev); } void CIcqProto::ProcessSessionEnd(const JSONNode &/*ev*/) -- cgit v1.2.3