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

/*
 * Copyright (c) 2014-2016 Isode Limited.
 * All rights reserved.
 * See the COPYING file for more information.
 */

#pragma once

#include <Swiften/Elements/MUCInvitationPayload.h>
#include <Swiften/Roster/XMPPRoster.h>

#include <Swift/Controllers/SettingConstants.h>
#include <Swift/Controllers/Settings/SettingsProvider.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()) {
                    return false; /* always ask the user for normal MUC invites */
                }

                if (invite->getIsContinuation()) {
                    return true;
                }

                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);
                    return false;
                }
            }

        private:
            JID domain_;
            XMPPRoster* roster_;
            SettingsProvider* settings_;
    };
}