summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'Swiften/MUC')
-rw-r--r--Swiften/MUC/MUC.cpp22
-rw-r--r--Swiften/MUC/MUC.h13
2 files changed, 31 insertions, 4 deletions
diff --git a/Swiften/MUC/MUC.cpp b/Swiften/MUC/MUC.cpp
index a52f552..f85cf8d 100644
--- a/Swiften/MUC/MUC.cpp
+++ b/Swiften/MUC/MUC.cpp
@@ -29,7 +29,7 @@ namespace Swift {
typedef std::pair<std::string, MUCOccupant> StringMUCOccupantPair;
-MUC::MUC(StanzaChannel* stanzaChannel, IQRouter* iqRouter, DirectedPresenceSender* presenceSender, const JID &muc, MUCRegistry* mucRegistry) : ownMUCJID(muc), stanzaChannel(stanzaChannel), iqRouter_(iqRouter), presenceSender(presenceSender), mucRegistry(mucRegistry), createAsReservedIfNew(false), unlocking(false) {
+MUC::MUC(StanzaChannel* stanzaChannel, IQRouter* iqRouter, DirectedPresenceSender* presenceSender, const JID &muc, MUCRegistry* mucRegistry) : ownMUCJID(muc), stanzaChannel(stanzaChannel), iqRouter_(iqRouter), presenceSender(presenceSender), mucRegistry(mucRegistry), createAsReservedIfNew(false), unlocking(false), isUnlocked_(false) {
scopedConnection_ = stanzaChannel->onPresenceReceived.connect(boost::bind(&MUC::handleIncomingPresence, this, _1));
}
@@ -58,6 +58,10 @@ void MUC::joinWithContextSince(const std::string &nick, const boost::posix_time:
internalJoin(nick);
}
+std::map<std::string, MUCOccupant> MUC::getOccupants() const {
+ return occupants;
+}
+
void MUC::internalJoin(const std::string &nick) {
//TODO: history request
joinComplete_ = false;
@@ -97,6 +101,7 @@ void MUC::handleUserLeft(LeavingType type) {
occupants.clear();
joinComplete_ = false;
joinSucceeded_ = false;
+ isUnlocked_ = false;
presenceSender->removeDirectedPresenceReceiver(ownMUCJID, DirectedPresenceSender::DontSendPresence);
}
@@ -170,8 +175,9 @@ void MUC::handleIncomingPresence(Presence::ref presence) {
std::map<std::string,MUCOccupant>::iterator i = occupants.find(nick);
if (i != occupants.end()) {
//TODO: part type
- onOccupantLeft(i->second, type, "");
+ MUCOccupant occupant = i->second;
occupants.erase(i);
+ onOccupantLeft(occupant, type, "");
}
}
}
@@ -200,6 +206,7 @@ void MUC::handleIncomingPresence(Presence::ref presence) {
onOccupantPresenceChange(presence);
}
if (mucPayload && !joinComplete_) {
+ bool isLocked = false;
foreach (MUCUserPayload::StatusCode status, mucPayload->getStatusCodes()) {
if (status.code == 110) {
/* Simply knowing this is your presence is enough, 210 doesn't seem to be necessary. */
@@ -212,6 +219,7 @@ void MUC::handleIncomingPresence(Presence::ref presence) {
onJoinComplete(getOwnNick());
}
if (status.code == 201) {
+ isLocked = true;
/* Room is created and locked */
/* Currently deal with this by making an instant room */
if (ownMUCJID != presence->getFrom()) {
@@ -233,6 +241,10 @@ void MUC::handleIncomingPresence(Presence::ref presence) {
}
}
}
+ if (!isLocked && !isUnlocked_ && (presence->getFrom() == ownMUCJID)) {
+ isUnlocked_ = true;
+ onUnlocked();
+ }
}
}
@@ -243,6 +255,8 @@ void MUC::handleCreationConfigResponse(MUCOwnerPayload::ref /*unused*/, ErrorPay
onJoinFailed(error);
} else {
onJoinComplete(getOwnNick()); /* Previously, this wasn't needed here, as the presence duplication bug caused an emit elsewhere. */
+ isUnlocked_ = true;
+ onUnlocked();
}
}
@@ -386,13 +400,15 @@ void MUC::destroyRoom() {
request->send();
}
-void MUC::invitePerson(const JID& person, const std::string& reason) {
+void MUC::invitePerson(const JID& person, const std::string& reason, bool isImpromptu, bool isReuseChat) {
Message::ref message = boost::make_shared<Message>();
message->setTo(person);
message->setType(Message::Normal);
MUCInvitationPayload::ref invite = boost::make_shared<MUCInvitationPayload>();
invite->setReason(reason);
invite->setJID(ownMUCJID.toBare());
+ invite->setIsImpromptu(isImpromptu);
+ invite->setIsContinuation(isReuseChat);
message->addPayload(invite);
stanzaChannel->sendMessage(message);
}
diff --git a/Swiften/MUC/MUC.h b/Swiften/MUC/MUC.h
index 85f4564..6a0ab75 100644
--- a/Swiften/MUC/MUC.h
+++ b/Swiften/MUC/MUC.h
@@ -45,11 +45,20 @@ namespace Swift {
return ownMUCJID.toBare();
}
+ /**
+ * Returns if the room is unlocked and other people can join the room.
+ * @return True if joinable by others; false otherwise.
+ */
+ bool isUnlocked() const {
+ return isUnlocked_;
+ }
+
void joinAs(const std::string &nick);
void joinWithContextSince(const std::string &nick, const boost::posix_time::ptime& since);
/*void queryRoomInfo(); */
/*void queryRoomItems(); */
std::string getCurrentNick();
+ std::map<std::string, MUCOccupant> getOccupants() const;
void part();
void handleIncomingMessage(Message::ref message);
/** Expose public so it can be called when e.g. user goes offline */
@@ -67,7 +76,7 @@ namespace Swift {
void cancelConfigureRoom();
void destroyRoom();
/** Send an invite for the person to join the MUC */
- void invitePerson(const JID& person, const std::string& reason = "");
+ void invitePerson(const JID& person, const std::string& reason = "", bool isImpromptu = false, bool isReuseChat = false);
void setCreateAsReservedIfNew() {createAsReservedIfNew = true;}
void setPassword(const boost::optional<std::string>& password);
@@ -85,6 +94,7 @@ namespace Swift {
boost::signal<void (const MUCOccupant&, LeavingType, const std::string& /*reason*/)> onOccupantLeft;
boost::signal<void (Form::ref)> onConfigurationFormReceived;
boost::signal<void (MUCOccupant::Affiliation, const std::vector<JID>&)> onAffiliationListReceived;
+ boost::signal<void ()> onUnlocked;
/* boost::signal<void (const MUCInfo&)> onInfoResult; */
/* boost::signal<void (const blah&)> onItemsResult; */
@@ -121,6 +131,7 @@ namespace Swift {
boost::posix_time::ptime joinSince_;
bool createAsReservedIfNew;
bool unlocking;
+ bool isUnlocked_;
boost::optional<std::string> password;
};
}