blob: 27c693cb303da4f755c8da2f490a7ea340a55754 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
|
#include "stdafx.h"
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 (root.isnull())
return;
const JSONNode &response = root["response"];
for (auto &session : response["message_sessions"]) {
long long accountId = _wtoi64(session["accountid_friend"].as_mstring());
const char *who = AccountIdToSteamId(accountId);
time_t lastMessageTS = _wtoi64(session["last_message"].as_mstring());
/*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);*/
if (lastMessageTS > m_lastMessageTS) {
ptrA token(getStringA("TokenSecret"));
ptrA steamId(getStringA("SteamID"));
PushRequest(new GetHistoryMessagesRequest(token, steamId, who, m_lastMessageTS), &CSteamProto::OnGotHistoryMessages, mir_strdup(who));
}
}
}
void CSteamProto::OnGotHistoryMessages(const JSONNode &root, void *arg)
{
ptrA cSteamId((char *)arg);
MCONTACT hContact = GetContact(cSteamId);
if (!hContact)
return;
if (root.isnull())
return;
const JSONNode &response = root["response"];
const JSONNode &messages = response["messages"];
for (size_t i = messages.size(); i > 0; i--) {
const JSONNode &message = messages[i - 1];
long long accountId = _wtoi64(message["accountid"].as_mstring());
const char *steamId = AccountIdToSteamId(accountId);
json_string text = message["message"].as_string();
time_t timestamp = _wtoi64(message["timestamp"].as_mstring());
// Ignore already existing messages
if (timestamp <= m_lastMessageTS)
continue;
PROTORECVEVENT recv = { 0 };
recv.timestamp = timestamp;
recv.szMessage = (char *)text.c_str();
if (IsMe(steamId))
recv.flags = PREF_SENT;
RecvMsg(hContact, &recv);
}
}
|