Software /
code /
prosody
Comparison
plugins/mod_pubsub/pubsub.lib.lua @ 8340:7c1fb8c042dc
mod_pubsub: Move service feature dection to pubsub.lib to allow reuse
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Wed, 18 Oct 2017 09:38:45 +0200 |
parent | 8338:30d8157391e9 |
child | 8374:b52663586243 |
comparison
equal
deleted
inserted
replaced
8339:4fce6bc0719f | 8340:7c1fb8c042dc |
---|---|
1 local t_unpack = table.unpack or unpack; -- luacheck: ignore 113 | 1 local t_unpack = table.unpack or unpack; -- luacheck: ignore 113 |
2 local time_now = os.time; | 2 local time_now = os.time; |
3 | 3 |
4 local set = require "util.set"; | |
4 local st = require "util.stanza"; | 5 local st = require "util.stanza"; |
5 local it = require "util.iterators"; | 6 local it = require "util.iterators"; |
6 local uuid_generate = require "util.uuid".generate; | 7 local uuid_generate = require "util.uuid".generate; |
7 local dataform = require"util.dataforms".new; | 8 local dataform = require"util.dataforms".new; |
8 | 9 |
51 name = "pubsub#persist_items"; | 52 name = "pubsub#persist_items"; |
52 label = "Persist items to storage"; | 53 label = "Persist items to storage"; |
53 }; | 54 }; |
54 }; | 55 }; |
55 | 56 |
57 local service_method_feature_map = { | |
58 add_subscription = { "subscribe" }; | |
59 create = { "create-nodes", "instant-nodes", "item-ids", "create-and-configure" }; | |
60 delete = { "delete-nodes" }; | |
61 get_items = { "retrieve-items" }; | |
62 get_subscriptions = { "retrieve-subscriptions" }; | |
63 node_defaults = { "retrieve-default" }; | |
64 publish = { "publish" }; | |
65 purge = { "purge-nodes" }; | |
66 retract = { "delete-items", "retract-items" }; | |
67 set_node_config = { "config-node" }; | |
68 }; | |
69 local service_config_feature_map = { | |
70 autocreate_on_publish = { "auto-create" }; | |
71 }; | |
72 | |
73 function _M.get_feature_set(service) | |
74 local supported_features = set.new(); | |
75 | |
76 for method, features in pairs(service_method_feature_map) do | |
77 if service[method] then | |
78 for _, feature in ipairs(features) do | |
79 if feature then | |
80 supported_features:add(feature); | |
81 end | |
82 end | |
83 end | |
84 end | |
85 | |
86 for option, features in pairs(service_config_feature_map) do | |
87 if service.config[option] then | |
88 for _, feature in ipairs(features) do | |
89 if feature then | |
90 supported_features:add(feature); | |
91 end | |
92 end | |
93 end | |
94 end | |
95 | |
96 for affiliation in pairs(service.config.capabilities) do | |
97 if affiliation ~= "none" and affiliation ~= "owner" then | |
98 supported_features:add(affiliation.."-affiliation"); | |
99 end | |
100 end | |
101 | |
102 return supported_features; | |
103 end | |
104 | |
56 function _M.handle_pubsub_iq(event, service) | 105 function _M.handle_pubsub_iq(event, service) |
57 local origin, stanza = event.origin, event.stanza; | 106 local origin, stanza = event.origin, event.stanza; |
58 local pubsub_tag = stanza.tags[1]; | 107 local pubsub_tag = stanza.tags[1]; |
59 local action = pubsub_tag.tags[1]; | 108 local action = pubsub_tag.tags[1]; |
60 if not action then | 109 if not action then |