Compare commits
165 Commits
object-gen
...
develop
Author | SHA1 | Date | |
---|---|---|---|
dd6fd39ae3 | |||
42d9ab7716 | |||
22fcbe1e31 | |||
da6e3f8b7b | |||
3ffd5a5b38 | |||
01603d50e0 | |||
5d0a0886e6 | |||
aeecc7a03d | |||
03625e8a8f | |||
1c14ad77ff | |||
8f0f60e372 | |||
f4a8b47aa6 | |||
80dad1b03a | |||
96e36f49e1 | |||
2966b926c1 | |||
45066ff67e | |||
b804d2d1c9 | |||
8fe499e967 | |||
01a596a8c3 | |||
d6ea38832f | |||
49a6d84a74 | |||
86147377d0 | |||
091bb38286 | |||
3418c22250 | |||
a3dee44bb8 | |||
fb217e6b68 | |||
49b466f67e | |||
1f0fdb79e3 | |||
11d18ef27a | |||
80e61b8f93 | |||
5c3911e6fb | |||
76d68d5c7b | |||
6b8f2fe22c | |||
b69b9d0d89 | |||
62b106511d | |||
b211ee2fc2 | |||
fe238ff236 | |||
c8fe8e1ebb | |||
c91035dbd0 | |||
f97896a250 | |||
25f809d37e | |||
94c49193c8 | |||
d3be50a6a0 | |||
51a4b1492c | |||
9054fb2a72 | |||
5bc80a215f | |||
e77e6473b8 | |||
3c6b0a85bf | |||
2a098de9bf | |||
2dc42021b6 | |||
a73866a918 | |||
5fedf09f76 | |||
457371b25b | |||
4c6ffe59f4 | |||
758ee3ae81 | |||
1d16628861 | |||
6ab67b44be | |||
d9a032ac28 | |||
33bb63e4f1 | |||
21ee03d030 | |||
4ce4ae4641 | |||
734a8349d0 | |||
161c171144 | |||
b125086669 | |||
ca4b897d99 | |||
cf53bfa686 | |||
8d725d9f34 | |||
4db2d5ebf2 | |||
3f7057c652 | |||
00a67705e7 | |||
3dd3568384 | |||
15d1896669 | |||
3ddac22f78 | |||
0e4a572058 | |||
341cb2f31c | |||
5cdbc16aa8 | |||
c8f815c542 | |||
9f236de0b9 | |||
3bc8735eb5 | |||
5254776d4f | |||
34b0bea889 | |||
c547e5c080 | |||
710c575479 | |||
ee9e27f8d2 | |||
c9465dc1c0 | |||
f6df2200b7 | |||
fcc592b072 | |||
62eb4e7e21 | |||
04950f8c34 | |||
f1d1eda2e4 | |||
595d93412b | |||
4c9a79758a | |||
39a4e2f73c | |||
6e5c73c6ad | |||
65dffc38da | |||
c7d927e6fe | |||
275a47b5e8 | |||
78fc89804c | |||
51cbda451c | |||
1f1bc94bbd | |||
19323453a9 | |||
d99cb8b589 | |||
32245397fd | |||
5bb3620395 | |||
0bcb72d5aa | |||
f1a58f84b8 | |||
6fc2bffe9c | |||
ddf2165cc2 | |||
a33e3cf6b2 | |||
4a5aef0a10 | |||
d714661c17 | |||
49a8b1f665 | |||
feb2bd0323 | |||
75ab5512f1 | |||
9be25a5d61 | |||
4a86522b72 | |||
e317df6f01 | |||
42f1d50877 | |||
7817fb68f6 | |||
969d9d27ea | |||
3fe5b57d1c | |||
be2220b079 | |||
a68afb1efb | |||
ddf3fccbaa | |||
a668dc7b98 | |||
06daf1757c | |||
27e27667ef | |||
c2569c70d0 | |||
a39edfc15a | |||
51c204cc90 | |||
ff6400a94a | |||
b9ded01e98 | |||
11de94b822 | |||
b6b5bbf567 | |||
399105d961 | |||
be8910b8be | |||
1f804e0d42 | |||
6db0e82ca7 | |||
e958e0ecc7 | |||
66ae5cff58 | |||
3f7bf44989 | |||
18bff85653 | |||
d267b9e110 | |||
ff2530ed2d | |||
529fb29155 | |||
c8c26a5398 | |||
39fd66946e | |||
bfc5062f90 | |||
83d021dfbe | |||
69a8dc7954 | |||
5c121cef0e | |||
82536c650d | |||
c581f9e2fb | |||
13abc13adc | |||
0aaab4af7e | |||
f48eaf4c88 | |||
26d144c593 | |||
3a39c704f1 | |||
d4ce1cb06c | |||
70dfaff080 | |||
5f0b877db1 | |||
97a075d2d2 | |||
f37d90e468 | |||
95084b8e93 | |||
b9e798145f |
49
.gitignore
vendored
49
.gitignore
vendored
@@ -37,6 +37,7 @@ Makefile.in
|
||||
/INSTALL
|
||||
/ChangeLog
|
||||
/src/matrix-version.h
|
||||
/src/matrix-enumtypes.[ch]
|
||||
/src/matrix-marshalers.[ch]
|
||||
/src/stamp-matrix-marshalers
|
||||
/docs/valadoc/gtk-doc/gtk-doc
|
||||
@@ -48,13 +49,45 @@ Makefile.in
|
||||
/src/matrix-glib.h
|
||||
/src/matrix-api.c
|
||||
/src/matrix-client.c
|
||||
/src/matrix-enums.c
|
||||
/src/matrix-http-api.c
|
||||
/src/matrix-http-client.c
|
||||
/src/matrix-compacts.c
|
||||
/src/matrix-event.c
|
||||
/src/matrix-presence-event.c
|
||||
/src/matrix-room-event.c
|
||||
/src/matrix-room-member-event.c
|
||||
/src/matrix-state-event.c
|
||||
/src/matrix-room-message-event.c
|
||||
/src/matrix-event-base.c
|
||||
/src/matrix-event-presence.c
|
||||
/src/matrix-event-room-base.c
|
||||
/src/matrix-event-room-member.c
|
||||
/src/matrix-event-state-base.c
|
||||
/src/matrix-event-room-message.c
|
||||
/src/namespace-info.vala
|
||||
/src/namespace-info.c
|
||||
/src/matrix-event-room-topic.c
|
||||
/src/matrix-event-typing.c
|
||||
/src/matrix-event-room-aliases.c
|
||||
/src/matrix-event-receipt.c
|
||||
/src/matrix-event-room-history-visibility.c
|
||||
/src/matrix-event-room-join-rules.c
|
||||
/src/matrix-event-room-name.c
|
||||
/src/matrix-event-tag.c
|
||||
/src/matrix-event-room-canonical-alias.c
|
||||
/src/matrix-event-room-create.c
|
||||
/src/matrix-event-room-power-levels.c
|
||||
/src/matrix-event-room-avatar.c
|
||||
/src/matrix-event-room-message-feedback.c
|
||||
/src/matrix-event-room-guest-access.c
|
||||
/src/matrix-event-room-redaction.c
|
||||
/src/matrix-event-room-third-party-invite.c
|
||||
/src/matrix-event-call-invite.c
|
||||
/src/matrix-event-call-candidates.c
|
||||
/src/matrix-event-call-answer.c
|
||||
/src/matrix-event-call-hangup.c
|
||||
/src/matrix-event-call-base.c
|
||||
/src/matrix-glib-0.0.pc
|
||||
/src/matrix-message-base.c
|
||||
/src/matrix-message-text.c
|
||||
/src/matrix-message-emote.c
|
||||
/src/matrix-message-notice.c
|
||||
/src/matrix-message-file.c
|
||||
/src/matrix-message-image.c
|
||||
/src/matrix-message-audio.c
|
||||
/src/matrix-message-video.c
|
||||
/src/matrix-message-location.c
|
||||
/src/matrix-room.c
|
||||
|
79
CODE_OF_CONDUCT.md
Normal file
79
CODE_OF_CONDUCT.md
Normal file
@@ -0,0 +1,79 @@
|
||||
# Contributor Covenant Code of Conduct
|
||||
|
||||
## Our Pledge
|
||||
|
||||
In the interest of fostering an open and welcoming environment, we as
|
||||
contributors and maintainers pledge to making participation in our
|
||||
project and our community a harassment-free experience for everyone,
|
||||
regardless of age, body size, disability, ethnicity, gender identity
|
||||
and expression, level of experience, nationality, personal appearance,
|
||||
race, religion, or sexual identity and orientation.
|
||||
|
||||
## Our Standards
|
||||
|
||||
Examples of behavior that contributes to creating a positive
|
||||
environment include:
|
||||
|
||||
* Using welcoming and inclusive language
|
||||
* Being respectful of differing viewpoints and experiences
|
||||
* Gracefully accepting constructive criticism
|
||||
* Focusing on what is best for the community
|
||||
* Showing empathy towards other community members
|
||||
|
||||
Examples of unacceptable behavior by participants include:
|
||||
|
||||
* The use of sexualized language or imagery and unwelcome sexual
|
||||
attention or advances
|
||||
* Trolling, insulting/derogatory comments, and personal or political
|
||||
attacks
|
||||
* Public or private harassment
|
||||
* Publishing others' private information, such as a physical or
|
||||
electronic address, without explicit permission
|
||||
* Other conduct which could reasonably be considered inappropriate in
|
||||
a professional setting
|
||||
|
||||
## Our Responsibilities
|
||||
|
||||
Project maintainers are responsible for clarifying the standards of
|
||||
acceptable behavior and are expected to take appropriate and fair
|
||||
corrective action in response to any instances of unacceptable
|
||||
behavior.
|
||||
|
||||
Project maintainers have the right and responsibility to remove, edit,
|
||||
or reject comments, commits, code, wiki edits, issues, and other
|
||||
contributions that are not aligned to this Code of Conduct, or to ban
|
||||
temporarily or permanently any contributor for other behaviors that
|
||||
they deem inappropriate, threatening, offensive, or harmful.
|
||||
|
||||
## Scope
|
||||
|
||||
This Code of Conduct applies both within project spaces and in public
|
||||
spaces when an individual is representing the project or its
|
||||
community. Examples of representing a project or community include
|
||||
using an official project e-mail address, posting via an official
|
||||
social media account, or acting as an appointed representative at an
|
||||
online or offline event. Representation of a project may be further
|
||||
defined and clarified by project maintainers.
|
||||
|
||||
## Enforcement
|
||||
|
||||
Instances of abusive, harassing, or otherwise unacceptable behavior
|
||||
may be reported by contacting the project team at
|
||||
gergely@polonkai.eu. All complaints will be reviewed and investigated
|
||||
and will result in a response that is deemed necessary and appropriate
|
||||
to the circumstances. The project team is obligated to maintain
|
||||
confidentiality with regard to the reporter of an incident. Further
|
||||
details of specific enforcement policies may be posted separately.
|
||||
|
||||
Project maintainers who do not follow or enforce the Code of Conduct
|
||||
in good faith may face temporary or permanent repercussions as
|
||||
determined by other members of the project's leadership.
|
||||
|
||||
## Attribution
|
||||
|
||||
This Code of Conduct is adapted from the
|
||||
[Contributor Covenant][homepage], version 1.4, available at
|
||||
[http://contributor-covenant.org/version/1/4][version]
|
||||
|
||||
[homepage]: http://contributor-covenant.org
|
||||
[version]: http://contributor-covenant.org/version/1/4/
|
114
CONTRIBUTING.md
Normal file
114
CONTRIBUTING.md
Normal file
@@ -0,0 +1,114 @@
|
||||
# Contributing code to the Matrix GLib SDK
|
||||
|
||||
Everyone is welcome to contribute code to this SDK, provided that they
|
||||
are willing to license their contributions under the same license as
|
||||
the project itself. We follow a simple 'inbound=outbound' model for
|
||||
contributions: the act of submitting an 'inbound' contribution means
|
||||
that the contributor agrees to license the code under the same terms
|
||||
as the project's overall 'outbound' license - which is the GNU Lesser
|
||||
General Public License (see COPYING).
|
||||
|
||||
## How to contribute
|
||||
|
||||
The preferred and easiest way to contribute changes to the Matrix GLib
|
||||
SDK is to fork the project on GitHub, and then create a pull request
|
||||
to ask us to pull your changes into our repo
|
||||
(https://help.github.com/articles/using-pull-requests/)
|
||||
|
||||
**The single biggest thing you need to know is: please base your changes on
|
||||
the develop branch - /not/ master.**
|
||||
|
||||
We use the master branch to track the most recent release, so that
|
||||
folks who blindly clone the repo and automatically check out master
|
||||
get something that works. Develop is the unstable branch where all the
|
||||
development actually happens: the workflow is that contributors should
|
||||
fork the develop branch to make a 'feature' branch for a particular
|
||||
contribution, and then make a pull request to merge this back into the
|
||||
matrix.org 'official' develop branch. We use GitHub's pull request
|
||||
workflow to review the contribution, and either ask you to make any
|
||||
refinements needed or merge it and make them ourselves. The changes
|
||||
will then land on master when we next do a release.
|
||||
|
||||
## Code style
|
||||
|
||||
The projects have a loosely-defined code-style, which is close to
|
||||
GNOME's with a few differences. Check the source files for a hint.
|
||||
|
||||
Please ensure your changes match the cosmetic style of the project,
|
||||
and **never** mix cosmetic and functional changes in the same commit,
|
||||
as it makes it horribly hard to review otherwise.
|
||||
|
||||
## Attribution
|
||||
|
||||
Everyone who contributes anything to this SDK is welcome to be listed in the
|
||||
AUTHORS file for the project in question. Please feel free to include a
|
||||
change to AUTHORS in your pull request to list yourself and a short
|
||||
description of the area(s) you've worked on.
|
||||
|
||||
## Sign off
|
||||
|
||||
In order to have a concrete record that your contribution is
|
||||
intentional and you agree to license it under the same terms as the
|
||||
project's license, we've adopted the same lightweight approach that
|
||||
the
|
||||
[Linux Kernel](https://www.kernel.org/doc/Documentation/SubmittingPatches),
|
||||
[Docker](https://github.com/docker/docker/blob/master/CONTRIBUTING.md),
|
||||
and many other projects use: the DCO
|
||||
([Developer Certificate of Origin](http://developercertificate.org/)). This
|
||||
is a simple declaration that you wrote the contribution or otherwise
|
||||
have the right to contribute it to the SDK:
|
||||
|
||||
Developer Certificate of Origin
|
||||
Version 1.1
|
||||
|
||||
Copyright (C) 2004, 2006 The Linux Foundation and its contributors.
|
||||
660 York Street, Suite 102,
|
||||
San Francisco, CA 94110 USA
|
||||
|
||||
Everyone is permitted to copy and distribute verbatim copies of this
|
||||
license document, but changing it is not allowed.
|
||||
|
||||
Developer's Certificate of Origin 1.1
|
||||
|
||||
By making a contribution to this project, I certify that:
|
||||
|
||||
(a) The contribution was created in whole or in part by me and I
|
||||
have the right to submit it under the open source license
|
||||
indicated in the file; or
|
||||
|
||||
(b) The contribution is based upon previous work that, to the best
|
||||
of my knowledge, is covered under an appropriate open source
|
||||
license and I have the right under that license to submit that
|
||||
work with modifications, whether created in whole or in part
|
||||
by me, under the same open source license (unless I am
|
||||
permitted to submit under a different license), as indicated
|
||||
in the file; or
|
||||
|
||||
(c) The contribution was provided directly to me by some other
|
||||
person who certified (a), (b) or (c) and I have not modified
|
||||
it.
|
||||
|
||||
(d) I understand and agree that this project and the contribution
|
||||
are public and that a record of the contribution (including all
|
||||
personal information I submit with it, including my sign-off) is
|
||||
maintained indefinitely and may be redistributed consistent with
|
||||
this project or the open source license(s) involved.
|
||||
|
||||
If you agree to this for your contribution, then all that's needed is
|
||||
to include the line in your commit or pull request comment:
|
||||
|
||||
Signed-off-by: Your Name <your@email.example.org>
|
||||
|
||||
using your real name; unfortunately pseudonyms and anonymous
|
||||
contributions can't be accepted. Git makes this trivial - just use the
|
||||
`-s` flag when you do `git commit`, having first set `user.name` and
|
||||
`user.email` git configs (which you should have done anyway :)
|
||||
|
||||
## Conclusion
|
||||
|
||||
That's it! Similar to Matrix, this SDK is a very open and project as
|
||||
you might expect given our obsession with open communication. If we're
|
||||
going to successfully matrix together all the fragmented communication
|
||||
technologies out there we are reliant on contributions and
|
||||
collaboration from the community to do so. So please get involved -
|
||||
and we hope you have as much fun hacking on Matrix as we do!
|
31
README.md
31
README.md
@@ -22,8 +22,35 @@ object model to perform actions on.
|
||||
|
||||
## Client
|
||||
|
||||
The `MatrixClient` interface is not fully planned yet.
|
||||
For a working example, see [test-client.c](src/test-client.c).
|
||||
|
||||
// Create a client object
|
||||
MatrixClient *client = MATRIX_CLIENT(matrix_http_client_new("http://localhost:8008"));
|
||||
|
||||
// Set tokens for the session. Alternatively you may want to login with matrix_api_login() or matrix_client_login_with_password()
|
||||
matrix_api_set_token(MATRIX_API(client), "your_access_token");
|
||||
matrix_api_set_refresh_token(MATRIX_API(client), "your_refresh_token");
|
||||
|
||||
// Connect a callback that gets called when a m.room.message event arrives
|
||||
matrix_client_connect_event(client, MATRIX_EVENT_TYPE_ROOM_MESSAGE, message_callback, NULL);
|
||||
|
||||
// Enter polling mode. This continuously calls the /sync API
|
||||
matrix_client_begin_polling(client);
|
||||
|
||||
// Now enter a main loop with g_main_loop_run() so polling for events can actually begin
|
||||
|
||||
## API
|
||||
|
||||
For a full blown example, see [test-client.c](src/test-client.c).
|
||||
For a full blown example, see [test-api-client.c](src/test-api-client.c).
|
||||
|
||||
# Contribution
|
||||
|
||||
See the file [CONTRIBUTING.md](CONTRIBUTING.md) for details.
|
||||
|
||||
# Code of Conduct
|
||||
|
||||
See the file [CODE_OF_CONDUCT.md](CODE_OF_CONDUCT.md) for details.
|
||||
|
||||
# Contact
|
||||
|
||||
Should you need any help, join us in Matrix at #matrix-glib-sdk:polonkai.eu.
|
||||
|
11
configure.ac
11
configure.ac
@@ -90,7 +90,6 @@ AC_SUBST([MATRIX_GLIB_VERSION], matrix_glib_base_version)
|
||||
GLIB_REQUIRED=2.40.0
|
||||
VALA_REQUIRED=0.30.0
|
||||
LIBVALA_REQUIRED=0.30
|
||||
GEE_REQUIRED=0.10.5
|
||||
GIO_REQUIRED=2.22
|
||||
SOUP_REQUIRED=2.44.2
|
||||
JSON_REQUIRED=0.16.2
|
||||
@@ -104,9 +103,6 @@ PKG_CHECK_MODULES([GLIB],
|
||||
# Check for vala
|
||||
VALAC_CHECK
|
||||
|
||||
# Check for libgee
|
||||
PKG_CHECK_MODULES([GEE], [gee-0.8 >= $GEE_REQUIRED])
|
||||
|
||||
# Check for GIO
|
||||
PKG_CHECK_MODULES([GIO], [gio-2.0 >= $GIO_REQUIRED])
|
||||
|
||||
@@ -173,7 +169,7 @@ AC_ARG_ENABLE(debug,
|
||||
AM_CONDITIONAL([DEBUG], [test $debug = yes])
|
||||
|
||||
if test x"$debug" = x"$enableval"; then
|
||||
AC_DEFINE([DEBUG], [1], [Define if debugging should be enabled])
|
||||
AC_DEFINE([DEBUG], [1], [Define as 1 if debugging should be enabled])
|
||||
|
||||
if test x"$cflags_set" != x"set"; then
|
||||
case " $CFLAGS " in
|
||||
@@ -181,6 +177,8 @@ if test x"$debug" = x"$enableval"; then
|
||||
*) CFLAGS="$CFLAGS -g" ;;
|
||||
esac
|
||||
fi
|
||||
else
|
||||
AC_DEFINE([DEBUG], [0], [Define as 1 if debugging should be enabled])
|
||||
fi
|
||||
|
||||
AC_SUBST([MATRIX_GLIB_MAJOR_VERSION], matrix_glib_major_version)
|
||||
@@ -196,11 +194,14 @@ AC_SUBST([MATRIX_GLIB_MICRO_VERSION], matrix_glib_micro_version)
|
||||
AC_SUBST([MATRIX_GLIB_API_VERSION], matrix_glib_api_version)
|
||||
|
||||
AC_PATH_PROG([GLIB_GENMARSHAL], [glib-genmarshal])
|
||||
AC_PATH_PROG([GLIB_MKENUMS], [glib-mkenums])
|
||||
|
||||
AC_CONFIG_FILES([
|
||||
Makefile
|
||||
src/Makefile
|
||||
src/matrix-version.h
|
||||
src/matrix-glib-0.0.pc
|
||||
src/namespace-info.vala
|
||||
docs/Makefile
|
||||
docs/valadoc/Makefile
|
||||
docs/valadoc/gtk-doc/Makefile
|
||||
|
@@ -1,105 +0,0 @@
|
||||
## Process this file with automake to produce Makefile.in
|
||||
|
||||
# We require automake 1.6 at least.
|
||||
AUTOMAKE_OPTIONS = 1.6
|
||||
|
||||
# This is a blank Makefile.am for using gtk-doc.
|
||||
# Copy this to your project's API docs directory and modify the variables to
|
||||
# suit your project. See the GTK+ Makefiles in gtk+/docs/reference for examples
|
||||
# of using the various options.
|
||||
|
||||
# The name of the module, e.g. 'glib'.
|
||||
DOC_MODULE=matrix-glib
|
||||
|
||||
# Uncomment for versioned docs and specify the version of the module, e.g. '2'.
|
||||
DOC_MODULE_VERSION=$(MATRIX_GLIB_API_VERSION)
|
||||
|
||||
|
||||
# The top-level XML file (SGML in the past). You can change this if you want to.
|
||||
DOC_MAIN_SGML_FILE=$(DOC_MODULE)-docs.xml
|
||||
|
||||
# Directories containing the source code.
|
||||
# gtk-doc will search all .c and .h files beneath these paths
|
||||
# for inline comments documenting functions and macros.
|
||||
# e.g. DOC_SOURCE_DIR=$(top_srcdir)/gtk $(top_srcdir)/gdk
|
||||
DOC_SOURCE_DIR=$(top_srcdir)/src
|
||||
|
||||
# Extra options to pass to gtkdoc-scangobj. Not normally needed.
|
||||
SCANGOBJ_OPTIONS=
|
||||
|
||||
# Extra options to supply to gtkdoc-scan.
|
||||
# e.g. SCAN_OPTIONS=--deprecated-guards="GTK_DISABLE_DEPRECATED"
|
||||
SCAN_OPTIONS=--rebuild-types --deprecated-guards="MATRIX_DISABLE_DEPRECATED"
|
||||
|
||||
# Extra options to supply to gtkdoc-mkdb.
|
||||
# e.g. MKDB_OPTIONS=--xml-mode --output-format=xml
|
||||
MKDB_OPTIONS=--xml-mode --output-format=xml
|
||||
|
||||
# Extra options to supply to gtkdoc-mktmpl
|
||||
# e.g. MKTMPL_OPTIONS=--only-section-tmpl
|
||||
MKTMPL_OPTIONS=
|
||||
|
||||
# Extra options to supply to gtkdoc-mkhtml
|
||||
MKHTML_OPTIONS=
|
||||
|
||||
# Extra options to supply to gtkdoc-fixref. Not normally needed.
|
||||
# e.g. FIXXREF_OPTIONS=--extra-dir=../gdk-pixbuf/html --extra-dir=../gdk/html
|
||||
FIXXREF_OPTIONS=
|
||||
|
||||
# Used for dependencies. The docs will be rebuilt if any of these change.
|
||||
# e.g. HFILE_GLOB=$(top_srcdir)/gtk/*.h
|
||||
# e.g. CFILE_GLOB=$(top_srcdir)/gtk/*.c
|
||||
HFILE_GLOB=$(top_srcdir)/src/*.h
|
||||
CFILE_GLOB=$(top_srcdir)/src/*.c
|
||||
|
||||
# Extra header to include when scanning, which are not under DOC_SOURCE_DIR
|
||||
# e.g. EXTRA_HFILES=$(top_srcdir}/contrib/extra.h
|
||||
EXTRA_HFILES=
|
||||
|
||||
# Header files or dirs to ignore when scanning. Use base file/dir names
|
||||
# e.g. IGNORE_HFILES=gtkdebug.h gtkintl.h private_code
|
||||
IGNORE_HFILES =
|
||||
|
||||
# Images to copy into HTML directory.
|
||||
# e.g. HTML_IMAGES=$(top_srcdir)/gtk/stock-icons/stock_about_24.png
|
||||
HTML_IMAGES=
|
||||
|
||||
# Extra SGML files that are included by $(DOC_MAIN_SGML_FILE).
|
||||
# e.g. content_files=running.sgml building.sgml changes-2.0.sgml
|
||||
content_files=
|
||||
|
||||
# SGML files where gtk-doc abbrevations (#GtkWidget) are expanded
|
||||
# These files must be listed here *and* in content_files
|
||||
# e.g. expand_content_files=running.sgml
|
||||
expand_content_files=
|
||||
|
||||
# CFLAGS and LDFLAGS for compiling gtkdoc-scangobj with your library.
|
||||
# Only needed if you are using gtkdoc-scangobj to dynamically query widget
|
||||
# signals and properties.
|
||||
# e.g. GTKDOC_CFLAGS=-I$(top_srcdir) -I$(top_builddir) $(GTK_DEBUG_FLAGS)
|
||||
# e.g. GTKDOC_LIBS=$(top_builddir)/gtk/$(gtktargetlib)
|
||||
GTKDOC_CFLAGS=
|
||||
GTKDOC_LIBS = \
|
||||
$(top_builddir)/src/libmatrix-glib-$(MATRIX_GLIB_API_VERSION).la \
|
||||
$(NULL)
|
||||
|
||||
# This includes the standard gtk-doc make rules, copied by gtkdocize.
|
||||
include $(top_srcdir)/gtk-doc.make
|
||||
|
||||
# Other files to distribute
|
||||
# e.g. EXTRA_DIST += version.xml.in
|
||||
EXTRA_DIST += version.xml.in
|
||||
|
||||
# Files not to distribute
|
||||
# for --rebuild-types in $(SCAN_OPTIONS), e.g. $(DOC_MODULE).types
|
||||
# for --rebuild-sections in $(SCAN_OPTIONS) e.g. $(DOC_MODULE)-sections.txt
|
||||
DISTCLEANFILES = $(DOC_MODULE).types
|
||||
|
||||
# Comment this out if you want 'make check' to test you doc status
|
||||
# and run some sanity checks
|
||||
if ENABLE_GTK_DOC
|
||||
TESTS_ENVIRONMENT = cd $(srcdir) && \
|
||||
DOC_MODULE=$(DOC_MODULE) DOC_MAIN_SGML_FILE=$(DOC_MAIN_SGML_FILE) \
|
||||
SRCDIR=$(abs_srcdir) BUILDDIR=$(abs_builddir)
|
||||
#TESTS = $(GTKDOC_CHECK)
|
||||
endif
|
@@ -1,49 +0,0 @@
|
||||
<?xml version="1.0"?>
|
||||
<!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.3//EN"
|
||||
"http://www.oasis-open.org/docbook/xml/4.3/docbookx.dtd"
|
||||
[
|
||||
<!ENTITY % local.common.attrib "xmlns:xi CDATA #FIXED 'http://www.w3.org/2003/XInclude'">
|
||||
<!ENTITY version SYSTEM "version.xml">
|
||||
<!ENTITY server "gergely.polonkai.eu">
|
||||
]>
|
||||
<book id="index">
|
||||
<bookinfo>
|
||||
<title>Matrix.org GLib SDK Reference Manual</title>
|
||||
<releaseinfo>
|
||||
for Matrix.org GLib SDK &version;.
|
||||
The latest version of this documentation can be found on-line at
|
||||
<ulink role="online-location" url="http://&server;/matrix-glib-sdk/index.html">http://&server;/matrix-glib-sdk/</ulink>.
|
||||
</releaseinfo>
|
||||
</bookinfo>
|
||||
|
||||
<chapter>
|
||||
<title>Matrix Client</title>
|
||||
<section>
|
||||
<title>Types</title>
|
||||
<xi:include href="xml/matrix-types.xml"/>
|
||||
<xi:include href="xml/matrix-event.xml"/>
|
||||
<xi:include href="xml/matrix-presence-event.xml"/>
|
||||
<xi:include href="xml/matrix-room-member-event.xml"/>
|
||||
</section>
|
||||
|
||||
<xi:include href="xml/matrix-client.xml"/>
|
||||
<xi:include href="xml/matrix-http-client.xml"/>
|
||||
<xi:include href="xml/matrix-api.xml"/>
|
||||
<xi:include href="xml/matrix-http-api.xml"/>
|
||||
<xi:include href="xml/matrix-version.xml"/>
|
||||
</chapter>
|
||||
<chapter id="object-tree">
|
||||
<title>Object Hierarchy</title>
|
||||
<xi:include href="xml/tree_index.sgml"/>
|
||||
</chapter>
|
||||
<index id="api-index-full">
|
||||
<title>API Index</title>
|
||||
<xi:include href="xml/api-index-full.xml"><xi:fallback /></xi:include>
|
||||
</index>
|
||||
<index id="deprecated-api-index" role="deprecated">
|
||||
<title>Index of deprecated API</title>
|
||||
<xi:include href="xml/api-index-deprecated.xml"><xi:fallback /></xi:include>
|
||||
</index>
|
||||
|
||||
<xi:include href="xml/annotation-glossary.xml"><xi:fallback /></xi:include>
|
||||
</book>
|
@@ -1,462 +0,0 @@
|
||||
<FILE>matrix-presence-event</FILE>
|
||||
<TITLE>MatrixPresenceEvent</TITLE>
|
||||
matrix_presence_event_set_display_name
|
||||
matrix_presence_event_get_display_name
|
||||
matrix_presence_event_set_avatar_url
|
||||
matrix_presence_event_get_avatar_url
|
||||
matrix_presence_event_set_last_active_ago
|
||||
matrix_presence_event_get_last_active_ago
|
||||
matrix_presence_event_set_presence
|
||||
matrix_presence_event_get_presence
|
||||
|
||||
<SUBSECTION Standard>
|
||||
MatrixPresenceEvent
|
||||
MatrixPresenceEventPrivate
|
||||
MATRIX_TYPE_PRESENCE_EVENT
|
||||
MATRIX_IS_PRESENCE_EVENT
|
||||
MATRIX_IS_PRESENCE_EVENT_CLASS
|
||||
MATRIX_PRESENCE_EVENT
|
||||
MATRIX_PRESENCE_EVENT_CLASS
|
||||
MATRIX_PRESENCE_EVENT_GET_CLASS
|
||||
matrix_presence_event_get_type
|
||||
matrix_presence_event_construct
|
||||
</SECTION>
|
||||
|
||||
<SECTION>
|
||||
<FILE>matrix-room-member-event</FILE>
|
||||
<TITLE>MatrixRoomMemberEvent</TITLE>
|
||||
matrix_room_member_event_set_membership
|
||||
matrix_room_member_event_get_membership
|
||||
matrix_room_member_event_set_state_key
|
||||
matrix_room_member_event_get_state_key
|
||||
matrix_room_member_event_set_avatar_url
|
||||
matrix_room_member_event_get_avatar_url
|
||||
matrix_room_member_event_set_display_name
|
||||
matrix_room_member_event_get_display_name
|
||||
|
||||
<SUBSECTION Standard>
|
||||
MATRIX_IS_ROOM_MEMBER_EVENT
|
||||
MATRIX_IS_ROOM_MEMBER_EVENT_CLASS
|
||||
MATRIX_ROOM_MEMBER_EVENT
|
||||
MATRIX_ROOM_MEMBER_EVENT_CLASS
|
||||
MATRIX_ROOM_MEMBER_EVENT_GET_CLASS
|
||||
MATRIX_TYPE_ROOM_MEMBER_EVENT
|
||||
MatrixRoomMemberEvent
|
||||
MatrixRoomMemberEventPrivate
|
||||
MatrixRoomMemberEventClass
|
||||
matrix_room_member_event_get_type
|
||||
matrix_room_member_event_construct
|
||||
</SECTION>
|
||||
|
||||
<SECTION>
|
||||
<FILE>matrix-event</FILE>
|
||||
<TITLE>MatrixEvent</TITLE>
|
||||
MatrixEventClass
|
||||
matrix_event_register_type
|
||||
matrix_event_unregister_type
|
||||
matrix_event_get_handler
|
||||
matrix_event_new
|
||||
matrix_event_get_event_type
|
||||
matrix_event_set_room_id
|
||||
matrix_event_get_room_id
|
||||
matrix_event_set_origin_server_ts
|
||||
matrix_event_get_origin_server_ts
|
||||
matrix_event_set_sender
|
||||
matrix_event_get_sender
|
||||
matrix_event_set_unsigned_data
|
||||
matrix_event_get_unsigned_data
|
||||
matrix_event_set_custom_field
|
||||
matrix_event_get_custom_field
|
||||
matrix_event_delete_custom_field
|
||||
matrix_event_to_json
|
||||
<SUBSECTION Standard>
|
||||
MatrixEvent
|
||||
MATRIX_EVENT
|
||||
MATRIX_EVENT_CLASS
|
||||
MATRIX_IS_EVENT
|
||||
MATRIX_IS_EVENT_CLASS
|
||||
MATRIX_EVENT_GET_CLASS
|
||||
MATRIX_TYPE_EVENT
|
||||
matrix_event_get_type
|
||||
</SECTION>
|
||||
|
||||
<SECTION>
|
||||
<FILE>matrix-client</FILE>
|
||||
<TITLE>MatrixClient</TITLE>
|
||||
MatrixClient
|
||||
MatrixClientInterface
|
||||
matrix_client_login_finished
|
||||
matrix_client_incoming_event
|
||||
matrix_client_register_with_password
|
||||
matrix_client_login_with_password
|
||||
matrix_client_logout
|
||||
matrix_client_begin_polling
|
||||
matrix_client_stop_polling
|
||||
matrix_client_connect_event
|
||||
|
||||
<SUBSECTION Standard>
|
||||
MATRIX_CLIENT_GET_IFACE
|
||||
MATRIX_CLIENT
|
||||
MATRIX_IS_CLIENT
|
||||
MATRIX_TYPE_CLIENT
|
||||
matrix_client_get_type
|
||||
</SECTION>
|
||||
|
||||
<SECTION>
|
||||
<FILE>matrix-http-client</FILE>
|
||||
<TITLE>MatrixHTTPClient</TITLE>
|
||||
MatrixHTTPClient
|
||||
matrix_http_client_new
|
||||
|
||||
<SUBSECTION Standard>
|
||||
MATRIX_HTTP_CLIENT
|
||||
MATRIX_HTTP_CLIENT_CLASS
|
||||
MATRIX_HTTP_CLIENT_GET_CLASS
|
||||
MATRIX_IS_HTTP_CLIENT
|
||||
MATRIX_IS_HTTP_CLIENT_CLASS
|
||||
MATRIX_TYPE_HTTP_CLIENT
|
||||
MatrixHTTPClientClass
|
||||
matrix_http_client_get_type
|
||||
</SECTION>
|
||||
|
||||
<SECTION>
|
||||
<FILE>matrix-types</FILE>
|
||||
<TITLE>Fundamental types for the Matrix GLib SDK</TITLE>
|
||||
|
||||
<SUBSECTION>
|
||||
MatrixError
|
||||
MATRIX_ERROR
|
||||
|
||||
<SUBSECTION>
|
||||
MatrixEventFormat
|
||||
MatrixRoomPreset
|
||||
MatrixRoomVisibility
|
||||
MatrixResizeMethod
|
||||
MatrixPresence
|
||||
MatrixPusherKind
|
||||
MatrixPusherConditionKind
|
||||
MatrixEventDirection
|
||||
MatrixReceiptType
|
||||
MatrixAccountKind
|
||||
MatrixRoomMembership
|
||||
|
||||
<SUBSECTION>
|
||||
MatrixFilterRules
|
||||
matrix_filter_rules_new
|
||||
matrix_filter_rules_ref
|
||||
matrix_filter_rules_unref
|
||||
matrix_filter_rules_set_limit
|
||||
matrix_filter_rules_get_limit
|
||||
matrix_filter_rules_set_rooms
|
||||
matrix_filter_rules_add_room
|
||||
matrix_filter_rules_delete_room
|
||||
matrix_filter_rules_get_rooms
|
||||
matrix_filter_rules_set_excluded_rooms
|
||||
matrix_filter_rules_add_excluded_room
|
||||
matrix_filter_rules_delete_excluded_room
|
||||
matrix_filter_rules_get_excluded_rooms
|
||||
matrix_filter_rules_set_senders
|
||||
matrix_filter_rules_add_sender
|
||||
matrix_filter_rules_delete_sender
|
||||
matrix_filter_rules_get_senders
|
||||
matrix_filter_rules_set_excluded_senders
|
||||
matrix_filter_rules_add_excluded_sender
|
||||
matrix_filter_rules_delete_excluded_sender
|
||||
matrix_filter_rules_get_excluded_senders
|
||||
matrix_filter_rules_set_types
|
||||
matrix_filter_rules_add_type
|
||||
matrix_filter_rules_delete_type
|
||||
matrix_filter_rules_get_types
|
||||
matrix_filter_rules_set_excluded_types
|
||||
matrix_filter_rules_add_excluded_type
|
||||
matrix_filter_rules_delete_excluded_type
|
||||
matrix_filter_rules_get_excluded_types
|
||||
matrix_filter_rules_get_json_node
|
||||
matrix_filter_rules_get_json_data
|
||||
|
||||
<SUBSECTION>
|
||||
MatrixRoomFilter
|
||||
matrix_room_filter_new
|
||||
matrix_room_filter_ref
|
||||
matrix_room_filter_unref
|
||||
matrix_room_filter_set_include_leave
|
||||
matrix_room_filter_get_include_leave
|
||||
matrix_room_filter_set_ephemeral
|
||||
matrix_room_filter_get_ephemeral
|
||||
matrix_room_filter_set_state
|
||||
matrix_room_filter_get_state
|
||||
matrix_room_filter_set_timeline
|
||||
matrix_room_filter_get_timeline
|
||||
matrix_room_filter_get_json_node
|
||||
matrix_room_filter_get_json_data
|
||||
|
||||
<SUBSECTION>
|
||||
MatrixFilter
|
||||
matrix_filter_new
|
||||
matrix_filter_ref
|
||||
matrix_filter_unref
|
||||
matrix_filter_set_event_fields
|
||||
matrix_filter_add_event_field
|
||||
matrix_filter_delete_event_field
|
||||
matrix_filter_get_event_fields
|
||||
matrix_filter_set_event_format
|
||||
matrix_filter_get_event_format
|
||||
matrix_filter_set_presence_filter
|
||||
matrix_filter_get_presence_filter
|
||||
matrix_filter_set_room_filter
|
||||
matrix_filter_get_room_filter
|
||||
matrix_filter_get_json_node
|
||||
matrix_filter_get_json_data
|
||||
|
||||
<SUBSECTION>
|
||||
Matrix3PidCredential
|
||||
matrix_3pid_credential_new
|
||||
matrix_3pid_credential_ref
|
||||
matrix_3pid_credential_unref
|
||||
matrix_3pid_credential_set_id_server
|
||||
matrix_3pid_credential_get_id_server
|
||||
matrix_3pid_credential_set_session_id
|
||||
matrix_3pid_credential_get_session_id
|
||||
matrix_3pid_credential_set_client_secret
|
||||
matrix_3pid_credential_get_client_secret
|
||||
matrix_3pid_credential_get_json_node
|
||||
matrix_3pid_credential_get_json_data
|
||||
|
||||
<SUBSECTION>
|
||||
MatrixPusher
|
||||
matrix_pusher_new
|
||||
matrix_pusher_ref
|
||||
matrix_pusher_unref
|
||||
matrix_pusher_set_device_display_name
|
||||
matrix_pusher_get_device_display_name
|
||||
matrix_pusher_set_app_display_name
|
||||
matrix_pusher_get_app_display_name
|
||||
matrix_pusher_set_app_id
|
||||
matrix_pusher_get_app_id
|
||||
matrix_pusher_set_append
|
||||
matrix_pusher_get_append
|
||||
matrix_pusher_set_kind
|
||||
matrix_pusher_get_kind
|
||||
matrix_pusher_set_lang
|
||||
matrix_pusher_get_lang
|
||||
matrix_pusher_set_profile_tag
|
||||
matrix_pusher_get_profile_tag
|
||||
matrix_pusher_set_pushkey
|
||||
matrix_pusher_get_pushkey
|
||||
matrix_pusher_set_data
|
||||
matrix_pusher_take_data
|
||||
matrix_pusher_get_data
|
||||
matrix_pusher_get_json_node
|
||||
matrix_pusher_get_json_data
|
||||
|
||||
<SUBSECTION>
|
||||
MatrixStateEvent
|
||||
matrix_state_event_new
|
||||
matrix_state_event_ref
|
||||
matrix_state_event_unref
|
||||
matrix_state_event_set_event_type
|
||||
matrix_state_event_get_event_type
|
||||
matrix_state_event_set_state_key
|
||||
matrix_state_event_get_state_key
|
||||
matrix_state_event_set_content
|
||||
matrix_state_event_get_content
|
||||
matrix_state_event_get_json_node
|
||||
matrix_state_event_get_json_data
|
||||
|
||||
<SUBSECTION>
|
||||
MatrixUnsignedEventData
|
||||
matrix_unsigned_event_data_new
|
||||
matrix_unsigned_event_data_new_from_json
|
||||
matrix_unsigned_event_data_ref
|
||||
matrix_unsigned_event_data_unref
|
||||
matrix_unsigned_event_data_set_age
|
||||
matrix_unsigned_event_data_get_age
|
||||
matrix_unsigned_event_data_set_redact_reason
|
||||
matrix_unsigned_event_data_get_redact_reason
|
||||
matrix_unsigned_event_data_set_transaction_id
|
||||
matrix_unsigned_event_data_get_transaction_id
|
||||
matrix_unsigned_event_data_get_json_node
|
||||
|
||||
<SUBSECTION Standard>
|
||||
MATRIX_TYPE_EVENT_FORMAT
|
||||
matrix_event_format_get_type
|
||||
MATRIX_TYPE_ROOM_PRESET
|
||||
matrix_room_preset_get_type
|
||||
MATRIX_TYPE_ROOM_VISIBILITY
|
||||
matrix_room_visibility_get_type
|
||||
MATRIX_TYPE_RESIZE_METHOD
|
||||
matrix_resize_method_get_type
|
||||
MATRIX_TYPE_PRESENCE
|
||||
matrix_presence_get_type
|
||||
MATRIX_TYPE_PUSHER_KIND
|
||||
matrix_pusher_kind_get_type
|
||||
MATRIX_TYPE_PUSHER_CONDITION_KIND
|
||||
matrix_pusher_condition_kind_get_type
|
||||
MATRIX_TYPE_EVENT_DIRECTION
|
||||
matrix_event_direction_get_type
|
||||
MATRIX_TYPE_RECEIPT_TYPE
|
||||
matrix_receipt_type_get_type
|
||||
MATRIX_TYPE_ACCOUNT_KIND
|
||||
matrix_account_kind_get_type
|
||||
MATRIX_TYPE_ROOM_MEMBERSHIP
|
||||
matrix_room_membership_get_type
|
||||
MATRIX_TYPE_FILTER_RULES
|
||||
matrix_filter_rules_get_type
|
||||
MATRIX_TYPE_ROOM_FILTER
|
||||
matrix_room_filter_get_type
|
||||
MATRIX_TYPE_FILTER
|
||||
matrix_filter_get_type
|
||||
MATRIX_TYPE_3PID_CREDENTIAL
|
||||
matrix_3pid_credential_get_type
|
||||
MATRIX_TYPE_PUSHER
|
||||
matrix_pusher_get_type
|
||||
MATRIX_TYPE_STATE_EVENT
|
||||
matrix_state_event_get_type
|
||||
MATRIX_TYPE_UNSIGNED_EVENT_DATA
|
||||
matrix_unsigned_event_data_get_type
|
||||
</SECTION>
|
||||
|
||||
<SECTION>
|
||||
<FILE>matrix-api</FILE>
|
||||
<TITLE>MatrixAPI</TITLE>
|
||||
MatrixAPIInterface
|
||||
MatrixAPICallback
|
||||
MATRIX_API_CALLBACK
|
||||
MATRIX_API_CALLBACK_PROTO
|
||||
|
||||
<SUBSECTION>
|
||||
matrix_api_set_token
|
||||
matrix_api_get_token
|
||||
matrix_api_set_refresh_token
|
||||
matrix_api_get_refresh_token
|
||||
matrix_api_get_user_id
|
||||
matrix_api_get_homeserver
|
||||
|
||||
<SUBSECTION>
|
||||
matrix_api_media_download
|
||||
matrix_api_media_thumbnail
|
||||
matrix_api_media_upload
|
||||
|
||||
<SUBSECTION>
|
||||
matrix_api_get_presence_list
|
||||
matrix_api_update_presence_list
|
||||
matrix_api_get_user_presence
|
||||
matrix_api_set_user_presence
|
||||
|
||||
<SUBSECTION>
|
||||
matrix_api_update_pusher
|
||||
matrix_api_get_pushers
|
||||
matrix_api_delete_pusher
|
||||
matrix_api_get_pusher
|
||||
matrix_api_add_pusher
|
||||
matrix_api_toggle_pusher
|
||||
|
||||
<SUBSECTION>
|
||||
matrix_api_create_room
|
||||
|
||||
<SUBSECTION>
|
||||
matrix_api_delete_room_alias
|
||||
matrix_api_get_room_id
|
||||
matrix_api_create_room_alias
|
||||
|
||||
<SUBSECTION>
|
||||
matrix_api_list_public_rooms
|
||||
|
||||
<SUBSECTION>
|
||||
matrix_api_ban_user
|
||||
matrix_api_forget_room
|
||||
matrix_api_invite_user_3rdparty
|
||||
matrix_api_invite_user
|
||||
matrix_api_join_room
|
||||
matrix_api_leave_room
|
||||
|
||||
<SUBSECTION>
|
||||
matrix_api_event_stream
|
||||
matrix_api_get_event
|
||||
matrix_api_initial_sync
|
||||
matrix_api_get_event_context
|
||||
matrix_api_initial_sync_room
|
||||
matrix_api_list_room_members
|
||||
matrix_api_list_room_messages
|
||||
matrix_api_send_event_receipt
|
||||
matrix_api_redact_event
|
||||
matrix_api_send_message_event
|
||||
matrix_api_get_room_state
|
||||
matrix_api_send_room_event
|
||||
matrix_api_notify_room_typing
|
||||
matrix_api_sync
|
||||
matrix_api_create_filter
|
||||
matrix_api_download_filter
|
||||
|
||||
<SUBSECTION>
|
||||
matrix_api_whois
|
||||
matrix_api_versions
|
||||
|
||||
<SUBSECTION>
|
||||
matrix_api_login
|
||||
matrix_api_token_refresh
|
||||
|
||||
<SUBSECTION>
|
||||
matrix_api_get_3pids
|
||||
matrix_api_add_3pid
|
||||
matrix_api_change_password
|
||||
matrix_api_get_profile
|
||||
matrix_api_get_avatar_url
|
||||
matrix_api_set_avatar_url
|
||||
matrix_api_get_display_name
|
||||
matrix_api_set_display_name
|
||||
matrix_api_register_account
|
||||
matrix_api_set_account_data
|
||||
matrix_api_get_room_tags
|
||||
matrix_api_delete_room_tag
|
||||
matrix_api_add_room_tag
|
||||
|
||||
<SUBSECTION>
|
||||
matrix_api_get_turn_server
|
||||
|
||||
<SUBSECTION>
|
||||
matrix_api_abort_pending
|
||||
|
||||
<SUBSECTION Standard>
|
||||
MatrixAPI
|
||||
MATRIX_TYPE_ERROR
|
||||
matrix_error_get_type
|
||||
MATRIX_TYPE_API
|
||||
MATRIX_API
|
||||
MATRIX_IS_API
|
||||
MATRIX_API_GET_IFACE
|
||||
MatrixApiPrivate
|
||||
matrix_api_get_type
|
||||
|
||||
<SUBSECTION Private>
|
||||
matrix_error_quark
|
||||
</SECTION>
|
||||
|
||||
<SECTION>
|
||||
<FILE>matrix-http-api</FILE>
|
||||
matrix_http_api_new
|
||||
matrix_http_api_set_validate_certificate
|
||||
matrix_http_api_get_validate_certificate
|
||||
matrix_http_api_set_base_url
|
||||
matrix_http_api_get_base_url
|
||||
|
||||
<SUBSECTION Standard>
|
||||
MatrixHTTPAPI
|
||||
MatrixHTTPAPIClass
|
||||
MATRIX_TYPE_HTTP_API
|
||||
MATRIX_HTTP_API
|
||||
MATRIX_HTTP_API_CLASS
|
||||
MATRIX_IS_HTTP_API
|
||||
MATRIX_IS_HTTP_API_CLASS
|
||||
MATRIX_HTTP_API_GET_CLASS
|
||||
matrix_http_api_get_type
|
||||
</SECTION>
|
||||
|
||||
<SECTION>
|
||||
<FILE>matrix-version</FILE>
|
||||
MATRIX_GLIB_MAJOR_VERSION
|
||||
MATRIX_GLIB_MINOR_VERSION
|
||||
MATRIX_GLIB_MICRO_VERSION
|
||||
MATRIX_GLIB_CHECK_VERSION
|
||||
matrix_glib_check_version
|
||||
</SECTION>
|
@@ -1 +0,0 @@
|
||||
@MATRIX_GLIB_API_VERSION@
|
103
src/Makefile.am
103
src/Makefile.am
@@ -16,18 +16,48 @@ lib_LTLIBRARIES = libmatrix-glib-0.0.la
|
||||
|
||||
# Vala source files
|
||||
libmatrix_glib_0_0_la_VALA_SOURCES = \
|
||||
namespace-info.vala \
|
||||
matrix-api.vala \
|
||||
matrix-client.vala \
|
||||
matrix-enums.vala \
|
||||
matrix-http-api.vala \
|
||||
matrix-http-client.vala \
|
||||
matrix-compacts.vala \
|
||||
matrix-event.vala \
|
||||
matrix-presence-event.vala \
|
||||
matrix-state-event.vala \
|
||||
matrix-room-event.vala \
|
||||
matrix-room-member-event.vala \
|
||||
matrix-room-message-event.vala \
|
||||
matrix-event-base.vala \
|
||||
matrix-event-room-base.vala \
|
||||
matrix-event-state-base.vala \
|
||||
matrix-event-presence.vala \
|
||||
matrix-event-room-member.vala \
|
||||
matrix-event-room-message.vala \
|
||||
matrix-event-room-topic.vala \
|
||||
matrix-event-typing.vala \
|
||||
matrix-event-room-aliases.vala \
|
||||
matrix-event-receipt.vala \
|
||||
matrix-event-room-history-visibility.vala \
|
||||
matrix-event-room-join-rules.vala \
|
||||
matrix-event-room-name.vala \
|
||||
matrix-event-tag.vala \
|
||||
matrix-event-room-canonical-alias.vala \
|
||||
matrix-event-room-create.vala \
|
||||
matrix-event-room-power-levels.vala \
|
||||
matrix-event-room-avatar.vala \
|
||||
matrix-event-room-message-feedback.vala \
|
||||
matrix-event-room-guest-access.vala \
|
||||
matrix-event-room-redaction.vala \
|
||||
matrix-event-room-third-party-invite.vala \
|
||||
matrix-event-call-base.vala \
|
||||
matrix-event-call-invite.vala \
|
||||
matrix-event-call-candidates.vala \
|
||||
matrix-event-call-answer.vala \
|
||||
matrix-event-call-hangup.vala \
|
||||
matrix-message-base.vala \
|
||||
matrix-message-text.vala \
|
||||
matrix-message-emote.vala \
|
||||
matrix-message-notice.vala \
|
||||
matrix-message-file.vala \
|
||||
matrix-message-image.vala \
|
||||
matrix-message-audio.vala \
|
||||
matrix-message-video.vala \
|
||||
matrix-message-location.vala \
|
||||
matrix-room.vala \
|
||||
$(NULL)
|
||||
|
||||
AM_CPPFLAGS += \
|
||||
@@ -39,7 +69,6 @@ AM_CPPFLAGS += \
|
||||
$(GOBJECT_CFLAGS) \
|
||||
$(SOUP_CFLAGS) \
|
||||
$(JSON_CFLAGS) \
|
||||
$(GEE_CFLAGS) \
|
||||
$(VALA_CFLAGS) \
|
||||
$(NULL)
|
||||
|
||||
@@ -51,7 +80,7 @@ AM_VALAFLAGS += \
|
||||
-C \
|
||||
--use-header \
|
||||
--gir=Matrix-$(MATRIX_GLIB_API_VERSION).gir \
|
||||
$(top_srcdir)/src/c-api.vapi \
|
||||
--vapidir=$(top_srcdir)/vapi \
|
||||
$(NULL)
|
||||
|
||||
vala-stamp: $(libmatrix_glib_0_0_la_VALA_SOURCES)
|
||||
@@ -82,19 +111,33 @@ $(libmatrix_glib_0_0_la_VALA_SOURCES:.vala=.c): vala-stamp
|
||||
bin_PROGRAMS = test-api-client test-client
|
||||
|
||||
INST_H_SRC_FILES = \
|
||||
matrix-types.h \
|
||||
matrix-compacts.h \
|
||||
utils.h \
|
||||
matrix-profile.h \
|
||||
$(NULL)
|
||||
|
||||
INST_H_BUILT_FILES = \
|
||||
matrix-version.h \
|
||||
matrix-enumtypes.h \
|
||||
matrix-marshalers.h \
|
||||
$(NULL)
|
||||
|
||||
matrix_enum_headers = \
|
||||
matrix-types.h \
|
||||
$(NULL)
|
||||
|
||||
libmatrix_glib_0_0_la_SOURCES = \
|
||||
$(INST_H_BUILT_FILES) \
|
||||
matrix-marshalers.c \
|
||||
$(libmatrix_glib_0_0_la_VALA_SOURCES:.vala=.c) \
|
||||
matrix-event-types.c \
|
||||
matrix-version.c \
|
||||
matrix-types.c \
|
||||
matrix-compacts.c \
|
||||
matrix-profile.c \
|
||||
utils.c \
|
||||
matrix-enumtypes.c \
|
||||
$(INST_H_SRC_FILES) \
|
||||
$(NULL)
|
||||
|
||||
@@ -103,7 +146,6 @@ libmatrix_glib_0_0_la_CFLAGS = \
|
||||
$(GOBJECT_CFLAGS) \
|
||||
$(SOUP_CFLAGS) \
|
||||
$(JSON_CFLAGS) \
|
||||
$(GEE_CFLAGS) \
|
||||
$(NULL)
|
||||
|
||||
libmatrix_glib_0_0_la_LIBADD = \
|
||||
@@ -111,7 +153,6 @@ libmatrix_glib_0_0_la_LIBADD = \
|
||||
$(GOBJECT_LIBS) \
|
||||
$(SOUP_LIBS) \
|
||||
$(JSON_LIBS) \
|
||||
$(GEE_LIBS) \
|
||||
$(NULL)
|
||||
|
||||
libmatrix_glib_0_0_la_LDFLAGS = \
|
||||
@@ -127,6 +168,8 @@ dist_vapi_DATA = \
|
||||
$(NULL)
|
||||
|
||||
BUILT_SOURCES += \
|
||||
matrix-enumtypes.c \
|
||||
matrix-enumtypes.h \
|
||||
matrix-marshalers.c \
|
||||
matrix-marshalers.h \
|
||||
$(NULL)
|
||||
@@ -147,10 +190,22 @@ test_client_LDADD = \
|
||||
|
||||
CLEANFILES += $(BUILT_SOURCES)
|
||||
EXTRA_DIST += \
|
||||
matrix-enumtypes.h.template \
|
||||
matrix-enumtypes.c.template \
|
||||
matrix-marshalers.list \
|
||||
$(INST_H_SRC_FILES) \
|
||||
$(NULL)
|
||||
|
||||
matrix-enumtypes.h: $(matrix_enum_headers) matrix-enumtypes.h.template
|
||||
$(AM_V_GEN) $(GLIB_MKENUMS) --template $(filter %.template,$^) \
|
||||
$(filter-out %.template,$^) > $@.tmp \
|
||||
&& mv $@.tmp $@
|
||||
|
||||
matrix-enumtypes.c: $(matrix_enum_headers) matrix-enumtypes.h matrix-enumtypes.c.template
|
||||
$(AM_V_GEN) $(GLIB_MKENUMS) --template $(filter %.template,$^) \
|
||||
$(filter-out %.template,$^) > $@.tmp \
|
||||
&& mv $@.tmp $@
|
||||
|
||||
matrix-marshalers.h: stamp-matrix-marshalers
|
||||
@true
|
||||
|
||||
@@ -176,11 +231,22 @@ matrix-marshalers.c: matrix-marshalers.h
|
||||
|
||||
CLEANFILES += stamp-matrix-marshalers
|
||||
|
||||
include $(INTROSPECTION_MAKEFILE)
|
||||
Matrix-0.0.gir: libmatrix-glib-$(MATRIX_GLIB_API_VERSION).la
|
||||
limtatrix_glib_dlname = \
|
||||
`$(SED) -nE "s/^dlname='([A-Za-z0-9.+-]+)'/\1/p" libmatrix-glib-0.0.la`¬
|
||||
INTROSPECTION_GIRS = Matrix-$(MATRIX_GLIB_API_VERSION).gir
|
||||
INTROSPECTION_COMPILER_ARGS = --includedir=. $(libmatrix_glib_dlname)
|
||||
|
||||
Matrix-0.0.gir: libmatrix-glib-$(MATRIX_GLIB_API_VERSION).la
|
||||
Matrix-0.0.typelib: $(INTROSPECTION_GIRS)
|
||||
$(INTROSPECTION_COMPILER) $(INTROSPECTION_COMPILER_ARGS) $< -o $@
|
||||
|
||||
girdir = $(INTROSPECTION_GIRDIR)
|
||||
gir_DATA = $(INTROSPECTION_GIRS)
|
||||
typelibdir = $(INTROSPECTION_TYPELIBDIR)
|
||||
typelib_DATA = Matrix-$(MATRIX_GLIB_API_VERSION).typelib
|
||||
|
||||
CLEANFILES += $(gir_DATA) $(typelibs_DATA)
|
||||
|
||||
typelibsdir = $(libdir)/girepository-1.0
|
||||
typelibs_DATA = Matrix-$(MATRIX_GLIB_API_VERSION).typelib
|
||||
|
||||
headerdir = $(includedir)/matrix-glib-$(MATRIX_GLIB_API_VERSION)
|
||||
header_DATA = \
|
||||
@@ -189,4 +255,7 @@ header_DATA = \
|
||||
$(INST_H_BUILT_FILES) \
|
||||
$(NULL)
|
||||
|
||||
CLEANFILES += $(typelibs_DATA)
|
||||
pkgconfig_in = matrix-glib-$(MATRIX_GLIB_API_VERSION).pc.in
|
||||
pkgconfigdir = $(libdir)/pkgconfig
|
||||
pkgconfig_DATA = $(pkgconfig_in:.in=)
|
||||
EXTRA_DIST += $(pkgconfig_in)
|
||||
|
@@ -1,4 +1,3 @@
|
||||
gio-2.0
|
||||
Json-1.0
|
||||
gee-0.8
|
||||
libsoup-2.4
|
||||
|
@@ -1,52 +0,0 @@
|
||||
/*
|
||||
* This file is part of matrix-glib-sdk
|
||||
*
|
||||
* matrix-glib-sdk is free software: you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation, either
|
||||
* version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* matrix-glib-sdk is distributed in the hope that it will be
|
||||
* useful, but WITHOUT ANY WARRANTY; without even the implied
|
||||
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
* See the GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with matrix-glib-sdk. If not, see
|
||||
* <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
[CCode (cprefix = "Matrix", gir_namespace = "Matrix", gir_version = "0.0", lower_case_cprefix = "matrix_")]
|
||||
namespace Matrix {
|
||||
/**
|
||||
* The major version number of the Matrix.org GLib SDK.
|
||||
*/
|
||||
[CCode (cheader_filename = "matrix-version.h", cname = "MATRIX_GLIB_MAJOR_VERSION")]
|
||||
public const int GLIB_MAJOR_VERSION;
|
||||
|
||||
/**
|
||||
* The micro (patch) version number of the Matrix.org GLib SDK.
|
||||
*/
|
||||
[CCode (cheader_filename = "matrix-version.h", cname = "MATRIX_GLIB_MINOR_VERSION")]
|
||||
public const int GLIB_MINOR_VERSION;
|
||||
|
||||
/**
|
||||
* The minor version number of the Matrix.org GLib SDK.
|
||||
*/
|
||||
[CCode (cheader_filename = "matrix-version.h", cname = "MATRIX_GLIB_MICRO_VERSION")]
|
||||
public const int GLIB_MICRO_VERSION;
|
||||
|
||||
/**
|
||||
* Check that the Matrix.org GLib SDK in use is compatible with
|
||||
* the given version.
|
||||
*
|
||||
* @param required_major the required major version
|
||||
* @param required_minor the required minor version
|
||||
* @param required_micro the required micro version
|
||||
* @return {{{true}}} if the required version is satisfied; {{{false}}} otherwise.
|
||||
*/
|
||||
[CCode (cheader_filename = "matrix-version.h", cname = "matrix_glib_check_version")]
|
||||
public bool glib_check_version(uint required_major,
|
||||
uint required_minor,
|
||||
uint required_micro);
|
||||
}
|
1987
src/matrix-api.vala
1987
src/matrix-api.vala
File diff suppressed because it is too large
Load Diff
@@ -47,9 +47,27 @@ public interface Matrix.Client : GLib.Object {
|
||||
*/
|
||||
[Signal (detailed=true)]
|
||||
public virtual signal void
|
||||
@event(string? room_id, Json.Node raw_event, Matrix.Event matrix_event)
|
||||
@event(string? room_id,
|
||||
Json.Node raw_event,
|
||||
Matrix.Event.Base? matrix_event)
|
||||
{}
|
||||
|
||||
/**
|
||||
* This signal is emitted when polling is started.
|
||||
*/
|
||||
public signal void
|
||||
polling_started();
|
||||
|
||||
/**
|
||||
* This signal gets invoked when polling is stopped due to any
|
||||
* reason.
|
||||
*
|
||||
* @param error gets set to an actual error if polling is stopped
|
||||
* due to one
|
||||
*/
|
||||
public signal void
|
||||
polling_stopped(GLib.Error? error);
|
||||
|
||||
/**
|
||||
* Callback function delegate for the event signal.
|
||||
*
|
||||
@@ -61,7 +79,7 @@ public interface Matrix.Client : GLib.Object {
|
||||
EventCallback(Matrix.Client client,
|
||||
string? room_id,
|
||||
Json.Node raw_event,
|
||||
Matrix.Event matrix_event);
|
||||
Matrix.Event.Base? matrix_event);
|
||||
|
||||
/**
|
||||
* Authenticate with the Matrix.org server with a username and
|
||||
@@ -144,9 +162,15 @@ public interface Matrix.Client : GLib.Object {
|
||||
public void
|
||||
incoming_event(string? room_id,
|
||||
Json.Node raw_event,
|
||||
Matrix.Event matrix_event)
|
||||
Matrix.Event.Base? matrix_event)
|
||||
{
|
||||
Quark equark = matrix_event.get_type().qname();
|
||||
Quark equark;
|
||||
|
||||
if (matrix_event == null) {
|
||||
equark = typeof(Matrix.Event.Base).qname();
|
||||
} else {
|
||||
equark = matrix_event.get_type().qname();
|
||||
}
|
||||
|
||||
this.@event[equark.to_string()](room_id, raw_event, matrix_event);
|
||||
}
|
||||
@@ -161,9 +185,103 @@ public interface Matrix.Client : GLib.Object {
|
||||
*
|
||||
* @param event_gtype the {@link GLib.Type} of a
|
||||
* {@link Matrix.Event} derivative
|
||||
* @param callback the allback function to connect
|
||||
* @param event_callback the allback function to connect
|
||||
*/
|
||||
public extern void
|
||||
connect_event(GLib.Type event_gtype,
|
||||
owned EventCallback event_callback);
|
||||
|
||||
/**
|
||||
* Get the profile of a user specified by @param user_id.
|
||||
* If @param room_id is not null, return the room-specific
|
||||
* profile. If the user's profile is not cached yet,
|
||||
* Matrix.Error.UNAVAILABLE is thrown.
|
||||
*/
|
||||
public abstract Profile?
|
||||
get_user_profile(string user_id, string? room_id = null)
|
||||
throws Matrix.Error;
|
||||
|
||||
/**
|
||||
* Get the presence state of a user specified
|
||||
* by @param user_id. If @param room_id is null, return
|
||||
* the room specific presence state. If the user's presence
|
||||
* state is not cached yet, Matrix.Error.UNAVAILABLE is
|
||||
* thrown.
|
||||
*/
|
||||
public abstract Presence
|
||||
get_user_presence(string user_id, string? room_id = null)
|
||||
throws Matrix.Error;
|
||||
|
||||
/**
|
||||
* Get a room object by the room ID specified in @param room_id.
|
||||
* If room data is not cached yet, Matrix.Error.UNAVAILABLE is
|
||||
* thrown.
|
||||
*
|
||||
* @param room_id the ID of a room
|
||||
* @return a Matrix.Room object
|
||||
*/
|
||||
public abstract Room
|
||||
get_room_by_id(string room_id)
|
||||
throws Matrix.Error;
|
||||
|
||||
/**
|
||||
* Get a room object by the room alias specified
|
||||
* in @param room_alias. If room data is not cached yet,
|
||||
* {@link Matrix.Error.UNAVAILABLE} is thrown.
|
||||
*
|
||||
* @param room_alias a room alias
|
||||
* @return a Matrix.Room object
|
||||
*/
|
||||
public abstract Room
|
||||
get_room_by_alias(string room_alias)
|
||||
throws Matrix.Error;
|
||||
|
||||
/**
|
||||
* Callback type for {@link Matrix.Client.send}.
|
||||
*
|
||||
* @param event_id the event_id returned by the server
|
||||
* @param err an error raised during event sending, if any
|
||||
*/
|
||||
public delegate void
|
||||
SendCallback(string? event_id, GLib.Error? err);
|
||||
|
||||
/**
|
||||
* Send an event to the given room. This will use the
|
||||
* /room/{roomId}/send or /room/{roomId}/state API depending on
|
||||
* the event: if the event has a state key (there is a state_key
|
||||
* key in the generated JSON), even if an empty one, it will use
|
||||
* the latter.
|
||||
*
|
||||
* @param room_id the room to send the event to
|
||||
* @param evt the event to send
|
||||
* @param cb the callback function to call when the request is
|
||||
* finished
|
||||
* @param txn_id the transaction ID used by this request. In case
|
||||
* of a state event, it will be untouched
|
||||
*/
|
||||
public abstract void
|
||||
send(string room_id,
|
||||
Matrix.Event.Base evt,
|
||||
SendCallback? cb,
|
||||
out ulong txn_id)
|
||||
throws Matrix.Error;
|
||||
|
||||
/*
|
||||
* Save the state of the client. Implementors can choose what they
|
||||
* actually save, and in what format.
|
||||
*
|
||||
* @param filename the name of the file to save state to
|
||||
*/
|
||||
public abstract void
|
||||
save_state(string filename)
|
||||
throws Matrix.Error, GLib.Error;
|
||||
|
||||
/**
|
||||
* Load the state of the client, as saved by save_state().
|
||||
*
|
||||
* @param filename the name of the file to load state from
|
||||
*/
|
||||
public abstract void
|
||||
load_state(string filename)
|
||||
throws Matrix.Error, GLib.Error;
|
||||
}
|
||||
|
3093
src/matrix-compacts.c
Normal file
3093
src/matrix-compacts.c
Normal file
File diff suppressed because it is too large
Load Diff
236
src/matrix-compacts.h
Normal file
236
src/matrix-compacts.h
Normal file
@@ -0,0 +1,236 @@
|
||||
/*
|
||||
* This file is part of matrix-glib-sdk
|
||||
*
|
||||
* matrix-glib-sdk is free software: you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation, either
|
||||
* version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* matrix-glib-sdk is distributed in the hope that it will be
|
||||
* useful, but WITHOUT ANY WARRANTY; without even the implied
|
||||
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
* See the GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with matrix-glib-sdk. If not, see
|
||||
* <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef __MATRIX_GLIB_SDK_COMPACTS_H__
|
||||
# define __MATRIX_GLIB_SDK_COMPACTS_H__
|
||||
|
||||
# include <glib-object.h>
|
||||
# include <json-glib/json-glib.h>
|
||||
|
||||
# include "matrix-types.h"
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
# define MATRIX_TYPE_JSON_COMPACT matrix_json_compact_get_type()
|
||||
# define MATRIX_JSON_COMPACT(o) (G_TYPE_CHECK_INSTANCE_CAST((o), MATRIX_TYPE_JSON_COMPACT, MatrixJsonCompact))
|
||||
# define MATRIX_JSON_COMPACT_CLASS(c) (G_TYPE_CHECK_CLASS_CAST((c), MATRIX_TYPE_JSON_COMPACT, MatrixJsonCompactClass))
|
||||
# define MATRIX_IS_JSON_COMPACT(o) (G_TYPE_CHECK_INSTANCE_TYPE((o), MATRIX_TYPE_JSON_COMPACT))
|
||||
# define MATRIX_IS_JSON_COMPACT_CLASS(c) (G_TYPE_CHECK_CLASS_TYPE((c), MATRIX_TYPE_JSON_COMPACT))
|
||||
# define MATRIX_JSON_COMPACT_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS((o), MATRIX_TYPE_JSON_COMPACT, MatrixJsonCompactClass))
|
||||
|
||||
typedef struct _MatrixJsonCompactClass MatrixJsonCompactClass;
|
||||
typedef struct _MatrixJsonCompact MatrixJsonCompact;
|
||||
void matrix_json_compact_unref(MatrixJsonCompact *json_compact);
|
||||
G_DEFINE_AUTOPTR_CLEANUP_FUNC(MatrixJsonCompact, matrix_json_compact_unref)
|
||||
|
||||
struct _MatrixJsonCompact {
|
||||
GTypeInstance parent_instance;
|
||||
|
||||
/* < private > */
|
||||
volatile int refcount;
|
||||
};
|
||||
|
||||
struct _MatrixJsonCompactClass {
|
||||
GTypeClass parent_class;
|
||||
|
||||
void (*finalize)(MatrixJsonCompact *json_compact);
|
||||
JsonNode *(*get_json_node)(MatrixJsonCompact *json_compact, GError **error);
|
||||
};
|
||||
|
||||
GType matrix_json_compact_get_type(void) G_GNUC_CONST;
|
||||
MatrixJsonCompact *matrix_json_compact_construct(GType object_type);
|
||||
MatrixJsonCompact *matrix_json_compact_ref(MatrixJsonCompact *json_compact);
|
||||
JsonNode *matrix_json_compact_get_json_node(MatrixJsonCompact *json_compact, GError **error);
|
||||
gchar *matrix_json_compact_get_json_data(MatrixJsonCompact *json_compact, gsize *datalen, GError **error);
|
||||
|
||||
#define MATRIX_TYPE_FILTER_RULES matrix_filter_rules_get_type()
|
||||
G_DECLARE_DERIVABLE_TYPE(MatrixFilterRules, matrix_filter_rules, MATRIX, FILTER_RULES, MatrixJsonCompact)
|
||||
|
||||
struct _MatrixFilterRulesClass {
|
||||
MatrixJsonCompactClass parent_class;
|
||||
};
|
||||
|
||||
MatrixFilterRules *matrix_filter_rules_new(void);
|
||||
MatrixFilterRules *matrix_filter_rules_construct(GType object_type);
|
||||
void matrix_filter_rules_set_limit(MatrixFilterRules *filter_rules, guint limit);
|
||||
guint matrix_filter_rules_get_limit(MatrixFilterRules *filter_rules);
|
||||
void matrix_filter_rules_set_types(MatrixFilterRules *filter_rules, gchar **types, int n_types);
|
||||
gchar **matrix_filter_rules_get_types(MatrixFilterRules *filter_rules, int *n_types);
|
||||
void matrix_filter_rules_set_excluded_types(MatrixFilterRules *filter_rules, gchar **excluded_types, int n_excluded_types);
|
||||
gchar **matrix_filter_rules_get_excluded_types(MatrixFilterRules *filter_rules, int *n_excluded_types);
|
||||
void matrix_filter_rules_set_senders(MatrixFilterRules *filter_rules, gchar **senders, int n_senders);
|
||||
gchar **matrix_filter_rules_get_senders(MatrixFilterRules *filter_rules, int *n_senders);
|
||||
void matrix_filter_rules_set_excluded_senders(MatrixFilterRules *filter_rules, gchar **excluded_senders, int n_excluded_senders);
|
||||
gchar **matrix_filter_rules_get_excluded_senders(MatrixFilterRules *filter_rules, int *n_excluded_senders);
|
||||
void matrix_filter_rules_set_rooms(MatrixFilterRules *filter_rules, gchar **rooms, int n_rooms);
|
||||
gchar **matrix_filter_rules_get_rooms(MatrixFilterRules *filter_rules, int *n_rooms);
|
||||
void matrix_filter_rules_set_excluded_rooms(MatrixFilterRules *filter_rules, gchar **excluded_rooms, int n_excluded_rooms);
|
||||
gchar **matrix_filter_rules_get_excluded_rooms(MatrixFilterRules *filter_rules, int *n_excluded_rooms);
|
||||
|
||||
# define MATRIX_TYPE_ROOM_FILTER matrix_room_filter_get_type()
|
||||
G_DECLARE_DERIVABLE_TYPE(MatrixRoomFilter, matrix_room_filter, MATRIX, ROOM_FILTER, MatrixJsonCompact)
|
||||
|
||||
struct _MatrixRoomFilterClass {
|
||||
MatrixJsonCompactClass parent_class;
|
||||
};
|
||||
|
||||
MatrixRoomFilter *matrix_room_filter_new(void);
|
||||
gboolean matrix_room_filter_get_include_leave(MatrixRoomFilter *room_filter);
|
||||
void matrix_room_filter_set_include_leave(MatrixRoomFilter *room_filter, gboolean include_leave);
|
||||
MatrixFilterRules *matrix_room_filter_get_ephemeral(MatrixRoomFilter *room_filter);
|
||||
void matrix_room_filter_set_ephemeral(MatrixRoomFilter *room_filter, MatrixFilterRules *ephemeral_rules);
|
||||
MatrixFilterRules *matrix_room_filter_get_state(MatrixRoomFilter *room_filter);
|
||||
void matrix_room_filter_set_state(MatrixRoomFilter *room_filter, MatrixFilterRules *state_rules);
|
||||
MatrixFilterRules *matrix_room_filter_get_timeline(MatrixRoomFilter *room_filter);
|
||||
void matrix_room_filter_set_timeline(MatrixRoomFilter *room_filter, MatrixFilterRules *timeline_rules);
|
||||
|
||||
# define MATRIX_TYPE_FILTER matrix_filter_get_type()
|
||||
G_DECLARE_DERIVABLE_TYPE(MatrixFilter, matrix_filter, MATRIX, FILTER, MatrixJsonCompact)
|
||||
|
||||
struct _MatrixFilterClass {
|
||||
MatrixJsonCompactClass parent_class;
|
||||
};
|
||||
|
||||
MatrixFilter *matrix_filter_new(void);
|
||||
gchar **matrix_filter_get_event_fields(MatrixFilter *filter, int *n_event_fields);
|
||||
void matrix_filter_set_event_fields(MatrixFilter *filter, gchar **event_fields, int n_event_fields);
|
||||
MatrixEventFormat matrix_filter_get_event_format(MatrixFilter *filter);
|
||||
void matrix_filter_set_event_format(MatrixFilter *filter, MatrixEventFormat event_format);
|
||||
MatrixFilterRules *matrix_filter_get_presence_filter(MatrixFilter *filter);
|
||||
void matrix_filter_set_presence_filter(MatrixFilter *filter, MatrixFilterRules *presence_filter);
|
||||
MatrixRoomFilter *matrix_filter_get_room_filter(MatrixFilter *filter);
|
||||
void matrix_filter_set_room_filter(MatrixFilter *filter, MatrixRoomFilter *room_filter);
|
||||
|
||||
# define MATRIX_TYPE_3PID_CREDENTIAL matrix_3pid_credential_get_type()
|
||||
G_DECLARE_DERIVABLE_TYPE(Matrix3PidCredential, matrix_3pid_credential, MATRIX, 3PID_CREDENTIAL, MatrixJsonCompact)
|
||||
|
||||
struct _Matrix3PidCredentialClass {
|
||||
MatrixJsonCompactClass parent_class;
|
||||
};
|
||||
|
||||
Matrix3PidCredential *matrix_3pid_credential_new(void);
|
||||
const gchar *matrix_3pid_credential_get_id_server(Matrix3PidCredential *credential);
|
||||
void matrix_3pid_credential_set_id_server(Matrix3PidCredential *credential, const gchar *id_server);
|
||||
const gchar *matrix_3pid_credential_get_session_id(Matrix3PidCredential *credential);
|
||||
void matrix_3pid_credential_set_session_id(Matrix3PidCredential *credential, const gchar *session_id);
|
||||
const gchar *matrix_3pid_credential_get_client_secret(Matrix3PidCredential *credential);
|
||||
void matrix_3pid_credential_set_client_secret(Matrix3PidCredential *credential, const gchar *client_secret);
|
||||
|
||||
# define MATRIX_TYPE_PUSHER matrix_pusher_get_type()
|
||||
G_DECLARE_DERIVABLE_TYPE(MatrixPusher, matrix_pusher, MATRIX, PUSHER, MatrixJsonCompact)
|
||||
|
||||
struct _MatrixPusherClass {
|
||||
MatrixJsonCompactClass parent_class;
|
||||
};
|
||||
|
||||
MatrixPusher *matrix_pusher_new(void);
|
||||
const gchar *matrix_pusher_get_device_display_name(MatrixPusher *pusher);
|
||||
void matrix_pusher_set_device_display_name(MatrixPusher *pusher, const gchar *device_display_name);
|
||||
const gchar *matrix_pusher_get_app_display_name(MatrixPusher *pusher);
|
||||
void matrix_pusher_set_app_display_name(MatrixPusher *pusher, const gchar *app_display_name);
|
||||
const gchar *matrix_pusher_get_app_id(MatrixPusher *pusher);
|
||||
void matrix_pusher_set_app_id(MatrixPusher *pusher, const gchar *app_id);
|
||||
gboolean matrix_pusher_get_append(MatrixPusher *pusher);
|
||||
void matrix_pusher_set_append(MatrixPusher *pusher, gboolean append);
|
||||
const gchar *matrix_pusher_get_kind(MatrixPusher *pusher);
|
||||
void matrix_pusher_set_kind(MatrixPusher *pusher, const gchar *kind);
|
||||
const gchar *matrix_pusher_get_lang(MatrixPusher *pusher);
|
||||
void matrix_pusher_set_lang(MatrixPusher *pusher, const gchar *lang);
|
||||
const gchar *matrix_pusher_get_profile_tag(MatrixPusher *pusher);
|
||||
void matrix_pusher_set_profile_tag(MatrixPusher *pusher, const gchar *profile_tag);
|
||||
const gchar *matrix_pusher_get_pushkey(MatrixPusher *pusher);
|
||||
void matrix_pusher_set_pushkey(MatrixPusher *pusher, const gchar *pushkey);
|
||||
JsonNode *matrix_pusher_get_data(MatrixPusher *pusher);
|
||||
void matrix_pusher_set_data(MatrixPusher *pusher, JsonNode *data);
|
||||
|
||||
# define MATRIX_TYPE_EVENT_CONTEXT matrix_event_context_get_type()
|
||||
G_DECLARE_DERIVABLE_TYPE(MatrixEventContext, matrix_event_context, MATRIX, EVENT_CONTEXT, MatrixJsonCompact)
|
||||
|
||||
struct _MatrixEventContextClass {
|
||||
MatrixJsonCompactClass parent_class;
|
||||
};
|
||||
|
||||
MatrixEventContext *matrix_event_context_new (void);
|
||||
gint matrix_event_context_get_before_limit (MatrixEventContext *event_context);
|
||||
void matrix_event_context_set_before_limit (MatrixEventContext *event_context, gint before_limit);
|
||||
gint matrix_event_context_get_after_limit (MatrixEventContext *event_context);
|
||||
void matrix_event_context_set_after_limit (MatrixEventContext *event_context, gint after_limit);
|
||||
gboolean matrix_event_context_get_include_profile (MatrixEventContext *event_context);
|
||||
void matrix_event_context_set_include_profile (MatrixEventContext *event_context, gboolean include_profile);
|
||||
|
||||
# define MATRIX_TYPE_SEARCH_GROUPING matrix_search_grouping_get_type()
|
||||
G_DECLARE_DERIVABLE_TYPE(MatrixSearchGrouping, matrix_search_grouping, MATRIX, SEARCH_GROUPING, MatrixJsonCompact)
|
||||
|
||||
struct _MatrixSearchGroupingClass {
|
||||
MatrixJsonCompactClass parent_class;
|
||||
};
|
||||
|
||||
MatrixSearchGrouping *matrix_search_grouping_new(void);
|
||||
MatrixSearchGroupBy matrix_search_grouping_get_key(MatrixSearchGrouping *search_grouping);
|
||||
void matrix_search_grouping_set_key(MatrixSearchGrouping *search_grouping, MatrixSearchGroupBy key);
|
||||
|
||||
# define MATRIX_TYPE_SEARCH_GROUPINGS matrix_search_groupings_get_type()
|
||||
G_DECLARE_DERIVABLE_TYPE(MatrixSearchGroupings, matrix_search_groupings, MATRIX, SEARCH_GROUPINGS, MatrixJsonCompact)
|
||||
|
||||
struct _MatrixSearchGroupingsClass {
|
||||
MatrixJsonCompactClass parent_class;
|
||||
};
|
||||
|
||||
MatrixSearchGroupings *matrix_search_groupings_new(void);
|
||||
MatrixSearchGrouping **matrix_search_groupings_get_group_by(MatrixSearchGroupings *search_groupings, int *n_group_by);
|
||||
void matrix_search_groupings_set_group_by(MatrixSearchGroupings *search_groupings, MatrixSearchGrouping **group_by, int n_group_by);
|
||||
|
||||
# define MATRIX_TYPE_SEARCH_ROOM_EVENTS matrix_search_room_events_get_type()
|
||||
G_DECLARE_DERIVABLE_TYPE(MatrixSearchRoomEvents, matrix_search_room_events, MATRIX, SEARCH_ROOM_EVENTS, MatrixJsonCompact)
|
||||
|
||||
struct _MatrixSearchRoomEventsClass {
|
||||
MatrixJsonCompactClass parent_class;
|
||||
};
|
||||
|
||||
MatrixSearchRoomEvents *matrix_search_room_events_new(void);
|
||||
MatrixSearchOrder matrix_search_room_events_get_order_by(MatrixSearchRoomEvents *search_room_events);
|
||||
void matrix_search_room_events_set_order_by(MatrixSearchRoomEvents *search_room_events, MatrixSearchOrder order_by);
|
||||
MatrixSearchKey *matrix_search_room_events_get_keys(MatrixSearchRoomEvents *search_room_events, guint *n_keys);
|
||||
void matrix_search_room_events_set_keys(MatrixSearchRoomEvents *search_room_events, MatrixSearchKey *keys, guint n_keys);
|
||||
MatrixEventContext *matrix_search_room_events_get_event_context(MatrixSearchRoomEvents *search_room_events);
|
||||
void matrix_search_room_events_set_event_context(MatrixSearchRoomEvents *search_room_events, MatrixEventContext *event_context);
|
||||
gboolean matrix_search_room_events_get_include_state(MatrixSearchRoomEvents *search_room_events);
|
||||
void matrix_search_room_events_set_include_state(MatrixSearchRoomEvents *search_room_events, gboolean include_state);
|
||||
const gchar *matrix_search_room_events_get_filter_id(MatrixSearchRoomEvents *search_room_events);
|
||||
void matrix_search_room_events_set_filter_id(MatrixSearchRoomEvents *search_room_events, const gchar *filter_id);
|
||||
MatrixFilter *matrix_search_room_events_get_filter(MatrixSearchRoomEvents *search_room_events);
|
||||
void matrix_search_room_events_set_filter(MatrixSearchRoomEvents *search_room_events, MatrixFilter *filter);
|
||||
const gchar *matrix_search_room_events_get_search_term(MatrixSearchRoomEvents *search_room_events);
|
||||
void matrix_search_room_events_set_search_term(MatrixSearchRoomEvents *search_room_events, const gchar *search_term);
|
||||
MatrixSearchGroupings *matrix_search_room_events_get_groupings(MatrixSearchRoomEvents *search_room_events);
|
||||
void matrix_search_room_events_set_groupings(MatrixSearchRoomEvents *search_room_events, MatrixSearchGroupings *groupings);
|
||||
|
||||
# define MATRIX_TYPE_SEARCH_CATEGORIES matrix_search_categories_get_type()
|
||||
G_DECLARE_DERIVABLE_TYPE(MatrixSearchCategories, matrix_search_categories, MATRIX, SEARCH_CATEGORIES, MatrixJsonCompact)
|
||||
|
||||
struct _MatrixSearchCategoriesClass {
|
||||
MatrixJsonCompactClass parent_class;
|
||||
};
|
||||
|
||||
MatrixSearchCategories *matrix_search_categories_new(void);
|
||||
MatrixSearchRoomEvents *matrix_search_categories_get_room_events(MatrixSearchCategories *search_categories);
|
||||
void matrix_search_categories_set_room_events(MatrixSearchCategories *search_categories, MatrixSearchRoomEvents *room_events);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* __MATRIX_GLIB_SDK_COMPACTS_H__ */
|
@@ -1,941 +0,0 @@
|
||||
/*
|
||||
* This file is part of matrix-glib-sdk
|
||||
*
|
||||
* matrix-glib-sdk is free software: you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation, either
|
||||
* version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* matrix-glib-sdk is distributed in the hope that it will be
|
||||
* useful, but WITHOUT ANY WARRANTY; without even the implied
|
||||
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
* See the GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with matrix-glib-sdk. If not, see
|
||||
* <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
namespace Matrix {
|
||||
/**
|
||||
* Abstract parent class for classes that can be saved to JSON.
|
||||
*/
|
||||
public abstract class JsonCompact {
|
||||
public abstract Json.Node?
|
||||
get_json_node()
|
||||
throws Matrix.Error;
|
||||
|
||||
public string
|
||||
get_json_data(out size_t datalen)
|
||||
throws Matrix.Error
|
||||
{
|
||||
var generator = new Json.Generator();
|
||||
|
||||
generator.set_root(get_json_node());
|
||||
|
||||
return generator.to_data(out datalen);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Class to hold a filter.
|
||||
*/
|
||||
public class Filter : JsonCompact {
|
||||
private List<string>? _event_fields;
|
||||
|
||||
/**
|
||||
* The event fields to include in the filtered events.
|
||||
*/
|
||||
public List<string>? event_fields {
|
||||
get {
|
||||
return _event_fields;
|
||||
}
|
||||
|
||||
set {
|
||||
_event_fields = value.copy();
|
||||
}
|
||||
|
||||
default = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* The desired event format for the filtered events (e.g. for
|
||||
* matrix_api_sync())
|
||||
*/
|
||||
public EventFormat event_format {
|
||||
get; set;
|
||||
default = Matrix.EventFormat.CLIENT;
|
||||
}
|
||||
|
||||
/**
|
||||
* A filtering ruleset for presence events.
|
||||
*/
|
||||
public FilterRules? presence_filter { get; set; default = null; }
|
||||
|
||||
/**
|
||||
* A filtering ruleset for room events.
|
||||
*/
|
||||
public RoomFilter? room_filter { get; set; default = null; }
|
||||
|
||||
/**
|
||||
* Get the filter as a JSON node.
|
||||
*/
|
||||
public override Json.Node?
|
||||
get_json_node()
|
||||
throws Matrix.Error
|
||||
{
|
||||
var builder = new Json.Builder();
|
||||
|
||||
builder.begin_object();
|
||||
|
||||
builder.set_member_name("event_fields");
|
||||
builder.begin_array();
|
||||
|
||||
foreach (var entry in event_fields) {
|
||||
builder.add_string_value(entry);
|
||||
}
|
||||
|
||||
builder.end_array();
|
||||
|
||||
builder.set_member_name("event_format");
|
||||
builder.add_string_value(
|
||||
_g_enum_value_to_nick(typeof(EventFormat), event_format));
|
||||
|
||||
builder.set_member_name("presence");
|
||||
builder.add_value(presence_filter.get_json_node());
|
||||
|
||||
builder.set_member_name("room");
|
||||
builder.add_value(room_filter.get_json_node());
|
||||
|
||||
builder.end_object();
|
||||
|
||||
return builder.get_root();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Class to hold room filters.
|
||||
*/
|
||||
public class RoomFilter : JsonCompact {
|
||||
/**
|
||||
* If {{{true}}}, events for rooms that the user has left will
|
||||
* be included in the filtered event list.
|
||||
*/
|
||||
public bool include_leave { get; set; default=true; }
|
||||
|
||||
/**
|
||||
* Filtering rules for ephemeral events, i.e. events that are
|
||||
* not recorded in the room history (typing notifications,
|
||||
* receipts, etc.)
|
||||
*/
|
||||
public FilterRules? ephemeral { get; set; default = null; }
|
||||
|
||||
/**
|
||||
* Filtering rules for state events.
|
||||
*/
|
||||
public FilterRules? state { get; set; default = null; }
|
||||
|
||||
/**
|
||||
* Filtering rules for timeline events.
|
||||
*/
|
||||
public FilterRules? timeline { get; set; default = null; }
|
||||
|
||||
/**
|
||||
* Get the room filters as a JSON node.
|
||||
*/
|
||||
public override Json.Node?
|
||||
get_json_node()
|
||||
throws Matrix.Error
|
||||
{
|
||||
var builder = new Json.Builder();
|
||||
|
||||
builder.begin_object();
|
||||
|
||||
builder.set_member_name("include_leave");
|
||||
builder.add_boolean_value(include_leave);
|
||||
|
||||
if (ephemeral != null) {
|
||||
builder.set_member_name("ephemeral");
|
||||
builder.add_value(ephemeral.get_json_node());
|
||||
}
|
||||
|
||||
if (state != null) {
|
||||
builder.set_member_name("state");
|
||||
builder.add_value(state.get_json_node());
|
||||
}
|
||||
|
||||
if (timeline != null) {
|
||||
builder.set_member_name("timeline");
|
||||
builder.add_value(timeline.get_json_node());
|
||||
}
|
||||
|
||||
builder.end_object();
|
||||
|
||||
return builder.get_root();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Class to hold filtering rules.
|
||||
*/
|
||||
public class FilterRules : JsonCompact {
|
||||
private List<string>? _types;
|
||||
private List<string>? _excluded_types;
|
||||
private List<string>? _senders;
|
||||
private List<string>? _excluded_senders;
|
||||
private List<string>? _rooms;
|
||||
private List<string>? _excluded_rooms;
|
||||
|
||||
/**
|
||||
* The limit of the count of returned events.
|
||||
*/
|
||||
public uint limit { get; set; }
|
||||
|
||||
/**
|
||||
* List of message types to include in the filtered result.
|
||||
*/
|
||||
public List<string>? types {
|
||||
get {
|
||||
return _types;
|
||||
}
|
||||
|
||||
set {
|
||||
_types = value.copy();
|
||||
}
|
||||
|
||||
default = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* List of message types to exclude from the filtered
|
||||
* result. A matching type will be excluded from the result
|
||||
* even if it is listed in the types to include.
|
||||
*/
|
||||
public List<string>? excluded_types {
|
||||
get {
|
||||
return _excluded_types;
|
||||
}
|
||||
|
||||
set {
|
||||
_excluded_types = value.copy();
|
||||
}
|
||||
|
||||
default = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* List of senders to include in the filtered results.
|
||||
*/
|
||||
public List<string>? senders {
|
||||
get {
|
||||
return _senders;
|
||||
}
|
||||
|
||||
set {
|
||||
_senders = value.copy();
|
||||
}
|
||||
|
||||
default = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* List of senders to exclude from the filtered result. A
|
||||
* matching sender will be excluded from the result even if it
|
||||
* is listed in the senders to include.
|
||||
*/
|
||||
public List<string>? excluded_senders {
|
||||
get {
|
||||
return _excluded_senders;
|
||||
}
|
||||
|
||||
set {
|
||||
_excluded_senders = value.copy();
|
||||
}
|
||||
|
||||
default = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* List of rooms to include in the filtered results.
|
||||
*/
|
||||
public List<string>? rooms {
|
||||
get {
|
||||
return _rooms;
|
||||
}
|
||||
|
||||
set {
|
||||
_rooms = value.copy();
|
||||
}
|
||||
|
||||
default = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* List of rooms to exclude from the filtered result. A
|
||||
* matching room will be excluded from the result even if it
|
||||
* is listed in the rooms to include.
|
||||
*/
|
||||
public List<string>? excluded_rooms {
|
||||
get {
|
||||
return _excluded_rooms;
|
||||
}
|
||||
|
||||
set {
|
||||
_excluded_rooms = value.copy();
|
||||
}
|
||||
|
||||
default = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the filtering rules as a JSON node.
|
||||
*/
|
||||
public override Json.Node?
|
||||
get_json_node()
|
||||
throws Matrix.Error
|
||||
{
|
||||
var builder = new Json.Builder();
|
||||
builder.begin_object();
|
||||
|
||||
builder.set_member_name("limit");
|
||||
builder.add_int_value(limit);
|
||||
|
||||
if (rooms != null) {
|
||||
builder.set_member_name("rooms");
|
||||
builder.begin_array();
|
||||
foreach (var entry in rooms) {
|
||||
builder.add_string_value(entry);
|
||||
}
|
||||
builder.end_array();
|
||||
}
|
||||
|
||||
if (excluded_rooms != null) {
|
||||
builder.set_member_name("not_rooms");
|
||||
builder.begin_array();
|
||||
foreach (var entry in excluded_rooms) {
|
||||
builder.add_string_value(entry);
|
||||
}
|
||||
builder.end_array();
|
||||
}
|
||||
|
||||
if (senders != null) {
|
||||
builder.set_member_name("senders");
|
||||
builder.begin_array();
|
||||
foreach (var entry in senders) {
|
||||
builder.add_string_value(entry);
|
||||
}
|
||||
builder.end_array();
|
||||
}
|
||||
|
||||
if (excluded_senders != null) {
|
||||
builder.set_member_name("not_senders");
|
||||
builder.begin_array();
|
||||
foreach (var entry in excluded_senders) {
|
||||
builder.add_string_value(entry);
|
||||
}
|
||||
builder.end_array();
|
||||
}
|
||||
|
||||
if (types != null) {
|
||||
builder.set_member_name("types");
|
||||
builder.begin_array();
|
||||
foreach (var entry in types) {
|
||||
builder.add_string_value(entry);
|
||||
}
|
||||
builder.end_array();
|
||||
}
|
||||
|
||||
if (excluded_types != null) {
|
||||
builder.set_member_name("not_types");
|
||||
builder.begin_array();
|
||||
foreach(var entry in types) {
|
||||
builder.add_string_value(entry);
|
||||
}
|
||||
builder.end_array();
|
||||
}
|
||||
|
||||
builder.end_object();
|
||||
|
||||
return builder.get_root();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Class to hold 3rd party credential related data.
|
||||
*/
|
||||
public class @3PidCredential : JsonCompact {
|
||||
/**
|
||||
* The Identity Server used for this credential.
|
||||
*/
|
||||
public string? id_server { get; set; default = null; }
|
||||
|
||||
/**
|
||||
* The session identifier got from the Identity Server.
|
||||
*/
|
||||
public string? session_id { get; set; default = null; }
|
||||
|
||||
/**
|
||||
* The client secret that was used in the session with the
|
||||
* Identity Server.
|
||||
*/
|
||||
public string? client_secret { get; set; default = null; }
|
||||
|
||||
/**
|
||||
* Get 3rd party credential related data as a JSON node.
|
||||
*/
|
||||
public override Json.Node?
|
||||
get_json_node()
|
||||
throws Matrix.Error
|
||||
{
|
||||
if ((id_server == null)
|
||||
|| (session_id == null)
|
||||
|| (client_secret == null))
|
||||
{
|
||||
throw new Matrix.Error.INCOMPLETE(
|
||||
"All fields of a 3PID credential must be filled!");
|
||||
}
|
||||
|
||||
var builder = new Json.Builder();
|
||||
|
||||
builder.begin_object();
|
||||
|
||||
builder.set_member_name("id_server");
|
||||
builder.add_string_value(id_server);
|
||||
|
||||
builder.set_member_name("session_id");
|
||||
builder.add_string_value(session_id);
|
||||
|
||||
builder.set_member_name("client_secret");
|
||||
builder.add_string_value(client_secret);
|
||||
|
||||
builder.end_object();
|
||||
|
||||
return builder.get_root();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Class to hold pusher related data.
|
||||
*/
|
||||
public class Pusher : JsonCompact {
|
||||
/**
|
||||
* A device display name.
|
||||
*/
|
||||
public string? device_display_name { get; set; default = null; }
|
||||
|
||||
/**
|
||||
* An application display name.
|
||||
*/
|
||||
public string? app_display_name { get; set; default = null; }
|
||||
|
||||
/**
|
||||
* An application ID.
|
||||
*/
|
||||
public string? app_id { get; set; default = null; }
|
||||
|
||||
/**
|
||||
* If {{{true}}}, the homeserver should add another pusher
|
||||
* with the given push key and app ID in addition to any
|
||||
* others with different user IDs. Otherwise, the homeserver
|
||||
* must remove any other pushers with the same App ID and
|
||||
* pushkey for different users.
|
||||
*/
|
||||
public bool append { get; set; default = true; }
|
||||
|
||||
/**
|
||||
* The kind of the pusher. {{{http}}} makes a pusher that
|
||||
* sends HTTP pokes. {{{null}}} deletes the pusher.
|
||||
*/
|
||||
public string? kind { get; set; default = null; }
|
||||
|
||||
/**
|
||||
* The preferred language for receiving notifications,
|
||||
* e.g. {{{en}}} or {{{en-US}}}.
|
||||
*/
|
||||
public string? lang { get; set; default = null; }
|
||||
|
||||
/**
|
||||
* A string that determines what set of device rules will be
|
||||
* matched when evaluating push rules for this pusher. It is
|
||||
* an arbitrary string. Multiple devices may use the same
|
||||
* profile tag. It is advised that when an app's data is
|
||||
* copied or restored to a different device, this value remain
|
||||
* the same. Client apps should offer ways to change the
|
||||
* profile tag, optionally copying rules from the old profile
|
||||
* tag. Maximum length is 32 bytes. If the profile tag is
|
||||
* longer than this, it will be truncated
|
||||
*/
|
||||
public string? profile_tag { get; set; default = null; }
|
||||
|
||||
/**
|
||||
* A unique identifier for this pusher. The value you should
|
||||
* use for this is the routing or destination address
|
||||
* information for the notification, for example, the APNS
|
||||
* token for APNS or the Registration ID for GCM. If your
|
||||
* notification client has no such concept, use any unique
|
||||
* identifier. Maximum length is 512 bytes. If pushkey is
|
||||
* longer than this, it will be truncated
|
||||
*/
|
||||
public string? pushkey { get; set; default = null; }
|
||||
|
||||
/**
|
||||
* a dictionary of information for the pusher implementation
|
||||
* itself. For example, if kind is {{{http}}}, this should
|
||||
* contain an {{{url}}} member, which is the URL to use to
|
||||
* send notifications to. This function creates a deep copy of
|
||||
* the data, so it can be freed after this call.
|
||||
*/
|
||||
public Json.Node? data { get; set; default = null; }
|
||||
|
||||
/**
|
||||
* Get the pusher data as a JSON node.
|
||||
*/
|
||||
public override Json.Node?
|
||||
get_json_node()
|
||||
throws Matrix.Error
|
||||
{
|
||||
if ((device_display_name == null)
|
||||
|| (app_display_name == null)
|
||||
|| (app_id == null)
|
||||
|| (data == null)
|
||||
|| (kind == null)
|
||||
|| (lang == null)
|
||||
|| (profile_tag == null)
|
||||
|| (pushkey == null)) {
|
||||
throw new Matrix.Error.INCOMPLETE("Pusher data incomplete");
|
||||
}
|
||||
|
||||
var builder = new Json.Builder();
|
||||
|
||||
builder.begin_object();
|
||||
|
||||
builder.set_member_name("device_display_name");
|
||||
builder.add_string_value(device_display_name);
|
||||
|
||||
builder.set_member_name("app_display_name");
|
||||
builder.add_string_value(app_display_name);
|
||||
|
||||
builder.set_member_name("app_id");
|
||||
builder.add_string_value(app_id);
|
||||
|
||||
builder.set_member_name("append");
|
||||
builder.add_boolean_value(append);
|
||||
|
||||
builder.set_member_name("kind");
|
||||
builder.add_string_value(kind);
|
||||
|
||||
builder.set_member_name("lang");
|
||||
builder.add_string_value(lang);
|
||||
|
||||
builder.set_member_name("profile_tag");
|
||||
builder.add_string_value(profile_tag);
|
||||
|
||||
builder.set_member_name("pushkey");
|
||||
builder.add_string_value(pushkey);
|
||||
|
||||
builder.set_member_name("data");
|
||||
builder.add_value(data);
|
||||
|
||||
builder.end_object();
|
||||
|
||||
return builder.get_root();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Class to hold unsigned event data, like event age, redact
|
||||
* reason or a transaction ID.
|
||||
*/
|
||||
public class UnsignedEventData : JsonCompact {
|
||||
/**
|
||||
* The age of the event, in seconds.
|
||||
*/
|
||||
public uint age { get; set; default = 0; }
|
||||
|
||||
/**
|
||||
* The reason of redaction, if any.
|
||||
*/
|
||||
public string? redact_reason { get; set; default = null; }
|
||||
|
||||
/**
|
||||
* The transaction ID of the message.
|
||||
*/
|
||||
public string? transaction_id { get; set; default = null; }
|
||||
|
||||
/**
|
||||
* Create an UnsignedEventData object based
|
||||
* on @param json_data.
|
||||
*/
|
||||
public
|
||||
UnsignedEventData.from_json(Json.Node json_data)
|
||||
requires(json_data.get_node_type() == Json.NodeType.OBJECT)
|
||||
{
|
||||
var root = json_data.get_object();
|
||||
Json.Node node;
|
||||
|
||||
if ((node = root.get_member("age")) != null) {
|
||||
age = (uint)node.get_int();
|
||||
}
|
||||
|
||||
if ((node = root.get_member("redacted_because")) != null) {
|
||||
redact_reason = node.get_string();
|
||||
}
|
||||
|
||||
if ((node = root.get_member("transaction_id")) != null) {
|
||||
transaction_id = node.get_string();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the unsigned event data as a JSON node.
|
||||
*/
|
||||
public override Json.Node?
|
||||
get_json_node()
|
||||
throws Matrix.Error
|
||||
{
|
||||
var builder = new Json.Builder();
|
||||
|
||||
builder.begin_object();
|
||||
|
||||
builder.set_member_name("age");
|
||||
builder.add_int_value(age);
|
||||
|
||||
if (redact_reason != null) {
|
||||
builder.set_member_name("redacted_because");
|
||||
builder.add_string_value(redact_reason);
|
||||
}
|
||||
|
||||
if (transaction_id != null) {
|
||||
builder.set_member_name("transaction_id");
|
||||
builder.add_string_value(transaction_id);
|
||||
}
|
||||
|
||||
builder.end_object();
|
||||
|
||||
return builder.get_root();
|
||||
}
|
||||
}
|
||||
|
||||
public class EventContext : JsonCompact {
|
||||
public int? before_limit { get; set; default = null; }
|
||||
public int? after_limit { get; set; default = null; }
|
||||
public bool? include_profile { get; set; default = null; }
|
||||
|
||||
public override Json.Node?
|
||||
get_json_node()
|
||||
throws Matrix.Error
|
||||
{
|
||||
if ((before_limit == null)
|
||||
&& (after_limit == null)
|
||||
&& (include_profile == null))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
var builder = new Json.Builder();
|
||||
|
||||
builder.begin_object();
|
||||
|
||||
if (before_limit != null) {
|
||||
builder.set_member_name("before_limit");
|
||||
builder.add_int_value(before_limit);
|
||||
}
|
||||
|
||||
if (after_limit != null) {
|
||||
builder.set_member_name("after_limit");
|
||||
builder.add_int_value(after_limit);
|
||||
}
|
||||
|
||||
if (include_profile != null) {
|
||||
builder.set_member_name("include_profile");
|
||||
builder.add_boolean_value(include_profile);
|
||||
}
|
||||
|
||||
builder.end_object();
|
||||
|
||||
return builder.get_root();
|
||||
}
|
||||
}
|
||||
|
||||
public class SearchGrouping : JsonCompact {
|
||||
public SearchGroupBy? key { get; set; default = null; }
|
||||
|
||||
public override Json.Node?
|
||||
get_json_node()
|
||||
throws Matrix.Error
|
||||
{
|
||||
if (key == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
var builder = new Json.Builder();
|
||||
|
||||
builder.begin_object();
|
||||
|
||||
builder.set_member_name("key");
|
||||
builder.add_string_value(
|
||||
_g_enum_value_to_nick(typeof(SearchGroupBy), key, true));
|
||||
|
||||
builder.end_object();
|
||||
|
||||
return builder.get_root();
|
||||
}
|
||||
}
|
||||
|
||||
public class SearchGroupings : JsonCompact {
|
||||
private List<SearchGrouping>? _group_by = null;
|
||||
public List<SearchGrouping>? group_by {
|
||||
get {
|
||||
return _group_by;
|
||||
}
|
||||
|
||||
set {
|
||||
_group_by = value.copy();
|
||||
}
|
||||
|
||||
default = null;
|
||||
}
|
||||
|
||||
public override Json.Node?
|
||||
get_json_node()
|
||||
throws Matrix.Error
|
||||
{
|
||||
if (group_by == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
var builder = new Json.Builder();
|
||||
|
||||
builder.begin_object();
|
||||
|
||||
builder.set_member_name("group_by");
|
||||
builder.begin_array();
|
||||
|
||||
foreach (var entry in group_by) {
|
||||
var node = entry.get_json_node();
|
||||
|
||||
if (node != null) {
|
||||
builder.add_value(node);
|
||||
}
|
||||
}
|
||||
|
||||
builder.end_array();
|
||||
|
||||
builder.end_object();
|
||||
|
||||
return builder.get_root();
|
||||
}
|
||||
}
|
||||
|
||||
public class SearchRoomEvents : JsonCompact {
|
||||
private List<SearchKey?>? _keys = null;
|
||||
|
||||
public SearchOrder? order_by { get; set; default = SearchOrder.RECENT; }
|
||||
public List<SearchKey?>? keys {
|
||||
get {
|
||||
return _keys;
|
||||
}
|
||||
|
||||
set {
|
||||
_keys = value.copy();
|
||||
}
|
||||
|
||||
default = null; }
|
||||
public EventContext? event_context { get; set; default = null; }
|
||||
public bool? include_state { get; set; default = false; }
|
||||
public string? filter_id { get; set; default = null; }
|
||||
public Filter? filter { get; set; default = null; }
|
||||
public string search_term { get; set; }
|
||||
public SearchGroupings? groupings { get; set; default = null; }
|
||||
|
||||
public override Json.Node?
|
||||
get_json_node()
|
||||
throws Matrix.Error
|
||||
{
|
||||
Json.Node? node = null;
|
||||
|
||||
var builder = new Json.Builder();
|
||||
|
||||
if ((filter_id != null) && (filter != null)) {
|
||||
throw new Matrix.Error.INCOMPLETE(
|
||||
"filter and filter_id is exclusive to each other");
|
||||
}
|
||||
|
||||
builder.begin_object();
|
||||
|
||||
if (order_by != null) {
|
||||
builder.set_member_name("order_by");
|
||||
builder.add_string_value(
|
||||
_g_enum_value_to_nick(typeof(SearchOrder), order_by));
|
||||
}
|
||||
|
||||
if (keys != null) {
|
||||
EnumClass key_class = (EnumClass)(typeof(SearchKey).class_ref());
|
||||
var key_array = new Json.Array();
|
||||
|
||||
foreach (var entry in keys) {
|
||||
if (entry != null) {
|
||||
unowned EnumValue? key_value = key_class.get_value(entry);
|
||||
|
||||
if (key_value != null) {
|
||||
key_array.add_string_element(
|
||||
key_value.value_nick.replace("-", "."));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (key_array.get_length() > 0) {
|
||||
node = new Json.Node(Json.NodeType.ARRAY);
|
||||
node.set_array(key_array);
|
||||
|
||||
builder.set_member_name("keys");
|
||||
builder.add_value(node);
|
||||
}
|
||||
}
|
||||
|
||||
if ((event_context != null)
|
||||
&& ((node = event_context.get_json_node()) != null)) {
|
||||
builder.set_member_name("event_context");
|
||||
builder.add_value(node);
|
||||
}
|
||||
|
||||
if (include_state != null) {
|
||||
builder.set_member_name("include_state");
|
||||
builder.add_boolean_value(include_state);
|
||||
}
|
||||
|
||||
if ((filter != null)
|
||||
&& ((node = filter.get_json_node()) != null)) {
|
||||
builder.set_member_name("filter");
|
||||
builder.add_value(node);
|
||||
}
|
||||
|
||||
if (filter_id != null) {
|
||||
builder.set_member_name("filter");
|
||||
builder.add_string_value(filter_id);
|
||||
}
|
||||
|
||||
builder.set_member_name("search_term");
|
||||
builder.add_string_value(search_term);
|
||||
|
||||
if ((groupings != null)
|
||||
&& ((node = groupings.get_json_node()) != null)) {
|
||||
builder.set_member_name("groupings");
|
||||
builder.add_value(node);
|
||||
}
|
||||
|
||||
builder.end_object();
|
||||
|
||||
return builder.get_root();
|
||||
}
|
||||
}
|
||||
|
||||
public class SearchCategories : JsonCompact {
|
||||
public SearchRoomEvents? room_events { get; set; default = null; }
|
||||
|
||||
public override Json.Node?
|
||||
get_json_node()
|
||||
throws Matrix.Error
|
||||
{
|
||||
Json.Node? node = null;
|
||||
|
||||
if ((room_events == null)
|
||||
&& ((node = room_events.get_json_node()) != null)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
var builder = new Json.Builder();
|
||||
|
||||
builder.begin_object();
|
||||
|
||||
builder.set_member_name("room_events");
|
||||
builder.add_value(node);
|
||||
|
||||
builder.end_object();
|
||||
|
||||
return builder.get_root();
|
||||
}
|
||||
}
|
||||
|
||||
private Json.Node?
|
||||
_json_object_node_ensure_field(Json.Node node,
|
||||
string field_name,
|
||||
Json.NodeType field_type)
|
||||
requires(node.get_node_type() == Json.NodeType.OBJECT)
|
||||
{
|
||||
var root = node.get_object();
|
||||
Json.Node? new_node;
|
||||
|
||||
if ((new_node = root.get_member(field_name)) == null) {
|
||||
new_node = new Json.Node(field_type);
|
||||
|
||||
switch (field_type) {
|
||||
case Json.NodeType.OBJECT:
|
||||
new_node.set_object(new Json.Object());
|
||||
|
||||
break;
|
||||
|
||||
case Json.NodeType.ARRAY:
|
||||
new_node.set_array(new Json.Array());
|
||||
|
||||
break;
|
||||
|
||||
// Other node types don’t need special treatment
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
root.set_member(field_name, new_node);
|
||||
}
|
||||
|
||||
return new_node;
|
||||
}
|
||||
|
||||
public Json.Node?
|
||||
_json_node_deep_copy(Json.Node? node)
|
||||
{
|
||||
Json.Node ret;
|
||||
|
||||
if (node == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
ret = new Json.Node(node.get_node_type());
|
||||
|
||||
switch (node.get_node_type()) {
|
||||
case Json.NodeType.OBJECT:
|
||||
var new_obj = new Json.Object();
|
||||
|
||||
node.get_object().foreach_member(
|
||||
(old_obj, member_name, member_node) => {
|
||||
new_obj.set_member(
|
||||
member_name,
|
||||
_json_node_deep_copy(member_node));
|
||||
});
|
||||
|
||||
ret.set_object(new_obj);
|
||||
|
||||
break;
|
||||
|
||||
case Json.NodeType.ARRAY:
|
||||
var new_ary = new Json.Array();
|
||||
|
||||
node.get_array().foreach_element(
|
||||
(old_ary, idx, element_node) => {
|
||||
new_ary.add_element(
|
||||
_json_node_deep_copy(element_node));
|
||||
});
|
||||
|
||||
break;
|
||||
|
||||
case Json.NodeType.VALUE:
|
||||
ret.set_value(node.get_value());
|
||||
|
||||
break;
|
||||
|
||||
case Json.NodeType.NULL:
|
||||
break;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
}
|
@@ -1,227 +0,0 @@
|
||||
/*
|
||||
* This file is part of matrix-glib-sdk
|
||||
*
|
||||
* matrix-glib-sdk is free software: you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation, either
|
||||
* version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* matrix-glib-sdk is distributed in the hope that it will be
|
||||
* useful, but WITHOUT ANY WARRANTY; without even the implied
|
||||
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
* See the GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with matrix-glib-sdk. If not, see
|
||||
* <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
namespace Matrix {
|
||||
public errordomain Error {
|
||||
NONE, /// no error
|
||||
COMMUNICATION_ERROR, /// there was a problem in communication (e.g. connection error)
|
||||
INCOMPLETE, /// the passed/generated data is incomplete
|
||||
BAD_REQUEST, /// the request is invalid
|
||||
BAD_RESPONSE, /// malformed response, or the response is not a JSON object
|
||||
INVALID_ROOM_ID, /// the provided string doesn’t contain a valid room ID
|
||||
UNKNOWN_VALUE, /// the response from the Matrix.org server contains a value unknown to this library. These should be reported to the Matrix GLib SDK developers
|
||||
INVALID_TYPE, /// the provided type is invalid
|
||||
UNSUPPORTED, ///the operation is unsupported
|
||||
INVALID_FORMAT, /// the format of the JSON node is invalid (e.g. it is an array instead of an object)
|
||||
|
||||
/* Add Matrix-defined error codes under here, prefixing them with
|
||||
* `MATRIX_ERROR_`, i.e. `M_FORBIDDEN` =>
|
||||
* `MATRIX_ERROR_M_FORBIDDEN` */
|
||||
M_MISSING_TOKEN = 500, /// authorization token is missing from the request
|
||||
M_FORBIDDEN, /// access was forbidden (e.g. due to a missing/invalid token, or using a bad password during login)
|
||||
M_UNKNOWN, /// an error unknown to the Matrix homeserver
|
||||
M_UNKNOWN_TOKEN, /// the token provided is not known for the homeserver
|
||||
M_NOT_JSON, /// illegal request, the content is not valid JSON
|
||||
M_UNRECOGNIZED, /// the homeserver didn't understand the request
|
||||
M_UNAUTHORIZED, /// the request is unauthorized
|
||||
M_BAD_JSON, /// the JSON data is not in the required format
|
||||
M_USER_IN_USE, /// the specified username is in use
|
||||
M_ROOM_IN_USE, /// the specified room is in use
|
||||
M_BAD_PAGINATION, /// invalid pagination parameters
|
||||
M_BAD_STATE, /// invalid state event
|
||||
M_NOT_FOUND, /// the requested resource is not found
|
||||
M_GUEST_ACCESS_FORBIDDEN, /// guest access was requested, but it is forbidden
|
||||
M_LIMIT_EXCEEDED, /// the request was rate limited
|
||||
M_CAPTCHA_NEEDED, /// a captcha is needed to continue
|
||||
M_CAPTCHA_INVALID, /// the provided captcha is invalid
|
||||
M_MISSING_PARAM, /// a parameter is missing from the request
|
||||
M_TOO_LARGE, /// the request data is too large
|
||||
M_EXCLUSIVE, /// the desired user ID is in an exclusive namespace claimed by an application server
|
||||
M_THREEPID_AUTH_FAILED, /// 3rd party authentication failed
|
||||
M_THREEPID_IN_USE, /// the provided 3rd party ID is already in use
|
||||
M_INVALID_USERNAME, /// the given username is invalid
|
||||
|
||||
/* Allow for a lot of Matrix.org defined codes
|
||||
* Do not define error codes after this! */
|
||||
UNSPECIFIED = 16383, /// no error code was sent by the homeserver. If you see this error, that usually indicates a homeserver bug
|
||||
UNKNOWN_ERROR; /// an error unknown to this library
|
||||
|
||||
public static GLib.Quark
|
||||
quark ()
|
||||
{
|
||||
return Quark.from_string("matrix-error-quark");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* User account types.
|
||||
*/
|
||||
public enum AccountKind {
|
||||
DEFAULT, /// use the server default (usually {{{USER}}})
|
||||
USER, /// normal user
|
||||
GUEST; /// guest user
|
||||
}
|
||||
|
||||
/**
|
||||
* Direction of events when requesting an event context.
|
||||
*/
|
||||
public enum EventDirection {
|
||||
FORWARD, /// List events after the specified one
|
||||
BACKWARD; /// List events before the specified one
|
||||
}
|
||||
|
||||
/**
|
||||
* Event format received when synchronizing.
|
||||
*/
|
||||
public enum EventFormat {
|
||||
DEFAULT, /// event format will be omitted from the filter, so the server will use its default (usually {{{FEDERATION}}})
|
||||
CLIENT, /// return the events in a format suitable for clients
|
||||
FEDERATION; /// return the raw event as receieved over federation
|
||||
}
|
||||
|
||||
/**
|
||||
* Presence values for matrix_api_set_user_presence() and other
|
||||
* presence related queries.
|
||||
*/
|
||||
public enum Presence {
|
||||
UNKNOWN, /// user's presence is unknown
|
||||
ONLINE, /// user is online
|
||||
OFFLINE, /// user is offline
|
||||
UNAVAILABLE, /// user is unavailable (i.e. busy)
|
||||
FREE_FOR_CHAT; /// user is free for chat
|
||||
}
|
||||
|
||||
/**
|
||||
* Condition types for pushers.
|
||||
*/
|
||||
public enum PusherConditionKind {
|
||||
EVENT_MATCH, /// glob pattern match on a field of the event. Requires a {{{key}}} and a {{{pattern}}} parameter
|
||||
PROFILE_TAG, /// matches the profile tag of the device that the notification would be delivered to. Requires a {{{profile_tag}}} parameter
|
||||
CONTAINS_DISPLAY_NAME, /// matches unencrypted messages where the content's body contains the owner's display name in that room.
|
||||
ROOM_MEMBER_COUNT; /// matches the current number of members in the room. Requires an {{{is}}} parameter, which must be an integer, optionally prefixed by {{==}}}, {{{<}}}, {{{>}}}, {{{<=}}} or {{{>=}}}. If the prefix is omitted, it defaults to {{{==}}}
|
||||
}
|
||||
|
||||
/**
|
||||
* Pusher types.
|
||||
*/
|
||||
public enum PusherKind {
|
||||
OVERRIDE, /// highest priority rules
|
||||
SENDER, /// for (unencrypted) messages that match certain patterns
|
||||
ROOM, /// for all messages for a given room. The rule ID of a room rule is always the ID of the room that it affects
|
||||
CONTENT, /// for messages from a specific Matrix user ID. The rule ID of such rules is always the Matrix ID of the user whose messages they'd apply to
|
||||
UNDERRIDE; /// lowest priority rules
|
||||
}
|
||||
|
||||
/**
|
||||
* Receipt types of acknowledgment.
|
||||
*/
|
||||
public enum ReceiptType {
|
||||
READ; /// indicate that the message has been read
|
||||
}
|
||||
|
||||
/**
|
||||
* Resizing methods for matrix_api_media_thumbnail().
|
||||
*/
|
||||
public enum ResizeMethod {
|
||||
DEFAULT, /// use the server default value
|
||||
CROP, /// crop thumbnail to the requested size
|
||||
SCALE; /// scale thumbnail to the requested size
|
||||
}
|
||||
|
||||
/**
|
||||
* Room membership types.
|
||||
*/
|
||||
public enum RoomMembership {
|
||||
UNKNOWN, /// the membership sent by the server is unknown to this SDK
|
||||
INVITE, /// the user has been invited to join a room, but has not yet joined it. They may not participate in the room until they join
|
||||
JOIN, /// the user has joined the room (possibly after accepting an invite), and may participate in it
|
||||
LEAVE, /// the user was once joined to the room, but has since left (possibly by choice, or possibly by being kicked)
|
||||
BAN, /// the user has been banned from the room, and is no longer allowed to join it until they are un-banned from the room (by having their membership state set to a value other than {{{BAN}}})
|
||||
KNOCK; /// this is a reserved word, which currently has no meaning
|
||||
}
|
||||
|
||||
/**
|
||||
* Preset values for matrix_api_create_room() calls.
|
||||
*/
|
||||
public enum RoomPreset {
|
||||
NONE, /// no preset
|
||||
PRIVATE, /// preset for private rooms
|
||||
TRUSTED_PRIVATE, /// same as private rooms, but all users get the same power level as the room creator
|
||||
PUBLIC; /// preset for public rooms
|
||||
}
|
||||
|
||||
/**
|
||||
* Visibility values for room creation. Not to be confused with
|
||||
* join rules.
|
||||
*/
|
||||
public enum RoomVisibility {
|
||||
DEFAULT, /// use a server-assigned value (usually {{{private}}}
|
||||
PUBLIC, /// make the room visible in the public room list
|
||||
PRIVATE; /// hide the room from the public room list
|
||||
}
|
||||
|
||||
public enum SearchOrder {
|
||||
RECENT,
|
||||
RANK
|
||||
}
|
||||
|
||||
public enum SearchKey {
|
||||
CONTENT_BODY,
|
||||
CONTENT_NAME,
|
||||
CONTENT_TOPIC
|
||||
}
|
||||
|
||||
public enum SearchGroupBy {
|
||||
ROOM_ID,
|
||||
SENDER
|
||||
}
|
||||
|
||||
private int?
|
||||
_g_enum_nick_to_value(Type enum_type, string nick)
|
||||
{
|
||||
EnumClass enum_class = (EnumClass)enum_type.class_ref();
|
||||
unowned EnumValue? enum_val = enum_class.get_value_by_nick(nick);
|
||||
|
||||
if (enum_val != null) {
|
||||
return enum_val.value;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private string?
|
||||
_g_enum_value_to_nick(Type enum_type,
|
||||
int value,
|
||||
bool convert_dashes = true)
|
||||
{
|
||||
EnumClass enum_class = (EnumClass)enum_type.class_ref();
|
||||
unowned EnumValue? enum_val = enum_class.get_value(value);
|
||||
|
||||
if (enum_val != null) {
|
||||
var nick = enum_val.value_nick;
|
||||
|
||||
if (convert_dashes) {
|
||||
return nick.replace("-", "_");
|
||||
}
|
||||
|
||||
return nick;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
59
src/matrix-enumtypes.c.template
Normal file
59
src/matrix-enumtypes.c.template
Normal file
@@ -0,0 +1,59 @@
|
||||
/*** BEGIN file-header ***/
|
||||
/*
|
||||
* This file is part of matrix-glib-sdk
|
||||
*
|
||||
* matrix-glib-sdk is free software: you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation, either
|
||||
* version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* matrix-glib-sdk is distributed in the hope that it will be
|
||||
* useful, but WITHOUT ANY WARRANTY; without even the implied
|
||||
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
* See the GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with matrix-glib-sdk. If not, see
|
||||
* <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "matrix-enumtypes.h"
|
||||
/*** END file-header ***/
|
||||
|
||||
/*** BEGIN file-production ***/
|
||||
|
||||
/* enumerations from @filename@ */
|
||||
/*** END file-production ***/
|
||||
|
||||
/*** BEGIN value-header ***/
|
||||
|
||||
GType
|
||||
@enum_name@_get_type(void)
|
||||
{
|
||||
static volatile gsize g_define_type_id__volatile = 0;
|
||||
|
||||
if (g_once_init_enter(&g_define_type_id__volatile)) {
|
||||
static const G@Type@Value values[] = {
|
||||
/*** END value-header ***/
|
||||
|
||||
/*** BEGIN value-production ***/
|
||||
{
|
||||
@VALUENAME@,
|
||||
"@VALUENAME@",
|
||||
"@valuenick@"
|
||||
},
|
||||
/*** END value-production ***/
|
||||
|
||||
/*** BEGIN value-tail ***/
|
||||
{0, NULL, NULL}
|
||||
};
|
||||
|
||||
GType g_define_type_id = g_@type@_register_static(
|
||||
g_intern_static_string("@EnumName@"),
|
||||
values);
|
||||
g_once_init_leave(&g_define_type_id__volatile, g_define_type_id);
|
||||
}
|
||||
|
||||
return g_define_type_id__volatile;
|
||||
}
|
||||
/*** END value-tail ***/
|
42
src/matrix-enumtypes.h.template
Normal file
42
src/matrix-enumtypes.h.template
Normal file
@@ -0,0 +1,42 @@
|
||||
/*** BEGIN file-header ***/
|
||||
/*
|
||||
* This file is part of matrix-glib-sdk
|
||||
*
|
||||
* matrix-glib-sdk is free software: you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation, either
|
||||
* version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* matrix-glib-sdk is distributed in the hope that it will be
|
||||
* useful, but WITHOUT ANY WARRANTY; without even the implied
|
||||
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
* See the GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with matrix-glib-sdk. If not, see
|
||||
* <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef __MATRIX_ENUMTYPES_H__
|
||||
#define __MATRIX_ENUMTYPES_H__
|
||||
|
||||
#include <glib-object.h>
|
||||
|
||||
/*** END file-header ***/
|
||||
|
||||
/*** BEGIN file-production ***/
|
||||
/* enumerations from "@filename@" */
|
||||
|
||||
#include "@filename@"
|
||||
/*** END file-production ***/
|
||||
|
||||
/*** BEGIN value-header ***/
|
||||
|
||||
GType @enum_name@_get_type(void);
|
||||
#define @ENUMPREFIX@_TYPE_@ENUMSHORT@ (@enum_name@_get_type())
|
||||
/*** END value-header ***/
|
||||
|
||||
/*** BEGIN file-tail ***/
|
||||
|
||||
#endif /* __MATRIX_ENUMTYPES_H__ */
|
||||
/*** END file-tail ***/
|
322
src/matrix-event-base.vala
Normal file
322
src/matrix-event-base.vala
Normal file
@@ -0,0 +1,322 @@
|
||||
/*
|
||||
* This file is part of matrix-glib-sdk
|
||||
*
|
||||
* matrix-glib-sdk is free software: you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation, either
|
||||
* version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* matrix-glib-sdk is distributed in the hope that it will be
|
||||
* useful, but WITHOUT ANY WARRANTY; without even the implied
|
||||
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
* See the GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with matrix-glib-sdk. If not, see
|
||||
* <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Base class for Matrix events.
|
||||
*/
|
||||
public abstract class Matrix.Event.Base : GLib.Object,
|
||||
GLib.Initable,
|
||||
Json.Serializable {
|
||||
private Error? _construct_error = null;
|
||||
private bool _inited = false;
|
||||
private Json.Node? _json;
|
||||
|
||||
protected string? _event_type = null;
|
||||
|
||||
/**
|
||||
* The type of the event. It should be namespaced similar to the
|
||||
* Java package naming conventions,
|
||||
* e.g. `com.example.subdomain.event.type`. It cannot be changed
|
||||
* after object initialization.
|
||||
*/
|
||||
public string? event_type {
|
||||
get {
|
||||
return _event_type;
|
||||
}
|
||||
|
||||
construct {
|
||||
_event_type = value;
|
||||
}
|
||||
|
||||
default = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* The event as a JSON node.
|
||||
*/
|
||||
public Json.Node? json {
|
||||
get {
|
||||
_json = new Json.Node(Json.NodeType.OBJECT);
|
||||
_json.set_object(new Json.Object());
|
||||
|
||||
// Add the content node, as all event types must include it.
|
||||
var content_root = new Json.Node(Json.NodeType.OBJECT);
|
||||
var content_obj = new Json.Object();
|
||||
content_root.set_object(content_obj);
|
||||
_json.get_object().set_member("content", content_root);
|
||||
|
||||
try {
|
||||
to_json(_json);
|
||||
}
|
||||
catch (Matrix.Error e) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return _json;
|
||||
}
|
||||
|
||||
construct {
|
||||
if (value != null) {
|
||||
try {
|
||||
initialize_from_json(value);
|
||||
} catch (Matrix.Error e) {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Implementation of GLib.Initable
|
||||
|
||||
public bool
|
||||
init(GLib.Cancellable? cancellable = null)
|
||||
throws Error, Matrix.Error
|
||||
{
|
||||
if (cancellable != null) {
|
||||
throw new Matrix.Error.UNSUPPORTED(
|
||||
"Cancellable initialization not supported");
|
||||
}
|
||||
|
||||
if (_construct_error != null) {
|
||||
throw _construct_error;
|
||||
}
|
||||
|
||||
_inited = true;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// Implementation of Json.Serializable
|
||||
|
||||
|
||||
public unowned ParamSpec
|
||||
find_property(string name)
|
||||
{
|
||||
return get_class().find_property(name);
|
||||
}
|
||||
|
||||
public Json.Node
|
||||
serialize_property(string property_name,
|
||||
Value value,
|
||||
ParamSpec pspec)
|
||||
{
|
||||
return default_serialize_property(property_name, value, pspec);
|
||||
}
|
||||
|
||||
public bool
|
||||
deserialize_property(string property_name,
|
||||
out Value value,
|
||||
ParamSpec pspec,
|
||||
Json.Node property_node)
|
||||
{
|
||||
value = Value(pspec.value_type);
|
||||
|
||||
return default_deserialize_property(property_name,
|
||||
value,
|
||||
pspec,
|
||||
property_node);
|
||||
}
|
||||
|
||||
// Own methods
|
||||
|
||||
private void
|
||||
initialize_from_json(Json.Node json_data)
|
||||
throws Matrix.Error
|
||||
{
|
||||
Json.Object root;
|
||||
Json.Node node;
|
||||
|
||||
if (json_data.get_node_type() != Json.NodeType.OBJECT) {
|
||||
throw new Matrix.Error.INVALID_FORMAT(
|
||||
"The event is not valid");
|
||||
}
|
||||
|
||||
root = json_data.get_object();
|
||||
|
||||
if ((node = root.get_member("type")) == null) {
|
||||
throw new Matrix.Error.INCOMPLETE(
|
||||
"Event type is not specified");
|
||||
}
|
||||
|
||||
if ((_event_type != null)
|
||||
&& (_event_type != node.get_string())) {
|
||||
throw new Matrix.Error.INVALID_TYPE(
|
||||
"Changing event type is not supported");
|
||||
}
|
||||
|
||||
var evt_type = node.get_string();
|
||||
|
||||
if ((node = root.get_member("content")) == null) {
|
||||
warning("content key is missing from the %s event", evt_type);
|
||||
|
||||
// As event type objects depend on having this node, let’s
|
||||
// add it now.
|
||||
var content_node = new Json.Node(Json.NodeType.OBJECT);
|
||||
content_node.set_object(new Json.Object());
|
||||
root.set_member("content", content_node);
|
||||
}
|
||||
|
||||
from_json(json_data);
|
||||
|
||||
_event_type = evt_type;
|
||||
}
|
||||
|
||||
/**
|
||||
* Subclasses should implement this function to initialize
|
||||
* themselves from JSON data.
|
||||
*/
|
||||
public virtual void
|
||||
from_json(Json.Node json_data)
|
||||
throws Matrix.Error
|
||||
{
|
||||
var root = json_data.get_object();
|
||||
Json.Node? node;
|
||||
|
||||
if ((node = root.get_member("type")) != null) {
|
||||
_event_type = node.get_string();
|
||||
} else if (Config.DEBUG) {
|
||||
warning("type is not present in an event");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Subclasses should implement this to export their data to JSON.
|
||||
*/
|
||||
public virtual void
|
||||
to_json(Json.Node json_data)
|
||||
throws Matrix.Error
|
||||
{
|
||||
var root = json_data.get_object();
|
||||
|
||||
if (_event_type == null) {
|
||||
throw new Matrix.Error.INCOMPLETE(
|
||||
"Won't generate an event without type");
|
||||
}
|
||||
|
||||
root.set_string_member("type", _event_type);
|
||||
}
|
||||
|
||||
public static Base?
|
||||
new_from_json(owned string? event_type = null,
|
||||
Json.Node? json_data = null)
|
||||
throws Matrix.Error, GLib.Error
|
||||
{
|
||||
GLib.Type? event_gtype;
|
||||
Base? ret = null;
|
||||
|
||||
if (event_type == null) {
|
||||
if (json_data == null) {
|
||||
throw new Matrix.Error.INCOMPLETE(
|
||||
"Either event_type or json_data must be set!");
|
||||
}
|
||||
|
||||
if (json_data.get_node_type() != Json.NodeType.OBJECT) {
|
||||
throw new Matrix.Error.INVALID_FORMAT(
|
||||
"Event is not a JSON object!");
|
||||
}
|
||||
|
||||
Json.Node? node;
|
||||
|
||||
if ((node = json_data.get_object().get_member("type")) == null) {
|
||||
throw new Matrix.Error.INCOMPLETE(
|
||||
"event_type is null and JSON object doesn't contain type!");
|
||||
}
|
||||
|
||||
event_type = node.get_string();
|
||||
}
|
||||
|
||||
if ((event_gtype = get_handler(event_type)) == null) {
|
||||
throw new Matrix.Error.INVALID_TYPE(
|
||||
"No registered type for event type %s",
|
||||
event_type);
|
||||
}
|
||||
|
||||
ret = (Base)Object.new(event_gtype,
|
||||
event_type : event_type,
|
||||
json : json_data);
|
||||
|
||||
ret.init();
|
||||
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
||||
namespace Matrix.Event {
|
||||
|
||||
private HashTable<string, TypeClass>? type_handlers = null;
|
||||
|
||||
/**
|
||||
* Get the {@link GLib.Type} of the class that is registered to
|
||||
* handle events with type @param event_type.
|
||||
*
|
||||
* @param event_type the event type to look up
|
||||
* @return a {@link GLib.Type} or {@link Matrix.Event} if no
|
||||
* handler is registered
|
||||
*/
|
||||
public static GLib.Type?
|
||||
get_handler(string event_type)
|
||||
{
|
||||
unowned GLib.TypeClass? klass = null;
|
||||
|
||||
if ((type_handlers != null)
|
||||
&& ((klass = type_handlers.get(event_type)) != null)) {
|
||||
return klass.get_type();
|
||||
}
|
||||
|
||||
if (Config.DEBUG) {
|
||||
warning("No registered type for %s", event_type);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers @param event_type to be handled by the
|
||||
* type @param event_gtype.
|
||||
*
|
||||
* @param event_type the type of the event
|
||||
* @param event_gtype the {@link GLib.Type} of the event’s handler
|
||||
*/
|
||||
public static void
|
||||
register_type(string event_type, GLib.Type event_gtype)
|
||||
throws Matrix.Error
|
||||
{
|
||||
if (!event_gtype.is_a(typeof(Matrix.Event.Base))) {
|
||||
throw new Matrix.Error.INVALID_TYPE(
|
||||
"Invalid event type handler. It must be a subclass of MatrixEvent");
|
||||
}
|
||||
|
||||
if (type_handlers == null) {
|
||||
type_handlers = new HashTable<string, GLib.TypeClass>(
|
||||
str_hash, str_equal);
|
||||
}
|
||||
|
||||
type_handlers.replace(event_type, event_gtype.class_ref());
|
||||
}
|
||||
|
||||
/**
|
||||
* Unregister @param event_type.
|
||||
*
|
||||
* @param event_type the event type to remove
|
||||
*/
|
||||
public static void
|
||||
unregister_type(string event_type)
|
||||
{
|
||||
if (type_handlers != null) {
|
||||
type_handlers.remove(event_type);
|
||||
}
|
||||
}
|
||||
}
|
100
src/matrix-event-call-answer.vala
Normal file
100
src/matrix-event-call-answer.vala
Normal file
@@ -0,0 +1,100 @@
|
||||
/*
|
||||
* This file is part of matrix-glib-sdk
|
||||
*
|
||||
* matrix-glib-sdk is free software: you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation, either
|
||||
* version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* matrix-glib-sdk is distributed in the hope that it will be
|
||||
* useful, but WITHOUT ANY WARRANTY; without even the implied
|
||||
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
* See the GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with matrix-glib-sdk. If not, see
|
||||
* <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/**
|
||||
* This event is sent by the callee when they wish to answer the call.
|
||||
*/
|
||||
public class Matrix.Event.CallAnswer : Matrix.Event.Call {
|
||||
/**
|
||||
* The type of session description.
|
||||
*/
|
||||
public CallAnswerType answer_type { get; set; default = CallAnswerType.UNKNOWN; }
|
||||
|
||||
/**
|
||||
* The SDP text of the session description.
|
||||
*/
|
||||
public string? answer_sdp { get; set; default = null; }
|
||||
|
||||
protected override void
|
||||
from_json(Json.Node json_data)
|
||||
throws Matrix.Error
|
||||
{
|
||||
var content_root = json_data.get_object()
|
||||
.get_member("content").get_object();
|
||||
Json.Node? node;
|
||||
|
||||
if ((node = content_root.get_member("answer")) != null) {
|
||||
var answer_root = node.get_object();
|
||||
|
||||
if ((node = answer_root.get_member("type")) != null) {
|
||||
try {
|
||||
_answer_type = (CallAnswerType)_g_enum_nick_to_value(
|
||||
typeof(CallAnswerType), node.get_string());
|
||||
} catch (Matrix.Error e) {
|
||||
_answer_type = CallAnswerType.UNKNOWN;
|
||||
|
||||
if (Config.DEBUG) {
|
||||
warning("Unknown value %s for content.answer.type in a m.call.answer event",
|
||||
node.get_string());
|
||||
}
|
||||
}
|
||||
} else {
|
||||
warning("content.answer.type is missing from a m.call.answer event");
|
||||
}
|
||||
|
||||
if ((node = answer_root.get_member("sdp")) != null) {
|
||||
_answer_sdp = node.get_string();
|
||||
} else {
|
||||
warning("content.answer.sdp is missing from a m.call.answer event");
|
||||
}
|
||||
}
|
||||
|
||||
base.from_json(json_data);
|
||||
}
|
||||
|
||||
protected override void
|
||||
to_json(Json.Node json_data)
|
||||
throws Matrix.Error
|
||||
{
|
||||
if (_answer_type == CallAnswerType.UNKNOWN) {
|
||||
throw new Matrix.Error.INCOMPLETE(
|
||||
"Won't generate a m.call.answer event without a valid answer.type");
|
||||
}
|
||||
|
||||
if (_answer_sdp == null) {
|
||||
throw new Matrix.Error.INCOMPLETE(
|
||||
"Won't generate a m.call.answer event without answer.sdp");
|
||||
}
|
||||
|
||||
var content_root = json_data.get_object()
|
||||
.get_member("content").get_object();
|
||||
|
||||
var answer_root = new Json.Object();
|
||||
var answer_node = new Json.Node(Json.NodeType.OBJECT);
|
||||
answer_node.set_object(answer_root);
|
||||
|
||||
answer_root.set_string_member("type",
|
||||
_g_enum_value_to_nick(typeof(CallAnswerType),
|
||||
_answer_type));
|
||||
answer_root.set_string_member("sdp", _answer_sdp);
|
||||
|
||||
content_root.set_member("answer", answer_node);
|
||||
|
||||
base.to_json(json_data);
|
||||
}
|
||||
}
|
78
src/matrix-event-call-base.vala
Normal file
78
src/matrix-event-call-base.vala
Normal file
@@ -0,0 +1,78 @@
|
||||
/*
|
||||
* This file is part of matrix-glib-sdk
|
||||
*
|
||||
* matrix-glib-sdk is free software: you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation, either
|
||||
* version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* matrix-glib-sdk is distributed in the hope that it will be
|
||||
* useful, but WITHOUT ANY WARRANTY; without even the implied
|
||||
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
* See the GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with matrix-glib-sdk. If not, see
|
||||
* <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Base class for m.call.* events.
|
||||
*/
|
||||
public abstract class Matrix.Event.Call : Matrix.Event.Room {
|
||||
/**
|
||||
* The ID of the call this event relates to.
|
||||
*/
|
||||
public string? call_id { get; set; default = null; }
|
||||
|
||||
/**
|
||||
* The version of the VoIP specification this message adheres to.
|
||||
*/
|
||||
public int version { get; set; default = -1; }
|
||||
|
||||
protected override void
|
||||
from_json(Json.Node json_data)
|
||||
throws Matrix.Error
|
||||
{
|
||||
var content_root = json_data.get_object()
|
||||
.get_member("content").get_object();
|
||||
Json.Node? node;
|
||||
|
||||
if ((node = content_root.get_member("call_id")) != null) {
|
||||
_call_id = node.get_string();
|
||||
} else {
|
||||
warning("content.call_id is missing from a m.call.hangup event");
|
||||
}
|
||||
|
||||
if ((node = content_root.get_member("version")) != null) {
|
||||
_version = (int)node.get_int();
|
||||
} else {
|
||||
warning("content.version is missing from a m.call.hangup event");
|
||||
}
|
||||
|
||||
base.from_json(json_data);
|
||||
}
|
||||
|
||||
protected override void
|
||||
to_json(Json.Node json_data)
|
||||
throws Matrix.Error
|
||||
{
|
||||
if (_call_id == null) {
|
||||
throw new Matrix.Error.INCOMPLETE(
|
||||
"Won't generate a m.call.hangup event without call_id");
|
||||
}
|
||||
|
||||
if (_version < 0) {
|
||||
throw new Matrix.Error.INCOMPLETE(
|
||||
"Won't generate a m.call.hangup event without version");
|
||||
}
|
||||
|
||||
var content_root = json_data.get_object()
|
||||
.get_member("content").get_object();
|
||||
|
||||
content_root.set_string_member("call_id", _call_id);
|
||||
content_root.set_int_member("version", version);
|
||||
|
||||
base.to_json(json_data);
|
||||
}
|
||||
}
|
132
src/matrix-event-call-candidates.vala
Normal file
132
src/matrix-event-call-candidates.vala
Normal file
@@ -0,0 +1,132 @@
|
||||
/*
|
||||
* This file is part of matrix-glib-sdk
|
||||
*
|
||||
* matrix-glib-sdk is free software: you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation, either
|
||||
* version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* matrix-glib-sdk is distributed in the hope that it will be
|
||||
* useful, but WITHOUT ANY WARRANTY; without even the implied
|
||||
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
* See the GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with matrix-glib-sdk. If not, see
|
||||
* <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/**
|
||||
* This event is sent by callers after sending an invite and by the
|
||||
* callee after answering. Its purpose is to give the other party
|
||||
* additional ICE candidates to try using to communicate.
|
||||
*/
|
||||
public class Matrix.Event.CallCandidates : Matrix.Event.Call {
|
||||
public struct Candidate {
|
||||
string? sdp_mid; /// The SDP media type this candidate is
|
||||
/// intended for.
|
||||
int? sdp_line_index; /// The index of the SDP 'm' line this
|
||||
/// candidate is intended for.
|
||||
string? candidate; /// The SDP 'a' line of the candidate.
|
||||
}
|
||||
|
||||
/**
|
||||
* The list of candidates.
|
||||
*/
|
||||
public Candidate[] candidates { get; set; }
|
||||
|
||||
protected override void
|
||||
from_json(Json.Node json_data)
|
||||
throws Matrix.Error
|
||||
{
|
||||
var content_root = json_data.get_object()
|
||||
.get_member("content").get_object();
|
||||
Json.Node? node;
|
||||
|
||||
if ((node = content_root.get_member("candidates")) != null) {
|
||||
_candidates = new Candidate[node.get_array().get_length()];
|
||||
|
||||
node.get_array().foreach_element((ary, idx, cand_node) => {
|
||||
var cand_root = cand_node.get_object();
|
||||
var cand = Candidate();
|
||||
|
||||
if ((node = cand_root.get_member("sdpMid")) != null) {
|
||||
cand.sdp_mid = node.get_string();
|
||||
} else {
|
||||
warning("sdpMid is missing from a candidate of a m.call.candidates event");
|
||||
}
|
||||
|
||||
if ((node = cand_root.get_member("sdpMLineIndex")) != null) {
|
||||
cand.sdp_line_index = (int)node.get_int();
|
||||
} else {
|
||||
warning("sdpMLineIndex is missing from a candidate of a m.call.candidates event");
|
||||
}
|
||||
|
||||
if ((node = cand_root.get_member("candidate")) != null) {
|
||||
cand.candidate = node.get_string();
|
||||
} else {
|
||||
warning("candidate is missing from a candidate of a m.call.candidates event");
|
||||
}
|
||||
|
||||
_candidates[idx] = cand;
|
||||
});
|
||||
} else {
|
||||
warning("content.candidates is missing from a m.call.candidates event");
|
||||
}
|
||||
|
||||
base.from_json(json_data);
|
||||
}
|
||||
|
||||
protected override void
|
||||
to_json(Json.Node json_data)
|
||||
throws Matrix.Error
|
||||
{
|
||||
if (_candidates.length < 1) {
|
||||
throw new Matrix.Error.INCOMPLETE(
|
||||
"Won't generate a m.call.candidates event without candidates");
|
||||
}
|
||||
|
||||
var content_root = json_data.get_object()
|
||||
.get_member("content").get_object();
|
||||
|
||||
var cands = new Json.Array();
|
||||
|
||||
foreach (var entry in _candidates) {
|
||||
if (entry.sdp_mid == null) {
|
||||
throw new Matrix.Error.INCOMPLETE(
|
||||
"Won't generate a m.call.candidates event with a missing sdpMid for candidates");
|
||||
}
|
||||
|
||||
if (entry.sdp_line_index == null) {
|
||||
throw new Matrix.Error.INCOMPLETE(
|
||||
"Won't generate a m.call.candidates event with a missing sdpMLineIndex for candidates");
|
||||
}
|
||||
|
||||
if (entry.candidate == null) {
|
||||
throw new Matrix.Error.INCOMPLETE(
|
||||
"Won't generate a m.call.candidates event with a missing candidate for candidates");
|
||||
}
|
||||
|
||||
var cand_obj = new Json.Object();
|
||||
var cand_node = new Json.Node(Json.NodeType.OBJECT);
|
||||
cand_node.set_object(cand_obj);
|
||||
|
||||
cand_obj.set_string_member("sdpMid", entry.sdp_mid);
|
||||
cand_obj.set_int_member("sdpMLineIndex", entry.sdp_line_index);
|
||||
cand_obj.set_string_member("candidate", entry.candidate);
|
||||
|
||||
cands.add_element(cand_node);
|
||||
}
|
||||
|
||||
if (cands.get_length() < 1) {
|
||||
throw new Matrix.Error.INCOMPLETE(
|
||||
"Won't generate a m.call.candidates event with empty candidates list");
|
||||
}
|
||||
|
||||
var cands_node = new Json.Node(Json.NodeType.ARRAY);
|
||||
cands_node.set_array(cands);
|
||||
content_root.set_member("candidates", cands_node);
|
||||
|
||||
base.to_json(json_data);
|
||||
}
|
||||
}
|
38
src/matrix-event-call-hangup.vala
Normal file
38
src/matrix-event-call-hangup.vala
Normal file
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
* This file is part of matrix-glib-sdk
|
||||
*
|
||||
* matrix-glib-sdk is free software: you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation, either
|
||||
* version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* matrix-glib-sdk is distributed in the hope that it will be
|
||||
* useful, but WITHOUT ANY WARRANTY; without even the implied
|
||||
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
* See the GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with matrix-glib-sdk. If not, see
|
||||
* <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Sent by either party to signal their termination of the call. This
|
||||
* can be sent either once the call has has been established or before
|
||||
* to abort the call.
|
||||
*/
|
||||
public class Matrix.Event.CallHangup : Matrix.Event.Call {
|
||||
protected override void
|
||||
from_json(Json.Node json_data)
|
||||
throws Matrix.Error
|
||||
{
|
||||
base.from_json(json_data);
|
||||
}
|
||||
|
||||
protected override void
|
||||
to_json(Json.Node json_data)
|
||||
throws Matrix.Error
|
||||
{
|
||||
base.to_json(json_data);
|
||||
}
|
||||
}
|
122
src/matrix-event-call-invite.vala
Normal file
122
src/matrix-event-call-invite.vala
Normal file
@@ -0,0 +1,122 @@
|
||||
/*
|
||||
* This file is part of matrix-glib-sdk
|
||||
*
|
||||
* matrix-glib-sdk is free software: you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation, either
|
||||
* version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* matrix-glib-sdk is distributed in the hope that it will be
|
||||
* useful, but WITHOUT ANY WARRANTY; without even the implied
|
||||
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
* See the GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with matrix-glib-sdk. If not, see
|
||||
* <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/**
|
||||
* This event is sent by the caller when they wish to establish a
|
||||
* call.
|
||||
*/
|
||||
public class Matrix.Event.CallInvite : Matrix.Event.Call {
|
||||
/**
|
||||
* The type of session description.
|
||||
*/
|
||||
public CallOfferType offer_type { get; set; default = CallOfferType.UNKNOWN; }
|
||||
/**
|
||||
* The SDP text of the session description.
|
||||
*/
|
||||
public string? sdp { get; set; default = null; }
|
||||
|
||||
/**
|
||||
* The time in milliseconds that the invite is valid for. Once the
|
||||
* invite age exceeds this value, clients should discard it. They
|
||||
* should also no longer show the call as awaiting an answer in
|
||||
* the UI.
|
||||
*/
|
||||
public int lifetime { get; set; default = -1; }
|
||||
|
||||
protected override void
|
||||
from_json(Json.Node json_data)
|
||||
throws Matrix.Error
|
||||
{
|
||||
var content_root = json_data.get_object()
|
||||
.get_member("content").get_object();
|
||||
Json.Node? node;
|
||||
|
||||
if ((node = content_root.get_member("offer")) != null) {
|
||||
var offer_node = node.get_object();
|
||||
|
||||
if ((node = offer_node.get_member("type")) != null) {
|
||||
try {
|
||||
_offer_type = (CallOfferType)_g_enum_nick_to_value(
|
||||
typeof(CallOfferType), node.get_string());
|
||||
} catch (Matrix.Error e) {
|
||||
_offer_type = CallOfferType.UNKNOWN;
|
||||
|
||||
if (Config.DEBUG) {
|
||||
warning("Unknown value %s in content.offer.type of a m.call.invite event",
|
||||
node.get_string());
|
||||
}
|
||||
}
|
||||
} else {
|
||||
warning("content.offer.type is missing from a m.call.invite event");
|
||||
}
|
||||
|
||||
if ((node = offer_node.get_member("sdp")) != null) {
|
||||
_sdp = node.get_string();
|
||||
} else {
|
||||
warning("content.offer.sdp is missing from a m.call.invite event");
|
||||
}
|
||||
}
|
||||
|
||||
if ((node = content_root.get_member("lifetime")) != null) {
|
||||
_lifetime = (int)node.get_int();
|
||||
} else {
|
||||
warning("content.lifetime is missing from a m.call.invite event");
|
||||
}
|
||||
|
||||
base.from_json(json_data);
|
||||
}
|
||||
|
||||
protected override void
|
||||
to_json(Json.Node json_data)
|
||||
throws Matrix.Error
|
||||
{
|
||||
if (_offer_type == CallOfferType.UNKNOWN) {
|
||||
throw new Matrix.Error.INCOMPLETE(
|
||||
"Won't generate a m.call.invite without a valid offer.type");
|
||||
}
|
||||
|
||||
if (_sdp == null) {
|
||||
throw new Matrix.Error.INCOMPLETE(
|
||||
"Won't generate a m.call.invite without offer.sdp");
|
||||
}
|
||||
|
||||
if (_lifetime < 0) {
|
||||
throw new Matrix.Error.INCOMPLETE(
|
||||
"Won't generate a m.call.invite without lifetime");
|
||||
}
|
||||
|
||||
var content_root = json_data.get_object()
|
||||
.get_member("content").get_object();
|
||||
|
||||
content_root.set_int_member("lifetime", _lifetime);
|
||||
|
||||
var offer_root = new Json.Object();
|
||||
var offer_node = new Json.Node(Json.NodeType.OBJECT);
|
||||
offer_node.set_object(offer_root);
|
||||
|
||||
offer_root.set_string_member(
|
||||
"type",
|
||||
_g_enum_value_to_nick(typeof(CallOfferType),
|
||||
_offer_type));
|
||||
offer_root.set_string_member("sdp", _sdp);
|
||||
|
||||
content_root.set_member("offer", offer_node);
|
||||
|
||||
base.to_json(json_data);
|
||||
}
|
||||
}
|
159
src/matrix-event-presence.vala
Normal file
159
src/matrix-event-presence.vala
Normal file
@@ -0,0 +1,159 @@
|
||||
/*
|
||||
* This file is part of matrix-glib-sdk
|
||||
*
|
||||
* matrix-glib-sdk is free software: you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation, either
|
||||
* version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* matrix-glib-sdk is distributed in the hope that it will be
|
||||
* useful, but WITHOUT ANY WARRANTY; without even the implied
|
||||
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
* See the GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with matrix-glib-sdk. If not, see
|
||||
* <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Class for representing presence events
|
||||
*
|
||||
* Informs the client of a user's presence state change.
|
||||
*/
|
||||
public class Matrix.Event.Presence : Matrix.Event.Base {
|
||||
/**
|
||||
* The current avatar URL for this user, if any.
|
||||
*/
|
||||
public string? avatar_url { get; set; }
|
||||
|
||||
/**
|
||||
* The current display name for this user, if any.
|
||||
*/
|
||||
public string? display_name { get; set; }
|
||||
|
||||
/**
|
||||
* The last time since this used performed some action, in
|
||||
* milliseconds.
|
||||
*
|
||||
* This won’t get into the generated event JSON if negative.
|
||||
*/
|
||||
public long last_active_ago { get; set; default = -1; }
|
||||
|
||||
/**
|
||||
* The user's ID.
|
||||
*/
|
||||
public string? user_id { get; set; default = null; }
|
||||
|
||||
public string? event_id { get; set; default = null; }
|
||||
|
||||
/**
|
||||
* The presence state for this user.
|
||||
*/
|
||||
public Matrix.Presence presence {
|
||||
get; set;
|
||||
|
||||
default = Matrix.Presence.UNKNOWN;
|
||||
}
|
||||
|
||||
protected override void
|
||||
from_json(Json.Node json_data)
|
||||
throws Matrix.Error
|
||||
{
|
||||
var root = json_data.get_object();
|
||||
var content_root = root.get_member("content").get_object();
|
||||
Json.Node? node;
|
||||
|
||||
if ((node = root.get_member("event_id")) != null) {
|
||||
_event_id = node.get_string();
|
||||
} else if (Config.DEBUG) {
|
||||
warning("event_id is missing from a m.presence event");
|
||||
}
|
||||
|
||||
if ((node = content_root.get_member("user_id")) != null) {
|
||||
_user_id = node.get_string();
|
||||
} else if (Config.DEBUG) {
|
||||
warning("content.user_id is missing from the m.presence event");
|
||||
|
||||
// Workaround for having sender instead of content.user_id
|
||||
// in most (room-dependent) presence events
|
||||
if ((node = root.get_member("sender")) != null) {
|
||||
_user_id = node.get_string();
|
||||
}
|
||||
}
|
||||
|
||||
if ((node = content_root.get_member("last_active_ago")) != null) {
|
||||
_last_active_ago = (long)node.get_int();
|
||||
}
|
||||
|
||||
if ((node = content_root.get_member("avatar_url")) != null) {
|
||||
_avatar_url = node.get_string();
|
||||
}
|
||||
|
||||
if ((node = content_root.get_member("displayname")) != null) {
|
||||
_display_name = node.get_string();
|
||||
}
|
||||
|
||||
if ((node = content_root.get_member("presence")) != null) {
|
||||
try {
|
||||
_presence = (Matrix.Presence)_g_enum_nick_to_value(
|
||||
typeof(Matrix.Presence), node.get_string());
|
||||
} catch (Matrix.Error e) {
|
||||
_presence = Matrix.Presence.UNKNOWN;
|
||||
|
||||
if (Config.DEBUG) {
|
||||
warning("Unknown value %s for content.presence in a m.presence event",
|
||||
node.get_string());
|
||||
}
|
||||
}
|
||||
} else if (Config.DEBUG) {
|
||||
warning("content.presence is missing from the m.presence event");
|
||||
}
|
||||
|
||||
base.from_json(json_data);
|
||||
}
|
||||
|
||||
protected override void
|
||||
to_json(Json.Node json_data)
|
||||
throws Matrix.Error
|
||||
{
|
||||
if (_presence == Matrix.Presence.UNKNOWN) {
|
||||
throw new Matrix.Error.UNKNOWN_VALUE(
|
||||
"Won't generate a m.presence event with an unkwnown presence");
|
||||
}
|
||||
|
||||
if (_user_id == null) {
|
||||
throw new Matrix.Error.INCOMPLETE(
|
||||
"Won't generate a m.presence event without sender");
|
||||
}
|
||||
|
||||
if (_event_id == null) {
|
||||
throw new Matrix.Error.INCOMPLETE(
|
||||
"Won't generate a m.presence event without event_id");
|
||||
}
|
||||
|
||||
var root = json_data.get_object();
|
||||
var content_root = root.get_member("content").get_object();
|
||||
|
||||
root.set_string_member("event_id", _event_id);
|
||||
|
||||
content_root.set_string_member("user_id", _user_id);
|
||||
content_root.set_string_member("presence",
|
||||
_g_enum_value_to_nick(typeof(Presence),
|
||||
_presence));
|
||||
|
||||
if (last_active_ago >= 0) {
|
||||
content_root.set_int_member("last_active_ago", last_active_ago);
|
||||
}
|
||||
|
||||
if (avatar_url != null) {
|
||||
content_root.set_string_member("avatar_url", avatar_url);
|
||||
}
|
||||
|
||||
if (display_name != null) {
|
||||
content_root.set_string_member("displayname", display_name);
|
||||
}
|
||||
|
||||
base.to_json(json_data);
|
||||
}
|
||||
}
|
171
src/matrix-event-receipt.vala
Normal file
171
src/matrix-event-receipt.vala
Normal file
@@ -0,0 +1,171 @@
|
||||
/*
|
||||
* This file is part of matrix-glib-sdk
|
||||
*
|
||||
* matrix-glib-sdk is free software: you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation, either
|
||||
* version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* matrix-glib-sdk is distributed in the hope that it will be
|
||||
* useful, but WITHOUT ANY WARRANTY; without even the implied
|
||||
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
* See the GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with matrix-glib-sdk. If not, see
|
||||
* <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Class to hold m.receipt events.
|
||||
*
|
||||
* Informs the client of new receipts.
|
||||
*/
|
||||
public class Matrix.Event.Receipt : Matrix.Event.Base {
|
||||
public string? room_id { get; set; default = null; }
|
||||
|
||||
private struct ReceiptData {
|
||||
string event_id;
|
||||
string typ;
|
||||
string user;
|
||||
}
|
||||
|
||||
private HashTable<ReceiptData?, ulong?> _receipt_data = null;
|
||||
|
||||
private static bool
|
||||
_rd_equal(ReceiptData k1, ReceiptData k2)
|
||||
{
|
||||
return ((k1.event_id == k2.event_id)
|
||||
&& (k1.typ == k2.typ)
|
||||
&& (k1.user == k2.user));
|
||||
}
|
||||
|
||||
private void
|
||||
_init_receipt_data()
|
||||
{
|
||||
_receipt_data = new HashTable<ReceiptData?, ulong?>(null, (EqualFunc)_rd_equal);
|
||||
}
|
||||
|
||||
protected override void
|
||||
from_json(Json.Node json_data)
|
||||
throws Matrix.Error
|
||||
{
|
||||
var root = json_data.get_object();
|
||||
var content_root = root.get_member("content").get_object();
|
||||
Json.Node? node;
|
||||
|
||||
if ((node = root.get_member("room_id")) != null) {
|
||||
_room_id = node.get_string();
|
||||
} else if (Config.DEBUG) {
|
||||
warning("room_id is missing from a m.receipt event");
|
||||
}
|
||||
|
||||
content_root.foreach_member((obj, event_id, event_content) => {
|
||||
if ((node = event_content.get_object()
|
||||
.get_member("m.read")) != null) {
|
||||
var read_obj = node.get_object();
|
||||
read_obj.foreach_member((robj, r_user_id, r_content) => {
|
||||
if (_receipt_data == null) {
|
||||
_init_receipt_data();
|
||||
}
|
||||
|
||||
ReceiptData rd_key = ReceiptData() {
|
||||
event_id = event_id,
|
||||
typ = "m.read",
|
||||
user = r_user_id
|
||||
};
|
||||
|
||||
_receipt_data[rd_key] =
|
||||
(ulong)r_content.get_object().get_member("ts").get_int();
|
||||
});
|
||||
} else {
|
||||
warning("content.$event-id.m.read is missing from a m.presence event");
|
||||
}
|
||||
});
|
||||
|
||||
base.from_json(json_data);
|
||||
}
|
||||
|
||||
protected override void
|
||||
to_json(Json.Node json_data)
|
||||
throws Matrix.Error
|
||||
{
|
||||
Json.Node? node = null;
|
||||
|
||||
if (_room_id == null) {
|
||||
throw new Matrix.Error.INCOMPLETE(
|
||||
"Won't generate a m.receipt without room_id");
|
||||
}
|
||||
|
||||
var root = json_data.get_object();
|
||||
var content_root = root.get_member("content").get_object();
|
||||
int i = 0;
|
||||
Matrix.Error? error = null;
|
||||
|
||||
_receipt_data.foreach(
|
||||
(key, value) => {
|
||||
Json.Object event_object;
|
||||
Json.Object type_object;
|
||||
Json.Object user_object;
|
||||
|
||||
if (key.event_id == null) {
|
||||
error = new Matrix.Error.INCOMPLETE(
|
||||
"Won't generate a m.receipt event with an empty event ID");
|
||||
}
|
||||
|
||||
if (key.typ == null) {
|
||||
error = new Matrix.Error.INCOMPLETE(
|
||||
"Won't generate a m.receipt event with an empty receipt type");
|
||||
}
|
||||
|
||||
if (key.user == null) {
|
||||
error = new Matrix.Error.INCOMPLETE(
|
||||
"Won't generate a m.receipt event with an empty user ID");
|
||||
}
|
||||
|
||||
i++;
|
||||
|
||||
if ((node = content_root.get_member(key.event_id)) == null) {
|
||||
event_object = new Json.Object();
|
||||
node = new Json.Node(Json.NodeType.OBJECT);
|
||||
node.set_object(event_object);
|
||||
content_root.set_member(key.event_id, node);
|
||||
} else {
|
||||
event_object = node.get_object();
|
||||
}
|
||||
|
||||
if ((node = event_object.get_member(key.typ)) == null) {
|
||||
type_object = new Json.Object();
|
||||
node = new Json.Node(Json.NodeType.OBJECT);
|
||||
node.set_object(type_object);
|
||||
event_object.set_member(key.typ, node);
|
||||
} else {
|
||||
type_object = node.get_object();
|
||||
}
|
||||
|
||||
if ((node = type_object.get_member(key.user)) == null) {
|
||||
user_object = new Json.Object();
|
||||
node = new Json.Node(Json.NodeType.OBJECT);
|
||||
node.set_object(user_object);
|
||||
type_object.set_member(key.user, node);
|
||||
} else {
|
||||
user_object = node.get_object();
|
||||
}
|
||||
|
||||
user_object.set_int_member("ts", value);
|
||||
});
|
||||
|
||||
if (error != null) {
|
||||
throw error;
|
||||
}
|
||||
|
||||
if (i == 0) {
|
||||
throw new Matrix.Error.INCOMPLETE(
|
||||
"Won't generate a m.receipt event with no receipts");
|
||||
}
|
||||
|
||||
root.set_string_member("room_id", _room_id);
|
||||
|
||||
base.to_json(json_data);
|
||||
}
|
||||
}
|
87
src/matrix-event-room-aliases.vala
Normal file
87
src/matrix-event-room-aliases.vala
Normal file
@@ -0,0 +1,87 @@
|
||||
/*
|
||||
* This file is part of matrix-glib-sdk
|
||||
*
|
||||
* matrix-glib-sdk is free software: you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation, either
|
||||
* version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* matrix-glib-sdk is distributed in the hope that it will be
|
||||
* useful, but WITHOUT ANY WARRANTY; without even the implied
|
||||
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
* See the GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with matrix-glib-sdk. If not, see
|
||||
* <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Class to hold a m.room.aliases event.
|
||||
*
|
||||
* This event is sent by a homeserver directly to inform of changes to
|
||||
* the list of aliases it knows about for that room.
|
||||
*
|
||||
* The state_key for this event is set to the homeserver which owns
|
||||
* the room alias.
|
||||
*
|
||||
* The entire set of known aliases for the room is the union of all
|
||||
* the m.room.aliases events, one for each homeserver. Clients should
|
||||
* check the validity of any room alias given in this list before
|
||||
* presenting it to the user as trusted fact. The lists given by this
|
||||
* event should be considered simply as advice on which aliases might
|
||||
* exist, for which the client can perform the lookup to confirm
|
||||
* whether it receives the correct room ID.
|
||||
*/
|
||||
public class Matrix.Event.RoomAliases : Matrix.Event.State {
|
||||
/**
|
||||
* A list of room aliases.
|
||||
*/
|
||||
public string[] aliases { get; set; }
|
||||
|
||||
protected override void
|
||||
from_json(Json.Node json_data)
|
||||
throws Matrix.Error
|
||||
{
|
||||
var content_root = json_data.get_object()
|
||||
.get_member("content").get_object();
|
||||
Json.Node? node;
|
||||
|
||||
if ((node = content_root.get_member("aliases")) != null) {
|
||||
_aliases = new string[node.get_array().get_length()];
|
||||
|
||||
node.get_array().foreach_element((ary, idx, member_node) => {
|
||||
_aliases[idx] = member_node.get_string();
|
||||
});
|
||||
} else if (Config.DEBUG) {
|
||||
warning("content.aliases is missing from a m.room.aliases event");
|
||||
}
|
||||
|
||||
base.from_json(json_data);
|
||||
}
|
||||
|
||||
protected override void
|
||||
to_json(Json.Node json_data)
|
||||
throws Matrix.Error
|
||||
{
|
||||
if (_aliases.length == 0) {
|
||||
throw new Matrix.Error.INCOMPLETE(
|
||||
"Won't generate a m.room.aliases event without aliases");
|
||||
}
|
||||
|
||||
var content_root = json_data.get_object()
|
||||
.get_member("content").get_object();
|
||||
|
||||
var aliases_ary = new Json.Array();
|
||||
|
||||
foreach (var entry in _aliases) {
|
||||
aliases_ary.add_string_element(entry);
|
||||
}
|
||||
|
||||
var aliases_node = new Json.Node(Json.NodeType.ARRAY);
|
||||
aliases_node.set_array(aliases_ary);
|
||||
content_root.set_member("aliases", aliases_node);
|
||||
|
||||
base.to_json(json_data);
|
||||
}
|
||||
}
|
121
src/matrix-event-room-avatar.vala
Normal file
121
src/matrix-event-room-avatar.vala
Normal file
@@ -0,0 +1,121 @@
|
||||
/*
|
||||
* This file is part of matrix-glib-sdk
|
||||
*
|
||||
* matrix-glib-sdk is free software: you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation, either
|
||||
* version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* matrix-glib-sdk is distributed in the hope that it will be
|
||||
* useful, but WITHOUT ANY WARRANTY; without even the implied
|
||||
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
* See the GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with matrix-glib-sdk. If not, see
|
||||
* <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Class to hold a m.room.avatar event
|
||||
*
|
||||
* A picture that is associated with the room. This can be displayed
|
||||
* alongside the room information.
|
||||
*/
|
||||
public class Matrix.Event.RoomAvatar : Matrix.Event.State {
|
||||
/**
|
||||
* The URL to the image.
|
||||
*/
|
||||
public string? url { get; set; default = null; }
|
||||
|
||||
/**
|
||||
* The URL to the thumbnail of the image.
|
||||
*/
|
||||
public string? thumbnail_url { get; set; default = null; }
|
||||
|
||||
/**
|
||||
* Metadata about the image referred to in url.
|
||||
*/
|
||||
public ImageInfo? info { get; set; default = null; }
|
||||
|
||||
/**
|
||||
* Metadata about the image referred to in thumbnail_url.
|
||||
*/
|
||||
public ImageInfo? thumbnail_info { get; set; default = null; }
|
||||
|
||||
protected override void
|
||||
from_json(Json.Node json_data)
|
||||
throws Matrix.Error
|
||||
{
|
||||
var root = json_data.get_object();
|
||||
var content_root = root.get_member("content").get_object();
|
||||
Json.Node? node;
|
||||
|
||||
if (Config.DEBUG) {
|
||||
if ((node = root.get_member("state_key")) != null) {
|
||||
var sk = node.get_string();
|
||||
|
||||
if (sk != "") {
|
||||
warning("state_key of a m.room.avatar event is non-empty");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ((node = content_root.get_member("url")) != null) {
|
||||
_url = node.get_string();
|
||||
} else {
|
||||
warning("content.url is missing from a m.room.avatar event");
|
||||
}
|
||||
|
||||
if ((node = content_root.get_member("thumbnail_url")) != null) {
|
||||
_thumbnail_url = node.get_string();
|
||||
}
|
||||
|
||||
if ((node = content_root.get_member("info")) != null) {
|
||||
_info = ImageInfo();
|
||||
_info.set_from_json(node);
|
||||
}
|
||||
|
||||
if ((node = content_root.get_member("thumbnail_info")) != null) {
|
||||
_thumbnail_info = ImageInfo();
|
||||
_thumbnail_info.set_from_json(node);
|
||||
}
|
||||
|
||||
base.from_json(json_data);
|
||||
}
|
||||
|
||||
protected override void
|
||||
to_json(Json.Node json_data)
|
||||
throws Matrix.Error
|
||||
{
|
||||
if (_url == null) {
|
||||
throw new Matrix.Error.INCOMPLETE(
|
||||
"Won't generate a m.room.avatar event without url");
|
||||
}
|
||||
|
||||
var root = json_data.get_object();
|
||||
var content_root = root.get_member("content").get_object();
|
||||
|
||||
if (_state_key != "") {
|
||||
throw new Matrix.Error.INCOMPLETE(
|
||||
"Won't generate a m.room.avatar event with a non-empty state_key");
|
||||
}
|
||||
|
||||
content_root.set_string_member("url", _url);
|
||||
|
||||
if (_thumbnail_url != null) {
|
||||
content_root.set_string_member("thumbnail_url", _thumbnail_url);
|
||||
}
|
||||
|
||||
if (_info != null) {
|
||||
content_root.set_member("info", _info.get_json_node());
|
||||
}
|
||||
|
||||
if (_thumbnail_info != null) {
|
||||
content_root.set_member("thumbnail_info",
|
||||
_thumbnail_info.get_json_node());
|
||||
}
|
||||
|
||||
base.to_json(json_data);
|
||||
}
|
||||
}
|
147
src/matrix-event-room-base.vala
Normal file
147
src/matrix-event-room-base.vala
Normal file
@@ -0,0 +1,147 @@
|
||||
/*
|
||||
* This file is part of matrix-glib-sdk
|
||||
*
|
||||
* matrix-glib-sdk is free software: you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation, either
|
||||
* version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* matrix-glib-sdk is distributed in the hope that it will be
|
||||
* useful, but WITHOUT ANY WARRANTY; without even the implied
|
||||
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
* See the GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with matrix-glib-sdk. If not, see
|
||||
* <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Abstract base class for room events.
|
||||
*/
|
||||
public abstract class Matrix.Event.Room : Matrix.Event.Base {
|
||||
/**
|
||||
* A globally unique event ID. Required.
|
||||
*/
|
||||
public string? event_id { get; set; default = null; }
|
||||
|
||||
/**
|
||||
* The ID of the room associated with this event. Required, but it
|
||||
* may be stripped by HS implementations from some APIs if they
|
||||
* reside under a key marked with the room ID.
|
||||
*/
|
||||
public string? room_id { get; set; default = null; }
|
||||
|
||||
/**
|
||||
* The fully qualified Matrix ID of the user who sent the
|
||||
* event. Required.
|
||||
*/
|
||||
public string? sender { get; set; default = null; }
|
||||
|
||||
/**
|
||||
* The time, in milliseconds, that has elapsed since the event was
|
||||
* sent. This is part of the unsigned event data.
|
||||
*
|
||||
* This value will be omitted from the generated event JSON if
|
||||
* less than zero.
|
||||
*/
|
||||
public long age { get; set; default = 0; }
|
||||
|
||||
/**
|
||||
* The reason this event was redacted, if it was redacted.
|
||||
*/
|
||||
public string? redacted_because { get; set; default = null; }
|
||||
|
||||
/**
|
||||
* The client-supplied transaction ID. This should only be set if
|
||||
* the client being given the event is the same one which sent it.
|
||||
*/
|
||||
public string? transaction_id { get; set; default = null; }
|
||||
|
||||
protected override void
|
||||
from_json(Json.Node json_data)
|
||||
throws Matrix.Error
|
||||
{
|
||||
Json.Node? node;
|
||||
var root = json_data.get_object();
|
||||
|
||||
if ((node = root.get_member("event_id")) != null) {
|
||||
_event_id = node.get_string();
|
||||
} else if (Config.DEBUG) {
|
||||
warning("event_id is missing from a Room event");
|
||||
}
|
||||
|
||||
if ((node = root.get_member("room_id")) != null) {
|
||||
_room_id = node.get_string();
|
||||
} else if (Config.DEBUG) {
|
||||
warning("room_id is missing from a Room event");
|
||||
}
|
||||
|
||||
if ((node = root.get_member("sender")) != null) {
|
||||
_sender = node.get_string();
|
||||
} else if (Config.DEBUG) {
|
||||
warning("sender is missing from a Room event");
|
||||
}
|
||||
|
||||
if ((node = root.get_member("unsigned")) != null) {
|
||||
var unsigned_root = node.get_object();
|
||||
|
||||
if ((node = unsigned_root.get_member("age")) != null) {
|
||||
_age = (int)node.get_int();
|
||||
}
|
||||
|
||||
if ((node = unsigned_root.get_member("redacted_because")) != null) {
|
||||
_redacted_because = node.get_string();
|
||||
}
|
||||
|
||||
if ((node = unsigned_root.get_member("transaction_id")) != null) {
|
||||
_transaction_id = node.get_string();
|
||||
}
|
||||
}
|
||||
|
||||
base.from_json(json_data);
|
||||
}
|
||||
|
||||
protected override void
|
||||
to_json(Json.Node json_data)
|
||||
throws Matrix.Error
|
||||
{
|
||||
var root_obj = json_data.get_object();
|
||||
|
||||
if (event_id != null) {
|
||||
root_obj.set_string_member("event_id", _event_id);
|
||||
}
|
||||
|
||||
if (room_id != null) {
|
||||
root_obj.set_string_member("room_id", _room_id);
|
||||
}
|
||||
|
||||
if (sender != null) {
|
||||
root_obj.set_string_member("sender", _sender);
|
||||
}
|
||||
|
||||
var unsigned_obj = new Json.Object();
|
||||
|
||||
if (age >= 0) {
|
||||
unsigned_obj.set_int_member("age", _age);
|
||||
}
|
||||
|
||||
if (redacted_because != null) {
|
||||
unsigned_obj.set_string_member("redacted_because",
|
||||
_redacted_because);
|
||||
}
|
||||
|
||||
if (transaction_id != null) {
|
||||
unsigned_obj.set_string_member("transaction_id",
|
||||
_transaction_id);
|
||||
}
|
||||
|
||||
if (unsigned_obj.get_size() > 0) {
|
||||
var unsigned_node = new Json.Node(Json.NodeType.OBJECT);
|
||||
unsigned_node.set_object(unsigned_obj);
|
||||
root_obj.set_member("unsigned", unsigned_node);
|
||||
}
|
||||
|
||||
base.to_json(json_data);
|
||||
}
|
||||
}
|
71
src/matrix-event-room-canonical-alias.vala
Normal file
71
src/matrix-event-room-canonical-alias.vala
Normal file
@@ -0,0 +1,71 @@
|
||||
/*
|
||||
* This file is part of matrix-glib-sdk
|
||||
*
|
||||
* matrix-glib-sdk is free software: you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation, either
|
||||
* version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* matrix-glib-sdk is distributed in the hope that it will be
|
||||
* useful, but WITHOUT ANY WARRANTY; without even the implied
|
||||
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
* See the GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with matrix-glib-sdk. If not, see
|
||||
* <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Class to hold a m.room.canonical_alias event
|
||||
*
|
||||
* This event is used to inform the room about which alias should be
|
||||
* considered the canonical one. This could be for display purposes or
|
||||
* as suggestion to users which alias to use to advertise the room.
|
||||
*/
|
||||
public class Matrix.Event.RoomCanonicalAlias : Matrix.Event.State {
|
||||
/**
|
||||
* The canonical alias.
|
||||
*/
|
||||
public string? canonical_alias { get; set; default = null; }
|
||||
|
||||
protected override void
|
||||
from_json(Json.Node json_data)
|
||||
throws Matrix.Error
|
||||
{
|
||||
var root = json_data.get_object();
|
||||
var content_root = root.get_member("content").get_object();
|
||||
Json.Node? node = null;
|
||||
|
||||
if (Config.DEBUG && ((node = root.get_member("state_key")) != null)) {
|
||||
if (node.get_string() != "") {
|
||||
warning("state_key of a m.room.canonical_alias event is non-empty");
|
||||
}
|
||||
}
|
||||
|
||||
if ((node = content_root.get_member("alias")) != null) {
|
||||
_canonical_alias = node.get_string();
|
||||
}
|
||||
|
||||
base.from_json(json_data);
|
||||
}
|
||||
|
||||
protected override void
|
||||
to_json(Json.Node json_data)
|
||||
throws Matrix.Error
|
||||
{
|
||||
var content_root = json_data.get_object()
|
||||
.get_member("content").get_object();
|
||||
|
||||
if (_state_key != "") {
|
||||
throw new Matrix.Error.INCOMPLETE(
|
||||
"Won't generate a m.room.canonical_alias event with a non-empty state_key");
|
||||
}
|
||||
|
||||
if (_canonical_alias != null) {
|
||||
content_root.set_string_member("alias", _canonical_alias);
|
||||
}
|
||||
|
||||
base.to_json(json_data);
|
||||
}
|
||||
}
|
86
src/matrix-event-room-create.vala
Normal file
86
src/matrix-event-room-create.vala
Normal file
@@ -0,0 +1,86 @@
|
||||
/*
|
||||
* This file is part of matrix-glib-sdk
|
||||
*
|
||||
* matrix-glib-sdk is free software: you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation, either
|
||||
* version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* matrix-glib-sdk is distributed in the hope that it will be
|
||||
* useful, but WITHOUT ANY WARRANTY; without even the implied
|
||||
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
* See the GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with matrix-glib-sdk. If not, see
|
||||
* <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Class to hold a m.room.create event
|
||||
*
|
||||
* This is the first event in a room and cannot be changed. It acts as
|
||||
* the root of all other events.
|
||||
*/
|
||||
public class Matrix.Event.RoomCreate : Matrix.Event.State {
|
||||
/**
|
||||
* The user_id of the room creator. This is set by the homeserver.
|
||||
*/
|
||||
public string? creator { get; set; default = null; }
|
||||
|
||||
/**
|
||||
* Whether users on other servers can join this room. Defaults to
|
||||
* true if key does not exist.
|
||||
*/
|
||||
public bool federate { get; set; default = false; }
|
||||
|
||||
protected override void
|
||||
from_json(Json.Node json_data)
|
||||
throws Matrix.Error
|
||||
{
|
||||
var root = json_data.get_object();
|
||||
var content_root = root.get_member("content").get_object();
|
||||
Json.Node? node = null;
|
||||
|
||||
if (Config.DEBUG && ((node = root.get_member("state_key")) != null)) {
|
||||
if (node.get_string() != "") {
|
||||
warning("state_key of a m.room.create event is non-empty");
|
||||
}
|
||||
}
|
||||
|
||||
if ((node = content_root.get_member("creator")) != null) {
|
||||
_creator = node.get_string();
|
||||
} else {
|
||||
warning("content.creator is missing from a m.room.create event");
|
||||
}
|
||||
|
||||
if ((node = content_root.get_member("m.federate")) != null) {
|
||||
_federate = node.get_boolean();
|
||||
}
|
||||
|
||||
base.from_json(json_data);
|
||||
}
|
||||
|
||||
protected override void
|
||||
to_json(Json.Node json_data)
|
||||
throws Matrix.Error
|
||||
{
|
||||
if (_creator == null) {
|
||||
throw new Matrix.Error.INCOMPLETE(
|
||||
"Won't generate a m.room.create event without a creator key");
|
||||
}
|
||||
|
||||
if (state_key != "") {
|
||||
throw new Matrix.Error.INCOMPLETE(
|
||||
"Won't generater a m.root.create event with a non-empty state_key");
|
||||
}
|
||||
|
||||
var content_root = json_data.get_object()
|
||||
.get_member("content").get_object();
|
||||
|
||||
content_root.set_string_member("creator", _creator);
|
||||
content_root.set_boolean_member("m.federate", _federate);
|
||||
|
||||
base.to_json(json_data);
|
||||
}
|
||||
}
|
92
src/matrix-event-room-guest-access.vala
Normal file
92
src/matrix-event-room-guest-access.vala
Normal file
@@ -0,0 +1,92 @@
|
||||
/*
|
||||
* This file is part of matrix-glib-sdk
|
||||
*
|
||||
* matrix-glib-sdk is free software: you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation, either
|
||||
* version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* matrix-glib-sdk is distributed in the hope that it will be
|
||||
* useful, but WITHOUT ANY WARRANTY; without even the implied
|
||||
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
* See the GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with matrix-glib-sdk. If not, see
|
||||
* <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Class to hold a m.room.guest_access event
|
||||
*
|
||||
* This event controls whether guest users are allowed to join
|
||||
* rooms. If this event is absent, servers should act as if it is
|
||||
* present and has the guest_access value `forbidden`.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Class to hold a m.room.guest_access event
|
||||
*/
|
||||
public class Matrix.Event.RoomGuestAccess : Matrix.Event.State {
|
||||
/**
|
||||
* Whether guests can join the room.
|
||||
*/
|
||||
public GuestAccess guest_access { get; set; default = GuestAccess.UNKNOWN; }
|
||||
|
||||
protected override void
|
||||
from_json(Json.Node json_data)
|
||||
throws Matrix.Error
|
||||
{
|
||||
var root = json_data.get_object();
|
||||
var content_root = root.get_member("content").get_object();
|
||||
Json.Node? node = null;
|
||||
|
||||
if (Config.DEBUG && ((node = root.get_member("state_key")) != null)) {
|
||||
if (node.get_string() != "") {
|
||||
warning("state_key of a m.room.guest_access is non-empty");
|
||||
}
|
||||
}
|
||||
|
||||
if ((node = content_root.get_member("guest_access")) != null) {
|
||||
try {
|
||||
_guest_access = (GuestAccess)_g_enum_nick_to_value(
|
||||
typeof(GuestAccess), node.get_string());
|
||||
} catch (Matrix.Error e) {
|
||||
_guest_access = GuestAccess.UNKNOWN;
|
||||
|
||||
if (Config.DEBUG) {
|
||||
warning("Unknown value '%s' in a m.room.guest_access event",
|
||||
node.get_string());
|
||||
}
|
||||
}
|
||||
} else {
|
||||
warning("content.guest_access is missing from a m.room.guest_access event");
|
||||
}
|
||||
|
||||
base.from_json(json_data);
|
||||
}
|
||||
|
||||
protected override void
|
||||
to_json(Json.Node json_data)
|
||||
throws Matrix.Error
|
||||
{
|
||||
if (_state_key != "") {
|
||||
throw new Matrix.Error.INCOMPLETE(
|
||||
"Won't generate a m.room.guest_access event with a non-empty state key");
|
||||
}
|
||||
|
||||
if ((_guest_access == GuestAccess.UNKNOWN)) {
|
||||
throw new Matrix.Error.INCOMPLETE(
|
||||
"Won't generate a m.room.guest_access event with an unknown content.guest_access key");
|
||||
}
|
||||
|
||||
var content_root = json_data.get_object()
|
||||
.get_member("content").get_object();
|
||||
|
||||
content_root.set_string_member(
|
||||
"guest_access",
|
||||
_g_enum_value_to_nick(typeof(GuestAccess), _guest_access));
|
||||
|
||||
base.to_json(json_data);
|
||||
}
|
||||
}
|
89
src/matrix-event-room-history-visibility.vala
Normal file
89
src/matrix-event-room-history-visibility.vala
Normal file
@@ -0,0 +1,89 @@
|
||||
/*
|
||||
* This file is part of matrix-glib-sdk
|
||||
*
|
||||
* matrix-glib-sdk is free software: you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation, either
|
||||
* version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* matrix-glib-sdk is distributed in the hope that it will be
|
||||
* useful, but WITHOUT ANY WARRANTY; without even the implied
|
||||
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
* See the GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with matrix-glib-sdk. If not, see
|
||||
* <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Class to hold a m.room.history_visibility event.
|
||||
*
|
||||
* This event controls whether a user can see the events that happened
|
||||
* in a room from before they joined.
|
||||
*/
|
||||
public class Matrix.Event.RoomHistoryVisibility : Matrix.Event.State {
|
||||
/**
|
||||
* Who can see the room history.
|
||||
*/
|
||||
public Matrix.HistoryVisibility visibility {
|
||||
get; set;
|
||||
|
||||
default = Matrix.HistoryVisibility.UNKNOWN;
|
||||
}
|
||||
|
||||
protected override void
|
||||
from_json(Json.Node json_data)
|
||||
throws Matrix.Error
|
||||
{
|
||||
var root = json_data.get_object();
|
||||
var content_root = root.get_member("content").get_object();
|
||||
Json.Node? node = null;
|
||||
|
||||
if (Config.DEBUG && ((node = root.get_member("state_key")) != null)) {
|
||||
if (node.get_string() != "") {
|
||||
warning("state_key of a m.room.history_visibility event is non-empty");
|
||||
}
|
||||
}
|
||||
|
||||
if ((node = content_root.get_member("history_visibility")) != null) {
|
||||
try {
|
||||
_visibility = (Matrix.HistoryVisibility)_g_enum_nick_to_value(
|
||||
typeof(Matrix.HistoryVisibility), node.get_string());
|
||||
} catch (Matrix.Error e) {
|
||||
_visibility = Matrix.HistoryVisibility.UNKNOWN;
|
||||
|
||||
if (Config.DEBUG) {
|
||||
warning("Unknown history_visibility value %s", node.get_string());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
base.from_json(json_data);
|
||||
}
|
||||
|
||||
protected override void
|
||||
to_json(Json.Node json_data)
|
||||
throws Matrix.Error
|
||||
{
|
||||
var content_root = json_data.get_object()
|
||||
.get_member("content").get_object();
|
||||
|
||||
if (_state_key != "") {
|
||||
throw new Matrix.Error.INCOMPLETE(
|
||||
"Won't generate a m.room.history_visibility event with a non-empty state key");
|
||||
}
|
||||
|
||||
if (visibility == Matrix.HistoryVisibility.UNKNOWN) {
|
||||
throw new Matrix.Error.UNKNOWN_VALUE(
|
||||
"Won't send m.room.history_visibility event with unknown visibility value");
|
||||
}
|
||||
|
||||
content_root.set_string_member("history_visibility",
|
||||
_g_enum_value_to_nick(
|
||||
typeof(Matrix.HistoryVisibility),
|
||||
visibility));
|
||||
|
||||
base.to_json(json_data);
|
||||
}
|
||||
}
|
89
src/matrix-event-room-join-rules.vala
Normal file
89
src/matrix-event-room-join-rules.vala
Normal file
@@ -0,0 +1,89 @@
|
||||
/*
|
||||
* This file is part of matrix-glib-sdk
|
||||
*
|
||||
* matrix-glib-sdk is free software: you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation, either
|
||||
* version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* matrix-glib-sdk is distributed in the hope that it will be
|
||||
* useful, but WITHOUT ANY WARRANTY; without even the implied
|
||||
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
* See the GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with matrix-glib-sdk. If not, see
|
||||
* <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Class to hold a m.room.join_rules event.
|
||||
*
|
||||
* A room may be public meaning anyone can join the room without any
|
||||
* prior action. Alternatively, it can be invite meaning that a user
|
||||
* who wishes to join the room must first receive an invite to the
|
||||
* room from someone already inside of the room. Currently, knock and
|
||||
* private are reserved keywords which are not implemented.
|
||||
*/
|
||||
public class Matrix.Event.RoomJoinRules : Matrix.Event.State {
|
||||
public JoinRules join_rules { get; set; default = JoinRules.UNKNOWN; }
|
||||
|
||||
protected override void
|
||||
from_json(Json.Node json_data)
|
||||
throws Matrix.Error
|
||||
{
|
||||
var root = json_data.get_object();
|
||||
var content_root = root.get_member("content").get_object();
|
||||
Json.Node? node = null;
|
||||
|
||||
if (Config.DEBUG && ((node = root.get_member("state_key")) != null)) {
|
||||
if (node.get_string() != "") {
|
||||
warning("state_key of a m.room.join_rules is non-empty");
|
||||
}
|
||||
}
|
||||
|
||||
if ((node = content_root.get_member("join_rule")) != null) {
|
||||
try {
|
||||
_join_rules = (JoinRules)_g_enum_nick_to_value(
|
||||
typeof(JoinRules), node.get_string());
|
||||
} catch (Matrix.Error e) {
|
||||
_join_rules = Matrix.JoinRules.UNKNOWN;
|
||||
|
||||
if (Config.DEBUG) {
|
||||
warning("Unknown value %s in a m.room.join_rules event",
|
||||
node.get_string());
|
||||
}
|
||||
}
|
||||
} else {
|
||||
_join_rules = Matrix.JoinRules.UNKNOWN;
|
||||
|
||||
warning("content.join_rules is missing from a m.room.join_rules event.");
|
||||
}
|
||||
|
||||
base.from_json(json_data);
|
||||
}
|
||||
|
||||
protected override void
|
||||
to_json(Json.Node json_data)
|
||||
throws Matrix.Error
|
||||
{
|
||||
var content_root = json_data.get_object().
|
||||
get_member("content").get_object();
|
||||
|
||||
if (_state_key != "") {
|
||||
throw new Matrix.Error.INCOMPLETE(
|
||||
"Won't generate a m.room.join_rules event with a non-empty state_key");
|
||||
}
|
||||
|
||||
if (_join_rules == Matrix.JoinRules.UNKNOWN) {
|
||||
throw new Matrix.Error.INCOMPLETE(
|
||||
"Won't send a m.room.join_rules event with an unknown rule");
|
||||
}
|
||||
|
||||
content_root.set_string_member(
|
||||
"join_rule",
|
||||
_g_enum_value_to_nick(typeof(Matrix.JoinRules), _join_rules));
|
||||
|
||||
base.to_json(json_data);
|
||||
}
|
||||
}
|
315
src/matrix-event-room-member.vala
Normal file
315
src/matrix-event-room-member.vala
Normal file
@@ -0,0 +1,315 @@
|
||||
/*
|
||||
* This file is part of matrix-glib-sdk
|
||||
*
|
||||
* matrix-glib-sdk is free software: you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation, either
|
||||
* version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* matrix-glib-sdk is distributed in the hope that it will be
|
||||
* useful, but WITHOUT ANY WARRANTY; without even the implied
|
||||
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
* See the GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with matrix-glib-sdk. If not, see
|
||||
* <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Class for representing a room membership events
|
||||
*
|
||||
* Adjusts the membership state for a user in a room. It is preferable
|
||||
* to use the membership APIs (`/rooms/<room id>/invite` etc) when
|
||||
* performing membership actions rather than adjusting the state
|
||||
* directly as there are a restricted set of valid
|
||||
* transformations. For example, user A cannot force user B to join a
|
||||
* room, and trying to force this state change directly will
|
||||
* fail.
|
||||
*
|
||||
* The following membership states are specified:
|
||||
*
|
||||
* - invite - The user has been invited to join a room, but has not
|
||||
* yet joined it. They may not participate in the room until they
|
||||
* join.
|
||||
*
|
||||
* - join - The user has joined the room (possibly after accepting an
|
||||
* invite), and may participate in it.
|
||||
*
|
||||
* - leave - The user was once joined to the room, but has since left
|
||||
* (possibly by choice, or possibly by being kicked).
|
||||
*
|
||||
* - ban - The user has been banned from the room, and is no longer
|
||||
* allowed to join it until they are un-banned from the room (by
|
||||
* having their membership state set to a value other than ban).
|
||||
*
|
||||
* - knock - This is a reserved word, which currently has no meaning.
|
||||
*
|
||||
* The third_party_invite property will be set if this invite is an
|
||||
* invite event and is the successor of an m.room.third_party_invite
|
||||
* event, and absent otherwise.
|
||||
*
|
||||
* This event may also include an invite_room_state key outside the
|
||||
* content key. If present, this contains an array of stripped state
|
||||
* events. These events provide information on a few select state
|
||||
* events such as the room name.
|
||||
*/
|
||||
public class Matrix.Event.RoomMember : Matrix.Event.State {
|
||||
/**
|
||||
* The membership state of the user.
|
||||
*/
|
||||
public RoomMembership membership {
|
||||
get; set;
|
||||
|
||||
default = RoomMembership.UNKNOWN;
|
||||
}
|
||||
|
||||
/**
|
||||
* The avatar URL for this user, if any. This is added by the
|
||||
* homeserver.
|
||||
*/
|
||||
public string? avatar_url { get; set; default = null; }
|
||||
|
||||
/**
|
||||
* The display name for this user, if any. This is added by the
|
||||
* homeserver.
|
||||
*/
|
||||
public string? display_name { get; set; default = null; }
|
||||
|
||||
/**
|
||||
* A name which can be displayed to represent the user instead of
|
||||
* their third party identifier
|
||||
*/
|
||||
public string? tpi_display_name { get; set; default = null; }
|
||||
|
||||
/**
|
||||
* The invited matrix user ID. Must be equal to the user_id
|
||||
* property of the event.
|
||||
*/
|
||||
public string? tpi_signed_mxid { get; set; default = null; }
|
||||
|
||||
/**
|
||||
* The token property of the containing third_party_invite object.
|
||||
*/
|
||||
public string? tpi_signed_token { get; set; default = null; }
|
||||
|
||||
/**
|
||||
* A single signature from the verifying server, in the format
|
||||
* specified by the Signing Events section of the server-server
|
||||
* API.
|
||||
*/
|
||||
public Json.Node? tpi_signature { get; set; default = null; }
|
||||
|
||||
/**
|
||||
* A subset of the state of the room at the time of the invite, if
|
||||
* membership is invite.
|
||||
*/
|
||||
public Matrix.Event.State[] invite_room_state { get; set; }
|
||||
|
||||
/**
|
||||
* The user ID whom this event relates to.
|
||||
*/
|
||||
public string? user_id {
|
||||
get {
|
||||
return _state_key;
|
||||
}
|
||||
|
||||
set {
|
||||
_state_key = value;
|
||||
}
|
||||
|
||||
default = null;
|
||||
}
|
||||
|
||||
protected override void
|
||||
from_json(Json.Node json_data)
|
||||
throws Matrix.Error
|
||||
{
|
||||
Json.Object root = json_data.get_object();
|
||||
Json.Object content_root = root.get_member("content").get_object();
|
||||
Json.Node? node;
|
||||
|
||||
// Even though the state_key is handled by the parent class,
|
||||
// in this event type this actually means the sender
|
||||
if ((node = root.get_member("state_key")) != null) {
|
||||
_state_key = node.get_string();
|
||||
} else {
|
||||
warning("state_key is missing from a m.room.member event");
|
||||
}
|
||||
|
||||
if ((node = content_root.get_member("membership")) != null) {
|
||||
try {
|
||||
_membership = (Matrix.RoomMembership)_g_enum_nick_to_value(
|
||||
typeof(Matrix.RoomMembership), node.get_string());
|
||||
} catch (Matrix.Error e) {
|
||||
_membership = Matrix.RoomMembership.UNKNOWN;
|
||||
|
||||
if (Config.DEBUG) {
|
||||
warning("Unknown membership value %s", node.get_string());
|
||||
}
|
||||
}
|
||||
} else if (Config.DEBUG) {
|
||||
warning("membership key is missing from the m.room.member event");
|
||||
}
|
||||
|
||||
if ((node = content_root.get_member("avatar_url")) != null) {
|
||||
_avatar_url = node.get_string();
|
||||
}
|
||||
|
||||
if ((node = content_root.get_member("displayname")) != null) {
|
||||
_display_name = node.get_string();
|
||||
}
|
||||
|
||||
if ((node = content_root.get_member("third_party_invite")) != null) {
|
||||
var tpi_root = node.get_object();
|
||||
|
||||
if ((node = tpi_root.get_member("display_name")) != null) {
|
||||
_tpi_display_name = node.get_string();
|
||||
} else {
|
||||
warning("content.third_party_invite.display_name is missing from a m.room.member event");
|
||||
}
|
||||
|
||||
if ((node = tpi_root.get_member("signed")) != null) {
|
||||
var signed_root = node.get_object();
|
||||
|
||||
if ((node = signed_root.get_member("mxid")) != null) {
|
||||
tpi_signed_mxid = node.get_string();
|
||||
} else {
|
||||
warning("content.third_party_invit.signed.mxid is missing from a m.room.member event");
|
||||
}
|
||||
|
||||
if ((node = signed_root.get_member("token")) != null) {
|
||||
tpi_signed_token = node.get_string();
|
||||
} else {
|
||||
warning("content.third_party_invite.signed.token is missing from a m.room.member event");
|
||||
}
|
||||
|
||||
if ((node = signed_root.get_member("signatures")) != null) {
|
||||
tpi_signature = node;
|
||||
} else {
|
||||
warning("content.third_party_invite.signed.signatures is missing from a m.room.member event");
|
||||
}
|
||||
} else {
|
||||
warning("content.third_party_invite.signed is missing from a m.room.member event");
|
||||
}
|
||||
}
|
||||
|
||||
if ((node = root.get_member("invite_room_state")) != null) {
|
||||
var events = node.get_array();
|
||||
|
||||
if (events.get_length() > 0) {
|
||||
_invite_room_state = new Matrix.Event.State[node.get_array().get_length()];
|
||||
|
||||
events.foreach_element((ary, idx, member_node) => {
|
||||
try {
|
||||
var evt = Matrix.Event.Base.new_from_json(
|
||||
null, member_node);
|
||||
|
||||
_invite_room_state[idx] = (Matrix.Event.State)evt;
|
||||
} catch (GLib.Error e) {}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// Chain up
|
||||
base.from_json(json_data);
|
||||
}
|
||||
|
||||
protected override void
|
||||
to_json(Json.Node json_data)
|
||||
throws Matrix.Error
|
||||
{
|
||||
if (membership == RoomMembership.UNKNOWN) {
|
||||
throw new Matrix.Error.UNKNOWN_VALUE(
|
||||
"Unknown membership value cannot be added to a room member event");
|
||||
}
|
||||
|
||||
if (_state_key == "") {
|
||||
throw new Matrix.Error.INCOMPLETE(
|
||||
"Won't generate a m.room.member event with an empty state_key");
|
||||
}
|
||||
|
||||
var root = json_data.get_object();
|
||||
var content_root = root.get_member("content").get_object();
|
||||
string? mship;
|
||||
|
||||
mship = _g_enum_value_to_nick(typeof(Matrix.RoomMembership),
|
||||
membership);
|
||||
|
||||
if (mship != null) {
|
||||
content_root.set_string_member("membership", mship);
|
||||
} else {
|
||||
throw new Matrix.Error.UNKNOWN_VALUE(
|
||||
"Won't generate a m.room.member event with an unknown membership");
|
||||
}
|
||||
|
||||
if (avatar_url != null) {
|
||||
content_root.set_string_member("avatar_url", avatar_url);
|
||||
}
|
||||
|
||||
if (display_name != null) {
|
||||
content_root.set_string_member("displayname", display_name);
|
||||
}
|
||||
|
||||
var tpi_root = new Json.Object();
|
||||
|
||||
if (_tpi_display_name != null) {
|
||||
tpi_root.set_string_member("display_name", tpi_display_name);
|
||||
}
|
||||
|
||||
var tpi_signed_root = new Json.Object();
|
||||
|
||||
if (_tpi_signed_mxid != null) {
|
||||
tpi_signed_root.set_string_member("mxid", tpi_signed_mxid);
|
||||
}
|
||||
|
||||
if (_tpi_signed_token != null) {
|
||||
tpi_signed_root.set_string_member("token", tpi_signed_token);
|
||||
}
|
||||
|
||||
if (_tpi_signature != null) {
|
||||
tpi_signed_root.set_member("signature", tpi_signature);
|
||||
}
|
||||
|
||||
if ((tpi_signed_root.get_size() != 3)
|
||||
&& (tpi_signed_root.get_size() != 0)) {
|
||||
warning("3rd party invite data is not filled; ignoring");
|
||||
|
||||
tpi_signed_root = null;
|
||||
}
|
||||
|
||||
if ((_tpi_display_name != null) && (tpi_signed_root.get_size() == 3)) {
|
||||
var tpi_signed_node = new Json.Node(Json.NodeType.OBJECT);
|
||||
tpi_signed_node.set_object(tpi_signed_root);
|
||||
tpi_root.set_member("signed", tpi_signed_node);
|
||||
}
|
||||
|
||||
if (tpi_root.get_size() == 2) {
|
||||
var tpi_node = new Json.Node(Json.NodeType.OBJECT);
|
||||
tpi_node.set_object(tpi_root);
|
||||
content_root.set_member("third_party_invite", tpi_node);
|
||||
} else if (tpi_root.get_size() != 0) {
|
||||
warning("3rd party invite data is incomplete; ignoring");
|
||||
}
|
||||
|
||||
if (_invite_room_state != null) {
|
||||
var state_ary = new Json.Array();
|
||||
|
||||
foreach (var entry in _invite_room_state) {
|
||||
var state_node = entry.get_stripped_node();
|
||||
|
||||
if (state_node != null) {
|
||||
state_ary.add_element(state_node);
|
||||
}
|
||||
}
|
||||
|
||||
if (state_ary.get_length() > 0) {
|
||||
var state_node = new Json.Node(Json.NodeType.ARRAY);
|
||||
state_node.set_array(state_ary);
|
||||
root.set_member("invite_room_state", state_node);
|
||||
}
|
||||
}
|
||||
|
||||
base.to_json(json_data);
|
||||
}
|
||||
}
|
84
src/matrix-event-room-message-feedback.vala
Normal file
84
src/matrix-event-room-message-feedback.vala
Normal file
@@ -0,0 +1,84 @@
|
||||
/*
|
||||
* This file is part of matrix-glib-sdk
|
||||
*
|
||||
* matrix-glib-sdk is free software: you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation, either
|
||||
* version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* matrix-glib-sdk is distributed in the hope that it will be
|
||||
* useful, but WITHOUT ANY WARRANTY; without even the implied
|
||||
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
* See the GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with matrix-glib-sdk. If not, see
|
||||
* <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Class to hold a m.room.message.feedback event.
|
||||
*
|
||||
* Usage of this event is discouraged in favour of the receipts
|
||||
* module. Most clients will not recognise this event.
|
||||
*
|
||||
* Feedback events are events sent to acknowledge a message in some
|
||||
* way. There are two supported acknowledgements: `delivered` (sent
|
||||
* when the event has been received) and `read` (sent when the event
|
||||
* has been observed by the end-user). The `target_event_id` should
|
||||
* reference the `m.room.message` event being acknowledged.
|
||||
*/
|
||||
public class Matrix.Event.RoomMessageFeedback : Matrix.Event.Room {
|
||||
/**
|
||||
* The type of the feedback. As the use of this event type is
|
||||
* discouraged, Matrix GLib SDK doesn’t implement this as an
|
||||
* actual enum.
|
||||
*/
|
||||
public string? feedback_type { get; set; default = null; }
|
||||
|
||||
/**
|
||||
* The event that this feedback is related to.
|
||||
*/
|
||||
public string? target_event_id { get; set; default = null; }
|
||||
|
||||
protected override void
|
||||
from_json(Json.Node json_data)
|
||||
throws Matrix.Error
|
||||
{
|
||||
var content_root = json_data.get_object()
|
||||
.get_member("content").get_object();
|
||||
Json.Node? node;
|
||||
|
||||
if ((node = content_root.get_member("type")) != null) {
|
||||
_feedback_type = node.get_string();
|
||||
} else {
|
||||
warning("content.type is missing from a m.room.message.feedback event");
|
||||
}
|
||||
|
||||
if ((node = content_root.get_member("target_event_id")) != null) {
|
||||
_target_event_id = node.get_string();
|
||||
} else {
|
||||
warning("content.target_event_id is missing from a m.room.message.feedback event");
|
||||
}
|
||||
|
||||
base.from_json(json_data);
|
||||
}
|
||||
|
||||
protected override void
|
||||
to_json(Json.Node json_data)
|
||||
throws Matrix.Error
|
||||
{
|
||||
if ((_feedback_type == null) || (_target_event_id == null)) {
|
||||
throw new Matrix.Error.INCOMPLETE(
|
||||
"Won't generate a m.room.message.feedback without all fields set");
|
||||
}
|
||||
|
||||
var content_root = json_data.get_object()
|
||||
.get_member("content").get_object();
|
||||
|
||||
content_root.set_string_member("type", _feedback_type);
|
||||
content_root.set_string_member("target_event_id", _target_event_id);
|
||||
|
||||
base.to_json(json_data);
|
||||
}
|
||||
}
|
90
src/matrix-event-room-message.vala
Normal file
90
src/matrix-event-room-message.vala
Normal file
@@ -0,0 +1,90 @@
|
||||
/*
|
||||
* This file is part of matrix-glib-sdk
|
||||
*
|
||||
* matrix-glib-sdk is free software: you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation, either
|
||||
* version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* matrix-glib-sdk is distributed in the hope that it will be
|
||||
* useful, but WITHOUT ANY WARRANTY; without even the implied
|
||||
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
* See the GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with matrix-glib-sdk. If not, see
|
||||
* <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Class to hold an m.room.message event
|
||||
*
|
||||
* This event is used when sending messages in a room. Messages are
|
||||
* not limited to be text. The `msgtype` key outlines the type of
|
||||
* message, e.g. text, audio, image, video, etc. The `body` key is
|
||||
* text and MUST be used with every kind of `msgtype` as a fallback
|
||||
* mechanism for when a client cannot render a message. This allows
|
||||
* clients to display *something* even if it is just plain text.
|
||||
*/
|
||||
public class Matrix.Event.RoomMessage : Matrix.Event.Room {
|
||||
/**
|
||||
* The message as a Matrix.Message object.
|
||||
*/
|
||||
public Matrix.Message.Base? message { get; set; default = null; }
|
||||
|
||||
/**
|
||||
* The message as a JSON object. This gets set by
|
||||
* Matrix.Message.Base.new_from_json if no handler is installed
|
||||
* for the given message type.
|
||||
*/
|
||||
public Json.Node? fallback_content {
|
||||
get {
|
||||
return _fallback_content;
|
||||
}
|
||||
}
|
||||
|
||||
private Json.Node? _fallback_content;
|
||||
|
||||
protected override void
|
||||
from_json(Json.Node json_data)
|
||||
throws Matrix.Error
|
||||
{
|
||||
var content_node = json_data.get_object().get_member("content");
|
||||
|
||||
try {
|
||||
_message = Matrix.Message.Base.new_from_json(content_node);
|
||||
|
||||
// We don't want to fail on unknown message types, so
|
||||
// let's save the JSON content instead. Silent
|
||||
// (ie. without exception) null is only returned if there
|
||||
// is no handler class installed
|
||||
if (_message == null) {
|
||||
_fallback_content = content_node;
|
||||
} else {
|
||||
_fallback_content = null;
|
||||
}
|
||||
} catch (GLib.Error e) {
|
||||
throw new Matrix.Error.INVALID_TYPE(
|
||||
"Error during message initialization:%s",
|
||||
e.message);
|
||||
}
|
||||
|
||||
base.from_json(json_data);
|
||||
}
|
||||
|
||||
protected override void
|
||||
to_json(Json.Node json_data)
|
||||
throws Matrix.Error
|
||||
{
|
||||
if (_message == null) {
|
||||
throw new Matrix.Error.INCOMPLETE(
|
||||
"Won't generate a m.room.message event without content");
|
||||
}
|
||||
|
||||
var root = json_data.get_object();
|
||||
|
||||
root.set_member("content", _message.json);
|
||||
|
||||
base.to_json(json_data);
|
||||
}
|
||||
}
|
76
src/matrix-event-room-name.vala
Normal file
76
src/matrix-event-room-name.vala
Normal file
@@ -0,0 +1,76 @@
|
||||
/*
|
||||
* This file is part of matrix-glib-sdk
|
||||
*
|
||||
* matrix-glib-sdk is free software: you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation, either
|
||||
* version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* matrix-glib-sdk is distributed in the hope that it will be
|
||||
* useful, but WITHOUT ANY WARRANTY; without even the implied
|
||||
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
* See the GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with matrix-glib-sdk. If not, see
|
||||
* <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Class to hold a m.room.name event.
|
||||
*
|
||||
* A room has an opaque room ID which is not human-friendly to read. A
|
||||
* room alias is human-friendly, but not all rooms have room
|
||||
* aliases. The room name is a human-friendly string designed to be
|
||||
* displayed to the end-user. The room name is not unique, as multiple
|
||||
* rooms can have the same room name set. The room name can also be
|
||||
* set when creating a room using createRoom with the name key.
|
||||
*/
|
||||
public class Matrix.Event.RoomName : Matrix.Event.State {
|
||||
public string? name { get; set; default = null; }
|
||||
|
||||
protected override void
|
||||
from_json(Json.Node json_data)
|
||||
throws Matrix.Error
|
||||
{
|
||||
var root = json_data.get_object();
|
||||
var content_root = root.get_member("content").get_object();
|
||||
Json.Node? node = null;
|
||||
|
||||
if (Config.DEBUG && ((node = root.get_member("state_key")) != null)) {
|
||||
if (node.get_string() != "") {
|
||||
warning("state_key of a m.room.name event is non-empty");
|
||||
}
|
||||
}
|
||||
|
||||
if ((node = content_root.get_member("name")) != null) {
|
||||
_name = node.get_string();
|
||||
} else {
|
||||
warning("content.name is missing from a m.room.name event");
|
||||
}
|
||||
|
||||
base.from_json(json_data);
|
||||
}
|
||||
|
||||
protected override void
|
||||
to_json(Json.Node json_data)
|
||||
throws Matrix.Error
|
||||
{
|
||||
var content_root = json_data.get_object()
|
||||
.get_member("content").get_object();
|
||||
|
||||
if (_state_key != "") {
|
||||
throw new Matrix.Error.INCOMPLETE(
|
||||
"Won't send a m.room.name with a non-empty state key");
|
||||
}
|
||||
|
||||
if (_name == null) {
|
||||
throw new Matrix.Error.INCOMPLETE(
|
||||
"Won't send a m.room.name event without a name");
|
||||
}
|
||||
|
||||
content_root.set_string_member("name", _name);
|
||||
|
||||
base.to_json(json_data);
|
||||
}
|
||||
}
|
232
src/matrix-event-room-power-levels.vala
Normal file
232
src/matrix-event-room-power-levels.vala
Normal file
@@ -0,0 +1,232 @@
|
||||
/*
|
||||
* This file is part of matrix-glib-sdk
|
||||
*
|
||||
* matrix-glib-sdk is free software: you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation, either
|
||||
* version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* matrix-glib-sdk is distributed in the hope that it will be
|
||||
* useful, but WITHOUT ANY WARRANTY; without even the implied
|
||||
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
* See the GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with matrix-glib-sdk. If not, see
|
||||
* <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Class to handle m.room.power_levels event
|
||||
*
|
||||
* This event specifies the minimum level a user must have in order to
|
||||
* perform a certain action. It also specifies the levels of each user
|
||||
* in the room. If a user_id is in the users list, then that user_id
|
||||
* has the associated power level. Otherwise they have the default
|
||||
* level users_default. If users_default is not supplied, it is
|
||||
* assumed to be 0. The level required to send a certain event is
|
||||
* governed by events, state_default and events_default. If an event
|
||||
* type is specified in events, then the user must have at least the
|
||||
* level specified in order to send that event. If the event type is
|
||||
* not supplied, it defaults to events_default for Message Events and
|
||||
* state_default for State Events.
|
||||
*/
|
||||
public class Matrix.Event.RoomPowerLevels : Matrix.Event.State {
|
||||
/**
|
||||
* The default power level for every user in the room, unless
|
||||
* their user_id is mentioned in the users key.
|
||||
*/
|
||||
public int users_default { get; set; default = 0; }
|
||||
|
||||
/**
|
||||
* The default level required to send message events. Can be
|
||||
* overridden by the events key.
|
||||
*/
|
||||
public int events_default { get; set; default = 0; }
|
||||
|
||||
/**
|
||||
* The default level required to send state events. Can be
|
||||
* overridden by the events key.
|
||||
*/
|
||||
public int state_default { get; set; default = 10; }
|
||||
|
||||
/**
|
||||
* The level required to ban a user.
|
||||
*/
|
||||
public int ban { get; set; default = 5; }
|
||||
|
||||
/**
|
||||
* The level required to kick a user.
|
||||
*/
|
||||
public int kick { get; set; default = 5; }
|
||||
|
||||
/**
|
||||
* The level required to redact an event.
|
||||
*/
|
||||
public int redact { get; set; default = 20; }
|
||||
|
||||
/**
|
||||
* The level required to invite someone.
|
||||
*/
|
||||
public int invite { get; set; default = 0; }
|
||||
|
||||
/**
|
||||
* A hash map to store the required level to send specific events.
|
||||
*/
|
||||
public HashTable<string, int?> event_levels {
|
||||
get {
|
||||
return _event_levels;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* A hash map to store current level for individual users.
|
||||
*/
|
||||
public HashTable<string, int?> user_levels {
|
||||
get {
|
||||
return _user_levels;
|
||||
}
|
||||
}
|
||||
|
||||
private HashTable<string, int?> _event_levels =
|
||||
new HashTable<string, int?>(str_hash, str_equal);
|
||||
|
||||
private HashTable<string, int?> _user_levels =
|
||||
new HashTable<string, int?>(str_hash, str_equal);
|
||||
|
||||
protected override void
|
||||
from_json(Json.Node json_data)
|
||||
throws Matrix.Error
|
||||
{
|
||||
var root = json_data.get_object();
|
||||
var content_root = root.get_member("content").get_object();
|
||||
Json.Node? node = null;
|
||||
|
||||
if (Config.DEBUG && ((node = root.get_member("content")) != null)) {
|
||||
if (node.get_string() != "") {
|
||||
warning("state_key of a m.room.power_levels event is non-empty");
|
||||
}
|
||||
}
|
||||
|
||||
if ((node = content_root.get_member("ban")) != null) {
|
||||
_ban = (int)node.get_int();
|
||||
} else {
|
||||
warning("content.ban is missing from a m.room.power_levels event");
|
||||
}
|
||||
|
||||
if ((node = content_root.get_member("kick")) != null) {
|
||||
_kick = (int)node.get_int();
|
||||
} else {
|
||||
warning("content.kick is missing from a m.room.power_levels event");
|
||||
}
|
||||
|
||||
if ((node = content_root.get_member("redact")) != null) {
|
||||
_redact = (int)node.get_int();
|
||||
} else {
|
||||
warning("content.redact is missing from a m.room.power_levels event");
|
||||
}
|
||||
|
||||
if ((node = content_root.get_member("events_default")) != null) {
|
||||
_events_default = (int)node.get_int();
|
||||
} else {
|
||||
warning("content.events_default is missing from a m.room.power_levels event");
|
||||
}
|
||||
|
||||
if ((node = content_root.get_member("state_default")) != null) {
|
||||
_state_default = (int)node.get_int();
|
||||
} else {
|
||||
warning("content.state_default is missing from a m.room.power_levels event");
|
||||
}
|
||||
|
||||
if ((node = content_root.get_member("users_default")) != null) {
|
||||
_users_default = (int)node.get_int();
|
||||
}
|
||||
|
||||
if ((node = content_root.get_member("invite")) != null) {
|
||||
_invite = (int)node.get_int();
|
||||
}
|
||||
|
||||
if ((node = content_root.get_member("events")) != null) {
|
||||
_event_levels.remove_all();
|
||||
|
||||
node.get_object().foreach_member((obj, event_name, event_node) => {
|
||||
_event_levels[event_name] = (int)event_node.get_int();
|
||||
});
|
||||
}
|
||||
|
||||
if ((node = content_root.get_member("users")) != null) {
|
||||
_user_levels.remove_all();
|
||||
|
||||
node.get_object().foreach_member((obj, user_id, user_node) => {
|
||||
_user_levels[user_id] = (int)user_node.get_int();
|
||||
});
|
||||
}
|
||||
|
||||
base.from_json(json_data);
|
||||
}
|
||||
|
||||
protected override void
|
||||
to_json(Json.Node json_data)
|
||||
throws Matrix.Error
|
||||
{
|
||||
var content_root = json_data.get_object()
|
||||
.get_member("content").get_object();
|
||||
|
||||
if (_state_key != "") {
|
||||
throw new Matrix.Error.INCOMPLETE(
|
||||
"Won't generate a m.room.power_levels event with a non-empty state_key");
|
||||
}
|
||||
|
||||
if (_user_levels == null) {
|
||||
throw new Matrix.Error.INCOMPLETE(
|
||||
"Won't create an m.room.power_levels event without a content.users key");
|
||||
}
|
||||
|
||||
if (_event_levels == null) {
|
||||
throw new Matrix.Error.INCOMPLETE(
|
||||
"Won't create an m.room.power_levels event without a content.events key");
|
||||
}
|
||||
|
||||
content_root.set_int_member("ban", _ban);
|
||||
content_root.set_int_member("kick", _kick);
|
||||
content_root.set_int_member("redact", _redact);
|
||||
content_root.set_int_member("state_default", _state_default);
|
||||
content_root.set_int_member("events_default", _events_default);
|
||||
|
||||
var user_obj = new Json.Object();
|
||||
var user_node = new Json.Node(Json.NodeType.OBJECT);
|
||||
user_node.set_object(user_obj);
|
||||
|
||||
_user_levels.foreach(
|
||||
(key, value) => {
|
||||
user_obj.set_int_member(key, value);
|
||||
});
|
||||
|
||||
content_root.set_member("users", user_node);
|
||||
|
||||
var events_obj = new Json.Object();
|
||||
var events_node = new Json.Node(Json.NodeType.OBJECT);
|
||||
events_node.set_object(events_obj);
|
||||
|
||||
_event_levels.foreach(
|
||||
(key, value) => {
|
||||
events_obj.set_int_member(key, value);
|
||||
});
|
||||
|
||||
content_root.set_member("users", events_node);
|
||||
|
||||
base.to_json(json_data);
|
||||
}
|
||||
|
||||
public void
|
||||
set_user_level(string user_id, int level)
|
||||
{
|
||||
_user_levels[user_id] = level;
|
||||
}
|
||||
|
||||
public void
|
||||
set_event_level(string event_type, int level)
|
||||
{
|
||||
_event_levels[event_type] = level;
|
||||
}
|
||||
}
|
85
src/matrix-event-room-redaction.vala
Normal file
85
src/matrix-event-room-redaction.vala
Normal file
@@ -0,0 +1,85 @@
|
||||
/*
|
||||
* This file is part of matrix-glib-sdk
|
||||
*
|
||||
* matrix-glib-sdk is free software: you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation, either
|
||||
* version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* matrix-glib-sdk is distributed in the hope that it will be
|
||||
* useful, but WITHOUT ANY WARRANTY; without even the implied
|
||||
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
* See the GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with matrix-glib-sdk. If not, see
|
||||
* <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Class to hold a m.room.redaction event
|
||||
*
|
||||
* Events can be redacted by either room or server admins. Redacting
|
||||
* an event means that all keys not required by the protocol are
|
||||
* stripped off, allowing admins to remove offensive or illegal
|
||||
* content that may have been attached to any event. This cannot be
|
||||
* undone, allowing server owners to physically delete the offending
|
||||
* data. There is also a concept of a moderator hiding a message
|
||||
* event, which can be undone, but cannot be applied to state
|
||||
* events. The event that has been redacted is specified in the
|
||||
* redacts event level key.
|
||||
*/
|
||||
public class Matrix.Event.RoomRedaction : Matrix.Event.Room {
|
||||
/**
|
||||
* The reason for the redaction, if any.
|
||||
*/
|
||||
public string? reason { get; set; default = null; }
|
||||
|
||||
/**
|
||||
* The event ID that was redacted.
|
||||
*/
|
||||
public string? redacted_event_id { get; set; default = null; }
|
||||
|
||||
protected override void
|
||||
from_json(Json.Node json_data)
|
||||
throws Matrix.Error
|
||||
{
|
||||
var root = json_data.get_object();
|
||||
var content_root = root.get_member("content").get_object();
|
||||
Json.Node? node;
|
||||
|
||||
if ((node = content_root.get_member("reason")) != null) {
|
||||
_reason = node.get_string();
|
||||
}
|
||||
|
||||
if ((node = root.get_member("redacts")) != null) {
|
||||
_redacted_event_id = node.get_string();
|
||||
} else {
|
||||
warning("redacts is missing from a m.room.redaction event");
|
||||
}
|
||||
|
||||
base.from_json(json_data);
|
||||
}
|
||||
|
||||
protected override void
|
||||
to_json(Json.Node json_data)
|
||||
throws Matrix.Error
|
||||
{
|
||||
if (_redacted_event_id == null) {
|
||||
throw new Matrix.Error.INCOMPLETE(
|
||||
"Won't generate a m.room.redaction event without the redacts field");
|
||||
}
|
||||
|
||||
var root = json_data.get_object();
|
||||
|
||||
root.set_string_member("redacts", _redacted_event_id);
|
||||
|
||||
if (_reason != null) {
|
||||
var content_root = root.get_member("content").get_object();
|
||||
|
||||
content_root.set_string_member("reason", _reason);
|
||||
}
|
||||
|
||||
base.to_json(json_data);
|
||||
}
|
||||
}
|
177
src/matrix-event-room-third-party-invite.vala
Normal file
177
src/matrix-event-room-third-party-invite.vala
Normal file
@@ -0,0 +1,177 @@
|
||||
/*
|
||||
* This file is part of matrix-glib-sdk
|
||||
*
|
||||
* matrix-glib-sdk is free software: you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation, either
|
||||
* version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* matrix-glib-sdk is distributed in the hope that it will be
|
||||
* useful, but WITHOUT ANY WARRANTY; without even the implied
|
||||
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
* See the GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with matrix-glib-sdk. If not, see
|
||||
* <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Class to hold a m.room.third_party_invite event
|
||||
*
|
||||
* Acts as an m.room.member invite event, where there isn't a target
|
||||
* user_id to invite. This event contains a token and a public key
|
||||
* whose private key must be used to sign the token. Any user who can
|
||||
* present that signature may use this invitation to join the target
|
||||
* room.
|
||||
*/
|
||||
public class Matrix.Event.RoomThirdPartyInvite : Matrix.Event.State {
|
||||
public struct PublicKey {
|
||||
string? key;
|
||||
string? validity_url;
|
||||
}
|
||||
|
||||
/**
|
||||
* A user-readable string which represents the user who has been
|
||||
* invited. This should not contain the user's third party ID, as
|
||||
* otherwise when the invite is accepted it would leak the
|
||||
* association between the matrix ID and the third party ID.
|
||||
*/
|
||||
public string? display_name { get; set; default = null; }
|
||||
|
||||
/**
|
||||
* A URL which can be fetched, with querystring
|
||||
* public_key=public_key, to validate whether the key has been
|
||||
* revoked. The URL must return a JSON object containing a boolean
|
||||
* property named valid.
|
||||
*/
|
||||
public string? key_validity_url { get; set; default = null; }
|
||||
|
||||
/**
|
||||
* A base64-encoded ed25519 key with which token must be signed
|
||||
* (though a signature from any entry in public_keys is also
|
||||
* sufficient). This exists for backwards compatibility.
|
||||
*/
|
||||
public string? public_key { get; set; default = null;}
|
||||
|
||||
/**
|
||||
* Keys with which the token may be signed.
|
||||
*/
|
||||
public PublicKey[] public_keys { get; set; }
|
||||
|
||||
/**
|
||||
* The token, of which a signature must be produced in order to
|
||||
* join the room.
|
||||
*/
|
||||
public string? token {
|
||||
get {
|
||||
return _state_key;
|
||||
}
|
||||
set {
|
||||
_state_key = value;
|
||||
}
|
||||
|
||||
default = null;
|
||||
}
|
||||
|
||||
protected override void
|
||||
from_json(Json.Node json_data)
|
||||
throws Matrix.Error
|
||||
{
|
||||
var root = json_data.get_object();
|
||||
var content_root = root.get_member("content").get_object();
|
||||
Json.Node? node;
|
||||
|
||||
if ((node = root.get_member("state_key")) != null) {
|
||||
_state_key = node.get_string();
|
||||
} else if (Config.DEBUG) {
|
||||
warning("state_key is missing from a m.room.third_party_invite_event");
|
||||
}
|
||||
|
||||
if ((node = content_root.get_member("display_name")) != null) {
|
||||
_display_name = node.get_string();
|
||||
} else {
|
||||
warning("content.display_name is missing from a m.room.third_party_invite event");
|
||||
}
|
||||
|
||||
if ((node = content_root.get_member("public_key")) != null) {
|
||||
_public_key = node.get_string();
|
||||
} else {
|
||||
warning("content.public_key is missing from a m.room.third_party_invite event");
|
||||
}
|
||||
|
||||
if ((node = content_root.get_member("key_validity_url")) != null) {
|
||||
_key_validity_url = node.get_string();
|
||||
} else {
|
||||
warning("content.key_validity_url is missing from a m.room.third_party_invite event");
|
||||
}
|
||||
|
||||
if ((node = content_root.get_member("public_keys")) != null) {
|
||||
}
|
||||
|
||||
base.from_json(json_data);
|
||||
}
|
||||
|
||||
protected override void
|
||||
to_json(Json.Node json_data)
|
||||
throws Matrix.Error
|
||||
{
|
||||
if (_display_name == null) {
|
||||
throw new Matrix.Error.INCOMPLETE(
|
||||
"Won't generate a m.room.third_party_invite event without display_name");
|
||||
}
|
||||
|
||||
if (_public_key == null) {
|
||||
throw new Matrix.Error.INCOMPLETE(
|
||||
"Won't generate a m.room.third_party_invite without public_key");
|
||||
}
|
||||
|
||||
if (_key_validity_url == null) {
|
||||
throw new Matrix.Error.INCOMPLETE(
|
||||
"Won't generate a m.room.third_party_invite without key_validity_url");
|
||||
}
|
||||
|
||||
if (_state_key == null) {
|
||||
throw new Matrix.Error.INCOMPLETE(
|
||||
"Won't generate a m.room.third_party_invite without token");
|
||||
}
|
||||
|
||||
var content_root = json_data.get_object()
|
||||
.get_member("content").get_object();
|
||||
|
||||
// We don't need to set the state key here, our base class
|
||||
// will do it for us
|
||||
|
||||
content_root.set_string_member("display_name", _display_name);
|
||||
content_root.set_string_member("public_key", _public_key);
|
||||
content_root.set_string_member("key_validity_url", _key_validity_url);
|
||||
|
||||
var key_list = new Json.Array();
|
||||
|
||||
foreach (var entry in _public_keys) {
|
||||
if (entry.key == null) {
|
||||
throw new Matrix.Error.INCOMPLETE(
|
||||
"Won't generate a m.room.third_party_invite with a missing key under public_keys");
|
||||
}
|
||||
|
||||
var key_obj = new Json.Object();
|
||||
var key_node = new Json.Node(Json.NodeType.OBJECT);
|
||||
key_node.set_object(key_obj);
|
||||
key_obj.set_string_member("public_key", entry.key);
|
||||
|
||||
if (entry.validity_url != null) {
|
||||
key_obj.set_string_member("key_validity_url", entry.validity_url);
|
||||
}
|
||||
|
||||
key_list.add_element(key_node);
|
||||
}
|
||||
|
||||
if (key_list.get_length() > 0) {
|
||||
var keys_node = new Json.Node(Json.NodeType.ARRAY);
|
||||
keys_node.set_array(key_list);
|
||||
content_root.set_member("public_keys", keys_node);
|
||||
}
|
||||
|
||||
base.to_json(json_data);
|
||||
}
|
||||
}
|
74
src/matrix-event-room-topic.vala
Normal file
74
src/matrix-event-room-topic.vala
Normal file
@@ -0,0 +1,74 @@
|
||||
/*
|
||||
* This file is part of matrix-glib-sdk
|
||||
*
|
||||
* matrix-glib-sdk is free software: you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation, either
|
||||
* version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* matrix-glib-sdk is distributed in the hope that it will be
|
||||
* useful, but WITHOUT ANY WARRANTY; without even the implied
|
||||
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
* See the GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with matrix-glib-sdk. If not, see
|
||||
* <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Event type to hold the m.room.topic event.
|
||||
*
|
||||
* A topic is a short message detailing what is currently being
|
||||
* discussed in the room. It can also be used as a way to display
|
||||
* extra information about the room, which may not be suitable for the
|
||||
* room name.
|
||||
*/
|
||||
public class Matrix.Event.RoomTopic : Matrix.Event.State {
|
||||
/**
|
||||
* The topic text.
|
||||
*/
|
||||
public string? topic { get; set; default = null; }
|
||||
|
||||
protected override void
|
||||
from_json(Json.Node json_data)
|
||||
throws Matrix.Error
|
||||
{
|
||||
var root = json_data.get_object();
|
||||
var content_root = root.get_member("content").get_object();
|
||||
Json.Node? node = null;
|
||||
|
||||
if (Config.DEBUG && ((node = root.get_member("state_key")) != null)) {
|
||||
if (node.get_string() != "") {
|
||||
warning("state_key of a m.room.topic event is non-empty");
|
||||
}
|
||||
}
|
||||
|
||||
if ((node = content_root.get_member("topic")) != null) {
|
||||
_topic = node.get_string();
|
||||
} else if (Config.DEBUG) {
|
||||
warning("content.topic is missing from an m.room.topic event");
|
||||
}
|
||||
|
||||
base.from_json(json_data);
|
||||
}
|
||||
|
||||
protected override void
|
||||
to_json(Json.Node json_data)
|
||||
throws Matrix.Error
|
||||
{
|
||||
var root = json_data.get_object();
|
||||
var content_root = root.get_member("content").get_object();
|
||||
|
||||
if (_state_key != "") {
|
||||
throw new Matrix.Error.INCOMPLETE(
|
||||
"Won't generate a m.room.topic event with a non-empty state_key");
|
||||
}
|
||||
|
||||
if (_topic != null) {
|
||||
content_root.set_string_member("topic", _topic);
|
||||
}
|
||||
|
||||
base.to_json(json_data);
|
||||
}
|
||||
}
|
95
src/matrix-event-state-base.vala
Normal file
95
src/matrix-event-state-base.vala
Normal file
@@ -0,0 +1,95 @@
|
||||
/*
|
||||
* This file is part of matrix-glib-sdk
|
||||
*
|
||||
* matrix-glib-sdk is free software: you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation, either
|
||||
* version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* matrix-glib-sdk is distributed in the hope that it will be
|
||||
* useful, but WITHOUT ANY WARRANTY; without even the implied
|
||||
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
* See the GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with matrix-glib-sdk. If not, see
|
||||
* <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
public abstract class Matrix.Event.State : Matrix.Event.Room {
|
||||
protected string? _state_key;
|
||||
|
||||
public string? state_key {
|
||||
get {
|
||||
return _state_key;
|
||||
}
|
||||
|
||||
set {
|
||||
_state_key = value;
|
||||
}
|
||||
|
||||
default = null;
|
||||
}
|
||||
public Json.Node? prev_content { get; set; default = null; }
|
||||
|
||||
protected override void
|
||||
from_json(Json.Node json_data)
|
||||
throws Matrix.Error
|
||||
{
|
||||
var root = json_data.get_object();
|
||||
Json.Node? node;
|
||||
|
||||
if ((node = root.get_member("state_key")) != null) {
|
||||
_state_key = node.get_string();
|
||||
} else if (Config.DEBUG) {
|
||||
warning("state_key is not present in a State event");
|
||||
}
|
||||
|
||||
if ((node = root.get_member("prev_content")) != null) {
|
||||
_prev_content = node;
|
||||
}
|
||||
|
||||
base.from_json(json_data);
|
||||
}
|
||||
|
||||
protected override void
|
||||
to_json(Json.Node json_node)
|
||||
throws Matrix.Error
|
||||
{
|
||||
if (_state_key == null) {
|
||||
throw new Matrix.Error.INCOMPLETE(
|
||||
"Won't generate state events without state_key");
|
||||
}
|
||||
|
||||
var root = json_node.get_object();
|
||||
|
||||
root.set_string_member("state_key", state_key);
|
||||
|
||||
if (_prev_content != null) {
|
||||
root.set_member("prev_content", prev_content);
|
||||
}
|
||||
|
||||
base.to_json(json_node);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a stripped state event.
|
||||
*
|
||||
* @return `null` if the event is not allowed to be stripped, or
|
||||
* the full JSON node otherwise
|
||||
*/
|
||||
public Json.Node?
|
||||
get_stripped_node()
|
||||
{
|
||||
if ((_event_type != "m.room.join_rules")
|
||||
&& (_event_type != "m.room.canonical_alias")
|
||||
&& (_event_type != "m.room.avatar")
|
||||
&& (_event_type != "m.room.name")) {
|
||||
warning("Trying to strip down event that is not allowed to be stripped.");
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
return json;
|
||||
}
|
||||
}
|
69
src/matrix-event-tag.vala
Normal file
69
src/matrix-event-tag.vala
Normal file
@@ -0,0 +1,69 @@
|
||||
/*
|
||||
* This file is part of matrix-glib-sdk
|
||||
*
|
||||
* matrix-glib-sdk is free software: you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation, either
|
||||
* version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* matrix-glib-sdk is distributed in the hope that it will be
|
||||
* useful, but WITHOUT ANY WARRANTY; without even the implied
|
||||
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
* See the GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with matrix-glib-sdk. If not, see
|
||||
* <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
public class Matrix.Event.Tag : Matrix.Event.Base {
|
||||
private HashTable<string, Json.Node>? _tags = null;
|
||||
|
||||
protected override void
|
||||
from_json(Json.Node json_data)
|
||||
throws Matrix.Error
|
||||
{
|
||||
var content_root = json_data.get_object()
|
||||
.get_member("content").get_object();
|
||||
Json.Node? node;
|
||||
|
||||
if ((node = content_root.get_member("tags")) != null) {
|
||||
var tags_root = node.get_object();
|
||||
|
||||
tags_root.foreach_member((tobj, tag, tag_contents) => {
|
||||
if (_tags == null) {
|
||||
_tags = new HashTable<string, Json.Node>(
|
||||
str_hash, str_equal);
|
||||
}
|
||||
|
||||
_tags.replace(tag, tag_contents);
|
||||
});
|
||||
}
|
||||
|
||||
base.from_json(json_data);
|
||||
}
|
||||
|
||||
protected override void
|
||||
to_json(Json.Node json_data)
|
||||
throws Matrix.Error
|
||||
{
|
||||
if (_tags != null) {
|
||||
var tags_root = new Json.Object();
|
||||
|
||||
_tags.foreach((tag, tag_contents) => {
|
||||
tags_root.set_member(tag, tag_contents);
|
||||
});
|
||||
|
||||
if (tags_root.get_size() > 0) {
|
||||
var content_root = json_data.get_object()
|
||||
.get_member("content").get_object();
|
||||
var tags_node = new Json.Node(Json.NodeType.OBJECT);
|
||||
|
||||
tags_node.set_object(tags_root);
|
||||
content_root.set_member("tags", tags_node);
|
||||
}
|
||||
}
|
||||
|
||||
base.to_json(json_data);
|
||||
}
|
||||
}
|
@@ -153,13 +153,98 @@ static void
|
||||
matrix_event_types_ctor(void)
|
||||
{
|
||||
matrix_event_register_type("m.room.member",
|
||||
MATRIX_TYPE_ROOM_MEMBER_EVENT,
|
||||
MATRIX_EVENT_TYPE_ROOM_MEMBER,
|
||||
NULL);
|
||||
matrix_event_register_type("m.presence",
|
||||
MATRIX_TYPE_PRESENCE_EVENT,
|
||||
MATRIX_EVENT_TYPE_PRESENCE,
|
||||
NULL);
|
||||
matrix_event_register_type("m.room.message",
|
||||
MATRIX_TYPE_ROOM_MESSAGE_EVENT,
|
||||
MATRIX_EVENT_TYPE_ROOM_MESSAGE,
|
||||
NULL);
|
||||
matrix_event_register_type("m.room.topic",
|
||||
MATRIX_EVENT_TYPE_ROOM_TOPIC,
|
||||
NULL);
|
||||
matrix_event_register_type("m.typing",
|
||||
MATRIX_EVENT_TYPE_TYPING,
|
||||
NULL);
|
||||
matrix_event_register_type("m.room.aliases",
|
||||
MATRIX_EVENT_TYPE_ROOM_ALIASES,
|
||||
NULL);
|
||||
matrix_event_register_type("m.receipt",
|
||||
MATRIX_EVENT_TYPE_RECEIPT,
|
||||
NULL);
|
||||
matrix_event_register_type("m.room.history_visibility",
|
||||
MATRIX_EVENT_TYPE_ROOM_HISTORY_VISIBILITY,
|
||||
NULL);
|
||||
matrix_event_register_type("m.room.join_rules",
|
||||
MATRIX_EVENT_TYPE_ROOM_JOIN_RULES,
|
||||
NULL);
|
||||
matrix_event_register_type("m.room.name",
|
||||
MATRIX_EVENT_TYPE_ROOM_NAME,
|
||||
NULL);
|
||||
matrix_event_register_type("m.tag",
|
||||
MATRIX_EVENT_TYPE_TAG,
|
||||
NULL);
|
||||
matrix_event_register_type("m.room.canonical_alias",
|
||||
MATRIX_EVENT_TYPE_ROOM_CANONICAL_ALIAS,
|
||||
NULL);
|
||||
matrix_event_register_type("m.room.create",
|
||||
MATRIX_EVENT_TYPE_ROOM_CREATE,
|
||||
NULL);
|
||||
matrix_event_register_type("m.room.power_levels",
|
||||
MATRIX_EVENT_TYPE_ROOM_POWER_LEVELS,
|
||||
NULL);
|
||||
matrix_event_register_type("m.room.avatar",
|
||||
MATRIX_EVENT_TYPE_ROOM_AVATAR,
|
||||
NULL);
|
||||
matrix_event_register_type("m.room.message.feedback",
|
||||
MATRIX_EVENT_TYPE_ROOM_MESSAGE_FEEDBACK,
|
||||
NULL);
|
||||
matrix_event_register_type("m.room.guest_access",
|
||||
MATRIX_EVENT_TYPE_ROOM_GUEST_ACCESS,
|
||||
NULL);
|
||||
matrix_event_register_type("m.room.redaction",
|
||||
MATRIX_EVENT_TYPE_ROOM_REDACTION,
|
||||
NULL);
|
||||
matrix_event_register_type("m.room.third_party_invite",
|
||||
MATRIX_EVENT_TYPE_ROOM_THIRD_PARTY_INVITE,
|
||||
NULL);
|
||||
matrix_event_register_type("m.call.invite",
|
||||
MATRIX_EVENT_TYPE_CALL_INVITE,
|
||||
NULL);
|
||||
matrix_event_register_type("m.call.candidates",
|
||||
MATRIX_EVENT_TYPE_CALL_CANDIDATES,
|
||||
NULL);
|
||||
matrix_event_register_type("m.call.answer",
|
||||
MATRIX_EVENT_TYPE_CALL_ANSWER,
|
||||
NULL);
|
||||
matrix_event_register_type("m.call.hangup",
|
||||
MATRIX_EVENT_TYPE_CALL_HANGUP,
|
||||
NULL);
|
||||
|
||||
matrix_message_register_type("m.text",
|
||||
MATRIX_MESSAGE_TYPE_TEXT,
|
||||
NULL);
|
||||
matrix_message_register_type("m.emote",
|
||||
MATRIX_MESSAGE_TYPE_EMOTE,
|
||||
NULL);
|
||||
matrix_message_register_type("m.notice",
|
||||
MATRIX_MESSAGE_TYPE_NOTICE,
|
||||
NULL);
|
||||
matrix_message_register_type("m.file",
|
||||
MATRIX_MESSAGE_TYPE_FILE,
|
||||
NULL);
|
||||
matrix_message_register_type("m.image",
|
||||
MATRIX_MESSAGE_TYPE_IMAGE,
|
||||
NULL);
|
||||
matrix_message_register_type("m.audio",
|
||||
MATRIX_MESSAGE_TYPE_AUDIO,
|
||||
NULL);
|
||||
matrix_message_register_type("m.video",
|
||||
MATRIX_MESSAGE_TYPE_VIDEO,
|
||||
NULL);
|
||||
matrix_message_register_type("m.location",
|
||||
MATRIX_MESSAGE_TYPE_LOCATION,
|
||||
NULL);
|
||||
}
|
||||
|
||||
@@ -172,11 +257,11 @@ matrix_client_connect_event(MatrixClient *client,
|
||||
{
|
||||
GClosure *closure;
|
||||
GQuark equark;
|
||||
MatrixEventClass *event_class = MATRIX_EVENT_CLASS(
|
||||
MatrixEventBaseClass *event_class = MATRIX_EVENT_BASE_CLASS(
|
||||
g_type_class_ref(event_gtype));
|
||||
guint event_signal_id = g_signal_lookup("event", MATRIX_TYPE_CLIENT);
|
||||
|
||||
if (!MATRIX_IS_EVENT_CLASS(event_class)) {
|
||||
if (!MATRIX_EVENT_IS_BASE_CLASS(event_class)) {
|
||||
g_warning("Trying to connect to a type that is not derived from MatrixEvent");
|
||||
g_type_class_unref(event_class);
|
||||
|
||||
@@ -196,5 +281,4 @@ matrix_client_connect_event(MatrixClient *client,
|
||||
g_signal_connect_closure_by_id(client,
|
||||
event_signal_id, equark,
|
||||
closure, FALSE);
|
||||
|
||||
}
|
||||
|
86
src/matrix-event-typing.vala
Normal file
86
src/matrix-event-typing.vala
Normal file
@@ -0,0 +1,86 @@
|
||||
/*
|
||||
* This file is part of matrix-glib-sdk
|
||||
*
|
||||
* matrix-glib-sdk is free software: you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation, either
|
||||
* version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* matrix-glib-sdk is distributed in the hope that it will be
|
||||
* useful, but WITHOUT ANY WARRANTY; without even the implied
|
||||
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
* See the GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with matrix-glib-sdk. If not, see
|
||||
* <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Class to hold an m.typing event.
|
||||
*
|
||||
* Informs the client of the list of users currently typing.
|
||||
*/
|
||||
public class Matrix.Event.Typing : Matrix.Event.Base {
|
||||
/**
|
||||
* The ID of the room this event belongs to.
|
||||
*/
|
||||
public string? room_id { get; set; default = null; }
|
||||
|
||||
/**
|
||||
* The list of user IDs typing in this room, if any.
|
||||
*/
|
||||
public string[] user_ids { get; set; }
|
||||
|
||||
protected override void
|
||||
from_json(Json.Node json_data)
|
||||
throws Matrix.Error
|
||||
{
|
||||
var root = json_data.get_object();
|
||||
var content_root = root.get_member("content").get_object();
|
||||
Json.Node? node;
|
||||
|
||||
if ((node = root.get_member("room_id")) != null) {
|
||||
_room_id = node.get_string();
|
||||
} else if (Config.DEBUG) {
|
||||
warning("room_id is missing from a m.typing event");
|
||||
}
|
||||
|
||||
if ((node = content_root.get_member("user_ids")) != null) {
|
||||
_user_ids = new string[node.get_array().get_length()];
|
||||
|
||||
node.get_array().foreach_element((ary, idx, user_node) => {
|
||||
_user_ids[idx] = user_node.get_string();
|
||||
});
|
||||
} else if (Config.DEBUG) {
|
||||
warning("content.user_ids is missing from a m.typing event");
|
||||
}
|
||||
|
||||
base.from_json(json_data);
|
||||
}
|
||||
|
||||
protected override void
|
||||
to_json(Json.Node json_data)
|
||||
throws Matrix.Error
|
||||
{
|
||||
if (_room_id == null) {
|
||||
throw new Matrix.Error.INCOMPLETE(
|
||||
"Won't generate a m.typing event without room_id");
|
||||
}
|
||||
|
||||
var root = json_data.get_object();
|
||||
var content_root = root.get_member("content").get_object();
|
||||
|
||||
root.set_string_member("room_id", _room_id);
|
||||
|
||||
var users_ary = new Json.Array();
|
||||
var users_node = new Json.Node(Json.NodeType.ARRAY);
|
||||
content_root.set_member("user_ids", users_node);
|
||||
|
||||
foreach (var entry in _user_ids) {
|
||||
users_ary.add_string_element(entry);
|
||||
}
|
||||
|
||||
base.to_json(json_data);
|
||||
}
|
||||
}
|
@@ -1,339 +0,0 @@
|
||||
/*
|
||||
* This file is part of matrix-glib-sdk
|
||||
*
|
||||
* matrix-glib-sdk is free software: you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation, either
|
||||
* version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* matrix-glib-sdk is distributed in the hope that it will be
|
||||
* useful, but WITHOUT ANY WARRANTY; without even the implied
|
||||
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
* See the GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with matrix-glib-sdk. If not, see
|
||||
* <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
private HashTable<string, TypeClass>? event_type_handlers = null;
|
||||
|
||||
/**
|
||||
* Base class for Matrix events.
|
||||
*/
|
||||
public class Matrix.Event : GLib.Object, GLib.Initable {
|
||||
private Error? _construct_error = null;
|
||||
private bool _inited = false;
|
||||
private Json.Node? _json;
|
||||
private Gee.HashMap<string, Json.Node> _custom_fields =
|
||||
new Gee.HashMap<string, Json.Node>();
|
||||
|
||||
protected string? _sender = null;
|
||||
protected string? _room_id = null;
|
||||
|
||||
/**
|
||||
* The Matrix ID of the events sender.
|
||||
*/
|
||||
public string? sender {
|
||||
get {
|
||||
return _sender;
|
||||
}
|
||||
|
||||
set {
|
||||
_sender = value;
|
||||
}
|
||||
|
||||
default = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* The ID of the room this event is associated with.
|
||||
*/
|
||||
public string? room_id {
|
||||
get {
|
||||
return _room_id;
|
||||
}
|
||||
|
||||
set {
|
||||
_room_id = value;
|
||||
}
|
||||
|
||||
default = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* The type of the event.
|
||||
*/
|
||||
public string? event_type { get; construct; default = null; }
|
||||
|
||||
/**
|
||||
* The timestamp of the event on the originating server.
|
||||
*/
|
||||
public ulong? origin_server_ts { get; set; default = null; }
|
||||
|
||||
/**
|
||||
* The unsigned part of the event.
|
||||
*/
|
||||
public Matrix.UnsignedEventData unsigned_data {
|
||||
get; set;
|
||||
default = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* The event as a JSON node.
|
||||
*/
|
||||
public Json.Node? json {
|
||||
get {
|
||||
if (_json == null) {
|
||||
_json = new Json.Node(Json.NodeType.OBJECT);
|
||||
_json.set_object(new Json.Object());
|
||||
|
||||
}
|
||||
|
||||
try {
|
||||
to_json(_json);
|
||||
}
|
||||
catch (Matrix.Error e) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return _json;
|
||||
}
|
||||
|
||||
construct {
|
||||
if (value != null) {
|
||||
try {
|
||||
initialize_from_json(value);
|
||||
} catch (Matrix.Error e) {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public bool
|
||||
init(GLib.Cancellable? cancellable = null)
|
||||
throws Error, Matrix.Error
|
||||
{
|
||||
if (cancellable != null) {
|
||||
throw new Matrix.Error.UNSUPPORTED(
|
||||
"Cancellable initialization not supported");
|
||||
}
|
||||
|
||||
if (_construct_error != null) {
|
||||
throw _construct_error;
|
||||
}
|
||||
|
||||
_inited = true;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private void
|
||||
initialize_from_json(Json.Node json_data)
|
||||
throws Matrix.Error
|
||||
{
|
||||
Json.Object root;
|
||||
Json.Node node;
|
||||
|
||||
if (json_data.get_node_type() != Json.NodeType.OBJECT) {
|
||||
throw new Matrix.Error.INVALID_FORMAT(
|
||||
"The event is not valid");
|
||||
}
|
||||
|
||||
root = json_data.get_object();
|
||||
|
||||
if ((node = root.get_member("type")) == null) {
|
||||
throw new Matrix.Error.INCOMPLETE(
|
||||
"Event type is not specified");
|
||||
}
|
||||
|
||||
if ((_event_type != null)
|
||||
&& (_event_type != node.get_string())) {
|
||||
throw new Matrix.Error.INVALID_TYPE(
|
||||
"Changing event type is not supported");
|
||||
}
|
||||
|
||||
from_json(json_data);
|
||||
|
||||
_event_type = node.get_string();
|
||||
|
||||
if ((node = root.get_member("origin_server_ts")) != null) {
|
||||
_origin_server_ts = (ulong)node.get_int();
|
||||
}
|
||||
|
||||
if ((node = root.get_member("sender")) != null) {
|
||||
_sender = node.get_string();
|
||||
}
|
||||
|
||||
if ((node = root.get_member("unsigned")) != null) {
|
||||
_unsigned_data = new Matrix.UnsignedEventData.from_json(node);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Subclasses should implement this function to initialize
|
||||
* themselves from JSON data.
|
||||
*/
|
||||
public virtual void
|
||||
from_json(Json.Node json_data)
|
||||
throws Matrix.Error
|
||||
{}
|
||||
|
||||
/**
|
||||
* Subclasses should implement this to export their data to JSON.
|
||||
*/
|
||||
public virtual void
|
||||
to_json(Json.Node json_data)
|
||||
throws Matrix.Error
|
||||
{
|
||||
Json.Object root = json_data.get_object();
|
||||
|
||||
foreach (var entry in _custom_fields.entries) {
|
||||
root.set_member(entry.key, _json_node_deep_copy(entry.value));
|
||||
}
|
||||
|
||||
if (event_type != null) {
|
||||
root.set_string_member("type", event_type);
|
||||
}
|
||||
|
||||
if (origin_server_ts != null) {
|
||||
root.set_int_member("origin_server_ts", origin_server_ts);
|
||||
}
|
||||
|
||||
if (sender != null) {
|
||||
root.set_string_member("sender", sender);
|
||||
}
|
||||
|
||||
if (unsigned_data != null) {
|
||||
root.set_member("unsigned", unsigned_data.get_json_node());
|
||||
}
|
||||
}
|
||||
|
||||
public static Event?
|
||||
new_from_json(owned string? event_type = null,
|
||||
string? room_id = null,
|
||||
Json.Node? json_data = null)
|
||||
throws Matrix.Error, GLib.Error
|
||||
{
|
||||
GLib.Type event_gtype;
|
||||
Event? ret = null;
|
||||
|
||||
if (event_type == null) {
|
||||
if (json_data == null) {
|
||||
throw new Matrix.Error.INCOMPLETE(
|
||||
"Either event_type or json_data must be set!");
|
||||
}
|
||||
|
||||
if (json_data.get_node_type() != Json.NodeType.OBJECT) {
|
||||
throw new Matrix.Error.INVALID_FORMAT(
|
||||
"Event is not a JSON object!");
|
||||
}
|
||||
|
||||
Json.Node? node;
|
||||
|
||||
if ((node = json_data.get_object().get_member("type")) == null) {
|
||||
throw new Matrix.Error.INCOMPLETE(
|
||||
"event_type is null and JSON object doesn't contain type!");
|
||||
}
|
||||
|
||||
event_type = node.get_string();
|
||||
}
|
||||
|
||||
event_gtype = get_handler(event_type);
|
||||
|
||||
ret = (Event)Object.new(event_gtype,
|
||||
event_type : event_type,
|
||||
room_id : room_id,
|
||||
json : json_data);
|
||||
|
||||
ret.init();
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a value for a custom field.
|
||||
*/
|
||||
public void
|
||||
set_custom_field(string field_name, Json.Node value)
|
||||
{
|
||||
_custom_fields.set(field_name, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the value of a custom field.
|
||||
*/
|
||||
public Json.Node?
|
||||
get_custom_field (string field_name)
|
||||
{
|
||||
return _custom_fields.get(field_name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a custom field.
|
||||
*/
|
||||
public void
|
||||
delete_custom_field (string field_name)
|
||||
{
|
||||
_custom_fields.unset(field_name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the {@link GLib.Type} of the class that is registered to
|
||||
* handle events with type @param event_type.
|
||||
*
|
||||
* @param event_type the event type to look up
|
||||
* @return a {@link GLib.Type} or {@link Matrix.Event} if no
|
||||
* handler is registered
|
||||
*/
|
||||
public static GLib.Type
|
||||
get_handler(string event_type)
|
||||
{
|
||||
unowned GLib.TypeClass? klass = null;
|
||||
|
||||
if ((event_type_handlers != null)
|
||||
&& ((klass = event_type_handlers.get(event_type)) != null)) {
|
||||
return klass.get_type();
|
||||
}
|
||||
|
||||
warning("UsingMatrix.Event for %s", event_type);
|
||||
|
||||
return typeof(Matrix.Event);
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers @param event_type to be handled by the
|
||||
* type @param event_gtype.
|
||||
*
|
||||
* @param event_type the type of the event
|
||||
* @param event_gtype the {@link GLib.Type} of the event’s handler
|
||||
*/
|
||||
public static void
|
||||
register_type(string event_type, GLib.Type event_gtype)
|
||||
throws Matrix.Error
|
||||
{
|
||||
if (!event_gtype.is_a(typeof(Matrix.Event))) {
|
||||
throw new Matrix.Error.INVALID_TYPE(
|
||||
"Invalid event type handler. It must be a subclass of MatrixEvent");
|
||||
}
|
||||
|
||||
if (event_type_handlers == null) {
|
||||
event_type_handlers = new HashTable<string, GLib.TypeClass>(
|
||||
str_hash, str_equal);
|
||||
}
|
||||
|
||||
event_type_handlers.replace(event_type, event_gtype.class_ref());
|
||||
}
|
||||
|
||||
/**
|
||||
* Unregister @param event_type.
|
||||
*
|
||||
* @param event_type the event type to remove
|
||||
*/
|
||||
public static void
|
||||
unregister_type(string event_type)
|
||||
{
|
||||
if (event_type_handlers != null) {
|
||||
event_type_handlers.remove(event_type);
|
||||
}
|
||||
}
|
||||
}
|
14
src/matrix-glib-0.0.pc.in
Normal file
14
src/matrix-glib-0.0.pc.in
Normal file
@@ -0,0 +1,14 @@
|
||||
prefix=@prefix@
|
||||
exec_prefix=@exec_prefix@
|
||||
libdir=@libdir@
|
||||
datarootdir=@datarootdir@
|
||||
datadir=@datadir@
|
||||
includedir=@includedir@
|
||||
|
||||
Name: libmatrix-glib
|
||||
Description: GObject API for communicating with a Matrix.org Homeserver
|
||||
URL: http://gergely.polonkai.eu/matrix-glib-sdk
|
||||
Version: @MATRIX_GLIB_VERSION@
|
||||
Requires: glib-2.0 gobject-2.0 gio-2.0 json-glib-1.0
|
||||
Libs: -L${libdir} -lmatrix-glib-@MATRIX_GLIB_API_VERSION@
|
||||
Cflags: -I${includedir}/matrix-glib-@MATRIX_GLIB_API_VERSION@
|
@@ -63,14 +63,17 @@ public class Matrix.HTTPAPI : GLib.Object, Matrix.API {
|
||||
if ((api_uri != null) && (media_uri != null)) {
|
||||
_api_uri = api_uri;
|
||||
_media_uri = media_uri;
|
||||
_base_url = value;
|
||||
|
||||
_token = null;
|
||||
_refresh_token = null;
|
||||
_homeserver = null;
|
||||
_user_id = null;
|
||||
|
||||
if (Config.DEBUG) {
|
||||
debug("API URL: %s", api_uri.to_string(false));
|
||||
debug("Media URL: %s", media_uri.to_string(false));
|
||||
}
|
||||
} else {
|
||||
warning("Invalid base URL: %s", value);
|
||||
}
|
||||
@@ -85,7 +88,7 @@ public class Matrix.HTTPAPI : GLib.Object, Matrix.API {
|
||||
_soup_session.ssl_strict = value;
|
||||
}
|
||||
}
|
||||
private string? _user_id;
|
||||
protected string? _user_id;
|
||||
public string? user_id {
|
||||
get {
|
||||
return _user_id;
|
||||
@@ -95,7 +98,7 @@ public class Matrix.HTTPAPI : GLib.Object, Matrix.API {
|
||||
}
|
||||
public string? token { get; set; default = null; }
|
||||
public string? refresh_token { get; set; default = null; }
|
||||
private string? _homeserver;
|
||||
protected string? _homeserver;
|
||||
public string? homeserver {
|
||||
get {
|
||||
return _homeserver;
|
||||
@@ -124,10 +127,20 @@ public class Matrix.HTTPAPI : GLib.Object, Matrix.API {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new MatrixHTTPAPI object.
|
||||
*
|
||||
* @param base_url the base URL of the homeserver to use
|
||||
* @param token an access token to use
|
||||
* @param refresh_token a refresh token to use
|
||||
* @return a new MatrixHTTPAPI object
|
||||
*/
|
||||
protected
|
||||
HTTPAPI(string base_url, string? token = null)
|
||||
HTTPAPI(string base_url, string? token = null, string? refresh_token = null)
|
||||
{
|
||||
Object(base_url : base_url, token : token);
|
||||
Object(base_url : base_url,
|
||||
token : token,
|
||||
refresh_token : refresh_token);
|
||||
_soup_session.ssl_strict = true;
|
||||
}
|
||||
|
||||
@@ -186,7 +199,9 @@ public class Matrix.HTTPAPI : GLib.Object, Matrix.API {
|
||||
}
|
||||
|
||||
if (token != null) {
|
||||
if (Config.DEBUG) {
|
||||
debug("Adding access token '%s'", token);
|
||||
}
|
||||
|
||||
parms.replace("access_token", token);
|
||||
}
|
||||
@@ -202,12 +217,15 @@ public class Matrix.HTTPAPI : GLib.Object, Matrix.API {
|
||||
generator.set_root(json_content);
|
||||
var json_str = generator.to_data(null);
|
||||
request_data = json_str.data;
|
||||
request_data[request_data.length] = 0;
|
||||
} else if (raw_content != null) {
|
||||
request_data = raw_content.data;
|
||||
} else {
|
||||
request_data = "{}".data;
|
||||
request_data[2] = 0;
|
||||
}
|
||||
|
||||
if (Config.DEBUG) {
|
||||
debug("Sending %d bytes (%s %s): %s",
|
||||
request_data.length,
|
||||
method,
|
||||
@@ -215,6 +233,7 @@ public class Matrix.HTTPAPI : GLib.Object, Matrix.API {
|
||||
(raw_content != null)
|
||||
? "<Binary data>"
|
||||
: (string)request_data);
|
||||
}
|
||||
|
||||
message.set_flags(Soup.MessageFlags.NO_REDIRECT);
|
||||
message.set_request(
|
||||
@@ -276,7 +295,9 @@ public class Matrix.HTTPAPI : GLib.Object, Matrix.API {
|
||||
}
|
||||
|
||||
if (is_json) {
|
||||
if (Config.DEBUG) {
|
||||
debug("Response (%s): %s", request_url, data);
|
||||
}
|
||||
|
||||
content = parser.get_root();
|
||||
|
||||
@@ -290,7 +311,10 @@ public class Matrix.HTTPAPI : GLib.Object, Matrix.API {
|
||||
string? access_token;
|
||||
|
||||
if ((access_token = node.get_string()) != null) {
|
||||
if (Config.DEBUG) {
|
||||
debug("Got new access token: %s", access_token);
|
||||
}
|
||||
|
||||
token = access_token;
|
||||
}
|
||||
}
|
||||
@@ -301,8 +325,11 @@ public class Matrix.HTTPAPI : GLib.Object, Matrix.API {
|
||||
string? refresh_token;
|
||||
|
||||
if ((refresh_token = node.get_string()) != null) {
|
||||
if (Config.DEBUG) {
|
||||
debug("Got new refresh token: %s",
|
||||
refresh_token);
|
||||
}
|
||||
|
||||
this.refresh_token = refresh_token;
|
||||
}
|
||||
}
|
||||
@@ -311,7 +338,11 @@ public class Matrix.HTTPAPI : GLib.Object, Matrix.API {
|
||||
if ((node = root.get_member("home_server")) != null) {
|
||||
string homeserver = node.get_string();
|
||||
|
||||
debug("Our home server calls itself %s", homeserver);
|
||||
if (Config.DEBUG) {
|
||||
debug("Our home server calls itself %s",
|
||||
homeserver);
|
||||
}
|
||||
|
||||
this._homeserver = homeserver;
|
||||
}
|
||||
|
||||
@@ -320,7 +351,11 @@ public class Matrix.HTTPAPI : GLib.Object, Matrix.API {
|
||||
if ((node = root.get_member("user_id")) != null) {
|
||||
string user_id = node.get_string();
|
||||
|
||||
debug("We are reported to be logged in as %s", user_id);
|
||||
if (Config.DEBUG) {
|
||||
debug("We are reported to be logged in as %s",
|
||||
user_id);
|
||||
}
|
||||
|
||||
this._user_id = user_id;
|
||||
}
|
||||
|
||||
@@ -403,14 +438,21 @@ public class Matrix.HTTPAPI : GLib.Object, Matrix.API {
|
||||
if (accept_non_json) {
|
||||
raw_content = new ByteArray.sized((uint)datalen);
|
||||
raw_content.append(buffer.data);
|
||||
debug("Binary data (%s): %u bytes", request_url, (uint)datalen);
|
||||
|
||||
if (Config.DEBUG) {
|
||||
debug("Binary data (%s): %u bytes",
|
||||
request_url, (uint)datalen);
|
||||
}
|
||||
} else {
|
||||
err = new Matrix.Error.BAD_RESPONSE(
|
||||
"Malformed response (invalid JSON)");
|
||||
|
||||
if (Config.DEBUG) {
|
||||
debug("Malformed response (%s): %s", request_url, data);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Call the assigned function, if any */
|
||||
if (cb != null) {
|
||||
@@ -520,8 +562,8 @@ public class Matrix.HTTPAPI : GLib.Object, Matrix.API {
|
||||
public void
|
||||
update_presence_list(API.Callback? cb,
|
||||
string user_id,
|
||||
List<string> drop_ids,
|
||||
List<string> invite_ids)
|
||||
string[] drop_ids,
|
||||
string[] invite_ids)
|
||||
throws Matrix.Error
|
||||
{
|
||||
Json.Builder builder;
|
||||
@@ -532,23 +574,25 @@ public class Matrix.HTTPAPI : GLib.Object, Matrix.API {
|
||||
builder = new Json.Builder();
|
||||
builder.begin_object();
|
||||
|
||||
if (drop_ids != null) {
|
||||
if (drop_ids.length > 0) {
|
||||
builder.set_member_name("drop");
|
||||
builder.begin_array();
|
||||
drop_ids.foreach(
|
||||
(entry) => {
|
||||
|
||||
foreach (var entry in drop_ids) {
|
||||
builder.add_string_value(entry);
|
||||
});
|
||||
}
|
||||
|
||||
builder.end_array();
|
||||
}
|
||||
|
||||
if (invite_ids != null) {
|
||||
if (invite_ids.length > 0) {
|
||||
builder.set_member_name("invite");
|
||||
builder.begin_array();
|
||||
invite_ids.foreach(
|
||||
(entry) => {
|
||||
|
||||
foreach (var entry in invite_ids) {
|
||||
builder.add_string_value(entry);
|
||||
});
|
||||
}
|
||||
|
||||
builder.end_array();
|
||||
}
|
||||
|
||||
@@ -560,7 +604,7 @@ public class Matrix.HTTPAPI : GLib.Object, Matrix.API {
|
||||
}
|
||||
|
||||
public void
|
||||
get_user_presence(API.Callback? cb,
|
||||
get_presence(API.Callback? cb,
|
||||
string user_id)
|
||||
throws Matrix.Error
|
||||
{
|
||||
@@ -574,7 +618,7 @@ public class Matrix.HTTPAPI : GLib.Object, Matrix.API {
|
||||
}
|
||||
|
||||
public void
|
||||
set_user_presence(API.Callback? cb,
|
||||
set_presence(API.Callback? cb,
|
||||
string user_id,
|
||||
Presence presence,
|
||||
string? status_message)
|
||||
@@ -661,7 +705,7 @@ public class Matrix.HTTPAPI : GLib.Object, Matrix.API {
|
||||
}
|
||||
|
||||
public void
|
||||
delete_pusher(API.Callback? cb,
|
||||
delete_pushrule(API.Callback? cb,
|
||||
string scope,
|
||||
PusherKind kind,
|
||||
string rule_id)
|
||||
@@ -671,7 +715,7 @@ public class Matrix.HTTPAPI : GLib.Object, Matrix.API {
|
||||
}
|
||||
|
||||
public void
|
||||
get_pusher(API.Callback? cb,
|
||||
get_pushrule(API.Callback? cb,
|
||||
string scope,
|
||||
PusherKind kind,
|
||||
string rule_id)
|
||||
@@ -681,14 +725,14 @@ public class Matrix.HTTPAPI : GLib.Object, Matrix.API {
|
||||
}
|
||||
|
||||
public void
|
||||
add_pusher(API.Callback? cb,
|
||||
add_pushrule(API.Callback? cb,
|
||||
string scope,
|
||||
PusherKind kind,
|
||||
string rule_id,
|
||||
string? before,
|
||||
string? after,
|
||||
List<string> actions,
|
||||
List<PusherConditionKind?>? conditions)
|
||||
string[] actions,
|
||||
PusherConditionKind[] conditions)
|
||||
throws Matrix.Error
|
||||
{
|
||||
Json.Builder builder;
|
||||
@@ -707,17 +751,16 @@ public class Matrix.HTTPAPI : GLib.Object, Matrix.API {
|
||||
|
||||
builder.set_member_name("actions");
|
||||
builder.begin_array();
|
||||
actions.foreach(
|
||||
(entry) => {
|
||||
foreach (var entry in actions) {
|
||||
builder.add_string_value(entry);
|
||||
});
|
||||
}
|
||||
builder.end_array();
|
||||
|
||||
if (conditions != null) {
|
||||
if (conditions.length > 0) {
|
||||
builder.set_member_name("conditions");
|
||||
builder.begin_array();
|
||||
conditions.foreach(
|
||||
(entry) => {
|
||||
|
||||
foreach (var entry in conditions) {
|
||||
string? kind_string = _g_enum_value_to_nick(
|
||||
typeof(Matrix.PusherConditionKind),
|
||||
entry);
|
||||
@@ -732,7 +775,8 @@ public class Matrix.HTTPAPI : GLib.Object, Matrix.API {
|
||||
builder.set_member_name("kind");
|
||||
builder.add_string_value(kind_string);
|
||||
builder.end_object();
|
||||
});
|
||||
}
|
||||
|
||||
builder.end_array();
|
||||
}
|
||||
|
||||
@@ -745,7 +789,7 @@ public class Matrix.HTTPAPI : GLib.Object, Matrix.API {
|
||||
}
|
||||
|
||||
public void
|
||||
toggle_pusher(API.Callback? cb,
|
||||
toggle_pushrule(API.Callback? cb,
|
||||
string scope,
|
||||
PusherKind kind,
|
||||
string rule_id,
|
||||
@@ -768,6 +812,15 @@ public class Matrix.HTTPAPI : GLib.Object, Matrix.API {
|
||||
null, null, builder.get_root(), null, false);
|
||||
}
|
||||
|
||||
public void
|
||||
get_pushrules(API.Callback? cb)
|
||||
throws Matrix.Error
|
||||
{
|
||||
_send(cb,
|
||||
CallType.API, "GET", "pushrules",
|
||||
null, null, null, null, false);
|
||||
}
|
||||
|
||||
/* Room creation */
|
||||
|
||||
public void
|
||||
@@ -778,9 +831,9 @@ public class Matrix.HTTPAPI : GLib.Object, Matrix.API {
|
||||
string? topic,
|
||||
RoomVisibility visibility,
|
||||
Json.Node? creation_content,
|
||||
List<StateEvent>? initial_state,
|
||||
List<string>? invitees,
|
||||
List<3PidCredential>? invite_3pids)
|
||||
Matrix.Event.State[] initial_state,
|
||||
string[] invitees,
|
||||
3PidCredential[] invite_3pids)
|
||||
throws Matrix.Error
|
||||
{
|
||||
Json.Builder builder = new Json.Builder();
|
||||
@@ -792,37 +845,39 @@ public class Matrix.HTTPAPI : GLib.Object, Matrix.API {
|
||||
builder.add_value(creation_content);
|
||||
}
|
||||
|
||||
if (initial_state != null) {
|
||||
if (initial_state.length > 0) {
|
||||
builder.set_member_name("initial_state");
|
||||
builder.begin_array();
|
||||
initial_state.foreach(
|
||||
(entry) => {
|
||||
|
||||
foreach (var entry in initial_state) {
|
||||
builder.add_value(entry.json);
|
||||
});
|
||||
}
|
||||
|
||||
builder.end_array();
|
||||
}
|
||||
|
||||
if (invitees != null) {
|
||||
if (invitees.length > 0) {
|
||||
builder.set_member_name("invite");
|
||||
builder.begin_array();
|
||||
invitees.foreach(
|
||||
(entry) => {
|
||||
|
||||
foreach (var entry in invitees) {
|
||||
builder.add_string_value(entry);
|
||||
});
|
||||
}
|
||||
|
||||
builder.end_array();
|
||||
}
|
||||
|
||||
if (invite_3pids != null) {
|
||||
if (invite_3pids.length > 0) {
|
||||
builder.set_member_name("invite_3pid");
|
||||
builder.begin_array();
|
||||
invite_3pids.foreach(
|
||||
(entry) => {
|
||||
|
||||
foreach (var entry in invite_3pids) {
|
||||
try {
|
||||
builder.add_value(entry.get_json_node());
|
||||
// TODO exceptions should be handled
|
||||
// here somehow
|
||||
// TODO exceptions should be handled here somehow
|
||||
} catch (Matrix.Error e) {}
|
||||
});
|
||||
}
|
||||
|
||||
builder.end_array();
|
||||
}
|
||||
|
||||
@@ -961,6 +1016,27 @@ public class Matrix.HTTPAPI : GLib.Object, Matrix.API {
|
||||
null, null, builder.get_root(), null, false);
|
||||
}
|
||||
|
||||
public void
|
||||
unban_user(API.Callback? cb,
|
||||
string room_id,
|
||||
string user_id)
|
||||
throws Matrix.Error
|
||||
{
|
||||
string path = "rooms/"
|
||||
+ Soup.URI.encode(room_id, null)
|
||||
+ "/unban";
|
||||
var builder = new Json.Builder();
|
||||
|
||||
builder.begin_object();
|
||||
|
||||
builder.set_member_name("user_id");
|
||||
builder.add_string_value(user_id);
|
||||
|
||||
builder.end_object();
|
||||
|
||||
_send(cb, CallType.API, "POST", path, null, null, builder.get_root(), null, false);
|
||||
}
|
||||
|
||||
public void
|
||||
forget_room(API.Callback? cb,
|
||||
string room_id)
|
||||
@@ -1046,6 +1122,40 @@ public class Matrix.HTTPAPI : GLib.Object, Matrix.API {
|
||||
null, null, null, null, false);
|
||||
}
|
||||
|
||||
public void
|
||||
join_room_id_or_alias(API.Callback? cb, string room_id_or_alias)
|
||||
throws Matrix.Error
|
||||
{
|
||||
var path = "join/" + Soup.URI.encode(room_id_or_alias, null);
|
||||
|
||||
_send(cb, CallType.API, "POST", path,
|
||||
null, null, null, null, false);
|
||||
}
|
||||
|
||||
public void
|
||||
kick_user(API.Callback? cb,
|
||||
string room_id, string user_id, string? reason)
|
||||
throws Matrix.Error
|
||||
{
|
||||
var path = "rooms/" + Soup.URI.encode(room_id, null) + "/kick";
|
||||
var builder = new Json.Builder();
|
||||
|
||||
builder.begin_object();
|
||||
|
||||
builder.set_member_name("user_id");
|
||||
builder.add_string_value(user_id);
|
||||
|
||||
if (reason != null) {
|
||||
builder.set_member_name("reason");
|
||||
builder.add_string_value(reason);
|
||||
}
|
||||
|
||||
builder.end_object();
|
||||
|
||||
_send(cb, CallType.API, "POST", path,
|
||||
null, null, builder.get_root(), null, false);
|
||||
}
|
||||
|
||||
/* Room participation */
|
||||
|
||||
public void
|
||||
@@ -1244,7 +1354,7 @@ public class Matrix.HTTPAPI : GLib.Object, Matrix.API {
|
||||
}
|
||||
|
||||
public void
|
||||
send_message_event(API.Callback? cb,
|
||||
send_event(API.Callback? cb,
|
||||
string room_id,
|
||||
string event_type,
|
||||
string txn_id,
|
||||
@@ -1285,7 +1395,7 @@ public class Matrix.HTTPAPI : GLib.Object, Matrix.API {
|
||||
}
|
||||
|
||||
public void
|
||||
send_room_event(API.Callback? cb,
|
||||
send_state_event(API.Callback? cb,
|
||||
string room_id,
|
||||
string event_type,
|
||||
string? state_key,
|
||||
@@ -1491,6 +1601,15 @@ public class Matrix.HTTPAPI : GLib.Object, Matrix.API {
|
||||
null, null, builder.get_root(), null, false);
|
||||
}
|
||||
|
||||
public void
|
||||
logout(API.Callback? cb)
|
||||
throws Matrix.Error
|
||||
{
|
||||
_send(cb,
|
||||
CallType.API, "POST", "logout",
|
||||
null, null, null, null, false);
|
||||
}
|
||||
|
||||
/* User data */
|
||||
|
||||
public void
|
||||
@@ -1743,6 +1862,36 @@ public class Matrix.HTTPAPI : GLib.Object, Matrix.API {
|
||||
null, null, content, null, false);
|
||||
}
|
||||
|
||||
public void
|
||||
deactivate_account(API.Callback? cb, string? session, string? login_type)
|
||||
throws Matrix.Error
|
||||
{
|
||||
Json.Builder? builder = null;
|
||||
|
||||
if (login_type != null) {
|
||||
builder = new Json.Builder();
|
||||
|
||||
builder.begin_object();
|
||||
|
||||
builder.set_member_name("auth");
|
||||
builder.begin_object();
|
||||
|
||||
if (session != null) {
|
||||
builder.set_member_name("session");
|
||||
builder.add_string_value(session);
|
||||
}
|
||||
|
||||
builder.set_member_name("type");
|
||||
builder.add_string_value(login_type);
|
||||
|
||||
builder.end_object();
|
||||
builder.end_object();
|
||||
}
|
||||
|
||||
_send(cb, CallType.API, "POST", "account/deactivate",
|
||||
null, null, (builder != null) ? builder.get_root() : null, null, false);
|
||||
}
|
||||
|
||||
/* VoIP */
|
||||
|
||||
public void
|
||||
|
@@ -24,6 +24,13 @@ public class Matrix.HTTPClient : Matrix.HTTPAPI, Matrix.Client {
|
||||
private bool _polling = false;
|
||||
private ulong _event_timeout = 30000;
|
||||
private string? _last_sync_token;
|
||||
private HashTable<string, Profile> _user_global_profiles =
|
||||
new HashTable<string, Profile>(str_hash, str_equal);
|
||||
private HashTable<string, Presence> _user_global_presence =
|
||||
new HashTable<string, Presence>(str_hash, str_equal);
|
||||
private HashTable<string, Room> _rooms =
|
||||
new HashTable<string, Room>(str_hash, str_equal);
|
||||
private ulong _last_txn_id = 0;
|
||||
|
||||
public
|
||||
HTTPClient(string base_url)
|
||||
@@ -66,13 +73,16 @@ public class Matrix.HTTPClient : Matrix.HTTPAPI, Matrix.Client {
|
||||
false, username, password);
|
||||
}
|
||||
|
||||
public void
|
||||
public new void
|
||||
logout()
|
||||
throws Matrix.Error
|
||||
{
|
||||
((Matrix.API)this).logout(
|
||||
() => {
|
||||
token = null;
|
||||
refresh_token = null;
|
||||
abort_pending();
|
||||
});
|
||||
}
|
||||
|
||||
private void
|
||||
@@ -81,10 +91,12 @@ public class Matrix.HTTPClient : Matrix.HTTPAPI, Matrix.Client {
|
||||
Json.Object root_obj;
|
||||
Json.Node node;
|
||||
string event_type;
|
||||
Matrix.Event evt;
|
||||
Matrix.Event.Base? evt = null;
|
||||
|
||||
if (event_node.get_node_type() != Json.NodeType.OBJECT) {
|
||||
if (Config.DEBUG) {
|
||||
warning("Received event that is not an object.");
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
@@ -92,7 +104,9 @@ public class Matrix.HTTPClient : Matrix.HTTPAPI, Matrix.Client {
|
||||
root_obj = event_node.get_object();
|
||||
|
||||
if ((node = root_obj.get_member("type")) == null) {
|
||||
if (Config.DEBUG) {
|
||||
warning("Received event without type.");
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
@@ -100,20 +114,136 @@ public class Matrix.HTTPClient : Matrix.HTTPAPI, Matrix.Client {
|
||||
event_type = node.get_string();
|
||||
|
||||
try {
|
||||
evt = Matrix.Event.new_from_json(event_type, room_id, event_node);
|
||||
} catch (Matrix.Error e) {
|
||||
warning("Error during event creation: %s", e.message);
|
||||
|
||||
return;
|
||||
evt = Matrix.Event.Base.new_from_json(event_type, event_node);
|
||||
} catch (GLib.Error e) {
|
||||
warning("Error during event creation: %s", e.message);
|
||||
evt = null;
|
||||
}
|
||||
|
||||
return;
|
||||
if (evt != null) {
|
||||
// Make sure Room events have room_id set, even if it was
|
||||
// stripped by the HS
|
||||
if (evt is Matrix.Event.Room) {
|
||||
Matrix.Event.Room revt = (Matrix.Event.Room)evt;
|
||||
|
||||
if (revt.room_id == null) {
|
||||
revt.room_id = room_id;
|
||||
}
|
||||
}
|
||||
|
||||
if (evt is Matrix.Event.Presence) {
|
||||
var pevt = (Matrix.Event.Presence)evt;
|
||||
var user_id = pevt.user_id;
|
||||
|
||||
_user_global_presence[user_id] = pevt.presence;
|
||||
|
||||
Profile? profile = _user_global_profiles[user_id];
|
||||
|
||||
if (profile == null) {
|
||||
profile = new Profile();
|
||||
_user_global_profiles[user_id] = profile;
|
||||
}
|
||||
|
||||
profile.avatar_url = pevt.avatar_url;
|
||||
profile.display_name = pevt.display_name;
|
||||
} else if (evt is Matrix.Event.Room) {
|
||||
var revt = (Matrix.Event.Room)evt;
|
||||
var room = _get_or_create_room(revt.room_id);
|
||||
|
||||
if (evt is Matrix.Event.RoomMember) {
|
||||
var mevt = (Matrix.Event.RoomMember)evt;
|
||||
var user_id = mevt.user_id;
|
||||
Profile? profile = null;
|
||||
|
||||
try {
|
||||
profile = room.get_or_add_member(
|
||||
user_id,
|
||||
(mevt.tpi_display_name != null));
|
||||
} catch (Matrix.Error e) {}
|
||||
|
||||
profile.avatar_url = mevt.avatar_url;
|
||||
profile.display_name = mevt.display_name;
|
||||
} else if (evt is Matrix.Event.RoomAliases) {
|
||||
var aevt = (Matrix.Event.RoomAliases)evt;
|
||||
|
||||
room.aliases = aevt.aliases;
|
||||
} else if (evt is Matrix.Event.RoomAvatar) {
|
||||
var aevt = (Matrix.Event.RoomAvatar)evt;
|
||||
|
||||
room.avatar_url = aevt.url;
|
||||
room.avatar_info = aevt.info;
|
||||
room.avatar_thumbnail_url = aevt.thumbnail_url;
|
||||
room.avatar_thumbnail_info = aevt.thumbnail_info;
|
||||
} else if (evt is Matrix.Event.RoomCanonicalAlias) {
|
||||
var cevt = (Matrix.Event.RoomCanonicalAlias)evt;
|
||||
|
||||
room.canonical_alias = cevt.canonical_alias;
|
||||
} else if (evt is Matrix.Event.RoomCreate) {
|
||||
var cevt = (Matrix.Event.RoomCreate)evt;
|
||||
|
||||
room.creator = cevt.creator;
|
||||
room.federate = cevt.federate;
|
||||
} else if (evt is Matrix.Event.RoomGuestAccess) {
|
||||
var gevt = (Matrix.Event.RoomGuestAccess)evt;
|
||||
|
||||
room.guest_access = gevt.guest_access;
|
||||
} else if (evt is Matrix.Event.RoomHistoryVisibility) {
|
||||
var hevt = (Matrix.Event.RoomHistoryVisibility)evt;
|
||||
|
||||
room.history_visibility = hevt.visibility;
|
||||
} else if (evt is Matrix.Event.RoomJoinRules) {
|
||||
var jevt = (Matrix.Event.RoomJoinRules)evt;
|
||||
|
||||
room.join_rules = jevt.join_rules;
|
||||
} else if (evt is Matrix.Event.RoomName) {
|
||||
var nevt = (Matrix.Event.RoomName)evt;
|
||||
|
||||
room.name = nevt.name;
|
||||
} else if (evt is Matrix.Event.RoomPowerLevels) {
|
||||
var levt = (Matrix.Event.RoomPowerLevels)evt;
|
||||
|
||||
room.default_power_level = levt.users_default;
|
||||
room.default_event_level = levt.events_default;
|
||||
room.default_state_level = levt.state_default;
|
||||
room.ban_level = levt.ban;
|
||||
room.kick_level = levt.kick;
|
||||
room.redact_level = levt.redact;
|
||||
room.invite_level = levt.invite;
|
||||
room.clear_user_levels();
|
||||
room.clear_event_levels();
|
||||
|
||||
levt.user_levels.foreach(
|
||||
(key, value) => {
|
||||
room.set_user_level(key, value);
|
||||
});
|
||||
|
||||
levt.event_levels.foreach(
|
||||
(key, value) => {
|
||||
room.set_event_level(key, value);
|
||||
});
|
||||
} else if (evt is Matrix.Event.RoomTopic) {
|
||||
var tevt = (Matrix.Event.RoomTopic)evt;
|
||||
|
||||
room.topic = tevt.topic;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
incoming_event(room_id, event_node, evt);
|
||||
}
|
||||
|
||||
private Room
|
||||
_get_or_create_room(string room_id)
|
||||
{
|
||||
Room? room = null;
|
||||
|
||||
if ((room = _rooms[room_id]) == null) {
|
||||
room = new Room(room_id);
|
||||
_rooms[room_id] = room;
|
||||
}
|
||||
|
||||
return room;
|
||||
}
|
||||
|
||||
private void
|
||||
_process_event_list_obj(Json.Node node, string? room_id)
|
||||
requires(node.get_node_type() == Json.NodeType.OBJECT)
|
||||
@@ -143,11 +273,17 @@ public class Matrix.HTTPClient : Matrix.HTTPAPI, Matrix.Client {
|
||||
var root_obj = json_content.get_object();
|
||||
Json.Node? node;
|
||||
|
||||
if (Config.DEBUG) {
|
||||
debug("Processing account data");
|
||||
}
|
||||
|
||||
_process_event_list_obj(root_obj.get_member("account_data"),
|
||||
null);
|
||||
|
||||
if (Config.DEBUG) {
|
||||
debug("Processing presence");
|
||||
}
|
||||
|
||||
_process_event_list_obj(root_obj.get_member("presence"),
|
||||
null);
|
||||
|
||||
@@ -156,7 +292,9 @@ public class Matrix.HTTPClient : Matrix.HTTPAPI, Matrix.Client {
|
||||
Json.Object rooms_object = node.get_object();
|
||||
Json.Node rooms_node;
|
||||
|
||||
if (Config.DEBUG) {
|
||||
debug("Processing rooms");
|
||||
}
|
||||
|
||||
if ((rooms_node = rooms_object.get_member(
|
||||
"invite")) != null) {
|
||||
@@ -231,6 +369,26 @@ public class Matrix.HTTPClient : Matrix.HTTPAPI, Matrix.Client {
|
||||
if ((node = root_obj.get_member("next_batch")) != null) {
|
||||
_last_sync_token = node.get_string();
|
||||
}
|
||||
} else if ((error is Matrix.Error.M_FORBIDDEN)
|
||||
|| (error is Matrix.Error.M_UNKNOWN_TOKEN)
|
||||
|| (error is Matrix.Error.M_UNAUTHORIZED)) {
|
||||
try {
|
||||
token = null;
|
||||
|
||||
token_refresh((i, ct, jc, rc, err) => {
|
||||
login_finished((error == null)
|
||||
|| (error is Matrix.Error.NONE));
|
||||
|
||||
if (token == null) {
|
||||
refresh_token = null;
|
||||
polling_stopped(err);
|
||||
|
||||
try {
|
||||
stop_polling(false);
|
||||
} catch (GLib.Error e) {}
|
||||
}
|
||||
} , null);
|
||||
} catch (Matrix.Error e) {}
|
||||
}
|
||||
|
||||
// It is possible that polling has been disabled while we were
|
||||
@@ -242,6 +400,7 @@ public class Matrix.HTTPClient : Matrix.HTTPAPI, Matrix.Client {
|
||||
if ((error == null) || (error.code < 500)) {
|
||||
begin_polling();
|
||||
} else if ((error != null) && error.code >= 500) {
|
||||
polling_stopped(error);
|
||||
stop_polling(false);
|
||||
}
|
||||
} catch (Matrix.Error e) {}
|
||||
@@ -262,6 +421,10 @@ public class Matrix.HTTPClient : Matrix.HTTPAPI, Matrix.Client {
|
||||
throw e;
|
||||
}
|
||||
|
||||
if (_polling == false) {
|
||||
polling_started();
|
||||
}
|
||||
|
||||
_polling = true;
|
||||
}
|
||||
|
||||
@@ -275,4 +438,274 @@ public class Matrix.HTTPClient : Matrix.HTTPAPI, Matrix.Client {
|
||||
abort_pending();
|
||||
}
|
||||
}
|
||||
|
||||
public Profile?
|
||||
get_user_profile(string user_id, string? room_id = null)
|
||||
throws Matrix.Error
|
||||
{
|
||||
if (room_id == null) {
|
||||
var profile = _user_global_profiles[user_id];
|
||||
|
||||
if (profile == null) {
|
||||
throw new Matrix.Error.UNAVAILABLE(
|
||||
"Global profile for %s is not cached yet.",
|
||||
user_id);
|
||||
}
|
||||
|
||||
return profile;
|
||||
}
|
||||
|
||||
var room = _rooms[room_id];
|
||||
|
||||
if (room == null) {
|
||||
throw new Matrix.Error.UNAVAILABLE(
|
||||
"Room data for %s is not cached yet.", room_id);
|
||||
}
|
||||
|
||||
return room.get_member(user_id, null);
|
||||
}
|
||||
|
||||
public Presence
|
||||
get_user_presence(string user_id, string? room_id = null)
|
||||
throws Matrix.Error
|
||||
{
|
||||
if (room_id == null) {
|
||||
Presence? presence = _user_global_presence[user_id];
|
||||
|
||||
if (presence == null) {
|
||||
throw new Matrix.Error.UNAVAILABLE(
|
||||
"Global presence for %s is not cached yet.",
|
||||
user_id);
|
||||
}
|
||||
|
||||
return presence;
|
||||
}
|
||||
|
||||
throw new Matrix.Error.UNSUPPORTED(
|
||||
"Per-room presences are not supported yet.");
|
||||
}
|
||||
|
||||
public Room
|
||||
get_room_by_id(string room_id)
|
||||
throws Matrix.Error
|
||||
{
|
||||
Room? room;
|
||||
|
||||
if ((room = _rooms[room_id]) == null) {
|
||||
throw new Matrix.Error.UNAVAILABLE(
|
||||
"Room data for %s is not cached yet.", room_id);
|
||||
}
|
||||
|
||||
return room;
|
||||
}
|
||||
|
||||
public Room
|
||||
get_room_by_alias(string room_alias)
|
||||
throws Matrix.Error
|
||||
{
|
||||
Room? room_found = _rooms.find(
|
||||
(key, room) => {
|
||||
if (room.canonical_alias == room_alias) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (room_alias in room.aliases) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
});
|
||||
|
||||
if (room_found != null) {
|
||||
return room_found;
|
||||
}
|
||||
|
||||
throw new Matrix.Error.UNAVAILABLE(
|
||||
"Noo room data found for alias %s", room_alias);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the next transaction ID to use. It increments the
|
||||
* internally stored value and returns that, so it is guaranteed
|
||||
* to be unique until we run out of ulong boundaries.
|
||||
*
|
||||
* It is called internally by send().
|
||||
*/
|
||||
public ulong
|
||||
next_txn_id()
|
||||
{
|
||||
return ++_last_txn_id;
|
||||
}
|
||||
|
||||
private void
|
||||
send_callback(Json.Node? json_content,
|
||||
GLib.Error? err,
|
||||
Matrix.Client.SendCallback? cb)
|
||||
{
|
||||
string? event_id = null;
|
||||
GLib.Error? new_err = err;
|
||||
|
||||
// If there is no callback, there is no point to continue
|
||||
if (cb == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (err == null) {
|
||||
var root = json_content.get_object();
|
||||
|
||||
if (root.has_member("event_id")) {
|
||||
event_id = root.get_string_member("event_id");
|
||||
} else {
|
||||
new_err = new Matrix.Error.BAD_RESPONSE(
|
||||
"event_id is missing from an event response");
|
||||
}
|
||||
}
|
||||
|
||||
cb(event_id, new_err);
|
||||
}
|
||||
|
||||
public void
|
||||
send(string room_id,
|
||||
Matrix.Event.Base evt,
|
||||
Matrix.Client.SendCallback? cb,
|
||||
out ulong txn_id)
|
||||
throws Matrix.Error
|
||||
{
|
||||
var evt_node = evt.json;
|
||||
var evt_root = evt_node.get_object();
|
||||
string? state_key = null;
|
||||
|
||||
if (evt_root.has_member("state_key")) {
|
||||
state_key = evt_root.get_string_member("state_key");
|
||||
}
|
||||
|
||||
if (state_key != null) {
|
||||
txn_id = 0;
|
||||
send_state_event(
|
||||
(i, ct, json_node, rc, err) =>
|
||||
send_callback(json_node, err, cb),
|
||||
room_id,
|
||||
evt.event_type,
|
||||
(state_key == "") ? null : state_key,
|
||||
evt_root.get_member("content"));
|
||||
} else {
|
||||
txn_id = next_txn_id();
|
||||
send_event(
|
||||
(i, ct, json_node, rc, err) =>
|
||||
send_callback(json_node, err, cb),
|
||||
room_id,
|
||||
evt.event_type,
|
||||
"%lu".printf(txn_id),
|
||||
evt_root.get_member("content"));
|
||||
}
|
||||
}
|
||||
|
||||
public void
|
||||
save_state(string filename)
|
||||
throws Matrix.Error, GLib.Error
|
||||
{
|
||||
var root = new Json.Object();
|
||||
|
||||
root.set_string_member("base_url", base_url);
|
||||
|
||||
root.set_boolean_member("validate_certificate", validate_certificate);
|
||||
|
||||
if (user_id != null) {
|
||||
root.set_string_member("user_id", user_id);
|
||||
}
|
||||
|
||||
if (homeserver != null) {
|
||||
root.set_string_member("homeserver_name", homeserver);
|
||||
}
|
||||
|
||||
if (token != null) {
|
||||
root.set_string_member("access_token", token);
|
||||
}
|
||||
|
||||
if (refresh_token != null) {
|
||||
root.set_string_member("refresh_token", refresh_token);
|
||||
}
|
||||
|
||||
var node = new Json.Node(Json.NodeType.OBJECT);
|
||||
node.set_object(root);
|
||||
|
||||
if (Config.DEBUG) {
|
||||
debug("Saving state to %s\n", filename);
|
||||
}
|
||||
|
||||
var generator = new Json.Generator();
|
||||
generator.set_root(node);
|
||||
generator.to_file(filename);
|
||||
}
|
||||
|
||||
public void
|
||||
load_state(string filename)
|
||||
throws Matrix.Error, GLib.Error
|
||||
{
|
||||
var parser = new Json.Parser();
|
||||
|
||||
if (Config.DEBUG) {
|
||||
debug("Loading state from %s\n", filename);
|
||||
}
|
||||
|
||||
parser.load_from_file(filename);
|
||||
Json.Node? node = parser.get_root();
|
||||
|
||||
if (node.get_node_type() != Json.NodeType.OBJECT) {
|
||||
throw new Matrix.Error.INVALID_FORMAT(
|
||||
"Save data must be a JSON object.");
|
||||
}
|
||||
|
||||
var root = node.get_object();
|
||||
|
||||
if ((node = root.get_member("base_url")) == null) {
|
||||
throw new Matrix.Error.INVALID_FORMAT(
|
||||
"Save data has no base_url key");
|
||||
}
|
||||
|
||||
base_url = node.get_string();
|
||||
|
||||
if (Config.DEBUG) {
|
||||
debug("Loaded base URL %s", base_url);
|
||||
}
|
||||
|
||||
if ((node = root.get_member("validate_certificate")) == null) {
|
||||
throw new Matrix.Error.INVALID_FORMAT(
|
||||
"Save data has no validate_certificate key");
|
||||
}
|
||||
|
||||
validate_certificate = node.get_boolean();
|
||||
|
||||
if ((node = root.get_member("user_id")) != null) {
|
||||
_user_id = node.get_string();
|
||||
|
||||
if (Config.DEBUG) {
|
||||
debug("Loaded user ID %s", user_id);
|
||||
}
|
||||
}
|
||||
|
||||
if ((node = root.get_member("homeserver_name")) != null) {
|
||||
_homeserver = node.get_string();
|
||||
|
||||
if (Config.DEBUG) {
|
||||
debug("Loaded homeserver name %s", homeserver);
|
||||
}
|
||||
}
|
||||
|
||||
if ((node = root.get_member("access_token")) != null) {
|
||||
token = node.get_string();
|
||||
|
||||
if (Config.DEBUG) {
|
||||
debug("Loaded access token %s", token);
|
||||
}
|
||||
}
|
||||
|
||||
if ((node = root.get_member("refresh_token")) != null) {
|
||||
refresh_token = node.get_string();
|
||||
|
||||
if (Config.DEBUG) {
|
||||
debug("Loaded refresh token %s", refresh_token);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
75
src/matrix-message-audio.vala
Normal file
75
src/matrix-message-audio.vala
Normal file
@@ -0,0 +1,75 @@
|
||||
/*
|
||||
* This file is part of matrix-glib-sdk
|
||||
*
|
||||
* matrix-glib-sdk is free software: you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation, either
|
||||
* version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* matrix-glib-sdk is distributed in the hope that it will be
|
||||
* useful, but WITHOUT ANY WARRANTY; without even the implied
|
||||
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
* See the GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with matrix-glib-sdk. If not, see
|
||||
* <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Class to hold a m.audio message
|
||||
*
|
||||
* This message represents a single audio clip.
|
||||
*/
|
||||
public class Matrix.Message.Audio : Matrix.Message.Base {
|
||||
/**
|
||||
* The URL to the audio clip.
|
||||
*/
|
||||
public string? url { get; set; default = null; }
|
||||
|
||||
/**
|
||||
* Metadata for the audio clip referred to in `url`.
|
||||
*/
|
||||
public AudioInfo? info { get; set; default = null; }
|
||||
|
||||
protected override void
|
||||
from_json(Json.Node json_data)
|
||||
throws Matrix.Error
|
||||
{
|
||||
var root = json_data.get_object();
|
||||
Json.Node? node;
|
||||
|
||||
if ((node = root.get_member("url")) != null) {
|
||||
_url = node.get_string();
|
||||
} else if (Config.DEBUG) {
|
||||
warning("url is missing from a m.audio message");
|
||||
}
|
||||
|
||||
if ((node = root.get_member("info")) != null) {
|
||||
_info = AudioInfo();
|
||||
_info.set_from_json(node);
|
||||
}
|
||||
|
||||
base.from_json(json_data);
|
||||
}
|
||||
|
||||
protected override void
|
||||
to_json(Json.Node json_data)
|
||||
throws Matrix.Error
|
||||
{
|
||||
if (_url == null) {
|
||||
throw new Matrix.Error.INCOMPLETE(
|
||||
"Won't generate a m.audio message without url");
|
||||
}
|
||||
|
||||
var root = json_data.get_object();
|
||||
|
||||
root.set_string_member("url", _url);
|
||||
|
||||
if (_info != null) {
|
||||
root.set_member("info", _info.get_json_node());
|
||||
}
|
||||
|
||||
base.to_json(json_data);
|
||||
}
|
||||
}
|
234
src/matrix-message-base.vala
Normal file
234
src/matrix-message-base.vala
Normal file
@@ -0,0 +1,234 @@
|
||||
/*
|
||||
* This file is part of matrix-glib-sdk
|
||||
*
|
||||
* matrix-glib-sdk is free software: you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation, either
|
||||
* version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* matrix-glib-sdk is distributed in the hope that it will be
|
||||
* useful, but WITHOUT ANY WARRANTY; without even the implied
|
||||
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
* See the GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with matrix-glib-sdk. If not, see
|
||||
* <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Base class for message handlers.
|
||||
*
|
||||
* Message handler base class.
|
||||
*/
|
||||
public abstract class Matrix.Message.Base : Object, Initable {
|
||||
/**
|
||||
* The message type.
|
||||
*/
|
||||
public string? message_type { get; set; default = null; }
|
||||
|
||||
/**
|
||||
* The body of the message.
|
||||
*/
|
||||
public string? body { get; set; default = null; }
|
||||
|
||||
public Json.Node? json {
|
||||
get {
|
||||
_json = new Json.Node(Json.NodeType.OBJECT);
|
||||
_json.set_object(new Json.Object());
|
||||
|
||||
try {
|
||||
to_json(_json);
|
||||
} catch (Matrix.Error e) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return _json;
|
||||
}
|
||||
|
||||
construct {
|
||||
if (value != null) {
|
||||
try {
|
||||
initialize_from_json(value);
|
||||
} catch (Matrix.Error e) {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private bool _inited = false;
|
||||
private Error? _construct_error = null;
|
||||
private Json.Node? _json = null;
|
||||
|
||||
public bool
|
||||
init(Cancellable? cancellable = null)
|
||||
throws GLib.Error
|
||||
{
|
||||
if (cancellable != null) {
|
||||
throw new Matrix.Error.UNSUPPORTED(
|
||||
"Cancellable initialization not supported");
|
||||
}
|
||||
|
||||
if (_construct_error != null) {
|
||||
throw _construct_error;
|
||||
}
|
||||
|
||||
_inited = true;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private void
|
||||
initialize_from_json(Json.Node json_data)
|
||||
throws Matrix.Error
|
||||
{
|
||||
var gen = new Json.Generator();
|
||||
gen.set_root(json_data);
|
||||
|
||||
if (json_data.get_node_type() != Json.NodeType.OBJECT) {
|
||||
throw new Matrix.Error.INVALID_FORMAT(
|
||||
"The message is not valid");
|
||||
}
|
||||
|
||||
from_json(json_data);
|
||||
}
|
||||
|
||||
public static Matrix.Message.Base?
|
||||
new_from_json(Json.Node json_data)
|
||||
throws Matrix.Error, GLib.Error
|
||||
{
|
||||
var root = json_data.get_object();
|
||||
Json.Node? node;
|
||||
|
||||
if ((node = root.get_member("msgtype")) == null) {
|
||||
throw new Matrix.Error.INCOMPLETE(
|
||||
"Can not process a message without msgtype");
|
||||
}
|
||||
|
||||
Type? msg_gtype;
|
||||
|
||||
if ((msg_gtype = get_handler(node.get_string())) == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
var ret = (Base)Object.new(msg_gtype,
|
||||
json : json_data);
|
||||
|
||||
ret.init();
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Subclasses should override this method to initialize themselves
|
||||
* from JSON data while chaining up to allow parent classes to do
|
||||
* the same.
|
||||
*/
|
||||
public virtual void
|
||||
from_json(Json.Node json_data)
|
||||
throws Matrix.Error
|
||||
{
|
||||
var root = json_data.get_object();
|
||||
Json.Node? node;
|
||||
|
||||
if ((node = root.get_member("msgtype")) != null) {
|
||||
_message_type = node.get_string();
|
||||
} else if (Config.DEBUG) {
|
||||
warning("msgtype is not present in a message");
|
||||
}
|
||||
|
||||
if ((node = root.get_member("body")) != null) {
|
||||
_body = node.get_string();
|
||||
} else if (Config.DEBUG) {
|
||||
warning("body is not presente in a message");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Subclasses should override this method to export their data to
|
||||
* JSON, while chaining up to allow parent classes to do the same.
|
||||
*/
|
||||
public virtual void
|
||||
to_json(Json.Node json_data)
|
||||
throws Matrix.Error
|
||||
{
|
||||
var root = json_data.get_object();
|
||||
|
||||
if (_message_type == null) {
|
||||
throw new Matrix.Error.INCOMPLETE(
|
||||
"Won't generate a message with an empty msgtype");
|
||||
}
|
||||
|
||||
if (_body == null) {
|
||||
throw new Matrix.Error.INCOMPLETE(
|
||||
"Won't generate a message without body");
|
||||
}
|
||||
|
||||
root.set_string_member("msgtype", _message_type);
|
||||
}
|
||||
}
|
||||
|
||||
namespace Matrix.Message {
|
||||
|
||||
private HashTable<string, TypeClass>? type_handlers = null;
|
||||
|
||||
/**
|
||||
* Get the {@link GLib.Type} of the class that is registered to handle
|
||||
* messages with type @param message_type.
|
||||
*
|
||||
* @param message_type the message type to look up
|
||||
* @return a {@link GLib.Type} or `null` if no handler is registered
|
||||
*/
|
||||
public static GLib.Type?
|
||||
get_handler(string message_type)
|
||||
{
|
||||
unowned GLib.TypeClass? klass = null;
|
||||
|
||||
if ((type_handlers != null)
|
||||
&& ((klass = type_handlers.get(message_type)) != null)) {
|
||||
return klass.get_type();
|
||||
}
|
||||
|
||||
if (Config.DEBUG) {
|
||||
warning("No registered type for message %s", message_type);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Register @param message_type to be handled by the
|
||||
* type @param message_gtype.
|
||||
*
|
||||
* @param message_type the type of the message
|
||||
* @param message_gtype the {@link GLib.Type} of the event's handler
|
||||
*/
|
||||
public static void
|
||||
register_type(string message_type, GLib.Type message_gtype)
|
||||
throws Matrix.Error
|
||||
{
|
||||
if (!message_gtype.is_a(typeof(Matrix.Message.Base))) {
|
||||
throw new Matrix.Error.INVALID_TYPE(
|
||||
"Invalid message handler type");
|
||||
}
|
||||
|
||||
if (type_handlers == null) {
|
||||
type_handlers = new HashTable<string, GLib.TypeClass>(
|
||||
str_hash, str_equal);
|
||||
}
|
||||
|
||||
type_handlers.replace(message_type, message_gtype.class_ref());
|
||||
}
|
||||
|
||||
/**
|
||||
* Unregister @param message_type.
|
||||
*
|
||||
* @param message_type the message type to remove
|
||||
*/
|
||||
public void
|
||||
unregister_type(string message_type)
|
||||
{
|
||||
if (type_handlers != null) {
|
||||
type_handlers.remove(message_type);
|
||||
}
|
||||
}
|
||||
}
|
42
src/matrix-message-emote.vala
Normal file
42
src/matrix-message-emote.vala
Normal file
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
* This file is part of matrix-glib-sdk
|
||||
*
|
||||
* matrix-glib-sdk is free software: you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation, either
|
||||
* version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* matrix-glib-sdk is distributed in the hope that it will be
|
||||
* useful, but WITHOUT ANY WARRANTY; without even the implied
|
||||
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
* See the GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with matrix-glib-sdk. If not, see
|
||||
* <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/**
|
||||
* The emote message type
|
||||
*
|
||||
* This message is similar to `m.text` except that the sender is
|
||||
* 'performing' the action contained in the `body` key, similar to
|
||||
* `/me` in IRC. This message should be prefixed by the name of the
|
||||
* sender. This message could also be represented in a different
|
||||
* colour to distinguish it from regular `m.text` messages.
|
||||
*/
|
||||
public class Matrix.Message.Emote : Matrix.Message.Base {
|
||||
public override void
|
||||
from_json(Json.Node json_data)
|
||||
throws Matrix.Error
|
||||
{
|
||||
base.from_json(json_data);
|
||||
}
|
||||
|
||||
public override void
|
||||
to_json(Json.Node json_data)
|
||||
throws Matrix.Error
|
||||
{
|
||||
base.to_json(json_data);
|
||||
}
|
||||
}
|
113
src/matrix-message-file.vala
Normal file
113
src/matrix-message-file.vala
Normal file
@@ -0,0 +1,113 @@
|
||||
/*
|
||||
* This file is part of matrix-glib-sdk
|
||||
*
|
||||
* matrix-glib-sdk is free software: you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation, either
|
||||
* version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* matrix-glib-sdk is distributed in the hope that it will be
|
||||
* useful, but WITHOUT ANY WARRANTY; without even the implied
|
||||
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
* See the GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with matrix-glib-sdk. If not, see
|
||||
* <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Class to hold a m.file message
|
||||
*
|
||||
* This message represents a generic file.
|
||||
*/
|
||||
public class Matrix.Message.File : Matrix.Message.Base {
|
||||
/**
|
||||
* The original filename of the uploaded file.
|
||||
*/
|
||||
public string? filename { get; set; default = null; }
|
||||
|
||||
/**
|
||||
* The URL of the file.
|
||||
*/
|
||||
public string? url { get; set; default = null; }
|
||||
|
||||
/**
|
||||
* Information about the file referred to in ``url``.
|
||||
*/
|
||||
public FileInfo? info { get; set; default = null; }
|
||||
|
||||
/**
|
||||
* The URL of the thumbnail of the file.
|
||||
*/
|
||||
public string? thumbnail_url {get; set; default = null; }
|
||||
|
||||
/**
|
||||
* Metadata about the image referred to in `thumbnail_url`.
|
||||
*/
|
||||
public ImageInfo? thumbnail_info { get; set; default = null; }
|
||||
|
||||
protected override void
|
||||
from_json(Json.Node json_data)
|
||||
throws Matrix.Error
|
||||
{
|
||||
var root = json_data.get_object();
|
||||
Json.Node? node;
|
||||
|
||||
if ((node = root.get_member("url")) != null) {
|
||||
_url = node.get_string();
|
||||
} else if (Config.DEBUG) {
|
||||
warning("url is missing from a m.file message");
|
||||
}
|
||||
|
||||
if ((node = root.get_member("info")) != null) {
|
||||
_info = FileInfo();
|
||||
|
||||
_info.set_from_json(node);
|
||||
} else if (Config.DEBUG) {
|
||||
warning("info is missing from a m.file message");
|
||||
}
|
||||
|
||||
if ((node = root.get_member("thumbnail_url")) != null) {
|
||||
_thumbnail_url = node.get_string();
|
||||
}
|
||||
|
||||
if ((node = root.get_member("thumbnail_info")) != null) {
|
||||
_thumbnail_info = ImageInfo();
|
||||
|
||||
_thumbnail_info.set_from_json(node);
|
||||
}
|
||||
|
||||
base.from_json(json_data);
|
||||
}
|
||||
|
||||
protected override void
|
||||
to_json(Json.Node json_data)
|
||||
throws Matrix.Error
|
||||
{
|
||||
if (_url == null) {
|
||||
throw new Matrix.Error.INCOMPLETE(
|
||||
"Won't generate a m.file message without the URL");
|
||||
}
|
||||
|
||||
if (_info == null) {
|
||||
throw new Matrix.Error.INCOMPLETE(
|
||||
"Won't generate a m.file message without the file info.");
|
||||
}
|
||||
|
||||
var root = json_data.get_object();
|
||||
|
||||
root.set_string_member("url", _url);
|
||||
root.set_member("info", _info.get_json_node());
|
||||
|
||||
if (_thumbnail_url != null) {
|
||||
root.set_string_member("thumbnail_url", _thumbnail_url);
|
||||
}
|
||||
|
||||
if (_thumbnail_info != null) {
|
||||
root.set_member("thumbnail_info", _thumbnail_info.get_json_node());
|
||||
}
|
||||
|
||||
base.to_json(json_data);
|
||||
}
|
||||
}
|
102
src/matrix-message-image.vala
Normal file
102
src/matrix-message-image.vala
Normal file
@@ -0,0 +1,102 @@
|
||||
/*
|
||||
* This file is part of matrix-glib-sdk
|
||||
*
|
||||
* matrix-glib-sdk is free software: you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation, either
|
||||
* version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* matrix-glib-sdk is distributed in the hope that it will be
|
||||
* useful, but WITHOUT ANY WARRANTY; without even the implied
|
||||
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
* See the GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with matrix-glib-sdk. If not, see
|
||||
* <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Class to hold a m.image message
|
||||
*
|
||||
* This message represents a single image and an optional thumbnail.
|
||||
*/
|
||||
public class Matrix.Message.Image : Matrix.Message.Base {
|
||||
/**
|
||||
* The URL to the image.
|
||||
*/
|
||||
public string? url { get; set; default = null; }
|
||||
|
||||
/**
|
||||
* The URL to the thumbnail of the image.
|
||||
*/
|
||||
public string? thumbnail_url { get; set; default = null; }
|
||||
|
||||
/**
|
||||
* Metadata about the image referred to in `url`.
|
||||
*/
|
||||
public ImageInfo? info { get; set; default = null; }
|
||||
|
||||
/**
|
||||
* Metadata about the image referred to in `thumbnail_url`.
|
||||
*/
|
||||
public ImageInfo? thumbnail_info { get; set; default = null; }
|
||||
|
||||
protected override void
|
||||
from_json(Json.Node json_data)
|
||||
throws Matrix.Error
|
||||
{
|
||||
var root = json_data.get_object();
|
||||
Json.Node? node;
|
||||
|
||||
if ((node = root.get_member("url")) != null) {
|
||||
_url = node.get_string();
|
||||
} else if (Config.DEBUG) {
|
||||
warning("url is missing from a m.image message");
|
||||
}
|
||||
|
||||
if ((node = root.get_member("info")) != null) {
|
||||
_info = ImageInfo();
|
||||
_info.set_from_json(node);
|
||||
}
|
||||
|
||||
if ((node = root.get_member("thumbnail_url")) != null) {
|
||||
_thumbnail_url = node.get_string();
|
||||
}
|
||||
|
||||
if ((node = root.get_member("thumbnail_info")) != null) {
|
||||
_thumbnail_info = ImageInfo();
|
||||
_thumbnail_info.set_from_json(node);
|
||||
}
|
||||
|
||||
base.from_json(json_data);
|
||||
}
|
||||
|
||||
protected override void
|
||||
to_json(Json.Node json_data)
|
||||
throws Matrix.Error
|
||||
{
|
||||
if (_url == null) {
|
||||
throw new Matrix.Error.INCOMPLETE(
|
||||
"Won't generate a m.image message without url");
|
||||
}
|
||||
|
||||
var root = json_data.get_object();
|
||||
|
||||
root.set_string_member("url", _url);
|
||||
|
||||
if (_info != null) {
|
||||
root.set_member("info", _info.get_json_node());
|
||||
}
|
||||
|
||||
if (_thumbnail_url != null) {
|
||||
root.set_string_member("thumbnail_url", _thumbnail_url);
|
||||
}
|
||||
|
||||
if (_thumbnail_info != null) {
|
||||
root.set_member("thumbnail_info", _thumbnail_info.get_json_node());
|
||||
}
|
||||
|
||||
base.to_json(json_data);
|
||||
}
|
||||
}
|
86
src/matrix-message-location.vala
Normal file
86
src/matrix-message-location.vala
Normal file
@@ -0,0 +1,86 @@
|
||||
/*
|
||||
* This file is part of matrix-glib-sdk
|
||||
*
|
||||
* matrix-glib-sdk is free software: you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation, either
|
||||
* version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* matrix-glib-sdk is distributed in the hope that it will be
|
||||
* useful, but WITHOUT ANY WARRANTY; without even the implied
|
||||
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
* See the GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with matrix-glib-sdk. If not, see
|
||||
* <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/**
|
||||
* This message represents a real-world location.
|
||||
*/
|
||||
public class Matrix.Message.Location : Matrix.Message.Base {
|
||||
/**
|
||||
* A geo URI representing this location.
|
||||
*/
|
||||
public string? geo_uri { get; set; default = null; }
|
||||
|
||||
/**
|
||||
* The URL to a thumbnail of the location being represented.
|
||||
*/
|
||||
public string? thumbnail_url { get; set; default = null; }
|
||||
|
||||
/**
|
||||
* Metadata about the location referred to in `thumbnail_url`.
|
||||
*/
|
||||
public ImageInfo? thumbnail_info { get; set; default = null; }
|
||||
|
||||
protected override void
|
||||
from_json(Json.Node json_data)
|
||||
throws Matrix.Error
|
||||
{
|
||||
var root = json_data.get_object();
|
||||
Json.Node? node;
|
||||
|
||||
if ((node = root.get_member("geo_uri")) != null) {
|
||||
_geo_uri = node.get_string();
|
||||
} else if (Config.DEBUG) {
|
||||
warning("geo_uri is missing from a m.location message");
|
||||
}
|
||||
|
||||
if ((node = root.get_member("thumbnail_url")) != null) {
|
||||
_thumbnail_url = node.get_string();
|
||||
}
|
||||
|
||||
if ((node = root.get_member("thumbnail_info")) != null) {
|
||||
_thumbnail_info = ImageInfo();
|
||||
_thumbnail_info.set_from_json(node);
|
||||
}
|
||||
|
||||
base.from_json(json_data);
|
||||
}
|
||||
|
||||
protected override void
|
||||
to_json(Json.Node json_data)
|
||||
throws Matrix.Error
|
||||
{
|
||||
if (_geo_uri == null) {
|
||||
throw new Matrix.Error.INCOMPLETE(
|
||||
"Won't generate a m.location message without geo_uri");
|
||||
}
|
||||
|
||||
var root = json_data.get_object();
|
||||
|
||||
root.set_string_member("geo_uri", _geo_uri);
|
||||
|
||||
if (_thumbnail_url != null) {
|
||||
root.set_string_member("thumbnail_url", _thumbnail_url);
|
||||
}
|
||||
|
||||
if (_thumbnail_info != null) {
|
||||
root.set_member("thumbnail_info", _thumbnail_info.get_json_node());
|
||||
}
|
||||
|
||||
base.to_json(json_data);
|
||||
}
|
||||
}
|
45
src/matrix-message-notice.vala
Normal file
45
src/matrix-message-notice.vala
Normal file
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
* This file is part of matrix-glib-sdk
|
||||
*
|
||||
* matrix-glib-sdk is free software: you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation, either
|
||||
* version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* matrix-glib-sdk is distributed in the hope that it will be
|
||||
* useful, but WITHOUT ANY WARRANTY; without even the implied
|
||||
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
* See the GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with matrix-glib-sdk. If not, see
|
||||
* <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Message type to hold a m.notice message
|
||||
*
|
||||
* A m.notice message should be considered similar to a plain m.text
|
||||
* message except that clients should visually distinguish it in some
|
||||
* way. It is intended to be used by automated clients, such as bots,
|
||||
* bridges, and other entities, rather than humans. Additionally, such
|
||||
* automated agents which watch a room for messages and respond to
|
||||
* them ought to ignore m.notice messages. This helps to prevent
|
||||
* infinite-loop situations where two automated clients continuously
|
||||
* exchange messages, as each responds to the other.
|
||||
*/
|
||||
public class Matrix.Message.Notice : Matrix.Message.Base {
|
||||
public override void
|
||||
from_json(Json.Node json_data)
|
||||
throws Matrix.Error
|
||||
{
|
||||
base.from_json(json_data);
|
||||
}
|
||||
|
||||
public override void
|
||||
to_json(Json.Node json_data)
|
||||
throws Matrix.Error
|
||||
{
|
||||
base.to_json(json_data);
|
||||
}
|
||||
}
|
38
src/matrix-message-text.vala
Normal file
38
src/matrix-message-text.vala
Normal file
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
* This file is part of matrix-glib-sdk
|
||||
*
|
||||
* matrix-glib-sdk is free software: you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation, either
|
||||
* version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* matrix-glib-sdk is distributed in the hope that it will be
|
||||
* useful, but WITHOUT ANY WARRANTY; without even the implied
|
||||
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
* See the GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with matrix-glib-sdk. If not, see
|
||||
* <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Message handler for plain text messages
|
||||
*
|
||||
* Handle plain text messages.
|
||||
*/
|
||||
public class Matrix.Message.Text : Matrix.Message.Base {
|
||||
public override void
|
||||
from_json(Json.Node json_data)
|
||||
throws Matrix.Error
|
||||
{
|
||||
base.from_json(json_data);
|
||||
}
|
||||
|
||||
public override void
|
||||
to_json(Json.Node json_data)
|
||||
throws Matrix.Error
|
||||
{
|
||||
base.to_json(json_data);
|
||||
}
|
||||
}
|
73
src/matrix-message-video.vala
Normal file
73
src/matrix-message-video.vala
Normal file
@@ -0,0 +1,73 @@
|
||||
/*
|
||||
* This file is part of matrix-glib-sdk
|
||||
*
|
||||
* matrix-glib-sdk is free software: you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation, either
|
||||
* version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* matrix-glib-sdk is distributed in the hope that it will be
|
||||
* useful, but WITHOUT ANY WARRANTY; without even the implied
|
||||
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
* See the GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with matrix-glib-sdk. If not, see
|
||||
* <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/**
|
||||
* This message represents a single video clip.
|
||||
*/
|
||||
public class Matrix.Message.Video : Matrix.Message.Base {
|
||||
/**
|
||||
* The URL to the video clip.
|
||||
*/
|
||||
public string? url { get; set; default = null; }
|
||||
|
||||
/**
|
||||
* Metadata about the video clip referred to in `url`.
|
||||
*/
|
||||
public VideoInfo? info { get; set; default = null; }
|
||||
|
||||
protected override void
|
||||
from_json(Json.Node json_data)
|
||||
throws Matrix.Error
|
||||
{
|
||||
var root = json_data.get_object();
|
||||
Json.Node? node;
|
||||
|
||||
if ((node = root.get_member("url")) != null) {
|
||||
_url = node.get_string();
|
||||
} else if (Config.DEBUG) {
|
||||
warning("url is missing from a m.video message");
|
||||
}
|
||||
|
||||
if ((node = root.get_member("info")) != null) {
|
||||
_info = VideoInfo();
|
||||
_info.set_from_json(node);
|
||||
}
|
||||
|
||||
base.from_json(json_data);
|
||||
}
|
||||
|
||||
protected override void
|
||||
to_json(Json.Node json_data)
|
||||
throws Matrix.Error
|
||||
{
|
||||
if (_url == null) {
|
||||
throw new Matrix.Error.INCOMPLETE(
|
||||
"Won't generate a m.video message without url");
|
||||
}
|
||||
|
||||
var root = json_data.get_object();
|
||||
|
||||
root.set_string_member("url", _url);
|
||||
|
||||
if (_info != null) {
|
||||
root.set_member("info", _info.get_json_node());
|
||||
}
|
||||
|
||||
base.to_json(json_data);
|
||||
}
|
||||
}
|
@@ -1,121 +0,0 @@
|
||||
/*
|
||||
* This file is part of matrix-glib-sdk
|
||||
*
|
||||
* matrix-glib-sdk is free software: you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation, either
|
||||
* version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* matrix-glib-sdk is distributed in the hope that it will be
|
||||
* useful, but WITHOUT ANY WARRANTY; without even the implied
|
||||
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
* See the GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with matrix-glib-sdk. If not, see
|
||||
* <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Class for representing presence events
|
||||
*
|
||||
* The presence event class.
|
||||
*/
|
||||
public class Matrix.PresenceEvent : Matrix.Event {
|
||||
public string? avatar_url { get; set; }
|
||||
public string? display_name { get; set; }
|
||||
public ulong? last_active_ago { get; set; }
|
||||
public Matrix.Presence presence {
|
||||
get;
|
||||
set;
|
||||
default = Matrix.Presence.UNKNOWN;
|
||||
}
|
||||
|
||||
protected override void
|
||||
from_json(Json.Node json_data)
|
||||
throws Matrix.Error
|
||||
{
|
||||
Json.Object content_root = json_data.get_object().get_member("content").get_object();
|
||||
Json.Node? node;
|
||||
|
||||
if ((node = content_root.get_member("user_id")) != null) {
|
||||
_sender = node.get_string();
|
||||
} else {
|
||||
GLib.warning("user_id is missing from the m.presence event");
|
||||
}
|
||||
|
||||
if ((node = content_root.get_member("last_active_ago")) != null) {
|
||||
_last_active_ago = (ulong)node.get_int();
|
||||
} else {
|
||||
_last_active_ago = null;
|
||||
}
|
||||
|
||||
if ((node = content_root.get_member("avatar_url")) != null) {
|
||||
_avatar_url = node.get_string();
|
||||
}
|
||||
|
||||
if ((node = content_root.get_member("displayname")) != null) {
|
||||
_display_name = node.get_string();
|
||||
}
|
||||
|
||||
if ((node = content_root.get_member("presence")) != null) {
|
||||
Matrix.Presence? pres = (Matrix.Presence?)_g_enum_nick_to_value(
|
||||
typeof(Matrix.Presence), node.get_string());
|
||||
|
||||
if (pres != null) {
|
||||
_presence = pres;
|
||||
} else {
|
||||
_presence = Matrix.Presence.UNKNOWN;
|
||||
}
|
||||
} else {
|
||||
GLib.warning("presence is missing from the m.presence event");
|
||||
}
|
||||
|
||||
base.from_json(json_data);
|
||||
}
|
||||
|
||||
protected override void
|
||||
to_json(Json.Node json_data)
|
||||
throws Matrix.Error
|
||||
{
|
||||
Json.Object content_root;
|
||||
string? pres;
|
||||
|
||||
if (presence == Matrix.Presence.UNKNOWN) {
|
||||
throw new Matrix.Error.UNKNOWN_VALUE (
|
||||
"unkwnown presence cannot be added to a presence event");
|
||||
}
|
||||
|
||||
if (sender == null) {
|
||||
throw new Matrix.Error.INCOMPLETE (
|
||||
"sender must be set for presence events!");
|
||||
}
|
||||
|
||||
content_root = _json_object_node_ensure_field(json_data,
|
||||
"content",
|
||||
Json.NodeType.OBJECT)
|
||||
.get_object();
|
||||
|
||||
content_root.set_string_member("user_id", sender);
|
||||
|
||||
if (last_active_ago != null) {
|
||||
content_root.set_int_member("last_active_ago", last_active_ago);
|
||||
}
|
||||
|
||||
if (avatar_url != null) {
|
||||
content_root.set_string_member("avatar_url", avatar_url);
|
||||
}
|
||||
|
||||
if (display_name != null) {
|
||||
content_root.set_string_member("displayname", display_name);
|
||||
}
|
||||
|
||||
pres = _g_enum_value_to_nick(typeof(Matrix.Presence), presence);
|
||||
|
||||
if (pres != null) {
|
||||
content_root.set_string_member("presence", pres);
|
||||
}
|
||||
|
||||
base.to_json(json_data);
|
||||
}
|
||||
}
|
315
src/matrix-profile.c
Normal file
315
src/matrix-profile.c
Normal file
@@ -0,0 +1,315 @@
|
||||
/*
|
||||
* This file is part of matrix-glib-sdk
|
||||
*
|
||||
* matrix-glib-sdk is free software: you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation, either
|
||||
* version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* matrix-glib-sdk is distributed in the hope that it will be
|
||||
* useful, but WITHOUT ANY WARRANTY; without even the implied
|
||||
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
* See the GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with matrix-glib-sdk. If not, see
|
||||
* <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "matrix-profile.h"
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
// List of object properties
|
||||
enum {
|
||||
PROP_NONE,
|
||||
PROP_AGE,
|
||||
PROP_DISPLAY_NAME,
|
||||
PROP_AVATAR_URL,
|
||||
NUM_PROPERTIES
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
GDateTime* last_update;
|
||||
gchar* display_name;
|
||||
gchar* _avatar_url;
|
||||
} MatrixProfilePrivate;
|
||||
|
||||
G_DEFINE_TYPE(MatrixProfile, matrix_profile, G_TYPE_OBJECT);
|
||||
|
||||
static GParamSpec* matrix_profile_properties[NUM_PROPERTIES];
|
||||
|
||||
/**
|
||||
* matrix_profile_new:
|
||||
*
|
||||
* Create a new #MatrixProfile object.
|
||||
*
|
||||
* Returns: (transfer full): a new #MatrixProfile object
|
||||
*/
|
||||
MatrixProfile *
|
||||
matrix_profile_new (void)
|
||||
{
|
||||
return (MatrixProfile *)g_object_new(MATRIX_TYPE_PROFILE, NULL);
|
||||
}
|
||||
|
||||
/**
|
||||
* matrix_profile_get_age:
|
||||
* @profile: a #MatrixProfile
|
||||
*
|
||||
* Get the age of the profile.
|
||||
*
|
||||
* Returns: the profile age, in seconds
|
||||
*/
|
||||
GTimeSpan
|
||||
matrix_profile_get_age (MatrixProfile *matrix_profile)
|
||||
{
|
||||
GTimeSpan result;
|
||||
GDateTime* utcnow;
|
||||
MatrixProfilePrivate *priv = matrix_profile_get_instance_private(matrix_profile);
|
||||
|
||||
if (G_UNLIKELY(matrix_profile == NULL)) {
|
||||
return (GTimeSpan)0;
|
||||
}
|
||||
|
||||
utcnow = g_date_time_new_now_utc ();
|
||||
result = g_date_time_difference (utcnow, priv->last_update);
|
||||
g_date_time_unref(utcnow);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* matrix_profile_get_display_name:
|
||||
* @profile: a #MatrixProfile
|
||||
*
|
||||
* Get the display name from @profile.
|
||||
*
|
||||
* The returned value is owned by @profile and should not be modified.
|
||||
*
|
||||
* Returns: (transfer none) (nullable): a display name
|
||||
*/
|
||||
const gchar*
|
||||
matrix_profile_get_display_name (MatrixProfile *matrix_profile)
|
||||
{
|
||||
MatrixProfilePrivate *priv = matrix_profile_get_instance_private(matrix_profile);
|
||||
|
||||
if (G_UNLIKELY(matrix_profile == NULL)) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return priv->display_name;
|
||||
}
|
||||
|
||||
/**
|
||||
* matrix_profile_set_display_name:
|
||||
* @profile: a #MatrixProfile
|
||||
* @display_name: (transfer none) (nullable): a display name
|
||||
*
|
||||
* Set the display name in @profile.
|
||||
*/
|
||||
void
|
||||
matrix_profile_set_display_name (MatrixProfile *matrix_profile, const gchar* display_name)
|
||||
{
|
||||
MatrixProfilePrivate *priv = matrix_profile_get_instance_private(matrix_profile);
|
||||
|
||||
if (G_UNLIKELY(matrix_profile == NULL)) {
|
||||
return;
|
||||
}
|
||||
|
||||
g_free(priv->display_name);
|
||||
priv->display_name = g_strdup (display_name);
|
||||
|
||||
g_date_time_unref(priv->last_update);
|
||||
priv->last_update = g_date_time_new_now_utc ();
|
||||
|
||||
g_object_notify_by_pspec((GObject *)matrix_profile,
|
||||
matrix_profile_properties[PROP_DISPLAY_NAME]);
|
||||
}
|
||||
|
||||
/**
|
||||
* matrix_profile_get_avatar_url:
|
||||
* @profile: a #MatrixProfile
|
||||
*
|
||||
* Get the avatar URL from @profile.
|
||||
*
|
||||
* The returned value is owned by @profile and should not be freed.
|
||||
*
|
||||
* Returns: (transfer none) (nullable): an avatar URL
|
||||
*/
|
||||
const gchar *
|
||||
matrix_profile_get_avatar_url (MatrixProfile *matrix_profile)
|
||||
{
|
||||
MatrixProfilePrivate *priv = matrix_profile_get_instance_private(matrix_profile);
|
||||
|
||||
if (G_UNLIKELY(matrix_profile == NULL)) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return priv->_avatar_url;
|
||||
}
|
||||
|
||||
/**
|
||||
* matrix_profile_set_avatar_url:
|
||||
* @profile: a #MatrixProfile
|
||||
* @avatar_url: (transfer none) (nullable): the URL to the avatar
|
||||
*
|
||||
* Set the avatar URL in @profile.
|
||||
*/
|
||||
void
|
||||
matrix_profile_set_avatar_url (MatrixProfile *matrix_profile, const gchar* avatar_url)
|
||||
{
|
||||
MatrixProfilePrivate *priv = matrix_profile_get_instance_private(matrix_profile);
|
||||
|
||||
if (G_UNLIKELY(matrix_profile == NULL)) {
|
||||
return;
|
||||
}
|
||||
|
||||
g_free(priv->_avatar_url);
|
||||
priv->_avatar_url = g_strdup (avatar_url);
|
||||
|
||||
g_date_time_unref(priv->last_update);
|
||||
priv->last_update = g_date_time_new_now_utc ();
|
||||
|
||||
g_object_notify_by_pspec ((GObject *)matrix_profile,
|
||||
matrix_profile_properties[PROP_AVATAR_URL]);
|
||||
}
|
||||
|
||||
static void
|
||||
matrix_profile_finalize(GObject *gobject)
|
||||
{
|
||||
MatrixProfile *matrix_profile;
|
||||
MatrixProfilePrivate *priv;
|
||||
|
||||
matrix_profile = G_TYPE_CHECK_INSTANCE_CAST(gobject, MATRIX_TYPE_PROFILE, MatrixProfile);
|
||||
priv = matrix_profile_get_instance_private(matrix_profile);
|
||||
|
||||
g_date_time_unref(priv->last_update);
|
||||
g_free(priv->display_name);
|
||||
g_free(priv->_avatar_url);
|
||||
|
||||
priv->last_update = NULL;
|
||||
priv->display_name = NULL;
|
||||
priv->_avatar_url = NULL;
|
||||
|
||||
G_OBJECT_CLASS (matrix_profile_parent_class)->finalize(gobject);
|
||||
}
|
||||
|
||||
static void
|
||||
matrix_profile_get_property (GObject *gobject, guint property_id, GValue *value, GParamSpec *pspec)
|
||||
{
|
||||
MatrixProfile *matrix_profile;
|
||||
|
||||
matrix_profile = G_TYPE_CHECK_INSTANCE_CAST(gobject, MATRIX_TYPE_PROFILE, MatrixProfile);
|
||||
|
||||
switch (property_id) {
|
||||
case PROP_AGE:
|
||||
g_value_set_int64 (value, matrix_profile_get_age (matrix_profile));
|
||||
|
||||
break;
|
||||
case PROP_DISPLAY_NAME:
|
||||
g_value_set_string (value, matrix_profile_get_display_name (matrix_profile));
|
||||
|
||||
break;
|
||||
case PROP_AVATAR_URL:
|
||||
g_value_set_string(value, matrix_profile_get_avatar_url (matrix_profile));
|
||||
|
||||
break;
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID(gobject, property_id, pspec);
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
matrix_profile_set_property(GObject *gobject,
|
||||
guint property_id,
|
||||
const GValue *value,
|
||||
GParamSpec *pspec)
|
||||
{
|
||||
MatrixProfile *matrix_profile;
|
||||
|
||||
matrix_profile = G_TYPE_CHECK_INSTANCE_CAST(gobject, MATRIX_TYPE_PROFILE, MatrixProfile);
|
||||
|
||||
switch (property_id) {
|
||||
case PROP_DISPLAY_NAME:
|
||||
matrix_profile_set_display_name(matrix_profile, g_value_get_string(value));
|
||||
|
||||
break;
|
||||
case PROP_AVATAR_URL:
|
||||
matrix_profile_set_avatar_url(matrix_profile, g_value_get_string(value));
|
||||
|
||||
break;
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID(gobject, property_id, pspec);
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
matrix_profile_class_init(MatrixProfileClass *klass)
|
||||
{
|
||||
matrix_profile_parent_class = g_type_class_peek_parent(klass);
|
||||
|
||||
G_OBJECT_CLASS(klass)->get_property = matrix_profile_get_property;
|
||||
G_OBJECT_CLASS(klass)->set_property = matrix_profile_set_property;
|
||||
G_OBJECT_CLASS(klass)->finalize = matrix_profile_finalize;
|
||||
|
||||
/**
|
||||
* MatrixProfile:age:
|
||||
*
|
||||
* The age of the profile, in seconds.
|
||||
*/
|
||||
matrix_profile_properties[PROP_AGE] = g_param_spec_int64(
|
||||
"age", "Age",
|
||||
"Age of the profile",
|
||||
0, G_MAXINT64, 0,
|
||||
G_PARAM_STATIC_STRINGS | G_PARAM_READABLE);
|
||||
g_object_class_install_property(
|
||||
G_OBJECT_CLASS (klass),
|
||||
PROP_AGE,
|
||||
matrix_profile_properties[PROP_AGE]);
|
||||
|
||||
/**
|
||||
* MatrixProfile:display-name:
|
||||
*
|
||||
* The display name of the user in this profile.
|
||||
*/
|
||||
matrix_profile_properties[PROP_DISPLAY_NAME] = g_param_spec_string(
|
||||
"display-name", "display-name",
|
||||
"The human readable name of the usser",
|
||||
NULL,
|
||||
G_PARAM_STATIC_STRINGS | G_PARAM_READWRITE);
|
||||
g_object_class_install_property(
|
||||
G_OBJECT_CLASS(klass),
|
||||
PROP_DISPLAY_NAME,
|
||||
matrix_profile_properties[PROP_DISPLAY_NAME]);
|
||||
|
||||
/**
|
||||
* MatrixProfile:avatar-url:
|
||||
*
|
||||
* The avatar URL in this profile.
|
||||
*/
|
||||
matrix_profile_properties[PROP_AVATAR_URL] = g_param_spec_string (
|
||||
"avatar-url", "avatar-url",
|
||||
"The URL of the user's avatar",
|
||||
NULL,
|
||||
G_PARAM_STATIC_STRINGS | G_PARAM_READWRITE);
|
||||
g_object_class_install_property(
|
||||
G_OBJECT_CLASS (klass),
|
||||
PROP_AVATAR_URL,
|
||||
matrix_profile_properties[PROP_AVATAR_URL]);
|
||||
}
|
||||
|
||||
static void
|
||||
matrix_profile_init(MatrixProfile *matrix_profile)
|
||||
{
|
||||
MatrixProfilePrivate *priv = matrix_profile_get_instance_private(matrix_profile);
|
||||
|
||||
priv->display_name = NULL;
|
||||
priv->_avatar_url = NULL;
|
||||
|
||||
matrix_profile_set_display_name(matrix_profile, NULL);
|
||||
matrix_profile_set_avatar_url(matrix_profile, NULL);
|
||||
}
|
45
src/matrix-profile.h
Normal file
45
src/matrix-profile.h
Normal file
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
* This file is part of matrix-glib-sdk
|
||||
*
|
||||
* matrix-glib-sdk is free software: you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation, either
|
||||
* version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* matrix-glib-sdk is distributed in the hope that it will be
|
||||
* useful, but WITHOUT ANY WARRANTY; without even the implied
|
||||
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
* See the GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with matrix-glib-sdk. If not, see
|
||||
* <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef __MATRIX_GLIB_SDK_PROFILE_H__
|
||||
# define __MATRIX_GLIB_SDK_PROFILE_H__
|
||||
|
||||
# include <glib-object.h>
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
# define MATRIX_TYPE_PROFILE matrix_profile_get_type()
|
||||
G_DECLARE_DERIVABLE_TYPE(MatrixProfile, matrix_profile, MATRIX, PROFILE, GObject)
|
||||
|
||||
struct _MatrixProfileClass {
|
||||
GObjectClass parent_class;
|
||||
|
||||
/* < private > */
|
||||
gpointer padding[12];
|
||||
};
|
||||
|
||||
MatrixProfile *matrix_profile_new(void);
|
||||
GTimeSpan matrix_profile_get_age (MatrixProfile *profile);
|
||||
const gchar *matrix_profile_get_avatar_url(MatrixProfile *profile);
|
||||
void matrix_profile_set_avatar_url(MatrixProfile *profile, const gchar *avatar_url);
|
||||
const gchar *matrix_profile_get_display_name(MatrixProfile *profile);
|
||||
void matrix_profile_set_display_name(MatrixProfile *profile, const gchar *display_name);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* __MATRIX_GLIB_SDK_PROFILE_H__ */
|
@@ -1,119 +0,0 @@
|
||||
/*
|
||||
* This file is part of matrix-glib-sdk
|
||||
*
|
||||
* matrix-glib-sdk is free software: you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation, either
|
||||
* version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* matrix-glib-sdk is distributed in the hope that it will be
|
||||
* useful, but WITHOUT ANY WARRANTY; without even the implied
|
||||
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
* See the GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with matrix-glib-sdk. If not, see
|
||||
* <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Class for representing a room membership events
|
||||
*
|
||||
* The room membership event class.
|
||||
*/
|
||||
public class Matrix.RoomMemberEvent : Matrix.RoomEvent {
|
||||
public string? state_key { get; set; }
|
||||
public RoomMembership membership {
|
||||
get; set;
|
||||
default = RoomMembership.UNKNOWN;
|
||||
}
|
||||
public string? avatar_url { get; set; }
|
||||
public string? display_name { get; set; }
|
||||
|
||||
protected override void
|
||||
from_json(Json.Node json_data)
|
||||
throws Matrix.Error
|
||||
{
|
||||
Json.Object root = json_data.get_object();
|
||||
Json.Object content_root = root.get_member("content").get_object();
|
||||
Json.Node? node;
|
||||
|
||||
if ((node = root.get_member("state_key")) != null) {
|
||||
_state_key = node.get_string();
|
||||
} else {
|
||||
GLib.warning("state_key is missing from the m.room.member event");
|
||||
}
|
||||
|
||||
if ((node = root.get_member("room_id")) != null) {
|
||||
_room_id = node.get_string();
|
||||
} else {
|
||||
GLib.warning("room_id is missing from the m.room.member event");
|
||||
}
|
||||
|
||||
if ((node = content_root.get_member("membership")) != null) {
|
||||
Matrix.RoomMembership? mship = (Matrix.RoomMembership?)_g_enum_nick_to_value(
|
||||
typeof(Matrix.RoomMembership),
|
||||
node.get_string());
|
||||
|
||||
if (mship != null) {
|
||||
_membership = mship;
|
||||
}
|
||||
} else {
|
||||
GLib.warning("membership key is missing from the m.room.member event");
|
||||
}
|
||||
|
||||
if ((node = content_root.get_member("avatar_url")) != null) {
|
||||
_avatar_url = node.get_string();
|
||||
}
|
||||
|
||||
if ((node = content_root.get_member("displayname")) != null) {
|
||||
_display_name = node.get_string();
|
||||
}
|
||||
|
||||
// Chain up
|
||||
base.from_json(json_data);
|
||||
}
|
||||
|
||||
protected override void
|
||||
to_json(Json.Node json_data)
|
||||
throws Matrix.Error
|
||||
{
|
||||
Json.Object root, content_root;
|
||||
string? mship;
|
||||
|
||||
if (membership == RoomMembership.UNKNOWN) {
|
||||
throw new Matrix.Error.UNKNOWN_VALUE(
|
||||
"Unknown membership value cannot be added to a room member event");
|
||||
}
|
||||
|
||||
root = json_data.get_object();
|
||||
|
||||
content_root = _json_object_node_ensure_field(json_data,
|
||||
"content",
|
||||
Json.NodeType.OBJECT)
|
||||
.get_object();
|
||||
|
||||
root.set_string_member("state_key", state_key);
|
||||
|
||||
if (room_id != null) {
|
||||
root.set_string_member("room_id", room_id);
|
||||
}
|
||||
|
||||
mship = _g_enum_value_to_nick(typeof(Matrix.RoomMembership),
|
||||
membership);
|
||||
|
||||
if (mship != null) {
|
||||
content_root.set_string_member("membership", mship);
|
||||
}
|
||||
|
||||
if (avatar_url != null) {
|
||||
content_root.set_string_member("avatar_url", avatar_url);
|
||||
}
|
||||
|
||||
if (display_name != null) {
|
||||
content_root.set_string_member("displayname", display_name);
|
||||
}
|
||||
|
||||
base.to_json(json_data);
|
||||
}
|
||||
}
|
@@ -1,53 +0,0 @@
|
||||
/*
|
||||
* This file is part of matrix-glib-sdk
|
||||
*
|
||||
* matrix-glib-sdk is free software: you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation, either
|
||||
* version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* matrix-glib-sdk is distributed in the hope that it will be
|
||||
* useful, but WITHOUT ANY WARRANTY; without even the implied
|
||||
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
* See the GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with matrix-glib-sdk. If not, see
|
||||
* <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
public class Matrix.RoomMessageEvent : Matrix.RoomEvent {
|
||||
public string msg_type { get; set; }
|
||||
public string body { get; set; }
|
||||
|
||||
protected override void
|
||||
from_json(Json.Node json_data)
|
||||
throws Matrix.Error
|
||||
{
|
||||
var root = json_data.get_object();
|
||||
|
||||
if (root.get_member("content") == null) {
|
||||
throw new Matrix.Error.INCOMPLETE(
|
||||
"Message event without a content!");
|
||||
}
|
||||
|
||||
var content_root = root.get_member("content").get_object();
|
||||
Json.Node? node;
|
||||
|
||||
if ((node = content_root.get_member("msgtype")) == null) {
|
||||
throw new Matrix.Error.INCOMPLETE(
|
||||
"Message event without a message type!");
|
||||
}
|
||||
|
||||
_msg_type = node.get_string();
|
||||
|
||||
if ((node = content_root.get_member("body")) == null) {
|
||||
throw new Matrix.Error.INCOMPLETE(
|
||||
"Message event without a body!");
|
||||
}
|
||||
|
||||
_body = node.get_string();
|
||||
|
||||
base.from_json(json_data);
|
||||
}
|
||||
}
|
382
src/matrix-room.vala
Normal file
382
src/matrix-room.vala
Normal file
@@ -0,0 +1,382 @@
|
||||
/*
|
||||
* This file is part of matrix-glib-sdk
|
||||
*
|
||||
* matrix-glib-sdk is free software: you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation, either
|
||||
* version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* matrix-glib-sdk is distributed in the hope that it will be
|
||||
* useful, but WITHOUT ANY WARRANTY; without even the implied
|
||||
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
* See the GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with matrix-glib-sdk. If not, see
|
||||
* <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Class to hold data about rooms
|
||||
*
|
||||
* The Room class is there to hold different parameters of a room like
|
||||
* its known aliases, its members, etc.
|
||||
*/
|
||||
public class Matrix.Room : GLib.Object {
|
||||
/**
|
||||
* The ID of the room this object belongs to.
|
||||
*
|
||||
* If this property is null, then this object is acting as a
|
||||
* temporary stash for another room object, which is used when
|
||||
* calculating state events to be sent by apply_changes().
|
||||
*/
|
||||
public string? room_id { get; construct; }
|
||||
|
||||
/**
|
||||
* All the known room aliases.
|
||||
*/
|
||||
public string[] aliases { get; set; }
|
||||
|
||||
/**
|
||||
* The URL of the room’s avatar.
|
||||
*/
|
||||
public string? avatar_url { get; set; default = null; }
|
||||
|
||||
/**
|
||||
* ImageInfo relevant to the room avatar.
|
||||
*/
|
||||
public ImageInfo? avatar_info { get; set; default = null; }
|
||||
|
||||
/**
|
||||
* The URL of the room avatar’s thumbnail.
|
||||
*/
|
||||
public string? avatar_thumbnail_url { get; set; default = null; }
|
||||
|
||||
/**
|
||||
* ImageInfo relevant to the room avatar’s thumbnail.
|
||||
*/
|
||||
public ImageInfo? avatar_thumbnail_info { get; set; default = null; }
|
||||
|
||||
/**
|
||||
* The canonical alias of the room.
|
||||
*/
|
||||
public string? canonical_alias { get; set; default = null; }
|
||||
|
||||
/**
|
||||
* The Matrix ID of the room’s creator.
|
||||
*/
|
||||
public string? creator { get; set; default = null; }
|
||||
|
||||
/**
|
||||
* If false, the room is not federated.
|
||||
*/
|
||||
public bool federate { get; set; default = false; }
|
||||
|
||||
/**
|
||||
* Wether guests are allowed to join the room.
|
||||
*/
|
||||
public GuestAccess guest_access { get; set; default = GuestAccess.UNKNOWN; }
|
||||
|
||||
/**
|
||||
* This value controls the visibility of the room’s history.
|
||||
*/
|
||||
public HistoryVisibility history_visibility {
|
||||
get; set;
|
||||
default = HistoryVisibility.UNKNOWN;
|
||||
}
|
||||
|
||||
/**
|
||||
* Controls who can join the room.
|
||||
*/
|
||||
public JoinRules join_rules { get; set; default = JoinRules.UNKNOWN; }
|
||||
|
||||
/**
|
||||
* The room’s name.
|
||||
*/
|
||||
public string? name { get; set; default = null; }
|
||||
|
||||
/**
|
||||
* The default power level users get upon joining the room.
|
||||
*/
|
||||
public int default_power_level { get; set; default = 0; }
|
||||
|
||||
/**
|
||||
* The power level required to send non-state events to the
|
||||
* room. This gets applied if the event type doesn’t have an
|
||||
* explicit level requirement (see set_event_level() and
|
||||
* get_event_level()).
|
||||
*/
|
||||
public int default_event_level { get; set; default = 0; }
|
||||
|
||||
/**
|
||||
* The power level required to send state events to the room. This
|
||||
* get applied if the event type doesn’t have an explicit level
|
||||
* requirement (see set_event_level() and get_event_level()).
|
||||
*/
|
||||
public int default_state_level { get; set; default = 10; }
|
||||
|
||||
/**
|
||||
* The power level required to ban other users from the room.
|
||||
*/
|
||||
public int ban_level { get; set; default = 5; }
|
||||
|
||||
/**
|
||||
* The power level required to kick other users from the room.
|
||||
*/
|
||||
public int kick_level { get; set; default = 5; }
|
||||
|
||||
/**
|
||||
* The power level required to redact events in the room.
|
||||
*/
|
||||
public int redact_level { get; set; default = 20; }
|
||||
|
||||
/**
|
||||
* The power level required to invite users to the room.
|
||||
*/
|
||||
public int invite_level { get; set; default = 0; }
|
||||
|
||||
/**
|
||||
* The room’s topic.
|
||||
*/
|
||||
public string? topic { get; set; default = null; }
|
||||
|
||||
/**
|
||||
* The users currently typing in the room.
|
||||
*/
|
||||
public string[] typing_users { get; set; }
|
||||
|
||||
private HashTable<string, int?> _event_levels =
|
||||
new HashTable<string, int?>(str_hash, str_equal);
|
||||
|
||||
private HashTable<string, int?> _user_levels =
|
||||
new HashTable<string, int?>(str_hash, str_equal);
|
||||
|
||||
private struct MemberData {
|
||||
Profile profile;
|
||||
bool thirdparty;
|
||||
}
|
||||
|
||||
private HashTable<string, MemberData?> _members =
|
||||
new HashTable<string, MemberData?>(str_hash, str_equal);
|
||||
|
||||
private Room _stash = null;
|
||||
|
||||
/**
|
||||
* Create a new Room object.
|
||||
*
|
||||
* @param room_id the ID of the room this object belongs to. For
|
||||
* null values, see remark at the room_id property.
|
||||
*/
|
||||
public
|
||||
Room(string? room_id)
|
||||
{
|
||||
Object(room_id : room_id);
|
||||
|
||||
if (room_id != null) {
|
||||
_stash = new Room(null);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a member to the room member list. If a member with the
|
||||
* same @user_id exists, {@link Matrix.Error.ALREADY_EXISTS} is
|
||||
* thrown.
|
||||
*
|
||||
* @param user_id the Matrix ID of the user to add
|
||||
* @param third_party if true, the member is marked as a pending
|
||||
* 3rd party invitation
|
||||
*/
|
||||
public void
|
||||
add_member(string user_id, Profile? profile, bool third_party)
|
||||
throws Matrix.Error
|
||||
{
|
||||
MemberData? data = null;
|
||||
|
||||
if ((data = _members[user_id]) != null) {
|
||||
throw new Matrix.Error.ALREADY_EXISTS(
|
||||
"User already exists in that room");
|
||||
}
|
||||
|
||||
data = MemberData();
|
||||
|
||||
if (profile == null) {
|
||||
data.profile = new Profile();
|
||||
} else {
|
||||
data.profile = profile;
|
||||
}
|
||||
|
||||
data.thirdparty = third_party;
|
||||
|
||||
_members[user_id] = data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the profile of the room member specified in @user_id. If
|
||||
* that user is not added to the room yet, it gets added with an
|
||||
* empty profile and that profile is returned.
|
||||
*
|
||||
* @param user_id the Matrix ID of the user to add
|
||||
* @param third_party if true, the member is marked as a pending
|
||||
* 3rd party invitation
|
||||
* @return the {@link Matrix.Profile} of the user
|
||||
*/
|
||||
public Profile
|
||||
get_or_add_member(string user_id, bool third_party = false)
|
||||
throws Matrix.Error
|
||||
{
|
||||
try {
|
||||
return get_member(user_id, null);
|
||||
} catch (Matrix.Error e) {
|
||||
add_member(user_id, null, third_party);
|
||||
|
||||
return get_member(user_id, null);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the profile of the room member specified in @user_id. If
|
||||
* that user is not added to the room yet,
|
||||
* {@link Matrix.Error.NOT_FOUND} is thrown.
|
||||
*
|
||||
* @param user_id the Matrix ID of the user to find
|
||||
* @param third_party gets a true value if the member is actually
|
||||
* a pending 3rd party invitation
|
||||
* @return the profile of the user
|
||||
*/
|
||||
public Profile
|
||||
get_member(string user_id, out bool third_party)
|
||||
throws Matrix.Error
|
||||
{
|
||||
MemberData? data = null;
|
||||
|
||||
if ((data = _members[user_id]) == null) {
|
||||
throw new Matrix.Error.NOT_FOUND(
|
||||
"No such room member");
|
||||
}
|
||||
|
||||
third_party = data.thirdparty;
|
||||
|
||||
return data.profile;
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes a member from the member list.
|
||||
*/
|
||||
public void
|
||||
remove_member(string user_id)
|
||||
throws Matrix.Error
|
||||
{
|
||||
MemberData? data = null;
|
||||
|
||||
if ((data = _members[user_id]) == null) {
|
||||
throw new Matrix.Error.NOT_FOUND(
|
||||
"No such room member");
|
||||
}
|
||||
|
||||
_members.remove(user_id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear the stored individual user levels. This should be called
|
||||
* e.g. when receiving a new m.room.power_levels event.
|
||||
*/
|
||||
public void
|
||||
clear_user_levels()
|
||||
{
|
||||
_user_levels.remove_all();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set an individual power level for a user.
|
||||
*
|
||||
* @param user_id a fully qualified Matrix ID
|
||||
* @param level the new power level
|
||||
*/
|
||||
public void
|
||||
set_user_level(string user_id, int level)
|
||||
{
|
||||
_user_levels[user_id] = level;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the power level of a user.
|
||||
*
|
||||
* @param user_id a fully qualified Matrix ID
|
||||
* @return the level of the user. If the user doesn’t have an
|
||||
* individually set power level, the default value is
|
||||
* returned
|
||||
*/
|
||||
public int
|
||||
get_user_level(string user_id)
|
||||
{
|
||||
int? level = _user_levels[user_id];
|
||||
|
||||
if (level == null) {
|
||||
level = _default_power_level;
|
||||
}
|
||||
|
||||
return level;
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear the stored event level requirements. This should be
|
||||
* called e.g. when receiving a new m.room.power_levels event.
|
||||
*/
|
||||
public void
|
||||
clear_event_levels()
|
||||
{
|
||||
_event_levels.remove_all();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the required level to send an event of
|
||||
* type @param event_type.
|
||||
*
|
||||
* @param event_type the event type to restrict
|
||||
* @param level the desired level for the event type
|
||||
*/
|
||||
public void
|
||||
set_event_level(string event_type, int level)
|
||||
{
|
||||
_event_levels[event_type] = level;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the required level to send an event of
|
||||
* type @param event_type.
|
||||
*
|
||||
* @param event_type the event type to query
|
||||
* @return the level required to send a specific event. If there
|
||||
* is no level requirement is set for this event type,
|
||||
* this function returns null as there is no way to decide
|
||||
* if {@link Matrix.Room.default_state_level} or
|
||||
* {@link Matrix.Room.default_event_level} should be used
|
||||
*/
|
||||
public int?
|
||||
get_event_level(string event_type)
|
||||
{
|
||||
return _event_levels[event_type];
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate a set of events that can change the room state on the
|
||||
* home server similar to what this object shows.
|
||||
*/
|
||||
public void
|
||||
apply_changes()
|
||||
{
|
||||
Matrix.Event.Base[] ret = {};
|
||||
|
||||
foreach (var to_add in _aliases) {
|
||||
if (!(to_add in _stash._aliases)) {
|
||||
// add alias
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var to_remove in _stash._aliases) {
|
||||
if (!(to_remove in _aliases)) {
|
||||
// remove alias
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,58 +0,0 @@
|
||||
/*
|
||||
* This file is part of matrix-glib-sdk
|
||||
*
|
||||
* matrix-glib-sdk is free software: you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation, either
|
||||
* version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* matrix-glib-sdk is distributed in the hope that it will be
|
||||
* useful, but WITHOUT ANY WARRANTY; without even the implied
|
||||
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
* See the GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with matrix-glib-sdk. If not, see
|
||||
* <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
namespace Matrix {
|
||||
public class StateEvent : Matrix.Event {
|
||||
public string? state_key { get; set; default = null; }
|
||||
public Json.Node? content { get; set; default = null; }
|
||||
|
||||
protected override void
|
||||
from_json(Json.Node json_data)
|
||||
throws Matrix.Error
|
||||
{
|
||||
var root = json_data.get_object();
|
||||
Json.Node? node;
|
||||
|
||||
if ((node = root.get_member("state_key")) != null) {
|
||||
state_key = node.get_string();
|
||||
}
|
||||
|
||||
if ((node = root.get_member("content")) != null) {
|
||||
content = node;
|
||||
}
|
||||
|
||||
base.from_json(json_data);
|
||||
}
|
||||
|
||||
protected override void
|
||||
to_json(Json.Node json_node)
|
||||
throws Matrix.Error
|
||||
{
|
||||
var root = json_node.get_object();
|
||||
|
||||
if (state_key != null) {
|
||||
root.set_string_member("state_key", state_key);
|
||||
}
|
||||
|
||||
if (content != null) {
|
||||
root.set_member("content", content);
|
||||
}
|
||||
|
||||
base.to_json(json_node);
|
||||
}
|
||||
}
|
||||
}
|
1514
src/matrix-types.c
Normal file
1514
src/matrix-types.c
Normal file
File diff suppressed because it is too large
Load Diff
276
src/matrix-types.h
Normal file
276
src/matrix-types.h
Normal file
@@ -0,0 +1,276 @@
|
||||
/*
|
||||
* This file is part of matrix-glib-sdk
|
||||
*
|
||||
* matrix-glib-sdk is free software: you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation, either
|
||||
* version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* matrix-glib-sdk is distributed in the hope that it will be
|
||||
* useful, but WITHOUT ANY WARRANTY; without even the implied
|
||||
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
* See the GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with matrix-glib-sdk. If not, see
|
||||
* <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef __MATRIX_TYPE_H__
|
||||
# define __MATRIX_TYPE_H__
|
||||
|
||||
# include <glib-object.h>
|
||||
# include <json-glib/json-glib.h>
|
||||
|
||||
typedef enum {
|
||||
MATRIX_ERROR_NONE,
|
||||
MATRIX_ERROR_COMMUNICATION_ERROR,
|
||||
MATRIX_ERROR_INCOMPLETE,
|
||||
MATRIX_ERROR_BAD_REQUEST,
|
||||
MATRIX_ERROR_BAD_RESPONSE,
|
||||
MATRIX_ERROR_INVALID_ROOM_ID,
|
||||
MATRIX_ERROR_UNKNOWN_VALUE,
|
||||
MATRIX_ERROR_INVALID_TYPE,
|
||||
MATRIX_ERROR_UNSUPPORTED,
|
||||
MATRIX_ERROR_INVALID_FORMAT,
|
||||
MATRIX_ERROR_UNAVAILABLE,
|
||||
MATRIX_ERROR_NOT_FOUND,
|
||||
MATRIX_ERROR_ALREADY_EXISTS,
|
||||
|
||||
/* Add Matrix-defined error codes under here, prefixing them with
|
||||
* `MATRIX_ERROR_`, i.e. `M_FORBIDDEN` =>
|
||||
* `MATRIX_ERROR_M_FORBIDDEN` */
|
||||
|
||||
MATRIX_ERROR_M_MISSING_TOKEN = 500,
|
||||
MATRIX_ERROR_M_FORBIDDEN,
|
||||
MATRIX_ERROR_M_UNKNOWN,
|
||||
MATRIX_ERROR_M_UNKNOWN_TOKEN,
|
||||
MATRIX_ERROR_M_NOT_JSON,
|
||||
MATRIX_ERROR_M_UNRECOGNIZED,
|
||||
MATRIX_ERROR_M_UNAUTHORIZED,
|
||||
MATRIX_ERROR_M_BAD_JSON,
|
||||
MATRIX_ERROR_M_USER_IN_USE,
|
||||
MATRIX_ERROR_M_ROOM_IN_USE,
|
||||
MATRIX_ERROR_M_BAD_PAGINATION,
|
||||
MATRIX_ERROR_M_BAD_STATE,
|
||||
MATRIX_ERROR_M_NOT_FOUND,
|
||||
MATRIX_ERROR_M_GUEST_ACCESS_FORBIDDEN,
|
||||
MATRIX_ERROR_M_LIMIT_EXCEEDED,
|
||||
MATRIX_ERROR_M_CAPTCHA_NEEDED,
|
||||
MATRIX_ERROR_M_CAPTCHA_INVALID,
|
||||
MATRIX_ERROR_M_MISSING_PARAM,
|
||||
MATRIX_ERROR_M_TOO_LARGE,
|
||||
MATRIX_ERROR_M_EXCLUSIVE,
|
||||
MATRIX_ERROR_M_THREEPID_AUTH_FAILED,
|
||||
MATRIX_ERROR_M_THREEPID_IN_USE,
|
||||
MATRIX_ERROR_M_INVALID_USERNAME,
|
||||
|
||||
/* Allow for a lot of Matrix.org defined codes. Do not define
|
||||
* Matrix-specific error codes after this! */
|
||||
|
||||
MATRIX_ERROR_UNSPECIFIED = 16383,
|
||||
MATRIX_ERROR_UNKNOWN_ERROR
|
||||
} MatrixError;
|
||||
|
||||
# define MATRIX_ERROR matrix_error_quark()
|
||||
GQuark matrix_error_quark(void);
|
||||
|
||||
typedef enum {
|
||||
MATRIX_ACCOUNT_KIND_DEFAULT,
|
||||
MATRIX_ACCOUNT_KIND_USER,
|
||||
MATRIX_ACCOUNT_KIND_GUEST
|
||||
} MatrixAccountKind;
|
||||
|
||||
typedef enum {
|
||||
MATRIX_EVENT_DIRECTION_FORWARD,
|
||||
MATRIX_EVENT_DIRECTION_BACKWARD
|
||||
} MatrixEventDirection;
|
||||
|
||||
typedef enum {
|
||||
MATRIX_EVENT_FORMAT_DEFAULT,
|
||||
MATRIX_EVENT_FORMAT_CLIENT,
|
||||
MATRIX_EVENT_FORMAT_FEDERATION
|
||||
} MatrixEventFormat;
|
||||
|
||||
typedef enum {
|
||||
MATRIX_PRESENCE_UNKNOWN,
|
||||
MATRIX_PRESENCE_ONLINE,
|
||||
MATRIX_PRESENCE_OFFLINE,
|
||||
MATRIX_PRESENCE_UNAVAILABLE,
|
||||
MATRIX_PRESENCE_FREE_FOR_CHAT
|
||||
} MatrixPresence;
|
||||
|
||||
typedef enum {
|
||||
MATRIX_PUSHER_CONDITION_KIND_EVENT_MATCH,
|
||||
MATRIX_PUSHER_CONDITION_KIND_PROFILE_TAG,
|
||||
MATRIX_PUSHER_CONDITION_KIND_CONTAINS_DISPLAY_NAME,
|
||||
MATRIX_PUSHER_CONDITION_KIND_ROOM_MEMBER_COUNT
|
||||
} MatrixPusherConditionKind;
|
||||
|
||||
typedef enum {
|
||||
MATRIX_PUSHER_KIND_OVERRIDE,
|
||||
MATRIX_PUSHER_KIND_SENDER,
|
||||
MATRIX_PUSHER_KIND_ROOM,
|
||||
MATRIX_PUSHER_KIND_CONTENT,
|
||||
MATRIX_PUSHER_KIND_UNDERRIDE
|
||||
} MatrixPusherKind;
|
||||
|
||||
typedef enum {
|
||||
MATRIX_RECEIPT_TYPE_READ
|
||||
} MatrixReceiptType;
|
||||
|
||||
typedef enum {
|
||||
MATRIX_RESIZE_METHOD_DEFAULT,
|
||||
MATRIX_RESIZE_METHOD_CROP,
|
||||
MATRIX_RESIZE_METHOD_SCALE
|
||||
} MatrixResizeMethod;
|
||||
|
||||
typedef enum {
|
||||
MATRIX_ROOM_MEMBERSHIP_UNKNOWN,
|
||||
MATRIX_ROOM_MEMBERSHIP_INVITE,
|
||||
MATRIX_ROOM_MEMBERSHIP_JOIN,
|
||||
MATRIX_ROOM_MEMBERSHIP_LEAVE,
|
||||
MATRIX_ROOM_MEMBERSHIP_BAN,
|
||||
MATRIX_ROOM_MEMBERSHIP_KNOCK
|
||||
} MatrixRoomMembership;
|
||||
|
||||
typedef enum {
|
||||
MATRIX_ROOM_PRESET_NONE,
|
||||
MATRIX_ROOM_PRESET_PRIVATE,
|
||||
MATRIX_ROOM_PRESET_TRUSTED_PRIVATE,
|
||||
MATRIX_ROOM_PRESET_PUBLIC
|
||||
} MatrixRoomPreset;
|
||||
|
||||
typedef enum {
|
||||
MATRIX_ROOM_VISIBILITY_DEFAULT,
|
||||
MATRIX_ROOM_VISIBILITY_PUBLIC,
|
||||
MATRIX_ROOM_VISIBILITY_PRIVATE
|
||||
} MatrixRoomVisibility;
|
||||
|
||||
typedef enum {
|
||||
MATRIX_JOIN_RULES_UNKNOWN,
|
||||
MATRIX_JOIN_RULES_PUBLIC,
|
||||
MATRIX_JOIN_RULES_INVITE,
|
||||
MATRIX_JOIN_RULES_PRIVATE,
|
||||
MATRIX_JOIN_RULES_KNOCK
|
||||
} MatrixJoinRules;
|
||||
|
||||
typedef enum {
|
||||
MATRIX_SEARCH_ORDER_RECENT,
|
||||
MATRIX_SEARCH_ORDER_RANK
|
||||
} MatrixSearchOrder;
|
||||
|
||||
typedef enum {
|
||||
MATRIX_SEARCH_KEY_CONTENT_BODY,
|
||||
MATRIX_SEARCH_KEY_CONTENT_NAME,
|
||||
MATRIX_SEARCH_KEY_CONTENT_TOPIC
|
||||
} MatrixSearchKey;
|
||||
|
||||
typedef enum {
|
||||
MATRIX_SEARCH_GROUP_BY_NONE,
|
||||
MATRIX_SEARCH_GROUP_BY_ROOM_ID,
|
||||
MATRIX_SEARCH_GROUP_BY_SENDER
|
||||
} MatrixSearchGroupBy;
|
||||
|
||||
typedef enum {
|
||||
MATRIX_HISTORY_VISIBILITY_UNKNOWN,
|
||||
MATRIX_HISTORY_VISIBILITY_INVITED,
|
||||
MATRIX_HISTORY_VISIBILITY_JOINED,
|
||||
MATRIX_HISTORY_VISIBILITY_SHARED,
|
||||
MATRIX_HISTORY_VISIBILITY_WORLD_READABLE
|
||||
} MatrixHistoryVisibility;
|
||||
|
||||
typedef enum {
|
||||
MATRIX_GUEST_ACCESS_UNKNOWN,
|
||||
MATRIX_GUEST_ACCESS_CAN_JOIN,
|
||||
MATRIX_GUEST_ACCESS_FORBIDDEN
|
||||
} MatrixGuestAccess;
|
||||
|
||||
typedef enum {
|
||||
MATRIX_CALL_OFFER_TYPE_UNKNOWN,
|
||||
MATRIX_CALL_OFFER_TYPE_OFFER
|
||||
} MatrixCallOfferType;
|
||||
|
||||
typedef enum {
|
||||
MATRIX_CALL_ANSWER_TYPE_UNKNOWN,
|
||||
MATRIX_CALL_ANSWER_TYPE_ANSWER
|
||||
} MatrixCallAnswerType;
|
||||
|
||||
typedef struct _MatrixFileInfo MatrixFileInfo;
|
||||
|
||||
GType matrix_file_info_get_type(void);
|
||||
# define MATRIX_TYPE_FILE_INFO matrix_file_info_get_type()
|
||||
|
||||
MatrixFileInfo *matrix_file_info_new(void);
|
||||
MatrixFileInfo *matrix_file_info_ref(MatrixFileInfo *file_info);
|
||||
void matrix_file_info_unref(MatrixFileInfo *file_info);
|
||||
void matrix_file_info_set_size(MatrixFileInfo *file_info, gssize size);
|
||||
gssize matrix_file_info_get_size(MatrixFileInfo *file_info);
|
||||
void matrix_file_info_set_mimetype(MatrixFileInfo *file_info, const gchar *mimetype);
|
||||
const gchar *matrix_file_info_get_mimetype(MatrixFileInfo *file_info);
|
||||
void matrix_file_info_set_from_json(MatrixFileInfo *file_info, JsonNode *json_data);
|
||||
JsonNode *matrix_file_info_get_json_node(MatrixFileInfo *file_info, GError **error);
|
||||
|
||||
typedef struct _MatrixAudioInfo MatrixAudioInfo;
|
||||
|
||||
GType matrix_audio_info_get_type(void);
|
||||
# define MATRIX_TYPE_AUDIO_INFO matrix_audio_info_get_type()
|
||||
|
||||
MatrixAudioInfo *matrix_audio_info_new(void);
|
||||
MatrixAudioInfo *matrix_audio_info_ref(MatrixAudioInfo *audio_info);
|
||||
void matrix_audio_info_unref(MatrixAudioInfo *audio_info);
|
||||
void matrix_audio_info_set_size(MatrixAudioInfo *audio_info, gssize size);
|
||||
gssize matrix_audio_info_get_size(MatrixAudioInfo *audio_info);
|
||||
void matrix_audio_info_set_mimetype(MatrixAudioInfo *audio_info, const gchar *mimetype);
|
||||
const gchar *matrix_audio_info_get_mimetype(MatrixAudioInfo *audio_info);
|
||||
void matrix_audio_info_set_duration(MatrixAudioInfo *audio_info, gint duration);
|
||||
gint matrix_audio_info_get_duration(MatrixAudioInfo *audio_info);
|
||||
void matrix_audio_info_set_from_json(MatrixAudioInfo *audio_info, JsonNode *json_data);
|
||||
JsonNode *matrix_audio_info_get_json_node(MatrixAudioInfo *audio_info, GError **error);
|
||||
|
||||
typedef struct _MatrixImageInfo MatrixImageInfo;
|
||||
|
||||
GType matrix_image_info_get_type(void);
|
||||
# define MATRIX_TYPE_IMAGE_INFO matrix_image_info_get_type()
|
||||
|
||||
MatrixImageInfo *matrix_image_info_new(void);
|
||||
MatrixImageInfo *matrix_image_info_ref(MatrixImageInfo *image_info);
|
||||
void matrix_image_info_unref(MatrixImageInfo *image_info);
|
||||
void matrix_image_info_set_size(MatrixImageInfo *image_info, gssize size);
|
||||
gssize matrix_image_info_get_size(MatrixImageInfo *image_info);
|
||||
void matrix_image_info_set_height(MatrixImageInfo *image_info, gint height);
|
||||
gint matrix_image_info_get_height(MatrixImageInfo *image_info);
|
||||
void matrix_image_info_set_width(MatrixImageInfo *image_info, gint width);
|
||||
gint matrix_image_info_get_width(MatrixImageInfo *image_info);
|
||||
void matrix_image_info_set_mimetype(MatrixImageInfo *image_info, const gchar *mimetype);
|
||||
const gchar *matrix_image_info_get_mimetype(MatrixImageInfo *image_info);
|
||||
void matrix_image_info_set_from_json(MatrixImageInfo *image_info, JsonNode *json_data);
|
||||
JsonNode *matrix_image_info_get_json_node(MatrixImageInfo *image_info, GError **error);
|
||||
gboolean matrix_image_info_differs(MatrixImageInfo *image_info, MatrixImageInfo *other);
|
||||
|
||||
typedef struct _MatrixVideoInfo MatrixVideoInfo;
|
||||
|
||||
GType matrix_video_info_get_type(void) G_GNUC_CONST;
|
||||
# define MATRIX_TYPE_VIDEO_INFO matrix_video_info_get_type()
|
||||
|
||||
MatrixVideoInfo *matrix_video_info_new(void);
|
||||
MatrixVideoInfo *matrix_video_info_ref(MatrixVideoInfo *video_info);
|
||||
void matrix_video_info_unref(MatrixVideoInfo *video_info);
|
||||
void matrix_video_info_set_size(MatrixVideoInfo *video_info, gsize size);
|
||||
gsize matrix_video_info_get_size(MatrixVideoInfo *video_info);
|
||||
void matrix_video_info_set_mimetype(MatrixVideoInfo *video_info, const gchar *mimetype);
|
||||
const gchar *matrix_video_info_get_mimetype(MatrixVideoInfo *video_info);
|
||||
void matrix_video_info_set_duration(MatrixVideoInfo *video_info, gint duration);
|
||||
gint matrix_video_info_get_duration(MatrixVideoInfo *video_info);
|
||||
void matrix_video_info_set_width(MatrixVideoInfo *video_info, gint width);
|
||||
gint matrix_video_info_get_width(MatrixVideoInfo *video_info);
|
||||
void matrix_video_info_set_height(MatrixVideoInfo *video_info, gint height);
|
||||
gint matrix_video_info_get_height(MatrixVideoInfo *video_info);
|
||||
void matrix_video_info_set_thumbnail_url(MatrixVideoInfo *video_info, const gchar *thumbnail_url);
|
||||
const gchar *matrix_video_info_get_thumbnail_url(MatrixVideoInfo *video_info);
|
||||
void matrix_video_info_set_thumbnail_info(MatrixVideoInfo *video_info, const MatrixImageInfo *thumbnail_info);
|
||||
const MatrixImageInfo *matrix_video_info_get_thumbnail_info(MatrixVideoInfo *video_info);
|
||||
void matrix_video_info_set_from_json(MatrixVideoInfo *video_info, JsonNode *json_data);
|
||||
JsonNode *matrix_video_info_get_json_node(MatrixVideoInfo *video_info, GError **error);
|
||||
|
||||
#endif /* __MATRIX_TYPE_H__ */
|
26
src/namespace-info.vala.in
Normal file
26
src/namespace-info.vala.in
Normal file
@@ -0,0 +1,26 @@
|
||||
/*
|
||||
* This file is part of matrix-glib-sdk
|
||||
*
|
||||
* matrix-glib-sdk is free software: you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation, either
|
||||
* version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* matrix-glib-sdk is distributed in the hope that it will be
|
||||
* useful, but WITHOUT ANY WARRANTY; without even the implied
|
||||
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
* See the GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with matrix-glib-sdk. If not, see
|
||||
* <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
[CCode (gir_namespace = "Matrix", gir_version = "@MATRIX_GLIB_API_VERSION@")]
|
||||
namespace Matrix {
|
||||
[CCode (gir_namespace = "Event", gir_version = "@MATRIX_GLIB_API_VERSION@")]
|
||||
namespace Event {}
|
||||
|
||||
[CCode (gir_namespace = "Message", gir_version = "@MATRIX_GLIB_API_VERSION@")]
|
||||
namespace Message {}
|
||||
}
|
@@ -68,7 +68,7 @@ create_room_finished(MatrixAPI *api,
|
||||
}
|
||||
|
||||
static void
|
||||
get_user_presence_finished(MatrixAPI *api,
|
||||
get_presence_finished(MatrixAPI *api,
|
||||
const gchar *content_type,
|
||||
JsonNode *json_content,
|
||||
GByteArray *raw_content,
|
||||
@@ -135,16 +135,16 @@ login_finished(MatrixAPI *api,
|
||||
initial_sync_finished,
|
||||
data, 10, TRUE,
|
||||
NULL);
|
||||
matrix_api_create_room(api,
|
||||
matrix_api_create_room (api,
|
||||
create_room_finished, NULL,
|
||||
MATRIX_ROOM_PRESET_PUBLIC,
|
||||
"GLib SDK test room", "matrix-glib-sdk-test",
|
||||
"GLib SDK test room",
|
||||
MATRIX_ROOM_VISIBILITY_DEFAULT,
|
||||
NULL, NULL, NULL, NULL, NULL);
|
||||
NULL, NULL, 0, NULL, 0, NULL, 0, NULL);
|
||||
matrix_api_get_presence_list(api, NULL, NULL, user_id, NULL);
|
||||
matrix_api_get_user_presence(api,
|
||||
get_user_presence_finished, NULL,
|
||||
matrix_api_get_presence(api,
|
||||
get_presence_finished, NULL,
|
||||
user_id, NULL);
|
||||
} else {
|
||||
g_printf("Login unsuccessful!\n");
|
||||
@@ -183,7 +183,7 @@ main(int argc, char *argv[])
|
||||
|
||||
g_info("Starting up: %s with %s:%s", *homeserver, user, password);
|
||||
|
||||
api = MATRIX_API(matrix_http_api_new(*homeserver, NULL));
|
||||
api = MATRIX_API(matrix_http_api_new(*homeserver, NULL, NULL));
|
||||
matrix_http_api_set_validate_certificate(MATRIX_HTTP_API(api),
|
||||
!no_validate_certs);
|
||||
builder = json_builder_new();
|
||||
|
@@ -33,12 +33,50 @@ static GOptionEntry entries[] = {
|
||||
{G_OPTION_REMAINING, 0, 0, G_OPTION_ARG_FILENAME_ARRAY, &homeserver, "The homeserver to connect to", "homeserver"},
|
||||
};
|
||||
|
||||
static gchar *
|
||||
save_file_name(MatrixClient *client)
|
||||
{
|
||||
const gchar *base_url = matrix_http_api_get_base_url(
|
||||
MATRIX_HTTP_API(client));
|
||||
gchar *filename = g_compute_checksum_for_string(
|
||||
G_CHECKSUM_SHA1, base_url, -1);
|
||||
gchar *dir = g_strdup_printf("%s/matrix-glib-sdk", g_get_user_cache_dir());
|
||||
gchar *full_fn = g_strdup_printf("%s/%s", dir, filename);
|
||||
|
||||
g_mkdir_with_parents(dir, 0700);
|
||||
|
||||
g_free(dir);
|
||||
g_free(filename);
|
||||
|
||||
return full_fn;
|
||||
}
|
||||
|
||||
static void
|
||||
save_state(MatrixClient *client)
|
||||
{
|
||||
gchar *filename = save_file_name(client);
|
||||
|
||||
matrix_client_save_state(client, filename, NULL);
|
||||
g_free(filename);
|
||||
}
|
||||
|
||||
static void
|
||||
load_state(MatrixClient *client)
|
||||
{
|
||||
gchar *filename = save_file_name(client);
|
||||
|
||||
matrix_client_load_state(client, filename, NULL);
|
||||
g_printf("Token loaded: %s\n", matrix_api_get_token(MATRIX_API(client)));
|
||||
g_free(filename);
|
||||
}
|
||||
|
||||
void
|
||||
login_finished(MatrixClient *client, gboolean success, GMainLoop *loop)
|
||||
{
|
||||
g_printerr("Login %s.\n", (success) ? "succesful" : "failed");
|
||||
|
||||
if (success) {
|
||||
save_state(client);
|
||||
matrix_client_begin_polling(client, NULL);
|
||||
} else {
|
||||
g_main_loop_quit(loop);
|
||||
@@ -49,23 +87,22 @@ static void
|
||||
cb_presence_event(MatrixClient *client,
|
||||
const gchar *room_id,
|
||||
JsonNode *raw_event,
|
||||
MatrixEvent *event,
|
||||
MatrixEventBase *event,
|
||||
gpointer user_data)
|
||||
{
|
||||
g_printerr("Incoming presence event from %s!\n",
|
||||
matrix_event_get_sender(event));
|
||||
matrix_event_presence_get_user_id(MATRIX_EVENT_PRESENCE(event)));
|
||||
}
|
||||
|
||||
static void
|
||||
cb_room_member_event(MatrixClient *client,
|
||||
const gchar *room_id,
|
||||
JsonNode *raw_event,
|
||||
MatrixEvent *event,
|
||||
MatrixEventBase *event,
|
||||
gpointer user_data)
|
||||
{
|
||||
g_printerr("Incoming room member event from %s in room %s (%s)\n",
|
||||
matrix_event_get_sender(event),
|
||||
matrix_event_get_room_id(MATRIX_EVENT(event)),
|
||||
g_printerr("Incoming room member event from %s via room %s\n",
|
||||
matrix_event_room_member_get_user_id(MATRIX_EVENT_ROOM_MEMBER(event)),
|
||||
room_id);
|
||||
}
|
||||
|
||||
@@ -73,13 +110,22 @@ static void
|
||||
cb_room_message_event(MatrixClient *client,
|
||||
const gchar *room_id,
|
||||
JsonNode *raw_event,
|
||||
MatrixEvent *event,
|
||||
MatrixEventBase *event,
|
||||
gpointer user_data)
|
||||
{
|
||||
g_printf("Message from %s: %s\n",
|
||||
matrix_event_get_sender(event),
|
||||
matrix_room_message_event_get_body(
|
||||
MATRIX_ROOM_MESSAGE_EVENT(event)));
|
||||
MatrixMessageBase *message;
|
||||
|
||||
if ((message = matrix_event_room_message_get_message(
|
||||
MATRIX_EVENT_ROOM_MESSAGE(event))) != NULL) {
|
||||
g_printf("Message from %s in %s: %s\n",
|
||||
matrix_event_room_get_sender(MATRIX_EVENT_ROOM(event)),
|
||||
matrix_event_room_get_room_id(MATRIX_EVENT_ROOM(event)),
|
||||
matrix_message_base_get_body(message));
|
||||
} else {
|
||||
g_printf("Unknown message received from %s in %s\n",
|
||||
matrix_event_room_get_sender(MATRIX_EVENT_ROOM(event)),
|
||||
matrix_event_room_get_room_id(MATRIX_EVENT_ROOM(event)));
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
@@ -119,14 +165,20 @@ main(int argc, char *argv[])
|
||||
"login-finished",
|
||||
G_CALLBACK(login_finished),
|
||||
loop);
|
||||
matrix_client_connect_event(client, MATRIX_TYPE_PRESENCE_EVENT,
|
||||
matrix_client_connect_event(client, MATRIX_EVENT_TYPE_PRESENCE,
|
||||
cb_presence_event, NULL, NULL);
|
||||
matrix_client_connect_event(client, MATRIX_TYPE_ROOM_MEMBER_EVENT,
|
||||
matrix_client_connect_event(client, MATRIX_EVENT_TYPE_ROOM_MEMBER,
|
||||
cb_room_member_event, NULL, NULL);
|
||||
matrix_client_connect_event(client, MATRIX_TYPE_ROOM_MESSAGE_EVENT,
|
||||
matrix_client_connect_event(client, MATRIX_EVENT_TYPE_ROOM_MESSAGE,
|
||||
cb_room_message_event, NULL, NULL);
|
||||
|
||||
load_state(client);
|
||||
|
||||
if (matrix_api_get_token(MATRIX_API(client)) == NULL) {
|
||||
matrix_client_login_with_password(client, user, password, NULL);
|
||||
} else {
|
||||
matrix_client_begin_polling(client, NULL);
|
||||
}
|
||||
|
||||
g_main_loop_run(loop);
|
||||
|
||||
|
176
src/utils.c
Normal file
176
src/utils.c
Normal file
@@ -0,0 +1,176 @@
|
||||
/*
|
||||
* This file is part of matrix-glib-sdk
|
||||
*
|
||||
* matrix-glib-sdk is free software: you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation, either
|
||||
* version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* matrix-glib-sdk is distributed in the hope that it will be
|
||||
* useful, but WITHOUT ANY WARRANTY; without even the implied
|
||||
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
* See the GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with matrix-glib-sdk. If not, see
|
||||
* <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "utils.h"
|
||||
#include "matrix-types.h"
|
||||
|
||||
// GTK-Doc looking comments in this file intentionally do not begin with a double star, as the
|
||||
// functions here are internal
|
||||
|
||||
/*
|
||||
* _matrix_g_enum_to_string:
|
||||
*
|
||||
* @enum_type: a #GEnumType
|
||||
* @value: an integer value registered in @enum_type
|
||||
* @convert_dashes: if non-NUL, dashes in the value nick will be converted to this char
|
||||
*
|
||||
* Get the value nick (lower case, dash-separated name) of an enum, like matrix-error-none. If
|
||||
* @convert_dashes is not NUL (`'\0'`), dashes will be converted to that char.
|
||||
*
|
||||
* Returns: (transfer full) the converted enum name, which must be freed
|
||||
*/
|
||||
gchar *
|
||||
_matrix_g_enum_to_string(GType enum_type, gint value, gchar convert_dashes)
|
||||
{
|
||||
GEnumClass *enum_class = g_type_class_ref(enum_type);
|
||||
GEnumValue *enum_value = g_enum_get_value(enum_class, value);
|
||||
gchar *nick = NULL;
|
||||
|
||||
if (value) {
|
||||
nick = g_strdup(enum_value->value_nick);
|
||||
|
||||
if (convert_dashes) {
|
||||
gchar *a;
|
||||
|
||||
for (a = nick; *a; a++) {
|
||||
if (*a == '-') {
|
||||
*a = convert_dashes;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
g_type_class_unref(enum_class);
|
||||
|
||||
return nick;
|
||||
}
|
||||
|
||||
/*
|
||||
* _matrix_g_enum_nick_to_value:
|
||||
*
|
||||
* @enum_type: a #GEnumType
|
||||
* @nick: a value nick registered in @enum_type
|
||||
* @error: a #GError, or NULL to ignore errors
|
||||
*
|
||||
* Get the integer value of the enum nick @nick from @enum_type. If the nick contains underscores
|
||||
* (`_`), they will be converted to dashes (`-`) first.
|
||||
*
|
||||
* If @nick cannot be found in @enum_type, this function returns NULL, and sets @error to
|
||||
* #MATRIX_ERROR_UNKNOWN_VALUE.
|
||||
*
|
||||
* Returns: the integer value of @nick, or 0 if not found
|
||||
*/
|
||||
gint
|
||||
_matrix_g_enum_nick_to_value(GType enum_type, const gchar *nick, GError **error)
|
||||
{
|
||||
GEnumClass *enum_class = g_type_class_ref(enum_type);
|
||||
GEnumValue *enum_value;
|
||||
gchar *nick_c = NULL;
|
||||
gchar *a;
|
||||
gint ret = 0;
|
||||
|
||||
nick_c = g_strdup(nick);
|
||||
|
||||
for (a = nick_c; *a; a++) {
|
||||
if (*a == '_') {
|
||||
*a = '-';
|
||||
}
|
||||
}
|
||||
|
||||
enum_value = g_enum_get_value_by_nick(enum_class, nick_c);
|
||||
g_free(nick_c);
|
||||
|
||||
if (enum_value) {
|
||||
ret = enum_value->value;
|
||||
} else {
|
||||
g_set_error(error, MATRIX_ERROR, MATRIX_ERROR_UNKNOWN_VALUE,
|
||||
"Value %s is unknown", nick);
|
||||
}
|
||||
|
||||
g_type_class_unref(enum_class);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static void
|
||||
_copy_obj_member(JsonObject *old_obj, const gchar *member_name, JsonNode *member_node, gpointer user_data)
|
||||
{
|
||||
JsonObject *new_obj = user_data;
|
||||
|
||||
json_object_set_member(new_obj, member_name, _matrix_json_node_deep_copy(member_node));
|
||||
}
|
||||
|
||||
static void
|
||||
_copy_ary_member(JsonArray *old_ary, guint idx, JsonNode *element_node, gpointer user_data)
|
||||
{
|
||||
JsonArray *new_ary = user_data;
|
||||
|
||||
json_array_add_element(new_ary, _matrix_json_node_deep_copy(element_node));
|
||||
}
|
||||
|
||||
JsonNode *
|
||||
_matrix_json_node_deep_copy(JsonNode *node)
|
||||
{
|
||||
JsonNode *ret;
|
||||
JsonNodeType node_type;
|
||||
|
||||
g_return_val_if_fail(node != NULL, NULL);
|
||||
|
||||
node_type = json_node_get_node_type(node);
|
||||
ret = json_node_new(node_type);
|
||||
|
||||
switch (node_type) {
|
||||
case JSON_NODE_OBJECT:
|
||||
{
|
||||
JsonObject *new_obj = json_object_new();
|
||||
JsonObject *old_obj = json_node_get_object(node);
|
||||
|
||||
json_object_foreach_member(old_obj, _copy_obj_member, new_obj);
|
||||
|
||||
json_node_set_object(ret, new_obj);
|
||||
|
||||
break;
|
||||
}
|
||||
case JSON_NODE_ARRAY:
|
||||
{
|
||||
JsonArray *new_ary = json_array_new();
|
||||
JsonArray *old_ary = json_node_get_array(node);
|
||||
|
||||
json_array_foreach_element(old_ary, _copy_ary_member, new_ary);
|
||||
|
||||
json_node_set_array(ret, new_ary);
|
||||
|
||||
break;
|
||||
}
|
||||
case JSON_NODE_VALUE:
|
||||
{
|
||||
GValue node_value = G_VALUE_INIT;
|
||||
|
||||
json_node_get_value(node, &node_value);
|
||||
json_node_set_value(ret, &node_value);
|
||||
|
||||
g_value_unset(&node_value);
|
||||
|
||||
break;
|
||||
}
|
||||
case JSON_NODE_NULL:
|
||||
break;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
33
src/utils.h
Normal file
33
src/utils.h
Normal file
@@ -0,0 +1,33 @@
|
||||
/*
|
||||
* This file is part of matrix-glib-sdk
|
||||
*
|
||||
* matrix-glib-sdk is free software: you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation, either
|
||||
* version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* matrix-glib-sdk is distributed in the hope that it will be
|
||||
* useful, but WITHOUT ANY WARRANTY; without even the implied
|
||||
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
* See the GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with matrix-glib-sdk. If not, see
|
||||
* <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef __MATRIX_GLIB_SDK_UTILS_H__
|
||||
# define __MATRIX_GLIB_SDK_UTILS_H__
|
||||
|
||||
# include <glib-object.h>
|
||||
# include <json-glib/json-glib.h>
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
gchar *_matrix_g_enum_to_string(GType enum_type, gint value, gchar convert_dashes);
|
||||
gint _matrix_g_enum_nick_to_value(GType enum_type, const gchar *nick, GError **error);
|
||||
JsonNode *_matrix_json_node_deep_copy(JsonNode *node);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* __MATRIX_GLIB_SDK_UTILS_H__ */
|
@@ -1,8 +1,9 @@
|
||||
VALA_PKG_LIST = \
|
||||
--pkg=gio-2.0 \
|
||||
--pkg=Json-1.0 \
|
||||
--pkg=json-glib-1.0 \
|
||||
--pkg=libsoup-2.4 \
|
||||
--pkg=gee-0.8 \
|
||||
--pkg=c-api \
|
||||
--pkg=config \
|
||||
$(NULL)
|
||||
|
||||
VALADOC_FLAGS = \
|
||||
@@ -12,6 +13,5 @@ VALADOC_FLAGS = \
|
||||
--package-version=$(PACKAGE_VERSION) \
|
||||
-b $(top_srcdir)/src \
|
||||
$(VALA_PKG_LIST) \
|
||||
--vapidir=$(top_srcdir)/src \
|
||||
$(top_srcdir)/src/c-api.vapi \
|
||||
--vapidir=$(top_srcdir)/vapi \
|
||||
$(NULL)
|
||||
|
459
vapi/c-api.vapi
Normal file
459
vapi/c-api.vapi
Normal file
@@ -0,0 +1,459 @@
|
||||
/*
|
||||
* This file is part of matrix-glib-sdk
|
||||
*
|
||||
* matrix-glib-sdk is free software: you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation, either
|
||||
* version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* matrix-glib-sdk is distributed in the hope that it will be
|
||||
* useful, but WITHOUT ANY WARRANTY; without even the implied
|
||||
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
* See the GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with matrix-glib-sdk. If not, see
|
||||
* <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
[CCode (cprefix = "Matrix", gir_namespace = "Matrix", gir_version = "0.0", lower_case_cprefix = "matrix_")]
|
||||
namespace Matrix {
|
||||
[CCode (cheader_filename = "matrix-enumtypes.h", cprefix = "MATRIX_ERROR_")]
|
||||
public errordomain Error {
|
||||
NONE,
|
||||
COMMUNICATION_ERROR,
|
||||
INCOMPLETE,
|
||||
BAD_REQUEST,
|
||||
BAD_RESPONSE,
|
||||
INVALID_ROOM_ID,
|
||||
UNKNOWN_VALUE,
|
||||
INVALID_TYPE,
|
||||
UNSUPPORTED,
|
||||
INVALID_FORMAT,
|
||||
UNAVAILABLE,
|
||||
NOT_FOUND,
|
||||
ALREADY_EXISTS,
|
||||
M_MISSING_TOKEN,
|
||||
M_FORBIDDEN,
|
||||
M_UNKNOWN,
|
||||
M_UNKNOWN_TOKEN,
|
||||
M_NOT_JSON,
|
||||
M_UNRECOGNIZED,
|
||||
M_UNAUTHORIZED,
|
||||
M_BAD_JSON,
|
||||
M_USER_IN_USE,
|
||||
M_ROOM_IN_USE,
|
||||
M_BAD_PAGINATION,
|
||||
M_BAD_STATE,
|
||||
M_NOT_FOUND,
|
||||
M_GUEST_ACCESS_FORBIDDEN,
|
||||
M_LIMIT_EXCEEDED,
|
||||
M_CAPTCHA_NEEDED,
|
||||
M_CAPTCHA_INVALID,
|
||||
M_MISSING_PARAM,
|
||||
M_TOO_LARGE,
|
||||
M_EXCLUSIVE,
|
||||
M_THREEPID_AUTH_FAILED,
|
||||
M_THREEPID_IN_USE,
|
||||
M_INVALID_USERNAME,
|
||||
UNSPECIFIED,
|
||||
UNKNOWN_ERROR;
|
||||
|
||||
public static GLib.Quark quark ();
|
||||
}
|
||||
|
||||
public const int MATRIX_ERROR;
|
||||
|
||||
[CCode (cheader_filename = "matrix-enumtypes.h", cprefix = "MATRIX_ACCOUNT_KIND_")]
|
||||
public enum AccountKind {
|
||||
DEFAULT,
|
||||
USER,
|
||||
GUEST;
|
||||
}
|
||||
|
||||
[CCode (cheader_filename = "matrix-enumtypes.h", cprefix = "MATRIX_EVENT_DIRECTION_")]
|
||||
public enum EventDirection {
|
||||
FORWARD,
|
||||
BACKWARD;
|
||||
}
|
||||
|
||||
[CCode (cheader_filename = "matrix-enumtypes.h", cprefix = "MATRIX_EVENT_FORMAT_")]
|
||||
public enum EventFormat {
|
||||
DEFAULT,
|
||||
CLIENT,
|
||||
FEDERATION;
|
||||
}
|
||||
|
||||
[CCode (cheader_filename = "matrix-enumtypes.h", cprefix = "MATRIX_PRESENCE_")]
|
||||
public enum Presence {
|
||||
UNKNOWN,
|
||||
ONLINE,
|
||||
OFFLINE,
|
||||
UNAVAILABLE,
|
||||
FREE_FOR_CHAT;
|
||||
}
|
||||
|
||||
[CCode (cheader_filename = "matrix-enumtypes.h", cprefix = "MATRIX_PUSHER_CONDITION_KIND_")]
|
||||
public enum PusherConditionKind {
|
||||
EVENT_MATCH,
|
||||
PROFILE_TAG,
|
||||
CONTAINS_DISPLAY_NAME,
|
||||
ROOM_MEMBER_COUNT;
|
||||
}
|
||||
|
||||
[CCode (cheader_filename = "matrix-enumtypes.h", cprefix = "MATRIX_PUSHER_KIND_")]
|
||||
public enum PusherKind {
|
||||
OVERRIDE,
|
||||
SENDER,
|
||||
ROOM,
|
||||
CONTENT,
|
||||
UNDERRIDE;
|
||||
}
|
||||
|
||||
[CCode (cheader_filename = "matrix-enumtypes.h", cprefix = "MATRIX_RECEIPT_TYPE_")]
|
||||
public enum ReceiptType {
|
||||
READ;
|
||||
}
|
||||
|
||||
[CCode (cheader_filename = "matrix-enumtypes.h", cprefix = "MATRIX_RESIZE_METHOD_")]
|
||||
public enum ResizeMethod {
|
||||
DEFAULT,
|
||||
CROP,
|
||||
SCALE;
|
||||
}
|
||||
|
||||
[CCode (cheader_filename = "matrix-enumtypes.h", cprefix = "MATRIX_ROOM_MEMBERSHIP_")]
|
||||
public enum RoomMembership {
|
||||
UNKNOWN,
|
||||
INVITE,
|
||||
JOIN,
|
||||
LEAVE,
|
||||
BAN,
|
||||
KNOCK;
|
||||
}
|
||||
|
||||
[CCode (cheader_filename = "matrix-enumtypes.h", cprefix = "MATRIX_ROOM_PRESET_")]
|
||||
public enum RoomPreset {
|
||||
NONE,
|
||||
PRIVATE,
|
||||
TRUSTED_PRIVATE,
|
||||
PUBLIC;
|
||||
}
|
||||
|
||||
[CCode (cheader_filename = "matrix-enumtypes.h", cprefix = "MATRIX_ROOM_VISIBILITY_")]
|
||||
public enum RoomVisibility {
|
||||
DEFAULT,
|
||||
PUBLIC,
|
||||
PRIVATE;
|
||||
}
|
||||
|
||||
[CCode (cheader_filename = "matrix-enumtypes.h", cprefix = "MATRIX_JOIN_RULES_")]
|
||||
public enum JoinRules {
|
||||
UNKNOWN,
|
||||
PUBLIC,
|
||||
INVITE,
|
||||
PRIVATE,
|
||||
KNOCK;
|
||||
}
|
||||
|
||||
[CCode (cheader_filename = "matrix-enumtypes.h", cprefix = "MATRIX_SEARCH_ORDER_")]
|
||||
public enum SearchOrder {
|
||||
RECENT,
|
||||
RANK;
|
||||
}
|
||||
|
||||
[CCode (cheader_filename = "matrix-enumtypes.h", cprefix = "MATRIX_SEARCH_KEY_")]
|
||||
public enum SearchKey {
|
||||
CONTENT_BODY,
|
||||
CONTENT_NAME,
|
||||
CONTENT_TOPIC;
|
||||
}
|
||||
|
||||
[CCode (cheader_filename = "matrix-enumtypes.h", cprefix = "MATRIX_SEARCH_GROUP_BY_")]
|
||||
public enum SearchGroupBy {
|
||||
NONE,
|
||||
ROOM_ID,
|
||||
SENDER;
|
||||
}
|
||||
|
||||
[CCode (cheader_filename = "matrix-enumtypes.h", cprefix = "MATRIX_HISTORY_VISIBILITY_")]
|
||||
public enum HistoryVisibility {
|
||||
UNKNOWN,
|
||||
INVITED,
|
||||
JOINED,
|
||||
SHARED,
|
||||
WORLD_READABLE;
|
||||
}
|
||||
|
||||
[CCode (cheader_filename = "matrix-enumtypes.h", cprefix = "MATRIX_GUEST_ACCESS_")]
|
||||
public enum GuestAccess {
|
||||
UNKNOWN,
|
||||
CAN_JOIN,
|
||||
FORBIDDEN;
|
||||
}
|
||||
|
||||
[CCode (cheader_filename = "matrix-enumtypes.h", cprefix = "MATRIX_CALL_OFFER_TYPE_")]
|
||||
public enum CallOfferType {
|
||||
UNKNOWN,
|
||||
OFFER;
|
||||
}
|
||||
|
||||
[CCode (cheader_filename = "matrix-enumtypes.h", cprefix = "MATRIX_CALL_ANSWER_TYPE_")]
|
||||
public enum CallAnswerType {
|
||||
UNKNOWN,
|
||||
ANSWER;
|
||||
}
|
||||
|
||||
[CCode (cheader_filename = "matrix-types.h")]
|
||||
public struct FileInfo {
|
||||
public void set_size(ssize size);
|
||||
public ssize get_size();
|
||||
|
||||
public void set_mimetype(string? mimetype);
|
||||
public string? get_mimetype();
|
||||
|
||||
public void set_from_json(Json.Node json_data);
|
||||
|
||||
public Json.Node get_json_node()
|
||||
throws Matrix.Error;
|
||||
}
|
||||
|
||||
[CCode (cheader_filename = "matrix-types.h")]
|
||||
public struct AudioInfo {
|
||||
public ssize get_size();
|
||||
public void set_size(ssize size);
|
||||
|
||||
public string? get_mimetype();
|
||||
public void set_mimetype(string? mimetype);
|
||||
|
||||
public int get_duration();
|
||||
public void set_duration(int duration);
|
||||
|
||||
public void set_from_json(Json.Node json_data);
|
||||
|
||||
public Json.Node get_json_node()
|
||||
throws Matrix.Error;
|
||||
}
|
||||
|
||||
[CCode (cheader_filename = "matrix-types.h")]
|
||||
public struct ImageInfo {
|
||||
public ssize get_size();
|
||||
public void set_size(ssize size);
|
||||
public int get_height();
|
||||
public void set_height(int height);
|
||||
public int get_width();
|
||||
public void set_width(int width);
|
||||
string? mimetype;
|
||||
|
||||
public void set_from_json(Json.Node json_data);
|
||||
|
||||
public Json.Node get_json_node()
|
||||
throws Matrix.Error;
|
||||
|
||||
public bool differs(ImageInfo other);
|
||||
}
|
||||
|
||||
[CCode (cheader_filename = "matrix-types.h")]
|
||||
public struct VideoInfo {
|
||||
public ssize get_size();
|
||||
public void set_size(ssize size);
|
||||
|
||||
public string? get_mimetype();
|
||||
public void set_mimetype(string? mimetype);
|
||||
|
||||
public int get_duration();
|
||||
public void set_duration(int duration);
|
||||
|
||||
public int get_width();
|
||||
public void set_width(int witdh);
|
||||
|
||||
public int get_height();
|
||||
public void set_height(int height);
|
||||
|
||||
public string? get_thumbnail_url();
|
||||
public void set_thumbnail_url();
|
||||
|
||||
public ImageInfo? get_thumbnail_info();
|
||||
public void set_image_info(ImageInfo? image_info);
|
||||
|
||||
public void
|
||||
set_from_json(Json.Node json_data);
|
||||
|
||||
public Json.Node
|
||||
get_json_node()
|
||||
throws Matrix.Error;
|
||||
}
|
||||
|
||||
/* Compact classes */
|
||||
[CCode (cheader_filename = "matrix-compacts.h")]
|
||||
public abstract class JsonCompact {
|
||||
public JsonCompact();
|
||||
|
||||
public abstract Json.Node? get_json_node()
|
||||
throws Matrix.Error;
|
||||
|
||||
public string get_json_data(out size_t datalen)
|
||||
throws Matrix.Error;
|
||||
}
|
||||
|
||||
[CCode (cheader_filename = "matrix-compacts.h")]
|
||||
public class FilterRules : JsonCompact {
|
||||
public uint limit { get; set; }
|
||||
public string[] types { get; set; }
|
||||
public string[] excluded_types { get; set; }
|
||||
public string[] senders { get; set; }
|
||||
public string[] excluded_senders { get; set; }
|
||||
public string[] rooms { get; set; }
|
||||
public string[] excluded_rooms { get; set; }
|
||||
public override Json.Node? get_json_node()
|
||||
throws Matrix.Error;
|
||||
}
|
||||
|
||||
[CCode (cheader_filename = "matrix-compacts.h")]
|
||||
public class RoomFilter : JsonCompact {
|
||||
public bool include_leave { get; set; default=true; }
|
||||
public FilterRules? ephemeral { get; set; default = null; }
|
||||
public FilterRules? state { get; set; default = null; }
|
||||
public FilterRules? timeline { get; set; default = null; }
|
||||
|
||||
public override Json.Node? get_json_node()
|
||||
throws Matrix.Error;
|
||||
}
|
||||
|
||||
[CCode (cheader_filename = "matrix-compacts.h")]
|
||||
public class Filter : JsonCompact {
|
||||
public string[] event_fields { get; set; }
|
||||
public EventFormat event_format { get; set; default = Matrix.EventFormat.CLIENT; }
|
||||
public FilterRules? presence_filter { get; set; default = null; }
|
||||
public RoomFilter? room_filter { get; set; default = null; }
|
||||
public override Json.Node? get_json_node()
|
||||
throws Matrix.Error;
|
||||
}
|
||||
|
||||
[CCode (cheader_filename = "matrix-compacts.h")]
|
||||
public class @3PidCredential : JsonCompact {
|
||||
public string? id_server { get; set; default = null; }
|
||||
public string? session_id { get; set; default = null; }
|
||||
public string? client_secret { get; set; default = null; }
|
||||
public override Json.Node?
|
||||
get_json_node()
|
||||
throws Matrix.Error;
|
||||
}
|
||||
|
||||
[CCode (cheader_filename = "matrix-compacts.h")]
|
||||
public class Pusher : JsonCompact {
|
||||
public string? device_display_name { get; set; default = null; }
|
||||
public string? app_display_name { get; set; default = null; }
|
||||
public string? app_id { get; set; default = null; }
|
||||
public bool append { get; set; default = true; }
|
||||
public string? kind { get; set; default = null; }
|
||||
public string? lang { get; set; default = null; }
|
||||
public string? profile_tag { get; set; default = null; }
|
||||
public string? pushkey { get; set; default = null; }
|
||||
public Json.Node? data { get; set; default = null; }
|
||||
public override Json.Node? get_json_node()
|
||||
throws Matrix.Error;
|
||||
}
|
||||
|
||||
[CCode (cheader_filename = "matrix-compacts.h")]
|
||||
public class EventContext : JsonCompact {
|
||||
public int before_limit { get; set; default = -1; }
|
||||
public int after_limit { get; set; default = -1; }
|
||||
public bool include_profile { get; set; default = false; }
|
||||
|
||||
public override Json.Node? get_json_node()
|
||||
throws Matrix.Error;
|
||||
}
|
||||
|
||||
[CCode (cheader_filename = "matrix-compacts.h")]
|
||||
public class SearchGrouping : JsonCompact {
|
||||
public SearchGroupBy key { get; set; default = SearchGroupBy.NONE; }
|
||||
|
||||
public override Json.Node? get_json_node()
|
||||
throws Matrix.Error;
|
||||
}
|
||||
|
||||
[CCode (cheader_filename = "matrix-compacts.h")]
|
||||
public class SearchGroupings : JsonCompact {
|
||||
public SearchGrouping[] group_by { get; set; }
|
||||
|
||||
public override Json.Node?
|
||||
get_json_node()
|
||||
throws Matrix.Error;
|
||||
}
|
||||
|
||||
[CCode (cheader_filename = "matrix-compacts.h")]
|
||||
public class SearchRoomEvents : JsonCompact {
|
||||
public SearchOrder order_by { get; set; default = SearchOrder.RECENT; }
|
||||
public SearchKey[] keys { get; set; }
|
||||
public EventContext? event_context { get; set; default = null; }
|
||||
public bool include_state { get; set; default = false; }
|
||||
public string? filter_id { get; set; default = null; }
|
||||
public Filter? filter { get; set; default = null; }
|
||||
public string search_term { get; set; }
|
||||
public SearchGroupings? groupings { get; set; default = null; }
|
||||
|
||||
public override Json.Node? get_json_node()
|
||||
throws Matrix.Error;
|
||||
}
|
||||
|
||||
[CCode (cheader_filename = "matrix-compacts.h")]
|
||||
public class SearchCategories : JsonCompact {
|
||||
public SearchRoomEvents? room_events { get; set; default = null; }
|
||||
|
||||
public override Json.Node? get_json_node()
|
||||
throws Matrix.Error;
|
||||
}
|
||||
|
||||
/* Utilities */
|
||||
[CCode (cheader_filename = "utils.h", cname = "_matrix_g_enum_to_string")]
|
||||
public string? _g_enum_value_to_nick(GLib.Type enum_type, int value, char convert_dashes = '_');
|
||||
|
||||
[CCode (cheader_filename = "utils.h", cname = "_matrix_g_enum_nick_to_value")]
|
||||
public int _g_enum_nick_to_value(GLib.Type enum_type, string nick)
|
||||
throws Matrix.Error;
|
||||
|
||||
[CCode (cheader_filename = "utils.h", cname = "_matrix_json_node_deep_copy")]
|
||||
public Json.Node? _json_node_deep_copy(Json.Node? node);
|
||||
|
||||
[CCode (cheader_filename = "matrix-profile.h")]
|
||||
public class Profile : GLib.Object {
|
||||
public GLib.TimeSpan age {get;}
|
||||
public string? avatar_url {get; set;}
|
||||
public string? display_name {get; set;}
|
||||
|
||||
public Profile();
|
||||
}
|
||||
|
||||
/**
|
||||
* The major version number of the Matrix.org GLib SDK.
|
||||
*/
|
||||
[CCode (cheader_filename = "matrix-version.h", cname = "MATRIX_GLIB_MAJOR_VERSION")]
|
||||
public const int GLIB_MAJOR_VERSION;
|
||||
|
||||
/**
|
||||
* The micro (patch) version number of the Matrix.org GLib SDK.
|
||||
*/
|
||||
[CCode (cheader_filename = "matrix-version.h", cname = "MATRIX_GLIB_MINOR_VERSION")]
|
||||
public const int GLIB_MINOR_VERSION;
|
||||
|
||||
/**
|
||||
* The minor version number of the Matrix.org GLib SDK.
|
||||
*/
|
||||
[CCode (cheader_filename = "matrix-version.h", cname = "MATRIX_GLIB_MICRO_VERSION")]
|
||||
public const int GLIB_MICRO_VERSION;
|
||||
|
||||
/**
|
||||
* Check that the Matrix.org GLib SDK in use is compatible with
|
||||
* the given version.
|
||||
*
|
||||
* @param required_major the required major version
|
||||
* @param required_minor the required minor version
|
||||
* @param required_micro the required micro version
|
||||
* @return {{{true}}} if the required version is satisfied; {{{false}}} otherwise.
|
||||
*/
|
||||
[CCode (cheader_filename = "matrix-version.h", cname = "matrix_glib_check_version")]
|
||||
public bool glib_check_version(uint required_major,
|
||||
uint required_minor,
|
||||
uint required_micro);
|
||||
}
|
@@ -16,7 +16,7 @@
|
||||
* <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Abstract base class for room events.
|
||||
*/
|
||||
public abstract class Matrix.RoomEvent : Matrix.Event {}
|
||||
[CCode (cprefix = "", lower_case_cprefix = "", cheader_filename = "config.h")]
|
||||
namespace Config {
|
||||
public const bool DEBUG;
|
||||
}
|
Reference in New Issue
Block a user