Software /
code /
prosody-modules
Annotate
mod_block_strangers/mod_block_strangers.lua @ 946:2c5430ff1c11
mod_pubsub_googlecode: Module to receive post-commit webhook requests from Google Code Hosting
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Wed, 03 Apr 2013 15:14:16 +0100 |
parent | 774:52caf54fc270 |
child | 1324:853a382c9bd6 |
rev | line source |
---|---|
772
954532e273be
mod_block_strangers: Module to block message and iqs from people not on your roster
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1 |
954532e273be
mod_block_strangers: Module to block message and iqs from people not on your roster
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2 local jid_split = require "util.jid".split; |
954532e273be
mod_block_strangers: Module to block message and iqs from people not on your roster
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
3 local jid_bare = require "util.jid".bare; |
954532e273be
mod_block_strangers: Module to block message and iqs from people not on your roster
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
4 local is_contact_subscribed = require "core.rostermanager".is_contact_subscribed; |
954532e273be
mod_block_strangers: Module to block message and iqs from people not on your roster
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
5 |
954532e273be
mod_block_strangers: Module to block message and iqs from people not on your roster
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
6 function check_subscribed(event) |
954532e273be
mod_block_strangers: Module to block message and iqs from people not on your roster
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
7 local stanza = event.stanza; |
954532e273be
mod_block_strangers: Module to block message and iqs from people not on your roster
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
8 local to_user, to_host, to_resource = jid_split(stanza.attr.to); |
954532e273be
mod_block_strangers: Module to block message and iqs from people not on your roster
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
9 local from_jid = jid_bare(stanza.attr.from); |
954532e273be
mod_block_strangers: Module to block message and iqs from people not on your roster
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
10 if to_user and not is_contact_subscribed(to_user, to_host, from_jid) then |
954532e273be
mod_block_strangers: Module to block message and iqs from people not on your roster
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
11 if to_resource and stanza.attr.type == "groupchat" then |
954532e273be
mod_block_strangers: Module to block message and iqs from people not on your roster
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
12 return nil; -- Pass through |
954532e273be
mod_block_strangers: Module to block message and iqs from people not on your roster
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
13 end |
954532e273be
mod_block_strangers: Module to block message and iqs from people not on your roster
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
14 return true; -- Drop stanza |
954532e273be
mod_block_strangers: Module to block message and iqs from people not on your roster
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
15 end |
954532e273be
mod_block_strangers: Module to block message and iqs from people not on your roster
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
16 end |
954532e273be
mod_block_strangers: Module to block message and iqs from people not on your roster
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
17 |
774
52caf54fc270
mod_block_strangers: Bump handler priority to 200 (just because)
Matthew Wild <mwild1@gmail.com>
parents:
772
diff
changeset
|
18 module:hook("message/bare", check_subscribed, 200); |
52caf54fc270
mod_block_strangers: Bump handler priority to 200 (just because)
Matthew Wild <mwild1@gmail.com>
parents:
772
diff
changeset
|
19 module:hook("message/full", check_subscribed, 200); |
52caf54fc270
mod_block_strangers: Bump handler priority to 200 (just because)
Matthew Wild <mwild1@gmail.com>
parents:
772
diff
changeset
|
20 module:hook("iq/full", check_subscribed, 200); |