diff options
author | ElzorFox <elzorfox@ya.ru> | 2019-02-09 13:28:12 +0500 |
---|---|---|
committer | ElzorFox <elzorfox@ya.ru> | 2019-02-09 14:26:21 +0500 |
commit | cf25657511e567a9ce2278661393aec73ae743b3 (patch) | |
tree | 5a5328946acb9f92f06d5f6423bdd7eaee0af65d /protocols/VKontakte | |
parent | f1f2e30c147faf3ee68c47e9ade1cc38e36e2f23 (diff) |
VKontakte: preparation for transition to new VK_API version – stage 0.1
Diffstat (limited to 'protocols/VKontakte')
-rw-r--r-- | protocols/VKontakte/src/vk_chats.cpp | 30 | ||||
-rw-r--r-- | protocols/VKontakte/src/vk_files.cpp | 2 | ||||
-rw-r--r-- | protocols/VKontakte/src/vk_proto.h | 1 | ||||
-rw-r--r-- | protocols/VKontakte/src/vk_struct.cpp | 188 | ||||
-rw-r--r-- | protocols/VKontakte/src/vk_struct.h | 88 |
5 files changed, 289 insertions, 20 deletions
diff --git a/protocols/VKontakte/src/vk_chats.cpp b/protocols/VKontakte/src/vk_chats.cpp index 406582b9fc..7603de598a 100644 --- a/protocols/VKontakte/src/vk_chats.cpp +++ b/protocols/VKontakte/src/vk_chats.cpp @@ -100,7 +100,7 @@ void CVkProto::RetrieveChatInfo(CVkChatInfo *cc) debugLogA("CVkProto::RetrieveChatInfo");
Push(new AsyncHttpRequest(this, REQUEST_GET, "/method/execute.RetrieveChatInfo", true, &CVkProto::OnReceiveChatInfo)
- << INT_PARAM("chatid", cc->m_chatid)
+ << INT_PARAM("chatid", cc->m_iChatId)
<< INT_PARAM("func_v", cc->m_bHistoryRead ? 1 : 2)
)->pUserInfo = cc;
}
@@ -127,10 +127,10 @@ void CVkProto::OnReceiveChatInfo(NETLIBHTTPREQUEST *reply, AsyncHttpRequest *pRe if (jnInfo["left"].as_bool() || jnInfo["kicked"].as_bool()) {
setByte(cc->m_hContact, "kicked", jnInfo["kicked"].as_bool());
- LeaveChat(cc->m_chatid);
+ LeaveChat(cc->m_iChatId);
return;
}
- cc->m_admin_id = jnInfo["admin_id"].as_int();
+ cc->m_iAdminId = jnInfo["admin_id"].as_int();
}
const JSONNode &jnUsers = jnResponse["users"];
@@ -170,7 +170,7 @@ void CVkProto::OnReceiveChatInfo(NETLIBHTTPREQUEST *reply, AsyncHttpRequest *pRe gce.bIsMe = uid == m_myUserId;
gce.ptszUID = wszId;
gce.ptszNick = wszNick;
- gce.ptszStatus = TranslateW(sttStatuses[uid == cc->m_admin_id]);
+ gce.ptszStatus = TranslateW(sttStatuses[uid == cc->m_iAdminId]);
gce.dwItemData = (INT_PTR)cu;
Chat_Event(&gce);
}
@@ -219,7 +219,7 @@ void CVkProto::OnReceiveChatInfo(NETLIBHTTPREQUEST *reply, AsyncHttpRequest *pRe if (!jnMsg)
break;
- AppendChatMessage(cc->m_chatid, jnMsg, jnFUsers, true);
+ AppendChatMessage(cc->m_iChatId, jnMsg, jnFUsers, true);
}
cc->m_bHistoryRead = true;
}
@@ -284,7 +284,7 @@ void CVkProto::AppendChatMessage(int id, const JSONNode &jnMsg, const JSONNode & if (m_vkOptions.bAddMessageLinkToMesWAtt && (jnAttachments || jnFwdMessages))
wszBody += SetBBCString(TranslateT("Message link"), bbcNo, vkbbcUrl,
- CMStringW(FORMAT, L"https://vk.com/im?sel=c%d&msgid=%d", cc->m_chatid, mid));
+ CMStringW(FORMAT, L"https://vk.com/im?sel=c%d&msgid=%d", cc->m_iChatId, mid));
if (jnMsg["action"]) {
bIsAction = true;
@@ -405,7 +405,7 @@ void CVkProto::AppendChatMessage(CVkChatInfo *cc, int uid, int msgTime, LPCWSTR gce.ptszNick = cu->m_wszNick ? mir_wstrdup(cu->m_wszNick) : mir_wstrdup(hContact ? ptrW(db_get_wsa(hContact, m_szModuleName, "Nick")) : TranslateT("Unknown"));
gce.ptszText = IsEmpty((wchar_t *)pwszBody) ? mir_wstrdup(L"...") : mir_wstrdup(pwszBody);
Chat_Event(&gce);
- StopChatContactTyping(cc->m_chatid, uid);
+ StopChatContactTyping(cc->m_iChatId, uid);
}
/////////////////////////////////////////////////////////////////////////////////////////
@@ -525,7 +525,7 @@ void CVkProto::LogMenuHook(CVkChatInfo *cc, GCHOOK *gch) if (LPTSTR pwszNew = ChangeChatTopic(cc)) {
Push(new AsyncHttpRequest(this, REQUEST_GET, "/method/messages.editChat.json", true, &CVkProto::OnReceiveSmth)
<< WCHAR_PARAM("title", pwszNew)
- << INT_PARAM("chat_id", cc->m_chatid));
+ << INT_PARAM("chat_id", cc->m_iChatId));
mir_free(pwszNew);
}
break;
@@ -538,7 +538,7 @@ void CVkProto::LogMenuHook(CVkChatInfo *cc, GCHOOK *gch) if (uid != VK_INVALID_USER)
Push(new AsyncHttpRequest(this, REQUEST_GET, "/method/messages.addChatUser.json", true, &CVkProto::OnReceiveSmth)
<< INT_PARAM("user_id", uid)
- << INT_PARAM("chat_id", cc->m_chatid));
+ << INT_PARAM("chat_id", cc->m_iChatId));
}
}
break;
@@ -549,7 +549,7 @@ void CVkProto::LogMenuHook(CVkChatInfo *cc, GCHOOK *gch) TranslateT("Warning"), MB_YESNO | MB_ICONQUESTION)
)
Push(new AsyncHttpRequest(this, REQUEST_GET, "/method/execute.DestroyChat", true, &CVkProto::OnChatDestroy)
- << INT_PARAM("chatid", cc->m_chatid)
+ << INT_PARAM("chatid", cc->m_iChatId)
<< INT_PARAM("userid", m_myUserId)
)->pUserInfo = cc;
@@ -590,7 +590,7 @@ INT_PTR __cdecl CVkProto::OnLeaveChat(WPARAM hContact, LPARAM) return 1;
Push(new AsyncHttpRequest(this, REQUEST_GET, "/method/messages.removeChatUser.json", true, &CVkProto::OnChatLeave)
- << INT_PARAM("chat_id", cc->m_chatid)
+ << INT_PARAM("chat_id", cc->m_iChatId)
<< INT_PARAM("user_id", m_myUserId))->pUserInfo = cc;
return 0;
@@ -654,7 +654,7 @@ void CVkProto::OnChatLeave(NETLIBHTTPREQUEST *reply, AsyncHttpRequest *pReq) return;
CVkChatInfo *cc = (CVkChatInfo*)pReq->pUserInfo;
- LeaveChat(cc->m_chatid);
+ LeaveChat(cc->m_iChatId);
}
INT_PTR __cdecl CVkProto::SvcDestroyKickChat(WPARAM hContact, LPARAM)
@@ -686,7 +686,7 @@ void CVkProto::OnChatDestroy(NETLIBHTTPREQUEST *reply, AsyncHttpRequest *pReq) return;
CVkChatInfo *cc = (CVkChatInfo*)pReq->pUserInfo;
- LeaveChat(cc->m_chatid, true, true);
+ LeaveChat(cc->m_iChatId, true, true);
}
/////////////////////////////////////////////////////////////////////////////////////////
@@ -700,7 +700,7 @@ void CVkProto::NickMenuHook(CVkChatInfo *cc, GCHOOK *gch) char szUid[20], szChatId[20];
_itoa(cu->m_uid, szUid, 10);
- _itoa(cc->m_chatid, szChatId, 10);
+ _itoa(cc->m_iChatId, szChatId, 10);
switch (gch->dwData) {
case IDM_INFO:
@@ -750,7 +750,7 @@ void CVkProto::NickMenuHook(CVkChatInfo *cc, GCHOOK *gch) return;
Push(new AsyncHttpRequest(this, REQUEST_GET, "/method/messages.removeChatUser.json", true, &CVkProto::OnReceiveSmth)
- << INT_PARAM("chat_id", cc->m_chatid)
+ << INT_PARAM("chat_id", cc->m_iChatId)
<< INT_PARAM("user_id", cu->m_uid));
cu->m_bUnknown = true;
diff --git a/protocols/VKontakte/src/vk_files.cpp b/protocols/VKontakte/src/vk_files.cpp index 740bf42486..2160a722a9 100644 --- a/protocols/VKontakte/src/vk_files.cpp +++ b/protocols/VKontakte/src/vk_files.cpp @@ -355,7 +355,7 @@ void CVkProto::OnReciveUploadFile(NETLIBHTTPREQUEST *reply, AsyncHttpRequest *pR }
pMsgReq = new AsyncHttpRequest(this, REQUEST_POST, "/method/messages.send.json", true, &CVkProto::OnSendChatMsg, AsyncHttpRequest::rpHigh);
- pMsgReq << INT_PARAM("chat_id", cc->m_chatid);
+ pMsgReq << INT_PARAM("chat_id", cc->m_iChatId);
pMsgReq->pUserInfo = pReq->pUserInfo;
}
diff --git a/protocols/VKontakte/src/vk_proto.h b/protocols/VKontakte/src/vk_proto.h index d1d073ec2a..64bfc9c29d 100644 --- a/protocols/VKontakte/src/vk_proto.h +++ b/protocols/VKontakte/src/vk_proto.h @@ -129,6 +129,7 @@ struct CVkProto : public PROTO<CVkProto> private:
friend struct AsyncHttpRequest;
+ friend class CVkUserItem;
//==== Enums =========================================================================
diff --git a/protocols/VKontakte/src/vk_struct.cpp b/protocols/VKontakte/src/vk_struct.cpp index 375efbd82b..4793891447 100644 --- a/protocols/VKontakte/src/vk_struct.cpp +++ b/protocols/VKontakte/src/vk_struct.cpp @@ -229,4 +229,190 @@ CVKOptions::CVKOptions(PROTO_INTERFACE *proto) : db_unset(0, proto->m_szModuleName, "AutoClean");
}
// Note
-}
\ No newline at end of file +}
+
+
+
+////////////////////////////////////////////////////////////////////////////////////////////////////
+
+void CVkUserItem::LoadFromUserProfile(const JSONNode &jnNode)
+{
+ if (!jnNode)
+ return;
+
+ Set(m_bIsGroup, false);
+ Set(m_bIsUser, true);
+ Set(m_bIsMUChat, false);
+ Set(m_bIsEmail, false);
+
+ Set(m_iUserId, jnNode["id"].as_int());
+ Set(m_wszFirstName, jnNode["first_name"].as_mstring());
+ Set(m_wszLastName, jnNode["last_name"].as_mstring());
+
+ Set(m_bIsFriend, jnNode["is_friend"].as_bool());
+
+ Set(m_wszUserNick, m_wszFirstName + L" " + m_wszLastName);
+
+ m_bIsDeactivated = !Set(m_wszDeactivated, jnNode["deactivated"].as_mstring()).IsEmpty();
+
+ Set(m_btGender, BYTE(jnNode["sex"].as_int() == 2 ? 'M' : 'F'));
+ Set(m_btTimezone, BYTE(jnNode["timezone"].as_int() * -2));
+
+ Set(m_wszBDate, jnNode["bdate"].as_mstring());
+ Set(m_wszAvatarUrl, jnNode["photo_100"].as_mstring());
+
+ Set(m_wszCellular, jnNode["mobile_phone"].as_mstring());
+ Set(m_wszPhone, jnNode["home_phone"].as_mstring());
+
+ const JSONNode &jnLastSeen = jnNode["last_seen"];
+ if (jnLastSeen)
+ Set(m_iLastSeen, jnLastSeen["time"].as_int());
+
+ Set(m_iStatus, LONG((jnNode["online"].as_int() == 0) ? ID_STATUS_OFFLINE : ID_STATUS_ONLINE));
+
+ const JSONNode &jnCountry = jnNode["country"];
+ if (jnCountry)
+ Set(m_wszCountry, jnCountry["title"].as_mstring());
+
+ const JSONNode &jnCity = jnNode["city"];
+ if (jnCity)
+ Set(m_wszCity, jnCity["title"].as_mstring());
+
+ BYTE cMaritalStatus[] = { 0, 10, 11, 12, 20, 70, 50, 60, 80 };
+
+ if (jnNode["relation"] && jnNode["relation"].as_int() < _countof(cMaritalStatus))
+ Set(m_btMaritalStatus, cMaritalStatus[jnNode["relation"].as_int()]);
+
+ Set(m_wszAbout, jnNode["about"].as_mstring());
+ Set(m_wszDomain, jnNode["domain"].as_mstring());
+}
+
+
+void CVkUserItem::LoadFromConversation(const JSONNode &jnNode)
+{
+ if (!jnNode)
+ return;
+
+ Set(m_bIsGroup, false);
+ Set(m_bIsUser, false);
+ Set(m_bIsMUChat, false);
+ Set(m_bIsEmail, false);
+
+ Set(m_bIsFriend, false);
+
+ const JSONNode &jnPeer = jnNode["peer"];
+
+ CMStringW wszConversationType(jnPeer["type"].as_mstring());
+
+ if (wszConversationType.IsEmpty())
+ return;
+
+ if (wszConversationType == L"user") {
+ Set(m_bIsUser, true);
+ Set(m_iUserId, jnPeer["id"].as_int());
+ }
+ else if (wszConversationType == L"chat") {
+ Set(m_bIsMUChat, true);
+ Set(m_iUserId, jnPeer["id"].as_int());
+ Set(m_iChatId, jnPeer["local_id"].as_int());
+
+ const JSONNode &jnChatS = jnNode["chat_settings"];
+
+ Set(m_wszUserNick, jnChatS["title"].as_mstring());
+ Set(m_iAdminId, jnChatS["owner_id"].as_int());
+ }
+ else if (wszConversationType == L"group") {
+ Set(m_bIsGroup, true);
+ Set(m_iUserId, jnPeer["id"].as_int());
+ }
+
+ Set(m_iLastMsgId, jnNode["last_message_id"].as_int());
+}
+
+void CVkUserItem::LoadFromGroup(const JSONNode & jnNode)
+{
+ if (!jnNode)
+ return;
+
+ Set(m_bIsGroup, true);
+ Set(m_bIsUser, false);
+ Set(m_bIsMUChat, false);
+ Set(m_bIsEmail, false);
+
+ Set(m_iUserId, -1 * jnNode["id"].as_int());
+
+ Set(m_bIsFriend, jnNode["is_member"].as_bool());
+ Set(m_wszUserNick, jnNode["name"].as_mstring());
+
+ Set(m_wszAvatarUrl, jnNode["photo_100"].as_mstring());
+
+ Set(m_wszDomain, jnNode["screen_name"].as_mstring());
+}
+
+MCONTACT CVkUserItem::WriteToDB(bool bForce, VKContactType vkContactType)
+{
+ if (!bForce && !m_bIsUpdated)
+ return m_hContact;
+
+// Work in process...
+
+// LONG m_iUserId;
+// LONG m_iChatId;
+// LONG m_iAdminId;
+
+// LONG m_iStatus;
+// LONG m_iLastSeen;
+// LONG m_iLastMsgId;
+
+// MCONTACT m_hContact;
+
+// CMStringW m_wszFirstName;
+// CMStringW m_wszLastName;
+// CMStringW m_wszUserNick;
+// CMStringW m_wszLink;
+// CMStringW m_wszDeactivated;
+// CMStringW m_wszCellular;
+// CMStringW m_wszPhone;
+// CMStringW m_wszCountry;
+// CMStringW m_wszCity;
+// CMStringW m_wszAbout;
+// CMStringW m_wszDomain;
+// CMStringW m_wszBDate;
+// CMStringW m_wszAvatarUrl;
+
+// BYTE m_btGender;
+// BYTE m_btTimezone;
+// BYTE m_btMaritalStatus;
+
+// bool m_bIsGroup;
+// bool m_bIsFriend;
+// bool m_bIsUser;
+// bool m_bIsEmail;
+// bool m_bIsMUChat;
+// bool m_bIsDeactivated;
+
+// bool m_bIsHidden;
+// bool m_bIsUpdated;
+
+ return m_hContact;
+}
+
+CVkUserItem::CVkUserItem(CVkProto* vkProto, const JSONNode &jnNode, vkJSONNodeType vkJSONType)
+{
+ m_VK = vkProto;
+ m_iUserId = 0;
+
+ if (!jnNode)
+ return;
+
+ if (vkJSONTypeProfile == vkJSONType)
+ LoadFromUserProfile(jnNode);
+ else if (vkJSONTypeConversation == vkJSONType)
+ LoadFromConversation(jnNode);
+ else if (vkJSONTypeGroup == vkJSONType)
+ LoadFromGroup(jnNode);
+
+
+ m_hContact = m_bIsMUChat ? m_VK->FindChat(m_iChatId) : m_VK->FindUser(m_iUserId);
+ m_hContact = m_hContact ? m_hContact : INVALID_CONTACT_ID;
+}
diff --git a/protocols/VKontakte/src/vk_struct.h b/protocols/VKontakte/src/vk_struct.h index c659b04313..f6fb01ddc8 100644 --- a/protocols/VKontakte/src/vk_struct.h +++ b/protocols/VKontakte/src/vk_struct.h @@ -119,13 +119,13 @@ struct CVkChatInfo : public MZeroedObject CVkChatInfo(int _id) :
m_users(10, NumericKeySortT),
m_msgs(10, NumericKeySortT),
- m_chatid(_id),
- m_admin_id(0),
+ m_iChatId(_id),
+ m_iAdminId(0),
m_bHistoryRead(0),
m_hContact(INVALID_CONTACT_ID)
{}
- int m_chatid, m_admin_id;
+ int m_iChatId, m_iAdminId;
bool m_bHistoryRead;
ptrW m_wszTopic, m_wszId;
MCONTACT m_hContact;
@@ -332,3 +332,85 @@ struct CVKDeactivateEvent { enum VKContactType : BYTE { vkContactNormal, vkContactSelf, vkContactMUCUser };
enum VKMesType : BYTE { vkALL, vkIN, vkOUT };
+///////////////////////////////////////////////////////////////////////////////////////////////
+
+enum vkJSONNodeType { vkJSONTypeProfile = 0, vkJSONTypeGroup, vkJSONTypeConversation };
+
+class CVkUserItem : public MZeroedObject {
+ CVkUserItem(CVkProto* vkProto, const JSONNode& jnNode, vkJSONNodeType vkJSONType = vkJSONTypeProfile);
+
+ CVkUserItem(LONG _UserId) :
+ m_iUserId(_UserId),
+ m_bIsGroup(false)
+ {}
+
+ CVkUserItem(LONG _UserId, bool _bIsGroup, CMStringW& _wszUserNick, CMStringW& _wszLink, MCONTACT _hContact = 0) :
+ m_iUserId(_UserId),
+ m_bIsGroup(_bIsGroup),
+ m_wszUserNick(_wszUserNick),
+ m_wszLink(_wszLink),
+ m_hContact(_hContact)
+ {}
+
+ /*
+ "id, first_name, last_name, photo_100, bdate, sex, timezone, contacts, last_seen, online, status, country, city, relation, interests, activities, music, movies, tv, books, games, quotes, about, domain, is_friend";
+ */
+ LONG m_iKey;
+
+ LONG m_iUserId;
+ LONG m_iChatId;
+
+ LONG m_iAdminId;
+
+
+ LONG m_iStatus;
+ LONG m_iLastSeen;
+ LONG m_iLastMsgId;
+
+ MCONTACT m_hContact;
+
+ CMStringW m_wszFirstName;
+ CMStringW m_wszLastName;
+ CMStringW m_wszUserNick;
+ CMStringW m_wszLink;
+ CMStringW m_wszDeactivated;
+ CMStringW m_wszCellular;
+ CMStringW m_wszPhone;
+ CMStringW m_wszCountry;
+ CMStringW m_wszCity;
+ CMStringW m_wszAbout;
+ CMStringW m_wszDomain;
+ CMStringW m_wszBDate;
+ CMStringW m_wszAvatarUrl;
+
+ BYTE m_btGender;
+ BYTE m_btTimezone;
+ BYTE m_btMaritalStatus;
+
+ bool m_bIsGroup;
+ bool m_bIsFriend;
+ bool m_bIsUser;
+ bool m_bIsEmail;
+ bool m_bIsMUChat;
+ bool m_bIsDeactivated;
+
+ bool m_bIsHidden;
+ bool m_bIsUpdated;
+
+ CVkProto* m_VK;
+
+ void LoadFromUserProfile(const JSONNode &jnNode);
+ void LoadFromConversation(const JSONNode &jnNode);
+ void LoadFromGroup(const JSONNode &jnNode);
+
+ MCONTACT WriteToDB(bool bForce = false, VKContactType vkContactType = VKContactType::vkContactNormal);
+
+ template <class T>
+ T Set(T& PropertyName, T Value) {
+ m_bIsUpdated = (PropertyName == Value);
+ PropertyName = Value;
+ }
+
+
+};
+
|