diff options
Diffstat (limited to 'Swift/Controllers')
-rw-r--r-- | Swift/Controllers/Chat/ChatsManager.cpp | 17 | ||||
-rw-r--r-- | Swift/Controllers/Chat/ChatsManager.h | 2 | ||||
-rw-r--r-- | Swift/Controllers/Chat/UserSearchController.cpp | 3 | ||||
-rw-r--r-- | Swift/Controllers/Contact.cpp | 12 | ||||
-rw-r--r-- | Swift/Controllers/ContactProvider.h | 2 | ||||
-rw-r--r-- | Swift/Controllers/ContactSuggester.cpp | 12 | ||||
-rw-r--r-- | Swift/Controllers/ContactSuggester.h | 2 | ||||
-rw-r--r-- | Swift/Controllers/ContactsFromXMPPRoster.cpp | 2 | ||||
-rw-r--r-- | Swift/Controllers/ContactsFromXMPPRoster.h | 2 | ||||
-rw-r--r-- | Swift/Controllers/HighlightEditorController.cpp | 2 |
10 files changed, 43 insertions, 13 deletions
diff --git a/Swift/Controllers/Chat/ChatsManager.cpp b/Swift/Controllers/Chat/ChatsManager.cpp index 3db1327..c180024 100644 --- a/Swift/Controllers/Chat/ChatsManager.cpp +++ b/Swift/Controllers/Chat/ChatsManager.cpp @@ -971,13 +971,28 @@ std::vector<ChatListWindow::Chat> ChatsManager::getRecentChats() const { return std::vector<ChatListWindow::Chat>(recentChats_.begin(), recentChats_.end()); } -std::vector<Contact::ref> Swift::ChatsManager::getContacts() { +std::vector<Contact::ref> Swift::ChatsManager::getContacts(bool withMUCNicks) { std::vector<Contact::ref> result; foreach (ChatListWindow::Chat chat, recentChats_) { if (!chat.isMUC) { result.push_back(boost::make_shared<Contact>(chat.chatName.empty() ? chat.jid.toString() : chat.chatName, chat.jid, chat.statusType, chat.avatarPath)); } } + if (withMUCNicks) { + /* collect MUC nicks */ + typedef std::map<JID, MUCController*>::value_type Item; + foreach (const Item& item, mucControllers_) { + JID mucJID = item.second->getToJID(); + std::map<std::string, JID> participants = item.second->getParticipantJIDs(); + typedef std::map<std::string, JID>::value_type ParticipantType; + foreach (const ParticipantType& participant, participants) { + const JID nickJID = JID(mucJID.getNode(), mucJID.getDomain(), participant.first); + Presence::ref presence = presenceOracle_->getLastPresence(nickJID); + const boost::filesystem::path avatar = avatarManager_->getAvatarPath(nickJID); + result.push_back(boost::make_shared<Contact>(participant.first, JID(), presence->getShow(), avatar)); + } + } + } return result; } diff --git a/Swift/Controllers/Chat/ChatsManager.h b/Swift/Controllers/Chat/ChatsManager.h index 179f536..575b3cb 100644 --- a/Swift/Controllers/Chat/ChatsManager.h +++ b/Swift/Controllers/Chat/ChatsManager.h @@ -73,7 +73,7 @@ namespace Swift { void setServerDiscoInfo(boost::shared_ptr<DiscoInfo> info); void handleIncomingMessage(boost::shared_ptr<Message> message); std::vector<ChatListWindow::Chat> getRecentChats() const; - virtual std::vector<Contact::ref> getContacts(); + virtual std::vector<Contact::ref> getContacts(bool withMUCNicks); boost::signal<void (bool supportsImpromptu)> onImpromptuMUCServiceDiscovered; diff --git a/Swift/Controllers/Chat/UserSearchController.cpp b/Swift/Controllers/Chat/UserSearchController.cpp index f259a9a..f1849c9 100644 --- a/Swift/Controllers/Chat/UserSearchController.cpp +++ b/Swift/Controllers/Chat/UserSearchController.cpp @@ -196,7 +196,8 @@ void UserSearchController::handleNameSuggestionRequest(const JID &jid) { void UserSearchController::handleContactSuggestionsRequested(std::string text) { const std::vector<JID> existingJIDs = window_->getJIDs(); - std::vector<Contact::ref> suggestions = contactSuggester_->getSuggestions(text); + std::vector<Contact::ref> suggestions = contactSuggester_->getSuggestions(text, false); + /* do not suggest contacts that have already been added to the chat list */ std::vector<Contact::ref>::iterator i = suggestions.begin(); while (i != suggestions.end()) { bool found = false; diff --git a/Swift/Controllers/Contact.cpp b/Swift/Controllers/Contact.cpp index 198443d..be2b83a 100644 --- a/Swift/Controllers/Contact.cpp +++ b/Swift/Controllers/Contact.cpp @@ -17,11 +17,19 @@ Contact::Contact(const std::string& name, const JID& jid, StatusShow::Type statu } bool Contact::lexicographicalSortPredicate(const Contact::ref& a, const Contact::ref& b) { - return a->jid < b->jid; + if (a->jid.isValid() && b->jid.isValid()) { + return a->jid < b->jid; + } else { + return a->name < b->name; + } } bool Contact::equalityPredicate(const Contact::ref& a, const Contact::ref& b) { - return a->jid == b->jid; + if (a->jid.isValid() && b->jid.isValid()) { + return a->jid == b->jid; + } else { + return a->name == b->name; + } } bool Contact::sortPredicate(const Contact::ref& a, const Contact::ref& b, const std::string& search) { diff --git a/Swift/Controllers/ContactProvider.h b/Swift/Controllers/ContactProvider.h index 0e56de5..acc2bdc 100644 --- a/Swift/Controllers/ContactProvider.h +++ b/Swift/Controllers/ContactProvider.h @@ -21,7 +21,7 @@ namespace Swift { class ContactProvider { public: virtual ~ContactProvider(); - virtual std::vector<Contact::ref> getContacts() = 0; + virtual std::vector<Contact::ref> getContacts(bool withMUCNicks) = 0; }; } diff --git a/Swift/Controllers/ContactSuggester.cpp b/Swift/Controllers/ContactSuggester.cpp index 42e8308..8627aeb 100644 --- a/Swift/Controllers/ContactSuggester.cpp +++ b/Swift/Controllers/ContactSuggester.cpp @@ -43,14 +43,20 @@ void ContactSuggester::addContactProvider(ContactProvider* provider) { } bool ContactSuggester::matchContact(const std::string& search, const Contact::ref& c) { - return fuzzyMatch(c->name, search) || fuzzyMatch(c->jid.toString(), search); + if (fuzzyMatch(c->name, search)) { + return true; + } + else if (c->jid.isValid()) { + return fuzzyMatch(c->jid.toString(), search); + } + return false; } -std::vector<Contact::ref> ContactSuggester::getSuggestions(const std::string& search) const { +std::vector<Contact::ref> ContactSuggester::getSuggestions(const std::string& search, bool withMUCNicks) const { std::vector<Contact::ref> results; foreach(ContactProvider* provider, contactProviders_) { - append(results, provider->getContacts()); + append(results, provider->getContacts(withMUCNicks)); } std::sort(results.begin(), results.end(), Contact::lexicographicalSortPredicate); diff --git a/Swift/Controllers/ContactSuggester.h b/Swift/Controllers/ContactSuggester.h index 1c796c9..ae47766 100644 --- a/Swift/Controllers/ContactSuggester.h +++ b/Swift/Controllers/ContactSuggester.h @@ -29,7 +29,7 @@ namespace Swift { void addContactProvider(ContactProvider* provider); - std::vector<Contact::ref> getSuggestions(const std::string& search) const; + std::vector<Contact::ref> getSuggestions(const std::string& search, bool withMUCNicks) const; public: static bool matchContact(const std::string& search, const Contact::ref& c); /** diff --git a/Swift/Controllers/ContactsFromXMPPRoster.cpp b/Swift/Controllers/ContactsFromXMPPRoster.cpp index 7559962..abd62bd 100644 --- a/Swift/Controllers/ContactsFromXMPPRoster.cpp +++ b/Swift/Controllers/ContactsFromXMPPRoster.cpp @@ -27,7 +27,7 @@ ContactsFromXMPPRoster::ContactsFromXMPPRoster(XMPPRoster* roster, AvatarManager ContactsFromXMPPRoster::~ContactsFromXMPPRoster() { } -std::vector<Contact::ref> ContactsFromXMPPRoster::getContacts() { +std::vector<Contact::ref> ContactsFromXMPPRoster::getContacts(bool /*withMUCNicks*/) { std::vector<Contact::ref> results; std::vector<XMPPRosterItem> rosterItems = roster_->getItems(); foreach(const XMPPRosterItem& rosterItem, rosterItems) { diff --git a/Swift/Controllers/ContactsFromXMPPRoster.h b/Swift/Controllers/ContactsFromXMPPRoster.h index 4adc606..b76adc4 100644 --- a/Swift/Controllers/ContactsFromXMPPRoster.h +++ b/Swift/Controllers/ContactsFromXMPPRoster.h @@ -25,7 +25,7 @@ class ContactsFromXMPPRoster : public ContactProvider { ContactsFromXMPPRoster(XMPPRoster* roster, AvatarManager* avatarManager, PresenceOracle* presenceOracle); virtual ~ContactsFromXMPPRoster(); - virtual std::vector<Contact::ref> getContacts(); + virtual std::vector<Contact::ref> getContacts(bool withMUCNicks); private: XMPPRoster* roster_; AvatarManager* avatarManager_; diff --git a/Swift/Controllers/HighlightEditorController.cpp b/Swift/Controllers/HighlightEditorController.cpp index 38007f0..efa3ba2 100644 --- a/Swift/Controllers/HighlightEditorController.cpp +++ b/Swift/Controllers/HighlightEditorController.cpp @@ -49,7 +49,7 @@ void HighlightEditorController::handleUIEvent(boost::shared_ptr<UIEvent> rawEven void HighlightEditorController::handleContactSuggestionsRequested(const std::string& text) { if (contactSuggester_) { - highlightEditorWindow_->setContactSuggestions(contactSuggester_->getSuggestions(text)); + highlightEditorWindow_->setContactSuggestions(contactSuggester_->getSuggestions(text, true)); } } |