diff options
author | Sergey Bolhovskoy <elzorfox@ya.ru> | 2015-04-16 03:02:56 +0000 |
---|---|---|
committer | Sergey Bolhovskoy <elzorfox@ya.ru> | 2015-04-16 03:02:56 +0000 |
commit | beba9d5e9ab1240bc17f0c7fa0d50f1be7633594 (patch) | |
tree | 25ca7cf1c6a6cbc543936abe538063202920506c /protocols/VKontakte/src | |
parent | f76455fc258fb45cb17b571ac2d34f8f3d5ef8d3 (diff) |
VKontakte:
add invite support
version bump
git-svn-id: http://svn.miranda-ng.org/main/trunk@12852 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'protocols/VKontakte/src')
-rw-r--r-- | protocols/VKontakte/src/misc.cpp | 4 | ||||
-rw-r--r-- | protocols/VKontakte/src/resource.h | 3 | ||||
-rw-r--r-- | protocols/VKontakte/src/version.h | 2 | ||||
-rw-r--r-- | protocols/VKontakte/src/vk_feed.cpp | 123 | ||||
-rw-r--r-- | protocols/VKontakte/src/vk_options.cpp | 7 | ||||
-rw-r--r-- | protocols/VKontakte/src/vk_proto.cpp | 3 | ||||
-rw-r--r-- | protocols/VKontakte/src/vk_proto.h | 4 | ||||
-rw-r--r-- | protocols/VKontakte/src/vk_queue.cpp | 13 |
8 files changed, 132 insertions, 27 deletions
diff --git a/protocols/VKontakte/src/misc.cpp b/protocols/VKontakte/src/misc.cpp index 8d3a6c1295..1bc717248c 100644 --- a/protocols/VKontakte/src/misc.cpp +++ b/protocols/VKontakte/src/misc.cpp @@ -799,6 +799,10 @@ CMString CVkProto::SpanVKNotificationType(CMString& tszType, VKObjType& vkFeedba {
CVKNotification vkNotification[] = {
// type, parent, feedback, string for translate
+ { _T("group"), vkInvite, vkNull, _T("has invited you to a group") },
+ { _T("page"), vkInvite, vkNull, _T("has invited you to subscribe to a page") },
+ { _T("event"), vkInvite, vkNull, _T("invites you to event") },
+
{ _T("follow"), vkNull, vkUsers, _T("") },
{ _T("friend_accepted"), vkNull, vkUsers, _T("") },
{ _T("mention"), vkNull, vkPost, _T("") },
diff --git a/protocols/VKontakte/src/resource.h b/protocols/VKontakte/src/resource.h index 8f71ff1966..a9029746e6 100644 --- a/protocols/VKontakte/src/resource.h +++ b/protocols/VKontakte/src/resource.h @@ -104,6 +104,7 @@ #define IDC_ONLY_FRIENDS 1093
#define IDC_ST_WARNING 1095
#define IDC_NOTIF_MARK_VIEWED 1096
+#define IDC_N_INVITES 1097
// Next default values for new objects
//
@@ -112,7 +113,7 @@ #define _APS_NO_MFC 1
#define _APS_NEXT_RESOURCE_VALUE 122
#define _APS_NEXT_COMMAND_VALUE 40001
-#define _APS_NEXT_CONTROL_VALUE 1097
+#define _APS_NEXT_CONTROL_VALUE 1098
#define _APS_NEXT_SYMED_VALUE 101
#endif
#endif
diff --git a/protocols/VKontakte/src/version.h b/protocols/VKontakte/src/version.h index b153785e9c..ad23326b0b 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 52
+#define __BUILD_NUM 53
#include <stdver.h>
diff --git a/protocols/VKontakte/src/vk_feed.cpp b/protocols/VKontakte/src/vk_feed.cpp index abe233451a..fd2de60bf3 100644 --- a/protocols/VKontakte/src/vk_feed.cpp +++ b/protocols/VKontakte/src/vk_feed.cpp @@ -110,7 +110,10 @@ void CVkProto::CreateVkUserInfoList(OBJLIST<CVkUserInfo> &vkUsers, JSONNODE *pRe tszNick.AppendChar(' ');
tszNick += json_as_CMString(json_get(pProfile, "last_name"));
CMString tszLink = _T("https://vk.com/");
- tszLink += json_as_CMString(json_get(pProfile, "screen_name"));
+ CMString tszScreenName = json_as_CMString(json_get(pProfile, "screen_name"));
+ if (tszScreenName.IsEmpty())
+ tszScreenName.AppendFormat(_T("id%d"), UserId);
+ tszLink += tszScreenName;
CVkUserInfo * vkUser = new CVkUserInfo(UserId, false, tszNick, tszLink, FindUser(UserId));
vkUsers.insert(vkUser);
}
@@ -433,6 +436,51 @@ CVKNewsItem* CVkProto::GetVkNotificationsItem(JSONNODE *pItem, OBJLIST<CVkUserIn return NULL;
}
+CVKNewsItem* CVkProto::GetVkGroupInvates(JSONNODE *pItem, OBJLIST<CVkUserInfo> &vkUsers)
+{
+ debugLogA("CVkProto::GetVkGroupInvates");
+ if (pItem == NULL)
+ return NULL;
+
+ CMString tszType = json_as_CMString(json_get(pItem, "type"));
+ VKObjType vkFeedbackType = vkNull, vkParentType = vkNull;
+ CMString tszNotificationTranslate = SpanVKNotificationType(tszType, vkFeedbackType, vkParentType);
+ LONG iGroupId = json_as_int(json_get(pItem, "id"));
+
+ if (iGroupId == 0)
+ return NULL;
+
+ CMString tszId;
+ tszId.AppendFormat(_T("%d,"), iGroupId);
+ CMString tszIds = ptrT(db_get_tsa(NULL, m_szModuleName, "InviteGroupIds"));
+
+ if (tszIds.Find(tszId, 0) != -1)
+ return NULL;
+
+ LONG iUserId = json_as_int(json_get(pItem, "invited_by"));
+ CVKNewsItem *vkNotification = new CVKNewsItem();
+ vkNotification->tDate = time(NULL);
+ vkNotification->vkUser = GetVkUserInfo(iUserId, vkUsers);
+ vkNotification->tszType = tszType;
+ vkNotification->tszId = tszId;
+ vkNotification->vkFeedbackType = vkFeedbackType;
+ vkNotification->vkParentType = vkParentType;
+
+ CMString tszGroupName, tszGName, tszGLink;
+ tszGName = json_as_CMString(json_get(pItem, "name"));
+ tszGLink.AppendFormat(_T("https://vk.com/%s"), json_as_CMString(json_get(pItem, "screen_name")).GetBuffer());
+ tszGroupName = SetBBCString(tszGName.GetBuffer(), m_iBBCForNews, vkbbcUrl, tszGLink.GetBuffer());
+
+ CMString tszUsers = SetBBCString(vkNotification->vkUser->m_tszUserNick.GetBuffer(), m_iBBCForNews, vkbbcUrl, vkNotification->vkUser->m_tszLink.GetBuffer());
+
+ vkNotification->tszText.AppendFormat(_T("%s %s %s"), tszUsers.GetBuffer(), tszNotificationTranslate.GetBuffer(), tszGroupName.GetBuffer());
+
+ tszIds += tszId;
+ setTString("InviteGroupIds", tszIds);
+
+ return vkNotification;
+}
+
//////////////////////////////////////////////////////////////////////////////////////////////////////////
void CVkProto::RetrieveUnreadNews(time_t tLastNewsTime)
@@ -536,11 +584,15 @@ void CVkProto::RetrieveUnreadNotifications(time_t tLastNotificationsTime) debugLogA("CVkProto::RetrieveUnreadNotifications");
if (!IsOnline())
return;
-
- Push(new AsyncHttpRequest(this, REQUEST_GET, "/method/notifications.get.json", true, &CVkProto::OnReceiveUnreadNotifications)
- << INT_PARAM("count", 100)
- << INT_PARAM("start_time", tLastNotificationsTime + 1)
- << VER_API);
+
+ 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)
+ << TCHAR_PARAM("code", code.GetBuffer())
+ << VER_API);
}
bool CVkProto::FilterNotification(CVKNewsItem* vkNotificationItem, bool& isCommented)
@@ -559,6 +611,7 @@ bool CVkProto::FilterNotification(CVKNewsItem* vkNotificationItem, bool& isComme bool result = (vkNotificationItem->vkFeedbackType == vkUsers && m_bNotificationFilterLikes);
result = (vkNotificationItem->vkFeedbackType == vkCopy && m_bNotificationFilterReposts) || result;
result = (vkNotificationItem->vkFeedbackType == vkComment && m_bNotificationFilterComments) || result;
+ result = (vkNotificationItem->vkParentType == vkInvite && m_bNotificationFilterInvites) || result;
isCommented = (vkNotificationItem->vkFeedbackType == vkComment);
@@ -586,35 +639,61 @@ void CVkProto::OnReceiveUnreadNotifications(NETLIBHTTPREQUEST *reply, AsyncHttpR if (pResponse == NULL)
return;
+ JSONNODE *pNotifications = json_get(pResponse, "notifications");
+ JSONNODE *pGroupInvates = json_get(pResponse, "groupinvates");
+
OBJLIST<CVkUserInfo> vkUsers(5, NumericKeySortT);
- CreateVkUserInfoList(vkUsers, pResponse);
+ OBJLIST<CVKNewsItem> vkNotification(5, sttCompareVKNewsItems);
+
+ CreateVkUserInfoList(vkUsers, pNotifications);
+ CreateVkUserInfoList(vkUsers, pGroupInvates);
- JSONNODE *pItems = json_get(pResponse, "items");
- JSONNODE *pItem;
+ JSONNODE *pItems, *pItem;
- OBJLIST<CVKNewsItem> vkNotification(5, sttCompareVKNewsItems);
- if (pItems != NULL)
- for (int i = 0; (pItem = json_at(pItems, i)) != NULL; i++) {
- CVKNewsItem *vkNotificationItem = GetVkNotificationsItem(pItem, vkUsers);
- if (!vkNotificationItem)
- continue;
- if (vkNotification.find(vkNotificationItem) == NULL)
- vkNotification.insert(vkNotificationItem);
- else
- delete vkNotificationItem;
- }
+ if (pNotifications != NULL) {
+
+ pItems = json_get(pNotifications, "items");
+
+ if (pItems != NULL)
+ for (int i = 0; (pItem = json_at(pItems, i)) != NULL; i++) {
+ CVKNewsItem *vkNotificationItem = GetVkNotificationsItem(pItem, vkUsers);
+ if (!vkNotificationItem)
+ continue;
+ if (vkNotification.find(vkNotificationItem) == NULL)
+ vkNotification.insert(vkNotificationItem);
+ else
+ delete vkNotificationItem;
+ }
+
+ }
+
+ if (pGroupInvates != NULL) {
+ pItems = json_get(pGroupInvates, "items");
+
+ if (pItems != NULL)
+ for (int i = 0; (pItem = json_at(pItems, i)) != NULL; i++) {
+ CVKNewsItem *vkNotificationItem = GetVkGroupInvates(pItem, vkUsers);
+ if (!vkNotificationItem)
+ continue;
+ if (vkNotification.find(vkNotificationItem) == NULL)
+ vkNotification.insert(vkNotificationItem);
+ else
+ delete vkNotificationItem;
+ }
+ }
bool bNotificationCommentAdded = false;
bool bNotificationComment = false;
for (int i = 0; i < vkNotification.getCount(); i++)
- if (FilterNotification(&vkNotification[i], bNotificationComment)) {
+ if (FilterNotification(&vkNotification[i], bNotificationComment)) {
AddFeedEvent(vkNotification[i].tszText, vkNotification[i].tDate);
bNotificationCommentAdded = bNotificationComment || bNotificationCommentAdded;
}
-
+
setDword("LastNotificationsTime", time(NULL));
if (m_bNotificationsMarkAsViewed && bNotificationCommentAdded)
NotificationMarkAsViewed();
+
vkNotification.destroy();
vkUsers.destroy();
}
diff --git a/protocols/VKontakte/src/vk_options.cpp b/protocols/VKontakte/src/vk_options.cpp index e87594c40f..37ce884a2d 100644 --- a/protocols/VKontakte/src/vk_options.cpp +++ b/protocols/VKontakte/src/vk_options.cpp @@ -384,6 +384,7 @@ INT_PTR CALLBACK CVkProto::OptionsFeedsProc(HWND hwndDlg, UINT uMsg, WPARAM wPar CheckDlgButton(hwndDlg, IDC_N_LIKES, ppro->m_bNotificationFilterLikes ? BST_CHECKED : BST_UNCHECKED);
CheckDlgButton(hwndDlg, IDC_N_REPOSTS, ppro->m_bNotificationFilterReposts ? BST_CHECKED : BST_UNCHECKED);
CheckDlgButton(hwndDlg, IDC_N_MENTIONS, ppro->m_bNotificationFilterMentions ? BST_CHECKED : BST_UNCHECKED);
+ CheckDlgButton(hwndDlg, IDC_N_INVITES, ppro->m_bNotificationFilterInvites ? BST_CHECKED : BST_UNCHECKED);
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);
@@ -420,6 +421,7 @@ INT_PTR CALLBACK CVkProto::OptionsFeedsProc(HWND hwndDlg, UINT uMsg, WPARAM wPar case IDC_N_LIKES:
case IDC_N_REPOSTS:
case IDC_N_MENTIONS:
+ case IDC_N_INVITES:
if (HIWORD(wParam) == BN_CLICKED && (HWND)lParam == GetFocus())
SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0);
break;
@@ -485,9 +487,12 @@ INT_PTR CALLBACK CVkProto::OptionsFeedsProc(HWND hwndDlg, UINT uMsg, WPARAM wPar ppro->m_bNotificationFilterReposts = IsDlgButtonChecked(hwndDlg, IDC_N_REPOSTS) == BST_CHECKED;
ppro->setByte("NotificationFilterReposts", ppro->m_bNotificationFilterReposts);
- ppro->m_bNotificationFilterMentions = IsDlgButtonChecked(hwndDlg, IDC_N_REPOSTS) == BST_CHECKED;
+ ppro->m_bNotificationFilterMentions = IsDlgButtonChecked(hwndDlg, IDC_N_MENTIONS) == BST_CHECKED;
ppro->setByte("NotificationFilterMentions", ppro->m_bNotificationFilterMentions);
+ ppro->m_bNotificationFilterInvites = IsDlgButtonChecked(hwndDlg, IDC_N_INVITES) == BST_CHECKED;
+ ppro->setByte("NotificationFilterInvites", ppro->m_bNotificationFilterInvites);
+
TCHAR buffer[5] = { 0 };
GetDlgItemText(hwndDlg, IDC_ED_INT_NEWS, buffer, SIZEOF(buffer));
ppro->setDword("NewsInterval", ppro->m_iNewsInterval = _ttoi(buffer));
diff --git a/protocols/VKontakte/src/vk_proto.cpp b/protocols/VKontakte/src/vk_proto.cpp index b2465541dd..33cb2da12e 100644 --- a/protocols/VKontakte/src/vk_proto.cpp +++ b/protocols/VKontakte/src/vk_proto.cpp @@ -114,12 +114,15 @@ CVkProto::CVkProto(const char *szModuleName, const TCHAR *ptszUserName) : m_bNotificationFilterLikes = getBool("NotificationFilterLikes", true);
m_bNotificationFilterReposts = getBool("NotificationFilterReposts", true);
m_bNotificationFilterMentions = getBool("NotificationFilterMentions", true);
+ m_bNotificationFilterInvites = getBool("NotificationFilterInvites", true);
m_bUseNonStandardUrlEncode = getBool("UseNonStandardUrlEncode", true);
m_iInvisibleInterval = getDword("InvisibleInterval", 10);
m_bSetBroadcast = false;
m_bNeedSendOnline = false;
+ delSetting("InviteGroupIds");
+
// Set all contacts offline -- in case we crashed
SetAllContactStatuses(ID_STATUS_OFFLINE);
vk_Instances.insert(this);
diff --git a/protocols/VKontakte/src/vk_proto.h b/protocols/VKontakte/src/vk_proto.h index cb85df89a7..a00a08466e 100644 --- a/protocols/VKontakte/src/vk_proto.h +++ b/protocols/VKontakte/src/vk_proto.h @@ -197,7 +197,7 @@ struct CVkUserInfo : public MZeroedObject { bool m_bIsGroup;
};
-enum VKObjType { vkNull, vkPost, vkPhoto, vkVideo, vkComment, vkTopic, vkUsers, vkCopy };
+enum VKObjType { vkNull, vkPost, vkPhoto, vkVideo, vkComment, vkTopic, vkUsers, vkCopy, vkInvite };
struct CVKNotification {
TCHAR *ptszType;
@@ -356,6 +356,7 @@ struct CVkProto : public PROTO<CVkProto> CVKNewsItem* GetVkNewsItem(JSONNODE *pItem, OBJLIST<CVkUserInfo> &vkUsers, bool isRepost = false);
+ CVKNewsItem* GetVkGroupInvates(JSONNODE *pItem, OBJLIST<CVkUserInfo> &vkUsers);
CVKNewsItem* GetVkNotificationsItem(JSONNODE *pItem, OBJLIST<CVkUserInfo> &vkUsers);
CMString GetVkFeedback(JSONNODE *pFeedback, VKObjType vkFeedbackType, OBJLIST<CVkUserInfo> &vkUsers, CVkUserInfo *vkUser);
CVKNewsItem* GetVkParent(JSONNODE *pParent, VKObjType vkParentType, TCHAR *ptszReplyText = NULL, TCHAR *ptszReplyLink = NULL);
@@ -582,6 +583,7 @@ private: m_bNotificationFilterLikes,
m_bNotificationFilterReposts,
m_bNotificationFilterMentions,
+ m_bNotificationFilterInvites,
m_bUseBBCOnAttacmentsAsNews,
m_bUseNonStandardUrlEncode,
m_bSetBroadcast;
diff --git a/protocols/VKontakte/src/vk_queue.cpp b/protocols/VKontakte/src/vk_queue.cpp index 64b9bc7c47..aed8f64e50 100644 --- a/protocols/VKontakte/src/vk_queue.cpp +++ b/protocols/VKontakte/src/vk_queue.cpp @@ -95,6 +95,17 @@ void CVkProto::WorkerThread(void*) debugLogA("CVkProto::WorkerThread: entering");
m_bTerminated = m_prevError = false;
m_szAccessToken = getStringA("AccessToken");
+
+ char Score[] = "friends,photos,audio,docs,video,wall,messages,offline,status,notifications,groups";
+
+ CMStringA szAccessScore = ptrA(getStringA("AccessScore"));
+ if (szAccessScore != Score) {
+ setString("AccessScore", Score);
+ delSetting("AccessToken");
+ m_szAccessToken = NULL;
+ }
+
+
if (m_szAccessToken != NULL)
// try to receive a response from server
RetrieveMyInfo();
@@ -103,7 +114,7 @@ void CVkProto::WorkerThread(void*) extern char szBlankUrl[];
AsyncHttpRequest *pReq = new AsyncHttpRequest(this, REQUEST_GET, "https://oauth.vk.com/authorize", false, &CVkProto::OnOAuthAuthorize)
<< INT_PARAM("client_id", VK_APP_ID)
- << CHAR_PARAM("scope", "friends,photos,audio,docs,video,wall,messages,offline,status,notifications")
+ << CHAR_PARAM("scope", Score)
<< CHAR_PARAM("redirect_uri", szBlankUrl)
<< CHAR_PARAM("display", "mobile")
<< CHAR_PARAM("response_type", "token")
|