blob: 0f85a8afe336b5f2c6d2304e56157ab964919175 (
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
|
/*
* Copyright (c) 2013 Tobias Markmann
* Licensed under the simplified BSD license.
* See Documentation/Licenses/BSD-simplified.txt for more information.
*/
#pragma once
#include <Swiften/Roster/XMPPRoster.h>
#include <Swiften/Elements/MUCInvitationPayload.h>
#include <Swift/Controllers/Settings/SettingsProvider.h>
#include <Swift/Controllers/SettingConstants.h>
namespace Swift {
class AutoAcceptMUCInviteDecider {
public:
AutoAcceptMUCInviteDecider(const JID& domain, XMPPRoster* roster, SettingsProvider* settings) : domain_(domain), roster_(roster), settings_(settings) {
}
bool isAutoAcceptedInvite(const JID& from, MUCInvitationPayload::ref invite) {
if (!invite->getIsImpromptu() && !invite->getIsContinuation()) {
return false;
}
std::string auto_accept_mode = settings_->getSetting(SettingConstants::INVITE_AUTO_ACCEPT_MODE);
if (auto_accept_mode == "no") {
return false;
} else if (auto_accept_mode == "presence") {
return roster_->getSubscriptionStateForJID(from) == RosterItemPayload::From || roster_->getSubscriptionStateForJID(from) == RosterItemPayload::Both;
} else if (auto_accept_mode == "domain") {
return roster_->getSubscriptionStateForJID(from) == RosterItemPayload::From || roster_->getSubscriptionStateForJID(from) == RosterItemPayload::Both || from.getDomain() == domain_;
} else {
assert(false);
}
}
private:
JID domain_;
XMPPRoster* roster_;
SettingsProvider* settings_;
};
}
|