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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
|
#include "stdafx.h"
void CSteamProto::SendHistoryRequest(uint64_t accountId, uint32_t startTime)
{
CFriendMessagesGetRecentMessagesRequest request;
request.steamid1 = m_iSteamId; request.has_steamid1 = true;
request.steamid2 = AccountIdToSteamId(accountId); request.has_steamid2 = true;
request.rtime32_start_time = startTime; request.has_rtime32_start_time = true;
WSSendService(FriendGetRecentMessages, request);
}
void CSteamProto::OnGotRecentMessages(const CFriendMessagesGetRecentMessagesResponse &reply, const CMsgProtoBufHeader &hdr)
{
if (hdr.failed())
return;
for (int i = 0; i < reply.n_messages; i++) {
auto *pMsg = reply.messages[i];
auto steamId = AccountIdToSteamId(pMsg->accountid);
MCONTACT hContact = GetContact(steamId);
if (!hContact)
continue;
char szMsgId[100];
itoa(pMsg->timestamp, szMsgId, 10);
DB::EventInfo dbei(pMsg->has_timestamp ? db_event_getById(m_szModuleName, szMsgId) : 0);
dbei.flags = DBEF_UTF;
if (steamId == m_iSteamId)
dbei.flags |= DBEF_SENT;
dbei.cbBlob = (int)mir_strlen(pMsg->message);
dbei.pBlob = mir_strdup(pMsg->message);
dbei.timestamp = pMsg->has_timestamp ? pMsg->timestamp : time(0);
dbei.szId = szMsgId;
if (dbei.getEvent())
db_event_edit(dbei.getEvent(), &dbei, true);
else
ProtoChainRecvMsg(hContact, dbei);
}
}
void CSteamProto::OnGotConversations(const CFriendsMessagesGetActiveMessageSessionsResponse &reply, const CMsgProtoBufHeader &hdr)
{
if (hdr.failed())
return;
for (int i=0; i < reply.n_message_sessions; i++) {
auto *session = reply.message_sessions[i];
uint64_t steamId = AccountIdToSteamId(session->accountid_friend);
MCONTACT hContact = GetContact(steamId);
if (!hContact)
continue;
time_t storedMessageTS = getDword(hContact, DBKEY_LASTMSG);
if (session->last_message > storedMessageTS)
SendHistoryRequest(steamId, storedMessageTS);
}
}
void CSteamProto::OnGotHistoryMessages(const CMsgClientChatGetFriendMessageHistoryResponse &reply, const CMsgProtoBufHeader &hdr)
{
if (hdr.failed())
return;
MCONTACT hContact = GetContact(reply.steamid);
if (!hContact)
return;
for (int i = 0; i < reply.n_messages; i++) {
auto *pMsg = reply.messages[i];
char szMsgId[100];
itoa(pMsg->timestamp, szMsgId, 10);
DB::EventInfo dbei(pMsg->has_timestamp ? db_event_getById(m_szModuleName, szMsgId) : 0);
dbei.flags = DBEF_UTF;
if (pMsg->has_unread && !pMsg->unread)
dbei.flags |= DBEF_READ;
if (pMsg->accountid == m_iSteamId)
dbei.flags |= DBEF_SENT;
dbei.cbBlob = (int)mir_strlen(pMsg->message);
dbei.pBlob = mir_strdup(pMsg->message);
dbei.timestamp = pMsg->has_timestamp ? pMsg->timestamp : time(0);
dbei.szId = szMsgId;
if (dbei.getEvent())
db_event_edit(dbei.getEvent(), &dbei, true);
else
ProtoChainRecvMsg(hContact, dbei);
}
}
|