summaryrefslogtreecommitdiffstats
blob: 9ca35ec10499005b2833801d05abee73df07cbb9 (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
/*
 * Copyright (c) 2013 Kevin Smith and Remko Tronçon
 * Licensed under the GNU General Public License v3.
 * See Documentation/Licenses/GPLv3.txt for more information.
 */

#include <Swiften/MUC/UnitTest/MockMUC.h>

namespace Swift {

MockMUC::MockMUC(const JID &muc)
: ownMUCJID(muc)
{
}

MockMUC::~MockMUC() {
}

void MockMUC::insertOccupant(const MUCOccupant& occupant)
{
	occupants_.insert(std::make_pair(occupant.getNick(), occupant));
	onOccupantJoined(occupant);
}

const MUCOccupant& MockMUC::getOccupant(const std::string& nick) {
	return occupants_.find(nick)->second;
}

bool MockMUC::hasOccupant(const std::string& nick) {
	return occupants_.find(nick) != occupants_.end();
}

void MockMUC::changeAffiliation(const JID &jid, MUCOccupant::Affiliation newAffilation) {
	std::map<std::string, MUCOccupant>::iterator i = occupants_.find(jid.getResource());
	if (i != occupants_.end()) {
		const MUCOccupant old = i->second;
		i->second = MUCOccupant(old.getNick(), old.getRole(), newAffilation);
		onOccupantAffiliationChanged(i->first, newAffilation, old.getAffiliation());
	}
}

void MockMUC::changeOccupantRole(const JID &jid, MUCOccupant::Role newRole) {
	std::map<std::string, MUCOccupant>::iterator i = occupants_.find(jid.getResource());
	if (i != occupants_.end()) {
		const MUCOccupant old = i->second;
		i->second = MUCOccupant(old.getNick(), newRole, old.getAffiliation());
		onOccupantRoleChanged(i->first, i->second, old.getRole());
	}
}

}