summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--protocols/Teams/src/teams_contacts.cpp18
-rw-r--r--protocols/Teams/src/teams_history.cpp39
-rw-r--r--protocols/Teams/src/teams_http.cpp4
-rw-r--r--protocols/Teams/src/teams_proto.h2
4 files changed, 45 insertions, 18 deletions
diff --git a/protocols/Teams/src/teams_contacts.cpp b/protocols/Teams/src/teams_contacts.cpp
index 24b986cbd5..63926c6245 100644
--- a/protocols/Teams/src/teams_contacts.cpp
+++ b/protocols/Teams/src/teams_contacts.cpp
@@ -229,6 +229,24 @@ void CTeamsProto::OnGotContactsInfo(MHttpResponse *response, AsyncHttpRequest*)
/////////////////////////////////////////////////////////////////////////////////////////
+void CTeamsProto::GetShortInfo(const OBJLIST<char> &ids)
+{
+ auto *pReq = new AsyncHttpRequest(REQUEST_POST, HOST_TEAMS_API, "/users/fetchShortProfile?isMailAddress=false&canBeSmtpAddress=false&enableGuest=true&includeIBBarredUsers=true&skypeTeamsInfo=true&includeBots=true");
+
+ for (auto &it : ids) {
+ if (pReq->m_szParam.IsEmpty())
+ pReq->m_szParam = "[";
+ else
+ pReq->m_szParam += ",";
+ pReq->m_szParam.AppendFormat("\"%s\"", it);
+ }
+ pReq->m_szParam += "]";
+
+ PushRequest(pReq);
+}
+
+/////////////////////////////////////////////////////////////////////////////////////////
+
INT_PTR CTeamsProto::OnRequestAuth(WPARAM hContact, LPARAM)
{
return AuthRequest(hContact, 0);
diff --git a/protocols/Teams/src/teams_history.cpp b/protocols/Teams/src/teams_history.cpp
index aaf26da642..e83d660eb4 100644
--- a/protocols/Teams/src/teams_history.cpp
+++ b/protocols/Teams/src/teams_history.cpp
@@ -28,6 +28,17 @@ void CTeamsProto::RefreshConversations()
PushRequest(pReq);
}
+void CTeamsProto::FetchMissingHistory(const JSONNode &node, MCONTACT hContact)
+{
+ const JSONNode &lastMessage = node["lastMessage"];
+ if (lastMessage && hContact) {
+ int64_t id = _atoi64(lastMessage["id"].as_string().c_str());
+ auto lastMsgTime = getLastTime(hContact);
+ if (lastMsgTime && lastMsgTime < id && m_bAutoHistorySync)
+ GetServerHistory(hContact, 100, lastMsgTime, true);
+ }
+}
+
void CTeamsProto::OnSyncConversations(MHttpResponse *response, AsyncHttpRequest *)
{
TeamsReply reply(response);
@@ -38,17 +49,11 @@ void CTeamsProto::OnSyncConversations(MHttpResponse *response, AsyncHttpRequest
const JSONNode &metadata = root["_metadata"];
const JSONNode &conversations = root["conversations"].as_array();
- // int totalCount = metadata["totalCount"].as_int();
- std::string syncState = metadata["syncState"].as_string();
-
for (auto &it : conversations) {
- const JSONNode &lastMessage = it["lastMessage"];
- if (!lastMessage)
- continue;
+ CMStringA szSkypename = it["id"].as_mstring();
+ int iUserType = atoi(szSkypename);
+ MCONTACT hContact = FindContact(szSkypename);
- int iUserType;
- std::string strConversationLink = lastMessage["conversationLink"].as_string();
- CMStringA szSkypename = UrlToSkypeId(strConversationLink.c_str(), &iUserType);
switch (iUserType) {
case 19:
{
@@ -56,21 +61,21 @@ void CTeamsProto::OnSyncConversations(MHttpResponse *response, AsyncHttpRequest
if (!props["lastleaveat"])
StartChatRoom(it["id"].as_mstring(), props["topic"].as_mstring(), props["version"].as_string().c_str());
}
- __fallthrough;
+ FetchMissingHistory(it, hContact);
+ break;
case 8:
case 2:
- int64_t id = _atoi64(lastMessage["id"].as_string().c_str());
+ CMStringA szChatId(it["properties"]["onetoonethreadid"].as_mstring());
+ if (!szChatId.IsEmpty() && hContact)
+ setString(hContact, "ChatId", szChatId);
- MCONTACT hContact = FindContact(szSkypename);
- if (hContact != NULL) {
- auto lastMsgTime = getLastTime(hContact);
- if (lastMsgTime && lastMsgTime < id && m_bAutoHistorySync)
- GetServerHistory(hContact, 100, lastMsgTime, true);
- }
+ FetchMissingHistory(it, hContact);
}
}
+ std::string syncState = metadata["syncState"].as_string();
+
m_bHistorySynced = true;
}
diff --git a/protocols/Teams/src/teams_http.cpp b/protocols/Teams/src/teams_http.cpp
index 35c1a03c1f..7c602e5cdc 100644
--- a/protocols/Teams/src/teams_http.cpp
+++ b/protocols/Teams/src/teams_http.cpp
@@ -105,7 +105,7 @@ MHttpResponse* CTeamsProto::DoSend(AsyncHttpRequest *pReq)
case REQUEST_POST:
if (!pReq->FindHeader("Content-Type")) {
if (pReq->m_szParam[0] == '[' || pReq->m_szParam[0] == '{')
- pReq->AddHeader("Content-Type", "application/json; charset=UTF-8");
+ pReq->AddHeader("Content-Type", "application/json");
else
pReq->AddHeader("Content-Type", "application/x-www-form-urlencoded");
}
@@ -131,6 +131,8 @@ MHttpResponse* CTeamsProto::DoSend(AsyncHttpRequest *pReq)
case HOST_TEAMS_API:
if (!pReq->FindHeader("Authorization"))
pReq->AddHeader("Authorization", "Bearer " + m_szAccessToken);
+ if (m_szSkypeToken)
+ pReq->AddHeader("X-Skypetoken", m_szSkypeToken);
pReq->AddHeader("Accept", "application/json");
pReq->AddHeader("ms-ic3-product", "tfl");
pReq->AddHeader("ms-ic3-additional-product", "Sfl");
diff --git a/protocols/Teams/src/teams_proto.h b/protocols/Teams/src/teams_proto.h
index 5f502106b9..f2d4162818 100644
--- a/protocols/Teams/src/teams_proto.h
+++ b/protocols/Teams/src/teams_proto.h
@@ -253,6 +253,7 @@ private:
bool ParseMessage(const JSONNode &node, DB::EventInfo &dbei);
// contacts
+ void GetShortInfo(const OBJLIST<char> &ids);
void RefreshContactsInfo();
void SetContactStatus(MCONTACT hContact, uint16_t status);
@@ -271,6 +272,7 @@ private:
INT_PTR __cdecl SvcOfflineFile(WPARAM, LPARAM);
// history
+ void FetchMissingHistory(const JSONNode &node, MCONTACT);
void GetServerHistory(MCONTACT hContact, int pageSize, int64_t timestamp, bool bOperative);
void RefreshConversations();