]> granicus.if.org Git - ejabberd/commitdiff
Export aux functions from mod_muc_room
authorEvgeniy Khramtsov <ekhramtsov@process-one.net>
Fri, 16 Feb 2018 05:28:33 +0000 (08:28 +0300)
committerEvgeniy Khramtsov <ekhramtsov@process-one.net>
Fri, 16 Feb 2018 05:28:33 +0000 (08:28 +0300)
src/mod_muc_room.erl

index 646d0fdd76b1d62a01ac3578ebad9e2fc087e0d7..417bd4a155f8a695187e5508ca8aade0ebf7d193 100644 (file)
@@ -37,7 +37,9 @@
         get_role/2,
         get_affiliation/2,
         is_occupant_or_admin/2,
-        route/2]).
+        route/2,
+        expand_opts/1,
+        config_fields/0]).
 
 %% gen_fsm callbacks
 -export([init/1,
@@ -3568,6 +3570,35 @@ make_opts(StateData) ->
      {subject_author, StateData#state.subject_author},
      {subscribers, Subscribers}].
 
+expand_opts(CompactOpts) ->
+    DefConfig = #config{},
+    Fields = record_info(fields, config),
+    {_, Opts1} =
+        lists:foldl(
+          fun(Field, {Pos, Opts}) ->
+                  case lists:keyfind(Field, 1, CompactOpts) of
+                      false ->
+                          DefV = element(Pos, DefConfig),
+                          DefVal = case (?SETS):is_set(DefV) of
+                                       true -> (?SETS):to_list(DefV);
+                                       false -> DefV
+                                   end,
+                          {Pos+1, [{Field, DefVal}|Opts]};
+                      {_, Val} ->
+                          {Pos+1, [{Field, Val}|Opts]}
+                  end
+          end, {2, []}, Fields),
+    SubjectAuthor = proplists:get_value(subject_author, CompactOpts, <<"">>),
+    Subject = proplists:get_value(subject, CompactOpts, <<"">>),
+    Subscribers = proplists:get_value(subscribers, CompactOpts, []),
+    [{subject, Subject},
+     {subject_author, SubjectAuthor},
+     {subscribers, Subscribers}
+     | lists:reverse(Opts1)].
+
+config_fields() ->
+    [subject, subject_author, subscribers | record_info(fields, config)].
+
 -spec destroy_room(muc_destroy(), state()) -> {result, undefined, stop}.
 destroy_room(DEl, StateData) ->
     Destroy = DEl#muc_destroy{xmlns = ?NS_MUC_USER},