From 0f9db50c8d9fb15a062c5ccea47e5aa709a961b5 Mon Sep 17 00:00:00 2001 From: Evgeniy Khramtsov Date: Wed, 30 May 2018 08:11:58 +0300 Subject: [PATCH] Support for roomconfig_lang/roominfo_lang 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 | 3 ++- src/mod_muc.erl | 5 ++++- src/mod_muc_room.erl | 11 +++++++++-- 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/include/mod_muc_room.hrl b/include/mod_muc_room.hrl index b224192c8..5966a6e09 100644 --- a/include/mod_muc_room.hrl +++ b/include/mod_muc_room.hrl @@ -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{}. diff --git a/src/mod_muc.erl b/src/mod_muc.erl index 5a52c9bdd..6cfeb55d5 100644 --- a/src/mod_muc.erl +++ b/src/mod_muc.erl @@ -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}, diff --git a/src/mod_muc_room.erl b/src/mod_muc_room.erl index cf065ba44..4f7070741 100644 --- a/src/mod_muc_room.erl +++ b/src/mod_muc_room.erl @@ -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];