summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--protocols/FacebookRM/src/chat.cpp39
-rw-r--r--protocols/FacebookRM/src/communication.cpp4
-rw-r--r--protocols/FacebookRM/src/contacts.cpp31
-rw-r--r--protocols/FacebookRM/src/process.cpp9
-rw-r--r--protocols/FacebookRM/src/proto.h1
-rw-r--r--utils/std_string_utils.cpp10
-rw-r--r--utils/std_string_utils.h2
7 files changed, 54 insertions, 42 deletions
diff --git a/protocols/FacebookRM/src/chat.cpp b/protocols/FacebookRM/src/chat.cpp
index d271b544f9..126976137f 100644
--- a/protocols/FacebookRM/src/chat.cpp
+++ b/protocols/FacebookRM/src/chat.cpp
@@ -3,7 +3,7 @@
Facebook plugin for Miranda Instant Messenger
_____________________________________________
-Copyright � 2011-17 Robert P�sel
+Copyright © 2011-17 Robert Pösel
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -432,4 +432,39 @@ void FacebookProto::UpdateNotificationsChatRoom(facebook_notification *notificat
gce.ptszUID = idT;
Chat_Event(&gce);
-} \ No newline at end of file
+}
+
+std::string FacebookProto::GenerateChatName(facebook_chatroom *fbc)
+{
+ std::string name = "";
+ unsigned int namesUsed = 0;
+
+ for (auto it = fbc->participants.begin(); it != fbc->participants.end(); ++it) {
+ std::string participant = it->second.nick;
+
+ // Ignore self contact, empty and numeric only participant names
+ if (it->second.role == ROLE_ME || participant.empty() || participant.find_first_not_of("0123456789") == std::string::npos)
+ continue;
+
+ if (namesUsed > 0)
+ name += ", ";
+
+ name += utils::text::prepare_name(participant, false);
+
+ if (++namesUsed >= FACEBOOK_CHATROOM_NAMES_COUNT)
+ break;
+ }
+
+ // Participants.size()-1 because we ignore self contact
+ if (fbc->participants.size() - 1 > namesUsed) {
+ wchar_t more[200];
+ mir_snwprintf(more, TranslateT("%s and more (%d)"), fbc->chat_name.c_str(), fbc->participants.size() - 1 - namesUsed); // -1 because we ignore self contact
+ fbc->chat_name = more;
+ }
+
+ // If there are no participants to create a name from, use just thread_id
+ if (name.empty())
+ name = fbc->thread_id.c_str();
+
+ return name;
+}
diff --git a/protocols/FacebookRM/src/communication.cpp b/protocols/FacebookRM/src/communication.cpp
index 61e8a3de75..fb2447e8c1 100644
--- a/protocols/FacebookRM/src/communication.cpp
+++ b/protocols/FacebookRM/src/communication.cpp
@@ -353,7 +353,6 @@ void facebook_client::insert_reader(MCONTACT hContact, time_t timestamp, const s
}
}
- std::wstring treaderName = _A2T(name.c_str(), CP_UTF8);
std::wstring treaders;
// Load old readers
@@ -362,7 +361,8 @@ void facebook_client::insert_reader(MCONTACT hContact, time_t timestamp, const s
treaders = std::wstring(told) + L", ";
// Append new reader name and remember them
- treaders += utils::text::prepare_name(treaderName, true);
+ std::string reader = utils::text::prepare_name(name, true);
+ treaders += _A2T(reader.c_str(), CP_UTF8);
parent->setWString(hContact, FACEBOOK_KEY_MESSAGE_READERS, treaders.c_str());
}
diff --git a/protocols/FacebookRM/src/contacts.cpp b/protocols/FacebookRM/src/contacts.cpp
index 60fa9c0247..8f4bf3489b 100644
--- a/protocols/FacebookRM/src/contacts.cpp
+++ b/protocols/FacebookRM/src/contacts.cpp
@@ -332,35 +332,8 @@ void FacebookProto::LoadChatInfo(facebook_chatroom *fbc)
// If chat has no name, create name from participants list
if (fbc->chat_name.empty()) {
- unsigned int namesUsed = 0;
-
- for (auto it = fbc->participants.begin(); it != fbc->participants.end(); ++it) {
- std::string participant = it->second.nick;
-
- // Ignore self contact, empty and numeric only participant names
- if (it->second.role == ROLE_ME || participant.empty() || participant.find_first_not_of("0123456789") == std::string::npos)
- continue;
-
- if (namesUsed > 0)
- fbc->chat_name += L", ";
-
- std::wstring tname = _A2T(participant.c_str(), CP_UTF8);
- fbc->chat_name += utils::text::prepare_name(tname, false);
-
- if (++namesUsed >= FACEBOOK_CHATROOM_NAMES_COUNT)
- break;
- }
-
- // Participants.size()-1 because we ignore self contact
- if (fbc->participants.size() - 1 > namesUsed) {
- wchar_t more[200];
- mir_snwprintf(more, TranslateT("%s and more (%d)"), fbc->chat_name.c_str(), fbc->participants.size() - 1 - namesUsed); // -1 because we ignore self contact
- fbc->chat_name = more;
- }
-
- // If there are no participants to create a name from, use just thread_id
- if (fbc->chat_name.empty())
- fbc->chat_name = std::wstring(_A2T(fbc->thread_id.c_str())); // TODO: is this needed? Isn't it showed automatically as id if there is no name?
+ std::string newName = GenerateChatName(fbc);
+ fbc->chat_name = _A2T(newName.c_str(), CP_UTF8);
}
debugLogA("*** Chat thread info processed");
diff --git a/protocols/FacebookRM/src/process.cpp b/protocols/FacebookRM/src/process.cpp
index 6497145c00..4bc3867d0b 100644
--- a/protocols/FacebookRM/src/process.cpp
+++ b/protocols/FacebookRM/src/process.cpp
@@ -878,11 +878,14 @@ void FacebookProto::ReceiveMessages(std::vector<facebook_message> &messages, boo
}
}
break;
- case THREAD_NAME:
- // proto->RenameChat(thread_id.c_str(), msg.data.c_str()); // this don't work, why?
- setStringUtf(hChatContact, FACEBOOK_KEY_NICK, msg.data.c_str());
+ case THREAD_NAME: {
UpdateChat(thread_id.c_str(), NULL, NULL, msg.message_text.c_str());
+
+ std::string chatName = (!msg.data.empty() ? msg.data : GenerateChatName(fbc));
+ // proto->RenameChat(thread_id.c_str(), chatName.c_str()); // this don't work, why?
+ setStringUtf(hChatContact, FACEBOOK_KEY_NICK, chatName.c_str());
break;
+ }
case THREAD_IMAGE:
UpdateChat(thread_id.c_str(), NULL, NULL, msg.message_text.c_str());
break;
diff --git a/protocols/FacebookRM/src/proto.h b/protocols/FacebookRM/src/proto.h
index 2d46f0f7d6..09797e1481 100644
--- a/protocols/FacebookRM/src/proto.h
+++ b/protocols/FacebookRM/src/proto.h
@@ -225,6 +225,7 @@ public:
bool IsSpecialChatRoom(MCONTACT hContact);
void PrepareNotificationsChatRoom();
void UpdateNotificationsChatRoom(facebook_notification *notification);
+ std::string FacebookProto::GenerateChatName(facebook_chatroom *fbc);
// Connection client
facebook_client facy; // TODO: Refactor to "client" and make dynamic
diff --git a/utils/std_string_utils.cpp b/utils/std_string_utils.cpp
index dc763524f3..49cda52844 100644
--- a/utils/std_string_utils.cpp
+++ b/utils/std_string_utils.cpp
@@ -387,19 +387,19 @@ std::string utils::text::source_get_form_data(std::string* data, bool hiddenOnly
return values;
}
-std::wstring utils::text::prepare_name(const std::wstring &name, bool withSurnameLetter)
+std::string utils::text::prepare_name(const std::string &name, bool withSurnameLetter)
{
- std::wstring::size_type pos = name.find(L" ");
+ std::string::size_type pos = name.find(" ");
if (pos == std::wstring::npos)
return name;
- std::wstring result = name.substr(0, pos);
+ std::string result = name.substr(0, pos);
if (withSurnameLetter) {
- pos = name.rfind(L" ") + 1; // we're sure there is some space in name so we can do +1 safely
+ pos = name.rfind(" ") + 1; // we're sure there is some space in name so we can do +1 safely
if (pos < name.length())
- result += L" " + name.substr(pos, 1) + std::wstring(L".");
+ result += " " + name.substr(pos, 1) + std::string(".");
}
return result;
diff --git a/utils/std_string_utils.h b/utils/std_string_utils.h
index 96ee5ca4d9..2c72e3a918 100644
--- a/utils/std_string_utils.h
+++ b/utils/std_string_utils.h
@@ -76,7 +76,7 @@ namespace utils
std::string truncate_utf8(const std::string &text, size_t maxLength);
void explode(std::string str, const std::string &separator, std::vector<std::string>* results);
void append_ordinal(unsigned long value, std::string* data);
- std::wstring prepare_name(const std::wstring &name, bool withSurnameLetter);
+ std::string prepare_name(const std::string &name, bool withSurnameLetter);
};
namespace conversion