summaryrefslogtreecommitdiff
path: root/protocols/VKontakte/src
diff options
context:
space:
mode:
authorSergey Bolhovskoy <elzorfox@ya.ru>2015-07-09 10:33:09 +0000
committerSergey Bolhovskoy <elzorfox@ya.ru>2015-07-09 10:33:09 +0000
commit21c6c7a7cb65e25d55cce54b6e097c797b66f95e (patch)
tree0c8485de41cf9c550d8e7ed930bf8ba9f6b0b3e4 /protocols/VKontakte/src
parent3f42d3319d2a3e404db524428300ab0a8a9540b2 (diff)
VKontakte:
add locks for timer and vk_Instances fix mark messages as read in multiaccaunt configuration fix duplicate events and news version bump git-svn-id: http://svn.miranda-ng.org/main/trunk@14514 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'protocols/VKontakte/src')
-rw-r--r--protocols/VKontakte/src/version.h2
-rw-r--r--protocols/VKontakte/src/vk.h1
-rw-r--r--protocols/VKontakte/src/vk_feed.cpp22
-rw-r--r--protocols/VKontakte/src/vk_messages.cpp7
-rw-r--r--protocols/VKontakte/src/vk_proto.cpp11
-rw-r--r--protocols/VKontakte/src/vk_proto.h1
-rw-r--r--protocols/VKontakte/src/vk_thread.cpp21
7 files changed, 54 insertions, 11 deletions
diff --git a/protocols/VKontakte/src/version.h b/protocols/VKontakte/src/version.h
index 102e1daee0..b9104246f3 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 1
-#define __BUILD_NUM 8
+#define __BUILD_NUM 9
#include <stdver.h>
diff --git a/protocols/VKontakte/src/vk.h b/protocols/VKontakte/src/vk.h
index 4ee5ce3eac..8687a19dba 100644
--- a/protocols/VKontakte/src/vk.h
+++ b/protocols/VKontakte/src/vk.h
@@ -80,6 +80,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
struct CVkProto;
extern LIST<CVkProto> vk_Instances;
+extern mir_cs csInstances;
extern HINSTANCE hInst;
LPCSTR findHeader(NETLIBHTTPREQUEST *hdr, LPCSTR szField);
diff --git a/protocols/VKontakte/src/vk_feed.cpp b/protocols/VKontakte/src/vk_feed.cpp
index cf7978fcd5..487040ffb5 100644
--- a/protocols/VKontakte/src/vk_feed.cpp
+++ b/protocols/VKontakte/src/vk_feed.cpp
@@ -488,6 +488,10 @@ void CVkProto::RetrieveUnreadNews(time_t tLastNewsTime)
debugLogA("CVkProto::RetrieveUnreadNews");
if (!IsOnline())
return;
+
+ time_t tLastNewsReqTime = getDword("LastNewsReqTime", time(NULL) - 24 * 60 * 60);
+ if (time(NULL) - tLastNewsReqTime < 3 * 60)
+ return;
CMStringA szFilter;
szFilter = m_bNewsFilterPosts ? "post" : "";
@@ -523,14 +527,16 @@ void CVkProto::RetrieveUnreadNews(time_t tLastNewsTime)
return;
}
- Push(new AsyncHttpRequest(this, REQUEST_GET, "/method/newsfeed.get.json", true, &CVkProto::OnReceiveUnreadNews)
+ Push(new AsyncHttpRequest(this, REQUEST_GET, "/method/newsfeed.get.json", true, &CVkProto::OnReceiveUnreadNews))
<< INT_PARAM("count", 100)
<< INT_PARAM("return_banned", m_bNewsSourceIncludeBanned ? 1 : 0)
<< INT_PARAM("max_photos", m_iMaxLoadNewsPhoto)
<< INT_PARAM("start_time", tLastNewsTime + 1)
<< CHAR_PARAM("filters", szFilter)
<< CHAR_PARAM("source_ids", szSource)
- << VER_API);
+ << VER_API;
+
+ setDword("LastNewsReqTime", (DWORD)time(NULL));
}
static int sttCompareVKNewsItems(const CVKNewsItem *p1, const CVKNewsItem *p2)
@@ -554,6 +560,7 @@ static int sttCompareVKNotificationItems(const CVKNewsItem *p1, const CVKNewsIte
void CVkProto::OnReceiveUnreadNews(NETLIBHTTPREQUEST *reply, AsyncHttpRequest *pReq)
{
debugLogA("CVkProto::OnReceiveUnreadNews %d", reply->resultCode);
+ db_unset(NULL, m_szModuleName, "LastNewsReqTime");
if (reply->resultCode != 200)
return;
@@ -602,14 +609,20 @@ void CVkProto::RetrieveUnreadNotifications(time_t tLastNotificationsTime)
if (!IsOnline())
return;
+ time_t tLastNotificationsReqTime = getDword("LastNotificationsReqTime", time(NULL) - 24 * 60 * 60);
+ if (time(NULL) - tLastNotificationsReqTime < 3 * 60)
+ return;
+
CMString code;
code.AppendFormat(_T("return{\"notifications\":API.notifications.get({\"count\": 100, \"start_time\":%d})%s"),
(LONG)(tLastNotificationsTime + 1),
m_bNotificationFilterInvites ? _T(",\"groupinvates\":API.groups.getInvites({\"extended\":1})};") : _T("};"));
- Push(new AsyncHttpRequest(this, REQUEST_GET, "/method/execute.json", true, &CVkProto::OnReceiveUnreadNotifications)
+ Push(new AsyncHttpRequest(this, REQUEST_GET, "/method/execute.json", true, &CVkProto::OnReceiveUnreadNotifications))
<< TCHAR_PARAM("code", code)
- << VER_API);
+ << VER_API;
+
+ setDword("LastNotificationsReqTime", (DWORD)time(NULL));
}
bool CVkProto::FilterNotification(CVKNewsItem* vkNotificationItem, bool& isCommented)
@@ -648,6 +661,7 @@ void CVkProto::NotificationMarkAsViewed()
void CVkProto::OnReceiveUnreadNotifications(NETLIBHTTPREQUEST *reply, AsyncHttpRequest *pReq)
{
debugLogA("CVkProto::OnReceiveUnreadNotifications %d", reply->resultCode);
+ db_unset(NULL, m_szModuleName, "LastNotificationsReqTime");
if (reply->resultCode != 200)
return;
diff --git a/protocols/VKontakte/src/vk_messages.cpp b/protocols/VKontakte/src/vk_messages.cpp
index 657c56471b..a8970be976 100644
--- a/protocols/VKontakte/src/vk_messages.cpp
+++ b/protocols/VKontakte/src/vk_messages.cpp
@@ -126,6 +126,13 @@ void CVkProto::OnSendMessage(NETLIBHTTPREQUEST *reply, AsyncHttpRequest *pReq)
int CVkProto::OnDbEventRead(WPARAM hContact, LPARAM)
{
debugLogA("CVkProto::OnDbEventRead");
+ if (!hContact)
+ return 0;
+
+ CMString szProto(ptrA(db_get_sa(hContact, "Protocol", "p")));
+ if (szProto.IsEmpty() || szProto != m_szModuleName)
+ return 0;
+
if (m_iMarkMessageReadOn == markOnRead)
MarkMessagesRead(hContact);
return 0;
diff --git a/protocols/VKontakte/src/vk_proto.cpp b/protocols/VKontakte/src/vk_proto.cpp
index efa6adfc2d..7ea79a813a 100644
--- a/protocols/VKontakte/src/vk_proto.cpp
+++ b/protocols/VKontakte/src/vk_proto.cpp
@@ -30,6 +30,7 @@ static int sttCompareAsyncHttpRequest(const AsyncHttpRequest *p1, const AsyncHtt
}
LIST<CVkProto> vk_Instances(1, sttCompareProtocols);
+mir_cs csInstances;
static COLORREF sttColors[] = { 0, 1, 2, 3, 4, 5, 6 };
CVkProto::CVkProto(const char *szModuleName, const TCHAR *ptszUserName) :
@@ -125,7 +126,10 @@ CVkProto::CVkProto(const char *szModuleName, const TCHAR *ptszUserName) :
// Set all contacts offline -- in case we crashed
SetAllContactStatuses(ID_STATUS_OFFLINE);
- vk_Instances.insert(this);
+ {
+ mir_cslock lck(csInstances);
+ vk_Instances.insert(this);
+ }
}
CVkProto::~CVkProto()
@@ -139,7 +143,10 @@ CVkProto::~CVkProto()
Popup_UnregisterClass(m_hPopupClassError);
if (m_hPopupClassNotification)
Popup_UnregisterClass(m_hPopupClassNotification);
- vk_Instances.remove(this);
+ {
+ mir_cslock lck(csInstances);
+ vk_Instances.remove(this);
+ }
}
int CVkProto::OnModulesLoaded(WPARAM, LPARAM)
diff --git a/protocols/VKontakte/src/vk_proto.h b/protocols/VKontakte/src/vk_proto.h
index 4273d2b606..b041ef89b9 100644
--- a/protocols/VKontakte/src/vk_proto.h
+++ b/protocols/VKontakte/src/vk_proto.h
@@ -469,6 +469,7 @@ struct CVkProto : public PROTO<CVkProto>
__forceinline LPCTSTR getGroup() const { return m_defaultGroup; }
__forceinline void setGroup(LPCTSTR grp) { m_defaultGroup = mir_tstrdup(grp); }
+ static mir_cs m_csTimer;
static UINT_PTR m_timer;
private:
diff --git a/protocols/VKontakte/src/vk_thread.cpp b/protocols/VKontakte/src/vk_thread.cpp
index f609250406..0261f4ad6a 100644
--- a/protocols/VKontakte/src/vk_thread.cpp
+++ b/protocols/VKontakte/src/vk_thread.cpp
@@ -18,6 +18,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "stdafx.h"
UINT_PTR CVkProto::m_timer;
+mir_cs CVkProto::m_csTimer;
+
char szBlankUrl[] = "https://oauth.vk.com/blank.html";
static char VK_TOKEN_BEG[] = "access_token=";
static char VK_LOGIN_DOMAIN[] = "https://m.vk.com";
@@ -49,8 +51,10 @@ void CVkProto::ConnectionFailed(int iReason)
static VOID CALLBACK TimerProc(HWND, UINT, UINT_PTR, DWORD)
{
+ mir_cslock lck(csInstances);
for (int i = 0; i < vk_Instances.getCount(); i++)
if (vk_Instances[i]->IsOnline()) {
+ vk_Instances[i]->debugLogA("Tic timer for %i - %s", i, vk_Instances[i]->m_szModuleName);
vk_Instances[i]->SetServerStatus(vk_Instances[i]->m_iDesiredStatus);
vk_Instances[i]->RetrieveUsersInfo(true);
vk_Instances[i]->RetrieveUnreadEvents();
@@ -59,11 +63,15 @@ static VOID CALLBACK TimerProc(HWND, UINT, UINT_PTR, DWORD)
static void CALLBACK VKSetTimer(void*)
{
+ mir_cslock lck(CVkProto::m_csTimer);
+ if (CVkProto::m_timer)
+ return;
CVkProto::m_timer = SetTimer(NULL, 0, 60000, TimerProc);
}
static void CALLBACK VKUnsetTimer(void*)
{
+ mir_cslock lck(CVkProto::m_csTimer);
if (CVkProto::m_timer)
KillTimer(NULL, CVkProto::m_timer);
CVkProto::m_timer = 0;
@@ -78,8 +86,10 @@ void CVkProto::OnLoggedIn()
SetServerStatus(m_iDesiredStatus);
// initialize online timer
- if (!m_timer)
- CallFunctionAsync(VKSetTimer, this);
+ CallFunctionAsync(VKSetTimer, this);
+
+ db_unset(NULL, m_szModuleName, "LastNewsReqTime");
+ db_unset(NULL, m_szModuleName, "LastNotificationsReqTime");
}
void CVkProto::OnLoggedOut()
@@ -94,8 +104,11 @@ void CVkProto::OnLoggedOut()
m_iStatus = m_iDesiredStatus = ID_STATUS_OFFLINE;
bool bOnline = false;
- for (int i = 0; i < vk_Instances.getCount(); i++)
- bOnline = bOnline || vk_Instances[i]->IsOnline();
+ {
+ mir_cslock lck(csInstances);
+ for (int i = 0; i < vk_Instances.getCount(); i++)
+ bOnline = bOnline || vk_Instances[i]->IsOnline();
+ }
if (!bOnline)
CallFunctionAsync(VKUnsetTimer, this);
SetAllContactStatuses(ID_STATUS_OFFLINE);