From 7564a4e95368e41cc9d63371d942ebca50f537ce Mon Sep 17 00:00:00 2001 From: Linus Jahn Date: Sun, 12 Jun 2022 15:55:59 +0200 Subject: [PATCH] mod_mix_pam: Provide MIX channels as roster entries via hook --- include/mod_roster.hrl | 3 ++- src/mod_mix_pam.erl | 26 ++++++++++++++++++++++++++ src/mod_roster.erl | 6 +++++- 3 files changed, 33 insertions(+), 2 deletions(-) diff --git a/include/mod_roster.hrl b/include/mod_roster.hrl index 6ec05b3da..3f9a951c4 100644 --- a/include/mod_roster.hrl +++ b/include/mod_roster.hrl @@ -28,7 +28,8 @@ ask = none :: ask() | '_', groups = [] :: [binary()] | '_', askmessage = <<"">> :: binary() | '_', - xs = [] :: [fxml:xmlel()] | '_' + xs = [] :: [fxml:xmlel()] | '_', + mix_participant_id = <<>> :: binary() | '_' }). -record(roster_version, diff --git a/src/mod_mix_pam.erl b/src/mod_mix_pam.erl index e67ae2c80..9bf75d1ba 100644 --- a/src/mod_mix_pam.erl +++ b/src/mod_mix_pam.erl @@ -32,11 +32,13 @@ disco_sm_features/5, remove_user/2, process_iq/1, + get_mix_roster_items/2, webadmin_user/4, webadmin_page/3]). -include_lib("xmpp/include/xmpp.hrl"). -include("logger.hrl"). +-include("mod_roster.hrl"). -include("translate.hrl"). -include("ejabberd_http.hrl"). -include("ejabberd_web_admin.hrl"). @@ -65,6 +67,7 @@ start(Host, Opts) -> ejabberd_hooks:add(bounce_sm_packet, Host, ?MODULE, bounce_sm_packet, 50), ejabberd_hooks:add(disco_sm_features, Host, ?MODULE, disco_sm_features, 50), ejabberd_hooks:add(remove_user, Host, ?MODULE, remove_user, 50), + ejabberd_hooks:add(roster_get, Host, ?MODULE, get_mix_roster_items, 50), ejabberd_hooks:add(webadmin_user, Host, ?MODULE, webadmin_user, 50), ejabberd_hooks:add(webadmin_page_host, Host, ?MODULE, webadmin_page, 50), gen_iq_handler:add_iq_handler(ejabberd_sm, Host, ?NS_MIX_PAM_0, @@ -77,6 +80,7 @@ stop(Host) -> ejabberd_hooks:delete(bounce_sm_packet, Host, ?MODULE, bounce_sm_packet, 50), ejabberd_hooks:delete(disco_sm_features, Host, ?MODULE, disco_sm_features, 50), ejabberd_hooks:delete(remove_user, Host, ?MODULE, remove_user, 50), + ejabberd_hooks:delete(roster_get, Host, ?MODULE, get_mix_roster_items, 50), ejabberd_hooks:delete(webadmin_user, Host, ?MODULE, webadmin_user, 50), ejabberd_hooks:delete(webadmin_page_host, Host, ?MODULE, webadmin_page, 50), gen_iq_handler:remove_iq_handler(ejabberd_sm, Host, ?NS_MIX_PAM_0). @@ -208,6 +212,28 @@ process_iq(#iq{type = set, process_iq(IQ) -> xmpp:make_error(IQ, unsupported_query_error(IQ)). +-spec get_mix_roster_items([#roster{}], {binary(), binary()}) -> [#roster{}]. +get_mix_roster_items(Acc, {LUser, LServer}) -> + JID = jid:make(LUser, LServer), + case get_channels(JID) of + {ok, Channels} -> + lists:map( + fun({#jid{luser=Channel, lserver=Service}, Id}) -> + #roster{ + jid = {Channel, Service, <<>>}, + name = <<>>, + subscription = both, + ask = none, + groups = [<<"Channels">>], + askmessage = <<>>, + xs = [], + mix_participant_id = Id + } + end, Channels); + _ -> + [] + end ++ Acc. + -spec remove_user(binary(), binary()) -> ok | {error, db_failure}. remove_user(LUser, LServer) -> Mod = gen_mod:db_mod(LServer, ?MODULE), diff --git a/src/mod_roster.erl b/src/mod_roster.erl index e2b176502..d3a0c6be2 100644 --- a/src/mod_roster.erl +++ b/src/mod_roster.erl @@ -426,7 +426,11 @@ encode_item(Item) -> both -> subscribe; _ -> undefined end, - groups = Item#roster.groups}. + groups = Item#roster.groups, + mix_channel = case Item#roster.mix_participant_id of + <<>> -> undefined; + _ -> #mix_roster_channel{'participant-id' = Item#roster.mix_participant_id} + end}. -spec decode_item(roster_item(), #roster{}, boolean()) -> #roster{}. decode_item(#roster_item{subscription = remove} = Item, R, _) ->