From 70c8a5106f992a68148fccf4187602a662e4f4da Mon Sep 17 00:00:00 2001 From: Sergey Bolhovskoy Date: Mon, 22 Dec 2014 07:08:03 +0000 Subject: =?UTF-8?q?VKontakte:=20separate=20intervals=20for=20news=20and=20?= =?UTF-8?q?notifications=20add=20options=20for=20safe=20special=20contact?= =?UTF-8?q?=20if=20news=20and=20notification=20is=20disabled=20fix=20for?= =?UTF-8?q?=20move=20special=20contact=20to=20non-default=20group=20add=20?= =?UTF-8?q?=E2=80=98load=20news=20from=20vk=E2=80=99=20to=20protocol=20men?= =?UTF-8?q?u=20and=20contact=20menu=20for=20special=20contact=20version=20?= =?UTF-8?q?bump?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit git-svn-id: http://svn.miranda-ng.org/main/trunk@11572 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- protocols/VKontakte/src/resource.h | 9 +++-- protocols/VKontakte/src/version.h | 2 +- protocols/VKontakte/src/vk_feed.cpp | 72 ++++++++++++++++++++++++---------- protocols/VKontakte/src/vk_options.cpp | 20 ++++++++-- protocols/VKontakte/src/vk_proto.cpp | 18 +++++++++ protocols/VKontakte/src/vk_proto.h | 13 ++++-- protocols/VKontakte/src/vk_thread.cpp | 3 +- 7 files changed, 103 insertions(+), 34 deletions(-) (limited to 'protocols/VKontakte/src') diff --git a/protocols/VKontakte/src/resource.h b/protocols/VKontakte/src/resource.h index 9ce31f0f30..404ab529ec 100644 --- a/protocols/VKontakte/src/resource.h +++ b/protocols/VKontakte/src/resource.h @@ -62,8 +62,11 @@ #define IDC_NEWS_ENBL 1054 #define IDC_NOTIF_ENBL 1055 #define IDC_BBC_NEWS 1056 -#define IDC_ED_INT 1057 -#define IDC_SPIN_INT 1058 +#define IDC_ED_INT_NEWS 1057 +#define IDC_SPIN_INT_NEWS 1058 +#define IDC_ED_INT_NOTIF 1059 +#define IDC_SPIN_INT_NOTIF 1060 +#define IDC_SPEC_CONT_ENBL 1061 // Next default values for new objects // @@ -72,7 +75,7 @@ #define _APS_NO_MFC 1 #define _APS_NEXT_RESOURCE_VALUE 118 #define _APS_NEXT_COMMAND_VALUE 40001 -#define _APS_NEXT_CONTROL_VALUE 1059 +#define _APS_NEXT_CONTROL_VALUE 1062 #define _APS_NEXT_SYMED_VALUE 101 #endif #endif diff --git a/protocols/VKontakte/src/version.h b/protocols/VKontakte/src/version.h index c66a5036da..e416a29a63 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 33 +#define __BUILD_NUM 34 #include diff --git a/protocols/VKontakte/src/vk_feed.cpp b/protocols/VKontakte/src/vk_feed.cpp index 9452ed5da8..72e48360b3 100644 --- a/protocols/VKontakte/src/vk_feed.cpp +++ b/protocols/VKontakte/src/vk_feed.cpp @@ -21,26 +21,32 @@ static char* szImageTypes[] = { "photo_2560", "photo_1280", "photo_807", "photo_ void CVkProto::AddFeedSpecialUser() { - bool bSpecialContact = m_bNewsEnabled || m_bNotificationsEnabled; - MCONTACT hContact = FindUser(VK_FEED_USER, bSpecialContact); + bool bSpecialContact = m_bNewsEnabled || m_bNotificationsEnabled || m_bSpecialContactAlwaysEnabled; + + MCONTACT hContact = FindUser(VK_FEED_USER); if (!bSpecialContact) { if (hContact) CallService(MS_DB_CONTACT_DELETE, (WPARAM)hContact, 0); return; } + + if (!hContact) { + hContact = FindUser(VK_FEED_USER, true); + CMString tszNick = TranslateT("VKontakte"); - CMString tszNick = TranslateT("VKontakte"); - setTString(hContact, "Nick", tszNick.GetBuffer()); - CMString url = _T("https://vk.com/press/Simple.png"); - SetAvatarUrl(hContact, url); - ReloadAvatarInfo(hContact); + setTString(hContact, "Nick", tszNick.GetBuffer()); + CMString tszUrl = _T("https://vk.com/press/Simple.png"); + SetAvatarUrl(hContact, tszUrl); + ReloadAvatarInfo(hContact); + + setTString(hContact, "domain", _T("feed")); + setTString(hContact, "Homepage", _T("https://vk.com/feed")); + } if (getWord(hContact, "Status", 0) != ID_STATUS_ONLINE) setWord(hContact, "Status", ID_STATUS_ONLINE); SetMirVer(hContact, 7); - setTString(hContact, "domain", _T("feed")); - setTString(hContact, "Homepage", _T("https://vk.com/feed")); } void CVkProto::AddFeedEvent(CMString& tszBody, time_t tTime) @@ -397,14 +403,10 @@ CMString CVkProto::GetVkNotificationsItem(JSONNODE *pItem, OBJLIST ////////////////////////////////////////////////////////////////////////////////////////////////////////// -void CVkProto::RetrieveUnreadNews() +void CVkProto::RetrieveUnreadNews(time_t tLastNewsTime) { debugLogA("CVkProto::RetrieveUnreadNews"); - if (!IsOnline() || !m_bNewsEnabled) - return; - - time_t tLastNewsTime = getDword("LastNewsTime", time(NULL) - 24 * 60 * 60); - if (time(NULL) - tLastNewsTime <= m_iNewsInterval * 60) + if (!IsOnline()) return; Push(new AsyncHttpRequest(this, REQUEST_GET, "/method/newsfeed.get.json", true, &CVkProto::OnReceiveUnreadNews) @@ -447,14 +449,10 @@ void CVkProto::OnReceiveUnreadNews(NETLIBHTTPREQUEST *reply, AsyncHttpRequest *p ////////////////////////////////////////////////////////////////////////////////////////////////////////// -void CVkProto::RetrieveUnreadNotifications() +void CVkProto::RetrieveUnreadNotifications(time_t tLastNotificationsTime) { debugLogA("CVkProto::RetrieveUnreadNotifications"); - if (!IsOnline() || !m_bNotificationsEnabled) - return; - - time_t tLastNotificationsTime = getDword("LastNotificationsTime", time(NULL) - 24 * 60 * 60); - if (time(NULL) - tLastNotificationsTime <= m_iNewsInterval * 60) + if (!IsOnline()) return; Push(new AsyncHttpRequest(this, REQUEST_GET, "/method/notifications.get.json", true, &CVkProto::OnReceiveUnreadNotifications) @@ -490,4 +488,36 @@ void CVkProto::OnReceiveUnreadNotifications(NETLIBHTTPREQUEST *reply, AsyncHttpR setDword("LastNotificationsTime", time(NULL)); vkUsers.destroy(); +} + +void CVkProto::RetrieveUnreadEvents() +{ + debugLogA("CVkProto::RetrieveUnreadEvents"); + if (!IsOnline() || (!m_bNotificationsEnabled && !m_bNewsEnabled)) + return; + + time_t tLastNotificationsTime = getDword("LastNotificationsTime", time(NULL) - 24 * 60 * 60); + if (time(NULL) - tLastNotificationsTime >= m_iNotificationsInterval * 60 && m_bNotificationsEnabled) + RetrieveUnreadNotifications(tLastNotificationsTime); + + time_t tLastNewsTime = getDword("LastNewsTime", time(NULL) - 24 * 60 * 60); + if (time(NULL) - tLastNewsTime >= m_iNewsInterval * 60 && m_bNewsEnabled) + RetrieveUnreadNews(tLastNewsTime); + +} + +INT_PTR CVkProto::SvcLoadVKNews(WPARAM, LPARAM) +{ + if (!IsOnline()) + return 1; + + if (!m_bNewsEnabled && !m_bNotificationsEnabled){ + m_bSpecialContactAlwaysEnabled = true; + AddFeedSpecialUser(); + } + + time_t tLastNewsTime = getDword("LastNewsTime", time(NULL) - 24 * 60 * 60); + RetrieveUnreadNews(tLastNewsTime); + + return 0; } \ No newline at end of file diff --git a/protocols/VKontakte/src/vk_options.cpp b/protocols/VKontakte/src/vk_options.cpp index 7b5c51b0a1..a6f4aa46b0 100644 --- a/protocols/VKontakte/src/vk_options.cpp +++ b/protocols/VKontakte/src/vk_options.cpp @@ -354,22 +354,28 @@ INT_PTR CALLBACK CVkProto::OptionsFeedsProc(HWND hwndDlg, UINT uMsg, WPARAM wPar CheckDlgButton(hwndDlg, IDC_NEWS_ENBL, ppro->m_bNewsEnabled ? BST_CHECKED : BST_UNCHECKED); CheckDlgButton(hwndDlg, IDC_NOTIF_ENBL, ppro->m_bNotificationsEnabled ? BST_CHECKED : BST_UNCHECKED); + CheckDlgButton(hwndDlg, IDC_SPEC_CONT_ENBL, ppro->m_bSpecialContactAlwaysEnabled ? BST_CHECKED : BST_UNCHECKED); CheckDlgButton(hwndDlg, IDC_BBC_NEWS, ppro->m_bBBCOnNews ? BST_CHECKED : BST_UNCHECKED); - SendDlgItemMessage(hwndDlg, IDC_SPIN_INT, UDM_SETRANGE, 0, MAKELONG(60*24, 1)); - SendDlgItemMessage(hwndDlg, IDC_SPIN_INT, UDM_SETPOS, 0, ppro->m_iNewsInterval); + SendDlgItemMessage(hwndDlg, IDC_SPIN_INT_NEWS, UDM_SETRANGE, 0, MAKELONG(60*24, 1)); + SendDlgItemMessage(hwndDlg, IDC_SPIN_INT_NEWS, UDM_SETPOS, 0, ppro->m_iNewsInterval); + + SendDlgItemMessage(hwndDlg, IDC_SPIN_INT_NOTIF, UDM_SETRANGE, 0, MAKELONG(60 * 24, 1)); + SendDlgItemMessage(hwndDlg, IDC_SPIN_INT_NOTIF, UDM_SETPOS, 0, ppro->m_iNotificationsInterval); return TRUE; case WM_COMMAND: switch (LOWORD(wParam)) { - case IDC_ED_INT: + case IDC_ED_INT_NEWS: + case IDC_ED_INT_NOTIF: if ((HWND)lParam == GetFocus() && (HIWORD(wParam) == EN_CHANGE)) SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0); break; case IDC_NEWS_ENBL: case IDC_NOTIF_ENBL: + case IDC_SPEC_CONT_ENBL: case IDC_BBC_NEWS: if (HIWORD(wParam) == BN_CLICKED && (HWND)lParam == GetFocus()) SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0); @@ -388,12 +394,18 @@ INT_PTR CALLBACK CVkProto::OptionsFeedsProc(HWND hwndDlg, UINT uMsg, WPARAM wPar ppro->m_bNotificationsEnabled = IsDlgButtonChecked(hwndDlg, IDC_NOTIF_ENBL) == BST_CHECKED; ppro->setByte("NotificationsEnabled", ppro->m_bNotificationsEnabled); + ppro->m_bSpecialContactAlwaysEnabled = IsDlgButtonChecked(hwndDlg, IDC_SPEC_CONT_ENBL) == BST_CHECKED; + ppro->setByte("SpecialContactAlwaysEnabled", ppro->m_bSpecialContactAlwaysEnabled); + ppro->m_bBBCOnNews = IsDlgButtonChecked(hwndDlg, IDC_BBC_NEWS) == BST_CHECKED; ppro->setByte("BBCOnNews", ppro->m_bBBCOnNews); TCHAR buffer[5] = { 0 }; - GetDlgItemText(hwndDlg, IDC_ED_INT, buffer, SIZEOF(buffer)); + GetDlgItemText(hwndDlg, IDC_ED_INT_NEWS, buffer, SIZEOF(buffer)); ppro->setDword("NewsInterval", ppro->m_iNewsInterval = _ttoi(buffer)); + + GetDlgItemText(hwndDlg, IDC_ED_INT_NOTIF, buffer, SIZEOF(buffer)); + ppro->setDword("NotificationsInterval", ppro->m_iNotificationsInterval = _ttoi(buffer)); } break; diff --git a/protocols/VKontakte/src/vk_proto.cpp b/protocols/VKontakte/src/vk_proto.cpp index 5786d5aa0e..11a71fa2d8 100644 --- a/protocols/VKontakte/src/vk_proto.cpp +++ b/protocols/VKontakte/src/vk_proto.cpp @@ -80,8 +80,10 @@ CVkProto::CVkProto(const char *szModuleName, const TCHAR *ptszUserName) : db_set_b(NULL, "ListeningTo", szListeningTo.GetBuffer(), m_iMusicSendMetod == 0 ? 0 : 1); m_bNewsEnabled = getBool("NewsEnabled", false); m_bNotificationsEnabled = getBool("NotificationsEnabled", false); + m_bSpecialContactAlwaysEnabled = getBool("SpecialContactAlwaysEnabled", false); m_bBBCOnNews = getBool("BBCOnNews", false); m_iNewsInterval = getDword("NewsInterval", 15); + m_iNotificationsInterval = getDword("NotificationsInterval", 1); // Set all contacts offline -- in case we crashed SetAllContactStatuses(ID_STATUS_OFFLINE); @@ -147,6 +149,7 @@ void CVkProto::InitMenus() CreateProtoService(PS_REPORTABUSE, &CVkProto::SvcReportAbuse); CreateProtoService(PS_DESTROYKICKCHAT, &CVkProto::SvcDestroyKickChat); CreateProtoService(PS_OPENBROADCAST, &CVkProto::SvcOpenBroadcast); + CreateProtoService(PS_LOADVKNEWS, &CVkProto::SvcLoadVKNews); CLISTMENUITEM mi = { sizeof(mi) }; char szService[100]; @@ -161,6 +164,13 @@ void CVkProto::InitMenus() mi.icolibItem = LoadSkinnedIconHandle(SKINICON_CHAT_JOIN); mi.pszName = LPGEN("Create new chat"); g_hProtoMenuItems[PMI_CREATECHAT] = Menu_AddProtoMenuItem(&mi); + + mir_snprintf(szService, SIZEOF(szService), "%s%s", m_szModuleName, PS_LOADVKNEWS); + mi.pszService = szService; + mi.position = 10009 + PMI_LOADVKNEWS; + mi.icolibItem = Skin_GetIconByHandle(GetIconHandle(IDI_NOTIFICATION)); + mi.pszName = LPGEN("Load news from VK"); + g_hProtoMenuItems[PMI_LOADVKNEWS] = Menu_AddProtoMenuItem(&mi); mir_snprintf(szService, SIZEOF(szService), "%s%s", m_szModuleName, PS_VISITPROFILE); mi.pszService = szService; @@ -219,6 +229,13 @@ void CVkProto::InitMenus() mi.pszService = szService; g_hContactMenuItems[CMI_OPENBROADCAST] = Menu_AddContactMenuItem(&mi); + mir_snprintf(szService, SIZEOF(szService), "%s%s", m_szModuleName, PS_LOADVKNEWS); + mi.pszService = szService; + mi.position = -200001000 + CMI_LOADVKNEWS; + mi.icolibItem = Skin_GetIconByHandle(GetIconHandle(IDI_NOTIFICATION)); + mi.ptszName = LPGENT("Load news from VK"); + g_hContactMenuItems[CMI_LOADVKNEWS] = Menu_AddContactMenuItem(&mi); + // Sync history menu mir_snprintf(szService, SIZEOF(szService), "%s%s", m_szModuleName, PS_GETSERVERHISTORY); mi.position = -200001000 + CMI_GETSERVERHISTORY; @@ -287,6 +304,7 @@ int CVkProto::OnPreBuildContactMenu(WPARAM hContact, LPARAM) Menu_ShowItem(g_hContactMenuItems[CMI_DESTROYKICKCHAT], isChatRoom(hContact) && getBool(hContact, "off", false)); Menu_ShowItem(g_hContactMenuItems[CMI_OPENBROADCAST], !isChatRoom(hContact) && bisBroadcast); Menu_ShowItem(g_hContactMenuItems[CMI_GETSERVERHISTORY], !isChatRoom(hContact) && userID != VK_FEED_USER); + Menu_ShowItem(g_hContactMenuItems[CMI_LOADVKNEWS], userID == VK_FEED_USER); for (int i = 0; i < CHMI_COUNT; i++) Menu_ShowItem(g_hContactHistoryMenuItems[i], !isChatRoom(hContact) && userID != VK_FEED_USER); return 0; diff --git a/protocols/VKontakte/src/vk_proto.h b/protocols/VKontakte/src/vk_proto.h index 632ea47f60..4540ad7999 100644 --- a/protocols/VKontakte/src/vk_proto.h +++ b/protocols/VKontakte/src/vk_proto.h @@ -16,6 +16,7 @@ along with this program. If not, see . */ #define PS_CREATECHAT "/CreateNewChat" +#define PS_LOADVKNEWS "/LoadVKNews" #define PS_GETSERVERHISTORY "/SyncHistory" #define PS_GETSERVERHISTORYLAST1DAY "/GetServerHystoryLast1Day" #define PS_GETSERVERHISTORYLAST3DAY "/GetServerHystoryLast3Day" @@ -330,11 +331,14 @@ struct CVkProto : public PROTO CMString GetVkFeedback(JSONNODE *pFeedback, VKObjType vkFeedbackType, OBJLIST &vkUsers, CVkUserInfo *vkUser); CMString GetVkParent(JSONNODE *pParent, VKObjType vkParentType); - void RetrieveUnreadNews(); + void RetrieveUnreadNews(time_t tLastNewsTime); void OnReceiveUnreadNews(NETLIBHTTPREQUEST*, AsyncHttpRequest*); - void RetrieveUnreadNotifications(); + void RetrieveUnreadNotifications(time_t tLastNotificationsTime); void OnReceiveUnreadNotifications(NETLIBHTTPREQUEST*, AsyncHttpRequest*); + void CVkProto::RetrieveUnreadEvents(); + + INT_PTR __cdecl SvcLoadVKNews(WPARAM, LPARAM); CMString SpanVKNotificationType(CMString& tszType, VKObjType& vkFeedback, VKObjType& vkParent); @@ -418,6 +422,7 @@ private: CMI_REPORTABUSE, CMI_DESTROYKICKCHAT, CMI_OPENBROADCAST, + CMI_LOADVKNEWS, CMI_GETSERVERHISTORY, CMI_COUNT }; @@ -433,6 +438,7 @@ private: }; enum ProtoMenuIndexes { PMI_CREATECHAT, + PMI_LOADVKNEWS, PMI_VISITPROFILE, PMI_COUNT }; @@ -500,9 +506,10 @@ private: m_bUserForceOnlineOnActivity, m_bNewsEnabled, m_bNotificationsEnabled, + m_bSpecialContactAlwaysEnabled, m_bBBCOnNews; - int m_iNewsInterval; + int m_iNewsInterval, m_iNotificationsInterval; enum MarkMsgReadOn{ markOnRead, markOnReceive, markOnReply, markOnTyping }; int m_iMarkMessageReadOn; diff --git a/protocols/VKontakte/src/vk_thread.cpp b/protocols/VKontakte/src/vk_thread.cpp index 15bf752f69..71990dd0a5 100644 --- a/protocols/VKontakte/src/vk_thread.cpp +++ b/protocols/VKontakte/src/vk_thread.cpp @@ -54,8 +54,7 @@ static VOID CALLBACK TimerProc(HWND, UINT, UINT_PTR, DWORD) if (vk_Instances[i]->IsOnline()) { vk_Instances[i]->SetServerStatus(vk_Instances[i]->m_iDesiredStatus); vk_Instances[i]->RetrieveUsersInfo(true); - vk_Instances[i]->RetrieveUnreadNews(); - vk_Instances[i]->RetrieveUnreadNotifications(); + vk_Instances[i]->RetrieveUnreadEvents(); } } -- cgit v1.2.3