diff options
Diffstat (limited to 'protocols/Teams/src/teams_endpoint.cpp')
| -rw-r--r-- | protocols/Teams/src/teams_endpoint.cpp | 44 |
1 files changed, 18 insertions, 26 deletions
diff --git a/protocols/Teams/src/teams_endpoint.cpp b/protocols/Teams/src/teams_endpoint.cpp index 733008ee75..1b19cf4de5 100644 --- a/protocols/Teams/src/teams_endpoint.cpp +++ b/protocols/Teams/src/teams_endpoint.cpp @@ -73,11 +73,15 @@ void CTeamsProto::OnEndpointCreated(MHttpResponse *response, AsyncHttpRequest*) if (name == "registrationToken") m_szToken = val.Detach(); - else if (name == "endpointId") + else if (name == "endpointId") { + val.Replace("{", ""); + val.Replace("}", ""); m_szEndpoint = val.Detach(); + } } } + SetServerStatus(m_iDesiredStatus); StartTrouter(); PushRequest(new CreateSubscriptionsRequest()); } @@ -110,8 +114,6 @@ void CTeamsProto::OnCapabilitiesSended(MHttpResponse *response, AsyncHttpRequest return; } - PushRequest(new SetStatusRequest(MirandaToSkypeStatus(m_iDesiredStatus))); - LIST<char> skypenames(1); for (auto &hContact : AccContacts()) if (!isChatRoom(hContact)) @@ -166,36 +168,26 @@ void CTeamsProto::SendPresence() void CTeamsProto::OnStatusChanged(MHttpResponse *response, AsyncHttpRequest*) { - if (response == nullptr || response->body.IsEmpty()) { + if (response == nullptr || response->resultCode != 201) { debugLogA(__FUNCTION__ ": failed to change status"); ProtoBroadcastAck(NULL, ACKTYPE_LOGIN, ACKRESULT_FAILED, NULL, 1001); SetStatus(ID_STATUS_OFFLINE); return; } - JSONNode json = JSONNode::parse(response->body); - if (!json) { - debugLogA(__FUNCTION__ ": failed to change status"); - ProtoBroadcastAck(NULL, ACKTYPE_LOGIN, ACKRESULT_FAILED, NULL, 1001); - SetStatus(ID_STATUS_OFFLINE); - return; - } + int oldStatus = m_iStatus; + m_iStatus = m_iDesiredStatus; + ProtoBroadcastAck(NULL, ACKTYPE_STATUS, ACKRESULT_SUCCESS, (HANDLE)oldStatus, m_iStatus); +} - const JSONNode &nStatus = json["status"]; - if (!nStatus) { - debugLogA(__FUNCTION__ ": result contains no valid status to switch to"); - return; - } +void CTeamsProto::SetServerStatus(int iStatus) +{ + auto *pReq = new AsyncHttpRequest(REQUEST_PUT, HOST_PRESENCE, "/me/endpoints", &CTeamsProto::OnStatusChanged); - int iNewStatus = SkypeToMirandaStatus(nStatus.as_string().c_str()); - if (iNewStatus == ID_STATUS_OFFLINE) { - debugLogA(__FUNCTION__ ": failed to change status"); - ProtoBroadcastAck(NULL, ACKTYPE_LOGIN, ACKRESULT_FAILED, NULL, 1001); - SetStatus(ID_STATUS_OFFLINE); - return; - } + JSONNode node(JSON_NODE); + node << CHAR_PARAM("id", m_szEndpoint) << CHAR_PARAM("availability", MirandaToSkypeStatus(iStatus)) + << CHAR_PARAM("activity", "Available") << CHAR_PARAM("activityReporting", "Transport") << CHAR_PARAM("deviceType", "Desktop"); + pReq->m_szParam = node.write().c_str(); - int oldStatus = m_iStatus; - m_iStatus = m_iDesiredStatus = iNewStatus; - ProtoBroadcastAck(NULL, ACKTYPE_STATUS, ACKRESULT_SUCCESS, (HANDLE)oldStatus, m_iStatus); + PushRequest(pReq); } |
