summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--protocols/SkypeWeb/src/request_queue.cpp2
-rw-r--r--protocols/SkypeWeb/src/requests/chatrooms.h15
-rw-r--r--protocols/SkypeWeb/src/skype_chatrooms.cpp46
-rw-r--r--protocols/SkypeWeb/src/skype_proto.h9
-rw-r--r--protocols/SkypeWeb/src/stdafx.h1
5 files changed, 64 insertions, 9 deletions
diff --git a/protocols/SkypeWeb/src/request_queue.cpp b/protocols/SkypeWeb/src/request_queue.cpp
index 580658d4b6..3e1c51e57b 100644
--- a/protocols/SkypeWeb/src/request_queue.cpp
+++ b/protocols/SkypeWeb/src/request_queue.cpp
@@ -22,6 +22,7 @@ AsyncHttpRequest::AsyncHttpRequest(int type, SkypeHost host, LPCSTR url, MTHttpR
{
switch (host) {
case HOST_API: m_szUrl = "api.skype.com"; break;
+ case HOST_PEOPLE: m_szUrl = "people.skype.com/v2"; break;
case HOST_CONTACTS: m_szUrl = "contacts.skype.com/contacts/v2"; break;
case HOST_GRAPH: m_szUrl = "skypegraph.skype.com"; break;
case HOST_LOGIN: m_szUrl = "login.skype.com"; break;
@@ -103,6 +104,7 @@ MHttpResponse* CSkypeProto::DoSend(AsyncHttpRequest *pReq)
switch (pReq->m_host) {
case HOST_API:
+ case HOST_PEOPLE:
case HOST_CONTACTS:
if (m_szApiToken)
pReq->AddHeader((pReq->m_host == HOST_CONTACTS) ? "X-SkypeToken" : "X-Skypetoken", m_szApiToken);
diff --git a/protocols/SkypeWeb/src/requests/chatrooms.h b/protocols/SkypeWeb/src/requests/chatrooms.h
index a023a6bbe5..4e12b0c331 100644
--- a/protocols/SkypeWeb/src/requests/chatrooms.h
+++ b/protocols/SkypeWeb/src/requests/chatrooms.h
@@ -75,6 +75,21 @@ struct DestroyChatroomRequest : public AsyncHttpRequest
}
};
+struct GetChatMembersRequest : public AsyncHttpRequest
+{
+ GetChatMembersRequest(const LIST<char> &ids, SESSION_INFO *si) :
+ AsyncHttpRequest(REQUEST_POST, HOST_PEOPLE, "/profiles", &CSkypeProto::OnGetChatMembers)
+ {
+ JSONNode node, mris(JSON_ARRAY); mris.set_name("mris");
+ for (auto &it : ids)
+ mris.push_back(JSONNode("", it));
+ node << mris << CHAR_PARAM("locale", "en-US");
+ m_szParam = node.write().c_str();
+
+ pUserInfo = si;
+ }
+};
+
struct GetChatInfoRequest : public AsyncHttpRequest
{
GetChatInfoRequest(const wchar_t *chatId) :
diff --git a/protocols/SkypeWeb/src/skype_chatrooms.cpp b/protocols/SkypeWeb/src/skype_chatrooms.cpp
index eff2eabe7d..e3249b18e3 100644
--- a/protocols/SkypeWeb/src/skype_chatrooms.cpp
+++ b/protocols/SkypeWeb/src/skype_chatrooms.cpp
@@ -244,7 +244,11 @@ bool CSkypeProto::OnChatEvent(const JSONNode &node)
if (!doc.Parse(T2Utf(wszContent))) {
if (auto *pRoot = doc.FirstChildElement("addMember")) {
CMStringW target = Utf2T(XmlGetChildText(pRoot, "target"));
- AddChatContact(si, target, L"User");
+ if (!AddChatContact(si, target, L"User")) {
+ OBJLIST<char> arIds(1);
+ arIds.insert(mir_u2a(target));
+ PushRequest(new GetChatMembersRequest(arIds, si));
+ }
}
}
return true;
@@ -330,6 +334,24 @@ void CSkypeProto::SendChatMessage(SESSION_INFO *si, const wchar_t *tszMessage)
PushRequest(new SendChatMessageRequest(chat_id, time(0), szMessage));
}
+void CSkypeProto::OnGetChatMembers(MHttpResponse *response, AsyncHttpRequest *pRequest)
+{
+ JsonReply reply(response);
+ if (reply.error())
+ return;
+
+ auto &root = reply.data();
+ auto *si = (SESSION_INFO *)pRequest->pUserInfo;
+
+ for (auto &it : root["profiles"]) {
+ CMStringW wszUserId(Utf2T(it.name()));
+ if (auto *pUser = g_chatApi.UM_FindUser(si, wszUserId))
+ replaceStrW(pUser->pszNick, it["profile"]["displayName"].as_mstring());
+ }
+
+ g_chatApi.OnChangeNick(si);
+}
+
void CSkypeProto::OnGetChatInfo(MHttpResponse *response, AsyncHttpRequest*)
{
JsonReply reply(response);
@@ -346,17 +368,25 @@ void CSkypeProto::OnGetChatInfo(MHttpResponse *response, AsyncHttpRequest*)
if (si == nullptr)
return;
+ OBJLIST<char> arIds(1);
for (auto &member : root["members"]) {
CMStringW username(UrlToSkypeId(member["userLink"].as_mstring()));
CMStringW role = member["role"].as_mstring();
- AddChatContact(si, username, role, true);
+ if (!AddChatContact(si, username, role, true))
+ arIds.insert(newStr(mir_u2a(username)));
}
+ if (arIds.getCount())
+ PushRequest(new GetChatMembersRequest(arIds, si));
+
PushRequest(new GetHistoryRequest(si->hContact, T2Utf(si->ptszID), 100, 0, true));
}
-wchar_t* CSkypeProto::GetChatContactNick(MCONTACT hContact, const wchar_t *id, const wchar_t *name)
+wchar_t* CSkypeProto::GetChatContactNick(MCONTACT hContact, const wchar_t *id, const wchar_t *name, bool *isQualified)
{
+ if (isQualified)
+ *isQualified = true;
+
// Check if there is custom nick for this chat contact
if (hContact)
if (auto *tname = db_get_wsa(hContact, "UsersNicks", T2Utf(id)))
@@ -381,15 +411,19 @@ wchar_t* CSkypeProto::GetChatContactNick(MCONTACT hContact, const wchar_t *id, c
}
}
+ if (isQualified)
+ *isQualified = false;
+
// Return default value as nick - given name or user id
if (name != nullptr)
return mir_wstrdup(name);
return mir_wstrdup(GetSkypeNick(id));
}
-void CSkypeProto::AddChatContact(SESSION_INFO *si, const wchar_t *id, const wchar_t *role, bool isChange)
+bool CSkypeProto::AddChatContact(SESSION_INFO *si, const wchar_t *id, const wchar_t *role, bool isChange)
{
- ptrW szNick(GetChatContactNick(si->hContact, id));
+ bool isQualified;
+ ptrW szNick(GetChatContactNick(si->hContact, id, 0, &isQualified));
GCEVENT gce = { si, GC_EVENT_JOIN };
gce.dwFlags = GCEF_ADDTOLOG;
@@ -399,6 +433,8 @@ void CSkypeProto::AddChatContact(SESSION_INFO *si, const wchar_t *id, const wcha
gce.bIsMe = IsMe(id);
gce.pszStatus.w = TranslateW(role);
Chat_Event(&gce);
+
+ return isQualified;
}
void CSkypeProto::RemoveChatContact(SESSION_INFO *si, const wchar_t *id, bool isKick, const wchar_t *initiator)
diff --git a/protocols/SkypeWeb/src/skype_proto.h b/protocols/SkypeWeb/src/skype_proto.h
index b242ad4142..a22705c211 100644
--- a/protocols/SkypeWeb/src/skype_proto.h
+++ b/protocols/SkypeWeb/src/skype_proto.h
@@ -156,16 +156,17 @@ public:
void OnUnblockContact(MHttpResponse *response, AsyncHttpRequest *pRequest);
void OnMessageSent(MHttpResponse *response, AsyncHttpRequest *pRequest);
+ void OnReceiveAwayMsg(MHttpResponse *response, AsyncHttpRequest *pRequest);
void OnGetServerHistory(MHttpResponse *response, AsyncHttpRequest *pRequest);
void OnSyncConversations(MHttpResponse *response, AsyncHttpRequest *pRequest);
void OnGetChatInfo(MHttpResponse *response, AsyncHttpRequest *pRequest);
- void OnReceiveAwayMsg(MHttpResponse *response, AsyncHttpRequest *pRequest);
+ void OnGetChatMembers(MHttpResponse *response, AsyncHttpRequest *pRequest);
void CheckConvert(void);
-
bool CheckOauth(const char *szResponse);
+
void LoadProfile(MHttpResponse *response, AsyncHttpRequest *pRequest);
static INT_PTR __cdecl GlobalParseSkypeUriService(WPARAM, LPARAM lParam);
@@ -272,9 +273,9 @@ private:
SESSION_INFO* StartChatRoom(const wchar_t *tid, const wchar_t *tname);
bool OnChatEvent(const JSONNode &node);
- wchar_t* GetChatContactNick(MCONTACT hContact, const wchar_t *id, const wchar_t *name = nullptr);
+ wchar_t* GetChatContactNick(MCONTACT hContact, const wchar_t *id, const wchar_t *name = nullptr, bool *isQualified = nullptr);
- void AddChatContact(SESSION_INFO *si, const wchar_t *id, const wchar_t *role, bool isChange = false);
+ bool AddChatContact(SESSION_INFO *si, const wchar_t *id, const wchar_t *role, bool isChange = false);
void RemoveChatContact(SESSION_INFO *si, const wchar_t *id, bool isKick = false, const wchar_t *initiator = L"");
void SendChatMessage(SESSION_INFO *si, const wchar_t *tszMessage);
diff --git a/protocols/SkypeWeb/src/stdafx.h b/protocols/SkypeWeb/src/stdafx.h
index b053df673b..35f3a49207 100644
--- a/protocols/SkypeWeb/src/stdafx.h
+++ b/protocols/SkypeWeb/src/stdafx.h
@@ -96,6 +96,7 @@ enum SkypeHost
HOST_DEFAULT,
HOST_GRAPH,
HOST_LOGIN,
+ HOST_PEOPLE,
HOST_OTHER
};