summaryrefslogtreecommitdiff
path: root/protocols/FacebookRM/src
diff options
context:
space:
mode:
authorRobert Pösel <robyer@seznam.cz>2015-03-04 12:05:53 +0000
committerRobert Pösel <robyer@seznam.cz>2015-03-04 12:05:53 +0000
commitb8f9685565a64b1d04d545bfa1ffead2a84547cc (patch)
treeb170497a4e606728e892118bc7c9d2033db5f9e4 /protocols/FacebookRM/src
parent1d7cce364ec2c9793463072063c4f7bb087f5071 (diff)
Facebook: Use participant names in chatroom name / seen info in "Firstname S." format
git-svn-id: http://svn.miranda-ng.org/main/trunk@12312 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'protocols/FacebookRM/src')
-rw-r--r--protocols/FacebookRM/src/contacts.cpp6
-rw-r--r--protocols/FacebookRM/src/entities.h2
-rw-r--r--protocols/FacebookRM/src/json.cpp11
-rw-r--r--protocols/FacebookRM/src/utils.cpp18
-rw-r--r--protocols/FacebookRM/src/utils.h1
5 files changed, 28 insertions, 10 deletions
diff --git a/protocols/FacebookRM/src/contacts.cpp b/protocols/FacebookRM/src/contacts.cpp
index 23a6768638..df86cac727 100644
--- a/protocols/FacebookRM/src/contacts.cpp
+++ b/protocols/FacebookRM/src/contacts.cpp
@@ -304,10 +304,8 @@ void FacebookProto::LoadChatInfo(facebook_chatroom *fbc)
if (namesUsed > 0)
fbc->chat_name += _T(", ");
- std::string::size_type pos = participant.find(" ");
- std::string name = (pos != std::string::npos ? participant.substr(0, pos) : participant);
-
- fbc->chat_name += _A2T(name.c_str(), CP_UTF8);
+ std::tstring tname = _A2T(participant.c_str(), CP_UTF8);
+ fbc->chat_name += utils::text::prepare_name(tname, true);
if (++namesUsed >= FACEBOOK_CHATROOM_NAMES_COUNT)
break;
diff --git a/protocols/FacebookRM/src/entities.h b/protocols/FacebookRM/src/entities.h
index 08f6c9bc79..68ece467e1 100644
--- a/protocols/FacebookRM/src/entities.h
+++ b/protocols/FacebookRM/src/entities.h
@@ -79,7 +79,7 @@ struct facebook_chatroom
std::tstring chat_name;
std::map<std::string, std::string> participants;
- std::string message_readers;
+ std::tstring message_readers;
time_t last_active;
};
diff --git a/protocols/FacebookRM/src/json.cpp b/protocols/FacebookRM/src/json.cpp
index 2ab50f0590..7ef4b78518 100644
--- a/protocols/FacebookRM/src/json.cpp
+++ b/protocols/FacebookRM/src/json.cpp
@@ -462,16 +462,17 @@ int facebook_json_parser::parse_messages(std::string *data, std::vector< faceboo
participant = participants.find(reader_id);
if (participant != participants.end()) {
+ // TODO: remember just reader ids to avoid eventual duplication of names
if (!chatroom->message_readers.empty())
- chatroom->message_readers += ", ";
- chatroom->message_readers += participant->second;
+ chatroom->message_readers += _T(", ");
+
+ std::tstring tname = _A2T(participant->second.c_str(), CP_UTF8);
+ chatroom->message_readers += utils::text::prepare_name(tname, true);
MCONTACT hChatContact = proto->ChatIDToHContact(tid);
if (!hChatContact)
continue;
- ptrT readers(mir_utf8decodeT(chatroom->message_readers.c_str()));
-
StatusTextData st = { 0 };
st.cbSize = sizeof(st);
st.hIcon = Skin_GetIconByHandle(GetIconHandle("read"));
@@ -479,7 +480,7 @@ int facebook_json_parser::parse_messages(std::string *data, std::vector< faceboo
TCHAR ttime[64];
_tcsftime(ttime, SIZEOF(ttime), _T("%X"), localtime(&timestamp));
- mir_sntprintf(st.tszText, SIZEOF(st.tszText), TranslateT("Message read: %s by %s"), ttime, readers);
+ mir_sntprintf(st.tszText, SIZEOF(st.tszText), TranslateT("Message read: %s by %s"), ttime, chatroom->message_readers.c_str());
CallService(MS_MSG_SETSTATUSTEXT, (WPARAM)hChatContact, (LPARAM)&st);
}
diff --git a/protocols/FacebookRM/src/utils.cpp b/protocols/FacebookRM/src/utils.cpp
index f277103203..383aac5d4b 100644
--- a/protocols/FacebookRM/src/utils.cpp
+++ b/protocols/FacebookRM/src/utils.cpp
@@ -456,6 +456,24 @@ std::string utils::text::source_get_form_data(std::string* data)
return values;
}
+std::tstring utils::text::prepare_name(const std::tstring &name, bool withSurnameLetter)
+{
+ std::tstring::size_type pos = name.find(_T(" "));
+ if (pos == std::tstring::npos)
+ return name;
+
+ std::tstring result = name.substr(0, pos);
+
+ if (withSurnameLetter) {
+ pos = name.rfind(_T(" ")) + 1; // we're sure there is some space in name so we can do +1 safely
+
+ if (pos < name.length())
+ result += _T(" ") + name.substr(pos, 1) + std::tstring(_T("."));
+ }
+
+ return result;
+}
+
std::string utils::text::rand_string(int len, const char *chars, unsigned int *number)
{
std::stringstream out;
diff --git a/protocols/FacebookRM/src/utils.h b/protocols/FacebookRM/src/utils.h
index af9cf3ceed..b560b02912 100644
--- a/protocols/FacebookRM/src/utils.h
+++ b/protocols/FacebookRM/src/utils.h
@@ -67,6 +67,7 @@ namespace utils
std::string rand_string(int len, const char *chars = "0123456789" "ABCDEFGHIJKLMNOPQRSTUVWXYZ" "abcdefghijklmnopqrstuvwxyz", unsigned int *number = NULL);
void explode(std::string str, const std::string &separator, std::vector<std::string>* results);
void append_ordinal(unsigned long value, std::string* data);
+ std::tstring prepare_name(const std::tstring &name, bool withSurnameLetter);
};
namespace conversion