]> granicus.if.org Git - ejabberd/commitdiff
Shared roster gets contact nickname from vcard, when available (EJAB-114)
authorBadlop <badlop@process-one.net>
Tue, 2 Feb 2010 18:47:22 +0000 (19:47 +0100)
committerBadlop <badlop@process-one.net>
Mon, 15 Feb 2010 21:47:28 +0000 (22:47 +0100)
src/mod_shared_roster.erl

index 0a516f960a44379b568981781cb224e215b94b6e..60bf6a1afed966b6f5be21f988f4db81d4b43d58 100644 (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) ->