Software /
code /
verse
Annotate
plugins/blocking.lua @ 502:783188a44b0a
Makefile: Remove custom fetching of util.rsm
It should be covered by regular fetching of Prosody resources
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Fri, 23 Jun 2023 12:44:24 +0200 |
parent | 250:a5ac643a7fd6 |
rev | line source |
---|---|
250 | 1 local verse = require "verse"; |
2 | |
80
336864e83991
verse.plugins.blocking, squishy: New plugin for XEP-0191: Simple Communications Blocking
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
3 local xmlns_blocking = "urn:xmpp:blocking"; |
336864e83991
verse.plugins.blocking, squishy: New plugin for XEP-0191: Simple Communications Blocking
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
4 |
336864e83991
verse.plugins.blocking, squishy: New plugin for XEP-0191: Simple Communications Blocking
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
5 function verse.plugins.blocking(stream) |
336864e83991
verse.plugins.blocking, squishy: New plugin for XEP-0191: Simple Communications Blocking
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
6 -- FIXME: Disco |
336864e83991
verse.plugins.blocking, squishy: New plugin for XEP-0191: Simple Communications Blocking
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
7 stream.blocking = {}; |
336864e83991
verse.plugins.blocking, squishy: New plugin for XEP-0191: Simple Communications Blocking
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
8 function stream.blocking:block_jid(jid, callback) |
336864e83991
verse.plugins.blocking, squishy: New plugin for XEP-0191: Simple Communications Blocking
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
9 stream:send_iq(verse.iq{type="set"} |
336864e83991
verse.plugins.blocking, squishy: New plugin for XEP-0191: Simple Communications Blocking
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
10 :tag("block", { xmlns = xmlns_blocking }) |
336864e83991
verse.plugins.blocking, squishy: New plugin for XEP-0191: Simple Communications Blocking
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
11 :tag("item", { jid = jid }) |
336864e83991
verse.plugins.blocking, squishy: New plugin for XEP-0191: Simple Communications Blocking
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
12 , function () return callback and callback(true); end |
336864e83991
verse.plugins.blocking, squishy: New plugin for XEP-0191: Simple Communications Blocking
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
13 , function () return callback and callback(false); end |
336864e83991
verse.plugins.blocking, squishy: New plugin for XEP-0191: Simple Communications Blocking
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
14 ); |
336864e83991
verse.plugins.blocking, squishy: New plugin for XEP-0191: Simple Communications Blocking
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
15 end |
336864e83991
verse.plugins.blocking, squishy: New plugin for XEP-0191: Simple Communications Blocking
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
16 function stream.blocking:unblock_jid(jid, callback) |
336864e83991
verse.plugins.blocking, squishy: New plugin for XEP-0191: Simple Communications Blocking
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
17 stream:send_iq(verse.iq{type="set"} |
336864e83991
verse.plugins.blocking, squishy: New plugin for XEP-0191: Simple Communications Blocking
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
18 :tag("unblock", { xmlns = xmlns_blocking }) |
336864e83991
verse.plugins.blocking, squishy: New plugin for XEP-0191: Simple Communications Blocking
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
19 :tag("item", { jid = jid }) |
336864e83991
verse.plugins.blocking, squishy: New plugin for XEP-0191: Simple Communications Blocking
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
20 , function () return callback and callback(true); end |
336864e83991
verse.plugins.blocking, squishy: New plugin for XEP-0191: Simple Communications Blocking
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
21 , function () return callback and callback(false); end |
336864e83991
verse.plugins.blocking, squishy: New plugin for XEP-0191: Simple Communications Blocking
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
22 ); |
336864e83991
verse.plugins.blocking, squishy: New plugin for XEP-0191: Simple Communications Blocking
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
23 end |
336864e83991
verse.plugins.blocking, squishy: New plugin for XEP-0191: Simple Communications Blocking
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
24 function stream.blocking:unblock_all_jids(callback) |
336864e83991
verse.plugins.blocking, squishy: New plugin for XEP-0191: Simple Communications Blocking
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
25 stream:send_iq(verse.iq{type="set"} |
336864e83991
verse.plugins.blocking, squishy: New plugin for XEP-0191: Simple Communications Blocking
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
26 :tag("unblock", { xmlns = xmlns_blocking }) |
336864e83991
verse.plugins.blocking, squishy: New plugin for XEP-0191: Simple Communications Blocking
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
27 , function () return callback and callback(true); end |
336864e83991
verse.plugins.blocking, squishy: New plugin for XEP-0191: Simple Communications Blocking
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
28 , function () return callback and callback(false); end |
336864e83991
verse.plugins.blocking, squishy: New plugin for XEP-0191: Simple Communications Blocking
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
29 ); |
336864e83991
verse.plugins.blocking, squishy: New plugin for XEP-0191: Simple Communications Blocking
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
30 end |
336864e83991
verse.plugins.blocking, squishy: New plugin for XEP-0191: Simple Communications Blocking
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
31 function stream.blocking:get_blocked_jids(callback) |
336864e83991
verse.plugins.blocking, squishy: New plugin for XEP-0191: Simple Communications Blocking
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
32 stream:send_iq(verse.iq{type="get"} |
336864e83991
verse.plugins.blocking, squishy: New plugin for XEP-0191: Simple Communications Blocking
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
33 :tag("blocklist", { xmlns = xmlns_blocking }) |
336864e83991
verse.plugins.blocking, squishy: New plugin for XEP-0191: Simple Communications Blocking
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
34 , function (result) |
336864e83991
verse.plugins.blocking, squishy: New plugin for XEP-0191: Simple Communications Blocking
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
35 local list = result:get_child("blocklist", xmlns_blocking); |
336864e83991
verse.plugins.blocking, squishy: New plugin for XEP-0191: Simple Communications Blocking
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
36 if not list then return callback and callback(false); end |
336864e83991
verse.plugins.blocking, squishy: New plugin for XEP-0191: Simple Communications Blocking
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
37 local jids = {}; |
336864e83991
verse.plugins.blocking, squishy: New plugin for XEP-0191: Simple Communications Blocking
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
38 for item in list:childtags() do |
336864e83991
verse.plugins.blocking, squishy: New plugin for XEP-0191: Simple Communications Blocking
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
39 jids[#jids+1] = item.attr.jid; |
336864e83991
verse.plugins.blocking, squishy: New plugin for XEP-0191: Simple Communications Blocking
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
40 end |
336864e83991
verse.plugins.blocking, squishy: New plugin for XEP-0191: Simple Communications Blocking
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
41 return callback and callback(jids); |
336864e83991
verse.plugins.blocking, squishy: New plugin for XEP-0191: Simple Communications Blocking
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
42 end |
336864e83991
verse.plugins.blocking, squishy: New plugin for XEP-0191: Simple Communications Blocking
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
43 , function (result) return callback and callback(false); end |
336864e83991
verse.plugins.blocking, squishy: New plugin for XEP-0191: Simple Communications Blocking
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
44 ); |
336864e83991
verse.plugins.blocking, squishy: New plugin for XEP-0191: Simple Communications Blocking
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
45 end |
336864e83991
verse.plugins.blocking, squishy: New plugin for XEP-0191: Simple Communications Blocking
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
46 end |