summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert Pösel <robyer@seznam.cz>2015-12-19 22:32:35 +0000
committerRobert Pösel <robyer@seznam.cz>2015-12-19 22:32:35 +0000
commitf795b3b823f76d9c61fccfad53c2f2cfbe5b3115 (patch)
tree40652761c22bfc3c26982d17b9d7743def399878
parent02ca3b1dd1a02210333764ebafe7b4dedd68d56e (diff)
Steam: Use server timestamp for sent messages
git-svn-id: http://svn.miranda-ng.org/main/trunk@15905 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
-rw-r--r--protocols/Steam/src/steam_events.cpp1
-rw-r--r--protocols/Steam/src/steam_messages.cpp30
-rw-r--r--protocols/Steam/src/steam_proto.h2
3 files changed, 32 insertions, 1 deletions
diff --git a/protocols/Steam/src/steam_events.cpp b/protocols/Steam/src/steam_events.cpp
index 1a7bdbc9a4..3c57248900 100644
--- a/protocols/Steam/src/steam_events.cpp
+++ b/protocols/Steam/src/steam_events.cpp
@@ -4,6 +4,7 @@ int CSteamProto::OnModulesLoaded(WPARAM, LPARAM)
{
HookProtoEvent(ME_OPT_INITIALISE, &CSteamProto::OnOptionsInit);
HookProtoEvent(ME_IDLE_CHANGED, &CSteamProto::OnIdleChanged);
+ HookProtoEvent(ME_MSG_PRECREATEEVENT, &CSteamProto::OnPreCreateMessage);
HookEvent(ME_CLIST_PREBUILDCONTACTMENU, &CSteamProto::PrebuildContactMenu);
diff --git a/protocols/Steam/src/steam_messages.cpp b/protocols/Steam/src/steam_messages.cpp
index 1a51cccb90..f55a31366a 100644
--- a/protocols/Steam/src/steam_messages.cpp
+++ b/protocols/Steam/src/steam_messages.cpp
@@ -40,6 +40,7 @@ void CSteamProto::OnMessageSent(const HttpResponse *response, void *arg)
ptrT error(mir_tstrdup(TranslateT("Unknown error")));
ptrT steamId(getTStringA(param->hContact, "SteamID"));
+ time_t timestamp = NULL;
if (ResponseHttpOk(response))
{
@@ -47,6 +48,10 @@ void CSteamProto::OnMessageSent(const HttpResponse *response, void *arg)
JSONNode *node = json_get(root, "error");
if (node)
error = json_as_string(node);
+
+ node = json_get(root, "utc_timestamp");
+ if (node)
+ timestamp = atol(ptrA(mir_t2a(ptrT(json_as_string(node)))));
}
if (mir_tstrcmpi(error, _T("OK")) != 0)
@@ -56,5 +61,28 @@ void CSteamProto::OnMessageSent(const HttpResponse *response, void *arg)
ProtoBroadcastAck(param->hContact, ACKTYPE_MESSAGE, ACKRESULT_FAILED, param->hMessage, (LPARAM)errorA);
}
else
+ {
+ // remember server time of this message
+ auto it = m_mpOutMessages.find(param->hMessage);
+ if (it == m_mpOutMessages.end() && timestamp != NULL)
+ m_mpOutMessages[param->hMessage] = timestamp;
+
ProtoBroadcastAck(param->hContact, ACKTYPE_MESSAGE, ACKRESULT_SUCCESS, param->hMessage, 0);
-} \ No newline at end of file
+ }
+}
+
+int CSteamProto::OnPreCreateMessage(WPARAM, LPARAM lParam)
+{
+ MessageWindowEvent *evt = (MessageWindowEvent*)lParam;
+ if (mir_strcmp(GetContactProto(evt->hContact), m_szModuleName))
+ return 0;
+
+ auto it = m_mpOutMessages.find((HANDLE)evt->seq);
+ if (it != m_mpOutMessages.end())
+ {
+ evt->dbei->timestamp = it->second;
+ m_mpOutMessages.erase(it);
+ }
+
+ return 0;
+}
diff --git a/protocols/Steam/src/steam_proto.h b/protocols/Steam/src/steam_proto.h
index 89805d86af..f30c4aa90c 100644
--- a/protocols/Steam/src/steam_proto.h
+++ b/protocols/Steam/src/steam_proto.h
@@ -81,6 +81,7 @@ protected:
mir_cs contact_search_lock;
mir_cs requests_queue_lock;
mir_cs set_status_lock;
+ std::map<HANDLE, time_t> m_mpOutMessages;
// instances
static LIST<CSteamProto> InstanceList;
@@ -158,6 +159,7 @@ protected:
// messages
int OnSendMessage(MCONTACT hContact, const char* message);
void OnMessageSent(const HttpResponse *response, void *arg);
+ int __cdecl OnPreCreateMessage(WPARAM, LPARAM lParam);
// menus
static int hChooserMenu;