aboutsummaryrefslogtreecommitdiff
path: root/src/mod_shared_roster.erl
diff options
context:
space:
mode:
authorBadlop <badlop@process-one.net>2010-02-02 19:47:22 +0100
committerBadlop <badlop@process-one.net>2010-02-15 22:47:28 +0100
commit6795675108c664b2e104db13c2c410b1ba7d319a (patch)
tree09874d86af1efed7764fbbfa9994e08087f1fd59 /src/mod_shared_roster.erl
parentCross-domain HTTP-Bind support (thanks to Jack Moffitt)(EJAB-1168) (diff)
Shared roster gets contact nickname from vcard, when available (EJAB-114)
Diffstat (limited to 'src/mod_shared_roster.erl')
-rw-r--r--src/mod_shared_roster.erl31
1 files changed, 30 insertions, 1 deletions
diff --git a/src/mod_shared_roster.erl b/src/mod_shared_roster.erl
index 0a516f960..60bf6a1af 100644
--- a/src/mod_shared_roster.erl
+++ b/src/mod_shared_roster.erl
@@ -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) ->