-
Notifications
You must be signed in to change notification settings - Fork 428
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
89 additions
and
2 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
50 changes: 50 additions & 0 deletions
50
src/graphql/user/mongoose_graphql_roster_user_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,50 @@ | ||
-module(mongoose_graphql_roster_user_mutation). | ||
-behaviour(mongoose_graphql). | ||
|
||
-export([execute/4]). | ||
|
||
-ignore_xref([execute/4]). | ||
|
||
-import(mongoose_graphql_helper, [make_error/2, format_result/2, null_to_default/2]). | ||
|
||
execute(Ctx, _Obj, <<"addContact">>, Args) -> | ||
add_contact(Ctx, Args); | ||
execute(Ctx, _Obj, <<"addContacts">>, Args) -> | ||
add_contacts(Ctx, Args); | ||
execute(Ctx, _Obj, <<"subscription">>, Args) -> | ||
subscription(Ctx, Args); | ||
execute(Ctx, _Obj, <<"deleteContact">>, Args) -> | ||
delete_contact(Ctx, Args); | ||
execute(Ctx, _Obj, <<"deleteContacts">>, Args) -> | ||
delete_contacts(Ctx, Args). | ||
|
||
-spec add_contact(mongoose_graphql:context(), mongoose_graphql:args()) -> | ||
mongoose_graphql_roster:binary_result(). | ||
add_contact(#{user := UserJID}, #{<<"contact">> := ContactJID, | ||
<<"name">> := Name, | ||
<<"groups">> := Groups}) -> | ||
mongoose_graphql_roster:add_contact(UserJID, ContactJID, Name, Groups). | ||
|
||
-spec add_contacts(mongoose_graphql:context(), mongoose_graphql:args()) -> | ||
mongoose_graphql_roster:list_binary_result(). | ||
add_contacts(#{user := UserJID}, #{<<"contacts">> := Contacts}) -> | ||
{ok, [mongoose_graphql_roster:add_contact(UserJID, ContactJID, Name, Groups) | ||
|| #{<<"jid">> := ContactJID, <<"name">> := Name, <<"groups">> := Groups} <- Contacts]}. | ||
|
||
-spec subscription(mongoose_graphql:context(), mongoose_graphql:args()) -> | ||
mongoose_graphql_roster:binary_result(). | ||
subscription(#{user := UserJID}, #{<<"contact">> := ContactJID, <<"action">> := Action}) -> | ||
Type = mongoose_graphql_roster:translate_sub_action(Action), | ||
Res = mod_roster_api:subscription(UserJID, ContactJID, Type), | ||
format_result(Res, #{contact => jid:to_binary(ContactJID)}). | ||
|
||
-spec delete_contact(mongoose_graphql:context(), mongoose_graphql:args()) -> | ||
mongoose_graphql_roster:binary_result(). | ||
delete_contact(#{user := UserJID}, #{<<"contact">> := ContactJID}) -> | ||
mongoose_graphql_roster:delete_contact(UserJID, ContactJID). | ||
|
||
-spec delete_contacts(mongoose_graphql:context(), mongoose_graphql:args()) -> | ||
mongoose_graphql_roster:list_binary_result(). | ||
delete_contacts(#{user := UserJID}, #{<<"contacts">> := ContactJIDs}) -> | ||
{ok, [mongoose_graphql_roster:delete_contact(UserJID, ContactJID) | ||
|| ContactJID <- ContactJIDs]}. |
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,31 @@ | ||
-module(mongoose_graphql_roster_user_query). | ||
-behaviour(mongoose_graphql). | ||
|
||
-export([execute/4]). | ||
|
||
-ignore_xref([execute/4]). | ||
|
||
-include("../mongoose_graphql_types.hrl"). | ||
|
||
-import(mongoose_graphql_helper, [make_error/2, format_result/2]). | ||
|
||
execute(Ctx, _Obj, <<"listContacts">>, Args) -> | ||
list_contacts(Ctx, Args); | ||
execute(Ctx, _Obj, <<"getContact">>, Args) -> | ||
get_contact(Ctx, Args). | ||
|
||
-spec list_contacts(mongoose_graphql:context(), mongoose_graphql:args()) -> | ||
{ok, mongoose_graphql_roster:contact_list()} | {error, resolver_error()}. | ||
list_contacts(#{user := UserJID}, #{}) -> | ||
{ok, Contacts} = mod_roster_api:list_contacts(UserJID), | ||
{ok, [mongoose_graphql_roster:make_ok_roster(C) || C <- Contacts]}. | ||
|
||
-spec get_contact(mongoose_graphql:context(), mongoose_graphql:args()) -> | ||
{ok, mongoose_graphql_roster:contact()} | {error, resolver_error()}. | ||
get_contact(#{user := UserJID}, #{<<"contact">> := ContactJID}) -> | ||
case mod_roster_api:get_contact(UserJID, ContactJID) of | ||
{ok, Contact} -> | ||
mongoose_graphql_roster:make_ok_roster(Contact); | ||
Error -> | ||
make_error(Error, #{contact => jid:to_binary(ContactJID)}) | ||
end. |
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