-
Notifications
You must be signed in to change notification settings - Fork 426
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3538 from esl/graphql/muc-light-api
GraphQL - Implement MUC Light rooms API for admin
- Loading branch information
Showing
24 changed files
with
1,192 additions
and
277 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
""" | ||
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: 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" | ||
inviteUser(room: JID!, sender: JID!, recipient: JID!): String | ||
"Remove a MUC Light room" | ||
deleteRoom(room: JID!): String | ||
"Kick a user from a MUC Light room" | ||
kickUser(room: JID!, user: JID!): String | ||
"Send a message to a MUC Light room" | ||
sendMessageToRoom(room: JID!, from: JID!, body: String!): String | ||
} | ||
|
||
""" | ||
Allow admin to get information about Multi-User Chat Light rooms. | ||
""" | ||
type MUCLightAdminQuery @protected{ | ||
"Get the MUC Light room archived messages" | ||
getRoomMessages(room: JID!, pageSize: Int!, before: DateTime): StanzasPayload | ||
"Get configuration of the MUC Light room" | ||
getRoomConfig(room: JID!): Room | ||
"Get users list of given MUC Light room" | ||
listRoomUsers(room: JID!): [RoomUser!] | ||
"Get the list of MUC Light rooms that the user participates in" | ||
listUserRooms(user: JID!): [JID!] | ||
} | ||
|
||
type Room{ | ||
jid: JID! | ||
name: String! | ||
subject: String! | ||
participants: [RoomUser!]! | ||
} | ||
|
||
type RoomUser{ | ||
jid: JID! | ||
affiliation: Affiliation! | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
enum Affiliation{ | ||
OWNER | ||
MEMBER | ||
NONE | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
src/graphql/admin/mongoose_graphql_muc_light_admin_mutation.erl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
-module(mongoose_graphql_muc_light_admin_mutation). | ||
|
||
-export([execute/4]). | ||
|
||
-ignore_xref([execute/4]). | ||
|
||
-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]). | ||
|
||
execute(_Ctx, _Obj, <<"createRoom">>, Args) -> | ||
create_room(Args); | ||
execute(_Ctx, _Obj, <<"changeRoomConfiguration">>, Args) -> | ||
change_room_config(Args); | ||
execute(_Ctx, _Obj, <<"inviteUser">>, Args) -> | ||
invite_user(Args); | ||
execute(_Ctx, _Obj, <<"deleteRoom">>, Args) -> | ||
delete_room(Args); | ||
execute(_Ctx, _Obj, <<"kickUser">>, Args) -> | ||
kick_user(Args); | ||
execute(_Ctx, _Obj, <<"sendMessageToRoom">>, Args) -> | ||
send_msg_to_room(Args). | ||
|
||
-spec create_room(map()) -> {ok, map()} | {error, resolver_error()}. | ||
create_room(#{<<"id">> := null} = Args) -> | ||
create_room(Args#{<<"id">> => <<>>}); | ||
create_room(#{<<"id">> := RoomID, <<"mucDomain">> := MUCDomain, <<"name">> := RoomName, | ||
<<"owner">> := CreatorJID, <<"subject">> := Subject}) -> | ||
case mod_muc_light_api:create_room(MUCDomain, RoomID, RoomName, CreatorJID, Subject) of | ||
{ok, Room} -> | ||
{ok, make_room(Room)}; | ||
Err -> | ||
make_error(Err, #{mucDomain => MUCDomain, id => RoomID, creator => CreatorJID}) | ||
end. | ||
|
||
-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 | ||
{ok, Room} -> | ||
{ok, make_room(Room)}; | ||
Err -> | ||
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 => 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 => 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}) -> | ||
Result = mod_muc_light_api:remove_user_from_room(RoomJID, UserJID, UserJID), | ||
format_result(Result, #{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 => jid:to_binary(RoomJID), from => jid:to_binary(FromJID)}). |
Oops, something went wrong.