diff options
author | Sergey Bolhovskoy <elzorfox@ya.ru> | 2014-09-30 06:09:29 +0000 |
---|---|---|
committer | Sergey Bolhovskoy <elzorfox@ya.ru> | 2014-09-30 06:09:29 +0000 |
commit | 3f737e93021a4e08083a31e98e52ac110249461d (patch) | |
tree | 2710fae36700a397e27d8ed8ca2fe85b06483300 /protocols/VKontakte/src | |
parent | 0094bfe3eff72016d0a2dd039d93cc3ff3fcf273 (diff) |
VKontakte:
deduplicate for set contact info code
fix for re-set empty statusmsg
fix for day&month only bdate
some code cleaning
git-svn-id: http://svn.miranda-ng.org/main/trunk@10646 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'protocols/VKontakte/src')
-rw-r--r-- | protocols/VKontakte/src/vk_proto.h | 51 | ||||
-rw-r--r-- | protocols/VKontakte/src/vk_thread.cpp | 258 |
2 files changed, 135 insertions, 174 deletions
diff --git a/protocols/VKontakte/src/vk_proto.h b/protocols/VKontakte/src/vk_proto.h index 9347e5e909..ba5db0edc7 100644 --- a/protocols/VKontakte/src/vk_proto.h +++ b/protocols/VKontakte/src/vk_proto.h @@ -210,7 +210,12 @@ struct CVkProto : public PROTO<CVkProto> void InitMenus();
void UnInitMenus();
int __cdecl OnPreBuildContactMenu(WPARAM hContact, LPARAM);
-
+
+ //==== PopUps ========================================================================
+
+ void InitPopups(void);
+ void MsgPopup(MCONTACT hContact, const TCHAR *szMsg, const TCHAR *szTitle, bool err = false);
+
//==== Search ========================================================================
void __cdecl SearchBasicThread(void* id);
@@ -224,6 +229,7 @@ struct CVkProto : public PROTO<CVkProto> void RetrieveStatusMsg(const CMString &StatusMsg);
void RetrieveStatusMusic(const CMString &StatusMsg);
+ MCONTACT SetContactInfo(JSONNODE* Item, bool flag = false);
void RetrieveMyInfo(void);
void OnReceiveMyInfo(NETLIBHTTPREQUEST*, AsyncHttpRequest*);
void RetrieveUserInfo(LONG userId);
@@ -234,24 +240,31 @@ struct CVkProto : public PROTO<CVkProto> void MarkMessagesRead(const CMStringA &mids);
void MarkMessagesRead(const MCONTACT hContact);
+
void RetrieveMessagesByIds(const CMStringA &mids);
void RetrieveUnreadMessages();
void OnReceiveMessages(NETLIBHTTPREQUEST*, AsyncHttpRequest*);
void OnReceiveDlgs(NETLIBHTTPREQUEST*, AsyncHttpRequest*);
+ CMString GetAttachmentDescr(JSONNODE*);
+
void OnSendMessage(NETLIBHTTPREQUEST*, AsyncHttpRequest*);
+
void OnReceiveHistoryMessages(NETLIBHTTPREQUEST *reply, AsyncHttpRequest *pReq);
void GetHistoryDlg(MCONTACT hContact, int iLastMsg);
void GetHistoryDlgMessages(MCONTACT hContact, int iOffset, int iMaxCount, int lastcount);
+
void RetrievePollingInfo();
void OnReceivePollingInfo(NETLIBHTTPREQUEST*, AsyncHttpRequest*);
- void OnReceiveAuthRequest(NETLIBHTTPREQUEST*, AsyncHttpRequest*);
- void OnReceiveDeleteFriend(NETLIBHTTPREQUEST*, AsyncHttpRequest*);
-
void __cdecl PollingThread(void*);
int PollServer();
void PollUpdates(JSONNODE*);
void OnReceivePolling(NETLIBHTTPREQUEST*, AsyncHttpRequest*);
+ void OnReceiveAuthRequest(NETLIBHTTPREQUEST*, AsyncHttpRequest*);
+ void OnReceiveDeleteFriend(NETLIBHTTPREQUEST*, AsyncHttpRequest*);
+ void DBAddAuthRequest(const MCONTACT hContact);
+ MCONTACT MContactFromDbEvent(HANDLE hDbEvent);
+
void SetServerStatus(int);
void CreateNewChat(LPCSTR uids, LPCTSTR ptrszTitle);
@@ -335,7 +348,8 @@ private: void __cdecl SendMsgAck(void *param);
- bool m_bOnline,
+ bool m_prevError,
+ m_bOnline,
m_bHideChats,
m_bMesAsUnread,
m_bMarkReadOnReply,
@@ -348,14 +362,22 @@ private: m_bRemoveFromClist;
LONG m_myUserId;
- ptrA m_szAccessToken;
ptrT m_defaultGroup;
- ptrA m_pollingServer, m_pollingKey, m_pollingTs;
- HANDLE m_pollingConn, m_hPollingThread;
+ ptrA
+ m_pollingServer,
+ m_pollingKey,
+ m_pollingTs,
+ m_szAccessToken;
+
+ HANDLE
+ m_pollingConn,
+ m_hPollingThread,
+ m_hPopupClassError,
+ m_hPopupClassNotification;
+
ULONG m_msgId;
- bool m_prevError;
-
+
LIST<void> m_sendIds;
bool CheckMid(int guid);
@@ -377,13 +399,4 @@ private: void SetChatStatus(MCONTACT hContact, int iStatus);
CVkChatInfo* GetChatById(LPCTSTR ptszId);
INT_PTR __cdecl SvcCreateChat(WPARAM, LPARAM);
-
- CMString GetAttachmentDescr(JSONNODE*);
-
- HANDLE m_hPopupClassError, m_hPopupClassNotification;
- void InitPopups(void);
- void MsgPopup(MCONTACT hContact, const TCHAR *szMsg, const TCHAR *szTitle, bool err=false);
-
- void DBAddAuthRequest(const MCONTACT hContact);
- MCONTACT MContactFromDbEvent(HANDLE hDbEvent);
};
diff --git a/protocols/VKontakte/src/vk_thread.cpp b/protocols/VKontakte/src/vk_thread.cpp index f23d7ae880..aa563a843b 100644 --- a/protocols/VKontakte/src/vk_thread.cpp +++ b/protocols/VKontakte/src/vk_thread.cpp @@ -237,6 +237,100 @@ void CVkProto::OnReceiveMyInfo(NETLIBHTTPREQUEST *reply, AsyncHttpRequest *pReq) static char fieldsName[] = "id, first_name, last_name, photo_100, bdate, sex, timezone, contacts, online, status, about, domain";
+MCONTACT CVkProto::SetContactInfo(JSONNODE* pItem, bool flag)
+{
+ debugLogA("CVkProto::SetContactInfo");
+ if (pItem == NULL)
+ return -1;
+
+ LONG userid = json_as_int(json_get(pItem, "id"));
+ if (userid == 0)
+ return -1;
+
+ MCONTACT hContact;
+ if (userid == m_myUserId)
+ hContact = NULL;
+ else if ((hContact = FindUser(userid, flag)) == NULL)
+ return -1;
+
+ debugLogA("CVkProto::SetContactInfo %d %d", userid, hContact);
+
+ CMString tszNick, tszValue;
+ int iValue;
+
+ tszValue = json_as_string(json_get(pItem, "first_name"));
+ if (!tszValue.IsEmpty()) {
+ setTString(hContact, "FirstName", tszValue.GetBuffer());
+ tszNick.Append(tszValue);
+ tszNick.AppendChar(' ');
+ }
+
+ tszValue = json_as_string(json_get(pItem, "last_name"));
+ if (!tszValue.IsEmpty()) {
+ setTString(hContact, "LastName", tszValue.GetBuffer());
+ tszNick.Append(tszValue);
+ }
+
+ if (!tszNick.IsEmpty())
+ setTString(hContact, "Nick", tszNick);
+
+ int sex = json_as_int(json_get(pItem, "sex"));
+ if (sex)
+ setByte(hContact, "Gender", sex == 2 ? 'M' : 'F');
+
+ tszValue = json_as_string(json_get(pItem, "bdate"));
+ if (!tszNick.IsEmpty()) {
+ int d, m, y, iReadCount;
+ iReadCount = _stscanf(tszValue.GetBuffer(), L"%d.%d.%d", &d, &m, &y);
+ if (iReadCount> 1) {
+ setByte(hContact, "BirthDay", d);
+ setByte(hContact, "BirthMonth", m);
+ if (iReadCount == 3)
+ setWord(hContact, "BirthYear", y);
+ }
+ }
+
+ tszValue = json_as_string(json_get(pItem, "photo_100"));
+ if (!tszNick.IsEmpty()){
+ SetAvatarUrl(hContact, tszValue.GetBuffer());
+ ReloadAvatarInfo(hContact);
+ }
+
+ int iNewStatus = (json_as_int(json_get(pItem, "online")) == 0) ? ID_STATUS_OFFLINE : ID_STATUS_ONLINE;
+ if (getWord(hContact, "Status", 0) != iNewStatus)
+ setWord(hContact, "Status", iNewStatus);
+
+ if ((iValue = json_as_int(json_get(pItem, "timezone"))) != 0)
+ setByte(hContact, "Timezone", iValue * -2);
+
+ tszValue = json_as_string(json_get(pItem, "mobile_phone"));
+ if (!tszNick.IsEmpty())
+ setTString(hContact, "Cellular", tszValue.GetBuffer());
+ tszValue = json_as_string(json_get(pItem, "home_phone"));
+ if (!tszNick.IsEmpty())
+ setTString(hContact, "Phone", tszValue.GetBuffer());
+
+ tszValue = json_as_string(json_get(pItem, "status"));
+ CMString tszOldStatus(db_get_tsa(hContact, hContact ? "CList" : m_szModuleName, "StatusMsg"));
+ if (tszValue != tszOldStatus)
+ db_set_ts(hContact, hContact ? "CList" : m_szModuleName, "StatusMsg", tszValue.GetBuffer());
+
+ if ((hContact == NULL) && m_bOne){
+ setTString("OldStatusMsg", db_get_tsa(0, m_szModuleName, "StatusMsg"));
+ m_bOne = false;
+ }
+
+ tszValue = json_as_string(json_get(pItem, "about"));
+ if (!tszNick.IsEmpty())
+ setTString(hContact, "About", tszValue.GetBuffer());
+
+ tszValue = json_as_string(json_get(pItem, "domain"));
+ if (!tszNick.IsEmpty())
+ setTString(hContact, "domain", tszValue.GetBuffer());
+
+ return hContact;
+}
+
void CVkProto::RetrieveUserInfo(LONG userID)
{
debugLogA("CVkProto::RetrieveUserInfo %d", userID);
@@ -294,94 +388,7 @@ void CVkProto::OnReceiveUserInfo(NETLIBHTTPREQUEST *reply, AsyncHttpRequest *pRe if (pUsers == NULL)
return;
- for (size_t i=0; ; i++) {
- JSONNODE *pRecord = json_at(pUsers, i);
- if (pRecord == NULL)
- break;
-
- LONG userid = json_as_int( json_get(pRecord, "id"));
- if (userid == 0)
- break;
-
- MCONTACT hContact;
- if (userid == m_myUserId)
- hContact = NULL;
- else if ((hContact = FindUser(userid, false)) == NULL)
- break;
-
- CMString tszNick;
- int iValue;
- ptrT szValue( json_as_string( json_get(pRecord, "first_name")));
- if (szValue) {
- setTString(hContact, "FirstName", szValue);
- tszNick.Append(szValue);
- tszNick.AppendChar(' ');
- }
-
- if (szValue = json_as_string( json_get(pRecord, "last_name"))) {
- setTString(hContact, "LastName", szValue);
- tszNick.Append(szValue);
- }
-
- if (!tszNick.IsEmpty())
- setTString(hContact, "Nick", tszNick);
-
- int sex = json_as_int(json_get(pRecord, "sex"));
- if (sex)
- setByte(hContact, "Gender", sex == 2 ? 'M' : 'F');
-
- if (szValue = json_as_string( json_get(pRecord, "bdate"))) {
- int d, m, y;
- if ( _stscanf(szValue, _T("%d.%d.%d"), &d, &m, &y) == 3) {
- setByte(hContact, "BirthDay", d);
- setByte(hContact, "BirthMonth", m);
- setWord(hContact, "BirthYear", y);
- }
- }
-
- szValue = json_as_string( json_get(pRecord, "photo_100"));
- if (szValue && *szValue){
- SetAvatarUrl(hContact, szValue);
- ReloadAvatarInfo(hContact);
- }
-
- int iNewStatus = (json_as_int(json_get(pRecord, "online")) == 0) ? ID_STATUS_OFFLINE : ID_STATUS_ONLINE;
- if (getWord(hContact, "Status", 0) != iNewStatus)
- setWord(hContact, "Status", iNewStatus);
-
- if ((iValue = json_as_int(json_get(pRecord, "timezone"))) != 0)
- setByte(hContact, "Timezone", iValue * -2);
-
- szValue = json_as_string(json_get(pRecord, "mobile_phone"));
- if (szValue && *szValue)
- setTString(hContact, "Cellular", szValue);
- szValue = json_as_string(json_get(pRecord, "home_phone"));
- if (szValue && *szValue)
- setTString(hContact, "Phone", szValue);
-
- szValue = json_as_string(json_get(pRecord, "status"));
- if (szValue && *szValue) {
- ptrT tszOldStatus(db_get_tsa(hContact, hContact ? "CList" : m_szModuleName, "StatusMsg"));
- if (!tszOldStatus)
- db_set_ts(hContact, hContact ? "CList" : m_szModuleName, "StatusMsg", szValue);
- else if (_tcscmp(tszOldStatus, szValue))
- db_set_ts(hContact, hContact ? "CList" : m_szModuleName, "StatusMsg", szValue);
- }
- else
- db_set_ts(hContact, hContact ? "CList" : m_szModuleName, "StatusMsg", _T(""));
- if (!hContact&&m_bOne){
- setTString("OldStatusMsg", db_get_tsa(0, m_szModuleName, "StatusMsg"));
- m_bOne = false;
- };
-
- szValue = json_as_string(json_get(pRecord, "about"));
- if (szValue && *szValue)
- setTString(hContact, "About", szValue);
-
- szValue = json_as_string(json_get(pRecord, "domain"));
- if (szValue && *szValue)
- setTString(hContact, "domain", szValue);
- }
+ for (size_t i = 0; SetContactInfo(json_at(pUsers, i)) != -1; i++);
JSONNODE *pRequests = json_get(pResponse, "requests");
if (pRequests == NULL)
@@ -425,7 +432,7 @@ void CVkProto::OnReceiveFriends(NETLIBHTTPREQUEST *reply, AsyncHttpRequest *pReq return;
JSONROOT pRoot;
- JSONNODE *pResponse = CheckJsonResponse(pReq, reply, pRoot), *pInfo;
+ JSONNODE *pResponse = CheckJsonResponse(pReq, reply, pRoot);
if (pResponse == NULL)
return;
@@ -442,76 +449,17 @@ void CVkProto::OnReceiveFriends(NETLIBHTTPREQUEST *reply, AsyncHttpRequest *pReq int iCount = json_as_int(json_get(pResponse, "count"));
JSONNODE *pItems = json_get(pResponse, "items");
- for (int i = 0; (pInfo = json_at(pItems, i)) != NULL; i++) {
- ptrT szValue(json_as_string(json_get(pInfo, "id")));
- if (szValue == NULL)
- continue;
-
- CMString tszNick;
-
- MCONTACT hContact = FindUser(_ttoi(szValue), true);
- arContacts.remove((HANDLE)hContact);
- setByte(hContact, "Auth", 0);
-
- szValue = json_as_string(json_get(pInfo, "first_name"));
- if (szValue) {
- setTString(hContact, "FirstName", szValue);
- tszNick.Append(szValue);
- tszNick.AppendChar(' ');
- }
+ if (pItems)
+ for (int i = 0; i<iCount; i++) {
+ MCONTACT hContact = SetContactInfo(json_at(pItems, i));
- if (szValue = json_as_string(json_get(pInfo, "last_name"))) {
- setTString(hContact, "LastName", szValue);
- tszNick.Append(szValue);
- }
-
- if (!tszNick.IsEmpty())
- setTString(hContact, "Nick", tszNick);
+ if ((hContact == NULL) || hContact == -1)
+ continue;
- szValue = json_as_string(json_get(pInfo, "photo_100"));
- if (szValue && *szValue){
- SetAvatarUrl(hContact, szValue);
- ReloadAvatarInfo(hContact);
+ arContacts.remove((HANDLE)hContact);
+ setByte(hContact, "Auth", 0);
}
- int iNewStatus = (json_as_int(json_get(pInfo, "online")) == 0) ? ID_STATUS_OFFLINE : ID_STATUS_ONLINE;
- if (getWord(hContact, "Status", 0) != iNewStatus)
- setWord(hContact, "Status", iNewStatus);
-
- int iValue = json_as_int(json_get(pInfo, "sex"));
- if (iValue)
- setByte(hContact, "Gender", (iValue == 2) ? 'M' : 'F');
-
- if ((iValue = json_as_int(json_get(pInfo, "timezone"))) != 0)
- setByte(hContact, "Timezone", iValue * -2);
-
- szValue = json_as_string(json_get(pInfo, "mobile_phone"));
- if (szValue && *szValue)
- setTString(hContact, "Cellular", szValue);
- szValue = json_as_string(json_get(pInfo, "home_phone"));
- if (szValue && *szValue)
- setTString(hContact, "Phone", szValue);
-
- szValue = json_as_string(json_get(pInfo, "status"));
- if (szValue && *szValue) {
- ptrT tszOldStatus(db_get_tsa(hContact, "CList", "StatusMsg"));
- if (!tszOldStatus)
- db_set_ts(hContact, "CList", "StatusMsg", szValue);
- else if (_tcscmp(tszOldStatus, szValue))
- db_set_ts(hContact, "CList", "StatusMsg", szValue);
- }
- else
- db_set_ts(hContact, "CList", "StatusMsg", _T(""));
-
- szValue = json_as_string(json_get(pInfo, "about"));
- if (szValue && *szValue)
- setTString(hContact, "About", szValue);
-
- szValue = json_as_string(json_get(pInfo, "domain"));
- if (szValue && *szValue)
- setTString(hContact, "domain", szValue);
- }
-
if (bCleanContacts)
for (int i = 0; i < arContacts.getCount(); i++)
CallService(MS_DB_CONTACT_DELETE, (WPARAM)arContacts[i], 0);
|