summaryrefslogtreecommitdiff
path: root/protocols
diff options
context:
space:
mode:
authorGeorge Hazan <george.hazan@gmail.com>2023-11-27 21:04:41 +0300
committerGeorge Hazan <george.hazan@gmail.com>2023-11-27 21:04:41 +0300
commit390d3ecc13780511a2416eb4eb82a14a06516945 (patch)
treed2b134d10b92e78b8375e106e5fcb957a72d3b22 /protocols
parente0b3359cf55fbf3d83faad624265d928023f0928 (diff)
fixes #3810 (ICQ: неверно работает Last seen в user details)
Diffstat (limited to 'protocols')
-rw-r--r--protocols/ICQ-WIM/src/proto.cpp16
-rw-r--r--protocols/ICQ-WIM/src/proto.h2
-rw-r--r--protocols/ICQ-WIM/src/server.cpp7
-rw-r--r--protocols/ICQ-WIM/src/stdafx.h1
-rw-r--r--protocols/ICQ-WIM/src/userinfo.cpp13
-rw-r--r--protocols/ICQ-WIM/src/utils.cpp53
6 files changed, 74 insertions, 18 deletions
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;
}
/////////////////////////////////////////////////////////////////////////////////////////