diff options
Diffstat (limited to 'protocols/FacebookRM')
-rw-r--r-- | protocols/FacebookRM/src/chat.cpp | 39 | ||||
-rw-r--r-- | protocols/FacebookRM/src/communication.cpp | 4 | ||||
-rw-r--r-- | protocols/FacebookRM/src/contacts.cpp | 31 | ||||
-rw-r--r-- | protocols/FacebookRM/src/process.cpp | 9 | ||||
-rw-r--r-- | protocols/FacebookRM/src/proto.h | 1 |
5 files changed, 48 insertions, 36 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 |