aboutsummaryrefslogtreecommitdiff
path: root/libdino/src/service/blocking_manager.vala
blob: 1c125aaccb08957009fa3be7e51cd86714811135 (plain) (blame)
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
using Gee;

using Xmpp;
using Dino.Entities;

namespace Dino {

public class BlockingManager : StreamInteractionModule, Object {
    public static ModuleIdentity<BlockingManager> IDENTITY = new ModuleIdentity<BlockingManager>("blocking_manager");
    public string id { get { return IDENTITY.id; } }

    private StreamInteractor stream_interactor;

    public static void start(StreamInteractor stream_interactor) {
        BlockingManager m = new BlockingManager(stream_interactor);
        stream_interactor.add_module(m);
    }

    private BlockingManager(StreamInteractor stream_interactor) {
        this.stream_interactor = stream_interactor;
    }

    public bool is_blocked(Account account, Jid jid, bool domainblock = false) {
        XmppStream stream = stream_interactor.get_stream(account);
        string jid_str = domainblock ? jid.domainpart.to_string () : jid.to_string();
        return stream != null && stream.get_module(Xmpp.Xep.BlockingCommand.Module.IDENTITY).is_blocked(stream, jid_str);
    }

    public void block(Account account, Jid jid, bool domainblock = false) {
        XmppStream stream = stream_interactor.get_stream(account);
        string jid_str = domainblock ? jid.domainpart.to_string () : jid.to_string();
        stream.get_module(Xmpp.Xep.BlockingCommand.Module.IDENTITY).block(stream, { jid_str });
    }

    public void unblock(Account account, Jid jid, bool domainblock = false) {
        XmppStream stream = stream_interactor.get_stream(account);
        string jid_str = domainblock ? jid.domainpart.to_string () : jid.to_string();
        stream.get_module(Xmpp.Xep.BlockingCommand.Module.IDENTITY).unblock(stream, { jid_str });
    }

    public bool is_supported(Account account) {
        XmppStream stream = stream_interactor.get_stream(account);
        return stream != null && stream.get_module(Xmpp.Xep.BlockingCommand.Module.IDENTITY).is_supported(stream);
    }
}

}