24
1
mirror of https://github.com/processone/ejabberd.git synced 2024-06-16 22:05:29 +02:00

Add support for MUC room vCard in get_vcard commands

This commit is contained in:
Badlop 2022-04-12 13:23:36 +02:00
parent 10481ed895
commit 19019bbe32
2 changed files with 33 additions and 1 deletions

View File

@ -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];

View File

@ -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]).