summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--protocols/FacebookRM/src/chat.cpp7
-rw-r--r--protocols/FacebookRM/src/client.h2
-rw-r--r--protocols/FacebookRM/src/communication.cpp23
-rw-r--r--protocols/FacebookRM/src/db.h1
-rw-r--r--protocols/FacebookRM/src/entities.h10
-rw-r--r--protocols/FacebookRM/src/json.cpp32
-rw-r--r--protocols/FacebookRM/src/proto.cpp12
-rw-r--r--protocols/FacebookRM/src/version.h2
8 files changed, 46 insertions, 43 deletions
diff --git a/protocols/FacebookRM/src/chat.cpp b/protocols/FacebookRM/src/chat.cpp
index f2108e48a6..4ed39f0afa 100644
--- a/protocols/FacebookRM/src/chat.cpp
+++ b/protocols/FacebookRM/src/chat.cpp
@@ -49,12 +49,7 @@ void FacebookProto::UpdateChat(const TCHAR *tchat_id, const char *id, const char
gce.ptszUID = tid;
CallServiceSync(MS_GC_EVENT, 0, reinterpret_cast<LPARAM>(&gce));
- // TODO: keep it here or move it somewhere else?
- std::map<std::tstring, facebook_chatroom*>::iterator chatroom = facy.chat_rooms.find(tchat_id);
- if (chatroom != facy.chat_rooms.end()) {
- chatroom->second->message_readers.clear(); // TODO: move this to erase_reader method?
- facy.erase_reader(ChatIDToHContact(std::tstring(tchat_id)));
- }
+ facy.erase_reader(ChatIDToHContact(std::tstring(tchat_id)));
}
void FacebookProto::RenameChat(const char *chat_id, const char *name)
diff --git a/protocols/FacebookRM/src/client.h b/protocols/FacebookRM/src/client.h
index 3ffdce96b2..652a5b3dfa 100644
--- a/protocols/FacebookRM/src/client.h
+++ b/protocols/FacebookRM/src/client.h
@@ -122,7 +122,7 @@ public:
void clear_notifications();
void clear_chatrooms();
void clear_readers();
- void insert_reader(MCONTACT, time_t);
+ void insert_reader(MCONTACT, time_t, const std::tstring &reader = _T(""));
void erase_reader(MCONTACT);
////////////////////////////////////////////////////////////
diff --git a/protocols/FacebookRM/src/communication.cpp b/protocols/FacebookRM/src/communication.cpp
index 2c84a18b5b..88ce68ba1c 100644
--- a/protocols/FacebookRM/src/communication.cpp
+++ b/protocols/FacebookRM/src/communication.cpp
@@ -654,6 +654,10 @@ void facebook_client::clear_chatrooms()
void facebook_client::clear_readers()
{
for (std::map<MCONTACT, time_t>::iterator it = readers.begin(); it != readers.end();) {
+ if (parent->isChatRoom(it->first)) {
+ parent->delSetting(it->first, FACEBOOK_KEY_MESSAGE_READERS);
+ }
+
parent->delSetting(it->first, FACEBOOK_KEY_MESSAGE_READ);
it = readers.erase(it);
}
@@ -663,8 +667,21 @@ void facebook_client::clear_readers()
/**
* Inserts info to readers list, db and writes to statusbar
*/
-void facebook_client::insert_reader(MCONTACT hContact, time_t timestamp)
+void facebook_client::insert_reader(MCONTACT hContact, time_t timestamp, const std::tstring &reader)
{
+ if (parent->isChatRoom(hContact)) {
+ std::tstring treaders;
+
+ // Load old readers
+ ptrT told(parent->getTStringA(hContact, FACEBOOK_KEY_MESSAGE_READERS));
+ if (told)
+ treaders = std::tstring(told) + _T(", ");
+
+ // Append new reader name and remember them
+ treaders += utils::text::prepare_name(reader, true);
+ parent->setTString(hContact, FACEBOOK_KEY_MESSAGE_READERS, treaders.c_str());
+ }
+
parent->setDword(hContact, FACEBOOK_KEY_MESSAGE_READ, timestamp);
readers.insert(std::make_pair(hContact, timestamp));
parent->MessageRead(hContact);
@@ -675,6 +692,10 @@ void facebook_client::insert_reader(MCONTACT hContact, time_t timestamp)
*/
void facebook_client::erase_reader(MCONTACT hContact)
{
+ if (parent->isChatRoom(hContact)) {
+ parent->delSetting(hContact, FACEBOOK_KEY_MESSAGE_READERS);
+ }
+
parent->delSetting(hContact, FACEBOOK_KEY_MESSAGE_READ);
readers.erase(hContact);
CallService(MS_MSG_SETSTATUSTEXT, (WPARAM)hContact, NULL);
diff --git a/protocols/FacebookRM/src/db.h b/protocols/FacebookRM/src/db.h
index f5c4c22f14..dde49edca6 100644
--- a/protocols/FacebookRM/src/db.h
+++ b/protocols/FacebookRM/src/db.h
@@ -38,6 +38,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#define FACEBOOK_KEY_CONTACT_TYPE "ContactType"
#define FACEBOOK_KEY_MESSAGE_ID "LastMessageId"
#define FACEBOOK_KEY_MESSAGE_READ "MessageRead"
+#define FACEBOOK_KEY_MESSAGE_READERS "MessageReaders"
// Contact and account DB keys
#define FACEBOOK_KEY_KEEP_UNREAD "KeepUnread" // (byte) 1 = don't mark messages as read on server (works globally or per contact)
diff --git a/protocols/FacebookRM/src/entities.h b/protocols/FacebookRM/src/entities.h
index 68ece467e1..b335c6cf43 100644
--- a/protocols/FacebookRM/src/entities.h
+++ b/protocols/FacebookRM/src/entities.h
@@ -70,18 +70,12 @@ struct facebook_user
};
struct facebook_chatroom
-{
- facebook_chatroom(std::tstring thread_id) : thread_id(thread_id) {
- this->last_active = 0;
- }
-
+{
std::tstring thread_id;
std::tstring chat_name;
std::map<std::string, std::string> participants;
- std::tstring message_readers;
-
- time_t last_active;
+ facebook_chatroom(std::tstring thread_id) : thread_id(thread_id) {}
};
struct facebook_message
diff --git a/protocols/FacebookRM/src/json.cpp b/protocols/FacebookRM/src/json.cpp
index 20e1b937e3..5eea6287bc 100644
--- a/protocols/FacebookRM/src/json.cpp
+++ b/protocols/FacebookRM/src/json.cpp
@@ -431,56 +431,52 @@ int facebook_json_parser::parse_messages(std::string *data, std::vector< faceboo
if (t == "read_receipt") {
// user read message
- JSONNODE *reader = json_get(it, "reader");
- JSONNODE *time = json_get(it, "time");
+ JSONNODE *reader_ = json_get(it, "reader");
+ JSONNODE *time_ = json_get(it, "time");
- if (reader == NULL || time == NULL)
+ if (reader_ == NULL || time_ == NULL)
continue;
- time_t timestamp = utils::time::from_string(json_as_pstring(time));
+ time_t timestamp = utils::time::from_string(json_as_pstring(time_));
MCONTACT hContact = NULL;
+ std::tstring reader;
+ std::string readerId = json_as_pstring(reader_);
JSONNODE *threadid = json_get(it, "tid");
if (threadid == NULL) {
// classic contact
- hContact = proto->ContactIDToHContact(json_as_pstring(reader));
+ hContact = proto->ContactIDToHContact(readerId);
} else {
// multi user chat
if (!proto->m_enableChat)
continue;
std::tstring tid = ptrT(json_as_string(threadid));
- std::string reader_id = json_as_pstring(reader);
std::map<std::tstring, facebook_chatroom*>::iterator it = proto->facy.chat_rooms.find(tid);
if (it != proto->facy.chat_rooms.end()) {
facebook_chatroom *chatroom = it->second;
std::map<std::string, std::string> participants = chatroom->participants;
- std::map<std::string, std::string>::const_iterator participant = participants.find(reader_id);
+ std::map<std::string, std::string>::const_iterator participant = participants.find(readerId);
if (participant == participants.end()) {
// TODO: load name of this participant
- std::string name = reader_id;
- participants.insert(std::make_pair(reader_id, name));
- proto->AddChatContact(tid.c_str(), reader_id.c_str(), name.c_str());
+ std::string name = readerId;
+ participants.insert(std::make_pair(readerId, name));
+ proto->AddChatContact(tid.c_str(), readerId.c_str(), name.c_str());
}
- participant = participants.find(reader_id);
+ participant = participants.find(readerId);
if (participant != participants.end()) {
// TODO: remember just reader ids to avoid eventual duplication of names
- if (!chatroom->message_readers.empty())
- chatroom->message_readers += _T(", ");
-
- std::tstring tname = _A2T(participant->second.c_str(), CP_UTF8);
- chatroom->message_readers += utils::text::prepare_name(tname, true);
-
+ reader = _A2T(participant->second.c_str(), CP_UTF8);
hContact = proto->ChatIDToHContact(tid);
}
}
}
if (hContact)
- proto->facy.insert_reader(hContact, timestamp);
+ proto->facy.insert_reader(hContact, timestamp, reader);
}
else if (t == "deliver") {
// inbox message (multiuser or direct)
diff --git a/protocols/FacebookRM/src/proto.cpp b/protocols/FacebookRM/src/proto.cpp
index 47b34e8b39..f3d5cdc222 100644
--- a/protocols/FacebookRM/src/proto.cpp
+++ b/protocols/FacebookRM/src/proto.cpp
@@ -82,6 +82,7 @@ FacebookProto::FacebookProto(const char* proto_name, const TCHAR* username) :
db_set_resident(m_szModuleName, "Status");
db_set_resident(m_szModuleName, "IdleTS");
db_set_resident(m_szModuleName, FACEBOOK_KEY_MESSAGE_READ);
+ db_set_resident(m_szModuleName, FACEBOOK_KEY_MESSAGE_READERS);
InitHotkeys();
InitPopups();
@@ -1111,14 +1112,9 @@ void FacebookProto::MessageRead(MCONTACT hContact)
st.hIcon = Skin_GetIconByHandle(GetIconHandle("read"));
if (isChatRoom(hContact)) {
- // Get threadId to find chatroom in map
- std::tstring tid = ptrT(getTStringA(hContact, FACEBOOK_KEY_TID));
- std::map<std::tstring, facebook_chatroom*>::iterator it = facy.chat_rooms.find(tid);
-
- // Get readers from chatroom
- TCHAR *treaders = (it != facy.chat_rooms.end() ? it->second->message_readers.c_str() : _T("???"));
-
- mir_sntprintf(st.tszText, SIZEOF(st.tszText), TranslateT("Message read: %s by %s"), ttime, treaders);
+ // Load readers names
+ ptrT treaders(getTStringA(hContact, FACEBOOK_KEY_MESSAGE_READERS));
+ mir_sntprintf(st.tszText, SIZEOF(st.tszText), TranslateT("Message read: %s by %s"), ttime, treaders ? treaders : _T("???"));
} else {
mir_sntprintf(st.tszText, SIZEOF(st.tszText), TranslateT("Message read: %s"), ttime);
}
diff --git a/protocols/FacebookRM/src/version.h b/protocols/FacebookRM/src/version.h
index 2735e7c90f..103b6a9a5b 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 10
-#define __BUILD_NUM 4
+#define __BUILD_NUM 5
#include <stdver.h>