From 390d3ecc13780511a2416eb4eb82a14a06516945 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Mon, 27 Nov 2023 21:04:41 +0300 Subject: =?UTF-8?q?fixes=20#3810=20(ICQ:=20=D0=BD=D0=B5=D0=B2=D0=B5=D1=80?= =?UTF-8?q?=D0=BD=D0=BE=20=D1=80=D0=B0=D0=B1=D0=BE=D1=82=D0=B0=D0=B5=D1=82?= =?UTF-8?q?=20Last=20seen=20=D0=B2=20user=20details)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- protocols/ICQ-WIM/src/proto.cpp | 16 ++++++++++-- protocols/ICQ-WIM/src/proto.h | 2 +- protocols/ICQ-WIM/src/server.cpp | 7 ++++- protocols/ICQ-WIM/src/stdafx.h | 1 + protocols/ICQ-WIM/src/userinfo.cpp | 13 ++++++++-- protocols/ICQ-WIM/src/utils.cpp | 53 +++++++++++++++++++++++++++++--------- 6 files changed, 74 insertions(+), 18 deletions(-) (limited to 'protocols') diff --git a/protocols/ICQ-WIM/src/proto.cpp b/protocols/ICQ-WIM/src/proto.cpp index 9255001537..7ea15fc1bd 100644 --- a/protocols/ICQ-WIM/src/proto.cpp +++ b/protocols/ICQ-WIM/src/proto.cpp @@ -347,11 +347,23 @@ void CIcqProto::OnLastSeen(NETLIBHTTPREQUEST *pReply, AsyncHttpRequest *) for (auto &it : results["entries"]) { if (auto *pUser = FindUser(it["sn"].as_mstring())) { int iLastSeen = it["lastseen"].as_int(); - if (iLastSeen != 0) { + switch (iLastSeen) { + case 1388520000: // 01/01/2014, 00:00 GMT + setWString(pUser->m_hContact, DB_KEY_LASTSEEN, TranslateT("long time ago")); + ProcessStatus(pUser, ID_STATUS_OFFLINE); + break; + + case 0: + if (pUser->m_bWasOnline) { + ProcessStatus(pUser, ID_STATUS_ONLINE); + break; + } + __fallthrough; + + default: setDword(pUser->m_hContact, DB_KEY_LASTSEEN, iLastSeen); ProcessStatus(pUser, ID_STATUS_OFFLINE); } - else ProcessStatus(pUser, ID_STATUS_ONLINE); } } } diff --git a/protocols/ICQ-WIM/src/proto.h b/protocols/ICQ-WIM/src/proto.h index 50abf91a31..d44478774e 100644 --- a/protocols/ICQ-WIM/src/proto.h +++ b/protocols/ICQ-WIM/src/proto.h @@ -115,7 +115,7 @@ struct IcqUser : public MZeroedObject CMStringW m_aimid; MCONTACT m_hContact; - bool m_bInList, m_bGotCaps; + bool m_bInList, m_bGotCaps, m_bWasOnline; __int64 m_iProcessedMsgId; int m_iApparentMode; time_t m_timer1, m_timer2; diff --git a/protocols/ICQ-WIM/src/server.cpp b/protocols/ICQ-WIM/src/server.cpp index cc63593a3a..deb86738ec 100644 --- a/protocols/ICQ-WIM/src/server.cpp +++ b/protocols/ICQ-WIM/src/server.cpp @@ -417,8 +417,13 @@ MCONTACT CIcqProto::ParseBuddyInfo(const JSONNode &buddy, MCONTACT hContact, boo // we shall not remove existing phone number anyhow Json2string(hContact, buddy, "phoneNumber", DB_KEY_PHONE, true); + int onlineTime = buddy["onlineTime"].as_int(); + if (onlineTime) + setDword(hContact, DB_KEY_ONLINETS, time(0) - onlineTime); + else + delSetting(hContact, DB_KEY_ONLINETS); + Json2int(hContact, buddy, "official", "Official", bIsPartial); - Json2int(hContact, buddy, "onlineTime", DB_KEY_ONLINETS, bIsPartial); Json2int(hContact, buddy, "idleTime", "IdleTS", bIsPartial); Json2int(hContact, buddy, "memberSince", DB_KEY_MEMBERSINCE, bIsPartial); diff --git a/protocols/ICQ-WIM/src/stdafx.h b/protocols/ICQ-WIM/src/stdafx.h index 6a449f04d2..27b02cd679 100644 --- a/protocols/ICQ-WIM/src/stdafx.h +++ b/protocols/ICQ-WIM/src/stdafx.h @@ -108,6 +108,7 @@ bool IsValidType(const JSONNode &aimid); void RefreshGroups(void); wchar_t* time2text(time_t time); +wchar_t* time2text(DBVARIANT *dbv); CMStringW fileText2url(const CMStringW &wszText); diff --git a/protocols/ICQ-WIM/src/userinfo.cpp b/protocols/ICQ-WIM/src/userinfo.cpp index 61f661a31b..2bada55d29 100644 --- a/protocols/ICQ-WIM/src/userinfo.cpp +++ b/protocols/ICQ-WIM/src/userinfo.cpp @@ -36,10 +36,19 @@ struct IcqUserInfoDlg : public CUserInfoPageDlg SetDlgItemTextW(m_hwnd, IDC_NICK, ppro->getMStringW(m_hContact, DB_KEY_ICQNICK)); SetDlgItemTextW(m_hwnd, IDC_PHONE, ppro->getMStringW(m_hContact, DB_KEY_PHONE)); + DBVARIANT dbv = {}; + if (!db_get(m_hContact, ppro->m_szModuleName, DB_KEY_LASTSEEN, &dbv)) { + SetDlgItemTextW(m_hwnd, IDC_LASTSEEN, time2text(&dbv)); + db_free(&dbv); + } + + if (!db_get(m_hContact, ppro->m_szModuleName, DB_KEY_ONLINETS, &dbv)) { + SetDlgItemTextW(m_hwnd, IDC_ONLINESINCE, time2text(&dbv)); + db_free(&dbv); + } + SetDlgItemTextW(m_hwnd, IDC_IDLETIME, time2text(ppro->getDword(m_hContact, DB_KEY_IDLE))); - SetDlgItemTextW(m_hwnd, IDC_LASTSEEN, time2text(ppro->getDword(m_hContact, DB_KEY_LASTSEEN))); SetDlgItemTextW(m_hwnd, IDC_MEMBERSINCE, time2text(ppro->getDword(m_hContact, DB_KEY_MEMBERSINCE))); - SetDlgItemTextW(m_hwnd, IDC_ONLINESINCE, time2text(time(0) - ppro->getDword(m_hContact, DB_KEY_ONLINETS))); return false; } }; diff --git a/protocols/ICQ-WIM/src/utils.cpp b/protocols/ICQ-WIM/src/utils.cpp index 56ef3dce88..6db1050801 100644 --- a/protocols/ICQ-WIM/src/utils.cpp +++ b/protocols/ICQ-WIM/src/utils.cpp @@ -169,10 +169,17 @@ bool IsValidType(const JSONNode &n) int CIcqProto::StatusFromPresence(const JSONNode &presence, MCONTACT hContact) { + auto *pUser = FindUser(GetUserId(hContact)); + if (pUser == nullptr) + return -1; + CMStringW wszStatus = presence["state"].as_mstring(); int iStatus; - if (wszStatus == L"online") + if (wszStatus == L"online") { + pUser->m_bWasOnline = true; iStatus = ID_STATUS_ONLINE; + setDword(hContact, DB_KEY_ONLINETS, time(0)); + } else if (wszStatus == L"offline") iStatus = ID_STATUS_OFFLINE; else if (wszStatus == L"n/a") @@ -187,17 +194,21 @@ int CIcqProto::StatusFromPresence(const JSONNode &presence, MCONTACT hContact) return -1; int iLastSeen = presence["lastseen"].as_int(); - if (iLastSeen != 0) - setDword(hContact, DB_KEY_LASTSEEN, iLastSeen); + if (iLastSeen != 0) { + if (iLastSeen == 1388520000) // 01/01/2014, 00:00 GMT + setWString(hContact, DB_KEY_LASTSEEN, TranslateT("long time ago")); + else + setDword(hContact, DB_KEY_LASTSEEN, iLastSeen); + } else { - if (getDword(hContact, DB_KEY_ONLINETS)) + if (pUser->m_bWasOnline) { iStatus = ID_STATUS_ONLINE; + setDword(hContact, DB_KEY_ONLINETS, time(0)); + } else { - if (auto *pUser = FindUser(GetUserId(hContact))) { - mir_cslock lck(m_csLastSeenQueue); - m_arLastSeenQueue.insert(pUser); - m_impl.m_lastSeen.Start(500); - } + mir_cslock lck(m_csLastSeenQueue); + m_arLastSeenQueue.insert(pUser); + m_impl.m_lastSeen.Start(500); return -1; } } @@ -255,14 +266,32 @@ CMStringW fileText2url(const CMStringW &wszText) ///////////////////////////////////////////////////////////////////////////////////////// +static wchar_t g_statBuf[100]; + +wchar_t* time2text(DBVARIANT *dbv) +{ + switch (dbv->type) { + case DBVT_WCHAR: + return dbv->pwszVal; + + case DBVT_DWORD: + return time2text(time_t(dbv->dVal)); + + case DBVT_UTF8: + wcsncpy_s(g_statBuf, Utf2T(dbv->pszVal), _TRUNCATE); + return g_statBuf; + } + + return L""; +} + wchar_t* time2text(time_t ts) { if (ts == 0) return L""; - static wchar_t buf[100]; - TimeZone_PrintTimeStamp(NULL, ts, L"D t", buf, _countof(buf), 0); - return buf; + TimeZone_PrintTimeStamp(NULL, ts, L"D t", g_statBuf, _countof(g_statBuf), 0); + return g_statBuf; } ///////////////////////////////////////////////////////////////////////////////////////// -- cgit v1.2.3