summaryrefslogtreecommitdiff
path: root/protocols
diff options
context:
space:
mode:
authorRobert Pösel <robyer@seznam.cz>2014-12-23 15:30:07 +0000
committerRobert Pösel <robyer@seznam.cz>2014-12-23 15:30:07 +0000
commitdfc984e97259bab3ab2de2f3b9cca0d9a097550d (patch)
treeb9461d8acc5de1df006f6a8396b2a6dfb36e5d91 /protocols
parent2cd071fd8de860655b981d22ecac139cd6e4411b (diff)
Facebook: Rework working with timestamps; version bump
Use time_t almost everywhere instead of DWORD and remove fix_timestamp method to replace it with to_timestamp git-svn-id: http://svn.miranda-ng.org/main/trunk@11599 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'protocols')
-rw-r--r--protocols/FacebookRM/src/captcha.cpp2
-rw-r--r--protocols/FacebookRM/src/client.h14
-rw-r--r--protocols/FacebookRM/src/communication.cpp19
-rw-r--r--protocols/FacebookRM/src/db.h2
-rw-r--r--protocols/FacebookRM/src/entities.h7
-rw-r--r--protocols/FacebookRM/src/json.cpp15
-rw-r--r--protocols/FacebookRM/src/process.cpp48
-rw-r--r--protocols/FacebookRM/src/proto.cpp2
-rw-r--r--protocols/FacebookRM/src/utils.cpp23
-rw-r--r--protocols/FacebookRM/src/utils.h3
-rw-r--r--protocols/FacebookRM/src/version.h2
11 files changed, 60 insertions, 77 deletions
diff --git a/protocols/FacebookRM/src/captcha.cpp b/protocols/FacebookRM/src/captcha.cpp
index ca583f669d..4873667665 100644
--- a/protocols/FacebookRM/src/captcha.cpp
+++ b/protocols/FacebookRM/src/captcha.cpp
@@ -53,7 +53,7 @@ static INT_PTR CALLBACK CaptchaFormDlgProc(HWND hwndDlg, UINT msg, WPARAM wParam
case IDC_WHITERECT:
case IDC_INSTRUCTION:
case IDC_TITLE:
- return (BOOL)GetStockObject(WHITE_BRUSH);
+ return (INT_PTR)GetStockObject(WHITE_BRUSH);
}
return NULL;
diff --git a/protocols/FacebookRM/src/client.h b/protocols/FacebookRM/src/client.h
index 87ff2d1f39..8cf95e9468 100644
--- a/protocols/FacebookRM/src/client.h
+++ b/protocols/FacebookRM/src/client.h
@@ -77,12 +77,12 @@ public:
std::string chat_conn_num_;
std::string chat_clientid_;
std::string chat_traceid_;
- bool is_typing_;
- bool is_idle_;
- bool https_;
- time_t last_feeds_update_;
- unsigned __int64 last_notification_time_;
- int msgid_;
+ bool is_typing_;
+ bool is_idle_;
+ bool https_;
+ time_t last_feeds_update_;
+ time_t last_notification_time_;
+ int msgid_;
////////////////////////////////////////////////////////////
@@ -184,7 +184,7 @@ public:
// Messages handling
std::map<std::string, int> messages_ignore;
- std::map<int, DWORD> messages_timestamp;
+ std::map<int, time_t> messages_timestamp;
bool channel();
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 2150ff6ab5..df86bfed9d 100644
--- a/protocols/FacebookRM/src/communication.cpp
+++ b/protocols/FacebookRM/src/communication.cpp
@@ -1335,19 +1335,18 @@ int facebook_client::send_message(int seqid, MCONTACT hContact, const std::strin
if (!parent->isChatRoom(hContact))
parent->setString(hContact, FACEBOOK_KEY_MESSAGE_ID, mid.c_str());
- // Remember last action timestamp
+ // Get timestamp
std::string timestamp = utils::text::source_get_value(&resp.data, 2, "\"timestamp\":", ",");
- parent->setString(FACEBOOK_KEY_LAST_ACTION_TIMESTAMP, timestamp.c_str());
+ time_t time = utils::time::from_string(timestamp);
+
+ // Remember last action timestamp for history sync
+ parent->setDword(FACEBOOK_KEY_LAST_ACTION_TS, time);
- // For classic conversation we try to remember and then replace timestamp of added event in OnPreCreateEvent()
- if (seqid > 0) {
- long long time = _atoi64(timestamp.c_str());
- if (time > 100000000000)
- time /= 1000;
-
- messages_timestamp.insert(std::make_pair(seqid, (DWORD)time));
- }
+ // For classic conversation we try to replace timestamp of added event in OnPreCreateEvent()
+ if (seqid > 0)
+ messages_timestamp.insert(std::make_pair(seqid, time));
+ // We have this message in database, so ignore further tries (in channel) to add it again
messages_ignore.insert(std::make_pair(mid, 0));
} break;
diff --git a/protocols/FacebookRM/src/db.h b/protocols/FacebookRM/src/db.h
index 1205f3b763..0825a0765a 100644
--- a/protocols/FacebookRM/src/db.h
+++ b/protocols/FacebookRM/src/db.h
@@ -62,7 +62,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#define FACEBOOK_KEY_FILTER_ADS "FilterAds"
#define FACEBOOK_KEY_LOGON_TS "LogonTS"
#define FACEBOOK_KEY_LOGIN_SYNC "LoginSync" // (byte) 0 = get only unread messages, 1 = sync messages since last activity (default is 0)
-#define FACEBOOK_KEY_LAST_ACTION_TIMESTAMP "LastActionTimestamp"
+#define FACEBOOK_KEY_LAST_ACTION_TS "LastActionTS"
#define FACEBOOK_KEY_MESSAGES_ON_OPEN "MessagesOnOpen"
#define FACEBOOK_KEY_MESSAGES_ON_OPEN_COUNT "MessagesOnOpenCount"
#define FACEBOOK_KEY_HIDE_CHATS "HideChats"
diff --git a/protocols/FacebookRM/src/entities.h b/protocols/FacebookRM/src/entities.h
index e83760595b..e8daefaec1 100644
--- a/protocols/FacebookRM/src/entities.h
+++ b/protocols/FacebookRM/src/entities.h
@@ -33,7 +33,7 @@ struct facebook_user
unsigned int status_id;
unsigned int gender;
- DWORD last_active;
+ time_t last_active;
std::string image_url;
@@ -81,7 +81,7 @@ struct facebook_chatroom
std::string message_readers;
- DWORD last_active;
+ time_t last_active;
};
struct facebook_message
@@ -91,8 +91,7 @@ struct facebook_message
std::string message_text;
std::string message_id;
std::string thread_id;
- std::string timestamp;
- DWORD time;
+ time_t time;
bool isIncoming;
bool isUnread;
bool isChat;
diff --git a/protocols/FacebookRM/src/json.cpp b/protocols/FacebookRM/src/json.cpp
index 701b88f633..3a08e928fa 100644
--- a/protocols/FacebookRM/src/json.cpp
+++ b/protocols/FacebookRM/src/json.cpp
@@ -262,7 +262,7 @@ int facebook_json_parser::parse_notifications(std::string *data, std::map< std::
notification->id = id;
notification->link = utils::text::source_get_value(&text, 3, "<a ", "href=\"", "\"");
notification->text = utils::text::remove_html(utils::text::source_get_value(&text, 1, "<abbr"));
- notification->time = utils::time::fix_timestamp(json_as_float(time));
+ notification->time = utils::time::from_string(json_as_pstring(time));
// Write notification to chatroom
proto->UpdateNotificationsChatRoom(notification);
@@ -442,7 +442,7 @@ int facebook_json_parser::parse_messages(std::string *data, std::vector< faceboo
if (reader == NULL || time == NULL)
continue;
- time_t timestamp = utils::time::fix_timestamp(json_as_float(time));
+ time_t timestamp = utils::time::from_string(json_as_pstring(time));
JSONNODE *threadid = json_get(it, "tid");
if (threadid != NULL) { // multi user chat
@@ -546,8 +546,7 @@ int facebook_json_parser::parse_messages(std::string *data, std::vector< faceboo
message->isUnread = true;
message->isIncoming = (id != proto->facy.self_.user_id);
message->message_text = message_text;
- message->timestamp = json_as_pstring(timestamp);
- message->time = utils::time::fix_timestamp(json_as_float(timestamp));
+ message->time = utils::time::from_string(json_as_pstring(timestamp));
message->user_id = id;
message->message_id = message_id;
message->sender_name = utils::text::slashu_to_utf8(json_as_pstring(sender_name)); // TODO: or if not incomming use my own name from facy.self_ ?
@@ -589,7 +588,7 @@ int facebook_json_parser::parse_messages(std::string *data, std::vector< faceboo
if (time == NULL || text == NULL || url == NULL || alert_id == NULL)
continue;
- double timestamp = json_as_float(time);
+ time_t timestamp = utils::time::from_string(json_as_pstring(time));
if (timestamp > proto->facy.last_notification_time_) {
// Only new notifications
proto->facy.last_notification_time_ = timestamp;
@@ -598,7 +597,7 @@ int facebook_json_parser::parse_messages(std::string *data, std::vector< faceboo
notification->text = utils::text::slashu_to_utf8(json_as_pstring(text));
notification->link = json_as_pstring(url);
notification->id = json_as_pstring(alert_id);
- notification->time = utils::time::fix_timestamp(timestamp);
+ notification->time = timestamp;
std::string::size_type pos = notification->id.find(":");
if (pos != std::string::npos)
@@ -755,7 +754,7 @@ int facebook_json_parser::parse_messages(std::string *data, std::vector< faceboo
message->isUnread = true;
message->isIncoming = (id != proto->facy.self_.user_id);
message->message_text = message_text;
- message->time = utils::time::fix_timestamp(json_as_float(timestamp));
+ message->time = utils::time::from_string(json_as_pstring(timestamp));
message->user_id = id;
message->message_id = message_id;
message->sender_name.clear();
@@ -970,7 +969,7 @@ int facebook_json_parser::parse_thread_messages(std::string *data, std::vector<
message->message_text = message_text;
if (author_email != NULL)
message->sender_name = json_as_pstring(author_email);
- message->time = utils::time::fix_timestamp(json_as_float(timestamp));
+ message->time = utils::time::from_string(json_as_pstring(timestamp));
message->thread_id = thread_id;
message->message_id = message_id;
message->isIncoming = (author_id != proto->facy.self_.user_id);
diff --git a/protocols/FacebookRM/src/process.cpp b/protocols/FacebookRM/src/process.cpp
index bfe0f458eb..6f64727bc1 100644
--- a/protocols/FacebookRM/src/process.cpp
+++ b/protocols/FacebookRM/src/process.cpp
@@ -568,34 +568,27 @@ void FacebookProto::SyncThreads(void*)
if (isOffline())
return;
- // get timestamp of last action (last message or possibly logout time)
- ptrA ptrtimestamp(getStringA(FACEBOOK_KEY_LAST_ACTION_TIMESTAMP));
+ // Get timestamp of last action (message or other event)
+ time_t timestamp = getDword(FACEBOOK_KEY_LAST_ACTION_TS, 0);
- std::string timestamp = "0";
- if (ptrtimestamp != NULL)
- timestamp = ptrtimestamp;
+ // If last event is older than 1 day, we force sync to be 1 day old
+ time_t yesterday = ::time(NULL) - 24 * 60 * 60;
+ if (timestamp < yesterday) {
+ debugLogA("Last action timestamp is too old: %d, use 24 hours old instead: %d", timestamp, yesterday);
+ timestamp = yesterday;
- long long time = _atoi64(timestamp.c_str());
-
- if (time > 100000000000) {
- time /= 1000;
- }
-
- 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";
-
- ForkThread(&FacebookProto::ProcessUnreadMessages, NULL); // for older unread messages (necessary?)
+ // And load older unread messages that we might not get otherwise
+ ProcessUnreadMessages(NULL);
}
- setString(FACEBOOK_KEY_LAST_ACTION_TIMESTAMP, utils::time::mili_timestamp().c_str());
-
-
- // receive messages from all folders by default, use hidden setting to receive only inbox messages
+ // Receive messages from all folders by default, use hidden setting to receive only inbox messages
bool inboxOnly = getBool(FACEBOOK_KEY_INBOX_ONLY, 0);
+ // Get milli timestamp string for Facebook
+ std::string time = utils::conversion::to_string((void*)&timestamp, UTILS_CONV_TIME_T) + "000";
+
std::string data = "client=mercury";
- data += "&last_action_timestamp=" + timestamp;
+ data += "&last_action_timestamp=" + time;
data += "&__user=" + facy.self_.user_id;
data += "&fb_dtsg=" + facy.dtsg_;
data += "&folders[0]=inbox";
@@ -603,7 +596,7 @@ void FacebookProto::SyncThreads(void*)
data += "&folders[1]=other";
data += "&__req=7&__a=1&__dyn=&__req=&__rev=&ttstamp=" + facy.ttstamp();
- debugLogA("Sync timestamp: %s", timestamp.c_str());
+ debugLogA("Facebook's milli timestamp for sync: %s", time.c_str());
http::response resp = facy.flap(REQUEST_THREAD_SYNC, &data);
@@ -612,29 +605,26 @@ void FacebookProto::SyncThreads(void*)
return;
}
-
CODE_BLOCK_TRY
- std::vector<facebook_message*> messages;
+ std::vector<facebook_message*> messages;
std::map<std::string, facebook_chatroom*> chatrooms;
facebook_json_parser* p = new facebook_json_parser(this);
p->parse_thread_messages(&resp.data, &messages, &chatrooms, false, false);
delete p;
-
ReceiveMessages(messages, true);
debugLogA("***** Thread messages processed");
CODE_BLOCK_CATCH
- debugLogA("***** Error processing thread messages: %s", e.what());
+ debugLogA("***** Error processing thread messages: %s", e.what());
CODE_BLOCK_END
- facy.handle_success("SyncThreads");
-
+ facy.handle_success("SyncThreads");
}
@@ -739,7 +729,7 @@ void FacebookProto::ReceiveMessages(std::vector<facebook_message*> messages, boo
// We don't want to save (this) message ID for chatrooms
// setString(hChatContact, FACEBOOK_KEY_MESSAGE_ID, messages[i]->message_id.c_str());
- setString(FACEBOOK_KEY_LAST_ACTION_TIMESTAMP, messages[i]->timestamp.c_str());
+ setDword(FACEBOOK_KEY_LAST_ACTION_TS, messages[i]->time);
// Save TID if not exists already
ptrA tid(getStringA(hChatContact, FACEBOOK_KEY_TID));
diff --git a/protocols/FacebookRM/src/proto.cpp b/protocols/FacebookRM/src/proto.cpp
index 23eac2a9fd..f1785af1d5 100644
--- a/protocols/FacebookRM/src/proto.cpp
+++ b/protocols/FacebookRM/src/proto.cpp
@@ -595,7 +595,7 @@ int FacebookProto::OnPreCreateEvent(WPARAM, LPARAM lParam)
if (strcmp(GetContactProto(evt->hContact), m_szModuleName))
return 0;
- std::map<int, DWORD>::iterator it = facy.messages_timestamp.find(evt->seq);
+ std::map<int, time_t>::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;
diff --git a/protocols/FacebookRM/src/utils.cpp b/protocols/FacebookRM/src/utils.cpp
index bceae044cf..3f1043728b 100644
--- a/protocols/FacebookRM/src/utils.cpp
+++ b/protocols/FacebookRM/src/utils.cpp
@@ -54,22 +54,19 @@ std::string utils::time::mili_timestamp()
return timestamp.substr(0, 13);
}
-DWORD utils::time::fix_timestamp(unsigned __int64 mili_timestamp)
+time_t utils::time::from_string(const std::string &data)
{
- // If it is really mili_timestamp
- if (mili_timestamp > 100000000000)
- mili_timestamp /= 1000;
+ long long timestamp = _atoi64(data.c_str());
- return (DWORD)mili_timestamp;
-}
+ // If it is milli timestamp
+ if (timestamp > 100000000000)
+ timestamp /= 1000;
-DWORD utils::conversion::to_timestamp(const std::string &data)
-{
- DWORD timestamp = NULL;
- if (!utils::conversion::from_string<DWORD>(timestamp, data, std::dec)) {
- timestamp = static_cast<DWORD>(::time(NULL));
- }
- return timestamp;
+ // If conversion fails, use local time?
+ //if (!timestamp)
+ // timestamp = ::time(NULL);
+
+ return (time_t)timestamp;
}
std::string utils::conversion::to_string(void* data, WORD type)
diff --git a/protocols/FacebookRM/src/utils.h b/protocols/FacebookRM/src/utils.h
index 6a5943e0a3..67083c1a0c 100644
--- a/protocols/FacebookRM/src/utils.h
+++ b/protocols/FacebookRM/src/utils.h
@@ -43,7 +43,7 @@ namespace utils
{
std::string unix_timestamp();
std::string mili_timestamp();
- DWORD fix_timestamp(unsigned __int64 mili_timestamp);
+ time_t from_string(const std::string &data);
};
namespace number
@@ -71,7 +71,6 @@ namespace utils
namespace conversion
{
- DWORD to_timestamp(const std::string &data);
std::string to_string(void*, WORD type);
template <class T>
diff --git a/protocols/FacebookRM/src/version.h b/protocols/FacebookRM/src/version.h
index fd1aaf6101..e782d40cce 100644
--- a/protocols/FacebookRM/src/version.h
+++ b/protocols/FacebookRM/src/version.h
@@ -1,7 +1,7 @@
#define __MAJOR_VERSION 0
#define __MINOR_VERSION 2
#define __RELEASE_NUM 9
-#define __BUILD_NUM 8
+#define __BUILD_NUM 9
#include <stdver.h>