]> granicus.if.org Git - ejabberd/commitdiff
Advertise muc#roominfo_logs in disco#info of the room
authorEvgeny Khramtsov <ekhramtsov@process-one.net>
Thu, 26 Sep 2019 13:53:36 +0000 (16:53 +0300)
committerEvgeny Khramtsov <ekhramtsov@process-one.net>
Thu, 26 Sep 2019 13:53:36 +0000 (16:53 +0300)
The commit adds new `url` option for mod_muc_log.
Fixes #3040

src/mod_muc_log.erl
src/mod_muc_log_opt.erl
src/mod_muc_room.erl

index b20d949353717ddffbb86571bcbf61b51c8d6643..08498869f74016d2b3901211e255a46b6e3de8b5 100644 (file)
@@ -34,7 +34,7 @@
 -behaviour(gen_mod).
 
 %% API
--export([start/2, stop/1, reload/3,
+-export([start/2, stop/1, reload/3, get_url/1,
         check_access_log/2, add_to_log/5]).
 
 -export([init/1, handle_call/3, handle_cast/2,
@@ -90,6 +90,19 @@ check_access_log(Host, From) ->
       Res -> Res
     end.
 
+-spec get_url(#state{}) -> {ok, binary()} | error.
+get_url(#state{room = Room, host = Host, server_host = ServerHost}) ->
+    case mod_muc_log_opt:url(ServerHost) of
+       undefined -> error;
+       URL ->
+           case mod_muc_log_opt:dirname(ServerHost) of
+               room_jid ->
+                   {ok, <<URL/binary, $/, Room/binary, $@, Host/binary>>};
+               room_name ->
+                   {ok, <<URL/binary, $/, Room/binary>>}
+           end
+    end.
+
 depends(_Host, _Opts) ->
     [{mod_muc, hard}].
 
@@ -953,6 +966,8 @@ mod_opt_type(spam_prevention) ->
     econf:bool();
 mod_opt_type(timezone) ->
     econf:enum([local, universal]);
+mod_opt_type(url) ->
+    econf:url();
 mod_opt_type(top_link) ->
     econf:and_then(
       econf:non_empty(
@@ -965,7 +980,7 @@ mod_opt_type(top_link) ->
                                {atom(), any()}].
 mod_options(_) ->
     [{access_log, muc_admin},
-     {cssfile, filename:join(misc:css_dir(), <<"muc.css">>)},
+     {cssfile, {file, filename:join(misc:css_dir(), <<"muc.css">>)}},
      {dirname, room_jid},
      {dirtype, subdirs},
      {file_format, html},
@@ -973,4 +988,5 @@ mod_options(_) ->
      {outdir, <<"www/muc">>},
      {spam_prevention, true},
      {timezone, local},
+     {url, undefined},
      {top_link, {<<"/">>, <<"Home">>}}].
index 1fbad70c130312cd3720d5c33abc77efc853f786..fb4d0266fb208c2bd49ec6bb72f7a5be78a5ff06 100644 (file)
@@ -13,6 +13,7 @@
 -export([spam_prevention/1]).
 -export([timezone/1]).
 -export([top_link/1]).
+-export([url/1]).
 
 -spec access_log(gen_mod:opts() | global | binary()) -> 'muc_admin' | acl:acl().
 access_log(Opts) when is_map(Opts) ->
@@ -74,3 +75,9 @@ top_link(Opts) when is_map(Opts) ->
 top_link(Host) ->
     gen_mod:get_module_opt(Host, mod_muc_log, top_link).
 
+-spec url(gen_mod:opts() | global | binary()) -> 'undefined' | binary().
+url(Opts) when is_map(Opts) ->
+    gen_mod:get_opt(url, Opts);
+url(Host) ->
+    gen_mod:get_module_opt(Host, mod_muc_log, url).
+
index ff1a818453a5010d30420a855e29cbfadad926fa..ea2b069d7ffdac0ae94ab891c8b65f394f175b5e 100644 (file)
@@ -4113,8 +4113,19 @@ iq_disco_info_extras(Lang, StateData, Static) ->
              true ->
                  Fs2
          end,
+    Fs4 = case Config#config.logging of
+             true ->
+                 case mod_muc_log:get_url(StateData) of
+                     {ok, URL} ->
+                         [{logs, URL}|Fs3];
+                     error ->
+                         Fs3
+                 end;
+             false ->
+                 Fs3
+         end,
     #xdata{type = result,
-          fields = muc_roominfo:encode(Fs3, Lang)}.
+          fields = muc_roominfo:encode(Fs4, Lang)}.
 
 -spec process_iq_disco_items(jid(), iq(), state()) ->
                                    {error, stanza_error()} | {result, disco_items()}.