Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
Evangelos Ribeiro Tzaras
chatty
Commits
a7bbbe46
Commit
a7bbbe46
authored
Jul 06, 2021
by
Mohammed Sadiq
Committed by
Mohammed Sadiq
Jul 06, 2021
Browse files
matrix-api: Add API to delete 3pid
parent
74dca494
Changes
2
Hide whitespace changes
Inline
Side-by-side
src/matrix/matrix-api.c
View file @
a7bbbe46
...
...
@@ -2050,3 +2050,78 @@ matrix_api_get_3pid_finish (MatrixApi *self,
return
g_task_propagate_boolean
(
G_TASK
(
result
),
error
);
}
static
void
api_delete_3pid_cb
(
GObject
*
obj
,
GAsyncResult
*
result
,
gpointer
user_data
)
{
MatrixApi
*
self
;
g_autoptr
(
GTask
)
task
=
user_data
;
GError
*
error
=
NULL
;
JsonObject
*
object
;
g_assert
(
G_IS_TASK
(
task
));
self
=
g_task_get_source_object
(
task
);
g_assert
(
MATRIX_IS_API
(
self
));
object
=
g_task_propagate_pointer
(
G_TASK
(
result
),
&
error
);
CHATTY_TRACE_MSG
(
"Deleting 3pid. success: %d"
,
!
error
);
if
(
error
)
{
g_task_return_error
(
task
,
error
);
return
;
}
g_warning
(
"%s"
,
matrix_utils_json_object_to_string
(
object
,
TRUE
));
g_task_return_boolean
(
task
,
TRUE
);
}
void
matrix_api_delete_3pid_async
(
MatrixApi
*
self
,
const
char
*
value
,
ChattyIdType
type
,
GCancellable
*
cancellable
,
GAsyncReadyCallback
callback
,
gpointer
user_data
)
{
JsonObject
*
root
;
GTask
*
task
;
g_return_if_fail
(
MATRIX_IS_API
(
self
));
g_return_if_fail
(
value
&&
*
value
);
g_return_if_fail
(
type
==
CHATTY_ID_EMAIL
||
type
==
CHATTY_ID_PHONE
);
g_return_if_fail
(
!
cancellable
||
G_IS_CANCELLABLE
(
cancellable
));
CHATTY_TRACE_MSG
(
"Deleting 3pid: %s"
,
value
);
root
=
json_object_new
();
json_object_set_string_member
(
root
,
"address"
,
value
);
if
(
type
==
CHATTY_ID_PHONE
)
json_object_set_string_member
(
root
,
"medium"
,
"msisdn"
);
else
json_object_set_string_member
(
root
,
"medium"
,
"email"
);
task
=
g_task_new
(
self
,
cancellable
,
callback
,
user_data
);
g_object_set_data
(
G_OBJECT
(
task
),
"type"
,
GINT_TO_POINTER
(
type
));
g_object_set_data_full
(
G_OBJECT
(
task
),
"value"
,
g_strdup
(
value
),
g_free
);
matrix_net_send_json_async
(
self
->
matrix_net
,
2
,
root
,
"/_matrix/client/r0/account/3pid/delete"
,
SOUP_METHOD_POST
,
NULL
,
cancellable
,
api_delete_3pid_cb
,
task
);
}
gboolean
matrix_api_delete_3pid_finish
(
MatrixApi
*
self
,
GAsyncResult
*
result
,
GError
**
error
)
{
g_return_val_if_fail
(
MATRIX_IS_API
(
self
),
FALSE
);
g_return_val_if_fail
(
G_IS_TASK
(
result
),
FALSE
);
g_return_val_if_fail
(
!
error
||
!*
error
,
FALSE
);
return
g_task_propagate_boolean
(
G_TASK
(
result
),
error
);
}
src/matrix/matrix-api.h
View file @
a7bbbe46
...
...
@@ -186,5 +186,14 @@ gboolean matrix_api_get_3pid_finish (MatrixApi *self,
GPtrArray
**
phones
,
GAsyncResult
*
result
,
GError
**
error
);
void
matrix_api_delete_3pid_async
(
MatrixApi
*
self
,
const
char
*
value
,
ChattyIdType
type
,
GCancellable
*
cancellable
,
GAsyncReadyCallback
callback
,
gpointer
user_data
);
gboolean
matrix_api_delete_3pid_finish
(
MatrixApi
*
self
,
GAsyncResult
*
result
,
GError
**
error
);
G_END_DECLS
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment