From b49252af546cb42862b36e0a72af8e1ad9f5bd77 Mon Sep 17 00:00:00 2001 From: Mikhail Uvarov Date: Mon, 22 Aug 2022 18:41:29 +0200 Subject: [PATCH 1/8] Define RoomConfigDictEntry --- big_tests/tests/graphql_muc_light_SUITE.erl | 3 +++ priv/graphql/schemas/admin/muc_light.gql | 3 +++ priv/graphql/schemas/global/muc_light.gql | 15 +++++++++++++++ priv/graphql/schemas/user/muc_light.gql | 2 ++ 4 files changed, 23 insertions(+) diff --git a/big_tests/tests/graphql_muc_light_SUITE.erl b/big_tests/tests/graphql_muc_light_SUITE.erl index 1fd3f9a73b..6e7712d0b5 100644 --- a/big_tests/tests/graphql_muc_light_SUITE.erl +++ b/big_tests/tests/graphql_muc_light_SUITE.erl @@ -430,6 +430,7 @@ user_get_room_config_story(Config, Alice, Bob) -> Res = user_get_room_config(Alice, jid:to_binary(RoomJID), Config), % Owner can get a config ?assertEqual(#{<<"jid">> => RoomJIDBin, <<"subject">> => RoomSubject, <<"name">> => RoomName, + <<"options">> => null, <<"participants">> => [#{<<"jid">> => AliceLower, <<"affiliation">> => <<"OWNER">>}]}, get_ok_value(?GET_ROOM_CONFIG_PATH, Res)), @@ -446,6 +447,7 @@ user_get_room_config_story(Config, Alice, Bob) -> {ok, _} = invite_user(RoomJID, AliceBin, BobBin), Res5 = user_get_room_config(Bob, jid:to_binary(RoomJID), Config), ?assertEqual(#{<<"jid">> => RoomJIDBin, <<"subject">> => RoomSubject, <<"name">> => RoomName, + <<"options">> => null, <<"participants">> => [#{<<"jid">> => AliceLower, <<"affiliation">> => <<"OWNER">>}, #{<<"jid">> => BobLower, @@ -803,6 +805,7 @@ admin_get_room_config_story(Config, Alice) -> RoomJIDBin = jid:to_binary(RoomJID), Res = get_room_config(jid:to_binary(RoomJID), Config), ?assertEqual(#{<<"jid">> => RoomJIDBin, <<"subject">> => RoomSubject, <<"name">> => RoomName, + <<"options">> => null, <<"participants">> => [#{<<"jid">> => AliceLower, <<"affiliation">> => <<"OWNER">>}]}, get_ok_value([data, muc_light, getRoomConfig], Res)), diff --git a/priv/graphql/schemas/admin/muc_light.gql b/priv/graphql/schemas/admin/muc_light.gql index 08cfc21317..e09c20c01e 100644 --- a/priv/graphql/schemas/admin/muc_light.gql +++ b/priv/graphql/schemas/admin/muc_light.gql @@ -8,6 +8,9 @@ type MUCLightAdminMutation @protected{ "Change configuration of a MUC Light room" changeRoomConfiguration(room: JID!, owner: JID!, name: String!, subject: String!): Room @protected(type: DOMAIN, args: ["room"]) + "Update configuration of a MUC Light room" + updateRoomConfiguration(room: JID!, owner: JID!, options: [RoomConfigDictEntryInput!]!): Room + @protected(type: DOMAIN, args: ["room"]) "Invite a user to a MUC Light room" inviteUser(room: JID!, sender: JID!, recipient: JID!): String @protected(type: DOMAIN, args: ["sender"]) diff --git a/priv/graphql/schemas/global/muc_light.gql b/priv/graphql/schemas/global/muc_light.gql index d60f50ef6c..cdac57ba84 100644 --- a/priv/graphql/schemas/global/muc_light.gql +++ b/priv/graphql/schemas/global/muc_light.gql @@ -26,11 +26,26 @@ enum BlockedEntityType{ ROOM } +input RoomConfigDictEntryInput{ + "The name of the config option" + key: String! + "Config option value" + value: String! +} + +type RoomConfigDictEntry{ + "The name of the config option" + key: String! + "Config option value" + value: String! +} + type Room{ jid: JID! name: String! subject: String! participants: [RoomUser!]! + options: [RoomConfigDictEntry] } type RoomUser{ diff --git a/priv/graphql/schemas/user/muc_light.gql b/priv/graphql/schemas/user/muc_light.gql index f2f335a7fb..58991239bb 100644 --- a/priv/graphql/schemas/user/muc_light.gql +++ b/priv/graphql/schemas/user/muc_light.gql @@ -6,6 +6,8 @@ type MUCLightUserMutation @protected{ createRoom(mucDomain: String!, name: String!, subject: String!, id: NonEmptyString): Room "Change configuration of a MUC Light room" changeRoomConfiguration(room: JID!, name: String!, subject: String!): Room + "Update configuration of a MUC Light room" + updateRoomConfiguration(room: JID!, options: [RoomConfigDictEntryInput!]!): Room "Invite a user to a MUC Light room" inviteUser(room: JID!, recipient: JID!): String "Remove a MUC Light room" From b5c9191c35058d5557edeeed2f3f155059b82a5c Mon Sep 17 00:00:00 2001 From: Mikhail Uvarov Date: Tue, 23 Aug 2022 00:00:11 +0200 Subject: [PATCH 2/8] Return all opts --- big_tests/tests/graphql_muc_light_SUITE.erl | 9 +++-- ...goose_graphql_muc_light_admin_mutation.erl | 3 +- .../mongoose_graphql_muc_light_helper.erl | 7 ++-- ...ngoose_graphql_muc_light_user_mutation.erl | 3 +- .../mongoose_client_api_rooms_config.erl | 3 +- src/muc_light/mod_muc_light_api.erl | 36 ++++++++++++------- src/muc_light/mod_muc_light_commands.erl | 3 +- 7 files changed, 42 insertions(+), 22 deletions(-) diff --git a/big_tests/tests/graphql_muc_light_SUITE.erl b/big_tests/tests/graphql_muc_light_SUITE.erl index 6e7712d0b5..d8e8cef04e 100644 --- a/big_tests/tests/graphql_muc_light_SUITE.erl +++ b/big_tests/tests/graphql_muc_light_SUITE.erl @@ -430,7 +430,8 @@ user_get_room_config_story(Config, Alice, Bob) -> Res = user_get_room_config(Alice, jid:to_binary(RoomJID), Config), % Owner can get a config ?assertEqual(#{<<"jid">> => RoomJIDBin, <<"subject">> => RoomSubject, <<"name">> => RoomName, - <<"options">> => null, + <<"options">> => [#{<<"key">> => <<"roomname">>, <<"value">> => RoomName}, + #{<<"key">> => <<"subject">>, <<"value">> => RoomSubject}], <<"participants">> => [#{<<"jid">> => AliceLower, <<"affiliation">> => <<"OWNER">>}]}, get_ok_value(?GET_ROOM_CONFIG_PATH, Res)), @@ -447,7 +448,8 @@ user_get_room_config_story(Config, Alice, Bob) -> {ok, _} = invite_user(RoomJID, AliceBin, BobBin), Res5 = user_get_room_config(Bob, jid:to_binary(RoomJID), Config), ?assertEqual(#{<<"jid">> => RoomJIDBin, <<"subject">> => RoomSubject, <<"name">> => RoomName, - <<"options">> => null, + <<"options">> => [#{<<"key">> => <<"roomname">>, <<"value">> => RoomName}, + #{<<"key">> => <<"subject">>, <<"value">> => RoomSubject}], <<"participants">> => [#{<<"jid">> => AliceLower, <<"affiliation">> => <<"OWNER">>}, #{<<"jid">> => BobLower, @@ -805,7 +807,8 @@ admin_get_room_config_story(Config, Alice) -> RoomJIDBin = jid:to_binary(RoomJID), Res = get_room_config(jid:to_binary(RoomJID), Config), ?assertEqual(#{<<"jid">> => RoomJIDBin, <<"subject">> => RoomSubject, <<"name">> => RoomName, - <<"options">> => null, + <<"options">> => [#{<<"key">> => <<"roomname">>, <<"value">> => RoomName}, + #{<<"key">> => <<"subject">>, <<"value">> => RoomSubject}], <<"participants">> => [#{<<"jid">> => AliceLower, <<"affiliation">> => <<"OWNER">>}]}, get_ok_value([data, muc_light, getRoomConfig], Res)), diff --git a/src/graphql/admin/mongoose_graphql_muc_light_admin_mutation.erl b/src/graphql/admin/mongoose_graphql_muc_light_admin_mutation.erl index 1ef0d18b6d..fb472dd850 100644 --- a/src/graphql/admin/mongoose_graphql_muc_light_admin_mutation.erl +++ b/src/graphql/admin/mongoose_graphql_muc_light_admin_mutation.erl @@ -47,7 +47,8 @@ create_room(#{<<"id">> := RoomID, <<"mucDomain">> := MUCDomain, <<"name">> := Ro -spec change_room_config(map()) -> {ok, map()} | {error, resolver_error()}. change_room_config(#{<<"room">> := RoomJID, <<"name">> := RoomName, <<"owner">> := OwnerJID, <<"subject">> := Subject}) -> - case mod_muc_light_api:change_room_config(RoomJID, OwnerJID, RoomName, Subject) of + Config = #{<<"roomname">> => RoomName, <<"subject">> => Subject}, + case mod_muc_light_api:change_room_config(RoomJID, OwnerJID, Config) of {ok, Room} -> {ok, make_room(Room)}; Err -> diff --git a/src/graphql/mongoose_graphql_muc_light_helper.erl b/src/graphql/mongoose_graphql_muc_light_helper.erl index 84503f98c5..ad43fb8846 100644 --- a/src/graphql/mongoose_graphql_muc_light_helper.erl +++ b/src/graphql/mongoose_graphql_muc_light_helper.erl @@ -12,10 +12,10 @@ page_size_or_max_limit(PageSize, _MaxLimit) -> PageSize. -spec make_room(mod_muc_light_api:room()) -> map(). -make_room(#{jid := JID, name := Name, subject := Subject, aff_users := Users}) -> +make_room(#{jid := JID, name := Name, subject := Subject, aff_users := Users, options := Options}) -> Participants = lists:map(fun make_ok_user/1, Users), #{<<"jid">> => JID, <<"name">> => Name, <<"subject">> => Subject, - <<"participants">> => Participants}. + <<"participants">> => Participants, <<"options">> => make_options(Options)}. make_ok_user({JID, Aff}) -> {ok, #{<<"jid">> => JID, <<"affiliation">> => Aff}}. @@ -26,3 +26,6 @@ prepare_blocking_items(Items) -> blocking_item_to_map({What, Action, Who}) -> {ok, #{<<"entityType">> => What, <<"action">> => Action, <<"entity">> => Who}}. + +make_options(Options) -> + [{ok, #{<<"key">> => K, <<"value">> => V}} || {K, V} <- lists:sort(maps:to_list(Options))]. diff --git a/src/graphql/user/mongoose_graphql_muc_light_user_mutation.erl b/src/graphql/user/mongoose_graphql_muc_light_user_mutation.erl index abe532d632..ffa60e8782 100644 --- a/src/graphql/user/mongoose_graphql_muc_light_user_mutation.erl +++ b/src/graphql/user/mongoose_graphql_muc_light_user_mutation.erl @@ -46,7 +46,8 @@ create_room(#{user := UserJID}, #{<<"id">> := RoomID, <<"mucDomain">> := MUCDoma -spec change_room_config(map(), map()) -> {ok, map()} | {error, resolver_error()}. change_room_config(#{user := UserJID}, #{<<"room">> := RoomJID, <<"name">> := RoomName, <<"subject">> := Subject}) -> - case mod_muc_light_api:change_room_config(RoomJID, UserJID, RoomName, Subject) of + Config = #{<<"roomname">> => RoomName, <<"subject">> => Subject}, + case mod_muc_light_api:change_room_config(RoomJID, UserJID, Config) of {ok, Room} -> {ok, make_room(Room)}; Err -> diff --git a/src/mongoose_client_api/mongoose_client_api_rooms_config.erl b/src/mongoose_client_api/mongoose_client_api_rooms_config.erl index c9ec9df185..5a062876c2 100644 --- a/src/mongoose_client_api/mongoose_client_api_rooms_config.erl +++ b/src/mongoose_client_api/mongoose_client_api_rooms_config.erl @@ -67,4 +67,5 @@ handle_request_by_method(<<"PUT">>, Req, State) -> mongoose_client_api_rooms:assert_room_id_set(Req, State), #{jid := UserJID, room := #{jid := RoomJID}} = State, - mod_muc_light_api:change_room_config(RoomJID, UserJID, RoomName, Subject). + Config = #{<<"roomname">> => RoomName, <<"subject">> => Subject}, + mod_muc_light_api:change_room_config(RoomJID, UserJID, Config). diff --git a/src/muc_light/mod_muc_light_api.erl b/src/muc_light/mod_muc_light_api.erl index 89466cbbc1..745288bb7e 100644 --- a/src/muc_light/mod_muc_light_api.erl +++ b/src/muc_light/mod_muc_light_api.erl @@ -4,7 +4,7 @@ -export([create_room/4, create_room/5, invite_to_room/3, - change_room_config/4, + change_room_config/3, change_affiliation/4, remove_user_from_room/3, send_message/3, @@ -80,21 +80,20 @@ invite_to_room(#jid{lserver = MUCServer} = RoomJID, SenderJID, RecipientJID) -> end. --spec change_room_config(jid:jid(), jid:jid(), binary(), binary()) -> +-spec change_room_config(jid:jid(), jid:jid(), map()) -> {ok, room()} | {not_room_member | not_allowed | room_not_found | validation_error | muc_server_not_found, iolist()}. change_room_config(#jid{luser = RoomID, lserver = MUCServer} = RoomJID, - UserJID, RoomName, Subject) -> + UserJID, Config) -> case mongoose_domain_api:get_subdomain_info(MUCServer) of {ok, #{host_type := HostType, parent_domain := LServer}} -> UserUS = jid:to_bare(UserJID), - ConfigReq = #config{ raw_config = - [{<<"roomname">>, RoomName}, {<<"subject">>, Subject}]}, + ConfigReq = #config{ raw_config = maps:to_list(Config) }, Acc = mongoose_acc:new(#{location => ?LOCATION, lserver => LServer, host_type => HostType}), case mod_muc_light:change_room_config(UserUS, RoomID, MUCServer, ConfigReq, Acc) of - {ok, RoomJID, _} -> - {ok, make_room(RoomJID, RoomName, Subject, [])}; + {ok, RoomJID, KV} -> + {ok, make_room(RoomJID, KV, [])}; {error, item_not_found} -> ?USER_NOT_ROOM_MEMBER_RESULT; {error, not_allowed} -> @@ -255,8 +254,8 @@ get_room_info(#jid{lserver = MUCServer} = RoomJID) -> case mongoose_domain_api:get_subdomain_host_type(MUCServer) of {ok, HostType} -> case mod_muc_light_db_backend:get_info(HostType, jid:to_lus(RoomJID)) of - {ok, [{roomname, Name}, {subject, Subject}], AffUsers, _Version} -> - {ok, make_room(jid:to_binary(RoomJID), Name, Subject, AffUsers)}; + {ok, Conf, AffUsers, _Version} -> + {ok, make_room(jid:to_binary(RoomJID), Conf, AffUsers)}; {error, not_exists} -> ?ROOM_NOT_FOUND_RESULT end; @@ -335,8 +334,8 @@ set_blocking(#jid{lserver = LServer} = User, Items) -> create_room_raw(InRoomJID, CreatorJID, RoomTitle, Subject) -> Config = make_room_config(RoomTitle, Subject), try mod_muc_light:try_to_create_room(CreatorJID, InRoomJID, Config) of - {ok, RoomJID, #create{aff_users = AffUsers}} -> - {ok, make_room(RoomJID, RoomTitle, Subject, AffUsers)}; + {ok, RoomJID, #create{aff_users = AffUsers, raw_config = Conf}} -> + {ok, make_room(RoomJID, Conf, AffUsers)}; {error, exists} -> {already_exist, "Room already exists"}; {error, max_occupants_reached} -> @@ -390,8 +389,19 @@ is_user_room_member(HostType, UserUS, {_, MUCServer} = RoomLUS) -> lists:any(fun(LUS) -> LUS =:= RoomLUS end, RoomJIDs) end. -make_room(JID, Name, Subject, AffUsers) -> - #{jid => JID, name => Name, subject => Subject, aff_users => AffUsers}. + +make_room(JID, #config{ raw_config = Options}, AffUsers) -> + make_room(JID, Options, AffUsers); +make_room(JID, Options, AffUsers) when is_list(Options) -> + make_room(JID, maps:from_list(ensure_keys_are_binaries(Options)), AffUsers); +make_room(JID, Options, AffUsers) when is_map(Options) -> + #{<<"roomname">> := Name, <<"subject">> := Subject} = Options, + #{jid => JID, name => Name, subject => Subject, aff_users => AffUsers, options => Options}. + +ensure_keys_are_binaries([{K, _}|_] = Conf) when is_binary(K) -> + Conf; +ensure_keys_are_binaries(Conf) -> + [{atom_to_binary(K), V} || {K, V} <- Conf]. iq(To, From, Type, Children) -> UUID = uuid:uuid_to_string(uuid:get_v4(), binary_standard), diff --git a/src/muc_light/mod_muc_light_commands.erl b/src/muc_light/mod_muc_light_commands.erl index 7303e97e48..f0ad029ae3 100644 --- a/src/muc_light/mod_muc_light_commands.erl +++ b/src/muc_light/mod_muc_light_commands.erl @@ -192,7 +192,8 @@ invite_to_room(MUCServer, RoomID, Sender, Recipient) -> change_room_config(MUCServer, RoomID, RoomName, User, Subject) -> UserJID = jid:from_binary(User), RoomJID = jid:make_bare(RoomID, MUCServer), - Result = mod_muc_light_api:change_room_config(RoomJID, UserJID, RoomName, Subject), + Config = #{<<"roomname">> => RoomName, <<"subject">> => Subject}, + Result = mod_muc_light_api:change_room_config(RoomJID, UserJID, Config), format_result_no_msg(Result). -spec send_message(jid:server(), jid:user(), jid:literal_jid(), jid:literal_jid()) -> From c64785ade43bd358f33dcd2f403096f28fd39c98 Mon Sep 17 00:00:00 2001 From: Mikhail Uvarov Date: Thu, 25 Aug 2022 13:11:22 +0200 Subject: [PATCH 3/8] Test getting custom fields in graphql_muc_light_SUITE --- big_tests/tests/graphql_muc_light_SUITE.erl | 23 +++++++++++++++++---- src/muc_light/mod_muc_light_api.erl | 22 +++++++++----------- 2 files changed, 29 insertions(+), 16 deletions(-) diff --git a/big_tests/tests/graphql_muc_light_SUITE.erl b/big_tests/tests/graphql_muc_light_SUITE.erl index d8e8cef04e..a489688151 100644 --- a/big_tests/tests/graphql_muc_light_SUITE.erl +++ b/big_tests/tests/graphql_muc_light_SUITE.erl @@ -100,9 +100,18 @@ init_modules(Config) -> Config2. required_modules(_) -> - MucLightOpts = mod_config(mod_muc_light, #{rooms_in_rosters => true}), + MucLightOpts = mod_config(mod_muc_light, #{rooms_in_rosters => true, + config_schema => custom_schema()}), [{mod_muc_light, MucLightOpts}]. +custom_schema() -> + %% Should be sorted + [{<<"background">>, <<>>, background, binary}, + {<<"music">>, <<>>, music, binary}, + %% Default fields + {<<"roomname">>, <<>>, roomname, binary}, + {<<"subject">>, <<>>, subject, binary}]. + init_per_group(admin_muc_light_http, Config) -> graphql_helper:init_admin_handler(Config); init_per_group(admin_muc_light_cli, Config) -> @@ -430,7 +439,9 @@ user_get_room_config_story(Config, Alice, Bob) -> Res = user_get_room_config(Alice, jid:to_binary(RoomJID), Config), % Owner can get a config ?assertEqual(#{<<"jid">> => RoomJIDBin, <<"subject">> => RoomSubject, <<"name">> => RoomName, - <<"options">> => [#{<<"key">> => <<"roomname">>, <<"value">> => RoomName}, + <<"options">> => [#{<<"key">> => <<"background">>, <<"value">> => <<>>}, + #{<<"key">> => <<"music">>, <<"value">> => <<>>}, + #{<<"key">> => <<"roomname">>, <<"value">> => RoomName}, #{<<"key">> => <<"subject">>, <<"value">> => RoomSubject}], <<"participants">> => [#{<<"jid">> => AliceLower, <<"affiliation">> => <<"OWNER">>}]}, @@ -448,7 +459,9 @@ user_get_room_config_story(Config, Alice, Bob) -> {ok, _} = invite_user(RoomJID, AliceBin, BobBin), Res5 = user_get_room_config(Bob, jid:to_binary(RoomJID), Config), ?assertEqual(#{<<"jid">> => RoomJIDBin, <<"subject">> => RoomSubject, <<"name">> => RoomName, - <<"options">> => [#{<<"key">> => <<"roomname">>, <<"value">> => RoomName}, + <<"options">> => [#{<<"key">> => <<"background">>, <<"value">> => <<>>}, + #{<<"key">> => <<"music">>, <<"value">> => <<>>}, + #{<<"key">> => <<"roomname">>, <<"value">> => RoomName}, #{<<"key">> => <<"subject">>, <<"value">> => RoomSubject}], <<"participants">> => [#{<<"jid">> => AliceLower, <<"affiliation">> => <<"OWNER">>}, @@ -807,7 +820,9 @@ admin_get_room_config_story(Config, Alice) -> RoomJIDBin = jid:to_binary(RoomJID), Res = get_room_config(jid:to_binary(RoomJID), Config), ?assertEqual(#{<<"jid">> => RoomJIDBin, <<"subject">> => RoomSubject, <<"name">> => RoomName, - <<"options">> => [#{<<"key">> => <<"roomname">>, <<"value">> => RoomName}, + <<"options">> => [#{<<"key">> => <<"background">>, <<"value">> => <<>>}, + #{<<"key">> => <<"music">>, <<"value">> => <<>>}, + #{<<"key">> => <<"roomname">>, <<"value">> => RoomName}, #{<<"key">> => <<"subject">>, <<"value">> => RoomSubject}], <<"participants">> => [#{<<"jid">> => AliceLower, <<"affiliation">> => <<"OWNER">>}]}, diff --git a/src/muc_light/mod_muc_light_api.erl b/src/muc_light/mod_muc_light_api.erl index 745288bb7e..0f53b16280 100644 --- a/src/muc_light/mod_muc_light_api.erl +++ b/src/muc_light/mod_muc_light_api.erl @@ -47,15 +47,15 @@ [Key, Reason])}). -spec create_room(jid:lserver(), jid:jid(), binary(), binary()) -> create_room_result(). - create_room(MUCLightDomain, CreatorJID, RoomTitle, Subject) -> - RoomJID = jid:make_bare(<<>>, MUCLightDomain), - create_room_raw(RoomJID, CreatorJID, RoomTitle, Subject). +create_room(MUCLightDomain, CreatorJID, RoomTitle, Subject) -> + create_room(MUCLightDomain, <<>>, CreatorJID, RoomTitle, Subject). -spec create_room(jid:lserver(), jid:luser(), jid:jid(), binary(), binary()) -> create_room_result(). create_room(MUCLightDomain, RoomID, CreatorJID, RoomTitle, Subject) -> RoomJID = jid:make_bare(RoomID, MUCLightDomain), - create_room_raw(RoomJID, CreatorJID, RoomTitle, Subject). + Options = #{<<"roomname">> => RoomTitle, <<"subject">> => Subject}, + create_room_raw(RoomJID, CreatorJID, Options). -spec invite_to_room(jid:jid(), jid:jid(), jid:jid()) -> {ok | not_room_member | muc_server_not_found, iolist()}. @@ -330,9 +330,9 @@ set_blocking(#jid{lserver = LServer} = User, Items) -> %% Internal --spec create_room_raw(jid:jid(), jid:jid(), binary(), binary()) -> create_room_result(). -create_room_raw(InRoomJID, CreatorJID, RoomTitle, Subject) -> - Config = make_room_config(RoomTitle, Subject), +-spec create_room_raw(jid:jid(), jid:jid(), map()) -> create_room_result(). +create_room_raw(InRoomJID, CreatorJID, Options) -> + Config = make_room_config(Options), try mod_muc_light:try_to_create_room(CreatorJID, InRoomJID, Config) of {ok, RoomJID, #create{aff_users = AffUsers, raw_config = Conf}} -> {ok, make_room(RoomJID, Conf, AffUsers)}; @@ -354,11 +354,9 @@ blocking_item({What, Action, Who}) -> children = [#xmlcdata{ content = jid:to_binary(Who)}] }. --spec make_room_config(binary(), binary()) -> create_req_props(). -make_room_config(Name, Subject) -> - #create{raw_config = [{<<"roomname">>, Name}, - {<<"subject">>, Subject}] - }. +-spec make_room_config(map()) -> create_req_props(). +make_room_config(Options) -> + #create{raw_config = maps:to_list(Options)}. -spec get_room_user_aff(mongooseim:host_type(), jid:jid(), jid:jid()) -> {ok, aff()} | {error, room_not_found}. From 9df97446e262ca5c509777997e09d0d32290eb40 Mon Sep 17 00:00:00 2001 From: Mikhail Uvarov Date: Mon, 29 Aug 2022 09:44:14 +0200 Subject: [PATCH 4/8] Add a test to create rooms with custom options --- big_tests/tests/graphql_muc_light_SUITE.erl | 27 +++++++++++++++++++ priv/graphql/schemas/admin/muc_light.gql | 7 ++--- priv/graphql/schemas/user/muc_light.gql | 6 ++--- ...goose_graphql_muc_light_admin_mutation.erl | 16 ++++------- .../mongoose_graphql_muc_light_helper.erl | 13 ++++++++- ...ngoose_graphql_muc_light_user_mutation.erl | 24 +++++------------ src/muc_light/mod_muc_light_api.erl | 8 ++++-- 7 files changed, 60 insertions(+), 41 deletions(-) diff --git a/big_tests/tests/graphql_muc_light_SUITE.erl b/big_tests/tests/graphql_muc_light_SUITE.erl index a489688151..89ac8d6a90 100644 --- a/big_tests/tests/graphql_muc_light_SUITE.erl +++ b/big_tests/tests/graphql_muc_light_SUITE.erl @@ -47,6 +47,7 @@ groups() -> user_muc_light_tests() -> [user_create_room, + user_create_room_with_custom_fields, user_create_identified_room, user_change_room_config, user_change_room_config_errors, @@ -148,6 +149,24 @@ user_create_room_story(Config, Alice) -> Res2 = user_create_room(Alice, ?UNKNOWN_DOMAIN, Name, Subject, null, Config), ?assertNotEqual(nomatch, binary:match(get_err_msg(Res2), <<"not found">>)). +user_create_room_with_custom_fields(Config) -> + escalus:fresh_story_with_config(Config, [{alice, 1}], fun user_create_room_with_custom_fields_story/2). + +user_create_room_with_custom_fields_story(Config, Alice) -> + MucServer = ?config(muc_light_host, Config), + AliceBinLower = escalus_utils:jid_to_lower(escalus_client:short_jid(Alice)), + Name = <<"room with custom fields">>, + Subject = <<"testing_custom">>, + Opts = [#{<<"key">> => <<"background">>, <<"value">> => <<"red">>}, + #{<<"key">> => <<"roomname">>, <<"value">> => Name}, + #{<<"key">> => <<"subject">>, <<"value">> => Subject}], + Res = user_create_room_with_options(Alice, MucServer, Name, Subject, null, #{<<"background">> => <<"red">>}, Config), + #{<<"jid">> := JID, <<"name">> := Name, <<"subject">> := Subject, + <<"participants">> := Participants, <<"options">> := Opts} + = get_ok_value(?CREATE_ROOM_PATH, Res), + ?assertMatch(#jid{lserver = MucServer}, jid:from_binary(JID)), + ?assertEqual([#{<<"jid">> => AliceBinLower, <<"affiliation">> => <<"OWNER">>}], Participants). + user_create_identified_room(Config) -> escalus:fresh_story_with_config(Config, [{alice, 1}], fun user_create_identified_room_story/2). @@ -926,10 +945,18 @@ user_create_room(User, MUCDomain, Name, Subject, Id, Config) -> <<"id">> => Id}, execute_user_command(<<"muc_light">>, <<"createRoom">>, User, Vars, Config). +user_create_room_with_options(User, MUCDomain, Name, Subject, Id, CustomFields, Config) -> + Vars = #{<<"mucDomain">> => MUCDomain, <<"name">> => Name, <<"subject">> => Subject, + <<"id">> => Id, <<"options">> => format_options(CustomFields)}, + execute_user_command(<<"muc_light">>, <<"createRoom">>, User, Vars, Config). + user_change_room_configuration(User, RoomJID, Name, Subject, Config) -> Vars = #{<<"room">> => RoomJID, <<"name">> => Name, <<"subject">> => Subject}, execute_user_command(<<"muc_light">>, <<"changeRoomConfiguration">>, User, Vars, Config). +format_options(Map) -> + [#{<<"key">> => K, <<"value">> => V} || {K, V} <- maps:to_list(Map)]. + user_invite_user(User, RoomJID, Recipient, Config) -> Vars = #{<<"room">> => RoomJID, <<"recipient">> => Recipient}, execute_user_command(<<"muc_light">>, <<"inviteUser">>, User, Vars, Config). diff --git a/priv/graphql/schemas/admin/muc_light.gql b/priv/graphql/schemas/admin/muc_light.gql index e09c20c01e..37b5cd8fa2 100644 --- a/priv/graphql/schemas/admin/muc_light.gql +++ b/priv/graphql/schemas/admin/muc_light.gql @@ -3,13 +3,10 @@ Allow admin to manage Multi-User Chat Light rooms. """ type MUCLightAdminMutation @protected{ "Create a MUC light room under the given XMPP hostname" - createRoom(mucDomain: String!, name: String!, owner: JID!, subject: String!, id: NonEmptyString): Room + createRoom(mucDomain: String!, name: String!, owner: JID!, subject: String!, id: NonEmptyString, options: [RoomConfigDictEntryInput!]): Room @protected(type: DOMAIN, args: ["owner"]) "Change configuration of a MUC Light room" - changeRoomConfiguration(room: JID!, owner: JID!, name: String!, subject: String!): Room - @protected(type: DOMAIN, args: ["room"]) - "Update configuration of a MUC Light room" - updateRoomConfiguration(room: JID!, owner: JID!, options: [RoomConfigDictEntryInput!]!): Room + changeRoomConfiguration(room: JID!, owner: JID!, name: String!, subject: String!, options: [RoomConfigDictEntryInput!]): Room @protected(type: DOMAIN, args: ["room"]) "Invite a user to a MUC Light room" inviteUser(room: JID!, sender: JID!, recipient: JID!): String diff --git a/priv/graphql/schemas/user/muc_light.gql b/priv/graphql/schemas/user/muc_light.gql index 58991239bb..89f74b062b 100644 --- a/priv/graphql/schemas/user/muc_light.gql +++ b/priv/graphql/schemas/user/muc_light.gql @@ -3,11 +3,9 @@ Allow user to manage Multi-User Chat Light rooms. """ type MUCLightUserMutation @protected{ "Create a MUC light room under the given XMPP hostname" - createRoom(mucDomain: String!, name: String!, subject: String!, id: NonEmptyString): Room + createRoom(mucDomain: String!, name: String!, subject: String!, id: NonEmptyString, options: [RoomConfigDictEntryInput!]): Room "Change configuration of a MUC Light room" - changeRoomConfiguration(room: JID!, name: String!, subject: String!): Room - "Update configuration of a MUC Light room" - updateRoomConfiguration(room: JID!, options: [RoomConfigDictEntryInput!]!): Room + changeRoomConfiguration(room: JID!, name: String!, subject: String!, options: [RoomConfigDictEntryInput!]): Room "Invite a user to a MUC Light room" inviteUser(room: JID!, recipient: JID!): String "Remove a MUC Light room" diff --git a/src/graphql/admin/mongoose_graphql_muc_light_admin_mutation.erl b/src/graphql/admin/mongoose_graphql_muc_light_admin_mutation.erl index fb472dd850..52f665c8e4 100644 --- a/src/graphql/admin/mongoose_graphql_muc_light_admin_mutation.erl +++ b/src/graphql/admin/mongoose_graphql_muc_light_admin_mutation.erl @@ -9,7 +9,8 @@ -import(mongoose_graphql_helper, [make_error/2, format_result/2]). -import(mongoose_graphql_muc_light_helper, [make_room/1, make_ok_user/1, - prepare_blocking_items/1]). + prepare_blocking_items/1, + null_to_default/2, options_to_map/1]). execute(_Ctx, _Obj, <<"createRoom">>, Args) -> create_room(Args); @@ -27,17 +28,10 @@ execute(_Ctx, _Obj, <<"setBlockingList">>, Args) -> set_blocking_list(Args). -spec create_room(map()) -> {ok, map()} | {error, resolver_error()}. -create_room(#{<<"id">> := null, <<"mucDomain">> := MUCDomain, <<"name">> := RoomName, - <<"owner">> := CreatorJID, <<"subject">> := Subject}) -> - case mod_muc_light_api:create_room(MUCDomain, CreatorJID, RoomName, Subject) of - {ok, Room} -> - {ok, make_room(Room)}; - Err -> - make_error(Err, #{mucDomain => MUCDomain, creator => CreatorJID}) - end; create_room(#{<<"id">> := RoomID, <<"mucDomain">> := MUCDomain, <<"name">> := RoomName, - <<"owner">> := CreatorJID, <<"subject">> := Subject}) -> - case mod_muc_light_api:create_room(MUCDomain, RoomID, CreatorJID, RoomName, Subject) of + <<"owner">> := CreatorJID, <<"subject">> := Subject, <<"options">> := Options}) -> + case mod_muc_light_api:create_room(MUCDomain, null_to_default(RoomID, <<>>), CreatorJID, + RoomName, Subject, options_to_map(Options)) of {ok, Room} -> {ok, make_room(Room)}; Err -> diff --git a/src/graphql/mongoose_graphql_muc_light_helper.erl b/src/graphql/mongoose_graphql_muc_light_helper.erl index ad43fb8846..7bc2bfd411 100644 --- a/src/graphql/mongoose_graphql_muc_light_helper.erl +++ b/src/graphql/mongoose_graphql_muc_light_helper.erl @@ -1,7 +1,8 @@ -module(mongoose_graphql_muc_light_helper). -export([make_room/1, make_ok_user/1, blocking_item_to_map/1, - prepare_blocking_items/1, page_size_or_max_limit/2]). + prepare_blocking_items/1, page_size_or_max_limit/2, + null_to_default/2, options_to_map/1]). -spec page_size_or_max_limit(null | integer(), integer()) -> integer(). page_size_or_max_limit(null, MaxLimit) -> @@ -29,3 +30,13 @@ blocking_item_to_map({What, Action, Who}) -> make_options(Options) -> [{ok, #{<<"key">> => K, <<"value">> => V}} || {K, V} <- lists:sort(maps:to_list(Options))]. + +null_to_default(null, Default) -> + Default; +null_to_default(Value, _Default) -> + Value. + +options_to_map(null) -> + #{}; +options_to_map(Options) -> + maps:from_list([{K, V} || #{<<"key">> := K, <<"value">> := V} <- Options]). diff --git a/src/graphql/user/mongoose_graphql_muc_light_user_mutation.erl b/src/graphql/user/mongoose_graphql_muc_light_user_mutation.erl index ffa60e8782..bd4dbfcd7f 100644 --- a/src/graphql/user/mongoose_graphql_muc_light_user_mutation.erl +++ b/src/graphql/user/mongoose_graphql_muc_light_user_mutation.erl @@ -8,7 +8,8 @@ -include("../mongoose_graphql_types.hrl"). -import(mongoose_graphql_helper, [make_error/2, format_result/2]). --import(mongoose_graphql_muc_light_helper, [make_room/1, make_ok_user/1, prepare_blocking_items/1]). +-import(mongoose_graphql_muc_light_helper, [make_room/1, make_ok_user/1, prepare_blocking_items/1, + null_to_default/2, options_to_map/1]). execute(Ctx, _Obj, <<"createRoom">>, Args) -> create_room(Ctx, Args); @@ -26,17 +27,11 @@ execute(Ctx, _Obj, <<"setBlockingList">>, Args) -> set_blocking_list(Ctx, Args). -spec create_room(map(), map()) -> {ok, map()} | {error, resolver_error()}. -create_room(#{user := UserJID}, #{<<"id">> := null, <<"mucDomain">> := MUCDomain, - <<"name">> := RoomName, <<"subject">> := Subject}) -> - case mod_muc_light_api:create_room(MUCDomain, UserJID, RoomName, Subject) of - {ok, Room} -> - {ok, make_room(Room)}; - Err -> - make_error(Err, #{mucDomain => MUCDomain}) - end; create_room(#{user := UserJID}, #{<<"id">> := RoomID, <<"mucDomain">> := MUCDomain, - <<"name">> := RoomName, <<"subject">> := Subject}) -> - case mod_muc_light_api:create_room(MUCDomain, RoomID, UserJID, RoomName, Subject) of + <<"name">> := RoomName, <<"subject">> := Subject, + <<"options">> := Options}) -> + case mod_muc_light_api:create_room(MUCDomain, null_to_default(RoomID, <<>>), UserJID, + RoomName, Subject, options_to_map(Options)) of {ok, Room} -> {ok, make_room(Room)}; Err -> @@ -81,10 +76,3 @@ set_blocking_list(#{user := UserJID}, #{<<"items">> := Items}) -> Items2 = prepare_blocking_items(Items), Result = mod_muc_light_api:set_blocking(UserJID, Items2), format_result(Result, #{user => jid:to_binary(UserJID)}). - -%% Helpers - -null_to_default(null, Default) -> - Default; -null_to_default(Value, _Default) -> - Value. diff --git a/src/muc_light/mod_muc_light_api.erl b/src/muc_light/mod_muc_light_api.erl index 0f53b16280..992d270c31 100644 --- a/src/muc_light/mod_muc_light_api.erl +++ b/src/muc_light/mod_muc_light_api.erl @@ -3,6 +3,7 @@ -export([create_room/4, create_room/5, + create_room/6, invite_to_room/3, change_room_config/3, change_affiliation/4, @@ -53,9 +54,12 @@ create_room(MUCLightDomain, CreatorJID, RoomTitle, Subject) -> -spec create_room(jid:lserver(), jid:luser(), jid:jid(), binary(), binary()) -> create_room_result(). create_room(MUCLightDomain, RoomID, CreatorJID, RoomTitle, Subject) -> + create_room(MUCLightDomain, RoomID, CreatorJID, RoomTitle, Subject, #{}). + +create_room(MUCLightDomain, RoomID, CreatorJID, RoomTitle, Subject, Options) -> RoomJID = jid:make_bare(RoomID, MUCLightDomain), - Options = #{<<"roomname">> => RoomTitle, <<"subject">> => Subject}, - create_room_raw(RoomJID, CreatorJID, Options). + Options1 = Options#{<<"roomname">> => RoomTitle, <<"subject">> => Subject}, + create_room_raw(RoomJID, CreatorJID, Options1). -spec invite_to_room(jid:jid(), jid:jid(), jid:jid()) -> {ok | not_room_member | muc_server_not_found, iolist()}. From 80a715d83f047eb28dfde657e6b82d400accc7bc Mon Sep 17 00:00:00 2001 From: Mikhail Uvarov Date: Mon, 29 Aug 2022 09:51:49 +0200 Subject: [PATCH 5/8] Add create_room_with_custom_fields --- big_tests/tests/graphql_muc_light_SUITE.erl | 27 +++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/big_tests/tests/graphql_muc_light_SUITE.erl b/big_tests/tests/graphql_muc_light_SUITE.erl index 89ac8d6a90..231e413ceb 100644 --- a/big_tests/tests/graphql_muc_light_SUITE.erl +++ b/big_tests/tests/graphql_muc_light_SUITE.erl @@ -66,6 +66,7 @@ user_muc_light_tests() -> admin_muc_light_tests() -> [admin_create_room, + admin_create_room_with_custom_fields, admin_create_identified_room, admin_change_room_config, admin_change_room_config_errors, @@ -566,6 +567,25 @@ admin_create_room_story(Config, Alice) -> Res2 = create_room(?UNKNOWN_DOMAIN, Name, AliceBin, Subject, null, Config), ?assertNotEqual(nomatch, binary:match(get_err_msg(Res2), <<"not found">>)). +admin_create_room_with_custom_fields(Config) -> + escalus:fresh_story_with_config(Config, [{alice, 1}], fun admin_create_room_with_custom_fields_story/2). + +admin_create_room_with_custom_fields_story(Config, Alice) -> + AliceBin = escalus_client:short_jid(Alice), + AliceBinLower = escalus_utils:jid_to_lower(AliceBin), + MucServer = ?config(muc_light_host, Config), + Name = <<"first room">>, + Subject = <<"testing">>, + Options = #{<<"background">> => <<"red">>}, + Opts = [#{<<"key">> => <<"background">>, <<"value">> => <<"red">>}, + #{<<"key">> => <<"roomname">>, <<"value">> => Name}, + #{<<"key">> => <<"subject">>, <<"value">> => Subject}], + Res = create_room_with_custom_fields(MucServer, Name, AliceBin, Subject, null, Config, Options), + #{<<"jid">> := JID, <<"name">> := Name, <<"subject">> := Subject, + <<"participants">> := Participants, <<"options">> := Opts} = get_ok_value(?CREATE_ROOM_PATH, Res), + ?assertMatch(#jid{lserver = MucServer}, jid:from_binary(JID)), + ?assertEqual([#{<<"jid">> => AliceBinLower, <<"affiliation">> => <<"OWNER">>}], Participants). + admin_create_identified_room(Config) -> escalus:fresh_story_with_config(Config, [{alice, 1}], fun admin_create_identified_room_story/2). @@ -895,6 +915,13 @@ create_room(MUCDomain, Name, Owner, Subject, Id, Config) -> <<"subject">> => Subject, <<"id">> => Id}, execute_command(<<"muc_light">>, <<"createRoom">>, Vars, Config). +create_room_with_custom_fields(MUCDomain, Name, Owner, Subject, + Id, Config, CustomFields) -> + Vars = #{<<"mucDomain">> => MUCDomain, <<"name">> => Name, <<"owner">> => Owner, + <<"subject">> => Subject, <<"id">> => Id, + <<"options">> => format_options(CustomFields)}, + execute_command(<<"muc_light">>, <<"createRoom">>, Vars, Config). + change_room_configuration(RoomJID, OwnerJID, Name, Subject, Config) -> Vars = #{<<"room">> => RoomJID, <<"name">> => Name, <<"owner">> => OwnerJID, <<"subject">> => Subject}, From 6a44aae8440475342bafb341d95b236034869952 Mon Sep 17 00:00:00 2001 From: Mikhail Uvarov Date: Mon, 29 Aug 2022 10:28:20 +0200 Subject: [PATCH 6/8] Allow to provide options into change_room_config --- big_tests/tests/graphql_muc_light_SUITE.erl | 54 +++++++++++++++++++ ...goose_graphql_muc_light_admin_mutation.erl | 6 ++- ...ngoose_graphql_muc_light_user_mutation.erl | 5 +- 3 files changed, 61 insertions(+), 4 deletions(-) diff --git a/big_tests/tests/graphql_muc_light_SUITE.erl b/big_tests/tests/graphql_muc_light_SUITE.erl index 231e413ceb..8882059280 100644 --- a/big_tests/tests/graphql_muc_light_SUITE.erl +++ b/big_tests/tests/graphql_muc_light_SUITE.erl @@ -69,6 +69,7 @@ admin_muc_light_tests() -> admin_create_room_with_custom_fields, admin_create_identified_room, admin_change_room_config, + admin_change_room_config_with_custom_fields, admin_change_room_config_errors, admin_invite_user, admin_invite_user_errors, @@ -204,6 +205,24 @@ user_change_room_config_story(Config, Alice) -> Res = user_change_room_configuration(Alice, jid:to_binary(RoomJID), Name2, Subject2, Config), ?assertMatch(#{<<"name">> := Name2, <<"subject">> := Subject2}, get_ok_value(?CHANGE_CONFIG_PATH, Res)). +user_change_room_config_with_custom_fields(Config) -> + escalus:fresh_story_with_config(Config, [{alice, 1}], fun user_change_room_config_with_custom_fields_story/2). + +user_change_room_config_with_custom_fields_story(Config, Alice) -> + AliceBin = escalus_client:short_jid(Alice), + MUCServer = ?config(muc_light_host, Config), + % Create a new room + {ok, #{jid := RoomJID}} = create_room(MUCServer, <<"ornithology">>, <<"birds">>, AliceBin), + % Try to change the room configuration + Name2 = <<"changed room">>, + Subject2 = <<"not testing">>, + Opts2 = #{<<"music">> => <<"sad">>}, + Res = user_change_room_configuration_with_custom_fields(Alice, jid:to_binary(RoomJID), Name2, Subject2, Config, Opts2), + Opts3 = [#{<<"key">> => <<"music">>, <<"value">> => <<"sad">>}, + #{<<"key">> => <<"roomname">>, <<"value">> => Name2}, + #{<<"key">> => <<"subject">>, <<"value">> => Subject2}], + ?assertMatch(#{<<"name">> := Name2, <<"subject">> := Subject2, <<"options">> := Opts3}, get_ok_value(?CHANGE_CONFIG_PATH, Res)). + user_change_room_config_errors(Config) -> escalus:fresh_story_with_config(Config, [{alice, 1}, {bob, 1}], fun user_change_room_config_errors_story/3). @@ -626,6 +645,31 @@ admin_change_room_config_story(Config, Alice) -> ?assertMatch(#{<<"name">> := Name2, <<"subject">> := Subject2}, get_ok_value(?CHANGE_CONFIG_PATH, Res)). +admin_change_room_config_with_custom_fields(Config) -> + escalus:fresh_story_with_config(Config, [{alice, 1}], fun admin_change_room_config_with_custom_fields_story/2). + +admin_change_room_config_with_custom_fields_story(Config, Alice) -> + AliceBin = escalus_client:short_jid(Alice), + MUCServer = ?config(muc_light_host, Config), + Name = <<"first room">>, + Subject = <<"testing">>, + Opts = #{<<"background">> => <<"red">>}, + % Create a new room + Res = create_room_with_custom_fields(MUCServer, Name, AliceBin, Subject, null, Config, Opts), + #{<<"jid">> := RoomJID} = get_ok_value(?CREATE_ROOM_PATH, Res), + % Try to change the room configuration + Name2 = <<"changed room">>, + Subject2 = <<"not testing">>, + Opts2 = #{<<"music">> => <<"sad">>}, + Res2 = change_room_configuration_with_custom_fields(jid:to_binary(RoomJID), AliceBin, Name2, Subject2, Config, Opts2), + %% It overwrites old config for all fields + Opts3 = [% #{<<"key">> => <<"background">>, <<"value">> => <<"red">>}, + #{<<"key">> => <<"music">>, <<"value">> => <<"sad">>}, + #{<<"key">> => <<"roomname">>, <<"value">> => Name2}, + #{<<"key">> => <<"subject">>, <<"value">> => Subject2}], + ?assertMatch(#{<<"name">> := Name2, <<"subject">> := Subject2, <<"options">> := Opts3}, + get_ok_value(?CHANGE_CONFIG_PATH, Res2)). + admin_change_room_config_errors(Config) -> escalus:fresh_story_with_config(Config, [{alice, 1}, {bob, 1}], fun admin_change_room_config_errors_story/3). @@ -927,6 +971,11 @@ change_room_configuration(RoomJID, OwnerJID, Name, Subject, Config) -> <<"subject">> => Subject}, execute_command(<<"muc_light">>, <<"changeRoomConfiguration">>, Vars, Config). +change_room_configuration_with_custom_fields(RoomJID, OwnerJID, Name, Subject, Config, Opts) -> + Vars = #{<<"room">> => RoomJID, <<"name">> => Name, <<"owner">> => OwnerJID, + <<"subject">> => Subject, <<"options">> => format_options(Opts)}, + execute_command(<<"muc_light">>, <<"changeRoomConfiguration">>, Vars, Config). + invite_user(RoomJID, Sender, Recipient, Config) -> Vars = #{<<"room">> => RoomJID, <<"sender">> => Sender, <<"recipient">> => Recipient}, execute_command(<<"muc_light">>, <<"inviteUser">>, Vars, Config). @@ -981,6 +1030,11 @@ user_change_room_configuration(User, RoomJID, Name, Subject, Config) -> Vars = #{<<"room">> => RoomJID, <<"name">> => Name, <<"subject">> => Subject}, execute_user_command(<<"muc_light">>, <<"changeRoomConfiguration">>, User, Vars, Config). +user_change_room_configuration_with_custom_fields(User, RoomJID, Name, Subject, Config, Options) -> + Vars = #{<<"room">> => RoomJID, <<"name">> => Name, <<"subject">> => Subject, + <<"options">> => format_options(Options)}, + execute_user_command(<<"muc_light">>, <<"changeRoomConfiguration">>, User, Vars, Config). + format_options(Map) -> [#{<<"key">> => K, <<"value">> => V} || {K, V} <- maps:to_list(Map)]. diff --git a/src/graphql/admin/mongoose_graphql_muc_light_admin_mutation.erl b/src/graphql/admin/mongoose_graphql_muc_light_admin_mutation.erl index 52f665c8e4..abe77a394a 100644 --- a/src/graphql/admin/mongoose_graphql_muc_light_admin_mutation.erl +++ b/src/graphql/admin/mongoose_graphql_muc_light_admin_mutation.erl @@ -40,8 +40,10 @@ create_room(#{<<"id">> := RoomID, <<"mucDomain">> := MUCDomain, <<"name">> := Ro -spec change_room_config(map()) -> {ok, map()} | {error, resolver_error()}. change_room_config(#{<<"room">> := RoomJID, <<"name">> := RoomName, - <<"owner">> := OwnerJID, <<"subject">> := Subject}) -> - Config = #{<<"roomname">> => RoomName, <<"subject">> => Subject}, + <<"owner">> := OwnerJID, <<"subject">> := Subject, + <<"options">> := Options}) -> + OptMap = options_to_map(Options), + Config = OptMap#{<<"roomname">> => RoomName, <<"subject">> => Subject}, case mod_muc_light_api:change_room_config(RoomJID, OwnerJID, Config) of {ok, Room} -> {ok, make_room(Room)}; diff --git a/src/graphql/user/mongoose_graphql_muc_light_user_mutation.erl b/src/graphql/user/mongoose_graphql_muc_light_user_mutation.erl index bd4dbfcd7f..571f67252c 100644 --- a/src/graphql/user/mongoose_graphql_muc_light_user_mutation.erl +++ b/src/graphql/user/mongoose_graphql_muc_light_user_mutation.erl @@ -40,8 +40,9 @@ create_room(#{user := UserJID}, #{<<"id">> := RoomID, <<"mucDomain">> := MUCDoma -spec change_room_config(map(), map()) -> {ok, map()} | {error, resolver_error()}. change_room_config(#{user := UserJID}, #{<<"room">> := RoomJID, <<"name">> := RoomName, - <<"subject">> := Subject}) -> - Config = #{<<"roomname">> => RoomName, <<"subject">> => Subject}, + <<"subject">> := Subject, <<"options">> := Options}) -> + OptMap = options_to_map(Options), + Config = OptMap#{<<"roomname">> => RoomName, <<"subject">> => Subject}, case mod_muc_light_api:change_room_config(RoomJID, UserJID, Config) of {ok, Room} -> {ok, make_room(Room)}; From 471c60ddd9163b2c3ca962b64afc078826a070e4 Mon Sep 17 00:00:00 2001 From: Mikhail Uvarov Date: Mon, 29 Aug 2022 10:42:22 +0200 Subject: [PATCH 7/8] Add options field into room type --- src/muc_light/mod_muc_light_api.erl | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/muc_light/mod_muc_light_api.erl b/src/muc_light/mod_muc_light_api.erl index 992d270c31..483fee4bf3 100644 --- a/src/muc_light/mod_muc_light_api.erl +++ b/src/muc_light/mod_muc_light_api.erl @@ -34,7 +34,8 @@ -type room() :: #{jid := jid:jid(), name := binary(), subject := binary(), - aff_users := aff_users()}. + aff_users := aff_users(), + options := map()}. -export_type([room/0]). From f9d89a0e087f2654cb4ffec05bbc02a4cf23f364 Mon Sep 17 00:00:00 2001 From: Mikhail Uvarov Date: Wed, 31 Aug 2022 15:00:09 +0200 Subject: [PATCH 8/8] Always return options in Room type --- priv/graphql/schemas/global/muc_light.gql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/priv/graphql/schemas/global/muc_light.gql b/priv/graphql/schemas/global/muc_light.gql index cdac57ba84..a89fe1f539 100644 --- a/priv/graphql/schemas/global/muc_light.gql +++ b/priv/graphql/schemas/global/muc_light.gql @@ -45,7 +45,7 @@ type Room{ name: String! subject: String! participants: [RoomUser!]! - options: [RoomConfigDictEntry] + options: [RoomConfigDictEntry!]! } type RoomUser{