From 16836ea77582da49b82c9b95332762f7135c76ea Mon Sep 17 00:00:00 2001 From: Sergey Bolhovskoy Date: Sat, 11 Oct 2014 11:52:12 +0000 Subject: VKontakte: add processing for net error on PollServer fix for close chat tab when it destroy fix for rare crash on load chat history version bump git-svn-id: http://svn.miranda-ng.org/main/trunk@10763 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- protocols/VKontakte/src/version.h | 2 +- protocols/VKontakte/src/vk_chats.cpp | 11 +++++++---- protocols/VKontakte/src/vk_thread.cpp | 16 ++++++++++++++-- 3 files changed, 22 insertions(+), 7 deletions(-) diff --git a/protocols/VKontakte/src/version.h b/protocols/VKontakte/src/version.h index 74e50ca380..87061eb093 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 0 -#define __BUILD_NUM 20 +#define __BUILD_NUM 21 #include diff --git a/protocols/VKontakte/src/vk_chats.cpp b/protocols/VKontakte/src/vk_chats.cpp index 6c4f9e7fc8..8ddfaa201a 100644 --- a/protocols/VKontakte/src/vk_chats.cpp +++ b/protocols/VKontakte/src/vk_chats.cpp @@ -218,6 +218,7 @@ void CVkProto::OnReceiveChatInfo(NETLIBHTTPREQUEST *reply, AsyncHttpRequest *pRe void CVkProto::AppendChatMessage(int id, JSONNODE *pMsg, bool bIsHistory) { + debugLogA("CVkProto::AppendChatMessage"); CVkChatInfo *cc = AppendChat(id, NULL); if (cc == NULL) return; @@ -252,6 +253,7 @@ void CVkProto::AppendChatMessage(int id, JSONNODE *pMsg, bool bIsHistory) void CVkProto::AppendChatMessage(CVkChatInfo *cc, int mid, int uid, int msgTime, LPCTSTR ptszBody, bool bIsHistory) { + debugLogA("CVkProto::AppendChatMessage param"); CVkChatUser *cu = cc->m_users.find((CVkChatUser*)&uid); if (cu == NULL) { cc->m_users.insert(cu = new CVkChatUser(uid)); @@ -264,12 +266,12 @@ void CVkProto::AppendChatMessage(CVkChatInfo *cc, int mid, int uid, int msgTime, GCDEST gcd = { m_szModuleName, cc->m_tszId, GC_EVENT_MESSAGE }; GCEVENT gce = { sizeof(GCEVENT), &gcd }; - gce.bIsMe = uid == m_myUserId; + gce.bIsMe = (uid == m_myUserId); gce.ptszUID = tszId; gce.time = msgTime; gce.dwFlags = (bIsHistory) ? GCEF_NOTNOTIFY : GCEF_ADDTOLOG; - gce.ptszNick = cu->m_tszNick; - gce.ptszText = ptszBody; + gce.ptszNick = mir_tstrdup(cu->m_tszNick); + gce.ptszText = mir_tstrdup(ptszBody); CallServiceSync(MS_GC_EVENT, 0, (LPARAM)&gce); } @@ -472,7 +474,8 @@ void CVkProto::OnChatDestroy(NETLIBHTTPREQUEST *reply, AsyncHttpRequest *pReq) GCDEST gcd = { m_szModuleName, cc->m_tszId, GC_EVENT_QUIT }; GCEVENT gce = { sizeof(GCEVENT), &gcd }; CallServiceSync(MS_GC_EVENT, 0, (LPARAM)&gce); - + gcd.iType = GC_EVENT_CONTROL; + CallServiceSync(MS_GC_EVENT, SESSION_TERMINATE, (LPARAM)&gce); CallService(MS_DB_CONTACT_DELETE, (WPARAM)cc->m_hContact, 0); } } diff --git a/protocols/VKontakte/src/vk_thread.cpp b/protocols/VKontakte/src/vk_thread.cpp index d68c299bf4..e9e8bb035a 100644 --- a/protocols/VKontakte/src/vk_thread.cpp +++ b/protocols/VKontakte/src/vk_thread.cpp @@ -124,6 +124,7 @@ static char VK_TOKEN_BEG[] = "access_token="; void CVkProto::OnOAuthAuthorize(NETLIBHTTPREQUEST *reply, AsyncHttpRequest *pReq) { + debugLogA("CVkProto::OnOAuthAuthorize %d", reply->resultCode); GrabCookies(reply); if (reply->resultCode == 302) { // manual redirect @@ -1149,6 +1150,8 @@ int CVkProto::PollServer() NETLIBHTTPREQUEST *reply = (NETLIBHTTPREQUEST*)CallService(MS_NETLIB_HTTPTRANSACTION, (WPARAM)m_hNetlibUser, (LPARAM)&req); if (reply == NULL) { debugLogA("CVkProto::PollServer is dead"); + m_pollingConn = NULL; + CallService(MS_NETLIB_FREEHTTPREQUESTSTRUCT, 0, (LPARAM)reply); ShutdownSession(); return 0; } @@ -1169,6 +1172,14 @@ int CVkProto::PollServer() PollUpdates(pUpdates); retVal = 1; } + } + else if (((reply->resultCode >= 400) && (reply->resultCode <= 417)) + || ((reply->resultCode >= 500) && (reply->resultCode <= 509))) { + debugLogA("CVkProto::PollServer is dead. Error code - %d", reply->resultCode); + m_pollingConn = NULL; + CallService(MS_NETLIB_FREEHTTPREQUESTSTRUCT, 0, (LPARAM)reply); + ShutdownSession(); + return 0; } m_pollingConn = reply->nlc; @@ -1192,6 +1203,7 @@ void CVkProto::PollingThread(void*) CMString CVkProto::GetAttachmentDescr(JSONNODE *pAttachments) { + debugLogA("CVkProto::GetAttachmentDescr"); CMString res; res.AppendChar('\n'); res += TranslateT("Attachments:"); @@ -1218,7 +1230,7 @@ CMString CVkProto::GetAttachmentDescr(JSONNODE *pAttachments) ptrT ptszTypeTranslate((lstrcmp(ptszType, _T("photo")) == 0) ? TranslateT("Photo") : TranslateT("Sticker")); res.AppendFormat(_T("%s: %s (%dx%d)"), ptszTypeTranslate, ptszLink, iWidth, iHeight); if (m_bAddImgBbc) - res.AppendFormat(L"\n\t[img]%s[/img]", ptszLink); + res.AppendFormat(L"\n\t[img]%s[/img]", ptszLink); } else if (!lstrcmp(ptszType, _T("audio"))) { JSONNODE *pAudio = json_get(pAttach, "audio"); @@ -1257,7 +1269,7 @@ CMString CVkProto::GetAttachmentDescr(JSONNODE *pAttachments) ptrT ptszText(json_as_string(json_get(pWall, "text"))); int id = json_as_int(json_get(pWall, "id")); int fromID = json_as_int(json_get(pWall, "from_id")); - res.AppendFormat(_T("%s: %s - http://vk.com/wall%d_%d"), TranslateT("Wall post"), ptszText, fromID, id); + res.AppendFormat(_T("%s: %s - http://vk.com/wall%d_%d"), TranslateT("Wall post"), ptszText ? ptszText : L" ", fromID, id); } else res.AppendFormat(TranslateT("Unsupported or unknown attachment type: %s"), ptszType); -- cgit v1.2.3