summaryrefslogtreecommitdiff
path: root/protocols
diff options
context:
space:
mode:
authorElzorFox <elzorfox@ya.ru>2023-08-04 13:48:45 +0500
committerElzorFox <elzorfox@ya.ru>2023-08-04 13:49:45 +0500
commitd75f7701a7c242b9953ab0e867a7eaad72c0c319 (patch)
treecd0d17a70a44a55aacfb12a9b3cb0686448851f8 /protocols
parentc6391e7587e1b028735fd217f9c9cb05c6268e8f (diff)
VKontakte:
VK ID INT64 compatibility – part 1 code cleanup version bump
Diffstat (limited to 'protocols')
-rw-r--r--protocols/VKontakte/src/misc.cpp245
-rw-r--r--protocols/VKontakte/src/version.h2
-rw-r--r--protocols/VKontakte/src/vk.h11
-rw-r--r--protocols/VKontakte/src/vk_avatars.cpp4
-rw-r--r--protocols/VKontakte/src/vk_chats.cpp271
-rw-r--r--protocols/VKontakte/src/vk_dialogs.cpp8
-rw-r--r--protocols/VKontakte/src/vk_feed.cpp60
-rw-r--r--protocols/VKontakte/src/vk_files.cpp33
-rw-r--r--protocols/VKontakte/src/vk_history.cpp91
-rw-r--r--protocols/VKontakte/src/vk_messages.cpp152
-rw-r--r--protocols/VKontakte/src/vk_pollserver.cpp123
-rw-r--r--protocols/VKontakte/src/vk_proto.cpp63
-rw-r--r--protocols/VKontakte/src/vk_proto.h88
-rw-r--r--protocols/VKontakte/src/vk_queue.cpp22
-rw-r--r--protocols/VKontakte/src/vk_struct.cpp66
-rw-r--r--protocols/VKontakte/src/vk_struct.h65
-rw-r--r--protocols/VKontakte/src/vk_thread.cpp147
-rw-r--r--protocols/VKontakte/src/vk_wallpost.cpp6
18 files changed, 781 insertions, 676 deletions
diff --git a/protocols/VKontakte/src/misc.cpp b/protocols/VKontakte/src/misc.cpp
index 7e2d06bf90..aae67d094b 100644
--- a/protocols/VKontakte/src/misc.cpp
+++ b/protocols/VKontakte/src/misc.cpp
@@ -121,9 +121,9 @@ void CVkProto::CheckUpdate()
{
if (getByte("Compatibility") < 1) {
for (auto &cc : AccContacts()) {
- LONG userId = getDword(cc, "vk_chat_id", VK_INVALID_USER);
- if (userId != VK_INVALID_USER) {
- setDword(cc, "ID", userId);
+ VKUserID_t iUserId = getDword(cc, "vk_chat_id", VK_INVALID_USER);
+ if (iUserId != VK_INVALID_USER) {
+ WriteVKUserID(cc, iUserId);
delSetting(cc, "vk_chat_id");
delSetting(cc, "ChatRoomID");
}
@@ -132,6 +132,80 @@ void CVkProto::CheckUpdate()
}
}
+//////////////////////// bIint64IDCompatibility /////////////////////////////////////////
+
+void CVkProto::WriteQSWord(MCONTACT hContact, const char *szParam, uint64_t uValue)
+{
+ if (!bIint64IDCompatibility)
+ db_unset(hContact, m_szModuleName, szParam);
+
+ char szValue[40];
+ _ltoa(uValue, szValue, 10);
+ setString(hContact, szParam, szValue);
+}
+
+uint64_t CVkProto::ReadQSWord(MCONTACT hContact, const char* szParam, uint64_t uDefaultValue)
+{
+ if (!bIint64IDCompatibility) {
+ uint64_t uValue = getDword(hContact, szParam, uDefaultValue);
+ if (uValue != uDefaultValue) {
+ WriteQSWord(hContact, szParam, uValue);
+ return uValue;
+ }
+ }
+
+ ptrA szValue(getStringA(hContact, szParam));
+ return szValue ? strtol(szValue, nullptr, 10) : uDefaultValue;
+}
+
+VKUserID_t CVkProto::ReadVKUserIDFromString(MCONTACT hContact)
+{
+ ptrA szID(getStringA(hContact, "ID"));
+ return szID ? strtol(szID, nullptr, 10) : VK_INVALID_USER;
+}
+
+VKUserID_t CVkProto::ReadVKUserID(MCONTACT hContact)
+{
+ if (bIint64IDCompatibility)
+ return ReadVKUserIDFromString(hContact);
+
+ VKUserID_t iUserId = getDword(hContact, "ID", VK_INVALID_USER);
+ return iUserId ? iUserId : ReadVKUserIDFromString(hContact);
+}
+
+void CVkProto::WriteVKUserID(MCONTACT hContact, VKUserID_t iUserId)
+{
+ if (bIint64IDCompatibility || iUserId > 0xFFFFFFFF) {
+ char szID[40];
+ _ltoa(iUserId, szID, 10);
+ setString(hContact, "ID", szID);
+ }
+ else
+ setDword(hContact, "ID", iUserId);
+}
+
+VKPeerType CVkProto::GetVKPeerType(VKUserID_t iPeerId)
+{
+ if (VK_INVALID_USER == iPeerId)
+ return VKPeerType::vkPeerError;
+
+ if (iPeerId == VK_FEED_USER)
+ return VKPeerType::vkPeerFeed;
+
+ if (iPeerId < VK_INVALID_USER)
+ return VKPeerType::vkPeerGroup;
+
+ if ((iPeerId < VK_USERID_MAX1) || (iPeerId >= VK_USERID_MIN2 && iPeerId < VK_USERID_MAX2))
+ return VKPeerType::vkPeerUser;
+
+ if (iPeerId > VK_CHAT_MIN && iPeerId < VK_CHAT_MAX)
+ return VKPeerType::vkPeerMUC;
+
+ return VKPeerType::vkPeerError;
+}
+
+/////////////////////////////////////////////////////////////////////////////////////////
+
void CVkProto::ClearAccessToken()
{
debugLogA("CVkProto::ClearAccessToken");
@@ -166,7 +240,7 @@ void CVkProto::SetAllContactStatuses(int iStatus)
/////////////////////////////////////////////////////////////////////////////////////////
-MCONTACT CVkProto::FindUser(LONG dwUserid, bool bCreate)
+MCONTACT CVkProto::FindUser(VKUserID_t dwUserid, bool bCreate)
{
if (!dwUserid)
return 0;
@@ -175,7 +249,7 @@ MCONTACT CVkProto::FindUser(LONG dwUserid, bool bCreate)
if (isChatRoom(hContact))
continue;
- LONG dbUserid = getDword(hContact, "ID", VK_INVALID_USER);
+ VKUserID_t dbUserid = ReadVKUserID(hContact);
if (dbUserid == VK_INVALID_USER)
continue;
@@ -188,27 +262,27 @@ MCONTACT CVkProto::FindUser(LONG dwUserid, bool bCreate)
MCONTACT hNewContact = db_add_contact();
Proto_AddToContact(hNewContact, m_szModuleName);
- setDword(hNewContact, "ID", dwUserid);
+ WriteVKUserID(hNewContact, dwUserid);
Clist_SetGroup(hNewContact, m_vkOptions.pwszDefaultGroup);
- if (dwUserid < 0)
+ if (GetVKPeerType(dwUserid) == VKPeerType::vkPeerGroup)
setByte(hNewContact, "IsGroup", 1);
return hNewContact;
}
-MCONTACT CVkProto::FindChat(LONG dwUserid)
+MCONTACT CVkProto::FindChat(VKUserID_t iUserId)
{
- if (!dwUserid)
+ if (!iUserId)
return 0;
for (auto &hContact : AccContacts()) {
if (!isChatRoom(hContact))
continue;
- LONG dbUserid = getDword(hContact, "ID", VK_INVALID_USER);
+ VKUserID_t dbUserid = ReadVKUserID(hContact);
if (dbUserid == VK_INVALID_USER)
continue;
- if (dbUserid == dwUserid)
+ if (dbUserid == iUserId)
return hContact;
}
@@ -220,22 +294,10 @@ bool CVkProto::IsGroupUser(MCONTACT hContact)
if (getBool(hContact, "IsGroup", false))
return true;
- LONG userID = getDword(hContact, "ID", VK_INVALID_USER);
- return (userID < 0);
+ VKUserID_t iUserId = ReadVKUserID(hContact);
+ return GetVKPeerType(iUserId) == VKPeerType::vkPeerGroup;
}
-/////////////////////////////////////////////////////////////////////////////////////////
-
-bool CVkProto::CheckMid(LIST<void> &lList, int guid)
-{
- for (auto &it : lList)
- if ((INT_PTR)it == guid) {
- lList.removeItem(&it);
- return true;
- }
-
- return false;
-}
/////////////////////////////////////////////////////////////////////////////////////////
@@ -324,8 +386,8 @@ bool CVkProto::CheckJsonResult(AsyncHttpRequest *pReq, const JSONNode &jnNode)
pReq->m_iRetry--;
}
else {
- CMStringW msg(FORMAT, TranslateT("Error %d. Data will not be sent or received."), iErrorCode);
- MsgPopup(msg, TranslateT("Error"), true);
+ CMStringW wszMsg(FORMAT, TranslateT("Error %d. Data will not be sent or received."), iErrorCode);
+ MsgPopup(wszMsg, TranslateT("Error"), true);
debugLogA("CVkProto::CheckJsonResult SendError");
}
break;
@@ -658,11 +720,11 @@ MCONTACT CVkProto::MContactFromDbEvent(MEVENT hDbEvent)
/////////////////////////////////////////////////////////////////////////////////////////
-void CVkProto::SetMirVer(MCONTACT hContact, int platform)
+void CVkProto::SetMirVer(MCONTACT hContact, int iPlatform)
{
if (hContact == 0 || hContact == INVALID_CONTACT_ID)
return;
- if (platform == -1) {
+ if (iPlatform == -1) {
db_unset(hContact, m_szModuleName, "MirVer");
return;
}
@@ -670,7 +732,7 @@ void CVkProto::SetMirVer(MCONTACT hContact, int platform)
CMStringW MirVer, OldMirVer(ptrW(db_get_wsa(hContact, m_szModuleName, "MirVer")));
bool bSetFlag = true;
- switch (platform) {
+ switch (iPlatform) {
case VK_APP_ID:
MirVer = L"Miranda NG VKontakte";
break;
@@ -790,13 +852,13 @@ int CVkProto::OnProcessSrmmEvent(WPARAM, LPARAM lParam)
void CVkProto::SetSrmmReadStatus(MCONTACT hContact)
{
- time_t time = getDword(hContact, "LastMsgReadTime");
- if (!time)
+ time_t tTime = getDword(hContact, "LastMsgReadTime");
+ if (!tTime)
return;
wchar_t ttime[64];
_locale_t locale = _create_locale(LC_ALL, "");
- _wcsftime_l(ttime, _countof(ttime), L"%X - %x", localtime(&time), locale);
+ _wcsftime_l(ttime, _countof(ttime), L"%X - %x", localtime(&tTime), locale);
_free_locale(locale);
Srmm_SetStatusText(hContact, CMStringW(FORMAT, TranslateT("Message read: %s"), ttime), g_plugin.getIcon(IDI_READMSG));
@@ -808,8 +870,8 @@ void CVkProto::MarkDialogAsRead(MCONTACT hContact)
if (!IsOnline())
return;
- LONG userID = getDword(hContact, "ID", VK_INVALID_USER);
- if (userID == VK_INVALID_USER || userID == VK_FEED_USER)
+ VKUserID_t iUserId = ReadVKUserID(hContact);
+ if (iUserId == VK_INVALID_USER || iUserId == VK_FEED_USER)
return;
MEVENT hDBEvent = db_event_firstUnread(hContact);
@@ -827,28 +889,28 @@ void CVkProto::MarkDialogAsRead(MCONTACT hContact)
}
}
-char* CVkProto::GetStickerId(const char *Msg, int &stickerid)
+char* CVkProto::GetStickerId(const char *szMsg, int &iStickerId)
{
- stickerid = 0;
- char *retMsg = nullptr;
+ iStickerId = 0;
+ char *szRetMsg = nullptr;
int iRes = 0;
- const char *tmpMsg = strstr(Msg, "[sticker");
- if (tmpMsg)
- iRes = sscanf(tmpMsg, "[sticker:%d]", &stickerid) == 1 ? 1 : sscanf(tmpMsg, "[sticker-%d]", &stickerid);
+ const char *szTmpMsg = strstr(szMsg, "[sticker");
+ if (szTmpMsg)
+ iRes = sscanf(szTmpMsg, "[sticker:%d]", &iStickerId) == 1 ? 1 : sscanf(szTmpMsg, "[sticker-%d]", &iStickerId);
if (iRes == 1) {
char HeadMsg[32] = { 0 };
- mir_snprintf(HeadMsg, "[sticker:%d]", stickerid);
+ mir_snprintf(HeadMsg, "[sticker:%d]", iStickerId);
size_t retLen = mir_strlen(HeadMsg);
- if (retLen < mir_strlen(Msg)) {
- CMStringA szMsg(Msg, int(mir_strlen(Msg) - mir_strlen(tmpMsg)));
- szMsg.Append(&tmpMsg[retLen]);
- retMsg = mir_strdup(szMsg.Trim());
+ if (retLen < mir_strlen(szMsg)) {
+ CMStringA szRMsg(szMsg, int(mir_strlen(szMsg) - mir_strlen(szTmpMsg)));
+ szRMsg.Append(&szTmpMsg[retLen]);
+ szRetMsg = mir_strdup(szRMsg.Trim());
}
}
- return retMsg;
+ return szRetMsg;
}
const char* FindVKUrls(const char *Msg)
@@ -870,12 +932,12 @@ const char* FindVKUrls(const char *Msg)
}
-CMStringA CVkProto::GetAttachmentsFromMessage(const char *Msg)
+CMStringA CVkProto::GetAttachmentsFromMessage(const char *szMsg)
{
- if (IsEmpty(Msg))
+ if (IsEmpty(szMsg))
return CMStringA();
- const char *pos = FindVKUrls(Msg);
+ const char *pos = FindVKUrls(szMsg);
if (!pos)
return CMStringA();
@@ -888,7 +950,7 @@ CMStringA CVkProto::GetAttachmentsFromMessage(const char *Msg)
pos = pos2 + mir_strlen(szVKLinkParam[i]);
}
- if (pos >= (Msg + mir_strlen(Msg)))
+ if (pos >= (szMsg + mir_strlen(szMsg)))
return CMStringA();
int iRes = 0,
@@ -1194,7 +1256,7 @@ CMStringW CVkProto::GetAttachmentDescr(const JSONNode &jnAttachments, BBCSupport
CMStringW wszTitle(jnVideo["title"].as_mstring());
int iVideoId = jnVideo["id"].as_int();
- int iOwnerId = jnVideo["owner_id"].as_int();
+ VKUserID_t iOwnerId = jnVideo["owner_id"].as_int();
CMStringW wszUrl(FORMAT, L"https://vk.com/video%d_%d", iOwnerId, iVideoId);
res.AppendFormat(L"%s: %s",
@@ -1222,7 +1284,7 @@ CMStringW CVkProto::GetAttachmentDescr(const JSONNode &jnAttachments, BBCSupport
CMStringW wszText(jnWall["text"].as_mstring());
int iWallId = jnWall["id"].as_int();
- int iFromId = jnWall["from_id"].as_int();
+ VKUserID_t iFromId = jnWall["from_id"].as_int();
CMStringW wszUrl(FORMAT, L"https://vk.com/wall%d_%d", iFromId, iWallId);
res.AppendFormat(L"%s: %s",
SetBBCString(TranslateT("Wall post"), iBBC, vkbbcUrl, wszUrl).c_str(),
@@ -1233,7 +1295,7 @@ CMStringW CVkProto::GetAttachmentDescr(const JSONNode &jnAttachments, BBCSupport
for (auto& jnCopyHystoryItem : jnCopyHystory) {
CMStringW wszCHText(jnCopyHystoryItem["text"].as_mstring());
int iCHid = jnCopyHystoryItem["id"].as_int();
- int iCHfromID = jnCopyHystoryItem["from_id"].as_int();
+ VKUserID_t iCHfromID = jnCopyHystoryItem["from_id"].as_int();
CMStringW wszCHUrl(FORMAT, L"https://vk.com/wall%d_%d", iCHfromID, iCHid);
wszCHText.Replace(L"\n", L"\n\t\t");
res.AppendFormat(L"\n\t\t%s: %s",
@@ -1267,8 +1329,8 @@ CMStringW CVkProto::GetAttachmentDescr(const JSONNode &jnAttachments, BBCSupport
CMStringW wszText(jnWallReply["text"].as_mstring());
int iWallReplyId = jnWallReply["id"].as_int();
- int iFromId = jnWallReply["from_id"].as_int();
- int iFromOwnerId = jnWallReply["owner_id"].as_int();
+ VKUserID_t iFromId = jnWallReply["from_id"].as_int();
+ VKUserID_t iFromOwnerId = jnWallReply["owner_id"].as_int();
int iPostOwnerId = jnWallReply["post_id"].as_int();
int iThreadId = jnWallReply["reply_to_comment"].as_int();
@@ -1276,7 +1338,7 @@ CMStringW CVkProto::GetAttachmentDescr(const JSONNode &jnAttachments, BBCSupport
CMStringW wszFromNick, wszFromUrl;
MCONTACT hFromContact = FindUser(iFromId);
- if (hFromContact || iFromId == m_myUserId)
+ if (hFromContact || iFromId == m_iMyUserId)
wszFromNick = ptrW(db_get_wsa(hFromContact, m_szModuleName, "Nick"));
else
wszFromNick = TranslateT("(Unknown contact)");
@@ -1302,7 +1364,7 @@ CMStringW CVkProto::GetAttachmentDescr(const JSONNode &jnAttachments, BBCSupport
if (!jnStory)
continue;
int iStoryId = jnStory["id"].as_int();
- int iOwnerID = jnStory["owner_id"].as_int();
+ VKUserID_t iOwnerID = jnStory["owner_id"].as_int();
CMStringW wszUrl(FORMAT, L"https://vk.com/story%d_%d", iOwnerID, iStoryId);
res.AppendFormat(L"%s",
@@ -1325,7 +1387,7 @@ CMStringW CVkProto::GetAttachmentDescr(const JSONNode &jnAttachments, BBCSupport
CMStringW wszTitle(jnVideo["title"].as_mstring());
int iVideoId = jnVideo["id"].as_int();
- int iOwnerId = jnVideo["owner_id"].as_int();
+ VKUserID_t iOwnerId = jnVideo["owner_id"].as_int();
CMStringW wszVideoUrl(FORMAT, L"https://vk.com/video%d_%d", iOwnerId, iVideoId);
res.AppendFormat(L"\n\t%s: %s",
@@ -1427,14 +1489,14 @@ CMStringW CVkProto::GetAttachmentDescr(const JSONNode &jnAttachments, BBCSupport
const JSONNode& jnMarket = jnAttach["market"];
int id = jnMarket["id"].as_int();
- int ownerID = jnMarket["owner_id"].as_int();
+ VKUserID_t iOwnerID = jnMarket["owner_id"].as_int();
CMStringW wszTitle(jnMarket["title"].as_mstring());
CMStringW wszDescription(jnMarket["description"].as_mstring());
CMStringW wszPhoto(jnMarket["thumb_photo"].as_mstring());
CMStringW wszUrl(FORMAT, L"https://vk.com/%s%d?w=product%d_%d",
- ownerID > 0 ? L"id" : L"club",
- ownerID > 0 ? ownerID : (-1) * ownerID,
- ownerID,
+ iOwnerID > 0 ? L"id" : L"club",
+ iOwnerID > 0 ? iOwnerID : (-1) * iOwnerID,
+ iOwnerID,
id);
res.AppendFormat(L"%s: %s",
@@ -1490,10 +1552,10 @@ CMStringW CVkProto::GetAttachmentDescr(const JSONNode &jnAttachments, BBCSupport
CMStringW CVkProto::GetFwdMessage(const JSONNode& jnMsg, const JSONNode& jnFUsers, OBJLIST<CVkUserInfo>& vkUsers, BBCSupport iBBC)
{
- LONG uid = jnMsg["from_id"].as_int();
+ VKUserID_t iUserId = jnMsg["from_id"].as_int();
CMStringW wszBody(jnMsg["text"].as_mstring());
- CVkUserInfo* vkUser = vkUsers.find((CVkUserInfo*)&uid);
+ CVkUserInfo* vkUser = vkUsers.find((CVkUserInfo*)&iUserId);
CMStringW wszNick, wszUrl;
if (vkUser) {
@@ -1501,12 +1563,12 @@ CMStringW CVkProto::GetFwdMessage(const JSONNode& jnMsg, const JSONNode& jnFUser
wszUrl = vkUser->m_wszLink;
}
else {
- MCONTACT hContact = FindUser(uid);
- if (hContact || uid == m_myUserId)
+ MCONTACT hContact = FindUser(iUserId);
+ if (hContact || iUserId == m_iMyUserId)
wszNick = ptrW(db_get_wsa(hContact, m_szModuleName, "Nick"));
else
wszNick = TranslateT("(Unknown contact)");
- wszUrl = UserProfileUrl(uid);
+ wszUrl = UserProfileUrl(iUserId);
}
time_t datetime = (time_t)jnMsg["date"].as_int();
@@ -1560,7 +1622,7 @@ CMStringW CVkProto::GetFwdMessages(const JSONNode &jnMessages, const JSONNode &j
OBJLIST<CVkUserInfo> vkUsers(2, NumericKeySortT);
for (auto &jnUser : jnFUsers) {
- int iUserId = jnUser["id"].as_int();
+ VKUserID_t iUserId = jnUser["id"].as_int();
CMStringW wszNick(jnUser["name"].as_mstring());
if (!wszNick.IsEmpty())
@@ -1590,16 +1652,16 @@ CMStringW CVkProto::GetFwdMessages(const JSONNode &jnMessages, const JSONNode &j
void CVkProto::SetInvisible(MCONTACT hContact)
{
- debugLogA("CVkProto::SetInvisible %d", getDword(hContact, "ID", VK_INVALID_USER));
+ debugLogA("CVkProto::SetInvisible %d", ReadVKUserID(hContact));
if (getWord(hContact, "Status", ID_STATUS_OFFLINE) == ID_STATUS_OFFLINE) {
setWord(hContact, "Status", ID_STATUS_INVISIBLE);
SetMirVer(hContact, 1);
db_set_dw(hContact, "BuddyExpectator", "LastStatus", ID_STATUS_INVISIBLE);
- debugLogA("CVkProto::SetInvisible %d set ID_STATUS_INVISIBLE", getDword(hContact, "ID", VK_INVALID_USER));
+ debugLogA("CVkProto::SetInvisible %d set ID_STATUS_INVISIBLE", ReadVKUserID(hContact));
}
- time_t now = time(0);
- db_set_dw(hContact, "BuddyExpectator", "LastSeen", (uint32_t)now);
- setDword(hContact, "InvisibleTS", (uint32_t)now);
+ time_t tNow = time(0);
+ db_set_dw(hContact, "BuddyExpectator", "LastSeen", (uint32_t)tNow);
+ setDword(hContact, "InvisibleTS", (uint32_t)tNow);
}
CMStringW CVkProto::RemoveBBC(CMStringW& wszSrc)
@@ -1754,25 +1816,25 @@ void CVkProto::AddVkDeactivateEvent(MCONTACT hContact, CMStringW& wszType)
}
-MEVENT CVkProto::GetMessageFromDb(UINT iMsgId, UINT &timestamp, CMStringW &msg)
+MEVENT CVkProto::GetMessageFromDb(VKMessageID_t iMessageId, time_t& tTimeStamp, CMStringW& wszMsg)
{
char szMid[40];
- _itoa(iMsgId, szMid, 10);
- return GetMessageFromDb(szMid, timestamp, msg);
+ _ltoa(iMessageId, szMid, 10);
+ return GetMessageFromDb(szMid, tTimeStamp, wszMsg);
}
-MEVENT CVkProto::GetMessageFromDb(const char *messageId, UINT &timestamp, CMStringW &msg)
+MEVENT CVkProto::GetMessageFromDb(const char *szMessageId, time_t& tTimeStamp, CMStringW& wszMsg)
{
- if (messageId == nullptr)
+ if (szMessageId == nullptr)
return 0;
- MEVENT hDbEvent = db_event_getById(m_szModuleName, messageId);
+ MEVENT hDbEvent = db_event_getById(m_szModuleName, szMessageId);
if (!hDbEvent)
return 0;
DB::EventInfo dbei(hDbEvent);
- msg = ptrW(mir_utf8decodeW((char*)dbei.pBlob));
- timestamp = dbei.timestamp;
+ wszMsg = ptrW(mir_utf8decodeW((char*)dbei.pBlob));
+ tTimeStamp = dbei.timestamp;
return hDbEvent;
}
@@ -1783,10 +1845,10 @@ int CVkProto::DeleteContact(MCONTACT hContact)
return db_delete_contact(hContact, true);
}
-bool CVkProto::IsMessageExist(UINT iMsgId, VKMesType vkType)
+bool CVkProto::IsMessageExist(VKMessageID_t iMessageId, VKMesType vkType)
{
char szMid[40];
- _itoa(iMsgId, szMid, 10);
+ _ltoa(iMessageId, szMid, 10);
MEVENT hDbEvent = db_event_getById(m_szModuleName, szMid);
@@ -1803,7 +1865,18 @@ bool CVkProto::IsMessageExist(UINT iMsgId, VKMesType vkType)
return ((vkType == vkOUT) == (bool)(dbei.flags & DBEF_SENT));
}
-CMStringW CVkProto::UserProfileUrl(LONG iUserId)
+CMStringW CVkProto::UserProfileUrl(VKUserID_t iUserId)
{
- return CMStringW(FORMAT, L"https://vk.com/%s%d", iUserId > 0 ? L"id" : L"club", iUserId > 0 ? iUserId : -1 * iUserId);
+ if (GetVKPeerType(iUserId) == VKPeerType::vkPeerError)
+ return CMStringW(L"https://vk.com/");
+
+ if (GetVKPeerType(iUserId) == VKPeerType::vkPeerFeed)
+ return CMStringW(L"https://vk.com/feed");
+
+ if (GetVKPeerType(iUserId) == VKPeerType::vkPeerMUC)
+ return CMStringW(L"https://vk.com/im?sel=c%d", iUserId - VK_CHAT_MIN);
+
+ bool bIsUser = GetVKPeerType(iUserId) == VKPeerType::vkPeerUser;
+
+ return CMStringW(FORMAT, L"https://vk.com/%s%d", bIsUser ? L"id" : L"club", bIsUser ? iUserId : -1 * iUserId);
} \ No newline at end of file
diff --git a/protocols/VKontakte/src/version.h b/protocols/VKontakte/src/version.h
index f242dce88d..377ddcad09 100644
--- a/protocols/VKontakte/src/version.h
+++ b/protocols/VKontakte/src/version.h
@@ -1,7 +1,7 @@
#define __MAJOR_VERSION 0
#define __MINOR_VERSION 1
#define __RELEASE_NUM 14
-#define __BUILD_NUM 7
+#define __BUILD_NUM 8
#include <stdver.h>
diff --git a/protocols/VKontakte/src/vk.h b/protocols/VKontakte/src/vk.h
index f1af226f8a..e57b21b865 100644
--- a/protocols/VKontakte/src/vk.h
+++ b/protocols/VKontakte/src/vk.h
@@ -93,7 +93,13 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#define VK_FEED_USER 2147483647L
#define VK_INVALID_USER 0L
-#define VK_CHAT_FLAG 2000000000
+
+#define VK_CHAT_MIN 2000000000
+#define VK_CHAT_MAX VK_CHAT_MIN + 100000000
+#define VK_USERID_MAX1 1900000000
+#define VK_USERID_MIN2 200000000000
+#define VK_USERID_MAX2 1000000000000
+
#if defined(_DEBUG)
#define VK_NODUMPHEADERS 0
@@ -113,3 +119,6 @@ char* ExpUrlEncode(const char *szUrl, bool strict = false);
bool IsEmpty(LPCWSTR str);
bool IsEmpty(LPCSTR str);
+
+typedef long VKUserID_t;
+typedef long VKMessageID_t;
diff --git a/protocols/VKontakte/src/vk_avatars.cpp b/protocols/VKontakte/src/vk_avatars.cpp
index f6e02d8c2c..29288a2a3a 100644
--- a/protocols/VKontakte/src/vk_avatars.cpp
+++ b/protocols/VKontakte/src/vk_avatars.cpp
@@ -145,8 +145,8 @@ void CVkProto::GetAvatarFileName(MCONTACT hContact, wchar_t *pwszDest, size_t cb
szFileType = p;
}
- LONG id = getDword(hContact, "ID", VK_INVALID_USER);
- wszPath.AppendFormat(L"%d%s", id, szFileType);
+ VKUserID_t iUserId = ReadVKUserID(hContact);
+ wszPath.AppendFormat(L"%d%s", iUserId, szFileType);
wcsncpy_s(pwszDest, cbLen, wszPath, _TRUNCATE);
}
diff --git a/protocols/VKontakte/src/vk_chats.cpp b/protocols/VKontakte/src/vk_chats.cpp
index 3a52d29fe4..e40d9402c0 100644
--- a/protocols/VKontakte/src/vk_chats.cpp
+++ b/protocols/VKontakte/src/vk_chats.cpp
@@ -61,13 +61,13 @@ INT_PTR __cdecl CVkProto::SvcChatInviteUser(WPARAM hContact, LPARAM)
CVkInviteChatForm dlg(this);
if (dlg.DoModal() && dlg.m_hContact != 0) {
- LONG uid = getDword(dlg.m_hContact, "ID", VK_INVALID_USER);
+ VKUserID_t iUserId = ReadVKUserID(dlg.m_hContact);
- if (uid < 0)
- MsgPopup(TranslateT("Adding bots to MUC is not supported"), TranslateT("Not supported"));
- else if (uid != VK_INVALID_USER)
+ if (GetVKPeerType(iUserId) != VKPeerType::vkPeerUser)
+ MsgPopup(TranslateT("Adding bots, MUC or groups to MUC is not supported"), TranslateT("Not supported"));
+ else
Push(new AsyncHttpRequest(this, REQUEST_GET, "/method/messages.addChatUser.json", true, &CVkProto::OnReceiveSmth)
- << INT_PARAM("user_id", uid)
+ << INT_PARAM("user_id", iUserId)
<< INT_PARAM("chat_id", cc->m_iChatId));
}
@@ -90,7 +90,7 @@ INT_PTR __cdecl CVkProto::SvcChatDestroy(WPARAM hContact, LPARAM)
if (!getBool(hContact, "off"))
Push(new AsyncHttpRequest(this, REQUEST_GET, "/method/execute.DestroyChat", true, &CVkProto::OnChatDestroy)
<< INT_PARAM("chatid", cc->m_iChatId)
- << INT_PARAM("userid", m_myUserId)
+ << INT_PARAM("userid", m_iMyUserId)
)->pUserInfo = cc;
else {
Push(new AsyncHttpRequest(this, REQUEST_GET, "/method/execute.DestroyKickChat", true, &CVkProto::OnReceiveSmth)
@@ -104,7 +104,7 @@ INT_PTR __cdecl CVkProto::SvcChatDestroy(WPARAM hContact, LPARAM)
}
-CVkChatInfo* CVkProto::AppendConversationChat(int iChatId, const JSONNode& jnItem)
+CVkChatInfo* CVkProto::AppendConversationChat(VKUserID_t iChatId, const JSONNode& jnItem)
{
debugLogW(L"CVkProto::AppendConversationChat %d", iChatId);
if (iChatId == 0)
@@ -118,7 +118,7 @@ CVkChatInfo* CVkProto::AppendConversationChat(int iChatId, const JSONNode& jnIte
const JSONNode& jnAction = jnLastMessage["action"];
if (jnAction) {
CMStringW wszActionType(jnAction["type"].as_mstring());
- if ((wszActionType == L"chat_kick_user") && (jnAction["member_id"].as_int() == m_myUserId))
+ if ((wszActionType == L"chat_kick_user") && (jnAction["member_id"].as_int() == m_iMyUserId))
return nullptr;
}
}
@@ -156,7 +156,7 @@ CVkChatInfo* CVkProto::AppendConversationChat(int iChatId, const JSONNode& jnIte
for (int i = _countof(sttStatuses) - 1; i >= 0; i--)
Chat_AddGroup(si, TranslateW(sttStatuses[i]));
- setDword(si->hContact, "ID", iChatId);
+ WriteVKUserID(si->hContact, iChatId);
CMStringW wszHomepage(FORMAT, L"https://vk.com/im?sel=c%d", iChatId);
setWString(si->hContact, "Homepage", wszHomepage);
@@ -244,41 +244,41 @@ void CVkProto::OnReceiveChatInfo(NETLIBHTTPREQUEST *reply, AsyncHttpRequest *pRe
if (!jnUser)
break;
- LONG uid = jnUser["id"].as_int();
+ VKUserID_t iUserId = jnUser["id"].as_int();
bool bIsGroup = jnUser["type"].as_mstring() == L"group";
if (bIsGroup)
- uid *= -1;
+ iUserId *= -1;
wchar_t wszId[20];
- _itow(uid, wszId, 10);
+ _ltow(iUserId, wszId, 10);
bool bNew;
- CVkChatUser *cu = cc->m_users.find((CVkChatUser*)&uid);
- if (cu == nullptr) {
- cc->m_users.insert(cu = new CVkChatUser(uid));
+ CVkChatUser *iChatUser = cc->m_users.find((CVkChatUser*)&iUserId);
+ if (iChatUser == nullptr) {
+ cc->m_users.insert(iChatUser = new CVkChatUser(iUserId));
bNew = true;
}
else
- bNew = cu->m_bUnknown;
- cu->m_bDel = false;
+ bNew = iChatUser->m_bUnknown;
+ iChatUser->m_bDel = false;
- CMStringW wszNick(ptrW(db_get_wsa(cc->m_si->hContact, m_szModuleName, CMStringA(FORMAT, "nick%d", cu->m_uid))));
+ CMStringW wszNick(ptrW(db_get_wsa(cc->m_si->hContact, m_szModuleName, CMStringA(FORMAT, "nick%d", iChatUser->m_iUserId))));
if (wszNick.IsEmpty())
wszNick = bIsGroup ?
jnUser["name"].as_mstring() :
jnUser["first_name"].as_mstring().Trim() + L" " + jnUser["last_name"].as_mstring().Trim();
- cu->m_wszNick = mir_wstrdup(wszNick);
- cu->m_bUnknown = false;
+ iChatUser->m_wszNick = mir_wstrdup(wszNick);
+ iChatUser->m_bUnknown = false;
if (bNew) {
GCEVENT gce = { cc->m_si, GC_EVENT_JOIN };
- gce.bIsMe = uid == m_myUserId;
+ gce.bIsMe = iUserId == m_iMyUserId;
gce.pszUID.w = wszId;
gce.pszNick.w = wszNick;
- gce.pszStatus.w = TranslateW(sttStatuses[uid == cc->m_iAdminId]);
- gce.dwItemData = (INT_PTR)cu;
+ gce.pszStatus.w = TranslateW(sttStatuses[iUserId == cc->m_iAdminId]);
+ gce.dwItemData = (INT_PTR)iChatUser;
Chat_Event(&gce);
}
}
@@ -288,8 +288,8 @@ void CVkProto::OnReceiveChatInfo(NETLIBHTTPREQUEST *reply, AsyncHttpRequest *pRe
continue;
wchar_t wszId[20];
- _itow(cu->m_uid, wszId, 10);
- CMStringW wszNick(FORMAT, L"%s (%s)", cu->m_wszNick.get(), UserProfileUrl(cu->m_uid).c_str());
+ _itow(cu->m_iUserId, wszId, 10);
+ CMStringW wszNick(FORMAT, L"%s (%s)", cu->m_wszNick.get(), UserProfileUrl(cu->m_iUserId).c_str());
GCEVENT gce = { cc->m_si, GC_EVENT_PART };
gce.pszUID.w = wszId;
@@ -304,12 +304,12 @@ void CVkProto::OnReceiveChatInfo(NETLIBHTTPREQUEST *reply, AsyncHttpRequest *pRe
const JSONNode &jnMsgsUsers = jnResponse["msgs_users"];
for (auto &jnUser : jnMsgsUsers) {
- LONG uid = jnUser["id"].as_int();
- CVkChatUser *cu = cc->m_users.find((CVkChatUser*)&uid);
+ VKUserID_t iUserId = jnUser["id"].as_int();
+ CVkChatUser *cu = cc->m_users.find((CVkChatUser*)&iUserId);
if (cu)
continue;
- MCONTACT hContact = FindUser(uid);
+ MCONTACT hContact = FindUser(iUserId);
if (hContact)
continue;
@@ -334,7 +334,7 @@ void CVkProto::OnReceiveChatInfo(NETLIBHTTPREQUEST *reply, AsyncHttpRequest *pRe
cc->m_bHistoryRead = true;
for (auto &p : cc->m_msgs)
- AppendChatMessage(cc, p->m_mid, p->m_uid, p->m_date, p->m_wszBody, p->m_bHistory, p->m_bIsAction);
+ AppendChatMessage(cc, p->m_iMessageId, p->m_iUserId, p->m_tDate, p->m_wszBody, p->m_bHistory, p->m_bIsAction);
cc->m_msgs.destroy();
}
@@ -356,21 +356,21 @@ void CVkProto::SetChatTitle(CVkChatInfo *cc, LPCWSTR wszTopic)
/////////////////////////////////////////////////////////////////////////////////////////
-void CVkProto::AppendChatConversationMessage(int id, const JSONNode& jnMsg, const JSONNode& jnFUsers, bool bIsHistory)
+void CVkProto::AppendChatConversationMessage(VKUserID_t iChatId, const JSONNode& jnMsg, const JSONNode& jnFUsers, bool bIsHistory)
{
debugLogA("CVkProto::AppendChatConversationMessage");
- CVkChatInfo* cc = AppendConversationChat(id, nullNode);
- if (cc == nullptr)
+ CVkChatInfo* vkChatInfo = AppendConversationChat(iChatId, nullNode);
+ if (vkChatInfo == nullptr)
return;
- int mid = jnMsg["id"].as_int();
- int uid = jnMsg["from_id"].as_int();
+ VKMessageID_t iMessageId = jnMsg["id"].as_int();
+ VKUserID_t iUserId = jnMsg["from_id"].as_int();
bool bIsAction = false;
- int msgTime = jnMsg["date"].as_int();
- time_t now = time(0);
- if (!msgTime || msgTime > now)
- msgTime = now;
+ time_t tMsgTime = jnMsg["date"].as_int();
+ time_t tNow = time(0);
+ if (!tMsgTime || tMsgTime > tNow)
+ tMsgTime = tNow;
CMStringW wszBody(jnMsg["text"].as_mstring());
@@ -404,7 +404,7 @@ void CVkProto::AppendChatConversationMessage(int id, const JSONNode& jnMsg, cons
if (m_vkOptions.bAddMessageLinkToMesWAtt && ((jnAttachments && !jnAttachments.empty()) || (jnFwdMessages && !jnFwdMessages.empty()) || (jnReplyMessages && !jnReplyMessages.empty())))
wszBody += SetBBCString(TranslateT("Message link"), bbcNo, vkbbcUrl,
- CMStringW(FORMAT, L"https://vk.com/im?sel=c%d&msgid=%d", cc->m_iChatId, mid));
+ CMStringW(FORMAT, L"https://vk.com/im?sel=c%d&msgid=%d", vkChatInfo->m_iChatId, iMessageId));
if (jnMsg["action"] && jnMsg["action"]["type"]) {
bIsAction = true;
@@ -419,21 +419,21 @@ void CVkProto::AppendChatConversationMessage(int id, const JSONNode& jnMsg, cons
if (wszActionMid.IsEmpty())
wszBody = TranslateT("kick user");
else {
- CMStringW wszUid(FORMAT, L"%d", uid);
+ CMStringW wszUid(FORMAT, L"%d", iUserId);
if (wszUid == wszActionMid) {
- if (cc->m_bHistoryRead)
+ if (vkChatInfo->m_bHistoryRead)
return;
- wszBody.AppendFormat(L" (%s) %s", UserProfileUrl(uid).c_str(), TranslateT("left chat"));
+ wszBody.AppendFormat(L" (%s) %s", UserProfileUrl(iUserId).c_str(), TranslateT("left chat"));
}
else {
- int a_uid = 0;
- int iReadCount = swscanf(wszActionMid, L"%d", &a_uid);
+ VKUserID_t iActionUserId = 0;
+ int iReadCount = swscanf(wszActionMid, L"%d", &iActionUserId);
if (iReadCount == 1) {
- CVkChatUser* cu = cc->m_users.find((CVkChatUser*)&a_uid);
+ CVkChatUser* cu = vkChatInfo->m_users.find((CVkChatUser*)&iActionUserId);
if (cu == nullptr)
- wszBody.AppendFormat(L"%s (%s)", TranslateT("kick user"), UserProfileUrl(a_uid).c_str());
+ wszBody.AppendFormat(L"%s (%s)", TranslateT("kick user"), UserProfileUrl(iActionUserId).c_str());
else
- wszBody.AppendFormat(L"%s %s (%s)", TranslateT("kick user"), cu->m_wszNick.get(), UserProfileUrl(a_uid).c_str());
+ wszBody.AppendFormat(L"%s %s (%s)", TranslateT("kick user"), cu->m_wszNick.get(), UserProfileUrl(iActionUserId).c_str());
}
else wszBody = TranslateT("kick user");
}
@@ -444,18 +444,18 @@ void CVkProto::AppendChatConversationMessage(int id, const JSONNode& jnMsg, cons
if (wszActionMid.IsEmpty())
wszBody = TranslateT("invite user");
else {
- CMStringW wszUid(FORMAT, L"%d", uid);
+ CMStringW wszUid(FORMAT, L"%d", iUserId);
if (wszUid == wszActionMid)
- wszBody.AppendFormat(L" (%s) %s", UserProfileUrl(uid).c_str(), TranslateT("returned to chat"));
+ wszBody.AppendFormat(L" (%s) %s", UserProfileUrl(iUserId).c_str(), TranslateT("returned to chat"));
else {
- int a_uid = 0;
- int iReadCount = swscanf(wszActionMid, L"%d", &a_uid);
+ VKUserID_t iActionUserId = 0;
+ int iReadCount = swscanf(wszActionMid, L"%d", &iActionUserId);
if (iReadCount == 1) {
- CVkChatUser* cu = cc->m_users.find((CVkChatUser*)&a_uid);
+ CVkChatUser* cu = vkChatInfo->m_users.find((CVkChatUser*)&iActionUserId);
if (cu == nullptr)
- wszBody.AppendFormat(L"%s (%s)", TranslateT("invite user"), UserProfileUrl(a_uid).c_str());
+ wszBody.AppendFormat(L"%s (%s)", TranslateT("invite user"), UserProfileUrl(iActionUserId).c_str());
else
- wszBody.AppendFormat(L"%s %s (%s)", TranslateT("invite user"), cu->m_wszNick.get(), UserProfileUrl(a_uid).c_str());
+ wszBody.AppendFormat(L"%s %s (%s)", TranslateT("invite user"), cu->m_wszNick.get(), UserProfileUrl(iActionUserId).c_str());
}
else wszBody = TranslateT("invite user");
}
@@ -466,7 +466,7 @@ void CVkProto::AppendChatConversationMessage(int id, const JSONNode& jnMsg, cons
wszBody.AppendFormat(L"%s \"%s\"", TranslateT("change chat title to"), wszTitle.IsEmpty() ? L" " : wszTitle.c_str());
if (!bIsHistory)
- SetChatTitle(cc, wszTitle);
+ SetChatTitle(vkChatInfo, wszTitle);
}
else if (wszAction == L"chat_pin_message")
wszBody = TranslateT("pin message");
@@ -482,47 +482,48 @@ void CVkProto::AppendChatConversationMessage(int id, const JSONNode& jnMsg, cons
wszBody.Replace(L"%", L"%%");
- if (cc->m_bHistoryRead) {
- AppendChatMessage(cc, mid, uid, msgTime, wszBody, bIsHistory, bIsAction);
+ if (vkChatInfo->m_bHistoryRead) {
+ AppendChatMessage(vkChatInfo, iMessageId, iUserId, tMsgTime, wszBody, bIsHistory, bIsAction);
}
else {
- CVkChatMessage* cm = cc->m_msgs.find((CVkChatMessage*)&mid);
- if (cm == nullptr)
- cc->m_msgs.insert(cm = new CVkChatMessage(mid));
-
- cm->m_uid = uid;
- cm->m_date = msgTime;
- cm->m_wszBody = mir_wstrdup(wszBody);
- cm->m_bHistory = bIsHistory;
- cm->m_bIsAction = bIsAction;
+ CVkChatMessage* vkChatMessage = vkChatInfo->m_msgs.find((CVkChatMessage*)&iMessageId);
+ if (vkChatMessage == nullptr)
+ vkChatInfo->m_msgs.insert(vkChatMessage = new CVkChatMessage(iMessageId));
+
+ vkChatMessage->m_iUserId = iUserId;
+ vkChatMessage->m_tDate = tMsgTime;
+ vkChatMessage->m_wszBody = mir_wstrdup(wszBody);
+ vkChatMessage->m_bHistory = bIsHistory;
+ vkChatMessage->m_bIsAction = bIsAction;
}
}
-void CVkProto::AppendChatMessage(CVkChatInfo *cc, LONG mid, LONG uid, int msgTime, LPCWSTR pwszBody, bool bIsHistory, bool bIsAction)
+
+void CVkProto::AppendChatMessage(CVkChatInfo* vkChatInfo, VKMessageID_t iMessageId, VKUserID_t iUserId, time_t tMsgTime, LPCWSTR pwszBody, bool bIsHistory, bool bIsAction)
{
debugLogA("CVkProto::AppendChatMessage2");
- MCONTACT hChatContact = cc->m_si->hContact;
+ MCONTACT hChatContact = vkChatInfo->m_si->hContact;
if (!hChatContact)
return;
if (bIsAction) {
- MCONTACT hContact = FindUser(uid);
- CVkChatUser* cu = cc->m_users.find((CVkChatUser*)&uid);
+ MCONTACT hContact = FindUser(iUserId);
+ CVkChatUser* cu = vkChatInfo->m_users.find((CVkChatUser*)&iUserId);
if (cu == nullptr) {
- cc->m_users.insert(cu = new CVkChatUser(uid));
- CMStringW wszNick(ptrW(db_get_wsa(cc->m_si->hContact, m_szModuleName, CMStringA(FORMAT, "nick%d", cu->m_uid))));
+ vkChatInfo->m_users.insert(cu = new CVkChatUser(iUserId));
+ CMStringW wszNick(ptrW(db_get_wsa(vkChatInfo->m_si->hContact, m_szModuleName, CMStringA(FORMAT, "nick%d", cu->m_iUserId))));
cu->m_wszNick = mir_wstrdup(wszNick.IsEmpty() ? (hContact ? ptrW(db_get_wsa(hContact, m_szModuleName, "Nick")) : TranslateT("Unknown")) : wszNick);
cu->m_bUnknown = true;
}
wchar_t wszId[20];
- _itow(uid, wszId, 10);
+ _itow(iUserId, wszId, 10);
- GCEVENT gce = { cc->m_si, GC_EVENT_ACTION };
- gce.bIsMe = (uid == m_myUserId);
+ GCEVENT gce = { vkChatInfo->m_si, GC_EVENT_ACTION };
+ gce.bIsMe = (iUserId == m_iMyUserId);
gce.pszUID.w = wszId;
- gce.time = msgTime;
+ gce.time = tMsgTime;
gce.dwFlags = (bIsHistory) ? GCEF_NOTNOTIFY : GCEF_ADDTOLOG;
gce.pszNick.w = cu->m_wszNick ? mir_wstrdup(cu->m_wszNick) : mir_wstrdup(hContact ? ptrW(db_get_wsa(hContact, m_szModuleName, "Nick")) : TranslateT("Unknown"));
gce.pszText.w = IsEmpty((wchar_t*)pwszBody) ? mir_wstrdup(L"...") : mir_wstrdup(pwszBody);
@@ -531,18 +532,18 @@ void CVkProto::AppendChatMessage(CVkChatInfo *cc, LONG mid, LONG uid, int msgTim
else {
char szId[20];
- _itoa(uid, szId, 10);
+ _ltoa(iUserId, szId, 10);
char szMid[40];
- _itoa(mid, szMid, 10);
+ _ltoa(iMessageId, szMid, 10);
T2Utf pszBody(pwszBody);
PROTORECVEVENT pre = {};
pre.szMsgId = szMid;
- pre.timestamp = msgTime;
+ pre.timestamp = tMsgTime;
pre.szMessage = pszBody;
- if (uid == m_myUserId)
+ if (iUserId == m_iMyUserId)
pre.flags |= PREF_SENT;
if (bIsHistory)
pre.flags |= PREF_CREATEREAD;
@@ -552,7 +553,7 @@ void CVkProto::AppendChatMessage(CVkChatInfo *cc, LONG mid, LONG uid, int msgTim
ProtoChainRecvMsg(hChatContact, &pre);
}
- StopChatContactTyping(cc->m_iChatId, uid);
+ StopChatContactTyping(vkChatInfo->m_iChatId, iUserId);
}
/////////////////////////////////////////////////////////////////////////////////////////
@@ -562,12 +563,12 @@ CVkChatInfo* CVkProto::GetChatByContact(MCONTACT hContact)
if (!isChatRoom(hContact))
return nullptr;
- LONG dbUserid = getDword(hContact, "ID", VK_INVALID_USER);
- if (dbUserid == VK_INVALID_USER)
+ VKUserID_t iUserId = ReadVKUserID(hContact);
+ if (iUserId == VK_INVALID_USER)
return nullptr;
wchar_t wszChatID[40];
- _itow(dbUserid, wszChatID, 10);
+ _itow(iUserId, wszChatID, 10);
return GetChatById(wszChatID);
}
@@ -702,13 +703,13 @@ INT_PTR __cdecl CVkProto::OnJoinChat(WPARAM hContact, LPARAM)
if (!IsOnline() || getBool(hContact, "kicked") || !getBool(hContact, "off"))
return 1;
- int chat_id = getDword(hContact, "ID", VK_INVALID_USER);
- if (chat_id == VK_INVALID_USER)
+ VKUserID_t iChatId = ReadVKUserID(hContact);
+ if (iChatId == VK_INVALID_USER)
return 1;
AsyncHttpRequest* pReq = new AsyncHttpRequest(this, REQUEST_POST, "/method/messages.addChatUser.json", true, &CVkProto::OnReceiveSmth, AsyncHttpRequest::rpHigh);
- pReq << INT_PARAM("user_id", m_myUserId);
- pReq<< INT_PARAM("chat_id", chat_id);
+ pReq << INT_PARAM("user_id", m_iMyUserId);
+ pReq<< INT_PARAM("chat_id", iChatId);
Push(pReq);
db_unset(hContact, m_szModuleName, "off");
return 0;
@@ -726,61 +727,61 @@ INT_PTR __cdecl CVkProto::OnLeaveChat(WPARAM hContact, LPARAM)
Push(new AsyncHttpRequest(this, REQUEST_GET, "/method/messages.removeChatUser.json", true, &CVkProto::OnChatLeave)
<< INT_PARAM("chat_id", cc->m_iChatId)
- << INT_PARAM("user_id", m_myUserId))->pUserInfo = cc;
+ << INT_PARAM("user_id", m_iMyUserId))->pUserInfo = cc;
return 0;
}
-void CVkProto::LeaveChat(int chat_id, bool close_window, bool delete_chat)
+void CVkProto::LeaveChat(VKUserID_t iChatId, bool bCloseWindow, bool bDeleteChat)
{
debugLogA("CVkProto::LeaveChat");
- CVkChatInfo *cc = (CVkChatInfo*)m_chats.find((CVkChatInfo*)&chat_id);
+ CVkChatInfo *cc = (CVkChatInfo*)m_chats.find((CVkChatInfo*)&iChatId);
if (cc == nullptr)
return;
- if (close_window)
+ if (bCloseWindow)
Chat_Terminate(cc->m_si);
else
Chat_Control(cc->m_si, SESSION_OFFLINE);
- if (delete_chat)
+ if (bDeleteChat)
DeleteContact(cc->m_si->hContact);
else
setByte(cc->m_si->hContact, "off", (int)true);
m_chats.remove(cc);
}
-void CVkProto::KickFromChat(int chat_id, LONG user_id, const JSONNode &jnMsg, const JSONNode &jnFUsers)
+void CVkProto::KickFromChat(VKUserID_t iChatId, VKUserID_t iUserId, const JSONNode &jnMsg, const JSONNode &jnFUsers)
{
- debugLogA("CVkProto::KickFromChat (%d)", user_id);
+ debugLogA("CVkProto::KickFromChat (%d)", iUserId);
- MCONTACT chatContact = FindChat(chat_id);
+ MCONTACT chatContact = FindChat(iChatId);
if (chatContact && getBool(chatContact, "off"))
return;
- if (user_id == m_myUserId)
- LeaveChat(chat_id);
+ if (iUserId == m_iMyUserId)
+ LeaveChat(iChatId);
- CVkChatInfo *cc = (CVkChatInfo*)m_chats.find((CVkChatInfo*)&chat_id);
+ CVkChatInfo *cc = (CVkChatInfo*)m_chats.find((CVkChatInfo*)&iChatId);
if (cc == nullptr)
return;
- MCONTACT hContact = FindUser(user_id, false);
+ MCONTACT hContact = FindUser(iUserId, false);
- CMStringW msg(jnMsg["text"].as_mstring());
- if (msg.IsEmpty()) {
- msg = TranslateT("You've been kicked by ");
+ CMStringW wszMsg(jnMsg["text"].as_mstring());
+ if (wszMsg.IsEmpty()) {
+ wszMsg = TranslateT("You've been kicked by ");
if (hContact != 0)
- msg += ptrW(db_get_wsa(hContact, m_szModuleName, "Nick"));
+ wszMsg += ptrW(db_get_wsa(hContact, m_szModuleName, "Nick"));
else
- msg += TranslateT("(Unknown contact)");
+ wszMsg += TranslateT("(Unknown contact)");
}
else
- AppendChatConversationMessage(chat_id, jnMsg, jnFUsers, false);
+ AppendChatConversationMessage(iChatId, jnMsg, jnFUsers, false);
- MsgPopup(hContact, msg, TranslateT("Chat"));
+ MsgPopup(hContact, wszMsg, TranslateT("Chat"));
setByte(cc->m_si->hContact, "kicked", 1);
- LeaveChat(chat_id);
+ LeaveChat(iChatId);
}
void CVkProto::OnChatLeave(NETLIBHTTPREQUEST *reply, AsyncHttpRequest *pReq)
@@ -806,22 +807,22 @@ void CVkProto::OnChatDestroy(NETLIBHTTPREQUEST *reply, AsyncHttpRequest *pReq)
/////////////////////////////////////////////////////////////////////////////////////////
-void CVkProto::NickMenuHook(CVkChatInfo *cc, GCHOOK *gch)
+void CVkProto::NickMenuHook(CVkChatInfo *vkChatInfo, GCHOOK *gch)
{
- CVkChatUser *cu = cc->GetUserById(gch->ptszUID);
+ CVkChatUser *vkChatUser = vkChatInfo->GetUserById(gch->ptszUID);
MCONTACT hContact;
- if (cu == nullptr)
+ if (vkChatUser == nullptr)
return;
char szUid[20], szChatId[20];
- _itoa(cu->m_uid, szUid, 10);
- _itoa(cc->m_iChatId, szChatId, 10);
+ _itoa(vkChatUser->m_iUserId, szUid, 10);
+ _itoa(vkChatInfo->m_iChatId, szChatId, 10);
switch (gch->dwData) {
case IDM_INFO:
- hContact = FindUser(cu->m_uid);
+ hContact = FindUser(vkChatUser->m_iUserId);
if (hContact == 0) {
- hContact = FindUser(cu->m_uid, true);
+ hContact = FindUser(vkChatUser->m_iUserId, true);
Contact::Hide(hContact);
Contact::RemoveFromList(hContact);
db_set_dw(hContact, "Ignore", "Mask1", 0);
@@ -830,33 +831,33 @@ void CVkProto::NickMenuHook(CVkChatInfo *cc, GCHOOK *gch)
break;
case IDM_VISIT_PROFILE:
- hContact = FindUser(cu->m_uid);
+ hContact = FindUser(vkChatUser->m_iUserId);
if (hContact == 0)
- Utils_OpenUrlW(UserProfileUrl(cu->m_uid));
+ Utils_OpenUrlW(UserProfileUrl(vkChatUser->m_iUserId));
else
SvcVisitProfile(hContact, 0);
break;
case IDM_CHANGENICK:
{
- CMStringW wszNewNick = RunRenameNick(cu->m_wszNick);
- if (wszNewNick.IsEmpty() || wszNewNick == cu->m_wszNick)
+ CMStringW wszNewNick = RunRenameNick(vkChatUser->m_wszNick);
+ if (wszNewNick.IsEmpty() || wszNewNick == vkChatUser->m_wszNick)
break;
wchar_t wszId[20];
- _itow(cu->m_uid, wszId, 10);
+ _itow(vkChatUser->m_iUserId, wszId, 10);
- GCEVENT gce = { cc->m_si, GC_EVENT_NICK };
- gce.pszNick.w = mir_wstrdup(cu->m_wszNick);
- gce.bIsMe = (cu->m_uid == m_myUserId);
+ GCEVENT gce = { vkChatInfo->m_si, GC_EVENT_NICK };
+ gce.pszNick.w = mir_wstrdup(vkChatUser->m_wszNick);
+ gce.bIsMe = (vkChatUser->m_iUserId == m_iMyUserId);
gce.pszUID.w = wszId;
gce.pszText.w = mir_wstrdup(wszNewNick);
gce.dwFlags = GCEF_ADDTOLOG;
gce.time = time(0);
Chat_Event(&gce);
- cu->m_wszNick = mir_wstrdup(wszNewNick);
- setWString(cc->m_si->hContact, CMStringA(FORMAT, "nick%d", cu->m_uid), wszNewNick);
+ vkChatUser->m_wszNick = mir_wstrdup(wszNewNick);
+ setWString(vkChatInfo->m_si->hContact, CMStringA(FORMAT, "nick%d", vkChatUser->m_iUserId), wszNewNick);
}
break;
@@ -864,15 +865,15 @@ void CVkProto::NickMenuHook(CVkChatInfo *cc, GCHOOK *gch)
if (!IsOnline())
return;
- if (cu->m_uid < 0) {
+ if (GetVKPeerType(vkChatUser->m_iUserId) != VKPeerType::vkPeerUser) {
MsgPopup(TranslateT("Kick bots is not supported"), TranslateT("Not supported"));
return;
}
Push(new AsyncHttpRequest(this, REQUEST_GET, "/method/messages.removeChatUser.json", true, &CVkProto::OnReceiveSmth)
- << INT_PARAM("chat_id", cc->m_iChatId)
- << INT_PARAM("user_id", cu->m_uid));
- cu->m_bUnknown = true;
+ << INT_PARAM("chat_id", vkChatInfo->m_iChatId)
+ << INT_PARAM("user_id", vkChatUser->m_iUserId));
+ vkChatUser->m_bUnknown = true;
break;
}
@@ -918,8 +919,8 @@ void CVkProto::ChatContactTypingThread(void *p)
if (!p)
return;
- int iChatId = param->m_ChatId;
- LONG iUserId = param->m_UserId;
+ VKUserID_t iChatId = param->m_ChatId;
+ VKUserID_t iUserId = param->m_UserId;
debugLogA("CVkProto::ChatContactTypingThread %d %d", iChatId, iUserId);
@@ -955,7 +956,7 @@ void CVkProto::ChatContactTypingThread(void *p)
StopChatContactTyping(iChatId, iUserId);
}
-void CVkProto::StopChatContactTyping(int iChatId, LONG iUserId)
+void CVkProto::StopChatContactTyping(VKUserID_t iChatId, VKUserID_t iUserId)
{
debugLogA("CVkProto::StopChatContactTyping %d %d", iChatId, iUserId);
MCONTACT hChatContact = FindChat(iChatId);
@@ -1011,7 +1012,7 @@ void CVkProto::OnCreateNewChat(NETLIBHTTPREQUEST *reply, AsyncHttpRequest *pReq)
if (!jnResponse)
return;
- int chat_id = jnResponse.as_int();
- if (chat_id != 0)
- AppendConversationChat(chat_id, nullNode);
+ VKUserID_t iChatId = jnResponse.as_int();
+ if (iChatId != 0)
+ AppendConversationChat(iChatId, nullNode);
} \ No newline at end of file
diff --git a/protocols/VKontakte/src/vk_dialogs.cpp b/protocols/VKontakte/src/vk_dialogs.cpp
index 79ca3854ef..be16beda54 100644
--- a/protocols/VKontakte/src/vk_dialogs.cpp
+++ b/protocols/VKontakte/src/vk_dialogs.cpp
@@ -195,11 +195,11 @@ bool CVkGCCreateForm::OnApply()
HANDLE hItem = m_clc.FindContact(hContact);
if (hItem && m_clc.GetCheck(hItem)) {
- int uid = m_proto->getDword(hContact, "ID");
- if (uid != 0) {
+ VKUserID_t iUserId = m_proto->ReadVKUserID(hContact);
+ if (iUserId != 0) {
if (!szUIds.IsEmpty())
szUIds.AppendChar(',');
- szUIds.AppendFormat("%d", uid);
+ szUIds.AppendFormat("%d", iUserId);
}
}
}
@@ -214,7 +214,7 @@ void CVkGCCreateForm::FilterList(CCtrlClc*)
{
for (auto &hContact : Contacts()) {
char *proto = Proto_GetBaseAccountName(hContact);
- if (mir_strcmp(proto, m_proto->m_szModuleName) || m_proto->isChatRoom(hContact) || m_proto->getDword(hContact, "ID") == VK_FEED_USER)
+ if (mir_strcmp(proto, m_proto->m_szModuleName) || m_proto->isChatRoom(hContact) || m_proto->ReadVKUserID(hContact) == VK_FEED_USER)
if (HANDLE hItem = m_clc.FindContact(hContact))
m_clc.DeleteItem(hItem);
}
diff --git a/protocols/VKontakte/src/vk_feed.cpp b/protocols/VKontakte/src/vk_feed.cpp
index 787565d9f5..0edfe1851d 100644
--- a/protocols/VKontakte/src/vk_feed.cpp
+++ b/protocols/VKontakte/src/vk_feed.cpp
@@ -89,7 +89,7 @@ void CVkProto::AddCListEvent(bool bNews)
//////////////////////////////////////////////////////////////////////////////////////////////////////////
-CVkUserInfo* CVkProto::GetVkUserInfo(LONG iUserId, OBJLIST<CVkUserInfo> &vkUsers)
+CVkUserInfo* CVkProto::GetVkUserInfo(VKUserID_t iUserId, OBJLIST<CVkUserInfo> &vkUsers)
{
debugLogA("CVkProto::GetVkUserInfo %d", iUserId);
@@ -122,7 +122,7 @@ void CVkProto::CreateVkUserInfoList(OBJLIST<CVkUserInfo> &vkUsers, const JSONNod
for (auto &jnProfile : jnProfiles) {
if (!jnProfile["id"])
continue;
- LONG UserId = jnProfile["id"].as_int();
+ VKUserID_t UserId = jnProfile["id"].as_int();
CMStringW wszNick(jnProfile["first_name"].as_mstring());
wszNick.AppendChar(' ');
@@ -141,7 +141,7 @@ void CVkProto::CreateVkUserInfoList(OBJLIST<CVkUserInfo> &vkUsers, const JSONNod
for (auto &jnProfile : jnGroups) {
if (!jnProfile["id"])
continue;
- LONG UserId = -jnProfile["id"].as_int();
+ VKUserID_t UserId = -jnProfile["id"].as_int();
CMStringW wszNick(jnProfile["name"].as_mstring());
CMStringW wszLink = L"https://vk.com/";
@@ -153,7 +153,7 @@ void CVkProto::CreateVkUserInfoList(OBJLIST<CVkUserInfo> &vkUsers, const JSONNod
//////////////////////////////////////////////////////////////////////////////////////////////////////////
-CVKNewsItem* CVkProto::GetVkNewsItem(const JSONNode &jnItem, OBJLIST<CVkUserInfo> &vkUsers, bool isRepost)
+CVKNewsItem* CVkProto::GetVkNewsItem(const JSONNode &jnItem, OBJLIST<CVkUserInfo> &vkUsers, bool bIsRepost)
{
if (!jnItem || jnItem["type"].as_mstring() == L"friends_recomm")
return nullptr;
@@ -161,8 +161,8 @@ CVKNewsItem* CVkProto::GetVkNewsItem(const JSONNode &jnItem, OBJLIST<CVkUserInfo
bool bPostLink = true;
CVKNewsItem *vkNewsItem = new CVKNewsItem();
- LONG iSourceId = !jnItem["source_id"] ? jnItem["owner_id"].as_int() : jnItem["source_id"].as_int();
- LONG iPostId = jnItem["post_id"].as_int();
+ VKUserID_t iSourceId = !jnItem["source_id"] ? jnItem["owner_id"].as_int() : jnItem["source_id"].as_int();
+ VKMessageID_t iPostId = jnItem["post_id"].as_int();
CMStringW wszText(jnItem["text"].as_mstring());
CMStringW wszPopupText(wszText);
@@ -243,7 +243,7 @@ CVKNewsItem* CVkProto::GetVkNewsItem(const JSONNode &jnItem, OBJLIST<CVkUserInfo
CMStringW wszResFormat, wszTitleFormat;
- if (!isRepost) {
+ if (!bIsRepost) {
wszResFormat = Translate("News from %s\n%s");
wszTitleFormat = Translate("News from %s");
}
@@ -281,7 +281,7 @@ CMStringW CVkProto::GetVkFeedback(const JSONNode &jnFeedback, VKObjType vkFeedba
return wszRes;
CMStringW wszFormat;
- LONG iUserId = 0;
+ VKUserID_t iUserId = 0;
if (vkFeedbackType == vkComment) {
iUserId = jnFeedback["from_id"].as_int();
@@ -330,8 +330,8 @@ CVKNewsItem* CVkProto::GetVkParent(const JSONNode &jnParent, VKObjType vkParentT
if (vkParentType == vkPhoto) {
CMStringW wszPhoto = GetVkPhotoItem(jnParent, m_vkOptions.BBCForNews());
- LONG iOwnerId = jnParent["owner_id"].as_int();
- LONG iId = jnParent["id"].as_int();
+ VKUserID_t iOwnerId = jnParent["owner_id"].as_int();
+ int iId = jnParent["id"].as_int();
vkNotificationItem->wszId.AppendFormat(L"%d_%d", iOwnerId, iId);
vkNotificationItem->wszLink.AppendFormat(L"https://vk.com/photo%s", vkNotificationItem->wszId.c_str());
vkNotificationItem->wszText.AppendFormat(L"\n%s", wszPhoto.c_str());
@@ -344,8 +344,8 @@ CVKNewsItem* CVkProto::GetVkParent(const JSONNode &jnParent, VKObjType vkParentT
vkNotificationItem->wszText.AppendFormat(L"\n%s", SetBBCString(TranslateT("Link"), m_vkOptions.BBCForNews(), vkbbcUrl, vkNotificationItem->wszLink).c_str());
}
else if (vkParentType == vkVideo) {
- LONG iOwnerId = jnParent["owner_id"].as_int();
- LONG iId = jnParent["id"].as_int();
+ VKUserID_t iOwnerId = jnParent["owner_id"].as_int();
+ int iId = jnParent["id"].as_int();
CMStringW wszTitle(jnParent["title"].as_mstring());
vkNotificationItem->wszId.AppendFormat(L"%d_%d", iOwnerId, iId);
vkNotificationItem->wszLink.AppendFormat(L"https://vk.com/video%s", vkNotificationItem->wszId.c_str());
@@ -364,8 +364,8 @@ CVKNewsItem* CVkProto::GetVkParent(const JSONNode &jnParent, VKObjType vkParentT
vkNotificationItem->wszText.AppendFormat(L"\n%s", SetBBCString(wszTitle, m_vkOptions.BBCForNews(), vkbbcUrl, vkNotificationItem->wszLink).c_str());
}
else if (vkParentType == vkPost) {
- LONG iToId = jnParent["to_id"].as_int();
- LONG iId = jnParent["id"].as_int();
+ VKUserID_t iToId = jnParent["to_id"].as_int();
+ int iId = jnParent["id"].as_int();
vkNotificationItem->wszId.AppendFormat(L"%d_%d", iToId, iId);
vkNotificationItem->wszLink.AppendFormat(L"https://vk.com/wall%s%s", vkNotificationItem->wszId.c_str(), pwszReplyLink ? pwszReplyLink : L"");
@@ -387,8 +387,8 @@ CVKNewsItem* CVkProto::GetVkParent(const JSONNode &jnParent, VKObjType vkParentT
vkNotificationItem->wszText.AppendFormat(L"\n%s", SetBBCString(TranslateT("Link"), m_vkOptions.BBCForNews(), vkbbcUrl, vkNotificationItem->wszLink).c_str());
}
else if (vkParentType == vkTopic) {
- LONG iOwnerId = jnParent["owner_id"].as_int();
- LONG iId = jnParent["id"].as_int();
+ VKUserID_t iOwnerId = jnParent["owner_id"].as_int();
+ int iId = jnParent["id"].as_int();
CMStringW wszTitle(jnParent["title"].as_mstring());
vkNotificationItem->wszId.AppendFormat(L"%d_%d", iOwnerId, iId);
vkNotificationItem->wszLink.AppendFormat(L"https://vk.com/topic%s%s",
@@ -427,7 +427,7 @@ CVKNewsItem* CVkProto::GetVkParent(const JSONNode &jnParent, VKObjType vkParentT
return GetVkParent(jnVideo, vkVideo, wszText);
}
- LONG iId = jnParent["id"].as_int();
+ int iId = jnParent["id"].as_int();
const JSONNode &jnPost = jnParent["post"];
if (jnPost) {
@@ -510,7 +510,7 @@ void CVkProto::OnFriendAccepted(const JSONNode & jnFeedback)
if (!jnUserItem["from_id"])
continue;
- LONG iUserId = jnUserItem["from_id"].as_int();
+ VKUserID_t iUserId = jnUserItem["from_id"].as_int();
MCONTACT hContact = FindUser(iUserId, true);
RetrieveUserInfo(iUserId);
@@ -532,14 +532,14 @@ CVKNewsItem* CVkProto::GetVkGroupInvates(const JSONNode &jnItem, OBJLIST<CVkUser
if (!jnItem["id"])
return nullptr;
- LONG iGroupId = jnItem["id"].as_int();
+ VKUserID_t iGroupId = jnItem["id"].as_int();
CMStringW wszId(FORMAT, L"%d,", iGroupId);
CMStringW wszIds(ptrW(db_get_wsa(0, m_szModuleName, "InviteGroupIds")));
if (wszIds.Find(wszId, 0) != -1)
return nullptr;
- LONG iUserId = !jnItem["invited_by"] ? 0 : jnItem["invited_by"].as_int();
+ VKUserID_t iUserId = !jnItem["invited_by"] ? 0 : jnItem["invited_by"].as_int();
CVKNewsItem *vkNotification = new CVKNewsItem();
vkNotification->tDate = time(0);
vkNotification->vkUser = GetVkUserInfo(iUserId, vkUsers);
@@ -626,19 +626,19 @@ void CVkProto::RetrieveUnreadNews(time_t tLastNewsTime)
static int sttCompareVKNewsItems(const CVKNewsItem *p1, const CVKNewsItem *p2)
{
int compareId = p1->wszId.Compare(p2->wszId);
- LONG compareUserId = p1->vkUser->m_UserId - p2->vkUser->m_UserId;
- LONG compareDate = (LONG)p1->tDate - (LONG)p2->tDate;
+ VKUserID_t compareUserId = p1->vkUser->m_UserId - p2->vkUser->m_UserId;
+ time_t compareDate = p1->tDate - p2->tDate;
- return compareId ? (compareDate ? compareDate : compareUserId) : 0;
+ return compareId ? (compareDate ? (int)compareDate : (int)compareUserId) : 0;
}
static int sttCompareVKNotificationItems(const CVKNewsItem *p1, const CVKNewsItem *p2)
{
int compareType = p1->wszType.Compare(p2->wszType);
int compareId = p1->wszId.Compare(p2->wszId);
- LONG compareDate = (LONG)p1->tDate - (LONG)p2->tDate;
+ time_t compareDate = p1->tDate - p2->tDate;
- return compareType ? compareDate : (compareId ? compareDate : 0);
+ return compareType ? compareDate : (compareId ? (int)compareDate : 0);
}
void CVkProto::OnReceiveUnreadNews(NETLIBHTTPREQUEST *reply, AsyncHttpRequest *pReq)
@@ -704,7 +704,7 @@ void CVkProto::RetrieveUnreadNotifications(time_t tLastNotificationsTime)
return;
CMStringW code(FORMAT, L"return{\"notifications\":API.notifications.get({\"count\": 100, \"start_time\":%d})%s",
- (LONG)(tLastNotificationsTime + 1),
+ (long)(tLastNotificationsTime + 1),
m_vkOptions.bNotificationFilterInvites ? L",\"groupinvates\":API.groups.getInvites({\"extended\":1})};" : L"};");
Push(new AsyncHttpRequest(this, REQUEST_GET, "/method/execute.json", true, &CVkProto::OnReceiveUnreadNotifications)
@@ -714,16 +714,16 @@ void CVkProto::RetrieveUnreadNotifications(time_t tLastNotificationsTime)
setDword("LastNotificationsReqTime", (uint32_t)time(0));
}
-bool CVkProto::FilterNotification(CVKNewsItem* vkNotificationItem, bool& isCommented)
+bool CVkProto::FilterNotification(CVKNewsItem* vkNotificationItem, bool& bIsCommented)
{
- isCommented = false;
+ bIsCommented = false;
if (vkNotificationItem->vkParentType == vkNull)
return false;
if (vkNotificationItem->wszType == L"mention_comments"
|| vkNotificationItem->wszType == L"mention_comment_photo"
|| vkNotificationItem->wszType == L"mention_comment_video") {
- isCommented = true;
+ bIsCommented = true;
return (m_vkOptions.bNotificationFilterMentions != 0);
}
@@ -732,7 +732,7 @@ bool CVkProto::FilterNotification(CVKNewsItem* vkNotificationItem, bool& isComme
result = (vkNotificationItem->vkFeedbackType == vkComment && m_vkOptions.bNotificationFilterComments) || result;
result = (vkNotificationItem->vkParentType == vkInvite && m_vkOptions.bNotificationFilterInvites) || result;
- isCommented = (vkNotificationItem->vkFeedbackType == vkComment);
+ bIsCommented = (vkNotificationItem->vkFeedbackType == vkComment);
return result;
}
diff --git a/protocols/VKontakte/src/vk_files.cpp b/protocols/VKontakte/src/vk_files.cpp
index 7ac1b9657e..c376c9ce59 100644
--- a/protocols/VKontakte/src/vk_files.cpp
+++ b/protocols/VKontakte/src/vk_files.cpp
@@ -21,8 +21,8 @@ HANDLE CVkProto::SendFile(MCONTACT hContact, const wchar_t *desc, wchar_t **file
{
debugLogA("CVkProto::SendFile");
- LONG userID = getDword(hContact, "ID", VK_INVALID_USER);
- if (!IsOnline() || ((userID == VK_INVALID_USER || userID == VK_FEED_USER) && !isChatRoom(hContact)) || !files || !files[0])
+ VKUserID_t iUserId = ReadVKUserID(hContact);
+ if (!IsOnline() || ((iUserId == VK_INVALID_USER || iUserId == VK_FEED_USER) && !isChatRoom(hContact)) || !files || !files[0])
return (HANDLE)nullptr;
CVkFileUploadParam *fup = new CVkFileUploadParam(hContact, desc, files);
@@ -155,7 +155,7 @@ void CVkProto::OnReciveUploadServer(NETLIBHTTPREQUEST *reply, AsyncHttpRequest *
return;
}
- FILE *pFile = _wfopen(fup->FileName, L"rb");
+ FILE *pFile = _wfopen(fup->wszFileName, L"rb");
if (pFile == nullptr) {
SendFileFiled(fup, VKERR_ERR_OPEN_FILE);
return;
@@ -325,19 +325,20 @@ void CVkProto::OnReciveUploadFile(NETLIBHTTPREQUEST *reply, AsyncHttpRequest *pR
return;
}
- int id, owner_id;
+ int id;
+ VKUserID_t iOwnerId;
if ((fup->GetType() == CVkFileUploadParam::typeDoc) || (fup->GetType() == CVkFileUploadParam::typeAudioMsg)) {
CMStringA wszType(jnResponse["type"].as_mstring());
const JSONNode& jnDoc = jnResponse[wszType];
id = jnDoc["id"].as_int();
- owner_id = jnDoc["owner_id"].as_int();
+ iOwnerId = jnDoc["owner_id"].as_int();
}
else {
id = fup->GetType() == CVkFileUploadParam::typeAudio ? jnResponse["id"].as_int() : (*jnResponse.begin())["id"].as_int();
- owner_id = fup->GetType() == CVkFileUploadParam::typeAudio ? jnResponse["owner_id"].as_int() : (*jnResponse.begin())["owner_id"].as_int();
+ iOwnerId = fup->GetType() == CVkFileUploadParam::typeAudio ? jnResponse["owner_id"].as_int() : (*jnResponse.begin())["owner_id"].as_int();
}
- if ((id == 0) || (owner_id == 0)) {
+ if ((id == 0) || (iOwnerId == 0)) {
SendFileFiled(fup, VKERR_INVALID_PARAMETERS);
return;
}
@@ -346,14 +347,14 @@ void CVkProto::OnReciveUploadFile(NETLIBHTTPREQUEST *reply, AsyncHttpRequest *pR
switch (fup->GetType()) {
case CVkFileUploadParam::typeImg:
- Attachment.AppendFormat(L"photo%d_%d", owner_id, id);
+ Attachment.AppendFormat(L"photo%d_%d", iOwnerId, id);
break;
case CVkFileUploadParam::typeAudio:
- Attachment.AppendFormat(L"audio%d_%d", owner_id, id);
+ Attachment.AppendFormat(L"audio%d_%d", iOwnerId, id);
break;
case CVkFileUploadParam::typeDoc:
case CVkFileUploadParam::typeAudioMsg:
- Attachment.AppendFormat(L"doc%d_%d", owner_id, id);
+ Attachment.AppendFormat(L"doc%d_%d", iOwnerId, id);
break;
default:
SendFileFiled(fup, VKERR_FTYPE_NOT_SUPPORTED);
@@ -375,20 +376,20 @@ void CVkProto::OnReciveUploadFile(NETLIBHTTPREQUEST *reply, AsyncHttpRequest *pR
}
else {
- LONG userID = getDword(fup->hContact, "ID", VK_INVALID_USER);
- if (userID == VK_INVALID_USER || userID == VK_FEED_USER) {
+ VKUserID_t iUserId = ReadVKUserID(fup->hContact);
+ if (iUserId == VK_INVALID_USER || iUserId == VK_FEED_USER) {
SendFileFiled(fup, VKERR_INVALID_USER);
return;
}
pMsgReq = new AsyncHttpRequest(this, REQUEST_POST, "/method/messages.send.json", true, &CVkProto::OnSendMessage, AsyncHttpRequest::rpHigh);
- pMsgReq << INT_PARAM("user_id", userID);
+ pMsgReq << INT_PARAM("user_id", iUserId);
pMsgReq->pUserInfo = new CVkSendMsgParam(fup->hContact, fup);
}
- ULONG uMsgId = ::InterlockedIncrement(&m_msgId);
- pMsgReq << WCHAR_PARAM("message", fup->Desc) << WCHAR_PARAM("attachment", Attachment);
- pMsgReq << INT_PARAM("random_id", ((LONG)time(0)) * 100 + uMsgId % 100);
+ ULONG uMsgId = ::InterlockedIncrement(&m_iMsgId);
+ pMsgReq << WCHAR_PARAM("message", fup->wszDesc) << WCHAR_PARAM("attachment", Attachment);
+ pMsgReq << INT_PARAM("random_id", ((long)time(0)) * 100 + uMsgId % 100);
pMsgReq->AddHeader("Content-Type", "application/x-www-form-urlencoded");
Push(pMsgReq);
diff --git a/protocols/VKontakte/src/vk_history.cpp b/protocols/VKontakte/src/vk_history.cpp
index 559c31c98d..5b35d5e48a 100644
--- a/protocols/VKontakte/src/vk_history.cpp
+++ b/protocols/VKontakte/src/vk_history.cpp
@@ -32,8 +32,8 @@ INT_PTR __cdecl CVkProto::SvcGetAllServerHistoryForContact(WPARAM hContact, LPAR
if (IDNO == MessageBoxW(nullptr, str, TranslateT("Attention!"), MB_ICONWARNING | MB_YESNO))
return 0;
- LONG userID = getDword(hContact, "ID", VK_INVALID_USER);
- if (userID == VK_INVALID_USER || userID == VK_FEED_USER)
+ VKUserID_t iUserId = ReadVKUserID(hContact);
+ if (iUserId == VK_INVALID_USER || iUserId == VK_FEED_USER)
return 0;
setByte(hContact, "ActiveHistoryTask", 1);
@@ -59,8 +59,8 @@ INT_PTR __cdecl CVkProto::SvcGetAllServerHistory(WPARAM, LPARAM)
return 0;
for (auto &hContact : AccContacts()) {
- LONG userID = getDword(hContact, "ID", VK_INVALID_USER);
- if (userID == VK_INVALID_USER || userID == VK_FEED_USER)
+ VKUserID_t iUserId = ReadVKUserID(hContact);
+ if (iUserId == VK_INVALID_USER || iUserId == VK_FEED_USER)
continue;
if (getBool(hContact, "ActiveHistoryTask"))
@@ -75,7 +75,7 @@ INT_PTR __cdecl CVkProto::SvcGetAllServerHistory(WPARAM, LPARAM)
mir_cslock lck(m_csLoadHistoryTask);
m_iLoadHistoryTask++;
m_bNotifyForEndLoadingHistoryAllContact = m_bNotifyForEndLoadingHistory = true;
- debugLogA("CVkProto::SvcGetAllServerHistory for ID=%d m_iLoadHistoryTask=%d", userID, m_iLoadHistoryTask);
+ debugLogA("CVkProto::SvcGetAllServerHistory for ID=%d m_iLoadHistoryTask=%d", iUserId, m_iLoadHistoryTask);
}
db_unset(hContact, m_szModuleName, "lastmsgid");
@@ -87,17 +87,17 @@ INT_PTR __cdecl CVkProto::SvcGetAllServerHistory(WPARAM, LPARAM)
/////////////////////////////////////////////////////////////////////////////////////////
-void CVkProto::GetServerHistoryLastNDay(MCONTACT hContact, int NDay)
+void CVkProto::GetServerHistoryLastNDay(MCONTACT hContact, int iNDay)
{
- debugLogA("CVkProto::SvcGetServerHistoryLastNDay %d", NDay);
+ debugLogA("CVkProto::SvcGetServerHistoryLastNDay %d", iNDay);
if (getBool(hContact, "ActiveHistoryTask"))
return;
setByte(hContact, "ActiveHistoryTask", 1);
- time_t tTime = time(0) - 60 * 60 * 24 * NDay;
+ time_t tTime = time(0) - 60 * 60 * 24 * iNDay;
- if (NDay > 3) {
+ if (iNDay > 3) {
DB::ECPTR pCursor(DB::Events(hContact));
while (MEVENT hDbEvent = pCursor.FetchNext()) {
DBEVENTINFO dbei = {};
@@ -114,48 +114,48 @@ void CVkProto::GetServerHistoryLastNDay(MCONTACT hContact, int NDay)
}
- setDword(hContact, "oldlastmsgid", getDword(hContact, "lastmsgid", -1));
+ WriteQSWord(hContact, "oldlastmsgid", ReadQSWord(hContact, "lastmsgid", -1));
db_unset(hContact, m_szModuleName, "lastmsgid");
GetServerHistory(hContact, 0, MAXHISTORYMIDSPERONE, tTime, 0);
}
-void CVkProto::GetServerHistory(MCONTACT hContact, int iOffset, int iCount, int iTime, int iLastMsgId, bool once)
+void CVkProto::GetServerHistory(MCONTACT hContact, int iOffset, int iCount, time_t tTime, VKMessageID_t iLastMsgId, bool bOnce)
{
debugLogA("CVkProto::GetServerHistory");
if (!IsOnline() || iCount == 0)
return;
- LONG userID = getDword(hContact, "ID", VK_INVALID_USER);
- debugLogA("CVkProto::GetServerHistory %ld %d %d %d %d %d", userID, iOffset, iCount, iTime, iLastMsgId, (int)once);
- if (VK_INVALID_USER == userID || userID == VK_FEED_USER)
+ VKUserID_t iUserId = ReadVKUserID(hContact);
+ debugLogA("CVkProto::GetServerHistory %ld %d %d %d %d %d", iUserId, iOffset, iCount, tTime, iLastMsgId, (int)bOnce);
+ if (VK_INVALID_USER == iUserId || iUserId == VK_FEED_USER)
return;
Push(new AsyncHttpRequest(this, REQUEST_GET, "/method/execute.GetServerConversationHistory", true, &CVkProto::OnReceiveHistoryMessages, AsyncHttpRequest::rpLow)
<< INT_PARAM("reqcount", iCount)
<< INT_PARAM("offset", iOffset)
- << INT_PARAM("userid", userID)
- << INT_PARAM("time", iTime)
+ << INT_PARAM("userid", iUserId)
+ << INT_PARAM("time", tTime)
<< INT_PARAM("lastmid", iLastMsgId)
- << INT_PARAM("once", (int)once)
+ << INT_PARAM("once", (int)bOnce)
)->pUserInfo = new CVkSendMsgParam(hContact, iLastMsgId, iOffset);
}
-void CVkProto::GetHistoryDlg(MCONTACT hContact, int iLastMsg)
+void CVkProto::GetHistoryDlg(MCONTACT hContact, VKMessageID_t iLastMsg)
{
debugLogA("CVkProto::GetHistoryDlg %d", iLastMsg);
- int lastmsgid = -1;
+ VKMessageID_t iLastMsgId = -1;
switch (m_vkOptions.iSyncHistoryMetod) {
case syncAuto:
- lastmsgid = getDword(hContact, "lastmsgid", -1);
- if (lastmsgid == -1 || !IsOnline()) {
- setDword(hContact, "lastmsgid", iLastMsg);
+ iLastMsgId = ReadQSWord(hContact, "lastmsgid", -1);
+ if (iLastMsgId == -1 || !IsOnline()) {
+ WriteQSWord(hContact, "lastmsgid", iLastMsg);
return;
}
m_bNotifyForEndLoadingHistory = false;
if (getBool(hContact, "ActiveHistoryTask"))
return;
setByte(hContact, "ActiveHistoryTask", 1);
- GetServerHistory(hContact, 0, MAXHISTORYMIDSPERONE, 0, lastmsgid);
+ GetServerHistory(hContact, 0, MAXHISTORYMIDSPERONE, 0, iLastMsgId);
break;
case sync1Days:
GetServerHistoryLastNDay(hContact, 1);
@@ -215,27 +215,26 @@ void CVkProto::OnReceiveHistoryMessages(NETLIBHTTPREQUEST *reply, AsyncHttpReque
int iTime = jnResponse["datetime"].as_int();
const JSONNode &jnMsgs = jnResponse["items"];
const JSONNode &jnFUsers = jnResponse["fwd_users"];
-
- int iLastMsgId = getDword(param->hContact, "lastmsgid", -1);
+ VKMessageID_t iLastMsgId = ReadQSWord(param->hContact, "lastmsgid", -1);
time_t tLastReadMessageTime = 0;
int count = 0;
for (auto it = jnMsgs.rbegin(); it != jnMsgs.rend(); ++it) {
const JSONNode &jnMsg = (*it);
- int mid = jnMsg["id"].as_int();
- if (iLastMsgId < mid)
- iLastMsgId = mid;
+ VKMessageID_t iMessageId = jnMsg["id"].as_int();
+ if (iLastMsgId < iMessageId)
+ iLastMsgId = iMessageId;
char szMid[40];
- _itoa(mid, szMid, 10);
+ _ltoa(iMessageId, szMid, 10);
CMStringW wszBody(jnMsg["text"].as_mstring());
- int uid = jnMsg["peer_id"].as_int();
- int iReadMsg = getDword(param->hContact, "in_read", 0);
- int isRead = (mid <= iReadMsg);
- int datetime = jnMsg["date"].as_int();
- int isOut = jnMsg["out"].as_int();
- MCONTACT hContact = FindUser(uid, true);
+ VKUserID_t iUserId = jnMsg["peer_id"].as_int();
+ VKMessageID_t iReadMsg = ReadQSWord(param->hContact, "in_read", 0);
+ bool bIsRead = (iMessageId <= iReadMsg);
+ time_t tDateTime = jnMsg["date"].as_int();
+ bool bIsOut = jnMsg["out"].as_int();
+ MCONTACT hContact = FindUser(iUserId, true);
const JSONNode &jnFwdMessages = jnMsg["fwd_messages"];
if (jnFwdMessages && !jnFwdMessages.empty()) {
@@ -269,21 +268,21 @@ void CVkProto::OnReceiveHistoryMessages(NETLIBHTTPREQUEST *reply, AsyncHttpReque
if (m_vkOptions.bAddMessageLinkToMesWAtt && ((jnAttachments && !jnAttachments.empty()) || (jnFwdMessages && !jnFwdMessages.empty()) || (jnReplyMessages && !jnReplyMessages.empty())))
wszBody += SetBBCString(TranslateT("Message link"), m_vkOptions.BBCForAttachments(), vkbbcUrl,
- CMStringW(FORMAT, L"https://vk.com/im?sel=%d&msgid=%d", uid, mid));
+ CMStringW(FORMAT, L"https://vk.com/im?sel=%d&msgid=%d", iUserId, iMessageId));
PROTORECVEVENT recv = { 0 };
- if (isRead)
+ if (bIsRead)
recv.flags |= PREF_CREATEREAD;
- if (isOut)
+ if (bIsOut)
recv.flags |= PREF_SENT;
- time_t update_time = (time_t)jnMsg["update_time"].as_int();
- if (update_time) {
+ time_t tUpdateTime = (time_t)jnMsg["update_time"].as_int();
+ if (tUpdateTime) {
CMStringW wszEditTime;
wchar_t ttime[64];
_locale_t locale = _create_locale(LC_ALL, "");
- _wcsftime_l(ttime, _countof(ttime), TranslateT("%x at %X"), localtime(&update_time), locale);
+ _wcsftime_l(ttime, _countof(ttime), TranslateT("%x at %X"), localtime(&tUpdateTime), locale);
_free_locale(locale);
wszEditTime.Format(TranslateT("Edited message (updated %s):\n"), ttime);
@@ -296,7 +295,7 @@ void CVkProto::OnReceiveHistoryMessages(NETLIBHTTPREQUEST *reply, AsyncHttpReque
T2Utf pszBody(wszBody);
- recv.timestamp = datetime;
+ recv.timestamp = tDateTime;
recv.szMessage = pszBody;
recv.szMsgId = szMid;
ProtoChainRecvMsg(hContact, &recv);
@@ -305,13 +304,13 @@ void CVkProto::OnReceiveHistoryMessages(NETLIBHTTPREQUEST *reply, AsyncHttpReque
if (hDbEvent)
db_event_delete(hDbEvent, true);
- if (isRead && isOut && datetime > tLastReadMessageTime)
- tLastReadMessageTime = datetime;
+ if (bIsRead && bIsOut && tDateTime > tLastReadMessageTime)
+ tLastReadMessageTime = tDateTime;
count++;
}
- setDword(param->hContact, "lastmsgid", iLastMsgId);
+ WriteQSWord(param->hContact, "lastmsgid", iLastMsgId);
if (g_bMessageState)
CallService(MS_MESSAGESTATE_UPDATE, param->hContact, MRD_TYPE_DELIVERED);
@@ -325,7 +324,7 @@ void CVkProto::OnReceiveHistoryMessages(NETLIBHTTPREQUEST *reply, AsyncHttpReque
if (m_iLoadHistoryTask > 0)
m_iLoadHistoryTask--;
- setDword(param->hContact, "lastmsgid", iLastMsgId == -1 ? getDword(param->hContact, "oldlastmsgid", -1) : iLastMsgId);
+ WriteQSWord(param->hContact, "lastmsgid", iLastMsgId == -1 ? ReadQSWord(param->hContact, "oldlastmsgid", -1) : iLastMsgId);
db_unset(param->hContact, m_szModuleName, "oldlastmsgid");
ptrW pwszNick(db_get_wsa(param->hContact, m_szModuleName, "Nick"));
diff --git a/protocols/VKontakte/src/vk_messages.cpp b/protocols/VKontakte/src/vk_messages.cpp
index 132e4dc7e3..cda9aaaabc 100644
--- a/protocols/VKontakte/src/vk_messages.cpp
+++ b/protocols/VKontakte/src/vk_messages.cpp
@@ -27,8 +27,8 @@ int CVkProto::SendMsg(MCONTACT hContact, int, const char *szMsg)
bool bIsChat = isChatRoom(hContact);
- LONG iUserID = getDword(hContact, "ID", VK_INVALID_USER);
- if (iUserID == VK_INVALID_USER || iUserID == VK_FEED_USER) {
+ VKUserID_t iUserId = ReadVKUserID(hContact);
+ if (iUserId == VK_INVALID_USER || iUserId == VK_FEED_USER) {
ProtoBroadcastAsync(hContact, ACKTYPE_MESSAGE, ACKRESULT_SUCCESS, 0);
return 0;
}
@@ -36,10 +36,10 @@ int CVkProto::SendMsg(MCONTACT hContact, int, const char *szMsg)
int StickerId = 0;
ptrA pszRetMsg(GetStickerId(szMsg, StickerId));
- ULONG uMsgId = ::InterlockedIncrement(&m_msgId);
+ ULONG uMsgId = ::InterlockedIncrement(&m_iMsgId);
AsyncHttpRequest *pReq = new AsyncHttpRequest(this, REQUEST_POST, "/method/messages.send.json", true,
bIsChat ? &CVkProto::OnSendChatMsg : &CVkProto::OnSendMessage, AsyncHttpRequest::rpHigh);
- pReq << INT_PARAM(bIsChat ? "chat_id" : "peer_id", iUserID) << INT_PARAM("random_id", ((LONG)time(0)) * 100 + uMsgId % 100);
+ pReq << INT_PARAM(bIsChat ? "chat_id" : "peer_id", iUserId) << INT_PARAM("random_id", ((long)time(0)) * 100 + uMsgId % 100);
pReq->AddHeader("Content-Type", "application/x-www-form-urlencoded");
if (StickerId)
@@ -81,7 +81,7 @@ void CVkProto::OnSendMessage(NETLIBHTTPREQUEST *reply, AsyncHttpRequest *pReq)
CVkSendMsgParam *param = (CVkSendMsgParam *)pReq->pUserInfo;
debugLogA("CVkProto::OnSendMessage %d", reply->resultCode);
- UINT mid = 0;
+ VKMessageID_t iMessageId = 0;
if (reply->resultCode == 200) {
JSONNode jnRoot;
const JSONNode &jnResponse = CheckJsonResponse(pReq, reply, jnRoot);
@@ -89,21 +89,21 @@ void CVkProto::OnSendMessage(NETLIBHTTPREQUEST *reply, AsyncHttpRequest *pReq)
debugLogA("CVkProto::OnSendMessage jnResponse %d", jnResponse.as_int());
switch (jnResponse.type()) {
case JSON_NUMBER:
- mid = jnResponse.as_int();
+ iMessageId = jnResponse.as_int();
break;
case JSON_STRING:
- if (swscanf(jnResponse.as_mstring(), L"%u", &mid) != 1)
- mid = 0;
+ if (swscanf(jnResponse.as_mstring(), L"%u", &iMessageId) != 1)
+ iMessageId = 0;
break;
case JSON_ARRAY:
- mid = jnResponse.as_array()[json_index_t(0)].as_int();
+ iMessageId = jnResponse.as_array()[json_index_t(0)].as_int();
break;
default:
- mid = 0;
+ iMessageId = 0;
}
- if (mid > getDword(param->hContact, "lastmsgid"))
- setDword(param->hContact, "lastmsgid", mid);
+ if (iMessageId > ReadQSWord(param->hContact, "lastmsgid"))
+ WriteQSWord(param->hContact, "lastmsgid", iMessageId);
if (m_vkOptions.iMarkMessageReadOn >= MarkMsgReadOn::markOnReply)
MarkMessagesRead(param->hContact);
@@ -113,7 +113,7 @@ void CVkProto::OnSendMessage(NETLIBHTTPREQUEST *reply, AsyncHttpRequest *pReq)
}
char szMid[40];
- _itoa(mid, szMid, 10);
+ _ltoa(iMessageId, szMid, 10);
if (param->pFUP) {
ProtoBroadcastAck(param->hContact, ACKTYPE_FILE, iResult, (HANDLE)(param->pFUP));
@@ -155,23 +155,23 @@ void CVkProto::MarkMessagesRead(const MCONTACT hContact)
if (!IsEmpty(ptrW(db_get_wsa(hContact, m_szModuleName, "Deactivated"))))
return;
- LONG userID = getDword(hContact, "ID", VK_INVALID_USER);
- if (userID == VK_INVALID_USER || userID == VK_FEED_USER)
+ VKUserID_t iUserId = ReadVKUserID(hContact);
+ if (iUserId == VK_INVALID_USER || iUserId == VK_FEED_USER)
return;
Push(new AsyncHttpRequest(this, REQUEST_GET, "/method/messages.markAsRead.json", true, &CVkProto::OnReceiveSmth, AsyncHttpRequest::rpLow)
<< INT_PARAM("mark_conversation_as_read", 1)
- << INT_PARAM("peer_id", isChatRoom(hContact) ? VK_CHAT_FLAG + userID : userID));
+ << INT_PARAM("peer_id", isChatRoom(hContact) ? VK_CHAT_MIN + iUserId : iUserId));
}
-void CVkProto::RetrieveMessagesByIds(const CMStringA &mids)
+void CVkProto::RetrieveMessagesByIds(const CMStringA &szMids)
{
debugLogA("CVkProto::RetrieveMessagesByIds");
- if (!IsOnline() || mids.IsEmpty())
+ if (!IsOnline() || szMids.IsEmpty())
return;
Push(new AsyncHttpRequest(this, REQUEST_GET, "/method/execute.RetrieveMessagesConversationByIds", true, &CVkProto::OnReceiveMessages, AsyncHttpRequest::rpHigh)
- << CHAR_PARAM("mids", mids)
+ << CHAR_PARAM("mids", szMids)
);
}
@@ -197,12 +197,12 @@ void CVkProto::OnReceiveMessages(NETLIBHTTPREQUEST *reply, AsyncHttpRequest *pRe
if (!jnResponse["Msgs"])
return;
- CMStringA mids;
- int numMessages = jnResponse["Msgs"]["count"].as_int();
+ CMStringA szMids;
+ int iNumMessages = jnResponse["Msgs"]["count"].as_int();
const JSONNode &jnMsgs = jnResponse["Msgs"]["items"];
const JSONNode &jnFUsers = jnResponse["fwd_users"];
- debugLogA("CVkProto::OnReceiveMessages numMessages = %d", numMessages);
+ debugLogA("CVkProto::OnReceiveMessages numMessages = %d", iNumMessages);
if (jnResponse["conv"]) {
const JSONNode& jnConversation = jnResponse["conv"]["items"];
@@ -212,11 +212,11 @@ void CVkProto::OnReceiveMessages(NETLIBHTTPREQUEST *reply, AsyncHttpRequest *pRe
break;
CMStringW wszPeerType(jnPeer["type"].as_mstring());
- int iUserId = jnPeer["id"].as_int();
+ VKUserID_t iUserId = jnPeer["id"].as_int();
- MCONTACT hContact = (wszPeerType == L"chat") ? FindChat(iUserId % VK_CHAT_FLAG) : FindUser(iUserId, true);
- setDword(hContact, "in_read", jnItem["in_read"].as_int());
- setDword(hContact, "out_read", jnItem["out_read"].as_int());
+ MCONTACT hContact = (wszPeerType == L"chat") ? FindChat(iUserId % VK_CHAT_MIN) : FindUser(iUserId, true);
+ WriteQSWord(hContact, "in_read", jnItem["in_read"].as_int());
+ WriteQSWord(hContact, "out_read", jnItem["out_read"].as_int());
if (m_vkOptions.iMarkMessageReadOn == MarkMsgReadOn::markOnReceive)
MarkMessagesRead(hContact);
}
@@ -228,34 +228,35 @@ void CVkProto::OnReceiveMessages(NETLIBHTTPREQUEST *reply, AsyncHttpRequest *pRe
break;
}
- UINT mid = jnMsg["id"].as_int();
+ VKMessageID_t iMessageId = jnMsg["id"].as_int();
CMStringW wszBody(jnMsg["text"].as_mstring());
- UINT datetime = jnMsg["date"].as_int();
+ time_t tDateTime = jnMsg["date"].as_int();
int isOut = jnMsg["out"].as_int();
- int uid = jnMsg["peer_id"].as_int();
+ VKUserID_t iUserId = jnMsg["peer_id"].as_int();
MCONTACT hContact = 0;
- int chat_id = uid / VK_CHAT_FLAG ? uid % VK_CHAT_FLAG : 0;
- if (chat_id == 0)
- hContact = FindUser(uid, true);
+ VKUserID_t iChatId = (GetVKPeerType(iUserId) == VKPeerType::vkPeerMUC) ? iUserId % VK_CHAT_MIN : 0;
+
+ if (iChatId == 0)
+ hContact = FindUser(iUserId, true);
char szMid[40];
- _itoa(mid, szMid, 10);
+ _ltoa(iMessageId, szMid, 10);
bool bUseServerReadFlag = m_vkOptions.bSyncReadMessageStatusFromServer ? true : !m_vkOptions.bMesAsUnread;
- if (chat_id != 0) {
+ if (iChatId != 0) {
debugLogA("CVkProto::OnReceiveMessages chat_id != 0");
- CMStringW action_chat = jnMsg["action"]["type"].as_mstring();
- int action_mid = _wtoi(jnMsg["action"]["member_id"].as_mstring());
- if ((action_chat == L"chat_kick_user") && (action_mid == m_myUserId))
- KickFromChat(chat_id, uid, jnMsg, jnFUsers);
+ CMStringW wszActionChat = jnMsg["action"]["type"].as_mstring();
+ VKMessageID_t iActionMessageId = _wtol(jnMsg["action"]["member_id"].as_mstring());
+ if ((wszActionChat == L"chat_kick_user") && (iActionMessageId == m_iMyUserId))
+ KickFromChat(iChatId, iUserId, jnMsg, jnFUsers);
else {
- MCONTACT chatContact = FindChat(chat_id);
+ MCONTACT chatContact = FindChat(iChatId);
if (chatContact && getBool(chatContact, "kicked", true))
db_unset(chatContact, m_szModuleName, "kicked");
- AppendChatConversationMessage(chat_id, jnMsg, jnFUsers, false);
+ AppendChatConversationMessage(iChatId, jnMsg, jnFUsers, false);
}
continue;
}
@@ -284,8 +285,8 @@ void CVkProto::OnReceiveMessages(NETLIBHTTPREQUEST *reply, AsyncHttpRequest *pRe
wszAttachmentDescr = GetAttachmentDescr(jnAttachments, m_vkOptions.BBCForAttachments());
if (wszAttachmentDescr == L"== FilterAudioMessages ==") {
- if (hContact && (mid > getDword(hContact, "lastmsgid", -1)))
- setDword(hContact, "lastmsgid", mid);
+ if (hContact && (iMessageId > ReadQSWord(hContact, "lastmsgid", -1)))
+ WriteQSWord(hContact, "lastmsgid", iMessageId);
continue;
}
@@ -296,18 +297,18 @@ void CVkProto::OnReceiveMessages(NETLIBHTTPREQUEST *reply, AsyncHttpRequest *pRe
if (m_vkOptions.bAddMessageLinkToMesWAtt && ((jnAttachments && !jnAttachments.empty()) || (jnFwdMessages && !jnFwdMessages.empty()) || (jnReplyMessages && !jnReplyMessages.empty())))
wszBody += SetBBCString(TranslateT("Message link"), m_vkOptions.BBCForAttachments(), vkbbcUrl,
- CMStringW(FORMAT, L"https://vk.com/im?sel=%d&msgid=%d", uid, mid));
+ CMStringW(FORMAT, L"https://vk.com/im?sel=%d&msgid=%d", iUserId, iMessageId));
- int iReadMsg = getDword(hContact, "in_read", 0);
- int isRead = (mid <= iReadMsg);
+ VKMessageID_t iReadMsg = ReadQSWord(hContact, "in_read", 0);
+ int isRead = (iMessageId <= iReadMsg);
- time_t update_time = (time_t)jnMsg["update_time"].as_int();
- bool bEdited = (update_time != 0);
+ time_t tUpdateTime = (time_t)jnMsg["update_time"].as_int();
+ bool bEdited = (tUpdateTime != 0);
if (bEdited) {
wchar_t ttime[64];
_locale_t locale = _create_locale(LC_ALL, "");
- _wcsftime_l(ttime, _countof(ttime), TranslateT("%x at %X"), localtime(&update_time), locale);
+ _wcsftime_l(ttime, _countof(ttime), TranslateT("%x at %X"), localtime(&tUpdateTime), locale);
_free_locale(locale);
wszBody = SetBBCString(
@@ -316,7 +317,7 @@ void CVkProto::OnReceiveMessages(NETLIBHTTPREQUEST *reply, AsyncHttpRequest *pRe
wszBody;
CMStringW wszOldMsg;
- if (GetMessageFromDb(mid, datetime, wszOldMsg))
+ if (GetMessageFromDb(iMessageId, tDateTime, wszOldMsg))
wszBody += SetBBCString(TranslateT("\nOriginal message:\n"), m_vkOptions.BBCForAttachments(), vkbbcB) +
wszOldMsg;
}
@@ -328,26 +329,26 @@ void CVkProto::OnReceiveMessages(NETLIBHTTPREQUEST *reply, AsyncHttpRequest *pRe
if (isOut)
recv.flags |= PREF_SENT;
- else if (m_vkOptions.bUserForceInvisibleOnActivity && time(0) - datetime < 60 * m_vkOptions.iInvisibleInterval)
+ else if (m_vkOptions.bUserForceInvisibleOnActivity && ((time(0) - tDateTime) < (60 * m_vkOptions.iInvisibleInterval)))
SetInvisible(hContact);
T2Utf pszBody(wszBody);
- recv.timestamp = bEdited ? datetime : (m_vkOptions.bUseLocalTime ? time(0) : datetime);
+ recv.timestamp = bEdited ? tDateTime : (m_vkOptions.bUseLocalTime ? time(0) : tDateTime);
recv.szMessage = pszBody;
- debugLogA("CVkProto::OnReceiveMessages mid = %d, datetime = %d, isOut = %d, isRead = %d, uid = %d, Edited = %d", mid, datetime, isOut, isRead, uid, (int)bEdited);
+ debugLogA("CVkProto::OnReceiveMessages mid = %d, datetime = %d, isOut = %d, isRead = %d, iUserId = %d, Edited = %d", iMessageId, tDateTime, isOut, isRead, iUserId, (int)bEdited);
- if (!IsMessageExist(mid, vkALL) || bEdited) {
+ if (!IsMessageExist(iMessageId, vkALL) || bEdited) {
debugLogA("CVkProto::OnReceiveMessages new or edited message");
recv.szMsgId = szMid;
ProtoChainRecvMsg(hContact, &recv);
- if (mid > getDword(hContact, "lastmsgid", -1))
- setDword(hContact, "lastmsgid", mid);
+ if (iMessageId > ReadQSWord(hContact, "lastmsgid", -1))
+ WriteQSWord(hContact, "lastmsgid", iMessageId);
}
else if (m_vkOptions.bLoadSentAttachments && !wszAttachmentDescr.IsEmpty()) {
CMStringW wszOldMsg;
- if (GetMessageFromDb(mid, datetime, wszOldMsg) && (wszOldMsg == wszBody))
+ if (GetMessageFromDb(iMessageId, tDateTime, wszOldMsg) && (wszOldMsg == wszBody))
continue;
if (wszBodyNoAttachments != wszOldMsg)
@@ -356,7 +357,7 @@ void CVkProto::OnReceiveMessages(NETLIBHTTPREQUEST *reply, AsyncHttpRequest *pRe
debugLogA("CVkProto::OnReceiveMessages add attachments");
T2Utf pszAttach(wszAttachmentDescr);
- recv.timestamp = isOut ? time(0) : datetime;
+ recv.timestamp = isOut ? time(0) : tDateTime;
recv.szMessage = pszAttach;
recv.szMsgId = strcat(szMid, "_");
ProtoChainRecvMsg(hContact, &recv);
@@ -383,30 +384,30 @@ void CVkProto::OnReceiveDlgs(NETLIBHTTPREQUEST *reply, AsyncHttpRequest *pReq)
if (!jnDlgs)
return;
- LIST<void> lufUsers(20, PtrKeySortT);
+ OBJLIST<VKUserID_t> lufUsers(20, NumericKeySortT);
const JSONNode &jnUsers = jnResponse["users"];
if (jnUsers)
for (auto &it : jnUsers) {
- int iUserId = it["user_id"].as_int();
+ VKUserID_t iUserId = it["user_id"].as_int();
int iStatus = it["friend_status"].as_int();
// iStatus == 3 - user is friend
- // uid < 0 - user is group
- if (iUserId < 0 || iStatus != 3 || lufUsers.indexOf((HANDLE)iUserId) != -1)
+ // iUserId < 0 - user is group
+
+ if (GetVKPeerType(iUserId) != VKPeerType::vkPeerUser || iStatus != 3 || lufUsers.find((VKUserID_t *) &iUserId))
continue;
- lufUsers.insert((HANDLE)iUserId);
+ lufUsers.insert(new VKUserID_t(iUserId));
}
const JSONNode &jnGroups = jnResponse["groups"];
if (jnGroups)
for (auto &it : jnGroups) {
- int iUserId = 1000000000 + it.as_int();
-
- if (lufUsers.indexOf((HANDLE)iUserId) != -1)
+ VKUserID_t iUserId = it.as_int();
+ if (lufUsers.find((VKUserID_t*) &iUserId))
continue;
- lufUsers.insert((HANDLE)iUserId);
+ lufUsers.insert(new VKUserID_t(iUserId));
}
CMStringA szGroupIds;
@@ -427,18 +428,17 @@ void CVkProto::OnReceiveDlgs(NETLIBHTTPREQUEST *reply, AsyncHttpRequest *pReq)
if (!jnPeer)
break;
- int iUserId = 0;
+ VKUserID_t iUserId = 0;
MCONTACT hContact(0);
CMStringW wszPeerType(jnPeer["type"].as_mstring());
if (wszPeerType == L"user" || wszPeerType == L"group") {
iUserId = jnPeer["id"].as_int();
- int iSearchId = (wszPeerType == L"group") ? (1000000000 - iUserId) : iUserId;
- int iIndex = lufUsers.indexOf((HANDLE)iSearchId);
- debugLogA("CVkProto::OnReceiveDlgs UserId = %d, iIndex = %d, numUnread = %d", iUserId, iIndex, iUnreadCount);
+ VKUserID_t *pUserID = lufUsers.find((VKUserID_t*) &iUserId);
+ debugLogA("CVkProto::OnReceiveDlgs UserId = %d, iIndex = %p, numUnread = %d", iUserId, pUserID, iUnreadCount);
- if (m_vkOptions.bLoadOnlyFriends && iUnreadCount == 0 && iIndex == -1)
+ if (m_vkOptions.bLoadOnlyFriends && iUnreadCount == 0 && !pUserID)
continue;
hContact = FindUser(iUserId, true);
@@ -447,8 +447,8 @@ void CVkProto::OnReceiveDlgs(NETLIBHTTPREQUEST *reply, AsyncHttpRequest *pReq)
if (IsGroupUser(hContact))
szGroupIds.AppendFormat(szGroupIds.IsEmpty() ? "%d" : ",%d", -1 * iUserId);
- setDword(hContact, "in_read", jnConversation["in_read"].as_int());
- setDword(hContact, "out_read", jnConversation["out_read"].as_int());
+ WriteQSWord(hContact, "in_read", jnConversation["in_read"].as_int());
+ WriteQSWord(hContact, "out_read", jnConversation["out_read"].as_int());
if (g_bMessageState) {
bool bIsOut = jnLastMessage["out"].as_bool();
@@ -460,16 +460,16 @@ void CVkProto::OnReceiveDlgs(NETLIBHTTPREQUEST *reply, AsyncHttpRequest *pReq)
}
if (wszPeerType == L"chat") {
- int iChatId = jnPeer["local_id"].as_int();
+ VKUserID_t iChatId = jnPeer["local_id"].as_int();
debugLogA("CVkProto::OnReceiveDlgs chatid = %d", iChatId);
if (m_chats.find((CVkChatInfo*)&iChatId) == nullptr)
AppendConversationChat(iChatId, it);
}
else if (m_vkOptions.iSyncHistoryMetod) {
- int iMessageId = jnLastMessage["id"].as_int();
+ VKMessageID_t iMessageId = jnLastMessage["id"].as_int();
m_bNotifyForEndLoadingHistory = false;
- if (getDword(hContact, "lastmsgid", -1) == -1 && iUnreadCount && !getBool(hContact, "ActiveHistoryTask")) {
+ if (ReadQSWord(hContact, "lastmsgid", -1) == -1 && iUnreadCount && !getBool(hContact, "ActiveHistoryTask")) {
setByte(hContact, "ActiveHistoryTask", 1);
GetServerHistory(hContact, 0, iUnreadCount, 0, 0, true);
}
diff --git a/protocols/VKontakte/src/vk_pollserver.cpp b/protocols/VKontakte/src/vk_pollserver.cpp
index 0b0218e38b..9c222f430c 100644
--- a/protocols/VKontakte/src/vk_pollserver.cpp
+++ b/protocols/VKontakte/src/vk_pollserver.cpp
@@ -48,18 +48,18 @@ void CVkProto::OnReceivePollingInfo(NETLIBHTTPREQUEST *reply, AsyncHttpRequest *
char ts[32];
itoa(jnResponse["ts"].as_int(), ts, 10);
- m_pollingTs = mir_strdup(ts);
- m_pollingKey = mir_u2a(jnResponse["key"].as_mstring());
- m_pollingServer = mir_u2a(jnResponse["server"].as_mstring());
+ m_szPollingTs = mir_strdup(ts);
+ m_szPollingKey = mir_u2a(jnResponse["key"].as_mstring());
+ m_szPollingServer = mir_u2a(jnResponse["server"].as_mstring());
if (!m_hPollingThread) {
debugLogA("CVkProto::OnReceivePollingInfo m_hPollingThread is nullptr");
debugLogA("CVkProto::OnReceivePollingInfo m_pollingTs = '%s' m_pollingKey = '%s' m_pollingServer = '%s'",
- m_pollingTs ? m_pollingTs.get() : "<nullptr>",
- m_pollingKey ? m_pollingKey.get() : "<nullptr>",
- m_pollingServer ? m_pollingServer.get() : "<nullptr>");
+ m_szPollingTs ? m_szPollingTs.get() : "<nullptr>",
+ m_szPollingKey ? m_szPollingKey.get() : "<nullptr>",
+ m_szPollingServer ? m_szPollingServer.get() : "<nullptr>");
- if (m_pollingTs != nullptr && m_pollingKey != nullptr && m_pollingServer != nullptr) {
+ if (m_szPollingTs != nullptr && m_szPollingKey != nullptr && m_szPollingServer != nullptr) {
debugLogA("CVkProto::OnReceivePollingInfo PollingThread starting...");
m_hPollingThread = ForkThreadEx(&CVkProto::PollingThread, nullptr, nullptr);
}
@@ -77,10 +77,13 @@ void CVkProto::OnReceivePollingInfo(NETLIBHTTPREQUEST *reply, AsyncHttpRequest *
void CVkProto::PollUpdates(const JSONNode &jnUpdates)
{
debugLogA("CVkProto::PollUpdates");
- CMStringA mids;
- int msgid, uid, flags, platform;
+ CMStringA szMids;
+
+ VKMessageID_t iMessageId;
+ int iFlags, iPlatform;
+ VKUserID_t iUserId;
MCONTACT hContact;
- UINT datetime = 0;
+ time_t tDateTime = 0;
CMStringW wszMsg;
for (auto &it : jnUpdates) {
@@ -89,18 +92,18 @@ void CVkProto::PollUpdates(const JSONNode &jnUpdates)
case VKPOLL_MSG_DELFLAGS:
if (jnChild.size() < 4)
break;
- msgid = jnChild[1].as_int();
- flags = jnChild[2].as_int();
- uid = jnChild[3].as_int();
- hContact = FindUser(uid);
-
- if (hContact != 0 && (flags & VKFLAG_MSGDELETED)) {
- if (!mids.IsEmpty())
- mids.AppendChar(',');
- mids.AppendFormat("%d", msgid);
+ iMessageId = jnChild[1].as_int();
+ iFlags = jnChild[2].as_int();
+ iUserId = jnChild[3].as_int();
+ hContact = FindUser(iUserId);
+
+ if (hContact != 0 && (iFlags & VKFLAG_MSGDELETED)) {
+ if (!szMids.IsEmpty())
+ szMids.AppendChar(',');
+ szMids.AppendFormat("%d", iMessageId);
}
- if (hContact != 0 && (flags & VKFLAG_MSGUNREAD) && !IsMessageExist(msgid, vkIN)) {
+ if (hContact != 0 && (iFlags & VKFLAG_MSGUNREAD) && !IsMessageExist(iMessageId, vkIN)) {
setDword(hContact, "LastMsgReadTime", time(0));
if (g_bMessageState)
CallService(MS_MESSAGESTATE_UPDATE, hContact, MRD_TYPE_READ);
@@ -117,16 +120,16 @@ void CVkProto::PollUpdates(const JSONNode &jnUpdates)
case VKPOLL_MSG_ADDFLAGS:
if (jnChild.size() < 4)
break;
- msgid = jnChild[1].as_int();
- flags = jnChild[2].as_int();
- uid = jnChild[3].as_int();
- hContact = FindUser(uid);
+ iMessageId = jnChild[1].as_int();
+ iFlags = jnChild[2].as_int();
+ iUserId = jnChild[3].as_int();
+ hContact = FindUser(iUserId);
- if (hContact != 0 && (flags & VKFLAG_MSGDELETED) && IsMessageExist(msgid, vkALL) && GetMessageFromDb(msgid, datetime, wszMsg)) {
+ if (hContact != 0 && (iFlags & VKFLAG_MSGDELETED) && IsMessageExist(iMessageId, vkALL) && GetMessageFromDb(iMessageId, tDateTime, wszMsg)) {
wchar_t ttime[64];
- time_t delete_time = time(0);
+ time_t tDeleteTime = time(0);
_locale_t locale = _create_locale(LC_ALL, "");
- _wcsftime_l(ttime, _countof(ttime), TranslateT("%x at %X"), localtime(&delete_time), locale);
+ _wcsftime_l(ttime, _countof(ttime), TranslateT("%x at %X"), localtime(&tDeleteTime), locale);
_free_locale(locale);
wszMsg = SetBBCString(
@@ -135,16 +138,16 @@ void CVkProto::PollUpdates(const JSONNode &jnUpdates)
wszMsg;
PROTORECVEVENT recv = {};
- if (uid == m_myUserId)
+ if (iUserId == m_iMyUserId)
recv.flags |= PREF_SENT;
- else if (m_vkOptions.bUserForceInvisibleOnActivity && time(0) - datetime < 60 * m_vkOptions.iInvisibleInterval)
+ else if (m_vkOptions.bUserForceInvisibleOnActivity && time(0) - tDateTime < 60 * m_vkOptions.iInvisibleInterval)
SetInvisible(hContact);
char szMid[40];
- _itoa(msgid, szMid, 10);
+ _itoa(iMessageId, szMid, 10);
T2Utf pszMsg(wszMsg);
- recv.timestamp = datetime;
+ recv.timestamp = tDateTime;
recv.szMessage = pszMsg;
recv.szMsgId = szMid;
ProtoChainRecvMsg(hContact, &recv);
@@ -152,27 +155,27 @@ void CVkProto::PollUpdates(const JSONNode &jnUpdates)
break;
case VKPOLL_MSG_EDITED:
- msgid = jnChild[1].as_int();
- if (!mids.IsEmpty())
- mids.AppendChar(',');
- mids.AppendFormat("%d", msgid);
+ iMessageId = jnChild[1].as_int();
+ if (!szMids.IsEmpty())
+ szMids.AppendChar(',');
+ szMids.AppendFormat("%d", iMessageId);
break;
case VKPOLL_MSG_ADDED: // new message
- msgid = jnChild[1].as_int();
+ iMessageId = jnChild[1].as_int();
// skip outgoing messages sent from a client
- flags = jnChild[2].as_int();
- if (flags & VKFLAG_MSGOUTBOX && !(flags & VKFLAG_MSGCHAT) && !m_vkOptions.bSendVKLinksAsAttachments && IsMessageExist(msgid, vkOUT))
+ iFlags = jnChild[2].as_int();
+ if (iFlags & VKFLAG_MSGOUTBOX && !(iFlags & VKFLAG_MSGCHAT) && !m_vkOptions.bSendVKLinksAsAttachments && IsMessageExist(iMessageId, vkOUT))
break;
- if (!mids.IsEmpty())
- mids.AppendChar(',');
- mids.AppendFormat("%d", msgid);
+ if (!szMids.IsEmpty())
+ szMids.AppendChar(',');
+ szMids.AppendFormat("%d", iMessageId);
break;
case VKPOLL_READ_ALL_OUT:
- uid = jnChild[1].as_int();
- hContact = FindUser(uid);
+ iUserId = jnChild[1].as_int();
+ hContact = FindUser(iUserId);
if (hContact != 0) {
setDword(hContact, "LastMsgReadTime", time(0));
if (g_bMessageState)
@@ -185,24 +188,24 @@ void CVkProto::PollUpdates(const JSONNode &jnUpdates)
}
break;
case VKPOLL_READ_ALL_IN:
- uid = jnChild[1].as_int();
- hContact = FindUser(uid);
+ iUserId = jnChild[1].as_int();
+ hContact = FindUser(iUserId);
if (hContact != 0 && m_vkOptions.bSyncReadMessageStatusFromServer)
MarkDialogAsRead(hContact);
break;
case VKPOLL_USR_ONLINE:
- uid = -jnChild[1].as_int();
- if ((hContact = FindUser(uid)) != 0) {
+ iUserId = -jnChild[1].as_int();
+ if ((hContact = FindUser(iUserId)) != 0) {
setWord(hContact, "Status", ID_STATUS_ONLINE);
- platform = jnChild[2].as_int();
- SetMirVer(hContact, platform);
+ iPlatform = jnChild[2].as_int();
+ SetMirVer(hContact, iPlatform);
}
break;
case VKPOLL_USR_OFFLINE:
- uid = -jnChild[1].as_int();
- if ((hContact = FindUser(uid)) != 0) {
+ iUserId = -jnChild[1].as_int();
+ if ((hContact = FindUser(iUserId)) != 0) {
setWord(hContact, "Status", ID_STATUS_OFFLINE);
db_unset(hContact, m_szModuleName, "ListeningTo");
SetMirVer(hContact, -1);
@@ -210,8 +213,8 @@ void CVkProto::PollUpdates(const JSONNode &jnUpdates)
break;
case VKPOLL_USR_UTN:
- uid = jnChild[1].as_int();
- hContact = FindUser(uid);
+ iUserId = jnChild[1].as_int();
+ hContact = FindUser(iUserId);
if (hContact != 0) {
ForkThread(&CVkProto::ContactTypingThread, (void *)hContact);
if (m_vkOptions.bUserForceInvisibleOnActivity)
@@ -224,15 +227,15 @@ void CVkProto::PollUpdates(const JSONNode &jnUpdates)
break;
case VKPOLL_CHAT_CHANGED:
- int chat_id = jnChild[1].as_int();
- CVkChatInfo *cc = m_chats.find((CVkChatInfo*)&chat_id);
+ VKUserID_t iChatId = jnChild[1].as_int();
+ CVkChatInfo *cc = m_chats.find((CVkChatInfo*)&iChatId);
if (cc)
RetrieveChatInfo(cc);
break;
}
}
- RetrieveMessagesByIds(mids);
+ RetrieveMessagesByIds(szMids);
}
int CVkProto::PollServer()
@@ -248,7 +251,7 @@ int CVkProto::PollServer()
debugLogA("CVkProto::PollServer (online)");
int iPollConnRetry = MAX_RETRIES;
- CMStringA szReqUrl(FORMAT, "https://%s?act=a_check&key=%s&ts=%s&wait=25&access_token=%s&mode=%d&version=%d", m_pollingServer, m_pollingKey, m_pollingTs, m_szAccessToken, 106, 2);
+ CMStringA szReqUrl(FORMAT, "https://%s?act=a_check&key=%s&ts=%s&wait=25&access_token=%s&mode=%d&version=%d", m_szPollingServer, m_szPollingKey, m_szPollingTs, m_szAccessToken, 106, 2);
// see mode parametr description on https://vk.com/dev/using_longpoll (Russian version)
NETLIBHTTPREQUEST req = {};
req.cbSize = sizeof(req);
@@ -256,7 +259,7 @@ int CVkProto::PollServer()
req.szUrl = szReqUrl.GetBuffer();
req.flags = VK_NODUMPHEADERS | NLHRF_PERSISTENT | NLHRF_HTTP11 | NLHRF_SSL;
req.timeout = 30000;
- req.nlc = m_pollingConn;
+ req.nlc = m_hPollingConn;
time_t tLocalPoolThreadTimer;
{
mir_cslock lck(m_csPoolThreadTimer);
@@ -298,7 +301,7 @@ int CVkProto::PollServer()
else if (CheckJsonResult(nullptr, jnRoot)) {
char ts[32];
itoa(jnRoot["ts"].as_int(), ts, 10);
- m_pollingTs = mir_strdup(ts);
+ m_szPollingTs = mir_strdup(ts);
const JSONNode &jnUpdates = jnRoot["updates"];
if (jnUpdates)
PollUpdates(jnUpdates);
@@ -313,7 +316,7 @@ int CVkProto::PollServer()
return 0;
}
- m_pollingConn = reply->nlc;
+ m_hPollingConn = reply->nlc;
debugLogA("CVkProto::PollServer return %d", retVal);
return retVal;
diff --git a/protocols/VKontakte/src/vk_proto.cpp b/protocols/VKontakte/src/vk_proto.cpp
index f2c2b5a251..678df6c0ec 100644
--- a/protocols/VKontakte/src/vk_proto.cpp
+++ b/protocols/VKontakte/src/vk_proto.cpp
@@ -20,7 +20,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
static int sttCompareAsyncHttpRequest(const AsyncHttpRequest *p1, const AsyncHttpRequest *p2)
{
if (p1->m_priority == p2->m_priority)
- return (int)p1->m_reqNum - (int)p2->m_reqNum;
+ return (int)p1->m_uReqNum - (int)p2->m_uReqNum;
return (int)p2->m_priority - (int)p1->m_priority;
}
@@ -30,19 +30,20 @@ CVkProto::CVkProto(const char *szModuleName, const wchar_t *pwszUserName) :
PROTO<CVkProto>(szModuleName, pwszUserName),
m_arRequestsQueue(10, sttCompareAsyncHttpRequest),
m_cookies(5),
- m_msgId(1),
+ m_iMsgId(1),
m_chats(1, NumericKeySortT),
m_ChatsTyping(1, NumericKeySortT),
m_iLoadHistoryTask(0),
m_bNotifyForEndLoadingHistory(false),
m_bNotifyForEndLoadingHistoryAllContact(false),
m_hAPIConnection(nullptr),
- m_pollingConn(nullptr),
+ m_hPollingConn(nullptr),
m_bSetBroadcast(false),
m_bNeedSendOnline(false),
m_bErr404Return(false),
m_vkOptions(this)
{
+ bIint64IDCompatibility = false;
m_tWorkThreadTimer = m_tPoolThreadTimer = time(0);
InitQueue();
@@ -377,27 +378,27 @@ void CVkProto::InitMenus()
int CVkProto::OnPreBuildContactMenu(WPARAM hContact, LPARAM)
{
- LONG userID = getDword(hContact, "ID", VK_INVALID_USER);
+ VKUserID_t iUserId = ReadVKUserID(hContact);
bool bisFriend = !getBool(hContact, "Auth", true);
bool bisBroadcast = !(IsEmpty(ptrW(db_get_wsa(hContact, m_szModuleName, "AudioUrl"))));
bool bIsGroup = IsGroupUser(hContact);
- Menu_ShowItem(m_hContactMenuItems[CMI_VISITPROFILE], userID != VK_FEED_USER);
- Menu_ShowItem(m_hContactMenuItems[CMI_MARKMESSAGESASREAD], userID != VK_FEED_USER);
+ Menu_ShowItem(m_hContactMenuItems[CMI_VISITPROFILE], iUserId != VK_FEED_USER);
+ Menu_ShowItem(m_hContactMenuItems[CMI_MARKMESSAGESASREAD], iUserId != VK_FEED_USER);
Menu_ShowItem(m_hContactMenuItems[CMI_WALLPOST], !isChatRoom(hContact));
- Menu_ShowItem(m_hContactMenuItems[CMI_ADDASFRIEND], !bisFriend && !isChatRoom(hContact) && userID != VK_FEED_USER && !bIsGroup);
- Menu_ShowItem(m_hContactMenuItems[CMI_DELETEFRIEND], bisFriend && userID != VK_FEED_USER && !bIsGroup);
- Menu_ShowItem(m_hContactMenuItems[CMI_BANUSER], !isChatRoom(hContact) && userID != VK_FEED_USER && !bIsGroup);
- Menu_ShowItem(m_hContactMenuItems[CMI_REPORTABUSE], !isChatRoom(hContact) && userID != VK_FEED_USER && !bIsGroup);
+ Menu_ShowItem(m_hContactMenuItems[CMI_ADDASFRIEND], !bisFriend && !isChatRoom(hContact) && iUserId != VK_FEED_USER && !bIsGroup);
+ Menu_ShowItem(m_hContactMenuItems[CMI_DELETEFRIEND], bisFriend && iUserId != VK_FEED_USER && !bIsGroup);
+ Menu_ShowItem(m_hContactMenuItems[CMI_BANUSER], !isChatRoom(hContact) && iUserId != VK_FEED_USER && !bIsGroup);
+ Menu_ShowItem(m_hContactMenuItems[CMI_REPORTABUSE], !isChatRoom(hContact) && iUserId != VK_FEED_USER && !bIsGroup);
Menu_ShowItem(m_hContactMenuItems[CMI_OPENBROADCAST], !isChatRoom(hContact) && bisBroadcast);
Menu_ShowItem(m_hContactMenuItems[CMI_CHATCHANGETOPIC], isChatRoom(hContact));
Menu_ShowItem(m_hContactMenuItems[CMI_CHATINVITEUSER], isChatRoom(hContact));
Menu_ShowItem(m_hContactMenuItems[CMI_CHATDESTROY], isChatRoom(hContact));
- Menu_ShowItem(m_hContactMenuItems[CMI_GETSERVERHISTORY], !isChatRoom(hContact) && userID != VK_FEED_USER);
- Menu_ShowItem(m_hContactMenuItems[CMI_LOADVKNEWS], userID == VK_FEED_USER);
+ Menu_ShowItem(m_hContactMenuItems[CMI_GETSERVERHISTORY], !isChatRoom(hContact) && iUserId != VK_FEED_USER);
+ Menu_ShowItem(m_hContactMenuItems[CMI_LOADVKNEWS], iUserId == VK_FEED_USER);
for (int i = 0; i < CHMI_COUNT; i++)
- Menu_ShowItem(m_hContactHistoryMenuItems[i], !isChatRoom(hContact) && userID != VK_FEED_USER);
+ Menu_ShowItem(m_hContactHistoryMenuItems[i], !isChatRoom(hContact) && iUserId != VK_FEED_USER);
return 0;
}
@@ -512,7 +513,7 @@ void CVkProto::OnShutdown()
debugLogA("CVkProto::OnPreShutdown");
m_bTerminated = true;
- SetEvent(m_evRequestsQueue);
+ SetEvent(m_hEvRequestsQueue);
}
//////////////////////////////////////////////////////////////////////////////
@@ -549,12 +550,12 @@ MCONTACT CVkProto::AddToList(int, PROTOSEARCHRESULT *psr)
{
debugLogA("CVkProto::AddToList");
- int uid = _wtoi(psr->id.w);
- if (!uid)
+ VKUserID_t iUserId = _wtol(psr->id.w);
+ if (!iUserId)
return 0;
- MCONTACT hContact = FindUser(uid, true);
- RetrieveUserInfo(uid);
+ MCONTACT hContact = FindUser(iUserId, true);
+ RetrieveUserInfo(iUserId);
return hContact;
}
@@ -564,11 +565,11 @@ int CVkProto::AuthRequest(MCONTACT hContact, const wchar_t *message)
if (!IsOnline())
return 1;
- LONG userID = getDword(hContact, "ID", VK_INVALID_USER);
- if (userID == VK_INVALID_USER || !hContact || userID == VK_FEED_USER)
+ VKUserID_t iUserId = ReadVKUserID(hContact);
+ if (iUserId == VK_INVALID_USER || !hContact || iUserId == VK_FEED_USER)
return 1;
- if (userID < 0)
+ if (iUserId < 0)
return 1;
@@ -577,7 +578,7 @@ int CVkProto::AuthRequest(MCONTACT hContact, const wchar_t *message)
wcsncpy_s(msg, _countof(msg), message, _TRUNCATE);
Push(new AsyncHttpRequest(this, REQUEST_GET, "/method/friends.add.json", true, &CVkProto::OnReceiveAuthRequest)
- << INT_PARAM("user_id", userID)
+ << INT_PARAM("user_id", iUserId)
<< WCHAR_PARAM("text", msg))->pUserInfo = new CVkSendMsgParam(hContact);
return 0;
@@ -650,8 +651,8 @@ int CVkProto::UserIsTyping(MCONTACT hContact, int type)
{
debugLogA("CVkProto::UserIsTyping");
if (PROTOTYPE_SELFTYPING_ON == type) {
- LONG userID = getDword(hContact, "ID", VK_INVALID_USER);
- if (userID == VK_INVALID_USER || !IsOnline() || userID == VK_FEED_USER)
+ VKUserID_t iUserId = ReadVKUserID(hContact);
+ if (iUserId == VK_INVALID_USER || !IsOnline() || iUserId == VK_FEED_USER)
return 1;
if (!IsEmpty(ptrW(db_get_wsa(hContact, m_szModuleName, "Deactivated"))))
@@ -664,7 +665,7 @@ int CVkProto::UserIsTyping(MCONTACT hContact, int type)
return 1;
Push(new AsyncHttpRequest(this, REQUEST_GET, "/method/messages.setActivity.json", true, &CVkProto::OnReceiveSmth, AsyncHttpRequest::rpLow)
- << INT_PARAM("user_id", userID)
+ << INT_PARAM("user_id", iUserId)
<< CHAR_PARAM("type", "typing"));
return 0;
}
@@ -674,10 +675,10 @@ int CVkProto::UserIsTyping(MCONTACT hContact, int type)
int CVkProto::GetInfo(MCONTACT hContact, int)
{
debugLogA("CVkProto::GetInfo");
- LONG userID = getDword(hContact, "ID", VK_INVALID_USER);
- if (userID == VK_INVALID_USER || userID == VK_FEED_USER)
+ VKUserID_t iUserId = ReadVKUserID(hContact);
+ if (iUserId == VK_INVALID_USER || iUserId == VK_FEED_USER)
return 1;
- RetrieveUserInfo(userID);
+ RetrieveUserInfo(iUserId);
return 0;
}
@@ -689,8 +690,8 @@ void CVkProto::OnContactDeleted(MCONTACT hContact)
if (!Contact::OnList(hContact) || getBool(hContact, "SilentDelete") || isChatRoom((MCONTACT)hContact))
return;
- LONG userID = getDword(hContact, "ID", VK_INVALID_USER);
- if (userID == VK_INVALID_USER || userID == VK_FEED_USER)
+ VKUserID_t iUserId = ReadVKUserID(hContact);
+ if (iUserId == VK_INVALID_USER || iUserId == VK_FEED_USER)
return;
CONTACTDELETE_FORM_PARAMS *param = new CONTACTDELETE_FORM_PARAMS(pwszNick, true, !getBool(hContact, "Auth", true), true);
@@ -701,7 +702,7 @@ void CVkProto::OnContactDeleted(MCONTACT hContact)
if (!(param->bDeleteDialog || param->bDeleteFromFriendlist))
return;
- CMStringA code(FORMAT, "var userID=\"%d\";", userID);
+ CMStringA code(FORMAT, "var userID=\"%d\";", iUserId);
if (param->bDeleteDialog)
code += "API.messages.deleteConversation({\"peer_id\":userID});";
diff --git a/protocols/VKontakte/src/vk_proto.h b/protocols/VKontakte/src/vk_proto.h
index a3755e3721..4ebab92222 100644
--- a/protocols/VKontakte/src/vk_proto.h
+++ b/protocols/VKontakte/src/vk_proto.h
@@ -133,11 +133,17 @@ struct CVkProto : public PROTO<CVkProto>
void ShowCaptchaInBrowser(HBITMAP hBitmap);
static mir_cs m_csTimer;
- static UINT_PTR m_timer;
+ static UINT_PTR m_Timer;
CVKOptions m_vkOptions;
+ VKUserID_t ReadVKUserIDFromString(MCONTACT hContact);
+ VKUserID_t ReadVKUserID(MCONTACT hContact);
+ void WriteVKUserID(MCONTACT hContact, VKUserID_t iUserId);
+
private:
+ VKPeerType GetVKPeerType(VKUserID_t iPeerId);
+
friend struct AsyncHttpRequest;
friend class CVkUserItem;
@@ -185,7 +191,7 @@ private:
//====================================================================================
bool
- m_prevError,
+ m_bPrevError,
m_bOnline,
m_bNeedSendOnline,
m_bSetBroadcast,
@@ -194,26 +200,26 @@ private:
m_bTerminated,
m_bErr404Return;
- LONG m_myUserId;
+ VKUserID_t m_iMyUserId;
ptrA
- m_pollingServer,
- m_pollingKey,
- m_pollingTs,
+ m_szPollingServer,
+ m_szPollingKey,
+ m_szPollingTs,
m_szAccessToken;
HNETLIBCONN
- m_pollingConn,
+ m_hPollingConn,
m_hAPIConnection;
HANDLE
m_hPollingThread,
m_hPopupClassError,
m_hPopupClassNotification,
- m_evRequestsQueue,
+ m_hEvRequestsQueue,
m_hWorkerThread;
- ULONG m_msgId;
+ long m_iMsgId;
mir_cs
m_csChatTyping,
@@ -234,7 +240,7 @@ private:
OBJLIST<CVkCookie> m_cookies;
LIST<AsyncHttpRequest> m_arRequestsQueue;
- CMStringA m_prevUrl;
+ CMStringA m_szPrevUrl;
HGENMENU
m_hContactMenuItems[CMI_COUNT],
@@ -281,9 +287,9 @@ private:
void AddFeedSpecialUser();
void AddFeedEvent(CVKNewsItem& vkNewsItem);
void AddCListEvent(bool bNews);
- CVkUserInfo* GetVkUserInfo(LONG iUserId, OBJLIST<CVkUserInfo> &vkUsers);
+ CVkUserInfo* GetVkUserInfo(VKUserID_t iUserId, OBJLIST<CVkUserInfo> &vkUsers);
void CreateVkUserInfoList(OBJLIST<CVkUserInfo> &vkUsers, const JSONNode &jnResponse);
- CVKNewsItem* GetVkNewsItem(const JSONNode &jnItem, OBJLIST<CVkUserInfo> &vkUsers, bool isRepost = false);
+ CVKNewsItem* GetVkNewsItem(const JSONNode &jnItem, OBJLIST<CVkUserInfo> &vkUsers, bool bIsRepost = false);
CVKNewsItem* GetVkGroupInvates(const JSONNode &jnItem, OBJLIST<CVkUserInfo> &vkUsers);
CVKNewsItem* GetVkNotificationsItem(const JSONNode &jnItem, OBJLIST<CVkUserInfo> &vkUsers);
void OnFriendAccepted(const JSONNode &jnFeedback);
@@ -292,7 +298,7 @@ private:
void RetrieveUnreadNews(time_t tLastNewsTime);
void OnReceiveUnreadNews(NETLIBHTTPREQUEST*, AsyncHttpRequest*);
void RetrieveUnreadNotifications(time_t tLastNotificationsTime);
- bool FilterNotification(CVKNewsItem *vkNotificationItem, bool& isCommented);
+ bool FilterNotification(CVKNewsItem *vkNotificationItem, bool& bIsCommented);
void NotificationMarkAsViewed();
void OnReceiveUnreadNotifications(NETLIBHTTPREQUEST*, AsyncHttpRequest*);
void RetrieveUnreadEvents();
@@ -302,33 +308,33 @@ private:
//====================================================================================
void SetServerStatus(int);
- void RetrieveUsersInfo(bool flag = false, bool bRepeat = false);
+ void RetrieveUsersInfo(bool bFlag = false, bool bRepeat = false);
void RetrieveStatusMsg(const CMStringW &StatusMsg);
void RetrieveStatusMusic(const CMStringW &StatusMsg);
void OnReceiveStatus(NETLIBHTTPREQUEST*, AsyncHttpRequest*);
void OnReceiveStatusMsg(NETLIBHTTPREQUEST*, AsyncHttpRequest*);
- MCONTACT SetContactInfo(const JSONNode &jnItem, bool flag = false, VKContactType vkContactType = VKContactType::vkContactNormal);
+ MCONTACT SetContactInfo(const JSONNode &jnItem, bool bFlag = false, VKContactType vkContactType = VKContactType::vkContactNormal);
void TrackVisitor();
void RetrieveMyInfo(void);
void OnReceiveMyInfo(NETLIBHTTPREQUEST*, AsyncHttpRequest*);
- void RetrieveUserInfo(LONG userId);
- void RetrieveGroupInfo(LONG groupID);
+ void RetrieveUserInfo(VKUserID_t iUserId);
+ void RetrieveGroupInfo(VKUserID_t iGroupID);
void RetrieveGroupInfo(CMStringA & groupIDs);
void OnReceiveUserInfo(NETLIBHTTPREQUEST*, AsyncHttpRequest*);
void OnReceiveGroupInfo(NETLIBHTTPREQUEST * reply, AsyncHttpRequest * pReq);
void RetrieveFriends(bool bCleanNonFriendContacts = false);
void OnReceiveFriends(NETLIBHTTPREQUEST*, AsyncHttpRequest*);
void MarkMessagesRead(const MCONTACT hContact);
- void RetrieveMessagesByIds(const CMStringA &mids);
+ void RetrieveMessagesByIds(const CMStringA &szMids);
void RetrieveUnreadMessages();
void OnReceiveMessages(NETLIBHTTPREQUEST*, AsyncHttpRequest*);
void OnReceiveDlgs(NETLIBHTTPREQUEST*, AsyncHttpRequest*);
void OnSendMessage(NETLIBHTTPREQUEST*, AsyncHttpRequest*);
void WallPost(MCONTACT hContact, wchar_t *pwszMsg, wchar_t *pwszUrl, bool bFriendsOnly);
- void GetServerHistoryLastNDay(MCONTACT hContact, int NDay);
- void GetServerHistory(MCONTACT hContact, int iOffset, int iCount, int iTime, int iLastMsgId, bool once = false);
+ void GetServerHistoryLastNDay(MCONTACT hContact, int iNDay);
+ void GetServerHistory(MCONTACT hContact, int iOffset, int iCount, time_t tTime, VKMessageID_t iLastMsgId, bool bOnce = false);
void OnReceiveHistoryMessages(NETLIBHTTPREQUEST *reply, AsyncHttpRequest *pReq);
- void GetHistoryDlg(MCONTACT hContact, int iLastMsg);
+ void GetHistoryDlg(MCONTACT hContact, VKMessageID_t iLastMsg);
void RetrievePollingInfo();
void OnReceivePollingInfo(NETLIBHTTPREQUEST*, AsyncHttpRequest*);
void __cdecl PollingThread(void*);
@@ -339,11 +345,10 @@ private:
//==== Misc ==========================================================================
- void SetAllContactStatuses(int status);
- MCONTACT FindUser(LONG userid, bool bCreate = false);
- MCONTACT FindChat(LONG dwUserid);
+ void SetAllContactStatuses(int iStatus);
+ MCONTACT FindUser(VKUserID_t iUserId, bool bCreate = false);
+ MCONTACT FindChat(VKUserID_t iUserId);
bool IsGroupUser(MCONTACT hContact);
- bool CheckMid(LIST<void> &lList, int guid);
JSONNode& CheckJsonResponse(AsyncHttpRequest *pReq, NETLIBHTTPREQUEST *reply, JSONNode &root);
bool CheckJsonResult(AsyncHttpRequest *pReq, const JSONNode &Node);
void OnReceiveSmth(NETLIBHTTPREQUEST*, AsyncHttpRequest*);
@@ -357,14 +362,14 @@ private:
void __cdecl DBAddAuthRequestThread(void *p);
void DBAddAuthRequest(const MCONTACT hContact, bool bAdded = false);
MCONTACT MContactFromDbEvent(MEVENT hDbEvent);
- void SetMirVer(MCONTACT hContact, int platform);
+ void SetMirVer(MCONTACT hContact, int iPlatform);
void __cdecl ContactTypingThread(void *p);
int IsHystoryMessageExist(MCONTACT hContact);
void SetSrmmReadStatus(MCONTACT hContact);
void MarkDialogAsRead(MCONTACT hContact);
void CheckUpdate();
- char* GetStickerId(const char *Msg, int& stickerid);
- CMStringA GetAttachmentsFromMessage(const char * Msg);
+ char* GetStickerId(const char *szMsg, int& iStickerid);
+ CMStringA GetAttachmentsFromMessage(const char * szMsg);
CMStringW SpanVKNotificationType(CMStringW& wszType, VKObjType& vkFeedback, VKObjType& vkParent);
CMStringW GetVkPhotoItem(const JSONNode &jnPhoto, BBCSupport iBBC);
CMStringW SetBBCString(LPCWSTR wszString, BBCSupport iBBC, VKBBCType bbcType, LPCWSTR wszAddString = nullptr);
@@ -375,11 +380,11 @@ private:
void SetInvisible(MCONTACT hContact);
CMStringW RemoveBBC(CMStringW& wszSrc);
void AddVkDeactivateEvent(MCONTACT hContact, CMStringW & wszType);
- MEVENT GetMessageFromDb(UINT iMsgId, UINT& timestamp, CMStringW& msg);
- MEVENT GetMessageFromDb(const char * messageId, UINT &timestamp, CMStringW &msg);
+ MEVENT GetMessageFromDb(VKMessageID_t iMessageId, time_t& tTimeStamp, CMStringW& wszMsg);
+ MEVENT GetMessageFromDb(const char * szMessageId, time_t& tTimeStamp, CMStringW& wszMsg);
int DeleteContact(MCONTACT hContact);
- bool IsMessageExist(UINT iMsgId, VKMesType vkType = vkALL);
- CMStringW UserProfileUrl(LONG iUserId);
+ bool IsMessageExist(VKMessageID_t iMessageId, VKMesType vkType = vkALL);
+ CMStringW UserProfileUrl(VKUserID_t iUserId);
void InitQueue();
void UninitQueue();
bool ExecuteRequest(AsyncHttpRequest*);
@@ -397,12 +402,14 @@ private:
void GetAvatarFileName(MCONTACT hContact, wchar_t *pwszDest, size_t cbLen);
void ReloadAvatarInfo(MCONTACT hContact);
void __cdecl ChatContactTypingThread(void *p);
- void StopChatContactTyping(int iChatId, LONG iUserId);
+
+ void StopChatContactTyping(VKUserID_t iChatId, VKUserID_t iUserId);
+
void OnCreateNewChat(NETLIBHTTPREQUEST*, AsyncHttpRequest*);
- CVkChatInfo* AppendConversationChat(int iChatId, const JSONNode& jnItem);
+ CVkChatInfo* AppendConversationChat(VKUserID_t iChatId, const JSONNode& jnItem);
void SetChatTitle(CVkChatInfo *cc, LPCWSTR wszTopic);
- void AppendChatConversationMessage(int id, const JSONNode& jnMsg, const JSONNode& jnFUsers, bool bIsHistory);
- void AppendChatMessage(CVkChatInfo *cc, LONG mid, LONG uid, int msgTime, LPCWSTR pwszBody, bool bIsHistory, bool bIsAction = false);
+ void AppendChatConversationMessage(VKUserID_t iChatId, const JSONNode& jnMsg, const JSONNode& jnFUsers, bool bIsHistory);
+ void AppendChatMessage(CVkChatInfo* vkChatInfo, VKMessageID_t iMessageId, VKUserID_t iUserId, time_t tMsgTime, LPCWSTR pwszBody, bool bIsHistory, bool bIsAction = false);
void RetrieveChatInfo(CVkChatInfo*);
void OnReceiveChatInfo(NETLIBHTTPREQUEST*, AsyncHttpRequest*);
void OnSendChatMsg(NETLIBHTTPREQUEST*, AsyncHttpRequest*);
@@ -410,8 +417,8 @@ private:
void OnChatDestroy(NETLIBHTTPREQUEST*, AsyncHttpRequest*);
int __cdecl OnChatEvent(WPARAM, LPARAM);
int __cdecl OnGcMenuHook(WPARAM, LPARAM);
- void KickFromChat(int chat_id, LONG user_id, const JSONNode &jnMsg, const JSONNode &jnFUsers);
- void LeaveChat(int chat_id, bool close_window = true, bool delete_chat = false);
+ void KickFromChat(VKUserID_t iChatId, VKUserID_t iUserId, const JSONNode &jnMsg, const JSONNode &jnFUsers);
+ void LeaveChat(VKUserID_t iChatId, bool bCloseWindow = true, bool bDeleteChat = false);
INT_PTR __cdecl OnLeaveChat(WPARAM, LPARAM);
INT_PTR __cdecl OnJoinChat(WPARAM, LPARAM);
void LogMenuHook(CVkChatInfo*, GCHOOK*);
@@ -422,6 +429,11 @@ private:
CVkChatInfo* GetChatByContact(MCONTACT hContact);
INT_PTR __cdecl SvcCreateChat(WPARAM, LPARAM);
void __cdecl GetAwayMsgThread(void* p);
+
+ void CVkProto::WriteQSWord(MCONTACT hContact, const char* szParam, uint64_t uValue);
+ uint64_t CVkProto::ReadQSWord(MCONTACT hContact, const char* szParam, uint64_t uDefaultValue = 0);
+
+ bool bIint64IDCompatibility;
};
struct CMPlugin : public ACCPROTOPLUGIN<CVkProto>
diff --git a/protocols/VKontakte/src/vk_queue.cpp b/protocols/VKontakte/src/vk_queue.cpp
index ecf98468d0..e3384f430b 100644
--- a/protocols/VKontakte/src/vk_queue.cpp
+++ b/protocols/VKontakte/src/vk_queue.cpp
@@ -20,14 +20,14 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
void CVkProto::InitQueue()
{
debugLogA("CVkProto::InitQueue");
- m_evRequestsQueue = CreateEvent(nullptr, false, false, nullptr);
+ m_hEvRequestsQueue = CreateEvent(nullptr, false, false, nullptr);
}
void CVkProto::UninitQueue()
{
debugLogA("CVkProto::UninitQueue");
m_arRequestsQueue.destroy();
- CloseHandle(m_evRequestsQueue);
+ CloseHandle(m_hEvRequestsQueue);
}
/////////////////////////////////////////////////////////////////////////////////////////
@@ -124,7 +124,7 @@ AsyncHttpRequest* CVkProto::Push(MHttpRequest *p, int iTimeout)
mir_cslock lck(m_csRequestsQueue);
m_arRequestsQueue.insert(pReq);
}
- SetEvent(m_evRequestsQueue);
+ SetEvent(m_hEvRequestsQueue);
return pReq;
}
@@ -133,7 +133,7 @@ AsyncHttpRequest* CVkProto::Push(MHttpRequest *p, int iTimeout)
void CVkProto::WorkerThread(void*)
{
debugLogA("CVkProto::WorkerThread: entering");
- m_bTerminated = m_prevError = false;
+ m_bTerminated = m_bPrevError = false;
m_szAccessToken = getStringA("AccessToken");
extern char szScore[];
@@ -186,12 +186,12 @@ void CVkProto::WorkerThread(void*)
CloseAPIConnection();
while (true) {
- WaitForSingleObject(m_evRequestsQueue, 1000);
+ WaitForSingleObject(m_hEvRequestsQueue, 1000);
if (m_bTerminated)
break;
AsyncHttpRequest *pReq;
- ULONG uTime[3] = { 0, 0, 0 };
+ time_t tTime[3] = { 0, 0, 0 };
long lWaitingTime = 0;
while (true) {
@@ -203,8 +203,8 @@ void CVkProto::WorkerThread(void*)
pReq = m_arRequestsQueue[0];
m_arRequestsQueue.remove(0);
- ULONG utime = GetTickCount();
- lWaitingTime = (utime - uTime[0]) > 1500 ? 0 : 1500 - (utime - uTime[0]);
+ ULONGLONG utime = GetTickCount64();
+ lWaitingTime = (utime - tTime[0]) > 1500 ? 0 : 1500 - (utime - tTime[0]);
if (!(pReq->m_bApiReq))
lWaitingTime = 0;
@@ -219,9 +219,9 @@ void CVkProto::WorkerThread(void*)
}
if (pReq->m_bApiReq) {
- uTime[0] = uTime[1];
- uTime[1] = uTime[2];
- uTime[2] = GetTickCount();
+ tTime[0] = tTime[1];
+ tTime[1] = tTime[2];
+ tTime[2] = GetTickCount();
// There can be maximum 3 requests to API methods per second from a client
// see https://vk.com/dev/api_requests
}
diff --git a/protocols/VKontakte/src/vk_struct.cpp b/protocols/VKontakte/src/vk_struct.cpp
index dffe7a2341..52ababd13c 100644
--- a/protocols/VKontakte/src/vk_struct.cpp
+++ b/protocols/VKontakte/src/vk_struct.cpp
@@ -19,7 +19,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
/////////////////////////////////////////////////////////////////////////////////////////
-ULONG AsyncHttpRequest::m_reqCount = 0;
+ULONG AsyncHttpRequest::m_uReqCount = 0;
AsyncHttpRequest::AsyncHttpRequest()
{
@@ -31,7 +31,7 @@ AsyncHttpRequest::AsyncHttpRequest()
bNeedsRestart = false;
bIsMainConn = false;
m_pFunc = nullptr;
- m_reqNum = ::InterlockedIncrement(&m_reqCount);
+ m_uReqNum = ::InterlockedIncrement(&m_uReqCount);
m_priority = rpLow;
}
@@ -61,7 +61,7 @@ AsyncHttpRequest::AsyncHttpRequest(CVkProto *ppro, int iRequestType, LPCSTR _url
m_iRetry = MAX_RETRIES;
m_iErrorCode = 0;
bNeedsRestart = false;
- m_reqNum = ::InterlockedIncrement(&m_reqCount);
+ m_uReqNum = ::InterlockedIncrement(&m_uReqCount);
m_priority = rpPriority;
}
@@ -75,73 +75,73 @@ void AsyncHttpRequest::Redirect(NETLIBHTTPREQUEST *nhr)
CVkFileUploadParam::CVkFileUploadParam(MCONTACT _hContact, const wchar_t *_desc, wchar_t **_files) :
hContact(_hContact),
- Desc(mir_wstrdup(_desc)),
- FileName(mir_wstrdup(_files[0])),
- atr(nullptr),
- fname(nullptr),
- filetype(typeInvalid)
+ wszDesc(mir_wstrdup(_desc)),
+ wszFileName(mir_wstrdup(_files[0])),
+ szAtr(nullptr),
+ szFname(nullptr),
+ vkFileType(typeInvalid)
{}
CVkFileUploadParam::~CVkFileUploadParam()
{
- mir_free(Desc);
- mir_free(FileName);
- mir_free(atr);
- mir_free(fname);
+ mir_free(wszDesc);
+ mir_free(wszFileName);
+ mir_free(szAtr);
+ mir_free(szFname);
}
CVkFileUploadParam::VKFileType CVkFileUploadParam::GetType()
{
- if (filetype != typeInvalid)
- return filetype;
+ if (vkFileType != typeInvalid)
+ return vkFileType;
- if (atr)
- mir_free(atr);
- if (fname)
- mir_free(fname);
+ if (szAtr)
+ mir_free(szAtr);
+ if (szFname)
+ mir_free(szFname);
wchar_t img[] = L".jpg .jpeg .png .bmp";
wchar_t audio[] = L".mp3";
wchar_t audiomsg[] = L".ogg";
wchar_t DRIVE[3], DIR[256], FNAME[256], EXT[256];
- _wsplitpath(FileName, DRIVE, DIR, FNAME, EXT);
+ _wsplitpath(wszFileName, DRIVE, DIR, FNAME, EXT);
T2Utf pszFNAME(FNAME), pszEXT(EXT);
CMStringA fn(FORMAT, "%s%s", pszFNAME, pszEXT);
- fname = mir_strdup(fn);
+ szFname = mir_strdup(fn);
if (wlstrstr(img, EXT)) {
- filetype = CVkFileUploadParam::typeImg;
- atr = mir_strdup("photo");
+ vkFileType = CVkFileUploadParam::typeImg;
+ szAtr = mir_strdup("photo");
}
else if (wlstrstr(audio, EXT)) {
- filetype = CVkFileUploadParam::typeAudio;
- atr = mir_strdup("file");
+ vkFileType = CVkFileUploadParam::typeAudio;
+ szAtr = mir_strdup("file");
}
else if (wlstrstr(audiomsg, EXT)) {
- filetype = CVkFileUploadParam::typeAudioMsg;
- atr = mir_strdup("file");
+ vkFileType = CVkFileUploadParam::typeAudioMsg;
+ szAtr = mir_strdup("file");
}
else {
- filetype = CVkFileUploadParam::typeDoc;
- atr = mir_strdup("file");
+ vkFileType = CVkFileUploadParam::typeDoc;
+ szAtr = mir_strdup("file");
}
- return filetype;
+ return vkFileType;
}
/////////////////////////////////////////////////////////////////////////////////////////
CVkChatUser* CVkChatInfo::GetUserById(LPCWSTR pwszId)
{
- int user_id = _wtoi(pwszId);
- return m_users.find((CVkChatUser*)&user_id);
+ VKUserID_t iUserId = _wtol(pwszId);
+ return m_users.find((CVkChatUser*)&iUserId);
}
-CVkChatUser* CVkChatInfo::GetUserById(int user_id)
+CVkChatUser* CVkChatInfo::GetUserById(VKUserID_t iUserId)
{
- return m_users.find((CVkChatUser*)&user_id);
+ return m_users.find((CVkChatUser*)&iUserId);
}
/////////////////////////////////////////////////////////////////////////////////////////
diff --git a/protocols/VKontakte/src/vk_struct.h b/protocols/VKontakte/src/vk_struct.h
index b9be280032..08ad3e9412 100644
--- a/protocols/VKontakte/src/vk_struct.h
+++ b/protocols/VKontakte/src/vk_struct.h
@@ -30,32 +30,32 @@ struct AsyncHttpRequest : public MTHttpRequest<CVkProto>
int m_iRetry;
int m_iErrorCode;
RequestPriority m_priority;
- static ULONG m_reqCount;
- ULONG m_reqNum;
+ static ULONG m_uReqCount;
+ ULONG m_uReqNum;
bool m_bApiReq;
bool bNeedsRestart, bIsMainConn;
};
struct CVkFileUploadParam : public MZeroedObject {
enum VKFileType { typeInvalid, typeImg, typeAudio, typeAudioMsg, typeDoc, typeNotSupported };
- wchar_t *FileName;
- wchar_t *Desc;
- char *atr;
- char *fname;
+ wchar_t *wszFileName;
+ wchar_t *wszDesc;
+ char *szAtr;
+ char *szFname;
MCONTACT hContact;
- VKFileType filetype;
+ VKFileType vkFileType;
CVkFileUploadParam(MCONTACT _hContact, const wchar_t *_desc, wchar_t **_files);
~CVkFileUploadParam();
VKFileType GetType();
- __forceinline bool IsAccess() { return ::_waccess(FileName, 0) == 0; }
- __forceinline char* atrName() { GetType(); return atr; }
- __forceinline char* fileName() { GetType(); return fname; }
+ __forceinline bool IsAccess() { return ::_waccess(wszFileName, 0) == 0; }
+ __forceinline char* atrName() { GetType(); return szAtr; }
+ __forceinline char* fileName() { GetType(); return szFname; }
};
struct CVkSendMsgParam : public MZeroedObject
{
- CVkSendMsgParam(MCONTACT _hContact, int _iMsgID = 0, int _iCount = 0) :
+ CVkSendMsgParam(MCONTACT _hContact, VKMessageID_t _iMsgID = 0, int _iCount = 0) :
hContact(_hContact),
iMsgID(_iMsgID),
iCount(_iCount),
@@ -70,7 +70,7 @@ struct CVkSendMsgParam : public MZeroedObject
{}
MCONTACT hContact;
- int iMsgID;
+ VKMessageID_t iMsgID;
int iCount;
CVkFileUploadParam *pFUP;
};
@@ -88,41 +88,44 @@ struct CVkDBAddAuthRequestThreadParam : public MZeroedObject
struct CVkChatMessage : public MZeroedObject
{
- CVkChatMessage(int _id) :
- m_mid(_id),
- m_uid(0),
- m_date(0),
+ CVkChatMessage(VKUserID_t _id) :
+ m_iMessageId(_id),
+ m_iUserId(0),
+ m_tDate(0),
m_bHistory(false),
m_bIsAction(false)
{}
- int m_mid, m_uid, m_date;
+ VKMessageID_t m_iMessageId;
+ VKUserID_t m_iUserId;
+ time_t m_tDate;
bool m_bHistory, m_bIsAction;
ptrW m_wszBody;
};
struct CVkChatUser : public MZeroedObject
{
- CVkChatUser(LONG _id) :
- m_uid(_id),
+ CVkChatUser(VKUserID_t _id) :
+ m_iUserId(_id),
m_bDel(false),
m_bUnknown(false)
{}
- LONG m_uid;
+ VKUserID_t m_iUserId;
bool m_bDel, m_bUnknown;
ptrW m_wszNick;
};
struct CVkChatInfo : public MZeroedObject
{
- CVkChatInfo(int _id) :
+ CVkChatInfo(VKUserID_t _id) :
m_users(10, NumericKeySortT),
m_msgs(10, NumericKeySortT),
m_iChatId(_id)
{}
- int m_iChatId, m_iAdminId = 0;
+ VKUserID_t m_iChatId;
+ VKUserID_t m_iAdminId = 0;
bool m_bHistoryRead = false;
ptrW m_wszTopic;
SESSION_INFO *m_si = nullptr;
@@ -130,16 +133,16 @@ struct CVkChatInfo : public MZeroedObject
OBJLIST<CVkChatMessage> m_msgs;
CVkChatUser* GetUserById(LPCWSTR);
- CVkChatUser* GetUserById(int user_id);
+ CVkChatUser* GetUserById(VKUserID_t iUserId);
};
struct CVkUserInfo : public MZeroedObject {
- CVkUserInfo(LONG _UserId) :
+ CVkUserInfo(VKUserID_t _UserId) :
m_UserId(_UserId),
m_bIsGroup(false)
{}
- CVkUserInfo(LONG _UserId, bool _bIsGroup, const CMStringW& _wszUserNick, const CMStringW& _wszLink, MCONTACT _hContact = 0) :
+ CVkUserInfo(VKUserID_t _UserId, bool _bIsGroup, const CMStringW& _wszUserNick, const CMStringW& _wszLink, MCONTACT _hContact = 0) :
m_UserId(_UserId),
m_bIsGroup(_bIsGroup),
m_wszUserNick(_wszUserNick),
@@ -147,7 +150,7 @@ struct CVkUserInfo : public MZeroedObject {
m_hContact(_hContact)
{}
- LONG m_UserId;
+ VKUserID_t m_UserId;
MCONTACT m_hContact;
CMStringW m_wszUserNick;
CMStringW m_wszLink;
@@ -195,13 +198,13 @@ struct CVKBBCItem {
};
struct CVKChatContactTypingParam {
- CVKChatContactTypingParam(int pChatId, int pUserId) :
+ CVKChatContactTypingParam(VKUserID_t pChatId, VKUserID_t pUserId) :
m_ChatId(pChatId),
m_UserId(pUserId)
{}
- int m_ChatId;
- LONG m_UserId;
+ VKUserID_t m_ChatId;
+ VKUserID_t m_UserId;
};
struct CVKInteres {
@@ -339,4 +342,6 @@ struct CVKImageSizeItem {
iSizeH(0),
iSizeW(0)
{}
-}; \ No newline at end of file
+};
+
+enum VKPeerType : uint8_t { vkPeerError = 0 , vkPeerUser, vkPeerGroup, vkPeerMUC, vkPeerFeed}; \ No newline at end of file
diff --git a/protocols/VKontakte/src/vk_thread.cpp b/protocols/VKontakte/src/vk_thread.cpp
index 704aa6ea35..b58a7c8a91 100644
--- a/protocols/VKontakte/src/vk_thread.cpp
+++ b/protocols/VKontakte/src/vk_thread.cpp
@@ -17,7 +17,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "stdafx.h"
-UINT_PTR CVkProto::m_timer;
+UINT_PTR CVkProto::m_Timer;
mir_cs CVkProto::m_csTimer;
char szBlankUrl[] = "https://oauth.vk.com/blank.html";
@@ -70,7 +70,7 @@ void CVkProto::ShutdownSession()
debugLogA("CVkProto::ShutdownSession");
m_bTerminated = true;
if (m_hWorkerThread)
- SetEvent(m_evRequestsQueue);
+ SetEvent(m_hEvRequestsQueue);
OnLoggedOut();
}
@@ -102,17 +102,17 @@ static VOID CALLBACK TimerProc(HWND, UINT, UINT_PTR, DWORD)
static void CALLBACK VKSetTimer(void*)
{
mir_cslock lck(CVkProto::m_csTimer);
- if (CVkProto::m_timer)
+ if (CVkProto::m_Timer)
return;
- CVkProto::m_timer = SetTimer(nullptr, 0, 60000, TimerProc);
+ CVkProto::m_Timer = SetTimer(nullptr, 0, 60000, TimerProc);
}
static void CALLBACK VKUnsetTimer(void*)
{
mir_cslock lck(CVkProto::m_csTimer);
- if (CVkProto::m_timer)
- KillTimer(nullptr, CVkProto::m_timer);
- CVkProto::m_timer = 0;
+ if (CVkProto::m_Timer)
+ KillTimer(nullptr, CVkProto::m_Timer);
+ CVkProto::m_Timer = 0;
}
/////////////////////////////////////////////////////////////////////////////////////////
@@ -139,16 +139,16 @@ void CVkProto::OnLoggedIn()
void CVkProto::ClosePollingConnection(bool bShutdown)
{
- if (!m_pollingConn)
+ if (!m_hPollingConn)
return;
debugLogA("CVkProto::ClosePollingConnection %d", bShutdown ? 1 : 0);
if (bShutdown)
- Netlib_Shutdown(m_pollingConn);
+ Netlib_Shutdown(m_hPollingConn);
else
- Netlib_CloseHandle(m_pollingConn);
- m_pollingConn = nullptr;
+ Netlib_CloseHandle(m_hPollingConn);
+ m_hPollingConn = nullptr;
}
void CVkProto::CloseAPIConnection(bool bShutdown)
@@ -251,13 +251,13 @@ void CVkProto::OnOAuthAuthorize(NETLIBHTTPREQUEST *reply, AsyncHttpRequest*)
pRedirectReq->requestType = REQUEST_GET;
pRedirectReq->flags = NLHRF_DUMPASTEXT | NLHRF_HTTP11;
pRedirectReq->m_pFunc = &CVkProto::OnOAuthAuthorize;
- pRedirectReq->AddHeader("Referer", m_prevUrl);
+ pRedirectReq->AddHeader("Referer", m_szPrevUrl);
pRedirectReq->Redirect(reply);
if (!pRedirectReq->m_szUrl.IsEmpty()) {
if (pRedirectReq->m_szUrl[0] == '/')
pRedirectReq->m_szUrl = szVKLoginDomain + pRedirectReq->m_szUrl;
ApplyCookies(pRedirectReq);
- m_prevUrl = pRedirectReq->m_szUrl;
+ m_szPrevUrl = pRedirectReq->m_szUrl;
}
pRedirectReq->m_bApiReq = false;
@@ -327,11 +327,11 @@ void CVkProto::OnOAuthAuthorize(NETLIBHTTPREQUEST *reply, AsyncHttpRequest*)
CMStringA szAction, szBody;
bool bSuccess = AutoFillForm(reply->pData, szAction, szBody);
if (!bSuccess || szAction.IsEmpty() || szBody.IsEmpty()) {
- if (m_prevError) {
+ if (m_bPrevError) {
ConnectionFailed(LOGINERR_NOSERVER);
return;
}
- m_prevError = true;
+ m_bPrevError = true;
}
AsyncHttpRequest *pReq = new AsyncHttpRequest();
@@ -341,7 +341,7 @@ void CVkProto::OnOAuthAuthorize(NETLIBHTTPREQUEST *reply, AsyncHttpRequest*)
pReq->m_szUrl = szAction;
if (!pReq->m_szUrl.IsEmpty() && pReq->m_szUrl[0] == '/')
pReq->m_szUrl = szVKLoginDomain + pReq->m_szUrl;
- m_prevUrl = pReq->m_szUrl;
+ m_szPrevUrl = pReq->m_szUrl;
pReq->m_pFunc = &CVkProto::OnOAuthAuthorize;
pReq->AddHeader("Content-Type", "application/x-www-form-urlencoded");
pReq->Redirect(reply);
@@ -396,37 +396,38 @@ void CVkProto::OnReceiveMyInfo(NETLIBHTTPREQUEST *reply, AsyncHttpRequest *pReq)
const JSONNode &jnUser = *(jnResponse.begin());
- m_myUserId = jnUser["id"].as_int();
- setDword("ID", m_myUserId);
+ m_iMyUserId = jnUser["id"].as_int();
+
+ WriteVKUserID(0, m_iMyUserId);
OnLoggedIn();
- RetrieveUserInfo(m_myUserId);
+ RetrieveUserInfo(m_iMyUserId);
TrackVisitor();
RetrieveUnreadMessages();
RetrieveFriends(m_vkOptions.bLoadOnlyFriends);
RetrievePollingInfo();
}
-MCONTACT CVkProto::SetContactInfo(const JSONNode &jnItem, bool flag, VKContactType vkContactType)
+MCONTACT CVkProto::SetContactInfo(const JSONNode &jnItem, bool bFlag, VKContactType vkContactType)
{
if (!jnItem) {
debugLogA("CVkProto::SetContactInfo pItem == nullptr");
return INVALID_CONTACT_ID;
}
- LONG userid = jnItem["id"].as_int();
- debugLogA("CVkProto::SetContactInfo %d", userid);
- if (userid == 0 || userid == VK_FEED_USER)
+ VKUserID_t iUserId = jnItem["id"].as_int();
+ debugLogA("CVkProto::SetContactInfo %d", iUserId);
+ if (iUserId == 0 || iUserId == VK_FEED_USER)
return 0;
- MCONTACT hContact = FindUser(userid, flag);
+ MCONTACT hContact = FindUser(iUserId, bFlag);
- if (userid == m_myUserId) {
+ if (iUserId == m_iMyUserId) {
if (hContact != 0)
if (vkContactType == VKContactType::vkContactSelf)
hContact = 0;
else
- SetContactInfo(jnItem, flag, VKContactType::vkContactSelf);
+ SetContactInfo(jnItem, bFlag, VKContactType::vkContactSelf);
}
else if (hContact == 0)
return 0;
@@ -501,10 +502,10 @@ MCONTACT CVkProto::SetContactInfo(const JSONNode &jnItem, bool flag, VKContactTy
const JSONNode &jnLastSeen = jnItem["last_seen"];
if (jnLastSeen) {
- int iLastSeen = jnLastSeen["time"].as_int();
+ time_t tLastSeen = jnLastSeen["time"].as_int();
int iOldLastSeen = db_get_dw(hContact, "BuddyExpectator", "LastSeen");
- if (iLastSeen && iLastSeen > iOldLastSeen) {
- db_set_dw(hContact, "BuddyExpectator", "LastSeen", (uint32_t)iLastSeen);
+ if (tLastSeen && tLastSeen > iOldLastSeen) {
+ db_set_dw(hContact, "BuddyExpectator", "LastSeen", (uint32_t)tLastSeen);
db_set_w(hContact, "BuddyExpectator", "LastStatus", ID_STATUS_ONLINE);
}
}
@@ -644,33 +645,33 @@ MCONTACT CVkProto::SetContactInfo(const JSONNode &jnItem, bool flag, VKContactTy
return hContact;
}
-void CVkProto::RetrieveUserInfo(LONG userID)
+void CVkProto::RetrieveUserInfo(VKUserID_t iUserId)
{
- debugLogA("CVkProto::RetrieveUserInfo (%d)", userID);
- if (userID == VK_FEED_USER || !IsOnline())
+ debugLogA("CVkProto::RetrieveUserInfo (%d)", iUserId);
+ if (iUserId == VK_FEED_USER || !IsOnline())
return;
- if (userID < 0) {
- RetrieveGroupInfo(userID);
+ if (iUserId < 0) {
+ RetrieveGroupInfo(iUserId);
return;
}
Push(new AsyncHttpRequest(this, REQUEST_POST, "/method/execute.RetrieveUserInfo", true, &CVkProto::OnReceiveUserInfo)
- << INT_PARAM("userid", userID)
+ << INT_PARAM("userid", iUserId)
<< CHAR_PARAM("fields", szFieldsName)
);
}
-void CVkProto::RetrieveGroupInfo(LONG groupID)
+void CVkProto::RetrieveGroupInfo(VKUserID_t iGroupId)
{
- debugLogA("CVkProto::RetrieveGroupInfo (%d)", groupID);
- if (groupID >= VK_INVALID_USER || !IsOnline())
+ debugLogA("CVkProto::RetrieveGroupInfo (%d)", iGroupId);
+ if (GetVKPeerType(iGroupId) != VKPeerType::vkPeerGroup || !IsOnline())
return;
Push(new AsyncHttpRequest(this, REQUEST_GET, "/method/groups.getById.json", true, &CVkProto::OnReceiveGroupInfo)
<< CHAR_PARAM("fields", "description")
- << INT_PARAM("group_id", -1 * groupID));
+ << INT_PARAM("group_id", -1 * iGroupId));
}
void CVkProto::RetrieveGroupInfo(CMStringA& groupIDs)
@@ -693,8 +694,8 @@ void CVkProto::RetrieveUsersInfo(bool bFreeOffline, bool bRepeat)
CMStringA userIDs;
int i = 0;
for (auto &hContact : AccContacts()) {
- LONG userID = getDword(hContact, "ID", VK_INVALID_USER);
- if (userID == VK_INVALID_USER || userID == VK_FEED_USER || userID < 0)
+ VKUserID_t iUserId = ReadVKUserID(hContact);
+ if (iUserId == VK_INVALID_USER || iUserId == VK_FEED_USER || iUserId < 0)
continue;
bool bIsFriend = !getBool(hContact, "Auth", true);
@@ -703,7 +704,7 @@ void CVkProto::RetrieveUsersInfo(bool bFreeOffline, bool bRepeat)
if (!userIDs.IsEmpty())
userIDs.AppendChar(',');
- userIDs.AppendFormat("%i", userID);
+ userIDs.AppendFormat("%i", iUserId);
if (i == MAX_CONTACTS_PER_REQUEST)
break;
@@ -756,8 +757,8 @@ void CVkProto::OnReceiveUserInfo(NETLIBHTTPREQUEST *reply, AsyncHttpRequest *pRe
if (jnResponse["freeoffline"].as_bool())
for (auto &it : arContacts) {
MCONTACT cc = (UINT_PTR)it;
- LONG userID = getDword(cc, "ID", VK_INVALID_USER);
- if (userID == m_myUserId || userID == VK_FEED_USER)
+ VKUserID_t iUserId = ReadVKUserID(cc);
+ if (iUserId == m_iMyUserId || iUserId == VK_FEED_USER)
continue;
int iContactStatus = getWord(cc, "Status", ID_STATUS_OFFLINE);
@@ -784,13 +785,13 @@ void CVkProto::OnReceiveUserInfo(NETLIBHTTPREQUEST *reply, AsyncHttpRequest *pRe
debugLogA("CVkProto::OnReceiveUserInfo AuthRequests");
for (auto it : jnItems) {
- LONG userid = it.as_int();
- if (userid == 0)
+ VKUserID_t iUserId = it.as_int();
+ if (iUserId == 0)
break;
- MCONTACT hContact = FindUser(userid, true);
+ MCONTACT hContact = FindUser(iUserId, true);
if (!IsAuthContactLater(hContact)) {
- RetrieveUserInfo(userid);
+ RetrieveUserInfo(iUserId);
AddAuthContactLater(hContact);
CVkDBAddAuthRequestThreadParam *param = new CVkDBAddAuthRequestThreadParam(hContact, false);
ForkThread(&CVkProto::DBAddAuthRequestThread, (void *)param);
@@ -811,7 +812,7 @@ void CVkProto::OnReceiveGroupInfo(NETLIBHTTPREQUEST *reply, AsyncHttpRequest *pR
return;
for (auto &jnItem : jnResponse) {
- int iGroupId = (-1)*jnItem["id"].as_int();
+ VKUserID_t iGroupId = (-1)*jnItem["id"].as_int();
bool bIsMember = jnItem["is_member"].as_bool();
MCONTACT hContact = FindUser(iGroupId, true);
@@ -922,9 +923,9 @@ void CVkProto::OnReceiveFriends(NETLIBHTTPREQUEST *reply, AsyncHttpRequest *pReq
if (bCleanContacts)
for (auto &it : arContacts) {
MCONTACT hContact = (UINT_PTR)it;
- LONG userID = getDword(hContact, "ID", VK_INVALID_USER);
+ VKUserID_t iUserId = ReadVKUserID(hContact);
bool bIsFriendGroup = IsGroupUser(hContact) && getBool(hContact, "friend");
- if (userID == m_myUserId || userID == VK_FEED_USER || bIsFriendGroup)
+ if (iUserId == m_iMyUserId || iUserId == VK_FEED_USER || bIsFriendGroup)
continue;
if (!IsAuthContactLater(hContact))
DeleteContact(hContact);
@@ -938,8 +939,8 @@ void CVkProto::OnReceiveFriends(NETLIBHTTPREQUEST *reply, AsyncHttpRequest *pReq
INT_PTR __cdecl CVkProto::SvcAddAsFriend(WPARAM hContact, LPARAM)
{
debugLogA("CVkProto::SvcAddAsFriend");
- LONG userID = getDword(hContact, "ID", VK_INVALID_USER);
- if (!IsOnline() || userID == VK_INVALID_USER || userID == VK_FEED_USER)
+ VKUserID_t iUserId = ReadVKUserID(hContact);
+ if (!IsOnline() || iUserId == VK_INVALID_USER || iUserId == VK_FEED_USER)
return 1;
ProtoChainSend(hContact, PSS_AUTHREQUEST, 0, (LPARAM)TranslateT("Please authorize me to add you to my friend list."));
return 0;
@@ -959,8 +960,8 @@ INT_PTR CVkProto::SvcWipeNonFriendContacts(WPARAM, LPARAM)
INT_PTR __cdecl CVkProto::SvcDeleteFriend(WPARAM hContact, LPARAM flag)
{
debugLogA("CVkProto::SvcDeleteFriend");
- LONG userID = getDword(hContact, "ID", VK_INVALID_USER);
- if (!IsOnline() || userID == VK_INVALID_USER || userID == VK_FEED_USER)
+ VKUserID_t iUserId = ReadVKUserID(hContact);
+ if (!IsOnline() || iUserId == VK_INVALID_USER || iUserId == VK_FEED_USER)
return 1;
if (flag == 0) {
@@ -971,7 +972,7 @@ INT_PTR __cdecl CVkProto::SvcDeleteFriend(WPARAM hContact, LPARAM flag)
return 1;
}
Push(new AsyncHttpRequest(this, REQUEST_GET, "/method/friends.delete.json", true, &CVkProto::OnReceiveDeleteFriend)
- << INT_PARAM("user_id", userID))->pUserInfo = new CVkSendMsgParam(hContact);
+ << INT_PARAM("user_id", iUserId))->pUserInfo = new CVkSendMsgParam(hContact);
return 0;
}
@@ -987,25 +988,25 @@ void CVkProto::OnReceiveDeleteFriend(NETLIBHTTPREQUEST *reply, AsyncHttpRequest
CMStringW wszNick(db_get_wsm(param->hContact, m_szModuleName, "Nick"));
if (wszNick.IsEmpty())
wszNick = TranslateT("(Unknown contact)");
- CMStringW msgformat, msg;
+ CMStringW wszMsgFormat, wszMsg;
if (jnResponse["success"].as_bool()) {
if (jnResponse["friend_deleted"].as_bool())
- msgformat = TranslateT("User %s was deleted from your friend list");
+ wszMsgFormat = TranslateT("User %s was deleted from your friend list");
else if (jnResponse["out_request_deleted"].as_bool())
- msgformat = TranslateT("Your request to the user %s was deleted");
+ wszMsgFormat = TranslateT("Your request to the user %s was deleted");
else if (jnResponse["in_request_deleted"].as_bool())
- msgformat = TranslateT("Friend request from the user %s declined");
+ wszMsgFormat = TranslateT("Friend request from the user %s declined");
else if (jnResponse["suggestion_deleted"].as_bool())
- msgformat = TranslateT("Friend request suggestion for the user %s deleted");
+ wszMsgFormat = TranslateT("Friend request suggestion for the user %s deleted");
- msg.AppendFormat(msgformat, wszNick.c_str());
- MsgPopup(param->hContact, msg, wszNick);
+ wszMsg.AppendFormat(wszMsgFormat, wszNick.c_str());
+ MsgPopup(param->hContact, wszMsg, wszNick);
setByte(param->hContact, "Auth", 1);
}
else {
- msg = TranslateT("User or request was not deleted");
- MsgPopup(param->hContact, msg, wszNick);
+ wszMsg = TranslateT("User or request was not deleted");
+ MsgPopup(param->hContact, wszMsg, wszNick);
}
}
}
@@ -1019,11 +1020,11 @@ void CVkProto::OnReceiveDeleteFriend(NETLIBHTTPREQUEST *reply, AsyncHttpRequest
INT_PTR __cdecl CVkProto::SvcBanUser(WPARAM hContact, LPARAM)
{
debugLogA("CVkProto::SvcBanUser");
- LONG userID = getDword(hContact, "ID", VK_INVALID_USER);
- if (!IsOnline() || userID == VK_INVALID_USER || userID == VK_FEED_USER)
+ VKUserID_t iUserId = ReadVKUserID(hContact);
+ if (!IsOnline() || iUserId == VK_INVALID_USER || iUserId == VK_FEED_USER)
return 1;
- CMStringA code(FORMAT, "var userID=\"%d\";API.account.banUser({\"user_id\":userID});", userID);
+ CMStringA code(FORMAT, "var userID=\"%d\";API.account.banUser({\"user_id\":userID});", iUserId);
CMStringW wszVarWarning;
if (m_vkOptions.bReportAbuse) {
@@ -1077,8 +1078,8 @@ INT_PTR __cdecl CVkProto::SvcBanUser(WPARAM hContact, LPARAM)
INT_PTR __cdecl CVkProto::SvcReportAbuse(WPARAM hContact, LPARAM)
{
debugLogA("CVkProto::SvcReportAbuse");
- LONG userID = getDword(hContact, "ID", VK_INVALID_USER);
- if (!IsOnline() || userID == VK_INVALID_USER || userID == VK_FEED_USER)
+ VKUserID_t iUserId = ReadVKUserID(hContact);
+ if (!IsOnline() || iUserId == VK_INVALID_USER || iUserId == VK_FEED_USER)
return 1;
CMStringW wszNick(db_get_wsm(hContact, m_szModuleName, "Nick")),
@@ -1087,7 +1088,7 @@ INT_PTR __cdecl CVkProto::SvcReportAbuse(WPARAM hContact, LPARAM)
return 1;
Push(new AsyncHttpRequest(this, REQUEST_GET, "/method/users.report.json", true, &CVkProto::OnReceiveSmth)
- << INT_PARAM("user_id", userID)
+ << INT_PARAM("user_id", iUserId)
<< CHAR_PARAM("type", "spam"));
return 0;
@@ -1114,14 +1115,14 @@ INT_PTR __cdecl CVkProto::SvcVisitProfile(WPARAM hContact, LPARAM)
return 0;
}
- LONG userID = getDword(hContact, "ID", VK_INVALID_USER);
+ VKUserID_t iUserId = ReadVKUserID(hContact);
ptrW wszDomain(db_get_wsa(hContact, m_szModuleName, "domain"));
CMStringW wszUrl("https://vk.com/");
if (wszDomain)
wszUrl.Append(wszDomain);
else
- wszUrl.AppendFormat(L"id%i", userID);
+ wszUrl.AppendFormat(L"id%i", iUserId);
Utils_OpenUrlW(wszUrl);
return 0;
diff --git a/protocols/VKontakte/src/vk_wallpost.cpp b/protocols/VKontakte/src/vk_wallpost.cpp
index 28fe3fcbd9..a96f3d2556 100644
--- a/protocols/VKontakte/src/vk_wallpost.cpp
+++ b/protocols/VKontakte/src/vk_wallpost.cpp
@@ -36,12 +36,12 @@ void CVkProto::WallPost(MCONTACT hContact, wchar_t *pwszMsg, wchar_t *pwszUrl, b
if (!IsOnline() || (IsEmpty(pwszMsg) && IsEmpty(pwszUrl)))
return;
- LONG userID = hContact ? m_myUserId : getDword(hContact, "ID", VK_INVALID_USER);
- if (userID == VK_INVALID_USER || userID == VK_FEED_USER)
+ VKUserID_t iUserId = hContact ? m_iMyUserId : ReadVKUserID(hContact);
+ if (iUserId == VK_INVALID_USER || iUserId == VK_FEED_USER)
return;
AsyncHttpRequest *pReq = new AsyncHttpRequest(this, REQUEST_POST, "/method/wall.post.json", true, &CVkProto::OnReceiveSmth);
- pReq << INT_PARAM("owner_id", userID) << INT_PARAM("friends_only", bFriendsOnly ? 1 : 0);
+ pReq << INT_PARAM("owner_id", iUserId) << INT_PARAM("friends_only", bFriendsOnly ? 1 : 0);
if (!IsEmpty(pwszMsg))
pReq << WCHAR_PARAM("message", pwszMsg);