summaryrefslogtreecommitdiffstats
blob: 2a327f4f2c4f13abecd574d4f1202c88636b89a1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#pragma once

#include "Swiften/JID/JID.h"
#include "Swiften/Base/String.h"
#include "Swiften/Elements/Message.h"
#include "Swiften/Elements/Presence.h"
#include "Swiften/MUC/MUCOccupant.h"

#include <boost/signals.hpp>
#include <boost/shared_ptr.hpp>

#include <map>

namespace Swift {
	class StanzaChannel;
	class PresenceSender;

	class MUC {
		public:
			enum JoinResult { JoinSucceeded, JoinFailed };
			enum LeavingType { Part };

		public:
			MUC(StanzaChannel* stanzaChannel, PresenceSender* presenceSender, const JID &muc);

			void joinAs(const String &nick);
			String getCurrentNick();
			void part();
			void handleIncomingMessage(boost::shared_ptr<Message> message);

		public:
			boost::signal<void (JoinResult)> onJoinComplete;
			boost::signal<void (boost::shared_ptr<Message>)> onMessageReceived;
			boost::signal<void (boost::shared_ptr<Presence>)> onOccupantPresenceChange;
			boost::signal<void (const MUCOccupant&)> onOccupantJoined;
			/**Occupant, type, and reason. */
			boost::signal<void (const MUCOccupant&, LeavingType, const String&)> onOccupantLeft;

		private:
			bool isFromMUC(const JID& j) const {
				return ownMUCJID.equals(j, JID::WithoutResource);
			}

			const String& getOwnNick() const {
				return ownMUCJID.getResource();
			}

		private:
			void handleIncomingPresence(boost::shared_ptr<Presence> presence);

		private:
			JID ownMUCJID;
			StanzaChannel* stanzaChannel;
			PresenceSender* presenceSender;
			std::map<String, MUCOccupant> occupants;
			bool firstPresenceSeen;
	};
}