summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--protocols/FacebookRM/src/client.h3
-rw-r--r--protocols/FacebookRM/src/communication.cpp14
-rw-r--r--protocols/FacebookRM/src/connection.cpp1
-rw-r--r--protocols/FacebookRM/src/entities.h4
-rw-r--r--protocols/FacebookRM/src/json.cpp2
-rw-r--r--protocols/FacebookRM/src/messages.cpp14
-rw-r--r--protocols/FacebookRM/src/process.cpp6
-rw-r--r--protocols/FacebookRM/src/proto.cpp17
-rw-r--r--protocols/FacebookRM/src/proto.h1
9 files changed, 46 insertions, 16 deletions
diff --git a/protocols/FacebookRM/src/client.h b/protocols/FacebookRM/src/client.h
index bc1fb30d97..87ff2d1f39 100644
--- a/protocols/FacebookRM/src/client.h
+++ b/protocols/FacebookRM/src/client.h
@@ -184,9 +184,10 @@ public:
// Messages handling
std::map<std::string, int> messages_ignore;
+ std::map<int, DWORD> messages_timestamp;
bool channel();
- int send_message(MCONTACT, const std::string &message_recipient, const std::string &message_text, std::string *error_text, MessageMethod method, const std::string &captchaPersistData = "", const std::string &captcha = "");
+ int send_message(int seqid, MCONTACT, const std::string &message_recipient, const std::string &message_text, std::string *error_text, MessageMethod method, const std::string &captchaPersistData = "", const std::string &captcha = "");
////////////////////////////////////////////////////////////
diff --git a/protocols/FacebookRM/src/communication.cpp b/protocols/FacebookRM/src/communication.cpp
index 7d0cc2e12e..e1518f4f8e 100644
--- a/protocols/FacebookRM/src/communication.cpp
+++ b/protocols/FacebookRM/src/communication.cpp
@@ -1218,7 +1218,7 @@ bool facebook_client::channel()
}
}
-int facebook_client::send_message(MCONTACT hContact, const std::string &message_recipient, const std::string &message_text, std::string *error_text, MessageMethod method, const std::string &captcha_persist_data, const std::string &captcha)
+int facebook_client::send_message(int seqid, MCONTACT hContact, const std::string &message_recipient, const std::string &message_text, std::string *error_text, MessageMethod method, const std::string &captcha_persist_data, const std::string &captcha)
{
ScopedLock s(send_message_lock_);
@@ -1339,6 +1339,16 @@ int facebook_client::send_message(MCONTACT hContact, const std::string &message_
std::string timestamp = utils::text::source_get_value(&resp.data, 2, "\"timestamp\":", ",");
parent->setString(FACEBOOK_KEY_LAST_ACTION_TIMESTAMP, timestamp.c_str());
+ // For classic conversation we try to remember and then replace timestamp of added event in OnPreCreateEvent()
+ bool localTimestamp = parent->getBool(FACEBOOK_KEY_LOCAL_TIMESTAMP, DEFAULT_LOCAL_TIME);
+ if (seqid > 0 && !localTimestamp) {
+ long long time = _atoi64(timestamp.c_str());
+ if (time > 100000000000)
+ time /= 1000;
+
+ messages_timestamp.insert(std::make_pair(seqid, (DWORD)time));
+ }
+
messages_ignore.insert(std::make_pair(mid, 0));
} break;
@@ -1381,7 +1391,7 @@ int facebook_client::send_message(MCONTACT hContact, const std::string &message_
return SEND_MESSAGE_CANCEL;
}
- return send_message(hContact, message_recipient, message_text, error_text, method, captchaPersistData, result);
+ return send_message(seqid, hContact, message_recipient, message_text, error_text, method, captchaPersistData, result);
}
return SEND_MESSAGE_CANCEL; // Cancel because we failed to load captcha image so we can't continue only with error
diff --git a/protocols/FacebookRM/src/connection.cpp b/protocols/FacebookRM/src/connection.cpp
index e38706ae61..387dfe99cf 100644
--- a/protocols/FacebookRM/src/connection.cpp
+++ b/protocols/FacebookRM/src/connection.cpp
@@ -61,6 +61,7 @@ void FacebookProto::ChangeStatus(void*)
facy.clear_readers();
facy.buddies.clear();
facy.messages_ignore.clear();
+ facy.messages_timestamp.clear();
facy.pages.clear();
facy.typers.clear();
diff --git a/protocols/FacebookRM/src/entities.h b/protocols/FacebookRM/src/entities.h
index 384e0b2ec9..e83760595b 100644
--- a/protocols/FacebookRM/src/entities.h
+++ b/protocols/FacebookRM/src/entities.h
@@ -147,10 +147,10 @@ struct send_chat
struct send_direct
{
- send_direct(MCONTACT hContact,const std::string &msg, HANDLE msgid) : hContact(hContact), msg(msg), msgid(msgid) {}
+ send_direct(MCONTACT hContact,const std::string &msg, int msgid) : hContact(hContact), msg(msg), msgid(msgid) {}
MCONTACT hContact;
std::string msg;
- HANDLE msgid;
+ int msgid;
};
struct send_typing
diff --git a/protocols/FacebookRM/src/json.cpp b/protocols/FacebookRM/src/json.cpp
index a8d8e8ea7a..369f94c31f 100644
--- a/protocols/FacebookRM/src/json.cpp
+++ b/protocols/FacebookRM/src/json.cpp
@@ -446,7 +446,7 @@ int facebook_json_parser::parse_messages(std::string *data, std::vector< faceboo
continue;
// check if we should use use local_timestamp for incoming messages and use it for read time too
- /*bool local_timestamp = proto->getBool(FACEBOOK_KEY_LOCAL_TIMESTAMP, 0);
+ /*bool local_timestamp = proto->getBool(FACEBOOK_KEY_LOCAL_TIMESTAMP, DEFAULT_LOCAL_TIME);
time_t timestamp = local_timestamp ? ::time(NULL) : utils::time::fix_timestamp(json_as_float(time));*/
// we can always use NOW for read time, because that's the time of receiving this event (+-)
diff --git a/protocols/FacebookRM/src/messages.cpp b/protocols/FacebookRM/src/messages.cpp
index 192ef1fb8c..c70ce6a7de 100644
--- a/protocols/FacebookRM/src/messages.cpp
+++ b/protocols/FacebookRM/src/messages.cpp
@@ -42,27 +42,27 @@ void FacebookProto::SendMsgWorker(void *p)
ptrA id(getStringA(data->hContact, FACEBOOK_KEY_ID));
if (!isOnline()) {
- ProtoBroadcastAck(data->hContact, ACKTYPE_MESSAGE, ACKRESULT_FAILED, data->msgid, (LPARAM)Translate("You cannot send messages when you are offline."));
+ ProtoBroadcastAck(data->hContact, ACKTYPE_MESSAGE, ACKRESULT_FAILED, (HANDLE)data->msgid, (LPARAM)Translate("You cannot send messages when you are offline."));
}
else if (id == NULL) {
- ProtoBroadcastAck(data->hContact, ACKTYPE_MESSAGE, ACKRESULT_FAILED, data->msgid, 0);
+ ProtoBroadcastAck(data->hContact, ACKTYPE_MESSAGE, ACKRESULT_FAILED, (HANDLE)data->msgid, 0);
}
else {
int retries = 5;
std::string error_text;
int result = SEND_MESSAGE_ERROR;
while (result == SEND_MESSAGE_ERROR && retries > 0) {
- result = facy.send_message(data->hContact, std::string(id), data->msg, &error_text, retries % 2 == 0 ? MESSAGE_INBOX : MESSAGE_MERCURY);
+ result = facy.send_message(data->msgid, data->hContact, std::string(id), data->msg, &error_text, retries % 2 == 0 ? MESSAGE_INBOX : MESSAGE_MERCURY);
retries--;
}
if (result == SEND_MESSAGE_OK) {
- ProtoBroadcastAck(data->hContact, ACKTYPE_MESSAGE, ACKRESULT_SUCCESS, data->msgid, 0);
+ ProtoBroadcastAck(data->hContact, ACKTYPE_MESSAGE, ACKRESULT_SUCCESS, (HANDLE)data->msgid, 0);
// Remove from "readers" list and clear statusbar
facy.erase_reader(data->hContact);
}
else {
- ProtoBroadcastAck(data->hContact, ACKTYPE_MESSAGE, ACKRESULT_FAILED, data->msgid, (LPARAM)error_text.c_str());
+ ProtoBroadcastAck(data->hContact, ACKTYPE_MESSAGE, ACKRESULT_FAILED, (HANDLE)data->msgid, (LPARAM)error_text.c_str());
}
}
@@ -101,7 +101,7 @@ void FacebookProto::SendChatMsgWorker(void *p)
}
if (!tid.empty()) {
- if (facy.send_message(hContact, tid, data->msg, &err_message, MESSAGE_TID) == SEND_MESSAGE_OK)
+ if (facy.send_message(0, hContact, tid, data->msg, &err_message, MESSAGE_TID) == SEND_MESSAGE_OK)
UpdateChat(_A2T(data->chat_id.c_str()), facy.self_.user_id.c_str(), facy.self_.real_name.c_str(), data->msg.c_str());
else
UpdateChat(_A2T(data->chat_id.c_str()), NULL, NULL, err_message.c_str());
@@ -117,7 +117,7 @@ int FacebookProto::SendMsg(MCONTACT hContact, int flags, const char *msg)
std::string message = (flags & PREF_UNICODE) ? ptrA(mir_utf8encode(msg)) : msg;
facy.msgid_ = (facy.msgid_ % 1024) + 1;
- ForkThread(&FacebookProto::SendMsgWorker, new send_direct(hContact, message, (HANDLE)facy.msgid_));
+ ForkThread(&FacebookProto::SendMsgWorker, new send_direct(hContact, message, facy.msgid_));
return facy.msgid_;
}
diff --git a/protocols/FacebookRM/src/process.cpp b/protocols/FacebookRM/src/process.cpp
index c0e6f28ee2..4af8154cdd 100644
--- a/protocols/FacebookRM/src/process.cpp
+++ b/protocols/FacebookRM/src/process.cpp
@@ -578,13 +578,13 @@ void FacebookProto::SyncThreads(void*)
if (ptrtimestamp != NULL)
timestamp = ptrtimestamp;
- unsigned __int64 time = _atoi64(timestamp.c_str());
+ long long time = _atoi64(timestamp.c_str());
if (time > 100000000000) {
time /= 1000;
}
- if (time < (unsigned) ::time(NULL) - 24 * 60 * 60) {
+ if (time < ::time(NULL) - 24 * 60 * 60) {
time_t last = ::time(NULL) - 24 * 60 * 60;
timestamp = utils::conversion::to_string((void*)&last, UTILS_CONV_TIME_T) + "000";
@@ -870,7 +870,7 @@ void FacebookProto::ProcessMessages(void* data)
p->parse_messages(resp, &messages, &facy.notifications, inboxOnly);
delete p;
- bool local_timestamp = getBool(FACEBOOK_KEY_LOCAL_TIMESTAMP, 0);
+ bool local_timestamp = getBool(FACEBOOK_KEY_LOCAL_TIMESTAMP, DEFAULT_LOCAL_TIME);
ReceiveMessages(messages, local_timestamp);
diff --git a/protocols/FacebookRM/src/proto.cpp b/protocols/FacebookRM/src/proto.cpp
index aacb6f08a7..cb070adb20 100644
--- a/protocols/FacebookRM/src/proto.cpp
+++ b/protocols/FacebookRM/src/proto.cpp
@@ -70,6 +70,7 @@ PROTO<FacebookProto>(proto_name, username)
HookProtoEvent(ME_GC_BUILDMENU, &FacebookProto::OnGCMenuHook);
HookProtoEvent(ME_DB_EVENT_MARKED_READ, &FacebookProto::OnDbEventRead);
HookProtoEvent(ME_MSG_WINDOWEVENT, &FacebookProto::OnProcessSrmmEvent);
+ HookProtoEvent(ME_MSG_PRECREATEEVENT, &FacebookProto::OnPreCreateEvent);
db_set_resident(m_szModuleName, "Status");
db_set_resident(m_szModuleName, "IdleTS");
@@ -583,6 +584,22 @@ int FacebookProto::OnProcessSrmmEvent(WPARAM, LPARAM lParam)
return 0;
}
+int FacebookProto::OnPreCreateEvent(WPARAM, LPARAM lParam)
+{
+ MessageWindowEvent *evt = (MessageWindowEvent *)lParam;
+ if (strcmp(GetContactProto(evt->hContact), m_szModuleName))
+ return 0;
+
+ std::map<int, DWORD>::iterator it = facy.messages_timestamp.find(evt->seq);
+ if (it != facy.messages_timestamp.end()) {
+ // set correct timestamp of this message
+ evt->dbei->timestamp = it->second;
+ facy.messages_timestamp.erase(it);
+ }
+
+ return 1;
+}
+
INT_PTR FacebookProto::CheckNewsfeeds(WPARAM, LPARAM)
{
if (!isOffline()) {
diff --git a/protocols/FacebookRM/src/proto.h b/protocols/FacebookRM/src/proto.h
index 9c7153309f..48249a1609 100644
--- a/protocols/FacebookRM/src/proto.h
+++ b/protocols/FacebookRM/src/proto.h
@@ -158,6 +158,7 @@ public:
int __cdecl OnGCMenuHook(WPARAM,LPARAM);
int __cdecl OnDbEventRead(WPARAM, LPARAM);
int __cdecl OnProcessSrmmEvent(WPARAM, LPARAM);
+ int __cdecl OnPreCreateEvent(WPARAM, LPARAM);
// Loops
bool NegotiateConnection();