diff options
author | Tobias Markmann <tm@ayena.de> | 2016-11-23 07:09:39 (GMT) |
---|---|---|
committer | Tobias Markmann <tm@ayena.de> | 2016-11-23 11:30:02 (GMT) |
commit | e405ff3561be3d3c0bd79d7d5173923a8828cf02 (patch) | |
tree | 9118ef838ebfaec1df90ec24761944b5d833774c /Swift/Controllers/Chat | |
parent | 8a71b91be885652f37c5aab5e1ecf25af4599fbc (diff) | |
download | swift-e405ff3561be3d3c0bd79d7d5173923a8828cf02.zip swift-e405ff3561be3d3c0bd79d7d5173923a8828cf02.tar.bz2 |
Migrate remaining Swiften/Base/foreach.h use to range-based for loop
Test-Information:
Build on macOS 10.12.1 and all tests pass.
Change-Id: Iedaa3fa7e7672c77909fd0568bf30e9393cb87e0
Diffstat (limited to 'Swift/Controllers/Chat')
-rw-r--r-- | Swift/Controllers/Chat/MUCController.cpp | 32 | ||||
-rw-r--r-- | Swift/Controllers/Chat/UnitTest/ChatsManagerTest.cpp | 14 | ||||
-rw-r--r-- | Swift/Controllers/Chat/UnitTest/MUCControllerTest.cpp | 10 | ||||
-rw-r--r-- | Swift/Controllers/Chat/UserSearchController.cpp | 16 |
4 files changed, 33 insertions, 39 deletions
diff --git a/Swift/Controllers/Chat/MUCController.cpp b/Swift/Controllers/Chat/MUCController.cpp index 9ae3845..349bf8a 100644 --- a/Swift/Controllers/Chat/MUCController.cpp +++ b/Swift/Controllers/Chat/MUCController.cpp @@ -11,10 +11,10 @@ #include <boost/bind.hpp> #include <boost/regex.hpp> #include <boost/algorithm/string.hpp> +#include <boost/range/adaptor/reversed.hpp> #include <Swiften/Avatars/AvatarManager.h> #include <Swiften/Base/Log.h> -#include <Swiften/Base/foreach.h> #include <Swiften/Base/format.h> #include <Swiften/Base/Tristate.h> #include <Swiften/Client/BlockList.h> @@ -238,7 +238,7 @@ void MUCController::handleActionRequestedOnOccupant(ChatWindow::OccupantAction a void MUCController::handleBareJIDCapsChanged(const JID& /*jid*/) { Tristate support = Yes; bool any = false; - foreach (const std::string& nick, currentOccupants_) { + for (const auto& nick : currentOccupants_) { DiscoInfo::ref disco = entityCapsProvider_->getCaps(toJID_.toBare().toString() + "/" + nick); if (disco && disco->hasFeature(DiscoInfo::MessageCorrectionFeature)) { any = true; @@ -295,9 +295,8 @@ bool MUCController::isImpromptu() const { std::map<std::string, JID> MUCController::getParticipantJIDs() const { std::map<std::string, JID> participants; - typedef std::pair<std::string, MUCOccupant> MUCOccupantPair; std::map<std::string, MUCOccupant> occupants = muc_->getOccupants(); - foreach(const MUCOccupantPair& occupant, occupants) { + for (const auto& occupant : occupants) { if (occupant.first != nick_) { participants[occupant.first] = occupant.second.getRealJID().is_initialized() ? occupant.second.getRealJID().get().toBare() : JID(); } @@ -306,7 +305,7 @@ std::map<std::string, JID> MUCController::getParticipantJIDs() const { } void MUCController::sendInvites(const std::vector<JID>& jids, const std::string& reason) const { - foreach (const JID& jid, jids) { + for (const auto& jid : jids) { muc_->invitePerson(jid, reason, isImpromptu_); } } @@ -859,7 +858,7 @@ std::string MUCController::concatenateListOfNames(const std::vector<NickJoinPart std::string MUCController::generateJoinPartString(const std::vector<NickJoinPart>& joinParts, bool isImpromptu) { std::vector<NickJoinPart> sorted[4]; std::string eventStrings[4]; - foreach (NickJoinPart event, joinParts) { + for (const auto& event : joinParts) { sorted[event.type].push_back(event); } std::string result; @@ -937,7 +936,7 @@ void MUCController::handleBookmarkRequest() { // Check for existing bookmark for this room and, if it exists, use it instead. std::vector<MUCBookmark> bookmarks = mucBookmarkManager_->getBookmarks(); - foreach (const MUCBookmark& bookmark, bookmarks) { + for (const auto& bookmark : bookmarks) { if (bookmark.getRoom() == jid.toBare()) { roomBookmark = bookmark; break; @@ -1001,7 +1000,7 @@ void MUCController::handleInvitePersonToThisMUCRequest(const std::vector<JID>& j void MUCController::handleUIEvent(std::shared_ptr<UIEvent> event) { std::shared_ptr<InviteToMUCUIEvent> inviteEvent = std::dynamic_pointer_cast<InviteToMUCUIEvent>(event); if (inviteEvent && inviteEvent->getRoom() == muc_->getJID()) { - foreach (const JID& jid, inviteEvent->getInvites()) { + for (const auto& jid : inviteEvent->getInvites()) { muc_->invitePerson(jid, inviteEvent->getReason(), isImpromptu_); } } @@ -1014,16 +1013,14 @@ void MUCController::handleGetAffiliationsRequest() { muc_->requestAffiliationList(MUCOccupant::Outcast); } -typedef std::pair<MUCOccupant::Affiliation, JID> AffiliationChangePair; - void MUCController::handleChangeAffiliationsRequest(const std::vector<std::pair<MUCOccupant::Affiliation, JID> >& changes) { std::set<JID> addedJIDs; - foreach (const AffiliationChangePair& change, changes) { + for (const auto& change : changes) { if (change.first != MUCOccupant::NoAffiliation) { addedJIDs.insert(change.second); } } - foreach (const AffiliationChangePair& change, changes) { + for (const auto& change : changes) { if (change.first != MUCOccupant::NoAffiliation || addedJIDs.find(change.second) == addedJIDs.end()) { muc_->changeAffiliation(change.second, change.first); } @@ -1070,7 +1067,7 @@ void MUCController::addRecentLogs() { joinContext_ = historyController_->getMUCContext(selfJID_, toJID_, lastActivity_); - foreach (const HistoryMessage& message, joinContext_) { + for (const auto& message : joinContext_) { bool senderIsSelf = nick_ == message.getFromJID().getResource(); // the chatWindow uses utc timestamps @@ -1083,7 +1080,7 @@ void MUCController::checkDuplicates(std::shared_ptr<Message> newMessage) { JID jid = newMessage->getFrom(); boost::optional<boost::posix_time::ptime> time = newMessage->getTimestamp(); - reverse_foreach (const HistoryMessage& message, joinContext_) { + for (const auto& message : boost::adaptors::reverse(joinContext_)) { boost::posix_time::ptime messageTime = message.getTime() - boost::posix_time::hours(message.getOffset()); if (time && time < messageTime) { break; @@ -1112,7 +1109,7 @@ Form::ref MUCController::buildImpromptuRoomConfiguration(Form::ref roomConfigura Form::ref result = std::make_shared<Form>(Form::SubmitType); std::string impromptuConfigs[] = { "muc#roomconfig_enablelogging", "muc#roomconfig_persistentroom", "muc#roomconfig_publicroom", "muc#roomconfig_whois"}; std::set<std::string> impromptuConfigsMissing(impromptuConfigs, impromptuConfigs + 4); - foreach (std::shared_ptr<FormField> field, roomConfigurationForm->getFields()) { + for (const auto& field : roomConfigurationForm->getFields()) { std::shared_ptr<FormField> resultField; if (field->getName() == "muc#roomconfig_enablelogging") { resultField = std::make_shared<FormField>(FormField::BooleanType, "0"); @@ -1138,7 +1135,7 @@ Form::ref MUCController::buildImpromptuRoomConfiguration(Form::ref roomConfigura } } - foreach (const std::string& config, impromptuConfigsMissing) { + for (const auto& config : impromptuConfigsMissing) { if (config == "muc#roomconfig_publicroom") { chatWindow_->addSystemMessage(chatMessageParser_->parseMessageBody(QT_TRANSLATE_NOOP("", "This server doesn't support hiding your chat from other users.")), ChatWindow::DefaultDirection); } else if (config == "muc#roomconfig_whois") { @@ -1151,12 +1148,11 @@ Form::ref MUCController::buildImpromptuRoomConfiguration(Form::ref roomConfigura void MUCController::setImpromptuWindowTitle() { std::string title; - typedef std::pair<std::string, MUCOccupant> StringMUCOccupantPair; std::map<std::string, MUCOccupant> occupants = muc_->getOccupants(); if (occupants.size() <= 1) { title = QT_TRANSLATE_NOOP("", "Empty Chat"); } else { - foreach (StringMUCOccupantPair pair, occupants) { + for (const auto& pair : occupants) { if (pair.first != nick_) { title += (title.empty() ? "" : ", ") + pair.first; } diff --git a/Swift/Controllers/Chat/UnitTest/ChatsManagerTest.cpp b/Swift/Controllers/Chat/UnitTest/ChatsManagerTest.cpp index 31c9be9..a5e68cf 100644 --- a/Swift/Controllers/Chat/UnitTest/ChatsManagerTest.cpp +++ b/Swift/Controllers/Chat/UnitTest/ChatsManagerTest.cpp @@ -89,7 +89,7 @@ class ChatsManagerTest : public CppUnit::TestFixture { CPPUNIT_TEST(testChatControllerHighlightingNotificationTesting); CPPUNIT_TEST(testChatControllerHighlightingNotificationDeduplicateSounds); CPPUNIT_TEST(testChatControllerMeMessageHandling); - CPPUNIT_TEST(testRestartingMUCComponentCrash); + CPPUNIT_TEST(testRestartingMUCComponentCrash); CPPUNIT_TEST(testChatControllerMeMessageHandlingInMUC); // Carbons tests @@ -455,7 +455,7 @@ public: uiEventStream_->send(std::make_shared<RequestChatUIEvent>(sender)); - foreach(const JID& senderJID, senderResource) { + for (const auto& senderJID : senderResource) { // The sender supports delivery receipts. DiscoInfo::ref disco = std::make_shared<DiscoInfo>(); disco->addFeature(DiscoInfo::MessageDeliveryReceiptsFeature); @@ -478,7 +478,7 @@ public: CPPUNIT_ASSERT(stanzaChannel_->getStanzaAtIndex<Message>(1)->getPayload<DeliveryReceiptRequest>()); // Two resources respond with message receipts. - foreach(const JID& senderJID, senderResource) { + for (const auto& senderJID : senderResource) { Message::ref receiptReply = std::make_shared<Message>(); receiptReply->setFrom(senderJID); receiptReply->setTo(ownJID); @@ -497,7 +497,7 @@ public: CPPUNIT_ASSERT(stanzaChannel_->getStanzaAtIndex<Message>(1)->getPayload<DeliveryReceiptRequest>()); // Two resources respond with message receipts. - foreach(const JID& senderJID, senderResource) { + for (const auto& senderJID : senderResource) { Message::ref receiptReply = std::make_shared<Message>(); receiptReply->setFrom(senderJID); receiptReply->setTo(ownJID); @@ -570,7 +570,7 @@ public: uiEventStream_->send(std::make_shared<RequestChatUIEvent>(sender)); - foreach(const JID& senderJID, senderResource) { + for (const auto& senderJID : senderResource) { // The sender supports delivery receipts. DiscoInfo::ref disco = std::make_shared<DiscoInfo>(); disco->addFeature(DiscoInfo::MessageDeliveryReceiptsFeature); @@ -593,7 +593,7 @@ public: CPPUNIT_ASSERT(stanzaChannel_->getStanzaAtIndex<Message>(1)->getPayload<DeliveryReceiptRequest>()); // Two resources respond with message receipts. - foreach(const JID& senderJID, senderResource) { + for (const auto& senderJID : senderResource) { Message::ref reply = std::make_shared<Message>(); reply->setFrom(senderJID); reply->setTo(ownJID); @@ -612,7 +612,7 @@ public: CPPUNIT_ASSERT(stanzaChannel_->getStanzaAtIndex<Message>(1)->getPayload<DeliveryReceiptRequest>()); // Two resources respond with message receipts. - foreach(const JID& senderJID, senderResource) { + for (const auto& senderJID : senderResource) { Message::ref receiptReply = std::make_shared<Message>(); receiptReply->setFrom(senderJID); receiptReply->setTo(ownJID); diff --git a/Swift/Controllers/Chat/UnitTest/MUCControllerTest.cpp b/Swift/Controllers/Chat/UnitTest/MUCControllerTest.cpp index 1142c98..32639f6 100644 --- a/Swift/Controllers/Chat/UnitTest/MUCControllerTest.cpp +++ b/Swift/Controllers/Chat/UnitTest/MUCControllerTest.cpp @@ -11,7 +11,6 @@ #include <hippomocks.h> #include <Swiften/Avatars/NullAvatarManager.h> -#include <Swiften/Base/foreach.h> #include <Swiften/Client/ClientBlockListManager.h> #include <Swiften/Client/DummyStanzaChannel.h> #include <Swiften/Client/NickResolver.h> @@ -371,8 +370,7 @@ public: occupants.insert(occupant_map::value_type("Ernie", MUCOccupant("Ernie", MUCOccupant::Participant, MUCOccupant::Owner))); /* populate the MUC with fake users */ - typedef const std::pair<std::string,MUCOccupant> occupantIterator; - foreach(occupantIterator &occupant, occupants) { + for (auto&& occupant : occupants) { muc_->insertOccupant(occupant.second); } @@ -387,7 +385,7 @@ public: alterations.push_back(MUCOccupant("Remko", MUCOccupant::NoRole, MUCOccupant::NoAffiliation)); alterations.push_back(MUCOccupant("Ernie", MUCOccupant::Visitor, MUCOccupant::Outcast)); - foreach(const MUCOccupant& alteration, alterations) { + for (const auto& alteration : alterations) { /* perform an alteration to a user's role and affiliation */ occupant_map::iterator occupant = occupants.find(alteration.getNick()); CPPUNIT_ASSERT(occupant != occupants.end()); @@ -506,10 +504,10 @@ public: void testRoleAffiliationStatesVerify(const std::map<std::string, MUCOccupant> &occupants) { /* verify that the roster is in sync */ GroupRosterItem* group = window_->getRosterModel()->getRoot(); - foreach(RosterItem* rosterItem, group->getChildren()) { + for (auto rosterItem : group->getChildren()) { GroupRosterItem* child = dynamic_cast<GroupRosterItem*>(rosterItem); CPPUNIT_ASSERT(child); - foreach(RosterItem* childItem, child->getChildren()) { + for (auto childItem : child->getChildren()) { ContactRosterItem* item = dynamic_cast<ContactRosterItem*>(childItem); CPPUNIT_ASSERT(item); std::map<std::string, MUCOccupant>::const_iterator occupant = occupants.find(item->getJID().getResource()); diff --git a/Swift/Controllers/Chat/UserSearchController.cpp b/Swift/Controllers/Chat/UserSearchController.cpp index 305049f..91e0dea 100644 --- a/Swift/Controllers/Chat/UserSearchController.cpp +++ b/Swift/Controllers/Chat/UserSearchController.cpp @@ -12,7 +12,6 @@ #include <Swiften/Avatars/AvatarManager.h> #include <Swiften/Base/String.h> -#include <Swiften/Base/foreach.h> #include <Swiften/Disco/DiscoServiceWalker.h> #include <Swiften/Disco/GetDiscoInfoRequest.h> #include <Swiften/Disco/GetDiscoItemsRequest.h> @@ -143,7 +142,8 @@ void UserSearchController::endDiscoWalker() { void UserSearchController::handleDiscoServiceFound(const JID& jid, std::shared_ptr<DiscoInfo> info) { //bool isUserDirectory = false; bool supports55 = false; - foreach (DiscoInfo::Identity identity, info->getIdentities()) { + // TODO: Cleanup code + for (const auto& identity : info->getIdentities()) { if ((identity.getCategory() == "directory" && identity.getType() == "user")) { //isUserDirectory = true; @@ -186,7 +186,7 @@ void UserSearchController::handleSearchResponse(std::shared_ptr<SearchPayload> r if (resultsPayload->getForm()) { window_->setResultsForm(resultsPayload->getForm()); } else { - foreach (SearchPayload::Item item, resultsPayload->getItems()) { + for (auto&& item : resultsPayload->getItems()) { JID jid(item.jid); std::map<std::string, std::string> fields; fields["first"] = item.first; @@ -232,7 +232,7 @@ void UserSearchController::handleContactSuggestionsRequested(std::string text) { std::vector<Contact::ref>::iterator i = suggestions.begin(); while (i != suggestions.end()) { bool found = false; - foreach (const JID& jid, existingJIDs) { + for (const auto& jid : existingJIDs) { if ((*i)->jid == jid) { found = true; break; @@ -274,7 +274,7 @@ void UserSearchController::handlePresenceChanged(Presence::ref presence) { void UserSearchController::handleJIDUpdateRequested(const std::vector<JID>& jids) { if (window_) { std::vector<Contact::ref> updates; - foreach(const JID& jid, jids) { + for (const auto& jid : jids) { updates.push_back(convertJIDtoContact(jid)); } window_->updateContacts(updates); @@ -283,7 +283,7 @@ void UserSearchController::handleJIDUpdateRequested(const std::vector<JID>& jids void UserSearchController::handleJIDAddRequested(const std::vector<JID>& jids) { std::vector<Contact::ref> contacts; - foreach(const JID& jid, jids) { + for (const auto& jid : jids) { contacts.push_back(convertJIDtoContact(jid)); } window_->addContacts(contacts); @@ -358,7 +358,7 @@ void UserSearchController::initializeUserWindow() { void UserSearchController::loadSavedDirectories() { savedDirectories_.clear(); - foreach (std::string stringItem, String::split(settings_->getStringSetting(SEARCHED_DIRECTORIES), '\n')) { + for (auto&& stringItem : String::split(settings_->getStringSetting(SEARCHED_DIRECTORIES), '\n')) { if(!stringItem.empty()) { savedDirectories_.push_back(JID(stringItem)); } @@ -375,7 +375,7 @@ void UserSearchController::addToSavedDirectories(const JID& jid) { std::string collapsed; int i = 0; - foreach (JID jidItem, savedDirectories_) { + for (const auto& jidItem : savedDirectories_) { if (i >= 15) { break; } |