diff options
-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 | 8 | ||||
-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 | ||||
-rw-r--r-- | Swift/QtUI/QtHighlightEditor.cpp | 8 | ||||
-rw-r--r-- | Swift/QtUI/QtHighlightEditor.h | 2 | ||||
-rw-r--r-- | Swift/QtUI/UserSearch/QtSuggestingJIDInput.cpp | 6 | ||||
-rw-r--r-- | Swift/QtUI/UserSearch/QtSuggestingJIDInput.h | 2 | ||||
-rw-r--r-- | Swift/QtUI/UserSearch/QtUserSearchWindow.cpp | 12 | ||||
-rw-r--r-- | Swift/QtUI/UserSearch/QtUserSearchWindow.h | 3 |
16 files changed, 64 insertions, 21 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 @@ -972,5 +972,5 @@ std::vector<ChatListWindow::Chat> ChatsManager::getRecentChats() const { } -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_) { @@ -979,4 +979,19 @@ std::vector<Contact::ref> Swift::ChatsManager::getContacts() { } } + 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 @@ -74,5 +74,5 @@ namespace Swift { 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 @@ -197,5 +197,6 @@ 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()) { 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 @@ -18,9 +18,17 @@ Contact::Contact(const std::string& name, const JID& jid, StatusShow::Type statu bool Contact::lexicographicalSortPredicate(const Contact::ref& a, const Contact::ref& b) { + 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) { + if (a->jid.isValid() && b->jid.isValid()) { return a->jid == b->jid; + } else { + return a->name == b->name; + } } 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 @@ -22,5 +22,5 @@ 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 @@ -44,12 +44,18 @@ 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)); } 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 @@ -30,5 +30,5 @@ 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 @@ -28,5 +28,5 @@ 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(); 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 @@ -26,5 +26,5 @@ class ContactsFromXMPPRoster : public ContactProvider { virtual ~ContactsFromXMPPRoster(); - virtual std::vector<Contact::ref> getContacts(); + virtual std::vector<Contact::ref> getContacts(bool withMUCNicks); private: XMPPRoster* roster_; 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 @@ -50,5 +50,5 @@ void HighlightEditorController::handleContactSuggestionsRequested(const std::str { if (contactSuggester_) { - highlightEditorWindow_->setContactSuggestions(contactSuggester_->getSuggestions(text)); + highlightEditorWindow_->setContactSuggestions(contactSuggester_->getSuggestions(text, true)); } } diff --git a/Swift/QtUI/QtHighlightEditor.cpp b/Swift/QtUI/QtHighlightEditor.cpp index 5aa4560..97774be 100644 --- a/Swift/QtUI/QtHighlightEditor.cpp +++ b/Swift/QtUI/QtHighlightEditor.cpp @@ -351,7 +351,11 @@ void QtHighlightEditor::selectSoundFile() } -void QtHighlightEditor::handleOnUserSelected(const JID& jid) { +void QtHighlightEditor::handleOnUserSelected(const Contact::ref& contact) { /* this might seem like it should be standard behaviour for the suggesting input box, but is not desirable in all cases */ - jid_->setText(P2QSTRING(jid.toString())); + if (contact->jid.isValid()) { + jid_->setText(P2QSTRING(contact->jid.toString())); + } else { + jid_->setText(P2QSTRING(contact->name)); + } } diff --git a/Swift/QtUI/QtHighlightEditor.h b/Swift/QtUI/QtHighlightEditor.h index e0595ad..93a19b6 100644 --- a/Swift/QtUI/QtHighlightEditor.h +++ b/Swift/QtUI/QtHighlightEditor.h @@ -54,5 +54,5 @@ namespace Swift { private: - void handleOnUserSelected(const JID& jid); + void handleOnUserSelected(const Contact::ref& contact); void populateList(); void selectRow(int row); diff --git a/Swift/QtUI/UserSearch/QtSuggestingJIDInput.cpp b/Swift/QtUI/UserSearch/QtSuggestingJIDInput.cpp index 78842a2..57033d8 100644 --- a/Swift/QtUI/UserSearch/QtSuggestingJIDInput.cpp +++ b/Swift/QtUI/UserSearch/QtSuggestingJIDInput.cpp @@ -115,5 +115,9 @@ void QtSuggestingJIDInput::keyPressEvent(QKeyEvent* event) { if (!contactListModel_->getList().empty() && index.isValid()) { currentContact_ = contactListModel_->getContact(index.row()); + if (currentContact_->jid.isValid()) { setText(P2QSTRING(currentContact_->jid.toString())); + } else { + setText(P2QSTRING(currentContact_->name)); + } hidePopup(); clearFocus(); @@ -145,5 +149,5 @@ void QtSuggestingJIDInput::handleClicked(const QModelIndex& index) { if (index.isValid()) { currentContact_ = contactListModel_->getContact(index.row()); - onUserSelected(currentContact_->jid); + onUserSelected(currentContact_); hidePopup(); } diff --git a/Swift/QtUI/UserSearch/QtSuggestingJIDInput.h b/Swift/QtUI/UserSearch/QtSuggestingJIDInput.h index 71cd87d..23e7b94 100644 --- a/Swift/QtUI/UserSearch/QtSuggestingJIDInput.h +++ b/Swift/QtUI/UserSearch/QtSuggestingJIDInput.h @@ -36,5 +36,5 @@ class QtSuggestingJIDInput : public QLineEdit { void clear(); - boost::signal<void (const JID&)> onUserSelected; + boost::signal<void (const Contact::ref&)> onUserSelected; signals: diff --git a/Swift/QtUI/UserSearch/QtUserSearchWindow.cpp b/Swift/QtUI/UserSearch/QtUserSearchWindow.cpp index 17214e4..e5bd5d0 100644 --- a/Swift/QtUI/UserSearch/QtUserSearchWindow.cpp +++ b/Swift/QtUI/UserSearch/QtUserSearchWindow.cpp @@ -79,5 +79,5 @@ void QtUserSearchWindow::handleCurrentChanged(int page) { resultsPage_->emitCompletenessCheck(); if (page == 1 && lastPage_ == 3) { - addSearchedJIDToList(getContactJID()); + addSearchedJIDToList(getContact()); setSecondPage(); } @@ -271,7 +271,11 @@ JID QtUserSearchWindow::getContactJID() const { } -void QtUserSearchWindow::addSearchedJIDToList(const JID& jid) { +Contact::ref QtUserSearchWindow::getContact() const { + return boost::make_shared<Contact>("", getContactJID(), StatusShow::None, ""); +} + +void QtUserSearchWindow::addSearchedJIDToList(const Contact::ref& contact) { std::vector<JID> jids; - jids.push_back(jid); + jids.push_back(contact->jid); handleJIDsAdded(jids); firstMultiJIDPage_->jid_->clear(); @@ -344,5 +348,5 @@ void QtUserSearchWindow::setContactSuggestions(const std::vector<Contact::ref>& void QtUserSearchWindow::setJIDs(const std::vector<JID> &jids) { foreach(JID jid, jids) { - addSearchedJIDToList(jid); + addSearchedJIDToList(boost::make_shared<Contact>("", jid, StatusShow::None, "")); } onJIDUpdateRequested(jids); diff --git a/Swift/QtUI/UserSearch/QtUserSearchWindow.h b/Swift/QtUI/UserSearch/QtUserSearchWindow.h index 0349ba4..0318b3d 100644 --- a/Swift/QtUI/UserSearch/QtUserSearchWindow.h +++ b/Swift/QtUI/UserSearch/QtUserSearchWindow.h @@ -78,5 +78,6 @@ namespace Swift { void handleSearch(); JID getContactJID() const; - void addSearchedJIDToList(const JID& jid); + Contact::ref getContact() const; + void addSearchedJIDToList(const Contact::ref& contact); private: |