From 7aed63a94c430094a66006ed459bfb8cbd7ff5f2 Mon Sep 17 00:00:00 2001 From: ElzorFox Date: Wed, 11 Jan 2017 01:18:09 +0500 Subject: Revert "VKontakte: no more write to db if oldValue == newValue" This reverts commit 77cccf9d4b13d9fad437eaf6361cec016a4ce27c. --- protocols/VKontakte/src/misc.cpp | 67 +------------------------- protocols/VKontakte/src/vk_chats.cpp | 14 +++--- protocols/VKontakte/src/vk_feed.cpp | 4 +- protocols/VKontakte/src/vk_proto.cpp | 2 +- protocols/VKontakte/src/vk_proto.h | 10 ---- protocols/VKontakte/src/vk_status.cpp | 6 +-- protocols/VKontakte/src/vk_thread.cpp | 88 ++++++++++++++++++++--------------- 7 files changed, 65 insertions(+), 126 deletions(-) (limited to 'protocols/VKontakte/src') diff --git a/protocols/VKontakte/src/misc.cpp b/protocols/VKontakte/src/misc.cpp index 4637498c33..f8f3bec513 100644 --- a/protocols/VKontakte/src/misc.cpp +++ b/protocols/VKontakte/src/misc.cpp @@ -1334,7 +1334,7 @@ void CVkProto::SetInvisible(MCONTACT hContact) if (getWord(hContact, "Status", ID_STATUS_OFFLINE) == ID_STATUS_OFFLINE) { setWord(hContact, "Status", ID_STATUS_INVISIBLE); SetMirVer(hContact, 1); - DBSetDWord(hContact, "BuddyExpectator", "LastStatus", ID_STATUS_INVISIBLE); + db_set_dw(hContact, "BuddyExpectator", "LastStatus", ID_STATUS_INVISIBLE); debugLogA("CVkProto::SetInvisible %d set ID_STATUS_INVISIBLE", getDword(hContact, "ID", VK_INVALID_USER)); } time_t now = time(NULL); @@ -1484,68 +1484,3 @@ void CVkProto::AddVkDeactivateEvent(MCONTACT hContact, CMStringW& wszType) db_event_add(hContact, &dbei); } -///////////////////////////////////////////////////////////////////////////////////////// - -bool CVkProto::DBSetByte(MCONTACT hContact, LPCSTR szKey, BYTE bValue, BYTE bDefaultValue) -{ - return DBSetByte(hContact, m_szModuleName, szKey, bValue, bDefaultValue); -} - -bool CVkProto::DBSetByte(MCONTACT hContact, LPCSTR szModuleName, LPCSTR szKey, BYTE bValue, BYTE bDefaultValue) -{ - DWORD bOldValue = db_get_b(hContact, szModuleName, szKey, bDefaultValue); - - if (bOldValue == bValue) - return false; - - db_set_b(hContact, szModuleName, szKey, bValue); - return true; -} - -bool CVkProto::DBSetWord(MCONTACT hContact, LPCSTR szKey, WORD wValue, WORD wDefaultValue) -{ - return DBSetWord(hContact, m_szModuleName, szKey, wValue, wDefaultValue); -} - -bool CVkProto::DBSetWord(MCONTACT hContact, LPCSTR szModuleName, LPCSTR szKey, WORD wValue, WORD wDefaultValue) -{ - DWORD wOldValue = db_get_w(hContact, szModuleName, szKey, wDefaultValue); - - if (wOldValue == wValue) - return false; - - db_set_w(hContact, szModuleName, szKey, wValue); - return true; -} - -bool CVkProto::DBSetDWord(MCONTACT hContact, LPCSTR szKey, DWORD dwValue, DWORD dwDefaultValue) -{ - return DBSetDWord(hContact, m_szModuleName, szKey, dwValue, dwDefaultValue); -} - -bool CVkProto::DBSetDWord(MCONTACT hContact, LPCSTR szModuleName, LPCSTR szKey, DWORD dwValue, DWORD dwDefaultValue) -{ - DWORD dwOldValue = db_get_dw(hContact, szModuleName, szKey, dwDefaultValue); - - if (dwOldValue == dwValue) - return false; - - db_set_dw(hContact, szModuleName, szKey, dwValue); - return true; -} - -bool CVkProto::DBSetWString(MCONTACT hContact, LPCSTR szKey, LPCWSTR wszValue) -{ - return DBSetWString(hContact, m_szModuleName, szKey, wszValue); -} - -bool CVkProto::DBSetWString(MCONTACT hContact, LPCSTR szModuleName, LPCSTR szKey, LPCWSTR wszValue) -{ - CMStringW wszOldValue(ptrW(db_get_wsa(hContact, szModuleName, szKey))); - - if (wszOldValue == wszValue) - return false; - - db_set_ws(hContact, szModuleName, szKey, wszValue); - return true; -} \ No newline at end of file diff --git a/protocols/VKontakte/src/vk_chats.cpp b/protocols/VKontakte/src/vk_chats.cpp index e5b9b3bc6c..79ee8ff0ed 100644 --- a/protocols/VKontakte/src/vk_chats.cpp +++ b/protocols/VKontakte/src/vk_chats.cpp @@ -68,7 +68,7 @@ CVkChatInfo* CVkProto::AppendChat(int id, const JSONNode &jnDlg) Chat_GetInfo(&gci); c->m_hContact = gci.hContact; - DBSetWString(gci.hContact, "Nick", wszTitle); + setWString(gci.hContact, "Nick", wszTitle); m_chats.insert(c); for (int i = _countof(sttStatuses)-1; i >= 0; i--) @@ -77,7 +77,7 @@ CVkChatInfo* CVkProto::AppendChat(int id, const JSONNode &jnDlg) setDword(gci.hContact, "vk_chat_id", id); CMStringW wszHomepage(FORMAT, L"https://vk.com/im?sel=c%d", id); - DBSetWString(gci.hContact, "Homepage", wszHomepage); + setWString(gci.hContact, "Homepage", wszHomepage); db_unset(gci.hContact, m_szModuleName, "off"); @@ -233,9 +233,9 @@ void CVkProto::OnReceiveChatInfo(NETLIBHTTPREQUEST *reply, AsyncHttpRequest *pRe continue; hContact = SetContactInfo(jnUser, true); - DBSetByte(hContact, "CList", "Hidden", 1); - DBSetByte(hContact, "CList", "NotOnList", 1); - DBSetDWord(hContact, "Ignore", "Mask1", 0); + db_set_b(hContact, "CList", "Hidden", 1); + db_set_b(hContact, "CList", "NotOnList", 1); + db_set_dw(hContact, "Ignore", "Mask1", 0); } const JSONNode &jnMsgs = jnResponse["msgs"]; @@ -272,7 +272,7 @@ void CVkProto::SetChatTitle(CVkChatInfo *cc, LPCWSTR wszTopic) return; cc->m_wszTopic = mir_wstrdup(wszTopic); - DBSetWString(cc->m_hContact, "Nick", wszTopic); + setWString(cc->m_hContact, "Nick", wszTopic); Chat_ChangeSessionName(m_szModuleName, cc->m_wszId, wszTopic); } @@ -794,7 +794,7 @@ void CVkProto::NickMenuHook(CVkChatInfo *cc, GCHOOK *gch) Chat_Event(&gce); cu->m_wszNick = mir_wstrdup(wszNewNick); - DBSetWString(cc->m_hContact, CMStringA(FORMAT, "nick%d", cu->m_uid), wszNewNick); + setWString(cc->m_hContact, CMStringA(FORMAT, "nick%d", cu->m_uid), wszNewNick); } break; diff --git a/protocols/VKontakte/src/vk_feed.cpp b/protocols/VKontakte/src/vk_feed.cpp index 85dcdd5343..ac23773168 100644 --- a/protocols/VKontakte/src/vk_feed.cpp +++ b/protocols/VKontakte/src/vk_feed.cpp @@ -40,8 +40,10 @@ void CVkProto::AddFeedSpecialUser() setWString(hContact, "Homepage", L"https://vk.com/feed"); } - DBSetWord(hContact, "Status", ID_STATUS_ONLINE, ID_STATUS_OFFLINE); + if (getWord(hContact, "Status") != ID_STATUS_ONLINE) + setWord(hContact, "Status", ID_STATUS_ONLINE); SetMirVer(hContact, 7); + } void CVkProto::AddFeedEvent(CVKNewsItem& vkNewsItem) diff --git a/protocols/VKontakte/src/vk_proto.cpp b/protocols/VKontakte/src/vk_proto.cpp index f8dec80402..94bef34949 100644 --- a/protocols/VKontakte/src/vk_proto.cpp +++ b/protocols/VKontakte/src/vk_proto.cpp @@ -73,7 +73,7 @@ CVkProto::CVkProto(const char *szModuleName, const wchar_t *pwszUserName) : Clist_GroupCreate(NULL, m_vkOptions.pwszDefaultGroup); CMStringA szListeningTo(FORMAT, "%sEnabled", m_szModuleName); - DBSetByte(NULL, "ListeningTo", szListeningTo, m_vkOptions.iMusicSendMetod == 0 ? 0 : 1); + db_set_b(NULL, "ListeningTo", szListeningTo, m_vkOptions.iMusicSendMetod == 0 ? 0 : 1); delSetting("InviteGroupIds"); diff --git a/protocols/VKontakte/src/vk_proto.h b/protocols/VKontakte/src/vk_proto.h index 215671eeaf..84167b2a4f 100644 --- a/protocols/VKontakte/src/vk_proto.h +++ b/protocols/VKontakte/src/vk_proto.h @@ -353,16 +353,6 @@ private: void SetInvisible(MCONTACT hContact); CMStringW RemoveBBC(CMStringW& wszSrc); void AddVkDeactivateEvent(MCONTACT hContact, CMStringW & wszType); - - bool DBSetByte(MCONTACT hContact, LPCSTR szKey, BYTE bValue, BYTE bDefaultValue = 0); - bool DBSetByte(MCONTACT hContact, LPCSTR szModuleName, LPCSTR szKey, BYTE bValue, BYTE bDefaultValue = 0); - bool DBSetWord(MCONTACT hContact, LPCSTR szKey, WORD wValue, WORD wDefaultValue = 0); - bool DBSetWord(MCONTACT hContact, LPCSTR szModuleName, LPCSTR szKey, WORD wValue, WORD wDefaultValue = 0); - bool DBSetDWord(MCONTACT hContact, LPCSTR szKey, DWORD dwValue, DWORD dwDefaultValue = 0); - bool DBSetDWord(MCONTACT hContact, LPCSTR szModuleName, LPCSTR szKey, DWORD dwValue, DWORD dwDefaultValue = 0); - bool DBSetWString(MCONTACT hContact, LPCSTR szKey, LPCWSTR wszValue); - bool DBSetWString(MCONTACT hContact, LPCSTR szModuleName, LPCSTR szKey, LPCWSTR wszValue); - void InitQueue(); void UninitQueue(); void ExecuteRequest(AsyncHttpRequest*); diff --git a/protocols/VKontakte/src/vk_status.cpp b/protocols/VKontakte/src/vk_status.cpp index f8b8558ed1..d7503923df 100644 --- a/protocols/VKontakte/src/vk_status.cpp +++ b/protocols/VKontakte/src/vk_status.cpp @@ -144,7 +144,7 @@ void CVkProto::OnReceiveStatusMsg(NETLIBHTTPREQUEST *reply, AsyncHttpRequest *pR return; RetrieveStatusMsg(wszNewStatusMsg); - DBSetWString(NULL, "OldStatusMsg", pwszOldStatusMsg); + setWString("OldStatusMsg", pwszOldStatusMsg); } void CVkProto::OnReceiveStatus(NETLIBHTTPREQUEST *reply, AsyncHttpRequest *pReq) @@ -161,7 +161,7 @@ void CVkProto::OnReceiveStatus(NETLIBHTTPREQUEST *reply, AsyncHttpRequest *pReq) if (!jnAudio) { CMStringW wszStatusText(jnResponse["text"].as_mstring()); if (wszStatusText[0] != wchar_t(9835)) - DBSetWString(NULL, "OldStatusMsg", wszStatusText); + setWString("OldStatusMsg", wszStatusText); } } @@ -245,7 +245,7 @@ INT_PTR __cdecl CVkProto::SvcSetListeningTo(WPARAM, LPARAM lParam) wszListeningTo.Format(L"%s - %s", pliInfo->ptszArtist ? pliInfo->ptszArtist : L"", pliInfo->ptszTitle ? pliInfo->ptszTitle : L""); - DBSetWString(NULL ,"ListeningTo", wszListeningTo); + setWString("ListeningTo", wszListeningTo); } RetrieveStatusMusic(wszListeningTo); return 0; diff --git a/protocols/VKontakte/src/vk_thread.cpp b/protocols/VKontakte/src/vk_thread.cpp index 747348fd7a..8e1c6b2b6a 100644 --- a/protocols/VKontakte/src/vk_thread.cpp +++ b/protocols/VKontakte/src/vk_thread.cpp @@ -287,19 +287,19 @@ MCONTACT CVkProto::SetContactInfo(const JSONNode &jnItem, bool flag, bool self) wszValue = jnItem["first_name"].as_mstring(); if (!wszValue.IsEmpty()) { - DBSetWString(hContact, "FirstName", wszValue); + setWString(hContact, "FirstName", wszValue); wszNick.Append(wszValue); wszNick.AppendChar(' '); } wszValue = jnItem["last_name"].as_mstring(); if (!wszValue.IsEmpty()) { - DBSetWString(hContact, "LastName", wszValue); + setWString(hContact, "LastName", wszValue); wszNick.Append(wszValue); } if (!wszNick.IsEmpty()) - DBSetWString(hContact, "Nick", wszNick); + setWString(hContact, "Nick", wszNick); wszValue = jnItem["deactivated"].as_mstring(); CMStringW wszOldDeactivated(ptrW(db_get_wsa(hContact, m_szModuleName, "Deactivated"))); @@ -316,7 +316,7 @@ MCONTACT CVkProto::SetContactInfo(const JSONNode &jnItem, bool flag, bool self) int sex = jnItem["sex"].as_int(); if (sex) - DBSetByte(hContact, "Gender", sex == 2 ? 'M' : 'F'); + setByte(hContact, "Gender", sex == 2 ? 'M' : 'F'); wszValue = jnItem["bdate"].as_mstring(); if (!wszValue.IsEmpty()) { @@ -324,9 +324,9 @@ MCONTACT CVkProto::SetContactInfo(const JSONNode &jnItem, bool flag, bool self) iReadCount = swscanf(wszValue, L"%d.%d.%d", &d, &m, &y); if (iReadCount > 1) { if (iReadCount == 3) - DBSetWord(hContact, "BirthYear", y); - DBSetByte(hContact, "BirthDay", d); - DBSetByte(hContact, "BirthMonth", m); + setWord(hContact, "BirthYear", y); + setByte(hContact, "BirthDay", d); + setByte(hContact, "BirthMonth", m); } } @@ -342,16 +342,17 @@ MCONTACT CVkProto::SetContactInfo(const JSONNode &jnItem, bool flag, bool self) int iOldLastSeen = db_get_dw(hContact, "BuddyExpectator", "LastSeen"); if (iLastSeen && iLastSeen > iOldLastSeen) { db_set_dw(hContact, "BuddyExpectator", "LastSeen", (DWORD)iLastSeen); - DBSetDWord(hContact, "BuddyExpectator", "LastStatus", ID_STATUS_ONLINE); + db_set_w(hContact, "BuddyExpectator", "LastStatus", ID_STATUS_ONLINE); } } int iNewStatus = (jnItem["online"].as_int() == 0) ? ID_STATUS_OFFLINE : ID_STATUS_ONLINE; - DBSetWord(hContact, "Status", iNewStatus, ID_STATUS_OFFLINE); + if (getWord(hContact, "Status", ID_STATUS_OFFLINE) != iNewStatus) + setWord(hContact, "Status", iNewStatus); if (iNewStatus == ID_STATUS_ONLINE) { db_set_dw(hContact, "BuddyExpectator", "LastSeen", (DWORD)time(NULL)); - DBSetDWord(hContact, "BuddyExpectator", "LastStatus", ID_STATUS_ONLINE); + db_set_dw(hContact, "BuddyExpectator", "LastStatus", ID_STATUS_ONLINE); int online_app = _wtoi(jnItem["online_app"].as_mstring()); int online_mobile = jnItem["online_mobile"].as_int(); @@ -367,27 +368,32 @@ MCONTACT CVkProto::SetContactInfo(const JSONNode &jnItem, bool flag, bool self) SetMirVer(hContact, -1); // unset MinVer if ((iValue = jnItem["timezone"].as_int()) != 0) - DBSetByte(hContact, "Timezone", iValue * -2); + setByte(hContact, "Timezone", iValue * -2); wszValue = jnItem["mobile_phone"].as_mstring(); if (!wszValue.IsEmpty()) - DBSetWString(hContact, "Cellular", wszValue); + setWString(hContact, "Cellular", wszValue); wszValue = jnItem["home_phone"].as_mstring(); if (!wszValue.IsEmpty()) - DBSetWString(hContact, "Phone", wszValue); + setWString(hContact, "Phone", wszValue); wszValue = jnItem["status"].as_mstring(); - DBSetWString(hContact, hContact ? "CList" : m_szModuleName, "StatusMsg", wszValue); + CMStringW wszOldStatus(ptrW(db_get_wsa(hContact, hContact ? "CList" : m_szModuleName, "StatusMsg"))); + if (wszValue != wszOldStatus) + db_set_ws(hContact, hContact ? "CList" : m_szModuleName, "StatusMsg", wszValue); + CMStringW wszOldListeningTo(ptrW(db_get_wsa(hContact, m_szModuleName, "ListeningTo"))); const JSONNode &jnAudio = jnItem["status_audio"]; if (jnAudio) { CMStringW wszListeningTo(FORMAT, L"%s - %s", jnAudio["artist"].as_mstring(), jnAudio["title"].as_mstring()); - if (DBSetWString(hContact, "ListeningTo", wszListeningTo)) - DBSetWString(hContact, "AudioUrl", jnAudio["url"].as_mstring()); + if (wszListeningTo != wszOldListeningTo) { + setWString(hContact, "ListeningTo", wszListeningTo); + setWString(hContact, "AudioUrl", jnAudio["url"].as_mstring()); + } } else if (wszValue[0] == wchar_t(9835) && wszValue.GetLength() > 2) { - DBSetWString(hContact, "ListeningTo", &(wszValue.GetBuffer())[2]); + setWString(hContact, "ListeningTo", &(wszValue.GetBuffer())[2]); db_unset(hContact, m_szModuleName, "AudioUrl"); } else { @@ -399,21 +405,21 @@ MCONTACT CVkProto::SetContactInfo(const JSONNode &jnItem, bool flag, bool self) if (jnCountry) { wszValue = jnCountry["title"].as_mstring(); if (!wszValue.IsEmpty()) - DBSetWString(hContact, "Country", wszValue); + setWString(hContact, "Country", wszValue); } const JSONNode &jnCity = jnItem["city"]; if (jnCity) { wszValue = jnCity["title"].as_mstring(); if (!wszValue.IsEmpty()) - DBSetWString(hContact, "City", wszValue); + setWString(hContact, "City", wszValue); } // MaritalStatus BYTE cMaritalStatus[] = {0, 10, 11, 12, 20, 70, 50, 60, 80}; if (jnItem["relation"] && jnItem["relation"].as_int() < _countof(cMaritalStatus)) - DBSetByte(hContact, "MaritalStatus", cMaritalStatus[jnItem["relation"].as_int()]); + setByte(hContact, "MaritalStatus", cMaritalStatus[jnItem["relation"].as_int()]); // interests, activities, music, movies, tv, books, games, quotes CVKInteres vkInteres[] = { @@ -437,8 +443,8 @@ MCONTACT CVkProto::SetContactInfo(const JSONNode &jnItem, bool flag, bool self) CMStringA InteresCat(FORMAT, "Interest%dCat", iInteres); CMStringA InteresText(FORMAT, "Interest%dText", iInteres); - DBSetWString(hContact, InteresCat, vkInteres[i].pwszTranslate); - DBSetWString(hContact, InteresText, wszValue); + setWString(hContact, InteresCat, vkInteres[i].pwszTranslate); + setWString(hContact, InteresText, wszValue); iInteres++; @@ -460,14 +466,14 @@ MCONTACT CVkProto::SetContactInfo(const JSONNode &jnItem, bool flag, bool self) wszValue = jnItem["about"].as_mstring(); if (!wszValue.IsEmpty()) - DBSetWString(hContact, "About", wszValue); + setWString(hContact, "About", wszValue); wszValue = jnItem["domain"].as_mstring(); if (!wszValue.IsEmpty()) { - DBSetWString(hContact, "domain", wszValue); + setWString(hContact, "domain", wszValue); CMStringW wszUrl("https://vk.com/"); wszUrl.Append(wszValue); - DBSetWString(hContact, "Homepage", wszUrl); + setWString(hContact, "Homepage", wszUrl); } return hContact; @@ -667,24 +673,25 @@ void CVkProto::OnReceiveGroupInfo(NETLIBHTTPREQUEST *reply, AsyncHttpRequest *pR wszValue = jnItem["name"].as_mstring(); if (!wszValue.IsEmpty()) - DBSetWString(hContact, "Nick", wszValue); + setWString(hContact, "Nick", wszValue); - DBSetWord(hContact, "Status", ID_STATUS_ONLINE, ID_STATUS_OFFLINE); + if (getWord(hContact, "Status", ID_STATUS_OFFLINE) != ID_STATUS_ONLINE) + setWord(hContact, "Status", ID_STATUS_ONLINE); - DBSetByte(hContact, "Auth", !bIsMember); - DBSetByte(hContact, "friend", bIsMember); - DBSetByte(hContact, "IsGroup", 1); + setByte(hContact, "Auth", !bIsMember); + setByte(hContact, "friend", bIsMember); + setByte(hContact, "IsGroup", 1); wszValue = jnItem["screen_name"].as_mstring(); if (!wszValue.IsEmpty()) { - DBSetWString(hContact, "domain", wszValue); + setWString(hContact, "domain", wszValue); wszValue = L"https://vk.com/" + wszValue; - DBSetWString(hContact, "Homepage", wszValue); + setWString(hContact, "Homepage", wszValue); } wszValue = jnItem["description"].as_mstring(); if (!wszValue.IsEmpty()) - DBSetWString(hContact, "About", wszValue); + setWString(hContact, "About", wszValue); wszValue = jnItem["photo_100"].as_mstring(); if (!wszValue.IsEmpty()) { @@ -693,16 +700,21 @@ void CVkProto::OnReceiveGroupInfo(NETLIBHTTPREQUEST *reply, AsyncHttpRequest *pR } wszValue = jnItem["status"].as_mstring(); - DBSetWString(hContact, "CList", "StatusMsg", wszValue); + CMStringW wszOldStatus(ptrW(db_get_wsa(hContact, "CList", "StatusMsg"))); + if (wszValue != wszOldStatus) + db_set_ws(hContact, "CList", "StatusMsg", wszValue); + CMStringW wszOldListeningTo(ptrW(db_get_wsa(hContact, m_szModuleName, "ListeningTo"))); const JSONNode &jnAudio = jnItem["status_audio"]; if (jnAudio) { CMStringW wszListeningTo(FORMAT, L"%s - %s", jnAudio["artist"].as_mstring(), jnAudio["title"].as_mstring()); - if (DBSetWString(hContact, "ListeningTo", wszListeningTo)) - DBSetWString(hContact, "AudioUrl", jnAudio["url"].as_mstring()); + if (wszListeningTo != wszOldListeningTo) { + setWString(hContact, "ListeningTo", wszListeningTo); + setWString(hContact, "AudioUrl", jnAudio["url"].as_mstring()); + } } else if (wszValue[0] == wchar_t(9835) && wszValue.GetLength() > 2) { - DBSetWString(hContact, "ListeningTo", &(wszValue.GetBuffer())[2]); + setWString(hContact, "ListeningTo", &(wszValue.GetBuffer())[2]); db_unset(hContact, m_szModuleName, "AudioUrl"); } else { @@ -758,7 +770,7 @@ void CVkProto::OnReceiveFriends(NETLIBHTTPREQUEST *reply, AsyncHttpRequest *pReq continue; arContacts.remove((HANDLE)hContact); - DBSetByte(hContact, "Auth", 0); + setByte(hContact, "Auth", 0); } if (bCleanContacts) -- cgit v1.2.3