diff options
author | Tobias Markmann <tm@ayena.de> | 2014-10-27 14:51:07 (GMT) |
---|---|---|
committer | Swift Review <review@swift.im> | 2014-10-30 13:58:51 (GMT) |
commit | 286ef105d813a12640d64b71101cafe53f212234 (patch) | |
tree | 39e3814048dd639b9a118a3b16f22b49235efd93 /Swiften/MUC/MUCImpl.cpp | |
parent | 190cdcf7478950a90a5c8666d82047e4f33e0d2c (diff) | |
download | swift-286ef105d813a12640d64b71101cafe53f212234.zip swift-286ef105d813a12640d64b71101cafe53f212234.tar.bz2 |
Resend presence to MUC on join completion only if it changed since join.
Test-Information:
Added test case to assure presence is not resend after join completion if it did
not change. The other test cases are untouched and still all succeed.
Change-Id: I2aace1aee8ca3deab9cd9050a25233617b3b0678
Diffstat (limited to 'Swiften/MUC/MUCImpl.cpp')
-rw-r--r-- | Swiften/MUC/MUCImpl.cpp | 31 |
1 files changed, 28 insertions, 3 deletions
diff --git a/Swiften/MUC/MUCImpl.cpp b/Swiften/MUC/MUCImpl.cpp index ab5faf4..778c290 100644 --- a/Swiften/MUC/MUCImpl.cpp +++ b/Swiften/MUC/MUCImpl.cpp @@ -14,6 +14,7 @@ #include <Swiften/Presence/DirectedPresenceSender.h> #include <Swiften/Client/StanzaChannel.h> #include <Swiften/Queries/IQRouter.h> +#include <Swiften/Elements/CapsInfo.h> #include <Swiften/Elements/Form.h> #include <Swiften/Elements/Message.h> #include <Swiften/Elements/IQ.h> @@ -66,6 +67,22 @@ std::map<std::string, MUCOccupant> MUCImpl::getOccupants() const { return occupants; } +bool MUCImpl::isEqualExceptID(const Presence& lhs, const Presence& rhs) { + bool isEqual = false; + if (lhs.getFrom() == rhs.getFrom() && lhs.getTo() == rhs.getTo() && lhs.getStatus() == rhs.getStatus() && lhs.getShow() == rhs.getShow()) { + CapsInfo::ref lhsCaps = lhs.getPayload<CapsInfo>(); + CapsInfo::ref rhsCaps = rhs.getPayload<CapsInfo>(); + + if (!!lhsCaps && !!rhsCaps) { + isEqual = (*lhsCaps == *rhsCaps); + } + else { + isEqual = (!lhsCaps && !rhsCaps); + } + } + return isEqual; +} + void MUCImpl::internalJoin(const std::string &nick) { //TODO: history request joinComplete_ = false; @@ -75,7 +92,7 @@ void MUCImpl::internalJoin(const std::string &nick) { ownMUCJID = JID(ownMUCJID.getNode(), ownMUCJID.getDomain(), nick); - Presence::ref joinPresence = boost::make_shared<Presence>(*presenceSender->getLastSentUndirectedPresence()); + Presence::ref joinPresence = presenceSender->getLastSentUndirectedPresence() ? (*presenceSender->getLastSentUndirectedPresence())->clone() : boost::make_shared<Presence>(); assert(joinPresence->getType() == Presence::Available); joinPresence->setTo(ownMUCJID); MUCPayload::ref mucPayload = boost::make_shared<MUCPayload>(); @@ -86,7 +103,7 @@ void MUCImpl::internalJoin(const std::string &nick) { mucPayload->setPassword(*password); } joinPresence->addPayload(mucPayload); - + joinRequestPresence_ = joinPresence; presenceSender->sendPresence(joinPresence); } @@ -137,7 +154,13 @@ void MUCImpl::handleIncomingPresence(Presence::ref presence) { } else { joinSucceeded_ = true; - presenceSender->addDirectedPresenceReceiver(ownMUCJID, DirectedPresenceSender::AndSendPresence); + presenceSender->addDirectedPresenceReceiver(ownMUCJID, DirectedPresenceSender::DontSendPresence); + if (presenceSender->getLastSentUndirectedPresence() && !isEqualExceptID(**(presenceSender->getLastSentUndirectedPresence()), *joinRequestPresence_)) { + // our presence changed between join request and join complete, send current presence to MUC + Presence::ref latestPresence = boost::make_shared<Presence>(**presenceSender->getLastSentUndirectedPresence()); + latestPresence->setTo(ownMUCJID); + presenceSender->sendPresence(latestPresence); + } } } @@ -245,6 +268,7 @@ void MUCImpl::handleIncomingPresence(Presence::ref presence) { } onJoinComplete(getOwnNick()); } + // MUC status 201: a new room has been created if (status.code == 201) { isLocked = true; /* Room is created and locked */ @@ -259,6 +283,7 @@ void MUCImpl::handleIncomingPresence(Presence::ref presence) { requestConfigurationForm(); } else { + // Accept default room configuration and create an instant room http://xmpp.org/extensions/xep-0045.html#createroom-instant MUCOwnerPayload::ref mucPayload(new MUCOwnerPayload()); presenceSender->addDirectedPresenceReceiver(ownMUCJID, DirectedPresenceSender::DontSendPresence); mucPayload->setPayload(boost::make_shared<Form>(Form::SubmitType)); |