Software /
code /
prosody
Comparison
plugins/mod_pep_plus.lua @ 8341:910d3c3f60a6
mod_pep_plus: Use feature detection from pubsub.lib
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Wed, 18 Oct 2017 09:43:43 +0200 |
parent | 8339:4fce6bc0719f |
child | 8342:0c0990a575de |
comparison
equal
deleted
inserted
replaced
8340:7c1fb8c042dc | 8341:910d3c3f60a6 |
---|---|
5 local set_new = require "util.set".new; | 5 local set_new = require "util.set".new; |
6 local st = require "util.stanza"; | 6 local st = require "util.stanza"; |
7 local calculate_hash = require "util.caps".calculate_hash; | 7 local calculate_hash = require "util.caps".calculate_hash; |
8 local is_contact_subscribed = require "core.rostermanager".is_contact_subscribed; | 8 local is_contact_subscribed = require "core.rostermanager".is_contact_subscribed; |
9 local cache = require "util.cache"; | 9 local cache = require "util.cache"; |
10 local set = require "util.set"; | |
10 | 11 |
11 local xmlns_pubsub = "http://jabber.org/protocol/pubsub"; | 12 local xmlns_pubsub = "http://jabber.org/protocol/pubsub"; |
12 local xmlns_pubsub_event = "http://jabber.org/protocol/pubsub#event"; | 13 local xmlns_pubsub_event = "http://jabber.org/protocol/pubsub#event"; |
13 local xmlns_pubsub_owner = "http://jabber.org/protocol/pubsub#owner"; | 14 local xmlns_pubsub_owner = "http://jabber.org/protocol/pubsub#owner"; |
14 | 15 |
409 | 410 |
410 module:hook("account-disco-info", function(event) | 411 module:hook("account-disco-info", function(event) |
411 local origin, reply = event.origin, event.reply; | 412 local origin, reply = event.origin, event.reply; |
412 | 413 |
413 reply:tag('identity', {category='pubsub', type='pep'}):up(); | 414 reply:tag('identity', {category='pubsub', type='pep'}):up(); |
414 reply:tag('feature', {var=xmlns_pubsub}):up(); | |
415 | 415 |
416 local username = jid_split(reply.attr.from) or origin.username; | 416 local username = jid_split(reply.attr.from) or origin.username; |
417 local service = get_pep_service(username); | 417 local service = get_pep_service(username); |
418 | 418 |
419 local feature_map = { | 419 local suppored_features = lib_pubsub.get_feature_set(service) + set.new{ |
420 create = { "create-nodes", "instant-nodes", "item-ids" }; | 420 -- Features not covered by the above |
421 retract = { "delete-items", "retract-items" }; | |
422 purge = { "purge-nodes" }; | |
423 publish = { "publish", service.config.autocreate_on_publish and "auto-create" }; | |
424 delete = { "delete-nodes" }; | |
425 get_items = { "retrieve-items" }; | |
426 add_subscription = { "subscribe" }; | |
427 get_subscriptions = { "retrieve-subscriptions" }; | |
428 set_node_config = { "config-node" }; | |
429 node_defaults = { "retrieve-default" }; | |
430 }; | |
431 | |
432 for method, features in pairs(feature_map) do | |
433 if service[method] then | |
434 for _, feature in ipairs(features) do | |
435 if feature then | |
436 reply:tag('feature', {var=xmlns_pubsub.."#"..feature}):up(); | |
437 end | |
438 end | |
439 end | |
440 end | |
441 for affiliation in pairs(service.config.capabilities) do | |
442 if affiliation ~= "none" and affiliation ~= "owner" then | |
443 reply:tag('feature', {var=xmlns_pubsub.."#"..affiliation.."-affiliation"}):up(); | |
444 end | |
445 end | |
446 | |
447 -- Features not covered by the above | |
448 local more_features = { | |
449 "access-presence", | 421 "access-presence", |
450 "auto-subscribe", | 422 "auto-subscribe", |
451 "filtered-notifications", | 423 "filtered-notifications", |
452 "last-published", | 424 "last-published", |
453 "persistent-items", | 425 "persistent-items", |
454 "presence-notifications", | 426 "presence-notifications", |
455 "presence-subscribe", | 427 "presence-subscribe", |
456 }; | 428 }; |
457 for _, feature in ipairs(more_features) do | 429 |
430 for feature in suppored_features do | |
458 reply:tag('feature', {var=xmlns_pubsub.."#"..feature}):up(); | 431 reply:tag('feature', {var=xmlns_pubsub.."#"..feature}):up(); |
459 end | 432 end |
460 end); | 433 end); |
461 | 434 |
462 module:hook("account-disco-items-node", function(event) | 435 module:hook("account-disco-items-node", function(event) |