25
1
mirror of https://github.com/processone/ejabberd.git synced 2024-11-22 16:20:52 +01:00

Shared roster gets contact nickname from vcard, when available (EJAB-114)

This commit is contained in:
Badlop 2010-02-02 19:47:22 +01:00
parent 6867ca43e4
commit 6795675108

View File

@ -152,16 +152,45 @@ get_user_roster(Items, US) ->
end, SRUsers, Items),
%% Export items in roster format:
ModVcard = get_vcard_module(S),
SRItems = [#roster{usj = {U, S, {U1, S1, ""}},
us = US,
jid = {U1, S1, ""},
name = "",
name = get_rosteritem_name(ModVcard, U1, S1),
subscription = both,
ask = none,
groups = GroupNames} ||
{{U1, S1}, GroupNames} <- dict:to_list(SRUsersRest)],
SRItems ++ NewItems1.
get_vcard_module(Server) ->
Modules = gen_mod:loaded_modules(Server),
[M || M <- Modules,
(M == mod_vcard) or (M == mod_vcard_odbc) or (M == mod_vcard_ldap)].
get_rosteritem_name([], _, _) ->
"";
get_rosteritem_name([ModVcard], U, S) ->
From = jlib:make_jid("", S, mod_shared_roster),
To = jlib:make_jid(U, S, ""),
IQ = {iq,"",get,"vcard-temp","",
{xmlelement,"vCard",[{"xmlns","vcard-temp"}],[]}},
IQ_Vcard = ModVcard:process_sm_iq(From, To, IQ),
try get_rosteritem_name_vcard(IQ_Vcard#iq.sub_el)
catch E1:E2 ->
?ERROR_MSG("Error ~p found when trying to get the vCard of ~s@~s "
"in ~p:~n ~p", [E1, U, S, ModVcard, E2]),
""
end.
get_rosteritem_name_vcard([]) ->
"";
get_rosteritem_name_vcard([Vcard]) ->
case xml:get_path_s(Vcard, [{elem, "NICKNAME"}, cdata]) of
"" -> xml:get_path_s(Vcard, [{elem, "FN"}, cdata]);
Nickname -> Nickname
end.
%% This function rewrites the roster entries when moving or renaming
%% them in the user contact list.
process_item(RosterItem, Host) ->