Skip to content

Commit

Permalink
Add RoomName GraphQL type
Browse files Browse the repository at this point in the history
  • Loading branch information
chrzaszcz committed Nov 18, 2022
1 parent cf683d3 commit 569a4ed
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 4 deletions.
2 changes: 1 addition & 1 deletion priv/graphql/schemas/admin/muc.gql
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Allow admin to manage Multi-User Chat rooms.
type MUCAdminMutation @protected @use(modules: ["mod_muc"]){
"Create a MUC room under the given XMPP hostname"
#There is no @use directive because it is currently impossible to get HostType from mucDomain in directive code
createInstantRoom(mucDomain: DomainName!, name: String!, owner: JID!, nick: String!): MUCRoomDesc
createInstantRoom(mucDomain: DomainName!, name: RoomName!, owner: JID!, nick: String!): MUCRoomDesc
@protected(type: DOMAIN, args: ["owner"])
"Invite a user to a MUC room"
inviteUser(room: JID!, sender: JID!, recipient: JID!, reason: String): String
Expand Down
2 changes: 1 addition & 1 deletion priv/graphql/schemas/admin/muc_light.gql
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Allow admin to manage Multi-User Chat Light rooms.
type MUCLightAdminMutation @use(modules: ["mod_muc_light"]) @protected{
"Create a MUC light room under the given XMPP hostname"
#There is no @use directive because it is currently impossible to get HostType from mucDomain in directive code
createRoom(mucDomain: DomainName!, name: String!, owner: JID!, subject: String!, id: NonEmptyString, options: [RoomConfigDictEntryInput!]): Room
createRoom(mucDomain: DomainName!, name: String!, owner: JID!, subject: String!, id: RoomName, options: [RoomConfigDictEntryInput!]): Room
@protected(type: DOMAIN, args: ["owner"])
"Change configuration of a MUC Light room"
changeRoomConfiguration(room: JID!, owner: JID!, name: String!, subject: String!, options: [RoomConfigDictEntryInput!]): Room
Expand Down
3 changes: 3 additions & 0 deletions priv/graphql/schemas/global/scalar_types.gql
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ scalar JID @spectaql(options: [{ key: "example", value: "alice@localhost" }])
scalar FullJID @spectaql(options: [{ key: "example", value: "alice@localhost/res1" }])
"XMPP user name (local part of a JID)"
scalar UserName @spectaql(options: [{ key: "example", value: "alice" }])
"XMPP room name (local part of a JID)"
scalar RoomName @spectaql(options: [{ key: "example", value: "my-chat-room" }])
"XMPP domain name (domain part of a JID)"
scalar DomainName @spectaql(options: [{ key: "example", value: "localhost" }])
"String that contains at least one character"
scalar NonEmptyString @spectaql(options: [{ key: "example", value: "xyz789" }])
Expand Down
2 changes: 1 addition & 1 deletion priv/graphql/schemas/user/muc.gql
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Allow user to manage Multi-User Chat rooms.
type MUCUserMutation @protected @use(modules: ["mod_muc"]){
"Create a MUC room under the given XMPP hostname"
#There is no @use directive because it is currently impossible to get HostType from mucDomain in directive code
createInstantRoom(mucDomain: DomainName!, name: String!, nick: String!): MUCRoomDesc
createInstantRoom(mucDomain: DomainName!, name: RoomName!, nick: String!): MUCRoomDesc
"Invite a user to a MUC room"
inviteUser(room: JID!, recipient: JID!, reason: String): String @use(arg: "room")
"Kick a user from a MUC room"
Expand Down
2 changes: 1 addition & 1 deletion priv/graphql/schemas/user/muc_light.gql
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Allow user to manage Multi-User Chat Light rooms.
type MUCLightUserMutation @protected @use(modules: ["mod_muc_light"]){
"Create a MUC light room under the given XMPP hostname"
#There is no @use directive because it is currently impossible to get HostType from mucDomain in directive code
createRoom(mucDomain: DomainName!, name: String!, subject: String!, id: NonEmptyString, options: [RoomConfigDictEntryInput!]): Room
createRoom(mucDomain: DomainName!, name: String!, subject: String!, id: RoomName, options: [RoomConfigDictEntryInput!]): Room
"Change configuration of a MUC Light room"
changeRoomConfiguration(room: JID!, name: String!, subject: String!, options: [RoomConfigDictEntryInput!]): Room @use(arg: "room")
"Invite a user to a MUC Light room"
Expand Down
12 changes: 12 additions & 0 deletions src/graphql/mongoose_graphql_scalar.erl
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ input(<<"DateTime">>, DT) -> binary_to_microseconds(DT);
input(<<"Stanza">>, Value) -> exml:parse(Value);
input(<<"JID">>, Jid) -> jid_from_binary(Jid);
input(<<"UserName">>, User) -> user_from_binary(User);
input(<<"RoomName">>, Room) -> room_from_binary(Room);
input(<<"DomainName">>, Domain) -> domain_from_binary(Domain);
input(<<"FullJID">>, Jid) -> full_jid_from_binary(Jid);
input(<<"NonEmptyString">>, Value) -> non_empty_string_to_binary(Value);
Expand All @@ -32,6 +33,7 @@ output(<<"DateTime">>, DT) -> {ok, microseconds_to_binary(DT)};
output(<<"Stanza">>, Elem) -> {ok, exml:to_binary(Elem)};
output(<<"JID">>, Jid) -> {ok, jid:to_binary(Jid)};
output(<<"UserName">>, User) -> {ok, User};
output(<<"RoomName">>, Room) -> {ok, Room};
output(<<"DomainName">>, Domain) -> {ok, Domain};
output(<<"NonEmptyString">>, Value) -> binary_to_non_empty_string(Value);
output(<<"PosInt">>, Value) -> validate_pos_integer(Value);
Expand All @@ -57,6 +59,16 @@ user_from_binary(Value) ->
{ok, User}
end.

room_from_binary(<<>>) ->
{error, empty_room_name};
room_from_binary(Value) ->
case jid:nodeprep(Value) of
error ->
{error, failed_to_parse_room_name};
Room ->
{ok, Room}
end.

domain_from_binary(<<>>) ->
{error, empty_domain_name};
domain_from_binary(Value) ->
Expand Down

0 comments on commit 569a4ed

Please sign in to comment.