diff options
author | Robert Pösel <robyer@seznam.cz> | 2016-09-06 03:53:05 +0000 |
---|---|---|
committer | Robert Pösel <robyer@seznam.cz> | 2016-09-06 03:53:05 +0000 |
commit | 910d3cab907dc5649a01bab756dc78af74a23981 (patch) | |
tree | fc0254ce435d41e553c0c1b815edc6a00067f465 /protocols/FacebookRM/src | |
parent | a41b7bafb1181d2953c977b3c3f9ee3d746e5cd7 (diff) |
Facebook: Improve loading history
* Allow loading history only for one contact at a time
* Make text in messagebox translatable and use question instead of warning type
* Don't load and refresh stickers during history loading (so it won't be slow)
git-svn-id: http://svn.miranda-ng.org/main/trunk@17264 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'protocols/FacebookRM/src')
-rw-r--r-- | protocols/FacebookRM/src/client.h | 6 | ||||
-rw-r--r-- | protocols/FacebookRM/src/json.cpp | 2 | ||||
-rw-r--r-- | protocols/FacebookRM/src/messages.cpp | 6 | ||||
-rw-r--r-- | protocols/FacebookRM/src/process.cpp | 54 | ||||
-rw-r--r-- | protocols/FacebookRM/src/proto.cpp | 14 |
5 files changed, 50 insertions, 32 deletions
diff --git a/protocols/FacebookRM/src/client.h b/protocols/FacebookRM/src/client.h index 5b2c6da90f..1747e07496 100644 --- a/protocols/FacebookRM/src/client.h +++ b/protocols/FacebookRM/src/client.h @@ -39,7 +39,7 @@ public: {
msgid_ = error_count_ = last_feeds_update_ = last_notification_time_ = random_ = chat_msgs_recv_ = chat_req_ = 0;
- send_message_lock_ = notifications_lock_ = cookies_lock_ = NULL;
+ send_message_lock_ = notifications_lock_ = cookies_lock_ = loading_history_lock_ = NULL;
hChannelCon = NULL;
hMessagesCon = NULL;
hFcbCon = NULL;
@@ -48,6 +48,7 @@ public: parent = NULL;
mbasicWorks = true;
+ loading_history = false;
}
HANDLE hChannelCon;
@@ -195,6 +196,9 @@ public: std::map<std::string, int> messages_ignore;
std::map<int, time_t> messages_timestamp;
+
+ bool loading_history;
+ HANDLE loading_history_lock_;
bool channel();
bool activity_ping();
diff --git a/protocols/FacebookRM/src/json.cpp b/protocols/FacebookRM/src/json.cpp index 720a842da8..19597bf2bd 100644 --- a/protocols/FacebookRM/src/json.cpp +++ b/protocols/FacebookRM/src/json.cpp @@ -333,7 +333,7 @@ void parseAttachments(FacebookProto *proto, std::string *message_text, const JSO attachments_text += sticker; // Stickers as smileys - if (proto->getByte(FACEBOOK_KEY_CUSTOM_SMILEYS, DEFAULT_CUSTOM_SMILEYS)) { + if (proto->getByte(FACEBOOK_KEY_CUSTOM_SMILEYS, DEFAULT_CUSTOM_SMILEYS) && !proto->facy.loading_history) { // FIXME: rewrite smileyadd to use custom smileys per protocol and not per contact and then remove this ugliness if (!other_user_fbid.empty()) { MCONTACT hContact = proto->ContactIDToHContact(other_user_fbid); diff --git a/protocols/FacebookRM/src/messages.cpp b/protocols/FacebookRM/src/messages.cpp index 425f926912..7ef0488313 100644 --- a/protocols/FacebookRM/src/messages.cpp +++ b/protocols/FacebookRM/src/messages.cpp @@ -193,6 +193,10 @@ void FacebookProto::ReadMessageWorker(void *p) void FacebookProto::StickerAsSmiley(std::string sticker, const std::string &url, MCONTACT hContact) { + // Don't load stickers as smileys when we're loading history + if (facy.loading_history) + return; + std::string b64 = ptrA(mir_base64_encode((PBYTE)sticker.c_str(), (unsigned)sticker.length())); b64 = utils::url::encode(b64); @@ -202,7 +206,7 @@ void FacebookProto::StickerAsSmiley(std::string sticker, const std::string &url, filename += (wchar_t*)_A2T(b64.c_str()); filename += L".png"; - // Check if we have this sticker already and download it it not + // Check if we have this sticker already and download it if not if (GetFileAttributes(filename.c_str()) == INVALID_FILE_ATTRIBUTES) { HANDLE nlc = NULL; facy.save_url(url, filename, nlc); diff --git a/protocols/FacebookRM/src/process.cpp b/protocols/FacebookRM/src/process.cpp index 6508f12fcd..4685d3cdcd 100644 --- a/protocols/FacebookRM/src/process.cpp +++ b/protocols/FacebookRM/src/process.cpp @@ -409,7 +409,10 @@ void FacebookProto::LoadHistory(void *pParam) MCONTACT hContact = *(MCONTACT*)pParam; delete (MCONTACT*)pParam; - if (!isOnline()) + ScopedLock s(facy.loading_history_lock_); + + // Allow loading history only from one contact at a time + if (!isOnline() || facy.loading_history) return; facy.handle_entry("LoadHistory"); @@ -447,6 +450,8 @@ void FacebookProto::LoadHistory(void *pParam) // Temporarily disable marking messages as read for this contact facy.ignore_read.insert(hContact); + // Mark we're loading history, so we can behave differently (e.g., stickers won't be refreshed as it slows the whole process down drastically) + facy.loading_history = true; POPUPDATAW pd = { sizeof(pd) }; pd.iSeconds = 5; @@ -499,37 +504,30 @@ void FacebookProto::LoadHistory(void *pParam) } lastMessageId = msg.message_id; - if (msg.isIncoming && msg.isUnread && msg.type == MESSAGE) { - PROTORECVEVENT recv = { 0 }; - recv.szMessage = const_cast<char*>(msg.message_text.c_str()); - recv.timestamp = msg.time; - ProtoChainRecvMsg(hContact, &recv); - } - else { - DBEVENTINFO dbei = { 0 }; - dbei.cbSize = sizeof(dbei); + // We don't use ProtoChainRecvMsg here as this is just loading of old messages, which we just add to log + DBEVENTINFO dbei = { 0 }; + dbei.cbSize = sizeof(dbei); - if (msg.type == MESSAGE) - dbei.eventType = EVENTTYPE_MESSAGE; - else if (msg.type == VIDEO_CALL || msg.type == PHONE_CALL) - dbei.eventType = FACEBOOK_EVENTTYPE_CALL; - else - dbei.eventType = EVENTTYPE_URL; // FIXME: Use better and specific type for our other event types. + if (msg.type == MESSAGE) + dbei.eventType = EVENTTYPE_MESSAGE; + else if (msg.type == VIDEO_CALL || msg.type == PHONE_CALL) + dbei.eventType = FACEBOOK_EVENTTYPE_CALL; + else + dbei.eventType = EVENTTYPE_URL; // FIXME: Use better and specific type for our other event types. - dbei.flags = DBEF_UTF; + dbei.flags = DBEF_UTF; - if (!msg.isIncoming) - dbei.flags |= DBEF_SENT; + if (!msg.isIncoming) + dbei.flags |= DBEF_SENT; - if (!msg.isUnread) - dbei.flags |= DBEF_READ; + if (!msg.isUnread) + dbei.flags |= DBEF_READ; - dbei.szModule = m_szModuleName; - dbei.timestamp = msg.time; - dbei.cbBlob = (DWORD)msg.message_text.length() + 1; - dbei.pBlob = (PBYTE)msg.message_text.c_str(); - db_event_add(hContact, &dbei); - } + dbei.szModule = m_szModuleName; + dbei.timestamp = msg.time; + dbei.cbBlob = (DWORD)msg.message_text.length() + 1; + dbei.pBlob = (PBYTE)msg.message_text.c_str(); + db_event_add(hContact, &dbei); loadedMessages++; } @@ -571,6 +569,8 @@ void FacebookProto::LoadHistory(void *pParam) // Enable marking messages as read for this contact facy.ignore_read.erase(hContact); + // Reset loading history flag + facy.loading_history = false; if (ServiceExists(MS_POPUP_CHANGETEXTW) && popupHwnd) { PUChangeTextW(popupHwnd, TranslateT("Loading history completed.")); diff --git a/protocols/FacebookRM/src/proto.cpp b/protocols/FacebookRM/src/proto.cpp index 291911d345..e815af9250 100644 --- a/protocols/FacebookRM/src/proto.cpp +++ b/protocols/FacebookRM/src/proto.cpp @@ -36,6 +36,7 @@ FacebookProto::FacebookProto(const char* proto_name, const wchar_t* username) : facy.fcb_conn_lock_ = CreateMutex(NULL, FALSE, NULL); facy.notifications_lock_ = CreateMutex(NULL, FALSE, NULL); facy.cookies_lock_ = CreateMutex(NULL, FALSE, NULL); + facy.loading_history_lock_ = CreateMutex(NULL, FALSE, NULL); // Initialize random seed for this client facy.random_ = ::time(NULL) + PtrToUint(&facy); @@ -127,6 +128,7 @@ FacebookProto::~FacebookProto() WaitForSingleObject(facy.send_message_lock_, IGNORE); WaitForSingleObject(facy.notifications_lock_, IGNORE); WaitForSingleObject(facy.cookies_lock_, IGNORE); + WaitForSingleObject(facy.loading_history_lock_, IGNORE); CloseHandle(signon_lock_); CloseHandle(avatar_lock_); @@ -136,6 +138,7 @@ FacebookProto::~FacebookProto() CloseHandle(facy.fcb_conn_lock_); CloseHandle(facy.notifications_lock_); CloseHandle(facy.cookies_lock_); + CloseHandle(facy.loading_history_lock_); } ////////////////////////////////////////////////////////////////////////////// @@ -782,6 +785,13 @@ INT_PTR FacebookProto::LoadHistory(WPARAM wParam, LPARAM) if (isChatRoom(hContact)) return 0; + // Allow loading history only from one contact at a time + if (facy.loading_history) { + const wchar_t *message = TranslateT("Loading history is already in progress. It can't run for more contacts at once so please wait until it finishes."); + MessageBox(0, message, m_tszUserName, MB_ICONWARNING | MB_OK); + return 0; + } + ptrW name(getWStringA(hContact, FACEBOOK_KEY_NICK)); if (name == NULL) name = getWStringA(hContact, FACEBOOK_KEY_ID); @@ -790,9 +800,9 @@ INT_PTR FacebookProto::LoadHistory(WPARAM wParam, LPARAM) CMStringW title; title.AppendFormat(L"%s - %s", m_tszUserName, name); - CMStringW message("This will load all messages from the server. It might take a while, so be patient.\n\nDo you want to continue?"); + const wchar_t *message = TranslateT("This will load all messages from the server. To avoid having duplicit messages in your history, delete existing messages manually before continuing.\nLoading process might take a while, so be patient.\n\nDo you want to continue?"); - if (MessageBox(0, message, title, MB_ICONWARNING | MB_YESNO | MB_DEFBUTTON2) == IDYES) { + if (MessageBox(0, message, title, MB_ICONQUESTION | MB_YESNO | MB_DEFBUTTON2) == IDYES) { ForkThread(&FacebookProto::LoadHistory, new MCONTACT(hContact)); } |