diff options
author | ElzorFox <elzorfox@ya.ru> | 2017-01-10 13:17:53 +0500 |
---|---|---|
committer | ElzorFox <elzorfox@ya.ru> | 2017-01-10 13:17:53 +0500 |
commit | 77cccf9d4b13d9fad437eaf6361cec016a4ce27c (patch) | |
tree | a18f22cccead332e7eca0ec5418c5dd8f2348c29 /protocols/VKontakte/src/vk_thread.cpp | |
parent | f124c479945d8d0db785b4259a2f41e2998fac73 (diff) |
VKontakte: no more write to db if oldValue == newValue
Diffstat (limited to 'protocols/VKontakte/src/vk_thread.cpp')
-rw-r--r-- | protocols/VKontakte/src/vk_thread.cpp | 88 |
1 files changed, 38 insertions, 50 deletions
diff --git a/protocols/VKontakte/src/vk_thread.cpp b/protocols/VKontakte/src/vk_thread.cpp index 8e1c6b2b6a..747348fd7a 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()) {
- setWString(hContact, "FirstName", wszValue);
+ DBSetWString(hContact, "FirstName", wszValue);
wszNick.Append(wszValue);
wszNick.AppendChar(' ');
}
wszValue = jnItem["last_name"].as_mstring();
if (!wszValue.IsEmpty()) {
- setWString(hContact, "LastName", wszValue);
+ DBSetWString(hContact, "LastName", wszValue);
wszNick.Append(wszValue);
}
if (!wszNick.IsEmpty())
- setWString(hContact, "Nick", wszNick);
+ DBSetWString(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)
- setByte(hContact, "Gender", sex == 2 ? 'M' : 'F');
+ DBSetByte(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)
- setWord(hContact, "BirthYear", y);
- setByte(hContact, "BirthDay", d);
- setByte(hContact, "BirthMonth", m);
+ DBSetWord(hContact, "BirthYear", y);
+ DBSetByte(hContact, "BirthDay", d);
+ DBSetByte(hContact, "BirthMonth", m);
}
}
@@ -342,17 +342,16 @@ 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);
- db_set_w(hContact, "BuddyExpectator", "LastStatus", ID_STATUS_ONLINE);
+ DBSetDWord(hContact, "BuddyExpectator", "LastStatus", ID_STATUS_ONLINE);
}
}
int iNewStatus = (jnItem["online"].as_int() == 0) ? ID_STATUS_OFFLINE : ID_STATUS_ONLINE;
- if (getWord(hContact, "Status", ID_STATUS_OFFLINE) != iNewStatus)
- setWord(hContact, "Status", iNewStatus);
+ DBSetWord(hContact, "Status", iNewStatus, ID_STATUS_OFFLINE);
if (iNewStatus == ID_STATUS_ONLINE) {
db_set_dw(hContact, "BuddyExpectator", "LastSeen", (DWORD)time(NULL));
- db_set_dw(hContact, "BuddyExpectator", "LastStatus", ID_STATUS_ONLINE);
+ DBSetDWord(hContact, "BuddyExpectator", "LastStatus", ID_STATUS_ONLINE);
int online_app = _wtoi(jnItem["online_app"].as_mstring());
int online_mobile = jnItem["online_mobile"].as_int();
@@ -368,32 +367,27 @@ MCONTACT CVkProto::SetContactInfo(const JSONNode &jnItem, bool flag, bool self) SetMirVer(hContact, -1); // unset MinVer
if ((iValue = jnItem["timezone"].as_int()) != 0)
- setByte(hContact, "Timezone", iValue * -2);
+ DBSetByte(hContact, "Timezone", iValue * -2);
wszValue = jnItem["mobile_phone"].as_mstring();
if (!wszValue.IsEmpty())
- setWString(hContact, "Cellular", wszValue);
+ DBSetWString(hContact, "Cellular", wszValue);
wszValue = jnItem["home_phone"].as_mstring();
if (!wszValue.IsEmpty())
- setWString(hContact, "Phone", wszValue);
+ DBSetWString(hContact, "Phone", wszValue);
wszValue = jnItem["status"].as_mstring();
- 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);
+ DBSetWString(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 (wszListeningTo != wszOldListeningTo) {
- setWString(hContact, "ListeningTo", wszListeningTo);
- setWString(hContact, "AudioUrl", jnAudio["url"].as_mstring());
- }
+ if (DBSetWString(hContact, "ListeningTo", wszListeningTo))
+ DBSetWString(hContact, "AudioUrl", jnAudio["url"].as_mstring());
}
else if (wszValue[0] == wchar_t(9835) && wszValue.GetLength() > 2) {
- setWString(hContact, "ListeningTo", &(wszValue.GetBuffer())[2]);
+ DBSetWString(hContact, "ListeningTo", &(wszValue.GetBuffer())[2]);
db_unset(hContact, m_szModuleName, "AudioUrl");
}
else {
@@ -405,21 +399,21 @@ MCONTACT CVkProto::SetContactInfo(const JSONNode &jnItem, bool flag, bool self) if (jnCountry) {
wszValue = jnCountry["title"].as_mstring();
if (!wszValue.IsEmpty())
- setWString(hContact, "Country", wszValue);
+ DBSetWString(hContact, "Country", wszValue);
}
const JSONNode &jnCity = jnItem["city"];
if (jnCity) {
wszValue = jnCity["title"].as_mstring();
if (!wszValue.IsEmpty())
- setWString(hContact, "City", wszValue);
+ DBSetWString(hContact, "City", wszValue);
}
// MaritalStatus
BYTE cMaritalStatus[] = {0, 10, 11, 12, 20, 70, 50, 60, 80};
if (jnItem["relation"] && jnItem["relation"].as_int() < _countof(cMaritalStatus))
- setByte(hContact, "MaritalStatus", cMaritalStatus[jnItem["relation"].as_int()]);
+ DBSetByte(hContact, "MaritalStatus", cMaritalStatus[jnItem["relation"].as_int()]);
// interests, activities, music, movies, tv, books, games, quotes
CVKInteres vkInteres[] = {
@@ -443,8 +437,8 @@ MCONTACT CVkProto::SetContactInfo(const JSONNode &jnItem, bool flag, bool self) CMStringA InteresCat(FORMAT, "Interest%dCat", iInteres);
CMStringA InteresText(FORMAT, "Interest%dText", iInteres);
- setWString(hContact, InteresCat, vkInteres[i].pwszTranslate);
- setWString(hContact, InteresText, wszValue);
+ DBSetWString(hContact, InteresCat, vkInteres[i].pwszTranslate);
+ DBSetWString(hContact, InteresText, wszValue);
iInteres++;
@@ -466,14 +460,14 @@ MCONTACT CVkProto::SetContactInfo(const JSONNode &jnItem, bool flag, bool self) wszValue = jnItem["about"].as_mstring();
if (!wszValue.IsEmpty())
- setWString(hContact, "About", wszValue);
+ DBSetWString(hContact, "About", wszValue);
wszValue = jnItem["domain"].as_mstring();
if (!wszValue.IsEmpty()) {
- setWString(hContact, "domain", wszValue);
+ DBSetWString(hContact, "domain", wszValue);
CMStringW wszUrl("https://vk.com/");
wszUrl.Append(wszValue);
- setWString(hContact, "Homepage", wszUrl);
+ DBSetWString(hContact, "Homepage", wszUrl);
}
return hContact;
@@ -673,25 +667,24 @@ void CVkProto::OnReceiveGroupInfo(NETLIBHTTPREQUEST *reply, AsyncHttpRequest *pR wszValue = jnItem["name"].as_mstring();
if (!wszValue.IsEmpty())
- setWString(hContact, "Nick", wszValue);
+ DBSetWString(hContact, "Nick", wszValue);
- if (getWord(hContact, "Status", ID_STATUS_OFFLINE) != ID_STATUS_ONLINE)
- setWord(hContact, "Status", ID_STATUS_ONLINE);
+ DBSetWord(hContact, "Status", ID_STATUS_ONLINE, ID_STATUS_OFFLINE);
- setByte(hContact, "Auth", !bIsMember);
- setByte(hContact, "friend", bIsMember);
- setByte(hContact, "IsGroup", 1);
+ DBSetByte(hContact, "Auth", !bIsMember);
+ DBSetByte(hContact, "friend", bIsMember);
+ DBSetByte(hContact, "IsGroup", 1);
wszValue = jnItem["screen_name"].as_mstring();
if (!wszValue.IsEmpty()) {
- setWString(hContact, "domain", wszValue);
+ DBSetWString(hContact, "domain", wszValue);
wszValue = L"https://vk.com/" + wszValue;
- setWString(hContact, "Homepage", wszValue);
+ DBSetWString(hContact, "Homepage", wszValue);
}
wszValue = jnItem["description"].as_mstring();
if (!wszValue.IsEmpty())
- setWString(hContact, "About", wszValue);
+ DBSetWString(hContact, "About", wszValue);
wszValue = jnItem["photo_100"].as_mstring();
if (!wszValue.IsEmpty()) {
@@ -700,21 +693,16 @@ void CVkProto::OnReceiveGroupInfo(NETLIBHTTPREQUEST *reply, AsyncHttpRequest *pR }
wszValue = jnItem["status"].as_mstring();
- CMStringW wszOldStatus(ptrW(db_get_wsa(hContact, "CList", "StatusMsg")));
- if (wszValue != wszOldStatus)
- db_set_ws(hContact, "CList", "StatusMsg", wszValue);
+ DBSetWString(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 (wszListeningTo != wszOldListeningTo) {
- setWString(hContact, "ListeningTo", wszListeningTo);
- setWString(hContact, "AudioUrl", jnAudio["url"].as_mstring());
- }
+ if (DBSetWString(hContact, "ListeningTo", wszListeningTo))
+ DBSetWString(hContact, "AudioUrl", jnAudio["url"].as_mstring());
}
else if (wszValue[0] == wchar_t(9835) && wszValue.GetLength() > 2) {
- setWString(hContact, "ListeningTo", &(wszValue.GetBuffer())[2]);
+ DBSetWString(hContact, "ListeningTo", &(wszValue.GetBuffer())[2]);
db_unset(hContact, m_szModuleName, "AudioUrl");
}
else {
@@ -770,7 +758,7 @@ void CVkProto::OnReceiveFriends(NETLIBHTTPREQUEST *reply, AsyncHttpRequest *pReq continue;
arContacts.remove((HANDLE)hContact);
- setByte(hContact, "Auth", 0);
+ DBSetByte(hContact, "Auth", 0);
}
if (bCleanContacts)
|