diff options
author | Sergey Bolhovskoy <elzorfox@ya.ru> | 2014-10-21 08:08:45 +0000 |
---|---|---|
committer | Sergey Bolhovskoy <elzorfox@ya.ru> | 2014-10-21 08:08:45 +0000 |
commit | 537cc1ec9cdd43257b19385acacd05cdace3ac1a (patch) | |
tree | b593f58dc1bd0da4d0bb3ef0218aa726955727eb /protocols/VKontakte | |
parent | f28932a9312ce067782665b9497f8203483d748d (diff) |
VKontakte:
add IsOnline() in functions with pushing requests
fix(?) for freeze offline status
git-svn-id: http://svn.miranda-ng.org/main/trunk@10843 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'protocols/VKontakte')
-rw-r--r-- | protocols/VKontakte/src/vk_captcha.cpp | 5 | ||||
-rw-r--r-- | protocols/VKontakte/src/vk_chats.cpp | 23 | ||||
-rw-r--r-- | protocols/VKontakte/src/vk_files.cpp | 18 | ||||
-rw-r--r-- | protocols/VKontakte/src/vk_proto.cpp | 11 | ||||
-rw-r--r-- | protocols/VKontakte/src/vk_search.cpp | 6 | ||||
-rw-r--r-- | protocols/VKontakte/src/vk_thread.cpp | 31 |
6 files changed, 86 insertions, 8 deletions
diff --git a/protocols/VKontakte/src/vk_captcha.cpp b/protocols/VKontakte/src/vk_captcha.cpp index 715e36761f..cd5a9eab89 100644 --- a/protocols/VKontakte/src/vk_captcha.cpp +++ b/protocols/VKontakte/src/vk_captcha.cpp @@ -103,6 +103,8 @@ bool CVkProto::RunCaptchaForm(LPCSTR szUrl, CMStringA &result) debugLogA("CVkProto::RunCaptchaForm: reading picture from %s", szUrl);
result.Empty();
+ if (!IsOnline())
+ return false;
NETLIBHTTPREQUEST req = { sizeof(req) };
req.requestType = REQUEST_GET;
req.szUrl = (LPSTR)szUrl;
@@ -144,6 +146,9 @@ bool CVkProto::RunCaptchaForm(LPCSTR szUrl, CMStringA &result) bool CVkProto::ApplyCaptcha(AsyncHttpRequest *pReq, JSONNODE *pErrorNode)
{
debugLogA("CVkProto::ApplyCaptcha");
+ if (!IsOnline())
+ return false;
+
char *szUrl = NEWSTR_ALLOCA( _T2A( json_as_string( json_get(pErrorNode, "captcha_img"))));
char *szSid = NEWSTR_ALLOCA( _T2A( json_as_string( json_get(pErrorNode, "captcha_sid"))));
if (szUrl == NULL || szSid == NULL)
diff --git a/protocols/VKontakte/src/vk_chats.cpp b/protocols/VKontakte/src/vk_chats.cpp index 36f2ba84da..0eac232a0e 100644 --- a/protocols/VKontakte/src/vk_chats.cpp +++ b/protocols/VKontakte/src/vk_chats.cpp @@ -110,7 +110,8 @@ void CVkProto::RetrieveChatInfo(CVkChatInfo *cc) szQuery.Append("};");
debugLogA("CVkProto::RetrieveChantInfo(%d)", cc->m_chatid);
-
+ if (!IsOnline())
+ return;
Push(new AsyncHttpRequest(this, REQUEST_GET, "/method/execute.json", true, &CVkProto::OnReceiveChatInfo)
<< CHAR_PARAM("code", szQuery)
<< VER_API )->pUserInfo = cc;
@@ -357,7 +358,7 @@ int CVkProto::OnChatEvent(WPARAM, LPARAM lParam) switch (gch->pDest->iType) {
case GC_USER_MESSAGE:
- if (m_bOnline && lstrlen(gch->ptszText) > 0) {
+ if (IsOnline() && lstrlen(gch->ptszText) > 0) {
TCHAR *buf = NEWTSTR_ALLOCA(gch->ptszText);
rtrimt(buf);
UnEscapeChatTags(buf);
@@ -441,6 +442,8 @@ LPTSTR CVkProto::ChangeChatTopic(CVkChatInfo *cc) void CVkProto::LogMenuHook(CVkChatInfo *cc, GCHOOK *gch)
{
MCONTACT hContact;
+ if (!IsOnline())
+ return;
switch (gch->dwData) {
case IDM_TOPIC:
@@ -488,7 +491,9 @@ void CVkProto::LogMenuHook(CVkChatInfo *cc, GCHOOK *gch) INT_PTR __cdecl CVkProto::OnJoinChat(WPARAM hContact, LPARAM)
{
debugLogA("CVkProto::OnJoinChat");
-
+ if (!IsOnline())
+ return 1;
+
if (getBool(hContact, "kicked", false))
return 1;
@@ -510,6 +515,9 @@ INT_PTR __cdecl CVkProto::OnJoinChat(WPARAM hContact, LPARAM) INT_PTR __cdecl CVkProto::OnLeaveChat(WPARAM hContact, LPARAM)
{
debugLogA("CVkProto::OnLeaveChat");
+ if (!IsOnline())
+ return 1;
+
ptrT tszChatID(getTStringA(hContact, "ChatRoomID"));
if (tszChatID == NULL)
return 1;
@@ -592,6 +600,8 @@ void CVkProto::OnChatLeave(NETLIBHTTPREQUEST *reply, AsyncHttpRequest *pReq) INT_PTR __cdecl CVkProto::SvcDestroyKickChat(WPARAM hContact, LPARAM)
{
debugLogA("CVkProto::SvcDestroyKickChat");
+ if (!IsOnline())
+ return 1;
if (!getBool(hContact, "off", false))
return 1;
@@ -644,6 +654,9 @@ void CVkProto::NickMenuHook(CVkChatInfo *cc, GCHOOK *gch) break;
case IDM_KICK:
+ if (!IsOnline())
+ return;
+
Push(new AsyncHttpRequest(this, REQUEST_GET, "/method/messages.removeChatUser.json", true, &CVkProto::OnReceiveSmth)
<< INT_PARAM("chat_id", cc->m_chatid)
<< INT_PARAM("user_id", cu->m_uid)
@@ -773,12 +786,16 @@ static INT_PTR CALLBACK GcCreateDlgProc(HWND hwndDlg, UINT msg, WPARAM wParam, L INT_PTR CVkProto::SvcCreateChat(WPARAM, LPARAM)
{
+ if (!IsOnline())
+ return 1;
DialogBoxParam(hInst, MAKEINTRESOURCE(IDD_GC_CREATE), NULL, GcCreateDlgProc, (LPARAM)this);
return 0;
}
void CVkProto::CreateNewChat(LPCSTR uids, LPCTSTR ptszTitle)
{
+ if (!IsOnline())
+ return;
Push(new AsyncHttpRequest(this, REQUEST_GET, "/method/messages.createChat.json", true, &CVkProto::OnCreateNewChat)
<< TCHAR_PARAM("title", ptszTitle)
<< CHAR_PARAM("user_ids", uids)
diff --git a/protocols/VKontakte/src/vk_files.cpp b/protocols/VKontakte/src/vk_files.cpp index 8d19508bb4..800d2f6607 100644 --- a/protocols/VKontakte/src/vk_files.cpp +++ b/protocols/VKontakte/src/vk_files.cpp @@ -72,6 +72,8 @@ CVkFileUploadParam::VKFileType CVkFileUploadParam::GetType() HANDLE CVkProto::SendFile(MCONTACT hContact, const PROTOCHAR *desc, PROTOCHAR **files)
{
debugLogA("CVkProto::SendFile");
+ if (!IsOnline())
+ return (HANDLE)0;
CVkFileUploadParam *fup = new CVkFileUploadParam(hContact, desc, files);
ForkThread(&CVkProto::SendFileThread, (void *)fup);
return (HANDLE)fup;
@@ -118,6 +120,10 @@ void CVkProto::SendFileThread(void *p) {
CVkFileUploadParam *fup = (CVkFileUploadParam *)p;
debugLog(L"CVkProto::SendFileThread %d %s", fup->GetType(), fup->fileName());
+ if (!IsOnline()){
+ SendFileFiled(fup, L"NotOnline");
+ return;
+ }
if (!fup->IsAccess()){
SendFileFiled(fup, L"FileIsNotAccess");
return;
@@ -148,6 +154,10 @@ void CVkProto::SendFileThread(void *p) void CVkProto::OnReciveUploadServer(NETLIBHTTPREQUEST *reply, AsyncHttpRequest *pReq)
{
CVkFileUploadParam *fup = (CVkFileUploadParam *)pReq->pUserInfo;
+ if (!IsOnline()){
+ SendFileFiled(fup, L"NotOnline");
+ return;
+ }
debugLogA("CVkProto::OnReciveUploadServer %d", reply->resultCode);
if (reply->resultCode != 200){
@@ -228,6 +238,10 @@ void CVkProto::OnReciveUploadServer(NETLIBHTTPREQUEST *reply, AsyncHttpRequest * void CVkProto::OnReciveUpload(NETLIBHTTPREQUEST *reply, AsyncHttpRequest *pReq)
{
CVkFileUploadParam *fup = (CVkFileUploadParam *)pReq->pUserInfo;
+ if (!IsOnline()){
+ SendFileFiled(fup, L"NotOnline");
+ return;
+ }
debugLogA("CVkProto::OnReciveUploadServer %d", reply->resultCode);
if (reply->resultCode != 200){
@@ -291,6 +305,10 @@ void CVkProto::OnReciveUpload(NETLIBHTTPREQUEST *reply, AsyncHttpRequest *pReq) void CVkProto::OnReciveUploadFile(NETLIBHTTPREQUEST *reply, AsyncHttpRequest *pReq)
{
CVkFileUploadParam *fup = (CVkFileUploadParam *)pReq->pUserInfo;
+ if (!IsOnline()){
+ SendFileFiled(fup, L"NotOnline");
+ return;
+ }
debugLogA("CVkProto::OnReciveUploadFile %d", reply->resultCode);
if (reply->resultCode != 200){
diff --git a/protocols/VKontakte/src/vk_proto.cpp b/protocols/VKontakte/src/vk_proto.cpp index 45b0f3c0f9..53be268746 100644 --- a/protocols/VKontakte/src/vk_proto.cpp +++ b/protocols/VKontakte/src/vk_proto.cpp @@ -344,6 +344,8 @@ void CVkProto::SendMsgAck(void *param) int CVkProto::SendMsg(MCONTACT hContact, int flags, const char *msg)
{
debugLogA("CVkProto::SendMsg");
+ if (!IsOnline())
+ return 0;
LONG userID = getDword(hContact, "ID", -1);
if (userID == -1)
return 0;
@@ -444,8 +446,11 @@ int CVkProto::SetStatus(int iNewStatus) }
else if (IsOnline())
SetServerStatus(iNewStatus);
- else
+ else {
ProtoBroadcastAck(NULL, ACKTYPE_STATUS, ACKRESULT_SUCCESS, (HANDLE)oldStatus, m_iStatus);
+ if (!(m_iStatus >= ID_STATUS_CONNECTING && m_iStatus < ID_STATUS_CONNECTING + MAX_CONNECT_RETRIES))
+ m_iDesiredStatus = m_iStatus;
+ }
return 0;
}
@@ -545,6 +550,8 @@ void CVkProto::OnReceiveAuthRequest(NETLIBHTTPREQUEST *reply, AsyncHttpRequest * int CVkProto::Authorize(HANDLE hDbEvent)
{
debugLogA("CVkProto::Authorize");
+ if (!IsOnline())
+ return 1;
MCONTACT hContact = MContactFromDbEvent(hDbEvent);
if (hContact == -1)
return 1;
@@ -555,6 +562,8 @@ int CVkProto::Authorize(HANDLE hDbEvent) int CVkProto::AuthDeny(HANDLE hDbEvent, const PROTOCHAR *reason)
{
debugLogA("CVkProto::AuthDeny");
+ if (!IsOnline())
+ return 1;
MCONTACT hContact = MContactFromDbEvent(hDbEvent);
if (hContact == -1)
return 1; diff --git a/protocols/VKontakte/src/vk_search.cpp b/protocols/VKontakte/src/vk_search.cpp index 7c3c86ad6d..2acfaedd1e 100644 --- a/protocols/VKontakte/src/vk_search.cpp +++ b/protocols/VKontakte/src/vk_search.cpp @@ -48,6 +48,8 @@ HANDLE CVkProto::SearchByName(const PROTOCHAR* nick, const PROTOCHAR* firstName, void CVkProto::SearchBasicThread(void* id)
{
debugLogA("CVkProto::OnSearchBasicThread");
+ if (!IsOnline())
+ return;
AsyncHttpRequest *pReq = new AsyncHttpRequest(this, REQUEST_GET, "/method/users.get.json", true, &CVkProto::OnSearch)
<< TCHAR_PARAM("user_ids", (TCHAR *)id)
<< CHAR_PARAM("fields", "nickname, domain")
@@ -59,6 +61,8 @@ void CVkProto::SearchBasicThread(void* id) void CVkProto::SearchByMailThread(void* email)
{
debugLogA("CVkProto::OnSearchBasicThread");
+ if (!IsOnline())
+ return;
AsyncHttpRequest *pReq = new AsyncHttpRequest(this, REQUEST_GET, "/method/account.lookupContacts.json", true, &CVkProto::OnSearchByMail)
<< TCHAR_PARAM("contacts", (TCHAR *)email)
<< CHAR_PARAM("service", "email")
@@ -73,6 +77,8 @@ void __cdecl CVkProto::SearchThread(void* p) TCHAR arg[200]; mir_sntprintf(arg, SIZEOF(arg), _T("%s %s %s"), pParam->pszFirstName, pParam->pszNick, pParam->pszLastName);
debugLog(_T("CVkProto::SearchThread %s"), arg);
+ if (!IsOnline())
+ return;
AsyncHttpRequest *pReq = new AsyncHttpRequest(this, REQUEST_GET, "/method/users.search.json", true, &CVkProto::OnSearch)
<< TCHAR_PARAM("q", (TCHAR *)arg)
diff --git a/protocols/VKontakte/src/vk_thread.cpp b/protocols/VKontakte/src/vk_thread.cpp index d4c1b8f2fc..59b96d9d5f 100644 --- a/protocols/VKontakte/src/vk_thread.cpp +++ b/protocols/VKontakte/src/vk_thread.cpp @@ -44,7 +44,7 @@ void CVkProto::ConnectionFailed(int iReason) static VOID CALLBACK TimerProc(HWND, UINT, UINT_PTR, DWORD)
{
for (int i = 0; i < vk_Instances.getCount(); i++){
- vk_Instances[i]->SetServerStatus(vk_Instances[i]->m_iStatus);
+ vk_Instances[i]->SetServerStatus(vk_Instances[i]->m_iDesiredStatus);
vk_Instances[i]->RetrieveUsersInfo(true);
}
}
@@ -359,6 +359,8 @@ MCONTACT CVkProto::SetContactInfo(JSONNODE* pItem, bool flag, bool self) void CVkProto::RetrieveUserInfo(LONG userID)
{
debugLogA("CVkProto::RetrieveUserInfo (%d)", userID);
+ if (!IsOnline())
+ return;
CMString userIDs, code;
userIDs.AppendFormat(L"%i", userID);
CMString codeformat("var userIDs=\"%s\";"
@@ -373,7 +375,8 @@ void CVkProto::RetrieveUserInfo(LONG userID) void CVkProto::RetrieveUsersInfo(bool flag)
{
debugLogA("CVkProto::RetrieveUsersInfo");
-
+ if (!IsOnline())
+ return;
CMString userIDs, code;
for (MCONTACT hContact = db_find_first(m_szModuleName); hContact; hContact = db_find_next(hContact, m_szModuleName)){
LONG userID = getDword(hContact, "ID", -1);
@@ -444,6 +447,8 @@ void CVkProto::OnReceiveUserInfo(NETLIBHTTPREQUEST *reply, AsyncHttpRequest *pRe void CVkProto::RetrieveFriends()
{
debugLogA("CVkProto::RetrieveFriends");
+ if (!IsOnline())
+ return;
Push(new AsyncHttpRequest(this, REQUEST_GET, "/method/friends.get.json", true, &CVkProto::OnReceiveFriends)
<< INT_PARAM("count", 1000)
<< CHAR_PARAM("fields", fieldsName)
@@ -504,6 +509,8 @@ int CVkProto::OnDbEventRead(WPARAM hContact, LPARAM) void CVkProto::MarkMessagesRead(const CMStringA &mids)
{
debugLogA("CVkProto::MarkMessagesRead (mids)");
+ if (!IsOnline())
+ return;
if (mids.IsEmpty())
return;
@@ -515,6 +522,8 @@ void CVkProto::MarkMessagesRead(const CMStringA &mids) void CVkProto::MarkMessagesRead(const MCONTACT hContact)
{
debugLogA("CVkProto::MarkMessagesRead (hContact)");
+ if (!IsOnline())
+ return;
LONG userID = getDword(hContact, "ID", -1);
if (userID == -1)
return;
@@ -527,6 +536,8 @@ void CVkProto::MarkMessagesRead(const MCONTACT hContact) void CVkProto::RetrieveMessagesByIds(const CMStringA &mids)
{
debugLogA("CVkProto::RetrieveMessagesByIds");
+ if (!IsOnline())
+ return;
if (mids.IsEmpty())
return;
@@ -538,6 +549,8 @@ void CVkProto::RetrieveMessagesByIds(const CMStringA &mids) void CVkProto::RetrieveUnreadMessages()
{
debugLogA("CVkProto::RetrieveUnreadMessages");
+ if (!IsOnline())
+ return;
Push(new AsyncHttpRequest(this, REQUEST_GET, "/method/messages.getDialogs.json", true, &CVkProto::OnReceiveDlgs)
<< VER_API);
}
@@ -694,7 +707,7 @@ void CVkProto::GetHistoryDlg(MCONTACT hContact, int iLastMsg) {
debugLogA("CVkProto::GetHistoryDlg %d", iLastMsg);
int lastmsgid = getDword(hContact, "lastmsgid", -1);
- if (lastmsgid == -1) {
+ if ((lastmsgid == -1)||(!IsOnline())) {
setDword(hContact, "lastmsgid", iLastMsg);
return;
}
@@ -710,7 +723,7 @@ void CVkProto::GetHistoryDlgMessages(MCONTACT hContact, int iOffset, int iMaxCou if (-1 == userID)
return;
- if (lastcount == 0 || iMaxCount < 1) {
+ if (lastcount == 0 || iMaxCount < 1 || !IsOnline()) {
setDword(hContact, "lastmsgid", getDword(hContact, "new_lastmsgid", -1));
db_unset(hContact, m_szModuleName, "new_lastmsgid");
if (getBool(hContact, "ImportHistory", false))
@@ -802,6 +815,8 @@ void CVkProto::OnReceiveHistoryMessages(NETLIBHTTPREQUEST *reply, AsyncHttpReque void CVkProto::RetrievePollingInfo()
{
debugLogA("CVkProto::RetrievePollingInfo");
+ if (!IsOnline())
+ return;
Push(new AsyncHttpRequest(this, REQUEST_GET, "/method/messages.getLongPollServer.json", true, &CVkProto::OnReceivePollingInfo)
<< VER_API);
}
@@ -829,6 +844,8 @@ void CVkProto::OnReceivePollingInfo(NETLIBHTTPREQUEST *reply, AsyncHttpRequest * void CVkProto::RetrieveStatusMsg(const CMString &StatusMsg)
{
debugLogA("CVkProto::RetrieveStatusMsg");
+ if (!IsOnline())
+ return;
Push(new AsyncHttpRequest(this, REQUEST_GET, "/method/status.set.json", true, &CVkProto::OnReceiveSmth)
<< TCHAR_PARAM("text", StatusMsg)
<< VER_API);
@@ -897,6 +914,8 @@ INT_PTR __cdecl CVkProto::SvcSetListeningTo(WPARAM wParam, LPARAM lParam) INT_PTR __cdecl CVkProto::SvcAddAsFriend(WPARAM hContact, LPARAM)
{
debugLogA("CVkProto::SvcAddAsFriend");
+ if (!IsOnline())
+ return 1;
CallContactService(hContact, PSS_AUTHREQUESTW, 0, (LPARAM)TranslateT("Please authorize me to add you to my friend list."));
return 0;
}
@@ -1062,6 +1081,8 @@ INT_PTR __cdecl CVkProto::SvcVisitProfile(WPARAM hContact, LPARAM) INT_PTR __cdecl CVkProto::SvcGetAllServerHistory(WPARAM hContact, LPARAM)
{
debugLogA("CVkProto::SvcGetAllServerHistory");
+ if (!IsOnline())
+ return 0;
LPCTSTR str = TranslateT("Are you sure to reload all messages from vk.com?\nLocal contact history will be deleted and reloaded from the server.\nIt may take a long time.\nDo you want to continue?");
if (IDNO == MessageBox(NULL, str, TranslateT("Attention!"), MB_ICONWARNING | MB_YESNO))
return 0;
@@ -1171,6 +1192,8 @@ void CVkProto::PollUpdates(JSONNODE *pUpdates) int CVkProto::PollServer()
{
debugLogA("CVkProto::PollServer");
+ if (!IsOnline())
+ return 0;
NETLIBHTTPREQUEST req = { sizeof(req) };
req.requestType = REQUEST_GET;
|