]> granicus.if.org Git - ejabberd/commitdiff
* src/mod_shared_roster.erl: Shared roster entries can now be
authorMickaël Rémond <mickael.remond@process-one.net>
Thu, 6 Jul 2006 14:08:09 +0000 (14:08 +0000)
committerMickaël Rémond <mickael.remond@process-one.net>
Thu, 6 Jul 2006 14:08:09 +0000 (14:08 +0000)
moved or rename from a client without breaking current presence status
(EJAB-70).
* src/mod_roster.erl: Likewise.
* src/mod_roster_odbc.erl: Likewise.

SVN Revision: 586

ChangeLog
src/mod_roster.erl
src/mod_roster_odbc.erl
src/mod_shared_roster.erl

index e39bdb54b2d40be1daa8e7826cca539982e8fa83..592f90926a9d75fa934e864d941a2aeb789cefce 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2006-07-06  Mickael Remond  <mickael.remond@process-one.net>
+
+       * src/mod_shared_roster.erl: Shared roster entries can now be moved or
+       rename from a client without breaking current presence status.
+       * src/mod_roster.erl: Likewise.
+       * src/mod_roster_odbc.erl: Likewise.
+
 2006-07-05  Mickael Remond  <mickael.remond@process-one.net>
 
        * src/web/ejabberd_web_admin.erl: More flexible parsing the shared
index 896b0e9f9bdea341b217f9b7d08501b505a59812..04d539cbf25b960d6466b3960b7f75edd307cd4e 100644 (file)
@@ -205,7 +205,11 @@ process_item_set(From, To, {xmlelement, _Name, Attrs, Els}) ->
                            _ ->
                                mnesia:write(Item2)
                        end,
-                       {Item, Item2}
+                       %% If the item exist in shared roster, take the
+                       %% subscription information from there:
+                       Item3 = ejabberd_hooks:run_fold(roster_process_item,
+                                                       LServer, Item2, [LServer]),
+                       {Item, Item3}
                end,
            case mnesia:transaction(F) of
                {atomic, {OldItem, Item}} ->
index 626698cc771fcf04cd724d7ca2b2f1babcc8f07a..dfea38480a196d63b685ea495e315c9c0fa912ac 100644 (file)
@@ -273,7 +273,11 @@ process_item_set(From, To, {xmlelement, _Name, Attrs, Els}) ->
                                              end,
                                              ItemGroups)
                        end,
-                       {Item, Item2}
+                       %% If the item exist in shared roster, take the
+                       %% subscription information from there:
+                       Item3 = ejabberd_hooks:run_fold(roster_process_item,
+                                                       LServer, Item2, [LServer]),
+                       {Item, Item3}
                end,
            case ejabberd_odbc:sql_transaction(LServer, F) of
                {atomic, {OldItem, Item}} ->
index 7477d31c9ab4fb46a2445a4f4dd018b145ded52d..6a438e673096f24eef17551746a5c23f29ab0ede 100644 (file)
@@ -15,6 +15,7 @@
         get_user_roster/2,
         get_subscription_lists/3,
         get_jid_info/4,
+        process_item/2,
         in_subscription/6,
         out_subscription/4,
         list_groups/1,
@@ -53,7 +54,9 @@ start(Host, _Opts) ->
     ejabberd_hooks:add(roster_get_subscription_lists, Host,
                       ?MODULE, get_subscription_lists, 70),
     ejabberd_hooks:add(roster_get_jid_info, Host,
-                      ?MODULE, get_jid_info, 70).
+                      ?MODULE, get_jid_info, 70),
+    ejabberd_hooks:add(roster_process_item, Host,
+                      ?MODULE, process_item, 50).
     %ejabberd_hooks:add(remove_user, Host,
     %                 ?MODULE, remove_user, 50),
 
@@ -67,7 +70,9 @@ stop(Host) ->
     ejabberd_hooks:delete(roster_get_subscription_lists, Host,
                          ?MODULE, get_subscription_lists, 70),
     ejabberd_hooks:delete(roster_get_jid_info, Host,
-                         ?MODULE, get_jid_info, 70).
+                         ?MODULE, get_jid_info, 70),
+    ejabberd_hooks:delete(roster_process_item, Host,
+                         ?MODULE, process_item, 50).
     %ejabberd_hooks:delete(remove_user, Host,
     %                    ?MODULE, remove_user, 50),
 
@@ -116,6 +121,28 @@ get_user_roster(Items, US) ->
                  {{U1, S1}, GroupNames} <- dict:to_list(SRUsersRest)],
     SRItems ++ NewItems1.
 
+%% This function in use to rewrite the roster entries when moving or renaming
+%% them in the user contact list.
+process_item(RosterItem, Host) ->
+    USFrom = RosterItem#roster.us,
+    {User,Server,_Resource} = RosterItem#roster.jid,
+    USTo = {User,Server},
+    DisplayedGroups = get_user_displayed_groups(USFrom),
+    CommonGroups = lists:filter(fun(Group) ->
+                                       is_user_in_group(USTo, Group, Host)
+                               end, DisplayedGroups),
+    case CommonGroups of
+       [] -> RosterItem;
+       %% Roster item cannot be removed: We simply reset the original groups:
+       _ when RosterItem#roster.subscription == remove ->
+           GroupNames = lists:map(fun(Group) ->
+                                          get_group_name(Host, Group)
+                                  end, CommonGroups),
+           RosterItem#roster{subscription = both, ask = none,
+                             groups=[GroupNames]};
+       _ -> RosterItem#roster{subscription = both, ask = none}
+    end.
+
 get_subscription_lists({F, T}, User, Server) ->
     LUser = jlib:nodeprep(User),
     LServer = jlib:nameprep(Server),
@@ -234,8 +261,6 @@ set_group_opts(Host, Group, Opts) ->
        end,
     mnesia:transaction(F).
 
-
-
 get_user_groups(US) ->
     Host = element(2, US),
     case catch mnesia:dirty_read(sr_user, US) of
@@ -306,6 +331,12 @@ get_user_displayed_groups(US) ->
            end, get_user_groups(US))),
     [Group || Group <- DisplayedGroups1, is_group_enabled(Host, Group)].
 
+is_user_in_group(US, Group, Host) ->
+    case mnesia:match_object(#sr_user{us=US, group_host={Group, Host}}) of
+       [] -> false;
+       _  -> true
+    end.
+
 add_user_to_group(Host, US, Group) ->
     R = #sr_user{us = US, group_host = {Group, Host}},
     F = fun() ->