]> granicus.if.org Git - ejabberd/commitdiff
Support for roomconfig_lang/roominfo_lang
authorEvgeniy Khramtsov <ekhramtsov@process-one.net>
Wed, 30 May 2018 05:11:58 +0000 (08:11 +0300)
committerEvgeniy Khramtsov <ekhramtsov@process-one.net>
Wed, 30 May 2018 05:11:58 +0000 (08:11 +0300)
Now room owners are able to set a preferred language
for the discussions in the room, so other users can
discover rooms based on the language they wish to talk.

TODO: the language format should conform to RFC 5646.
      This check should be implemented in 'xmpp' library.

Fixes #2436

include/mod_muc_room.hrl
src/mod_muc.erl
src/mod_muc_room.erl

index b224192c8f7736dfabbcef128ff903eed0a7100d..5966a6e09fe3a7bb31d614de7a3a974d3aeb06a0 100644 (file)
@@ -66,7 +66,8 @@
     vcard_xupdate                        = undefined :: undefined | external | binary(),
     captcha_whitelist                    = (?SETS):empty() :: ?TGB_SET,
     mam                                  = false :: boolean(),
-    pubsub                               = <<"">> :: binary()
+    pubsub                               = <<"">> :: binary(),
+    lang                                 = ?MYLANG :: binary()
 }).
 
 -type config() :: #config{}.
index 5a52c9bdddbabdea0c48cee7101b38518b543cac..6cfeb55d5bfbbd656f41f534fd0e97f9aabc4315 100644 (file)
@@ -976,7 +976,9 @@ mod_opt_type({default_room_options, presence_broadcast}) ->
                 (participant) -> participant;
                 (visitor) -> visitor
              end, L)
-    end.
+    end;
+mod_opt_type({default_room_options, lang}) ->
+    fun iolist_to_binary/1.
 
 mod_options(Host) ->
     [{access, all},
@@ -1014,6 +1016,7 @@ mod_options(Host) ->
        {allow_visitor_status,true},
        {anonymous,true},
        {captcha_protected,false},
+       {lang, ?MYLANG},
        {logging,false},
        {members_by_default,true},
        {members_only,false},
index cf065ba44f687cb913aa8af9e6796970600f2fa2..4f707074183ecc9a17ebc5f8884b3cb53e4ad641 100644 (file)
@@ -3277,7 +3277,8 @@ get_config(Lang, StateData, From) ->
              translate:translate(Lang, <<"Configuration of room ~s">>),
              [jid:encode(StateData#state.jid)]),
     Fs = [{roomname, Config#config.title},
-         {roomdesc, Config#config.description}] ++
+         {roomdesc, Config#config.description},
+         {lang, Config#config.lang}] ++
        case acl:match_rule(StateData#state.server_host, AccessPersistent, From) of
            allow -> [{persistentroom, Config#config.persistent}];
            deny -> []
@@ -3399,6 +3400,7 @@ set_config(Opts, Config, ServerHost, Lang) ->
         ({maxusers, V}, C) -> C#config{max_users = V};
         ({enablelogging, V}, C) -> C#config{logging = V};
         ({pubsub, V}, C) -> C#config{pubsub = V};
+        ({lang, L}, C) -> C#config{lang = L};
         ({captcha_whitelist, Js}, C) ->
              LJIDs = [jid:tolower(J) || J <- Js],
              C#config{captcha_whitelist = ?SETS:from_list(LJIDs)};
@@ -3630,6 +3632,9 @@ set_opts([{Opt, Val} | Opts], StateData) ->
            allow_subscription ->
                StateData#state{config =
                                    (StateData#state.config)#config{allow_subscription = Val}};
+           lang ->
+               StateData#state{config =
+                                   (StateData#state.config)#config{lang = Val}};
            subscribers ->
                  {Subscribers, Nicks} =
                      lists:foldl(
@@ -3709,6 +3714,7 @@ make_opts(StateData) ->
      ?MAKE_CONFIG_OPT(#config.vcard),
      ?MAKE_CONFIG_OPT(#config.vcard_xupdate),
      ?MAKE_CONFIG_OPT(#config.pubsub),
+     ?MAKE_CONFIG_OPT(#config.lang),
      {captcha_whitelist,
       (?SETS):to_list((StateData#state.config)#config.captcha_whitelist)},
      {affiliations,
@@ -3841,7 +3847,8 @@ process_iq_disco_info(From, #iq{type = get, lang = Lang,
 iq_disco_info_extras(Lang, StateData) ->
     Fs1 = [{description, (StateData#state.config)#config.description},
           {occupants, ?DICT:size(StateData#state.nicks)},
-          {contactjid, get_owners(StateData)}],
+          {contactjid, get_owners(StateData)},
+          {lang, (StateData#state.config)#config.lang}],
     Fs2 = case (StateData#state.config)#config.pubsub of
              Node when is_binary(Node), Node /= <<"">> ->
                  [{pubsub, Node}|Fs1];