summaryrefslogtreecommitdiffstats
blob: ddb2c7a48a3b8e9d4ff2f8707c4f1d4d51b1959f (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
/*
 * Copyright (c) 2013 Tobias Markmann
 * Licensed under the simplified BSD license.
 * See Documentation/Licenses/BSD-simplified.txt for more information.
 */

#pragma once

#include <Swiften/JID/JID.h>

#include <Swift/Controllers/Roster/ItemOperations/RosterItemOperation.h>
#include <Swift/Controllers/Roster/ContactRosterItem.h>

namespace Swift {

class RosterItem;

class SetBlockingState : public RosterItemOperation {
	public:
		SetBlockingState(const JID& jid, ContactRosterItem::BlockState state, JID::CompareType compareType = JID::WithoutResource) : RosterItemOperation(!jid.getNode().empty(), jid), jid_(jid), state_(state), compareType_(compareType) {
			if (state_ == ContactRosterItem::IsBlocked && jid.getNode().empty()) {
				state_ = ContactRosterItem::IsDomainBlocked;
			}
		}

		virtual void operator() (RosterItem* item) const {
			ContactRosterItem* contact = dynamic_cast<ContactRosterItem*>(item);
			if (jid_.getNode().empty()) {
				if (contact && contact->getJID().getDomain() == jid_.getDomain()) {
					contact->setBlockState(state_);
				}
			} else {
				if (contact && contact->getJID().equals(jid_, compareType_)) {
					contact->setBlockState(state_);
				}
			}
		}

	private:
		JID jid_;
		ContactRosterItem::BlockState state_;
		JID::CompareType compareType_;
};

}