Skip to content

Commit

Permalink
Add affiliance enum and format JIDs in errors
Browse files Browse the repository at this point in the history
  • Loading branch information
Premwoik committed Feb 23, 2022
1 parent e260108 commit e84b9c3
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 17 deletions.
9 changes: 2 additions & 7 deletions priv/graphql/schemas/admin/muc_light.gql
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Allow admin to manage Multi-User Chat Light rooms.
"""
type MUCLightAdminMutation @protected{
"Create a MUC light room under the given XMPP hostname"
createRoom(domain: String!, name: String!, owner: JID!, subject: String!, id: String): Room
createRoom(mucDomain: String!, name: String!, owner: JID!, subject: String!, id: String): Room
"Change configuration of a MUC Light room"
changeRoomConfiguration(room: JID!, owner: JID!, name: String!, subject: String!): Room
"Invite a user to a MUC Light room"
Expand All @@ -30,11 +30,6 @@ type MUCLightAdminQuery @protected{
listUserRooms(user: JID!): [JID!]
}

type RoomPayload{
message: String!
room: Room
}

type Room{
jid: JID
name: String
Expand All @@ -44,5 +39,5 @@ type Room{

type RoomUser{
jid: JID
affiliance: String
affiliation: Affiliation
}
5 changes: 5 additions & 0 deletions priv/graphql/schemas/global/muc.gql
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
enum Affiliation{
OWNER
MEMBER
NONE
}
15 changes: 8 additions & 7 deletions src/graphql/admin/mongoose_graphql_muc_light_admin_mutation.erl
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ execute(_Ctx, _Obj, <<"sendMessageToRoom">>, Args) ->
-spec create_room(map()) -> {ok, map()} | {error, resolver_error()}.
create_room(#{<<"id">> := null} = Args) ->
create_room(Args#{<<"id">> => <<>>});
create_room(#{<<"id">> := RoomID, <<"domain">> := Domain, <<"name">> := RoomName,
create_room(#{<<"id">> := RoomID, <<"mucDomain">> := MUCDomain, <<"name">> := RoomName,
<<"owner">> := CreatorJID, <<"subject">> := Subject}) ->
case mod_muc_light_api:create_room(Domain, RoomID, RoomName, CreatorJID, Subject) of
case mod_muc_light_api:create_room(MUCDomain, RoomID, RoomName, CreatorJID, Subject) of
{ok, Room} ->
{ok, make_room(Room)};
Err ->
make_error(Err, #{domain => Domain, roomID => RoomID, creator => CreatorJID})
make_error(Err, #{mucDomain => MUCDomain, id => RoomID, creator => CreatorJID})
end.

-spec change_room_config(map()) -> {ok, map()} | {error, resolver_error()}.
Expand All @@ -41,19 +41,20 @@ change_room_config(#{<<"room">> := RoomJID, <<"name">> := RoomName,
{ok, Room} ->
{ok, make_room(Room)};
Err ->
make_error(Err, #{room => RoomJID, owner => OwnerJID})
make_error(Err, #{room => jid:to_binary(RoomJID), owner => jid:to_binary(OwnerJID)})
end.

-spec delete_room(map()) -> {ok, binary()} | {error, resolver_error()}.
delete_room(#{<<"room">> := RoomJID}) ->
Result = mod_muc_light_api:delete_room(RoomJID),
format_result(Result, #{room => RoomJID}).
format_result(Result, #{room => jid:to_binary(RoomJID)}).

-spec invite_user(map()) -> {ok, binary()} | {error, resolver_error()}.
invite_user(#{<<"room">> := RoomJID, <<"sender">> := SenderJID,
<<"recipient">> := RecipientJID}) ->
Result = mod_muc_light_api:invite_to_room(RoomJID, SenderJID, RecipientJID),
format_result(Result, #{room => RoomJID, sender => SenderJID, recipient => RecipientJID}).
format_result(Result, #{room => jid:to_binary(RoomJID), sender => jid:to_binary(SenderJID),
recipient => jid:to_binary(RecipientJID)}).

-spec kick_user(map()) -> {ok, binary()} | {error, resolver_error()}.
kick_user(#{<<"room">> := RoomJID, <<"user">> := UserJID}) ->
Expand All @@ -63,4 +64,4 @@ kick_user(#{<<"room">> := RoomJID, <<"user">> := UserJID}) ->
-spec send_msg_to_room(map()) -> {ok, binary()} | {error, resolver_error()}.
send_msg_to_room(#{<<"room">> := RoomJID, <<"from">> := FromJID, <<"body">> := Message}) ->
Result = mod_muc_light_api:send_message(RoomJID, FromJID, Message),
format_result(Result, #{room => RoomJID, from => FromJID}).
format_result(Result, #{room => jid:to_binary(RoomJID), from => jid:to_binary(FromJID)}).
9 changes: 7 additions & 2 deletions src/graphql/mongoose_graphql_enum.erl
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,16 @@ input(<<"PresenceShow">>, Show) ->
input(<<"PresenceType">>, Type) ->
{ok, list_to_binary(string:to_lower(binary_to_list(Type)))};
input(<<"AuthStatus">>, <<"AUTHORIZED">>) -> {ok, 'AUTHORIZED'};
input(<<"AuthStatus">>, <<"UNAUTHORIZED">>) -> {ok, 'UNAUTHORIZED'}.
input(<<"AuthStatus">>, <<"UNAUTHORIZED">>) -> {ok, 'UNAUTHORIZED'};
input(<<"Affiliation">>, <<"OWNER">>) -> {ok, owner};
input(<<"Affiliation">>, <<"MEMBER">>) -> {ok, member};
input(<<"Affiliation">>, <<"NONE">>) -> {ok, none}.

output(<<"PresenceShow">>, Show) ->
{ok, list_to_binary(string:to_upper(binary_to_list(Show)))};
output(<<"PresenceType">>, Type) ->
{ok, list_to_binary(string:to_upper(binary_to_list(Type)))};
output(<<"AuthStatus">>, Status) ->
{ok, atom_to_binary(Status, utf8)}.
{ok, atom_to_binary(Status, utf8)};
output(<<"Affiliation">>, Aff) ->
{ok, list_to_binary(string:to_upper(atom_to_list(Aff)))}.
2 changes: 1 addition & 1 deletion src/graphql/mongoose_graphql_muc_light_helper.erl
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ make_room(#{jid := JID, name := Name, subject := Subject, aff_users := Users}) -
<<"participants">> => Participants}.

make_ok_user({JID, Aff}) ->
{ok, #{<<"jid">> => JID, <<"affiliance">> => atom_to_binary(Aff)}}.
{ok, #{<<"jid">> => JID, <<"affiliation">> => Aff}}.

0 comments on commit e84b9c3

Please sign in to comment.