From 19019bbe32be2074e3b78ac13fdfc30c260fff5e Mon Sep 17 00:00:00 2001 From: Badlop Date: Tue, 12 Apr 2022 13:23:36 +0200 Subject: [PATCH] Add support for MUC room vCard in get_vcard commands --- src/mod_admin_extra.erl | 33 ++++++++++++++++++++++++++++++++- src/mod_muc_admin.erl | 1 + 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/src/mod_admin_extra.erl b/src/mod_admin_extra.erl index 0b95c9ceb..cc1996bbd 100644 --- a/src/mod_admin_extra.erl +++ b/src/mod_admin_extra.erl @@ -1149,12 +1149,35 @@ set_vcard(User, Host, Name, SomeContent) -> set_vcard(User, Host, Name, Subname, SomeContent) -> set_vcard_content(User, Host, [Name, Subname], SomeContent). +%% +%% Room vcard + +is_muc_service(Domain) -> + try mod_muc_admin:get_room_serverhost(Domain) of + Domain -> false; + Service when is_binary(Service) -> true + catch _:{unregistered_route, _} -> + throw(error_wrong_hostname) + end. + +get_room_vcard(Name, Service) -> + case mod_muc_admin:get_room_options(Name, Service) of + [] -> + throw(error_no_vcard_found); + Opts -> + case lists:keyfind(<<"vcard">>, 1, Opts) of + false -> + throw(error_no_vcard_found); + {_, VCardRaw} -> + [fxml_stream:parse_element(VCardRaw)] + end + end. %% %% Internal vcard get_vcard_content(User, Server, Data) -> - case mod_vcard:get_vcard(jid:nodeprep(User), jid:nameprep(Server)) of + case get_vcard_element(User, Server) of [El|_] -> case get_vcard(Data, El) of [false] -> throw(error_no_value_found_in_vcard); @@ -1166,6 +1189,14 @@ get_vcard_content(User, Server, Data) -> throw(database_failure) end. +get_vcard_element(User, Server) -> + case is_muc_service(Server) of + true -> + get_room_vcard(User, Server); + false -> + mod_vcard:get_vcard(jid:nodeprep(User), jid:nameprep(Server)) + end. + get_vcard([<<"TEL">>, TelType], {_, _, _, OldEls}) -> {TakenEl, _NewEls} = take_vcard_tel(TelType, OldEls, [], not_found), [TakenEl]; diff --git a/src/mod_muc_admin.erl b/src/mod_muc_admin.erl index 0015eb30a..5e7ae6696 100644 --- a/src/mod_muc_admin.erl +++ b/src/mod_muc_admin.erl @@ -42,6 +42,7 @@ web_menu_main/2, web_page_main/2, web_menu_host/3, subscribe_room/4, subscribe_room_many/3, unsubscribe_room/2, get_subscribers/2, + get_room_serverhost/1, web_page_host/3, mod_opt_type/1, mod_options/1, get_commands_spec/0, find_hosts/1]).