1 Commits

Author SHA1 Message Date
Gergely Polonkai
0d024b6885 Start working on the GObject generator for event types 2016-03-04 17:09:16 +00:00
110 changed files with 5043 additions and 13154 deletions

51
.gitignore vendored
View File

@@ -37,7 +37,6 @@ 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
@@ -49,45 +48,15 @@ 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-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
/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/object-generator

View File

@@ -1,79 +0,0 @@
# 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/

View File

@@ -1,114 +0,0 @@
# 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!

View File

@@ -22,35 +22,8 @@ object model to perform actions on.
## Client
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
The `MatrixClient` interface is not fully planned yet.
## API
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.
For a full blown example, see [test-client.c](src/test-client.c).

View File

@@ -90,6 +90,7 @@ 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
@@ -103,6 +104,9 @@ 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])
@@ -169,7 +173,7 @@ AC_ARG_ENABLE(debug,
AM_CONDITIONAL([DEBUG], [test $debug = yes])
if test x"$debug" = x"$enableval"; then
AC_DEFINE([DEBUG], [1], [Define as 1 if debugging should be enabled])
AC_DEFINE([DEBUG], [1], [Define if debugging should be enabled])
if test x"$cflags_set" != x"set"; then
case " $CFLAGS " in
@@ -177,8 +181,6 @@ 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)
@@ -194,14 +196,11 @@ 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

View File

@@ -0,0 +1,105 @@
## 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

View File

@@ -0,0 +1,49 @@
<?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>

View File

@@ -0,0 +1,462 @@
<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>

View File

@@ -0,0 +1 @@
@MATRIX_GLIB_API_VERSION@

44
schemas/m.call.answer Normal file
View File

@@ -0,0 +1,44 @@
{
"type": "object",
"description": "This event is sent by the callee when they wish to answer the call.",
"allOf": [{
"$ref": "core-event-schema/room_event.yaml"
}],
"properties": {
"content": {
"type": "object",
"properties": {
"call_id": {
"type": "string",
"description": "The ID of the call this event relates to."
},
"answer": {
"type": "object",
"title": "Answer",
"description": "The session description object",
"properties": {
"type": {
"type": "string",
"enum": ["answer"],
"description": "The type of session description."
},
"sdp": {
"type": "string",
"description": "The SDP text of the session description."
}
},
"required": ["type", "sdp"]
},
"version": {
"type": "number",
"description": ""
}
},
"required": ["call_id", "answer", "version"]
},
"type": {
"type": "string",
"enum": ["m.call.answer"]
}
}
}

50
schemas/m.call.candidates Normal file
View File

@@ -0,0 +1,50 @@
{
"type": "object",
"description": "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.",
"allOf": [{
"$ref": "core-event-schema/room_event.yaml"
}],
"properties": {
"content": {
"type": "object",
"properties": {
"call_id": {
"type": "string",
"description": "The ID of the call this event relates to."
},
"candidates": {
"type": "array",
"description": "Array of objects describing the candidates.",
"items": {
"type": "object",
"title": "Candidate",
"properties": {
"sdpMid": {
"type": "string",
"description": "The SDP media type this candidate is intended for."
},
"sdpMLineIndex": {
"type": "number",
"description": "The index of the SDP 'm' line this candidate is intended for."
},
"candidate": {
"type": "string",
"description": "The SDP 'a' line of the candidate."
}
},
"required": ["candidate", "sdpMLineIndex", "sdpMid"]
}
},
"version": {
"type": "integer",
"description": "The version of the VoIP specification this messages adheres to. This specification is version 0."
}
},
"required": ["call_id", "candidates", "version"]
},
"type": {
"type": "string",
"enum": ["m.call.candidates"]
}
}
}

27
schemas/m.call.hangup Normal file
View File

@@ -0,0 +1,27 @@
{
"type": "object",
"description": "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.",
"allOf": [{
"$ref": "core-event-schema/room_event.yaml"
}],
"properties": {
"content": {
"type": "object",
"properties": {
"call_id": {
"type": "string",
"description": "The ID of the call this event relates to."
},
"version": {
"type": "integer",
"description": "The version of the VoIP specification this message adheres to. This specification is version 0."
}
},
"required": ["call_id", "version"]
},
"type": {
"type": "string",
"enum": ["m.call.hangup"]
}
}
}

48
schemas/m.call.invite Normal file
View File

@@ -0,0 +1,48 @@
{
"type": "object",
"description": "This event is sent by the caller when they wish to establish a call.",
"allOf": [{
"$ref": "core-event-schema/room_event.yaml"
}],
"properties": {
"content": {
"type": "object",
"properties": {
"call_id": {
"type": "string",
"description": "A unique identifer for the call."
},
"offer": {
"type": "object",
"title": "Offer",
"description": "The session description object",
"properties": {
"type": {
"type": "string",
"enum": ["offer"],
"description": "The type of session description."
},
"sdp": {
"type": "string",
"description": "The SDP text of the session description."
}
},
"required": ["type", "sdp"]
},
"version": {
"type": "integer",
"description": "The version of the VoIP specification this message adheres to. This specification is version 0."
},
"lifetime": {
"type": "integer",
"description": "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."
}
},
"required": ["call_id", "offer", "version", "lifetime"]
},
"type": {
"type": "string",
"enum": ["m.call.invite"]
}
}
}

42
schemas/m.presence Normal file
View File

@@ -0,0 +1,42 @@
{
"type": "object",
"title": "Presence Event",
"description": "Informs the client of a user's presence state change.",
"properties": {
"content": {
"type": "object",
"properties": {
"avatar_url": {
"type": "string",
"description": "The current avatar URL for this user, if any."
},
"displayname": {
"type": "string",
"description": "The current display name for this user, if any."
},
"last_active_ago": {
"type": "number",
"description": "The last time since this used performed some action, in milliseconds."
},
"presence": {
"type": "string",
"description": "The presence state for this user.",
"enum": ["online", "offline", "unavailable", "free_for_chat", "hidden"]
},
"user_id": {
"type": "string",
"description": "The user's ID."
}
},
"required": ["presence", "user_id"]
},
"type": {
"type": "string",
"enum": ["m.presence"]
},
"event_id": {
"type": "string"
}
},
"required": ["event_id", "type", "content"]
}

48
schemas/m.receipt Normal file
View File

@@ -0,0 +1,48 @@
{
"type": "object",
"title": "Receipt Event",
"description": "Informs the client of new receipts.",
"properties": {
"content": {
"type": "object",
"patternProperties": {
"^\\$": {
"type": "object",
"x-pattern": "$EVENT_ID",
"title": "Receipts",
"description": "The mapping of event ID to a collection of receipts for this event ID. The event ID is the ID of the event being acknowledged and *not* an ID for the receipt itself.",
"properties": {
"m.read": {
"type": "object",
"title": "Users",
"description": "A collection of users who have sent ``m.read`` receipts for this event.",
"patternProperties": {
"^@": {
"type": "object",
"title": "Receipt",
"description": "The mapping of user ID to receipt. The user ID is the entity who sent this receipt.",
"x-pattern": "$USER_ID",
"properties": {
"ts": {
"type": "number",
"description": "The timestamp the receipt was sent at."
}
}
}
}
}
}
}
},
"additionalProperties": false
},
"type": {
"type": "string",
"enum": ["m.receipt"]
},
"room_id": {
"type": "string"
}
},
"required": ["room_id", "type", "content"]
}

31
schemas/m.room.aliases Normal file
View File

@@ -0,0 +1,31 @@
{
"type": "object",
"title": "Informs the room about what room aliases it has been given.",
"description": "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.",
"allOf": [{
"$ref": "core-event-schema/state_event.yaml"
}],
"properties": {
"content": {
"type": "object",
"properties": {
"aliases": {
"type": "array",
"description": "A list of room aliases.",
"items": {
"type": "string"
}
}
},
"required": ["aliases"]
},
"state_key": {
"type": "string",
"description": "The homeserver domain which owns these room aliases."
},
"type": {
"type": "string",
"enum": ["m.room.aliases"]
}
}
}

64
schemas/m.room.avatar Normal file
View File

@@ -0,0 +1,64 @@
{
"title": "RoomAvatar",
"description": "A picture that is associated with the room. This can be displayed alongside the room information.",
"type": "object",
"allOf": [{
"$ref": "core-event-schema/state_event.yaml"
}],
"properties": {
"content": {
"type": "object",
"properties": {
"url": {
"type": "string",
"description": "The URL to the image."
},
"thumbnail_url": {
"type": "string",
"description": "The URL to the thumbnail of the image."
},
"thumbnail_info": {
"type": "object",
"title": "ImageInfo",
"description": "Metadata about the image referred to in ``thumbnail_url``.",
"allOf": [{
"$ref": "core-event-schema/msgtype_infos/image_info.yaml"
}]
},
"info": {
"type": "object",
"title": "ImageInfo",
"description": "Metadata about the image referred to in ``url``.",
"properties": {
"size": {
"type": "integer",
"description": "Size of the image in bytes."
},
"w": {
"type": "integer",
"description": "The width of the image in pixels."
},
"h": {
"type": "integer",
"description": "The height of the image in pixels."
},
"mimetype": {
"type": "string",
"description": "The mimetype of the image, e.g. ``image/jpeg``."
}
}
}
},
"required": ["url"]
},
"state_key": {
"type": "string",
"description": "A zero-length string.",
"pattern": "^$"
},
"type": {
"type": "string",
"enum": ["m.room.avatar"]
}
}
}

View File

@@ -0,0 +1,28 @@
{
"type": "object",
"title": "Informs the room as to which alias is the canonical one.",
"description": "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.",
"allOf": [{
"$ref": "core-event-schema/state_event.yaml"
}],
"properties": {
"content": {
"type": "object",
"properties": {
"alias": {
"type": "string",
"description": "The canonical alias."
}
}
},
"state_key": {
"type": "string",
"description": "A zero-length string.",
"pattern": "^$"
},
"type": {
"type": "string",
"enum": ["m.room.canonical_alias"]
}
}
}

33
schemas/m.room.create Normal file
View File

@@ -0,0 +1,33 @@
{
"type": "object",
"title": "The first event in the room.",
"description": "This is the first event in a room and cannot be changed. It acts as the root of all other events.",
"allOf": [{
"$ref": "core-event-schema/state_event.yaml"
}],
"properties": {
"content": {
"type": "object",
"properties": {
"creator": {
"type": "string",
"description": "The ``user_id`` of the room creator. This is set by the homeserver."
},
"m.federate": {
"type": "boolean",
"description": "Whether users on other servers can join this room. Defaults to ``true`` if key does not exist."
}
},
"required": ["creator"]
},
"state_key": {
"type": "string",
"description": "A zero-length string.",
"pattern": "^$"
},
"type": {
"type": "string",
"enum": ["m.room.create"]
}
}
}

View File

@@ -0,0 +1,30 @@
{
"type": "object",
"title": "Controls whether guest users are allowed to join rooms.",
"description": "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\".",
"allOf": [{
"$ref": "core-event-schema/state_event.yaml"
}],
"properties": {
"content": {
"type": "object",
"properties": {
"guest_access": {
"type": "string",
"description": "Whether guests can join the room.",
"enum": ["can_join", "forbidden"]
}
},
"required": ["guest_access"]
},
"state_key": {
"type": "string",
"description": "A zero-length string.",
"pattern": "^$"
},
"type": {
"type": "string",
"enum": ["m.room.guest_access"]
}
}
}

View File

@@ -0,0 +1,30 @@
{
"type": "object",
"title": "Controls visibility of history.",
"description": "This event controls whether a user can see the events that happened in a room from before they joined.",
"allOf": [{
"$ref": "core-event-schema/state_event.yaml"
}],
"properties": {
"content": {
"type": "object",
"properties": {
"history_visibility": {
"type": "string",
"description": "Who can see the room history.",
"enum": ["invited","joined","shared","world_readable"]
}
},
"required": ["history_visibility"]
},
"state_key": {
"type": "string",
"description": "A zero-length string.",
"pattern": "^$"
},
"type": {
"type": "string",
"enum": ["m.room.history_visibility"]
}
}
}

30
schemas/m.room.join_rules Normal file
View File

@@ -0,0 +1,30 @@
{
"type": "object",
"title": "Describes how users are allowed to join the room.",
"description": "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.",
"allOf": [{
"$ref": "core-event-schema/state_event.yaml"
}],
"properties": {
"content": {
"type": "object",
"properties": {
"join_rule": {
"type": "string",
"description": "The type of rules used for users wishing to join this room.",
"enum": ["public","knock","invite","private"]
}
},
"required": ["join_rule"]
},
"state_key": {
"type": "string",
"description": "A zero-length string.",
"pattern": "^$"
},
"type": {
"type": "string",
"enum": ["m.room.join_rules"]
}
}
}

96
schemas/m.room.member Normal file
View File

@@ -0,0 +1,96 @@
{
"type": "object",
"title": "The current membership state of a user in the room.",
"description": "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. \n\nThe following membership states are specified:\n\n- ``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.\n\n- ``join`` - The user has joined the room (possibly after accepting an invite), and may participate in it.\n\n- ``leave`` - The user was once joined to the room, but has since left (possibly by choice, or possibly by being kicked).\n\n- ``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``).\n\n- ``knock`` - This is a reserved word, which currently has no meaning.\n\nThe ``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.\n\nThis event may also include an ``invite_room_state`` key **outside the** ``content`` **key**. If present, this contains an array of ``StrippedState`` Events. These events provide information on a few select state events such as the room name.",
"allOf": [{
"$ref": "core-event-schema/state_event.yaml"
}],
"properties": {
"content": {
"type": "object",
"title": "EventContent",
"properties": {
"membership": {
"type": "string",
"description": "The membership state of the user.",
"enum": ["invite","join","knock","leave","ban"]
},
"avatar_url": {
"type": "string",
"description": "The avatar URL for this user, if any. This is added by the homeserver."
},
"displayname": {
"type": ["string", "null"],
"description": "The display name for this user, if any. This is added by the homeserver."
},
"third_party_invite": {
"type": "object",
"title": "Invite",
"properties": {
"display_name": {
"type": "string",
"description": "A name which can be displayed to represent the user instead of their third party identifier"
},
"signed": {
"type": "object",
"title": "signed",
"description": "A block of content which has been signed, which servers can use to verify the event. Clients should ignore this.",
"properties": {
"mxid": {
"type": "string",
"description": "The invited matrix user ID. Must be equal to the user_id property of the event."
},
"token": {
"type": "string",
"description": "The token property of the containing third_party_invite object."
},
"signatures": {
"type": "object",
"description": "A single signature from the verifying server, in the format specified by the Signing Events section of the server-server API.",
"title": "Signatures"
}
},
"required": ["mxid", "signatures", "token"]
}
},
"required": ["display_name", "signed"]
}
},
"required": ["membership"]
},
"state_key": {
"type": "string",
"description": "The ``user_id`` this membership event relates to."
},
"type": {
"type": "string",
"enum": ["m.room.member"]
},
"invite_room_state": {
"type": "array",
"description": "A subset of the state of the room at the time of the invite, if ``membership`` is ``invite``",
"items": {
"type": "object",
"title": "StrippedState",
"description": "A stripped down state event, with only the ``type``, ``state_key`` and ``content`` keys.",
"required": ["type", "state_key", "content"],
"properties": {
"type": {
"type": "string",
"description": "The ``type`` for the event.",
"enum": ["m.room.join_rules", "m.room.canonical_alias", "m.room.avatar", "m.room.name"]
},
"state_key": {
"type": "string",
"description": "The ``state_key`` for the event."
},
"content": {
"title": "EventContent",
"type": "object",
"description": "The ``content`` for the event."
}
}
}
}
}
}

28
schemas/m.room.message Normal file
View File

@@ -0,0 +1,28 @@
{
"type": "object",
"title": "Message",
"description": "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.",
"allOf": [{
"$ref": "core-event-schema/room_event.yaml"
}],
"properties": {
"content": {
"type": "object",
"properties": {
"msgtype": {
"type": "string",
"description": "The type of message, e.g. ``m.image``, ``m.text``"
},
"body": {
"type": "string",
"description": "The textual representation of this message."
}
},
"required": ["msgtype", "body"]
},
"type": {
"type": "string",
"enum": ["m.room.message"]
}
}
}

View File

@@ -0,0 +1,51 @@
{
"type": "object",
"title": "AudioMessage",
"description": "This message represents a single audio clip.",
"allOf": [{
"$ref": "core-event-schema/room_event.yaml"
}],
"properties": {
"content": {
"type": "object",
"properties": {
"msgtype": {
"type": "string",
"enum": ["m.audio"]
},
"body": {
"type": "string",
"description": "A description of the audio e.g. 'Bee Gees - Stayin' Alive', or some kind of content description for accessibility e.g. 'audio attachment'."
},
"url": {
"type": "string",
"description": "The URL to the audio clip."
},
"info": {
"type": "object",
"title": "AudioInfo",
"description": "Metadata for the audio clip referred to in ``url``.",
"properties": {
"mimetype": {
"type": "string",
"description": "The mimetype of the audio e.g. ``audio/aac``."
},
"size": {
"type": "integer",
"description": "The size of the audio clip in bytes."
},
"duration": {
"type": "integer",
"description": "The duration of the audio in milliseconds."
}
}
}
},
"required": ["msgtype", "body", "url"]
},
"type": {
"type": "string",
"enum": ["m.room.message"]
}
}
}

View File

@@ -0,0 +1,28 @@
{
"type": "object",
"title": "EmoteMessage",
"description": "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.",
"allOf": [{
"$ref": "core-event-schema/room_event.yaml"
}],
"properties": {
"content": {
"type": "object",
"properties": {
"msgtype": {
"type": "string",
"enum": ["m.emote"]
},
"body": {
"type": "string",
"description": "The emote action to perform."
}
},
"required": ["msgtype", "body"]
},
"type": {
"type": "string",
"enum": ["m.room.message"]
}
}
}

View File

@@ -0,0 +1,63 @@
{
"type": "object",
"title": "FileMessage",
"description": "This message represents a generic file.",
"allOf": [{
"$ref": "core-event-schema/room_event.yaml"
}],
"properties": {
"content": {
"type": "object",
"properties": {
"msgtype": {
"type": "string",
"enum": ["m.file"]
},
"filename": {
"type": "string",
"description": "The original filename of the uploaded file."
},
"body": {
"type": "string",
"description": "A human-readable description of the file. This is recommended to be the filename of the original upload."
},
"url": {
"type": "string",
"description": "The URL to the file."
},
"info": {
"type": "object",
"title": "FileInfo",
"description": "Information about the file referred to in ``url``.",
"properties": {
"size": {
"type": "integer",
"description": "The size of the file in bytes."
},
"mimetype": {
"type": "string",
"description": "The mimetype of the file e.g. ``application/msword``."
}
}
},
"thumbnail_url": {
"type": "string",
"description": "The URL to the thumbnail of the file."
},
"thumbnail_info": {
"type": "object",
"title": "ImageInfo",
"description": "Metadata about the image referred to in ``thumbnail_url``.",
"allOf": [{
"$ref": "core-event-schema/msgtype_infos/image_info.yaml"
}]
}
},
"required": ["msgtype", "body", "url", "filename"]
},
"type": {
"type": "string",
"enum": ["m.room.message"]
}
}
}

View File

@@ -0,0 +1,67 @@
{
"type": "object",
"title": "ImageMessage",
"description": "This message represents a single image and an optional thumbnail.",
"allOf": [{
"$ref": "core-event-schema/room_event.yaml"
}],
"properties": {
"content": {
"type": "object",
"properties": {
"msgtype": {
"type": "string",
"enum": ["m.image"]
},
"body": {
"type": "string",
"description": "A textual representation of the image. This could be the alt text of the image, the filename of the image, or some kind of content description for accessibility e.g. 'image attachment'."
},
"url": {
"type": "string",
"description": "The URL to the image."
},
"thumbnail_url": {
"type": "string",
"description": "The URL to the thumbnail of the image."
},
"thumbnail_info": {
"type": "object",
"title": "ImageInfo",
"description": "Metadata about the image referred to in ``thumbnail_url``.",
"allOf": [{
"$ref": "core-event-schema/msgtype_infos/image_info.yaml"
}]
},
"info": {
"type": "object",
"title": "ImageInfo",
"description": "Metadata about the image referred to in ``url``.",
"properties": {
"size": {
"type": "integer",
"description": "Size of the image in bytes."
},
"w": {
"type": "integer",
"description": "The width of the image in pixels."
},
"h": {
"type": "integer",
"description": "The height of the image in pixels."
},
"mimetype": {
"type": "string",
"description": "The mimetype of the image, e.g. ``image/jpeg``."
}
}
}
},
"required": ["msgtype", "body", "url"]
},
"type": {
"type": "string",
"enum": ["m.room.message"]
}
}
}

View File

@@ -0,0 +1,43 @@
{
"type": "object",
"title": "LocationMessage",
"description": "This message represents a real-world location.",
"allOf": [{
"$ref": "core-event-schema/room_event.yaml"
}],
"properties": {
"content": {
"type": "object",
"properties": {
"msgtype": {
"type": "string",
"enum": ["m.location"]
},
"body": {
"type": "string",
"description": "A description of the location e.g. 'Big Ben, London, UK', or some kind of content description for accessibility e.g. 'location attachment'."
},
"geo_uri": {
"type": "string",
"description": "A geo URI representing this location."
},
"thumbnail_url": {
"type": "string",
"description": "The URL to a thumbnail of the location being represented."
},
"thumbnail_info": {
"type": "object",
"title": "ImageInfo",
"allOf": [{
"$ref": "core-event-schema/msgtype_infos/image_info.yaml"
}]
}
},
"required": ["msgtype", "body", "geo_uri"]
},
"type": {
"type": "string",
"enum": ["m.room.message"]
}
}
}

View File

@@ -0,0 +1,28 @@
{
"type": "object",
"title": "NoticeMessage",
"description": "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.",
"allOf": [{
"$ref": "core-event-schema/room_event.yaml"
}],
"properties": {
"content": {
"type": "object",
"properties": {
"msgtype": {
"type": "string",
"enum": ["m.notice"]
},
"body": {
"type": "string",
"description": "The notice text to send."
}
},
"required": ["msgtype", "body"]
},
"type": {
"type": "string",
"enum": ["m.room.message"]
}
}
}

View File

@@ -0,0 +1,28 @@
{
"type": "object",
"title": "TextMessage",
"description": "This message is the most basic message and is used to represent text.",
"allOf": [{
"$ref": "core-event-schema/room_event.yaml"
}],
"properties": {
"content": {
"type": "object",
"properties": {
"msgtype": {
"type": "string",
"enum": ["m.text"]
},
"body": {
"type": "string",
"description": "The body of the message."
}
},
"required": ["msgtype", "body"]
},
"type": {
"type": "string",
"enum": ["m.room.message"]
}
}
}

View File

@@ -0,0 +1,70 @@
{
"type": "object",
"title": "VideoMessage",
"description": "This message represents a single video clip.",
"allOf": [{
"$ref": "core-event-schema/room_event.yaml"
}],
"properties": {
"content": {
"type": "object",
"properties": {
"msgtype": {
"type": "string",
"enum": ["m.video"]
},
"body": {
"type": "string",
"description": "A description of the video e.g. 'Gangnam style', or some kind of content description for accessibility e.g. 'video attachment'."
},
"url": {
"type": "string",
"description": "The URL to the video clip."
},
"info": {
"type": "object",
"title": "VideoInfo",
"description": "Metadata about the video clip referred to in ``url``.",
"properties": {
"mimetype": {
"type": "string",
"description": "The mimetype of the video e.g. ``video/mp4``."
},
"size": {
"type": "integer",
"description": "The size of the video in bytes."
},
"duration": {
"type": "integer",
"description": "The duration of the video in milliseconds."
},
"w": {
"type": "integer",
"description": "The width of the video in pixels."
},
"h": {
"type": "integer",
"description": "The height of the video in pixels."
},
"thumbnail_url": {
"type": "string",
"description": "The URL to a thumbnail of the video clip."
},
"thumbnail_info": {
"type": "object",
"title": "ImageInfo",
"allOf": [{
"$ref": "core-event-schema/msgtype_infos/image_info.yaml"
}]
}
}
}
},
"required": ["msgtype", "body", "url"]
},
"type": {
"type": "string",
"enum": ["m.room.message"]
}
}
}

View File

@@ -0,0 +1,29 @@
{
"type": "object",
"title": "MessageFeedback",
"description": "**NB: 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.",
"allOf": [{
"$ref": "core-event-schema/room_event.yaml"
}],
"properties": {
"content": {
"type": "object",
"properties": {
"type": {
"type": "string",
"description": "The type of feedback.",
"enum": ["delivered", "read"]
},
"target_event_id": {
"type": "string",
"description": "The event that this feedback is related to."
}
},
"required": ["type", "target_event_id"]
},
"type": {
"type": "string",
"enum": ["m.room.message.feedback"]
}
}
}

29
schemas/m.room.name Normal file
View File

@@ -0,0 +1,29 @@
{
"title": "RoomName",
"description": "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.",
"type": "object",
"allOf": [{
"$ref": "core-event-schema/state_event.yaml"
}],
"properties": {
"content": {
"type": "object",
"properties": {
"name": {
"type": "string",
"description": "The name of the room. This MUST NOT exceed 255 bytes."
}
},
"required": ["name"]
},
"state_key": {
"type": "string",
"description": "A zero-length string.",
"pattern": "^$"
},
"type": {
"type": "string",
"enum": ["m.room.name"]
}
}
}

View File

@@ -0,0 +1,66 @@
{
"type": "object",
"title": "Defines the power levels (privileges) of users in the room.",
"description": "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.",
"allOf": [{
"$ref": "core-event-schema/state_event.yaml"
}],
"properties": {
"content": {
"type": "object",
"properties": {
"ban": {
"type": "number",
"description": "The level required to ban a user."
},
"events_default": {
"type": "number",
"description": "The default level required to send message events. Can be overridden by the ``events`` key."
},
"kick": {
"type": "number",
"description": "The level required to kick a user."
},
"redact": {
"type": "number",
"description": "The level required to redact an event."
},
"state_default": {
"type": "number",
"description": "The default level required to send state events. Can be overridden by the ``events`` key."
},
"users_default": {
"type": "number",
"description": "The default power level for every user in the room, unless their ``user_id`` is mentioned in the ``users`` key."
},
"events": {
"type": "object",
"title": "Event power levels",
"description": "The level required to send specific event types. This is a mapping from event type to power level required.",
"additionalProperties": {
"type": "number"
}
},
"users": {
"type": "object",
"title": "User power levels",
"description": "The power levels for specific users. This is a mapping from ``user_id`` to power level for that user.",
"additionalProperties": {
"type": "number"
}
}
},
"required": ["ban","events","events_default","kick","redact",
"state_default","users"]
},
"state_key": {
"type": "string",
"description": "A zero-length string.",
"pattern": "^$"
},
"type": {
"type": "string",
"enum": ["m.room.power_levels"]
}
}
}

28
schemas/m.room.redaction Normal file
View File

@@ -0,0 +1,28 @@
{
"type": "object",
"title": "Redaction",
"description": "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.",
"allOf": [{
"$ref": "core-event-schema/room_event.yaml"
}],
"properties": {
"content": {
"type": "object",
"properties": {
"reason": {
"type": "string",
"description": "The reason for the redaction, if any."
}
}
},
"redacts": {
"type": "string",
"description": "The event ID that was redacted."
},
"type": {
"type": "string",
"enum": ["m.room.redaction"]
}
},
"required": ["redacts"]
}

View File

@@ -0,0 +1,56 @@
{
"$schema": "http://json-schema.org/draft-04/schema#",
"type": "object",
"title": "An invitation to a room issued to a third party identifier, rather than a matrix user ID.",
"description": "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.",
"allOf": [{
"$ref": "core-event-schema/state_event.yaml"
}],
"properties": {
"content": {
"type": "object",
"properties": {
"display_name": {
"type": "string",
"description": "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."
},
"key_validity_url": {
"type": "string",
"description": "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_key": {
"type": "string",
"description": "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_keys": {
"type": "array",
"description": "Keys with which the token may be signed.",
"items": {
"type": "object",
"title": "PublicKeys",
"properties": {
"public_key": {
"type": "string",
"description": "A base-64 encoded ed25519 key with which token may be signed."
},
"key_validity_url": {
"type": "string",
"description": "An optional 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'. If this URL is absent, the key must be considered valid indefinitely."
}
},
"required": ["public_key"]
}
}
},
"required": ["display_name", "key_validity_url", "public_key"]
},
"state_key": {
"type": "string",
"description": "The token, of which a signature must be produced in order to join the room."
},
"type": {
"type": "string",
"enum": ["m.room.third_party_invite"]
}
}
}

29
schemas/m.room.topic Normal file
View File

@@ -0,0 +1,29 @@
{
"type": "object",
"title": "Topic",
"description": "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. The room topic can also be set when creating a room using ``/createRoom`` with the ``topic`` key.",
"allOf": [{
"$ref": "core-event-schema/state_event.yaml"
}],
"properties": {
"content": {
"type": "object",
"properties": {
"topic": {
"type": "string",
"description": "The topic text."
}
},
"required": ["topic"]
},
"state_key": {
"type": "string",
"description": "A zero-length string.",
"pattern": "^$"
},
"type": {
"type": "string",
"enum": ["m.room.topic"]
}
}
}

25
schemas/m.tag Normal file
View File

@@ -0,0 +1,25 @@
{
"type": "object",
"title": "Tag Event",
"description": "Informs the client of tags on a room.",
"properties": {
"type": {
"type": "string",
"enum": ["m.tag"]
},
"content": {
"type": "object",
"properties": {
"tags": {
"type": "object",
"description": "The tags on the room and their contents.",
"additionalProperties": {
"title": "Tag",
"type": "object"
}
}
}
}
},
"required": ["type", "content"]
}

28
schemas/m.typing Normal file
View File

@@ -0,0 +1,28 @@
{
"type": "object",
"title": "Typing Event",
"description": "Informs the client of the list of users currently typing.",
"properties": {
"content": {
"type": "object",
"properties": {
"user_ids": {
"type": "array",
"items": {
"type": "string"
},
"description": "The list of user IDs typing in this room, if any."
}
},
"required": ["user_ids"]
},
"type": {
"type": "string",
"enum": ["m.typing"]
},
"room_id": {
"type": "string"
}
},
"required": ["type", "room_id", "content"]
}

View File

@@ -16,48 +16,18 @@ 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-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 \
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 \
$(NULL)
AM_CPPFLAGS += \
@@ -69,6 +39,7 @@ AM_CPPFLAGS += \
$(GOBJECT_CFLAGS) \
$(SOUP_CFLAGS) \
$(JSON_CFLAGS) \
$(GEE_CFLAGS) \
$(VALA_CFLAGS) \
$(NULL)
@@ -80,7 +51,7 @@ AM_VALAFLAGS += \
-C \
--use-header \
--gir=Matrix-$(MATRIX_GLIB_API_VERSION).gir \
--vapidir=$(top_srcdir)/vapi \
$(top_srcdir)/src/c-api.vapi \
$(NULL)
vala-stamp: $(libmatrix_glib_0_0_la_VALA_SOURCES)
@@ -111,33 +82,19 @@ $(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)
@@ -146,6 +103,7 @@ libmatrix_glib_0_0_la_CFLAGS = \
$(GOBJECT_CFLAGS) \
$(SOUP_CFLAGS) \
$(JSON_CFLAGS) \
$(GEE_CFLAGS) \
$(NULL)
libmatrix_glib_0_0_la_LIBADD = \
@@ -153,6 +111,7 @@ libmatrix_glib_0_0_la_LIBADD = \
$(GOBJECT_LIBS) \
$(SOUP_LIBS) \
$(JSON_LIBS) \
$(GEE_LIBS) \
$(NULL)
libmatrix_glib_0_0_la_LDFLAGS = \
@@ -168,8 +127,6 @@ dist_vapi_DATA = \
$(NULL)
BUILT_SOURCES += \
matrix-enumtypes.c \
matrix-enumtypes.h \
matrix-marshalers.c \
matrix-marshalers.h \
$(NULL)
@@ -190,22 +147,10 @@ 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
@@ -231,22 +176,11 @@ matrix-marshalers.c: matrix-marshalers.h
CLEANFILES += stamp-matrix-marshalers
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)
include $(INTROSPECTION_MAKEFILE)
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 = \
@@ -255,7 +189,4 @@ header_DATA = \
$(INST_H_BUILT_FILES) \
$(NULL)
pkgconfig_in = matrix-glib-$(MATRIX_GLIB_API_VERSION).pc.in
pkgconfigdir = $(libdir)/pkgconfig
pkgconfig_DATA = $(pkgconfig_in:.in=)
EXTRA_DIST += $(pkgconfig_in)
CLEANFILES += $(typelibs_DATA)

View File

@@ -1,3 +1,4 @@
gio-2.0
Json-1.0
gee-0.8
libsoup-2.4

52
src/c-api.vapi Normal file
View File

@@ -0,0 +1,52 @@
/*
* 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);
}

File diff suppressed because it is too large Load Diff

View File

@@ -47,27 +47,9 @@ public interface Matrix.Client : GLib.Object {
*/
[Signal (detailed=true)]
public virtual signal void
@event(string? room_id,
Json.Node raw_event,
Matrix.Event.Base? matrix_event)
@event(string? room_id, Json.Node raw_event, Matrix.Event 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.
*
@@ -79,7 +61,7 @@ public interface Matrix.Client : GLib.Object {
EventCallback(Matrix.Client client,
string? room_id,
Json.Node raw_event,
Matrix.Event.Base? matrix_event);
Matrix.Event matrix_event);
/**
* Authenticate with the Matrix.org server with a username and
@@ -162,15 +144,9 @@ public interface Matrix.Client : GLib.Object {
public void
incoming_event(string? room_id,
Json.Node raw_event,
Matrix.Event.Base? matrix_event)
Matrix.Event matrix_event)
{
Quark equark;
if (matrix_event == null) {
equark = typeof(Matrix.Event.Base).qname();
} else {
equark = matrix_event.get_type().qname();
}
Quark equark = matrix_event.get_type().qname();
this.@event[equark.to_string()](room_id, raw_event, matrix_event);
}
@@ -185,103 +161,9 @@ public interface Matrix.Client : GLib.Object {
*
* @param event_gtype the {@link GLib.Type} of a
* {@link Matrix.Event} derivative
* @param event_callback the allback function to connect
* @param 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;
}

File diff suppressed because it is too large Load Diff

View File

@@ -1,236 +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/>.
*/
#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__ */

941
src/matrix-compacts.vala Normal file
View File

@@ -0,0 +1,941 @@
/*
* 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 dont 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;
}
}

227
src/matrix-enums.vala Normal file
View File

@@ -0,0 +1,227 @@
/*
* 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 doesnt 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 {{==}}}, {{{&lt;}}}, {{{&gt;}}}, {{{&lt;=}}} or {{{&gt;=}}}. 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;
}
}
}

View File

@@ -1,59 +0,0 @@
/*** 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 ***/

View File

@@ -1,42 +0,0 @@
/*** 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 ***/

View File

@@ -1,322 +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/>.
*/
/**
* 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, lets
// 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 events 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);
}
}
}

View File

@@ -1,100 +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/>.
*/
/**
* 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);
}
}

View File

@@ -1,78 +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/>.
*/
/**
* 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);
}
}

View File

@@ -1,132 +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/>.
*/
/**
* 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);
}
}

View File

@@ -1,38 +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/>.
*/
/**
* 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);
}
}

View File

@@ -1,122 +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/>.
*/
/**
* 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);
}
}

View File

@@ -1,159 +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
*
* 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 wont 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);
}
}

View File

@@ -1,171 +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 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);
}
}

View File

@@ -1,87 +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 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);
}
}

View File

@@ -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 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);
}
}

View File

@@ -1,147 +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/>.
*/
/**
* 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);
}
}

View File

@@ -1,71 +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 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);
}
}

View File

@@ -1,86 +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 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);
}
}

View File

@@ -1,92 +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 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);
}
}

View File

@@ -1,89 +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 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);
}
}

View File

@@ -1,89 +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 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);
}
}

View File

@@ -1,315 +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
*
* 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);
}
}

View File

@@ -1,84 +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 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 doesnt 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);
}
}

View File

@@ -1,90 +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 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);
}
}

View File

@@ -1,76 +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 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);
}
}

View File

@@ -1,232 +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 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;
}
}

View File

@@ -1,85 +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 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);
}
}

View File

@@ -1,177 +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 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);
}
}

View File

@@ -1,74 +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/>.
*/
/**
* 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);
}
}

View File

@@ -1,95 +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 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;
}
}

View File

@@ -1,69 +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.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);
}
}

View File

@@ -153,98 +153,13 @@ static void
matrix_event_types_ctor(void)
{
matrix_event_register_type("m.room.member",
MATRIX_EVENT_TYPE_ROOM_MEMBER,
MATRIX_TYPE_ROOM_MEMBER_EVENT,
NULL);
matrix_event_register_type("m.presence",
MATRIX_EVENT_TYPE_PRESENCE,
MATRIX_TYPE_PRESENCE_EVENT,
NULL);
matrix_event_register_type("m.room.message",
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,
MATRIX_TYPE_ROOM_MESSAGE_EVENT,
NULL);
}
@@ -257,11 +172,11 @@ matrix_client_connect_event(MatrixClient *client,
{
GClosure *closure;
GQuark equark;
MatrixEventBaseClass *event_class = MATRIX_EVENT_BASE_CLASS(
MatrixEventClass *event_class = MATRIX_EVENT_CLASS(
g_type_class_ref(event_gtype));
guint event_signal_id = g_signal_lookup("event", MATRIX_TYPE_CLIENT);
if (!MATRIX_EVENT_IS_BASE_CLASS(event_class)) {
if (!MATRIX_IS_EVENT_CLASS(event_class)) {
g_warning("Trying to connect to a type that is not derived from MatrixEvent");
g_type_class_unref(event_class);
@@ -281,4 +196,5 @@ matrix_client_connect_event(MatrixClient *client,
g_signal_connect_closure_by_id(client,
event_signal_id, equark,
closure, FALSE);
}

View File

@@ -1,86 +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 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);
}
}

339
src/matrix-event.vala Normal file
View File

@@ -0,0 +1,339 @@
/*
* 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 events 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);
}
}
}

View File

@@ -1,14 +0,0 @@
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@

View File

@@ -63,17 +63,14 @@ 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);
}
@@ -88,7 +85,7 @@ public class Matrix.HTTPAPI : GLib.Object, Matrix.API {
_soup_session.ssl_strict = value;
}
}
protected string? _user_id;
private string? _user_id;
public string? user_id {
get {
return _user_id;
@@ -98,7 +95,7 @@ public class Matrix.HTTPAPI : GLib.Object, Matrix.API {
}
public string? token { get; set; default = null; }
public string? refresh_token { get; set; default = null; }
protected string? _homeserver;
private string? _homeserver;
public string? homeserver {
get {
return _homeserver;
@@ -127,20 +124,10 @@ 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, string? refresh_token = null)
HTTPAPI(string base_url, string? token = null)
{
Object(base_url : base_url,
token : token,
refresh_token : refresh_token);
Object(base_url : base_url, token : token);
_soup_session.ssl_strict = true;
}
@@ -199,9 +186,7 @@ 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);
}
@@ -217,15 +202,12 @@ 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,
@@ -233,7 +215,6 @@ 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(
@@ -295,9 +276,7 @@ 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();
@@ -311,10 +290,7 @@ 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;
}
}
@@ -325,11 +301,8 @@ 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;
}
}
@@ -338,11 +311,7 @@ public class Matrix.HTTPAPI : GLib.Object, Matrix.API {
if ((node = root.get_member("home_server")) != null) {
string homeserver = node.get_string();
if (Config.DEBUG) {
debug("Our home server calls itself %s",
homeserver);
}
debug("Our home server calls itself %s", homeserver);
this._homeserver = homeserver;
}
@@ -351,11 +320,7 @@ public class Matrix.HTTPAPI : GLib.Object, Matrix.API {
if ((node = root.get_member("user_id")) != null) {
string user_id = node.get_string();
if (Config.DEBUG) {
debug("We are reported to be logged in as %s",
user_id);
}
debug("We are reported to be logged in as %s", user_id);
this._user_id = user_id;
}
@@ -438,21 +403,14 @@ public class Matrix.HTTPAPI : GLib.Object, Matrix.API {
if (accept_non_json) {
raw_content = new ByteArray.sized((uint)datalen);
raw_content.append(buffer.data);
if (Config.DEBUG) {
debug("Binary data (%s): %u bytes",
request_url, (uint)datalen);
}
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) {
@@ -562,8 +520,8 @@ public class Matrix.HTTPAPI : GLib.Object, Matrix.API {
public void
update_presence_list(API.Callback? cb,
string user_id,
string[] drop_ids,
string[] invite_ids)
List<string> drop_ids,
List<string> invite_ids)
throws Matrix.Error
{
Json.Builder builder;
@@ -574,25 +532,23 @@ public class Matrix.HTTPAPI : GLib.Object, Matrix.API {
builder = new Json.Builder();
builder.begin_object();
if (drop_ids.length > 0) {
if (drop_ids != null) {
builder.set_member_name("drop");
builder.begin_array();
foreach (var entry in drop_ids) {
drop_ids.foreach(
(entry) => {
builder.add_string_value(entry);
}
});
builder.end_array();
}
if (invite_ids.length > 0) {
if (invite_ids != null) {
builder.set_member_name("invite");
builder.begin_array();
foreach (var entry in invite_ids) {
invite_ids.foreach(
(entry) => {
builder.add_string_value(entry);
}
});
builder.end_array();
}
@@ -604,7 +560,7 @@ public class Matrix.HTTPAPI : GLib.Object, Matrix.API {
}
public void
get_presence(API.Callback? cb,
get_user_presence(API.Callback? cb,
string user_id)
throws Matrix.Error
{
@@ -618,7 +574,7 @@ public class Matrix.HTTPAPI : GLib.Object, Matrix.API {
}
public void
set_presence(API.Callback? cb,
set_user_presence(API.Callback? cb,
string user_id,
Presence presence,
string? status_message)
@@ -705,7 +661,7 @@ public class Matrix.HTTPAPI : GLib.Object, Matrix.API {
}
public void
delete_pushrule(API.Callback? cb,
delete_pusher(API.Callback? cb,
string scope,
PusherKind kind,
string rule_id)
@@ -715,7 +671,7 @@ public class Matrix.HTTPAPI : GLib.Object, Matrix.API {
}
public void
get_pushrule(API.Callback? cb,
get_pusher(API.Callback? cb,
string scope,
PusherKind kind,
string rule_id)
@@ -725,14 +681,14 @@ public class Matrix.HTTPAPI : GLib.Object, Matrix.API {
}
public void
add_pushrule(API.Callback? cb,
add_pusher(API.Callback? cb,
string scope,
PusherKind kind,
string rule_id,
string? before,
string? after,
string[] actions,
PusherConditionKind[] conditions)
List<string> actions,
List<PusherConditionKind?>? conditions)
throws Matrix.Error
{
Json.Builder builder;
@@ -751,16 +707,17 @@ public class Matrix.HTTPAPI : GLib.Object, Matrix.API {
builder.set_member_name("actions");
builder.begin_array();
foreach (var entry in actions) {
actions.foreach(
(entry) => {
builder.add_string_value(entry);
}
});
builder.end_array();
if (conditions.length > 0) {
if (conditions != null) {
builder.set_member_name("conditions");
builder.begin_array();
foreach (var entry in conditions) {
conditions.foreach(
(entry) => {
string? kind_string = _g_enum_value_to_nick(
typeof(Matrix.PusherConditionKind),
entry);
@@ -775,8 +732,7 @@ 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();
}
@@ -789,7 +745,7 @@ public class Matrix.HTTPAPI : GLib.Object, Matrix.API {
}
public void
toggle_pushrule(API.Callback? cb,
toggle_pusher(API.Callback? cb,
string scope,
PusherKind kind,
string rule_id,
@@ -812,15 +768,6 @@ 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
@@ -831,9 +778,9 @@ public class Matrix.HTTPAPI : GLib.Object, Matrix.API {
string? topic,
RoomVisibility visibility,
Json.Node? creation_content,
Matrix.Event.State[] initial_state,
string[] invitees,
3PidCredential[] invite_3pids)
List<StateEvent>? initial_state,
List<string>? invitees,
List<3PidCredential>? invite_3pids)
throws Matrix.Error
{
Json.Builder builder = new Json.Builder();
@@ -845,39 +792,37 @@ public class Matrix.HTTPAPI : GLib.Object, Matrix.API {
builder.add_value(creation_content);
}
if (initial_state.length > 0) {
if (initial_state != null) {
builder.set_member_name("initial_state");
builder.begin_array();
foreach (var entry in initial_state) {
initial_state.foreach(
(entry) => {
builder.add_value(entry.json);
}
});
builder.end_array();
}
if (invitees.length > 0) {
if (invitees != null) {
builder.set_member_name("invite");
builder.begin_array();
foreach (var entry in invitees) {
invitees.foreach(
(entry) => {
builder.add_string_value(entry);
}
});
builder.end_array();
}
if (invite_3pids.length > 0) {
if (invite_3pids != null) {
builder.set_member_name("invite_3pid");
builder.begin_array();
foreach (var entry in invite_3pids) {
invite_3pids.foreach(
(entry) => {
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();
}
@@ -1016,27 +961,6 @@ 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)
@@ -1122,40 +1046,6 @@ 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
@@ -1354,7 +1244,7 @@ public class Matrix.HTTPAPI : GLib.Object, Matrix.API {
}
public void
send_event(API.Callback? cb,
send_message_event(API.Callback? cb,
string room_id,
string event_type,
string txn_id,
@@ -1395,7 +1285,7 @@ public class Matrix.HTTPAPI : GLib.Object, Matrix.API {
}
public void
send_state_event(API.Callback? cb,
send_room_event(API.Callback? cb,
string room_id,
string event_type,
string? state_key,
@@ -1601,15 +1491,6 @@ 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
@@ -1862,36 +1743,6 @@ 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

View File

@@ -24,13 +24,6 @@ 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)
@@ -73,16 +66,13 @@ public class Matrix.HTTPClient : Matrix.HTTPAPI, Matrix.Client {
false, username, password);
}
public new void
public void
logout()
throws Matrix.Error
{
((Matrix.API)this).logout(
() => {
token = null;
refresh_token = null;
abort_pending();
});
}
private void
@@ -91,12 +81,10 @@ public class Matrix.HTTPClient : Matrix.HTTPAPI, Matrix.Client {
Json.Object root_obj;
Json.Node node;
string event_type;
Matrix.Event.Base? evt = null;
Matrix.Event evt;
if (event_node.get_node_type() != Json.NodeType.OBJECT) {
if (Config.DEBUG) {
warning("Received event that is not an object.");
}
return;
}
@@ -104,9 +92,7 @@ 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;
}
@@ -114,136 +100,20 @@ public class Matrix.HTTPClient : Matrix.HTTPAPI, Matrix.Client {
event_type = node.get_string();
try {
evt = Matrix.Event.Base.new_from_json(event_type, event_node);
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;
} catch (GLib.Error e) {
evt = null;
}
warning("Error during event creation: %s", e.message);
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;
}
}
return;
}
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)
@@ -273,17 +143,11 @@ 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);
@@ -292,9 +156,7 @@ 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) {
@@ -369,26 +231,6 @@ 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
@@ -400,7 +242,6 @@ 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) {}
@@ -421,10 +262,6 @@ public class Matrix.HTTPClient : Matrix.HTTPAPI, Matrix.Client {
throw e;
}
if (_polling == false) {
polling_started();
}
_polling = true;
}
@@ -438,274 +275,4 @@ 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);
}
}
}
}

View File

@@ -1,75 +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 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);
}
}

View File

@@ -1,234 +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/>.
*/
/**
* 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);
}
}
}

View File

@@ -1,42 +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/>.
*/
/**
* 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);
}
}

View File

@@ -1,113 +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 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);
}
}

View File

@@ -1,102 +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 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);
}
}

View File

@@ -1,86 +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/>.
*/
/**
* 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);
}
}

View File

@@ -1,45 +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/>.
*/
/**
* 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);
}
}

View File

@@ -1,38 +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/>.
*/
/**
* 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);
}
}

View File

@@ -1,73 +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/>.
*/
/**
* 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);
}
}

View 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 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);
}
}

View File

@@ -1,315 +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/>.
*/
#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);
}

View File

@@ -1,45 +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/>.
*/
#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__ */

View File

@@ -16,7 +16,7 @@
* <http://www.gnu.org/licenses/>.
*/
[CCode (cprefix = "", lower_case_cprefix = "", cheader_filename = "config.h")]
namespace Config {
public const bool DEBUG;
}
/**
* Abstract base class for room events.
*/
public abstract class Matrix.RoomEvent : Matrix.Event {}

View File

@@ -0,0 +1,119 @@
/*
* 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);
}
}

View File

@@ -0,0 +1,53 @@
/*
* 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);
}
}

View File

@@ -1,382 +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 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 rooms 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 avatars thumbnail.
*/
public string? avatar_thumbnail_url { get; set; default = null; }
/**
* ImageInfo relevant to the room avatars 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 rooms 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 rooms 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 rooms 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 doesnt 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 doesnt 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 rooms 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 doesnt 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
}
}
}
}

View File

@@ -0,0 +1,58 @@
/*
* 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);
}
}
}

Some files were not shown because too many files have changed in this diff Show More