summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'Swiften/MUC')
-rw-r--r--Swiften/MUC/MUC.cpp30
-rw-r--r--Swiften/MUC/MUC.h4
2 files changed, 26 insertions, 8 deletions
diff --git a/Swiften/MUC/MUC.cpp b/Swiften/MUC/MUC.cpp
index b4265b5..91ba043 100644
--- a/Swiften/MUC/MUC.cpp
+++ b/Swiften/MUC/MUC.cpp
@@ -44,6 +44,18 @@ void MUC::part() {
presenceSender->removeDirectedPresenceReceiver(ownMUCJID);
}
+void MUC::handleUserLeft(LeavingType type) {
+ std::map<String,MUCOccupant>::iterator i = occupants.find(ownMUCJID.getResource());
+ if (i != occupants.end()) {
+ MUCOccupant me = i->second;
+ occupants.erase(i);
+ onOccupantLeft(me, type, "");
+ }
+ occupants.clear();
+ joinComplete_ = false;
+ presenceSender->removeDirectedPresenceReceiver(ownMUCJID);
+}
+
void MUC::handleIncomingPresence(boost::shared_ptr<Presence> presence) {
if (!isFromMUC(presence->getFrom())) {
return;
@@ -79,14 +91,18 @@ void MUC::handleIncomingPresence(boost::shared_ptr<Presence> presence) {
//170 is room logging to http
//TODO: Nick changes
if (presence->getType() == Presence::Unavailable) {
- std::map<String,MUCOccupant>::iterator i = occupants.find(nick);
- if (i != occupants.end()) {
- //TODO: part type
- onOccupantLeft(i->second, Part, "");
- occupants.erase(i);
+ if (presence->getFrom() == ownMUCJID) {
+ handleUserLeft(Part);
+ return;
+ } else {
+ std::map<String,MUCOccupant>::iterator i = occupants.find(nick);
+ if (i != occupants.end()) {
+ //TODO: part type
+ onOccupantLeft(i->second, Part, "");
+ occupants.erase(i);
+ }
}
- }
- else if (presence->getType() == Presence::Available) {
+ } else if (presence->getType() == Presence::Available) {
std::map<String, MUCOccupant>::iterator it = occupants.find(nick);
MUCOccupant occupant(nick, role, affiliation);
if (it != occupants.end()) {
diff --git a/Swiften/MUC/MUC.h b/Swiften/MUC/MUC.h
index 40fc2f6..bccc26c 100644
--- a/Swiften/MUC/MUC.h
+++ b/Swiften/MUC/MUC.h
@@ -25,7 +25,7 @@ namespace Swift {
class MUC {
public:
enum JoinResult { JoinSucceeded, JoinFailed };
- enum LeavingType { Part };
+ enum LeavingType { Part, Disconnect };
public:
MUC(StanzaChannel* stanzaChannel, PresenceSender* presenceSender, const JID &muc);
@@ -36,6 +36,8 @@ namespace Swift {
String getCurrentNick();
void part();
void handleIncomingMessage(boost::shared_ptr<Message> message);
+ /** Expose public so it can be called when e.g. user goes offline */
+ void handleUserLeft(LeavingType);
public:
boost::signal<void (const String& /*nick*/)> onJoinComplete;