-
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.
Implement the admin part of MUC Light API for GraphQL
- Loading branch information
Showing
18 changed files
with
1,005 additions
and
197 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
""" | ||
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 | ||
"Change configuration of MUC Light room" | ||
changeRoomConfiguration(id: String!, domain: String!, name: String!, owner: JID!, subject: String!): Room | ||
"Invite a user to a MUC Light room" | ||
inviteUser(domain: String!, name: String!, sender: JID!, recipient: JID!): String | ||
"Remove a MUC light room" | ||
deleteRoom(id: String!, domain: String!): String | ||
"Remove a user from a room" | ||
kickUser(domain: String!, id: String!, user: JID!): String | ||
"Send a message to a MUC Light room" | ||
sendMessageToRoom(domain: String!, name: String!, from: JID!, body: String!): String | ||
} | ||
|
||
""" | ||
Allow admin to get information about Multi-User Chat Light rooms. | ||
""" | ||
type MUCLightAdminQuery @protected{ | ||
"Read messages" | ||
getRoomMessages(domain: String!, id: String!): StanzasPayload | ||
"Get configuration of the MUC Light room" | ||
getRoomConfig(domain: String!, id: String!): Room | ||
"Get users list of MUC Light room" | ||
listRoomUsers(domain: String!, id: String!): [RoomUser!] | ||
"Get the list of rooms that the given user participates in" | ||
listUserRooms(user: JID!): [JID!] | ||
|
||
} | ||
|
||
type RoomPayload{ | ||
message: String! | ||
room: Room | ||
} | ||
|
||
type Room{ | ||
jid: JID | ||
name: String | ||
subject: String | ||
participants: [RoomUser!] | ||
} | ||
|
||
type RoomUser{ | ||
jid: JID | ||
affiliance: String | ||
} | ||
|
||
enum Affiliance{ | ||
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
64 changes: 64 additions & 0 deletions
64
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,64 @@ | ||
-module(mongoose_graphql_muc_light_admin_mutation). | ||
|
||
-export([execute/4]). | ||
|
||
-ignore_xref([execute/4]). | ||
|
||
-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). | ||
|
||
create_room(#{<<"id">> := null} = Args) -> | ||
create_room(Args#{<<"id">> => <<>>}); | ||
create_room(#{<<"id">> := Id, <<"domain">> := Domain, <<"name">> := RoomName, | ||
<<"owner">> := CreatorJID, <<"subject">> := Subject}) -> | ||
case mod_muc_light_api:create_room(Domain, Id, RoomName, CreatorJID, Subject) of | ||
{ok, Room} -> | ||
{ok, make_room(Room)}; | ||
Err -> | ||
make_error(Err, #{}) | ||
end. | ||
|
||
change_room_config(#{<<"id">> := RoomID, <<"domain">> := Domain, <<"name">> := RoomName, | ||
<<"owner">> := OwnerJID, <<"subject">> := Subject}) -> | ||
case mod_muc_light_api:change_room_config(Domain, RoomID, RoomName, OwnerJID, Subject) of | ||
{ok, Room} -> | ||
{ok, make_room(Room)}; | ||
Err -> | ||
make_error(Err, #{}) | ||
end. | ||
|
||
delete_room(#{<<"domain">> := Domain, <<"id">> := RoomID}) -> | ||
Result = mod_muc_light_api:delete_room(Domain, RoomID), | ||
format_result(Result, #{}). | ||
|
||
invite_user(#{<<"domain">> := Domain, <<"name">> := Name, <<"sender">> := SenderJID, | ||
<<"recipient">> := RecipientJID}) -> | ||
Result = mod_muc_light_api:invite_to_room(Domain, Name, SenderJID, RecipientJID), | ||
format_result(Result, #{}). | ||
|
||
kick_user(#{<<"domain">> := Domain, <<"id">> := RoomID, <<"user">> := UserJID}) -> | ||
Result = mod_muc_light_api:remove_user_from_room(Domain, RoomID, UserJID, UserJID), | ||
format_result(Result, #{}). | ||
|
||
send_msg_to_room(#{<<"domain">> := Domain, <<"name">> := RoomName, <<"from">> := FromJID, | ||
<<"body">> := Message}) -> | ||
Result = mod_muc_light_api:send_message(Domain, RoomName, FromJID, Message), | ||
format_result(Result, #{}). | ||
|
||
%% Internal | ||
|
||
|
66 changes: 66 additions & 0 deletions
66
src/graphql/admin/mongoose_graphql_muc_light_admin_query.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,66 @@ | ||
-module(mongoose_graphql_muc_light_admin_query). | ||
|
||
-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, <<"listUserRooms">>, Args) -> | ||
list_user_rooms(Args); | ||
execute(_Ctx, _Obj, <<"listRoomUsers">>, Args) -> | ||
list_room_users(Args); | ||
execute(_Ctx, _Obj, <<"getRoomConfig">>, Args) -> | ||
get_room_config(Args); | ||
execute(_Ctx, _Obj, <<"getRoomMessages">>, Args) -> | ||
get_room_messages(Args). | ||
|
||
-spec list_user_rooms(map()) -> {ok, [binary()]} | {error, resolver_error()}. | ||
list_user_rooms(#{<<"user">> := UserJID}) -> | ||
case mod_muc_light_api:get_user_rooms(UserJID) of | ||
{ok, Rooms} -> | ||
{ok, [{ok, R} || R <- Rooms]}; | ||
Err -> | ||
make_error(Err, #{}) | ||
end. | ||
|
||
-spec list_room_users(map()) -> {ok, [map()]} | {error, resolver_error()}. | ||
list_room_users(#{<<"domain">> := Domain, <<"id">> := RoomID}) -> | ||
case mod_muc_light_api:get_room_aff(Domain, RoomID) of | ||
{ok, Affs} -> | ||
{ok, [make_ok_user(A) || A <- Affs]}; | ||
Err -> | ||
make_error(Err, #{}) | ||
end. | ||
|
||
-spec get_room_config(map()) -> {ok, map()} | {error, resolver_error()}. | ||
get_room_config(#{<<"domain">> := Domain, <<"id">> := RoomID}) -> | ||
case mod_muc_light_api:get_room_info(Domain, RoomID) of | ||
{ok, Room} -> | ||
{ok, make_room(Room)}; | ||
Err -> | ||
make_error(Err, #{}) | ||
end. | ||
|
||
-spec get_room_messages(map()) -> {ok, map()} | {error, resolver_error()}. | ||
get_room_messages(#{<<"domain">> := Domain, <<"id">> := RoomID}) -> | ||
case mod_muc_light_api:get_room_messages(Domain, RoomID) of | ||
{ok, Rows} -> | ||
Maps = lists:map(fun row_to_map/1, Rows), | ||
{ok, #{<<"stanzas">> => Maps, <<"limit">> => 0}}; | ||
Err -> | ||
make_error(Err, #{}) | ||
end. | ||
|
||
-spec row_to_map(mod_mam:message_row()) -> {ok, map()}. | ||
row_to_map(#{id := Id, jid := From, packet := Msg}) -> | ||
{Microseconds, _} = mod_mam_utils:decode_compact_uuid(Id), | ||
StanzaID = mod_mam_utils:mess_id_to_external_binary(Id), | ||
Map = #{<<"sender">> => From, <<"timestamp">> => Microseconds, | ||
<<"stanza_id">> => StanzaID, <<"stanza">> => Msg}, | ||
{ok, Map}. | ||
|
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,12 @@ | ||
-module(mongoose_graphql_muc_light_helper). | ||
|
||
-export([make_room/1, make_ok_user/1]). | ||
|
||
-spec make_room(mod_muc_light_api:room()) -> map(). | ||
make_room(#{jid := JID, name := Name, subject := Subject, aff_users := Users}) -> | ||
Participants = lists:map(fun make_ok_user/1, Users), | ||
#{<<"jid">> => JID, <<"name">> => Name, <<"subject">> => Subject, | ||
<<"participants">> => Participants}. | ||
|
||
make_ok_user({JID, Aff}) -> | ||
{ok, #{<<"jid">> => JID, <<"affiliance">> => atom_to_binary(Aff)}}. |
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
Oops, something went wrong.