aboutsummaryrefslogtreecommitdiff
path: root/libdino/src/service/blocking_manager.vala
blob: 183c8a9e1088538eac2dc4cd7b30a1c17d3fb5fa (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
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) {
        XmppStream stream = stream_interactor.get_stream(account);
        return stream != null && stream.get_module(Xmpp.Xep.BlockingCommand.Module.IDENTITY).is_blocked(stream, jid.to_string());
    }

    public void block(Account account, Jid jid) {
        XmppStream stream = stream_interactor.get_stream(account);
        stream.get_module(Xmpp.Xep.BlockingCommand.Module.IDENTITY).block(stream, new ArrayList<string>.wrap(new string[] {jid.to_string()}));
    }

    public void unblock(Account account, Jid jid) {
        XmppStream stream = stream_interactor.get_stream(account);
        stream.get_module(Xmpp.Xep.BlockingCommand.Module.IDENTITY).unblock(stream, new ArrayList<string>.wrap(new string[] {jid.to_string()}));
    }

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

}