summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--protocols/Teams/src/teams_contacts.cpp2
-rw-r--r--protocols/Teams/src/teams_proto.h2
-rw-r--r--protocols/Teams/src/teams_trouter.cpp45
-rw-r--r--protocols/Teams/src/teams_utils.cpp68
-rw-r--r--protocols/Teams/src/teams_utils.h2
5 files changed, 30 insertions, 89 deletions
diff --git a/protocols/Teams/src/teams_contacts.cpp b/protocols/Teams/src/teams_contacts.cpp
index 9c7a1f728d..3cc2f857dc 100644
--- a/protocols/Teams/src/teams_contacts.cpp
+++ b/protocols/Teams/src/teams_contacts.cpp
@@ -110,7 +110,7 @@ void CTeamsProto::LoadContactsAuth(MHttpResponse *response, AsyncHttpRequest*)
time_t eventTime = 0;
for (auto &it : item["invites"])
- eventTime = IsoToUnixTime(it["time"].as_string());
+ eventTime = Utils_IsoToUnixTime(it["time"].as_string());
std::string displayName = item["displayname"].as_string();
const char *szNick = (displayName.empty()) ? nullptr : displayName.c_str();
diff --git a/protocols/Teams/src/teams_proto.h b/protocols/Teams/src/teams_proto.h
index 97991a3ca1..597ff28775 100644
--- a/protocols/Teams/src/teams_proto.h
+++ b/protocols/Teams/src/teams_proto.h
@@ -319,8 +319,6 @@ private:
CMStringW RemoveHtml(const CMStringW &src, bool bCheckSS = false);
- static time_t IsoToUnixTime(const std::string &stamp);
-
void ShowNotification(const wchar_t *message, MCONTACT hContact = NULL);
void ShowNotification(const wchar_t *caption, const wchar_t *message, MCONTACT hContact = NULL, int type = 0);
static bool IsFileExists(std::wstring path);
diff --git a/protocols/Teams/src/teams_trouter.cpp b/protocols/Teams/src/teams_trouter.cpp
index d832abaa26..721e9ca8b3 100644
--- a/protocols/Teams/src/teams_trouter.cpp
+++ b/protocols/Teams/src/teams_trouter.cpp
@@ -250,20 +250,17 @@ void CTeamsProto::TRouterProcess(const char *str)
if (message) {
Netlib_Logf(m_hTrouterNetlibUser, "Got event:\n%s", message.write_formatted().c_str());
- const JSONNode &resource = message["resource"];
-
- std::string resourceType = message["resourceType"].as_string();
- if (resourceType == "NewMessage")
- ProcessNewMessage(resource);
- else if (resourceType == "UserPresence")
- ProcessUserPresence(resource);
- else if (resourceType == "EndpointPresence")
- ProcessEndpointPresence(resource);
- else if (resourceType == "ConversationUpdate")
- ProcessConversationUpdate(resource);
- else if (resourceType == "ThreadUpdate")
- ProcessThreadUpdate(resource);
+ if (!mir_strcmp(message.name(), "presence")) {
+ for (auto &it : message)
+ ProcessUserPresence(it);
+ }
}
+
+ JSONNode reply, &old = packet["headers"], headers; headers.set_name("headers");
+ headers << WCHAR_PARAM("MS-CV", old["MS-CV"].as_mstring()) << old["trouter-request"] << old["trouter-client"];
+ reply << WCHAR_PARAM("id", packet["id"].as_mstring()) << INT_PARAM("status", 200) << headers << CHAR_PARAM("body", "");
+ if (m_ws)
+ m_ws->sendText(("3:::" + reply.write()).c_str());
}
break;
@@ -344,24 +341,28 @@ void CTeamsProto::ProcessUserPresence(const JSONNode &node)
{
debugLogA(__FUNCTION__);
- std::string selfLink = node["selfLink"].as_string();
- std::string status = node["availability"].as_string();
- CMStringA skypename = UrlToSkypeId(selfLink.c_str());
+ CMStringA skypename = node["mri"].as_mstring();
+ auto &presence = node["presence"];
+ std::string status = presence["availability"].as_string();
if (!skypename.IsEmpty()) {
if (IsMe(skypename)) {
- int iNewStatus = SkypeToMirandaStatus(status.c_str());
- if (iNewStatus == ID_STATUS_OFFLINE) return;
+ int iNewStatus = TeamsToMirandaStatus(status.c_str());
+ if (iNewStatus == ID_STATUS_OFFLINE)
+ return;
+
int old_status = m_iStatus;
m_iDesiredStatus = iNewStatus;
m_iStatus = iNewStatus;
if (old_status != iNewStatus)
ProtoBroadcastAck(NULL, ACKTYPE_STATUS, ACKRESULT_SUCCESS, (HANDLE)old_status, iNewStatus);
}
- else {
- MCONTACT hContact = FindContact(skypename);
- if (hContact != NULL)
- SetContactStatus(hContact, SkypeToMirandaStatus(status.c_str()));
+ else if (MCONTACT hContact = FindContact(skypename)) {
+ SetContactStatus(hContact, TeamsToMirandaStatus(status.c_str()));
+ if (auto &p = presence["lastActiveTime"])
+ setDword(hContact, "LastSeen", Utils_IsoToUnixTime(p.as_string().c_str()));
+ if (auto &p = presence["deviceType"])
+ setWString(hContact, "MirVer", L"Teams (" + p.as_mstring() + L")");
}
}
}
diff --git a/protocols/Teams/src/teams_utils.cpp b/protocols/Teams/src/teams_utils.cpp
index 8d158dfd4d..a71e9f7e4e 100644
--- a/protocols/Teams/src/teams_utils.cpp
+++ b/protocols/Teams/src/teams_utils.cpp
@@ -19,68 +19,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#pragma warning(disable:4566)
-time_t CTeamsProto::IsoToUnixTime(const std::string &stamp)
-{
- char date[9];
- int i, y;
-
- if (stamp.empty())
- return 0;
-
- char *p = NEWSTR_ALLOCA(stamp.c_str());
-
- // skip '-' chars
- int si = 0, sj = 0;
- while (true) {
- if (p[si] == '-')
- si++;
- else if (!(p[sj++] = p[si++]))
- break;
- }
-
- // Get the date part
- for (i = 0; *p != '\0' && i < 8 && isdigit(*p); p++, i++)
- date[i] = *p;
-
- // Parse year
- if (i == 6) {
- // 2-digit year (1970-2069)
- y = (date[0] - '0') * 10 + (date[1] - '0');
- if (y < 70) y += 100;
- }
- else if (i == 8) {
- // 4-digit year
- y = (date[0] - '0') * 1000 + (date[1] - '0') * 100 + (date[2] - '0') * 10 + date[3] - '0';
- y -= 1900;
- }
- else return 0;
-
- struct tm timestamp;
- timestamp.tm_year = y;
-
- // Parse month
- timestamp.tm_mon = (date[i - 4] - '0') * 10 + date[i - 3] - '0' - 1;
-
- // Parse date
- timestamp.tm_mday = (date[i - 2] - '0') * 10 + date[i - 1] - '0';
-
- // Skip any date/time delimiter
- for (; *p != '\0' && !isdigit(*p); p++);
-
- // Parse time
- if (sscanf(p, "%d:%d:%d", &timestamp.tm_hour, &timestamp.tm_min, &timestamp.tm_sec) != 3)
- return (time_t)0;
-
- timestamp.tm_isdst = 0; // DST is already present in _timezone below
- time_t t = mktime(&timestamp);
-
- _tzset();
- t -= _timezone;
- return (t >= 0) ? t : 0;
-}
-
-//////////////////////////////////////////////////////////////////////////////////////////
-
struct HtmlEntity
{
const char *entity;
@@ -576,14 +514,18 @@ uint32_t Utf16toUtf32(const wchar_t *str)
//////////////////////////////////////////////////////////////////////////////////////////
-int SkypeToMirandaStatus(const char *status)
+int TeamsToMirandaStatus(const char *status)
{
if (!mir_strcmpi(status, "Available"))
return ID_STATUS_ONLINE;
+ if (!mir_strcmpi(status, "Away"))
+ return ID_STATUS_AWAY;
if (!mir_strcmpi(status, "BeRightBack"))
return ID_STATUS_NA;
if (!mir_strcmpi(status, "AvailableIdle"))
return ID_STATUS_IDLE;
+ if (!mir_strcmpi(status, "Busy"))
+ return ID_STATUS_OCCUPIED;
if (!mir_strcmpi(status, "DoNotDisturb"))
return ID_STATUS_DND;
return ID_STATUS_OFFLINE;
diff --git a/protocols/Teams/src/teams_utils.h b/protocols/Teams/src/teams_utils.h
index 1fe980ef06..59931a4a3a 100644
--- a/protocols/Teams/src/teams_utils.h
+++ b/protocols/Teams/src/teams_utils.h
@@ -26,7 +26,7 @@ const wchar_t* GetSkypeNick(const wchar_t *szSkypeId);
CMStringA ParseUrl(const char *url, const char *token);
-int SkypeToMirandaStatus(const char *status);
+int TeamsToMirandaStatus(const char *status);
bool AddBbcodes(CMStringA &str);