summaryrefslogtreecommitdiff
path: root/protocols/Steam/src/steam_history.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'protocols/Steam/src/steam_history.cpp')
-rw-r--r--protocols/Steam/src/steam_history.cpp102
1 files changed, 39 insertions, 63 deletions
diff --git a/protocols/Steam/src/steam_history.cpp b/protocols/Steam/src/steam_history.cpp
index 3b62aa21bc..a897037bae 100644
--- a/protocols/Steam/src/steam_history.cpp
+++ b/protocols/Steam/src/steam_history.cpp
@@ -1,92 +1,64 @@
#include "stdafx.h"
-void CSteamProto::OnGotConversations(const HttpResponse *response)
+void CSteamProto::OnGotConversations(const JSONNode &root, void*)
{
// Don't load any messages when we don't have lastMessageTS, as it may cause duplicates
if (m_lastMessageTS <= 0)
return;
- if (!ResponseHttpOk(response))
+ if (root.isnull())
return;
- JSONROOT root(response->pData);
- if (root == nullptr)
+ JSONNode response = root["response"];
+ JSONNode sessions = response["message_sessions"].as_array();
+ if (sessions.isnull())
return;
- JSONNode *node = json_get(root, "response");
- JSONNode *sessions = json_get(node, "message_sessions");
- JSONNode *nsessions = json_as_array(sessions);
-
- if (nsessions != nullptr)
+ for (const JSONNode &session : sessions)
{
- ptrA token(getStringA("TokenSecret"));
- ptrA steamId(getStringA("SteamID"));
-
-
- for (size_t i = 0; i < json_size(nsessions); i++)
- {
- JSONNode *session = json_at(nsessions, i);
+ long long accountId = _wtoi64(session["accountid_friend"].as_mstring());
+ const char *who = AccountIdToSteamId(accountId);
- node = json_get(session, "accountid_friend");
- const char *who = AccountIdToSteamId(_wtoi64(ptrW(json_as_string(node))));
+ time_t lastMessageTS = _wtoi64(session["last_message"].as_mstring());
- node = json_get(session, "last_message");
- time_t lastMessageTS = _wtoi64(ptrW(json_as_string(node)));
+ /*node = json_get(session, "last_view");
+ time_t last_view = _wtoi64(ptrW(json_as_string(node)));
- /*node = json_get(session, "last_view");
- time_t last_view = _wtoi64(ptrW(json_as_string(node)));
+ node = json_get(session, "unread_message_count");
+ long unread_count = json_as_int(node);*/
- node = json_get(session, "unread_message_count");
- long unread_count = json_as_int(node);*/
+ if (lastMessageTS > m_lastMessageTS)
+ {
+ ptrA token(getStringA("TokenSecret"));
+ ptrA steamId(getStringA("SteamID"));
- if (lastMessageTS > m_lastMessageTS)
- {
- PushRequest(
- new GetHistoryMessagesRequest(token, steamId, who, m_lastMessageTS),
- &CSteamProto::OnGotHistoryMessages,
- mir_strdup(who),
- MirFreeArg);
- }
+ PushRequest(
+ new GetHistoryMessagesRequest(token, steamId, who, m_lastMessageTS),
+ &CSteamProto::OnGotHistoryMessages,
+ mir_strdup(who));
}
-
- json_delete(nsessions);
}
}
-void CSteamProto::OnGotHistoryMessages(const HttpResponse *response, void *arg)
+void CSteamProto::OnGotHistoryMessages(const JSONNode &root, void *arg)
{
- MCONTACT hContact = FindContact((char*)arg);
- if (!hContact)
- return;
+ ptrA cSteamId((char*)arg);
- if (!ResponseHttpOk(response))
+ if (root.isnull())
return;
- JSONROOT root(response->pData);
- if (root == nullptr)
- return;
-
- JSONNode *node = json_get(root, "response");
-
- JSONNode *messages = json_get(node, "messages");
- JSONNode *nmessages = json_as_array(messages);
-
- // Self SteamID
- ptrA steamId(getStringA("SteamID"));
-
- for (size_t i = json_size(nmessages); i > 0; i--)
+ JSONNode response = root["response"];
+ JSONNode messages = response["messages"].as_array();
+ for (size_t i = messages.size(); i > 0; i--)
{
- JSONNode *message = json_at(nmessages, i - 1);
+ JSONNode message = messages[i - 1];
- node = json_get(message, "accountid");
- const char *authorSteamId = AccountIdToSteamId(_wtoi64(ptrW(json_as_string(node))));
+ long long accountId = _wtoi64(message["accountid"].as_mstring());
+ const char *authorSteamId = AccountIdToSteamId(accountId);
- node = json_get(message, "message");
- ptrW text(json_as_string(node));
- T2Utf szMessage(text);
+ json_string text = message["message"].as_string();
- node = json_get(message, "timestamp");
- time_t timestamp = _wtoi64(ptrW(json_as_string(node)));
+ time_t timestamp = _wtoi64(message["timestamp"].as_mstring());
// Ignore already existing messages
if (timestamp <= m_lastMessageTS)
@@ -94,8 +66,14 @@ void CSteamProto::OnGotHistoryMessages(const HttpResponse *response, void *arg)
PROTORECVEVENT recv = { 0 };
recv.timestamp = timestamp;
- recv.szMessage = szMessage;
+ recv.szMessage = (char*)text.c_str();
+ MCONTACT hContact = FindContact(cSteamId);
+ if (!hContact)
+ return;
+
+ // Self SteamID
+ ptrA steamId(getStringA("SteamID"));
if (strcmp(steamId, authorSteamId))
{
// Received message
@@ -108,6 +86,4 @@ void CSteamProto::OnGotHistoryMessages(const HttpResponse *response, void *arg)
Proto_RecvMessage(hContact, &recv);
}
}
-
- json_delete(nmessages);
}