Software /
code /
prosody
Comparison
plugins/mod_pep_plus.lua @ 8982:4a576c39bb2f
mod_pep_plus: Use service discovery helpers from pubsub.lib
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Fri, 06 Jul 2018 17:59:39 +0200 |
parent | 8949:9194431b6447 |
child | 9029:c5e738b54d77 |
comparison
equal
deleted
inserted
replaced
8981:b6cb0a8f75b1 | 8982:4a576c39bb2f |
---|---|
421 end | 421 end |
422 update_subscriptions(contact, username, notify); | 422 update_subscriptions(contact, username, notify); |
423 end); | 423 end); |
424 | 424 |
425 module:hook("account-disco-info-node", function(event) | 425 module:hook("account-disco-info-node", function(event) |
426 local reply, stanza, origin = event.reply, event.stanza, event.origin; | 426 local stanza, origin = event.stanza, event.origin; |
427 local service_name = origin.username; | 427 local service_name = origin.username; |
428 if stanza.attr.to ~= nil then | 428 if stanza.attr.to ~= nil then |
429 service_name = jid_split(stanza.attr.to); | 429 service_name = jid_split(stanza.attr.to); |
430 end | 430 end |
431 local service = get_pep_service(service_name); | 431 local service = get_pep_service(service_name); |
432 local node = event.node; | 432 return lib_pubsub.handle_disco_info_node(event, service); |
433 local ok = service:get_items(node, jid_bare(stanza.attr.from) or true); | |
434 if not ok then return; end | |
435 event.exists = true; | |
436 reply:tag('identity', {category='pubsub', type='leaf'}):up(); | |
437 end); | 433 end); |
438 | 434 |
439 module:hook("account-disco-info", function(event) | 435 module:hook("account-disco-info", function(event) |
440 local origin, reply = event.origin, event.reply; | 436 local origin, reply = event.origin, event.reply; |
441 | 437 |
459 reply:tag('feature', {var=xmlns_pubsub.."#"..feature}):up(); | 455 reply:tag('feature', {var=xmlns_pubsub.."#"..feature}):up(); |
460 end | 456 end |
461 end); | 457 end); |
462 | 458 |
463 module:hook("account-disco-items-node", function(event) | 459 module:hook("account-disco-items-node", function(event) |
460 local stanza, origin = event.stanza, event.origin; | |
461 local is_self = stanza.attr.to == nil; | |
462 local username = jid_split(stanza.attr.to); | |
463 if is_self then | |
464 username = origin.username; | |
465 end | |
466 local service = get_pep_service(username); | |
467 return lib_pubsub.handle_disco_items_node(event, service); | |
468 end); | |
469 | |
470 module:hook("account-disco-items", function(event) | |
464 local reply, stanza, origin = event.reply, event.stanza, event.origin; | 471 local reply, stanza, origin = event.reply, event.stanza, event.origin; |
465 local node = event.node; | 472 |
466 local is_self = stanza.attr.to == nil; | 473 local is_self = stanza.attr.to == nil; |
467 local user_bare = jid_bare(stanza.attr.to); | 474 local user_bare = jid_bare(stanza.attr.to); |
468 local username = jid_split(stanza.attr.to); | 475 local username = jid_split(stanza.attr.to); |
469 if is_self then | 476 if is_self then |
470 username = origin.username; | 477 username = origin.username; |
471 user_bare = jid_join(username, host); | 478 user_bare = jid_join(username, host); |
472 end | 479 end |
473 local service = get_pep_service(username); | 480 local service = get_pep_service(username); |
474 local ok, ret = service:get_items(node, jid_bare(stanza.attr.from) or true); | |
475 if not ok then return; end | |
476 event.exists = true; | |
477 for _, id in ipairs(ret) do | |
478 reply:tag("item", { jid = user_bare, name = id }):up(); | |
479 end | |
480 end); | |
481 | |
482 module:hook("account-disco-items", function(event) | |
483 local reply, stanza, origin = event.reply, event.stanza, event.origin; | |
484 | |
485 local is_self = stanza.attr.to == nil; | |
486 local user_bare = jid_bare(stanza.attr.to); | |
487 local username = jid_split(stanza.attr.to); | |
488 if is_self then | |
489 username = origin.username; | |
490 user_bare = jid_join(username, host); | |
491 end | |
492 local service = get_pep_service(username); | |
493 | 481 |
494 local ok, ret = service:get_nodes(jid_bare(stanza.attr.from)); | 482 local ok, ret = service:get_nodes(jid_bare(stanza.attr.from)); |
495 if not ok then return; end | 483 if not ok then return; end |
496 | 484 |
497 for node, node_obj in pairs(ret) do | 485 for node, node_obj in pairs(ret) do |