summaryrefslogtreecommitdiff
path: root/protocols/VKontakte/src
diff options
context:
space:
mode:
Diffstat (limited to 'protocols/VKontakte/src')
-rw-r--r--protocols/VKontakte/src/vk_history.cpp91
-rw-r--r--protocols/VKontakte/src/vk_messages.cpp4
-rw-r--r--protocols/VKontakte/src/vk_proto.cpp19
-rw-r--r--protocols/VKontakte/src/vk_proto.h13
4 files changed, 117 insertions, 10 deletions
diff --git a/protocols/VKontakte/src/vk_history.cpp b/protocols/VKontakte/src/vk_history.cpp
index 183f661164..8860ac420e 100644
--- a/protocols/VKontakte/src/vk_history.cpp
+++ b/protocols/VKontakte/src/vk_history.cpp
@@ -19,9 +19,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
//////////////////////////// History services ///////////////////////////////////////////
-INT_PTR __cdecl CVkProto::SvcGetAllServerHistory(WPARAM hContact, LPARAM)
+INT_PTR __cdecl CVkProto::SvcGetAllServerHistoryForContact(WPARAM hContact, LPARAM)
{
- debugLogA("CVkProto::SvcGetAllServerHistory");
+ debugLogA("CVkProto::SvcGetAllServerHistoryForContact");
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?");
@@ -39,11 +39,50 @@ INT_PTR __cdecl CVkProto::SvcGetAllServerHistory(WPARAM hContact, LPARAM)
hDBEvent = hDBEventNext;
}
+ m_bNotifyForEndLoadingHistory = true;
+
db_unset(hContact, m_szModuleName, "lastmsgid");
GetServerHistory(hContact, 0, MAXHISTORYMIDSPERONE, 0, 0);
return 1;
}
+INT_PTR __cdecl CVkProto::SvcGetAllServerHistory(WPARAM, LPARAM)
+{
+ debugLogA("CVkProto::SvcGetAllServerHistory start");
+ if (!IsOnline())
+ return 0;
+ LPCTSTR str = TranslateT("Are you sure you want to reload all messages for all contacts from vk.com?\nLocal contact history will be deleted and reloaded from the server.\nIt may take a very long time and/or corrupt miranda database.\nWe recommend check your database before reloading messages and after it (Miranda32.exe /svc:dbchecker or Miranda64.exe /svc:dbchecker).\nDo you want to continue?");
+ if (IDNO == MessageBox(NULL, str, TranslateT("Attention!"), MB_ICONWARNING | MB_YESNO))
+ return 0;
+
+ for (MCONTACT hContact = db_find_first(m_szModuleName); hContact; hContact = db_find_next(hContact, m_szModuleName)) {
+ LONG userID = getDword(hContact, "ID", -1);
+ if (userID == -1 || userID == VK_FEED_USER)
+ continue;
+
+
+ MEVENT hDBEvent = db_event_first(hContact);
+ while (hDBEvent) {
+ MEVENT hDBEventNext = db_event_next(hContact, hDBEvent);
+ db_event_delete(hContact, hDBEvent);
+ hDBEvent = hDBEventNext;
+ }
+
+ {
+ mir_cslock lck(m_csLoadHistoryTask);
+ m_iLoadHistoryTask++;
+ m_bNotifyForEndLoadingHistoryAllContact = m_bNotifyForEndLoadingHistory = true;
+ debugLogA("CVkProto::SvcGetAllServerHistory for ID=%d m_iLoadHistoryTask=%d", userID, m_iLoadHistoryTask);
+ }
+
+ db_unset(hContact, m_szModuleName, "lastmsgid");
+ GetServerHistory(hContact, 0, MAXHISTORYMIDSPERONE, 0, 0);
+
+ }
+
+ return 1;
+}
+
/////////////////////////////////////////////////////////////////////////////////////////
void CVkProto::GetServerHistoryLastNDay(MCONTACT hContact, int NDay)
@@ -62,6 +101,13 @@ void CVkProto::GetServerHistoryLastNDay(MCONTACT hContact, int NDay)
hDBEvent = hDBEventNext;
}
+ {
+ mir_cslock lck(m_csLoadHistoryTask);
+ m_iLoadHistoryTask++;
+ if (NDay > 3)
+ m_bNotifyForEndLoadingHistory = true;
+ }
+
db_unset(hContact, m_szModuleName, "lastmsgid");
GetServerHistory(hContact, 0, MAXHISTORYMIDSPERONE, tTime, 0);
}
@@ -104,6 +150,7 @@ void CVkProto::GetHistoryDlg(MCONTACT hContact, int iLastMsg)
setDword(hContact, "lastmsgid", iLastMsg);
return;
}
+ m_bNotifyForEndLoadingHistory = false;
GetServerHistory(hContact, 0, MAXHISTORYMIDSPERONE, 0, lastmsgid);
break;
case sync1Days:
@@ -118,14 +165,35 @@ void CVkProto::GetHistoryDlg(MCONTACT hContact, int iLastMsg)
void CVkProto::OnReceiveHistoryMessages(NETLIBHTTPREQUEST *reply, AsyncHttpRequest *pReq)
{
debugLogA("CVkProto::OnReceiveHistoryMessages %d", reply->resultCode);
- if (reply->resultCode != 200 || !pReq->pUserInfo)
+ if (reply->resultCode != 200 || !pReq->pUserInfo) {
+ mir_cslock lck(m_csLoadHistoryTask);
+ if (m_iLoadHistoryTask > 0)
+ m_iLoadHistoryTask--;
+ debugLog(_T("CVkProto::OnReceiveHistoryMessages error m_iLoadHistoryTask=%d"), m_iLoadHistoryTask);
+ MsgPopup(NULL, TranslateT("Error loading history message from server"), TranslateT("Error"), true);
return;
+ }
JSONNode jnRoot;
CVkSendMsgParam *param = (CVkSendMsgParam*)pReq->pUserInfo;
const JSONNode &jnResponse = CheckJsonResponse(pReq, reply, jnRoot);
if (!jnResponse) {
if (!pReq->bNeedsRestart || m_bTerminated) {
+ mir_cslock lck(m_csLoadHistoryTask);
+ if (m_iLoadHistoryTask > 0)
+ m_iLoadHistoryTask--;
+
+ ptrT ptszNick(db_get_tsa(param->hContact, m_szModuleName, "Nick"));
+ CMString str(FORMAT, _T("%s for %s"), TranslateT("Error loading history message from server"), ptszNick);
+
+ MsgPopup(param->hContact, str, TranslateT("Error"), true);
+ debugLog(_T("CVkProto::OnReceiveHistoryMessages error for %s m_iLoadHistoryTask=%d"), ptszNick, m_iLoadHistoryTask);
+
+ if (m_iLoadHistoryTask == 0 && m_bNotifyForEndLoadingHistoryAllContact) {
+ MsgPopup(param->hContact, TranslateT("Loading messages for all contacts was complited"), TranslateT("Loading history"));
+ m_bNotifyForEndLoadingHistoryAllContact = m_bNotifyForEndLoadingHistory = false;
+ }
+
delete param;
pReq->pUserInfo = NULL;
}
@@ -202,6 +270,23 @@ void CVkProto::OnReceiveHistoryMessages(NETLIBHTTPREQUEST *reply, AsyncHttpReque
int iRCount = jnResponse["rcount"].as_int();
if (count == iRCount && once == 0)
GetServerHistory(param->hContact, param->iCount + count, iRCount, iTime, param->iMsgID);
+ else {
+ mir_cslock lck(m_csLoadHistoryTask);
+ if (m_iLoadHistoryTask > 0)
+ m_iLoadHistoryTask--;
+
+ ptrT ptszNick(db_get_tsa(param->hContact, m_szModuleName, "Nick"));
+ CMString str(FORMAT, TranslateT("Loading messages for %s was complited"), ptszNick);
+ debugLog(_T("CVkProto::OnReceiveHistoryMessages for %s m_iLoadHistoryTask=%d"), ptszNick, m_iLoadHistoryTask);
+
+ if (m_bNotifyForEndLoadingHistory)
+ MsgPopup(param->hContact, str, TranslateT("Loading history"));
+
+ if (m_iLoadHistoryTask == 0 && m_bNotifyForEndLoadingHistoryAllContact) {
+ MsgPopup(param->hContact, TranslateT("Loading messages for all contacts was complited"), TranslateT("Loading history"));
+ m_bNotifyForEndLoadingHistoryAllContact = m_bNotifyForEndLoadingHistory = false;
+ }
+ }
if (!pReq->bNeedsRestart || m_bTerminated) {
delete param;
diff --git a/protocols/VKontakte/src/vk_messages.cpp b/protocols/VKontakte/src/vk_messages.cpp
index 0327217b03..dcdc52d11b 100644
--- a/protocols/VKontakte/src/vk_messages.cpp
+++ b/protocols/VKontakte/src/vk_messages.cpp
@@ -374,7 +374,8 @@ void CVkProto::OnReceiveDlgs(NETLIBHTTPREQUEST *reply, AsyncHttpRequest *pReq)
}
else if (m_iSyncHistoryMetod) {
int mid = jnDlg["id"].as_int();
-
+ m_bNotifyForEndLoadingHistory = false;
+
if (getDword(hContact, "lastmsgid", -1) == -1 && numUnread)
GetServerHistory(hContact, 0, numUnread, 0, 0, true);
else
@@ -384,6 +385,7 @@ void CVkProto::OnReceiveDlgs(NETLIBHTTPREQUEST *reply, AsyncHttpRequest *pReq)
MarkMessagesRead(hContact);
}
else if (numUnread) {
+ m_bNotifyForEndLoadingHistory = false;
GetServerHistory(hContact, 0, numUnread, 0, 0, true);
if (m_iMarkMessageReadOn == markOnReceive)
diff --git a/protocols/VKontakte/src/vk_proto.cpp b/protocols/VKontakte/src/vk_proto.cpp
index f3c1fa77a5..00f4fd06f0 100644
--- a/protocols/VKontakte/src/vk_proto.cpp
+++ b/protocols/VKontakte/src/vk_proto.cpp
@@ -41,7 +41,10 @@ CVkProto::CVkProto(const char *szModuleName, const TCHAR *ptszUserName) :
m_cookies(5),
m_msgId(1),
m_chats(1, NumericKeySortT),
- m_ChatsTyping (1, NumericKeySortT)
+ m_ChatsTyping(1, NumericKeySortT),
+ m_iLoadHistoryTask(0),
+ m_bNotifyForEndLoadingHistory(false),
+ m_bNotifyForEndLoadingHistoryAllContact(false)
{
InitQueue();
@@ -201,6 +204,7 @@ void CVkProto::InitMenus()
CreateProtoService(PS_GETSERVERHISTORYLAST7DAY, &CVkProto::SvcGetServerHistoryLastNDay<7>);
CreateProtoService(PS_GETSERVERHISTORYLAST30DAY, &CVkProto::SvcGetServerHistoryLastNDay<30>);
CreateProtoService(PS_GETSERVERHISTORYLAST90DAY, &CVkProto::SvcGetServerHistoryLastNDay<90>);
+ CreateProtoService(PS_GETALLSERVERHISTORYFORCONTACT, &CVkProto::SvcGetAllServerHistoryForContact);
CreateProtoService(PS_GETALLSERVERHISTORY, &CVkProto::SvcGetAllServerHistory);
CreateProtoService(PS_VISITPROFILE, &CVkProto::SvcVisitProfile);
CreateProtoService(PS_CREATECHAT, &CVkProto::SvcCreateChat);
@@ -248,6 +252,13 @@ void CVkProto::InitMenus()
SET_UID(mi, 0x7c449456, 0xb731, 0x48cc, 0x9c, 0x4e, 0x20, 0xe4, 0x66, 0x7a, 0x16, 0x23);
g_hProtoMenuItems[PMI_LOADVKNEWS] = Menu_AddProtoMenuItem(&mi, m_szModuleName);
+ mi.pszService = PS_GETALLSERVERHISTORY;
+ mi.position = 10009 + PMI_GETALLSERVERHISTORY;
+ mi.hIcolibItem = IcoLib_GetIconByHandle(GetIconHandle(IDI_HISTORY));
+ mi.name.a = LPGEN("Load history for all contacts from VK");
+ SET_UID(mi, 0xe5028605, 0x92eb, 0x4956, 0xa0, 0xd0, 0x53, 0xb, 0x11, 0x44, 0x8f, 0x14);
+ g_hProtoMenuItems[PMI_GETALLSERVERHISTORY] = Menu_AddProtoMenuItem(&mi, m_szModuleName);
+
mi.pszService = PS_WIPENONFRIENDS;
mi.position = 10009 + PMI_WIPENONFRIENDS;
mi.hIcolibItem = IcoLib_GetIconByHandle(GetIconHandle(IDI_FRIENDDEL));
@@ -380,12 +391,12 @@ void CVkProto::InitMenus()
SET_UID(mi, 0xd8e30530, 0xa585, 0x4672, 0xa6, 0x39, 0x18, 0xc9, 0xc9, 0xcb, 0xc7, 0x7d);
g_hContactHistoryMenuItems[CHMI_GETSERVERHISTORYLAST90DAY] = Menu_AddContactMenuItem(&mi, m_szModuleName);
- mi.pszService = PS_GETALLSERVERHISTORY;
- mi.position = -200001000 + CMI_GETSERVERHISTORY + 100 + CHMI_GETALLSERVERHISTORY;
+ mi.pszService = PS_GETALLSERVERHISTORYFORCONTACT;
+ mi.position = -200001000 + CMI_GETSERVERHISTORY + 100 + CHMI_GETALLSERVERHISTORYFORCONTACT;
mi.hIcolibItem = IcoLib_GetIconByHandle(GetIconHandle(IDI_HISTORY));
mi.name.t = LPGENT("for all time");
SET_UID(mi, 0xaee3d02b, 0x3667, 0x47c8, 0x9f, 0x43, 0x14, 0xb7, 0xab, 0x52, 0x14, 0x94);
- g_hContactHistoryMenuItems[CHMI_GETALLSERVERHISTORY] = Menu_AddContactMenuItem(&mi, m_szModuleName);
+ g_hContactHistoryMenuItems[CHMI_GETALLSERVERHISTORYFORCONTACT] = Menu_AddContactMenuItem(&mi, m_szModuleName);
}
int CVkProto::OnPreBuildContactMenu(WPARAM hContact, LPARAM)
diff --git a/protocols/VKontakte/src/vk_proto.h b/protocols/VKontakte/src/vk_proto.h
index dde6d762e9..6d04a33b8d 100644
--- a/protocols/VKontakte/src/vk_proto.h
+++ b/protocols/VKontakte/src/vk_proto.h
@@ -27,6 +27,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#define PS_GETSERVERHISTORYLAST7DAY "/GetServerHystoryLast7Day"
#define PS_GETSERVERHISTORYLAST30DAY "/GetServerHystoryLast30Day"
#define PS_GETSERVERHISTORYLAST90DAY "/GetServerHystoryLast90Day"
+#define PS_GETALLSERVERHISTORYFORCONTACT "/GetAllServerHystoryForContact"
#define PS_GETALLSERVERHISTORY "/GetAllServerHystory"
#define PS_VISITPROFILE "/VisitProfile"
#define PS_ADDASFRIEND "/AddAsFriend"
@@ -119,7 +120,9 @@ struct CVkProto : public PROTO<CVkProto>
return 1;
}
- INT_PTR __cdecl SvcGetAllServerHistory(WPARAM hContact, LPARAM);
+ INT_PTR __cdecl SvcGetAllServerHistoryForContact(WPARAM hContact, LPARAM);
+ INT_PTR __cdecl SvcGetAllServerHistory(WPARAM, LPARAM);
+
void InitMenus();
void UnInitMenus();
int __cdecl OnPreBuildContactMenu(WPARAM hContact, LPARAM);
@@ -283,6 +286,11 @@ struct CVkProto : public PROTO<CVkProto>
void ClearAccessToken();
+ mir_cs m_csLoadHistoryTask;
+ int m_iLoadHistoryTask;
+ bool m_bNotifyForEndLoadingHistory;
+ bool m_bNotifyForEndLoadingHistoryAllContact;
+
private:
friend struct AsyncHttpRequest;
@@ -314,7 +322,7 @@ private:
CHMI_GETSERVERHISTORYLAST7DAY,
CHMI_GETSERVERHISTORYLAST30DAY,
CHMI_GETSERVERHISTORYLAST90DAY,
- CHMI_GETALLSERVERHISTORY,
+ CHMI_GETALLSERVERHISTORYFORCONTACT,
CHMI_COUNT
};
enum ProtoMenuIndexes {
@@ -322,6 +330,7 @@ private:
PMI_SETSTATUSMSG,
PMI_WALLPOST,
PMI_LOADVKNEWS,
+ PMI_GETALLSERVERHISTORY,
PMI_WIPENONFRIENDS,
PMI_VISITPROFILE,
PMI_COUNT