From 4c9a79758ae9b0d36816d7dd35ee60b8bbcc005e Mon Sep 17 00:00:00 2001 From: Gergely Polonkai Date: Thu, 10 Mar 2016 19:47:57 +0100 Subject: [PATCH] Add message handler for m.video --- .gitignore | 1 + src/Makefile.am | 1 + src/matrix-event-types.c | 3 ++ src/matrix-message-video.vala | 73 +++++++++++++++++++++++++++++++++++ 4 files changed, 78 insertions(+) create mode 100644 src/matrix-message-video.vala diff --git a/.gitignore b/.gitignore index 614a9c6..8971915 100644 --- a/.gitignore +++ b/.gitignore @@ -89,3 +89,4 @@ Makefile.in /src/matrix-message-file.c /src/matrix-message-image.c /src/matrix-message-audio.c +/src/matrix-message-video.c diff --git a/src/Makefile.am b/src/Makefile.am index 85e7069..892f4db 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -57,6 +57,7 @@ libmatrix_glib_0_0_la_VALA_SOURCES = \ matrix-message-file.vala \ matrix-message-image.vala \ matrix-message-audio.vala \ + matrix-message-video.vala \ $(NULL) AM_CPPFLAGS += \ diff --git a/src/matrix-event-types.c b/src/matrix-event-types.c index f7cd5b9..704d7b0 100644 --- a/src/matrix-event-types.c +++ b/src/matrix-event-types.c @@ -240,6 +240,9 @@ matrix_event_types_ctor(void) matrix_message_register_type("m.audio", MATRIX_MESSAGE_TYPE_AUDIO, NULL); + matrix_message_register_type("m.video", + MATRIX_MESSAGE_TYPE_VIDEO, + NULL); } void diff --git a/src/matrix-message-video.vala b/src/matrix-message-video.vala new file mode 100644 index 0000000..1b7fc83 --- /dev/null +++ b/src/matrix-message-video.vala @@ -0,0 +1,73 @@ +/* + * This file is part of matrix-glib-sdk + * + * matrix-glib-sdk is free software: you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation, either + * version 3 of the License, or (at your option) any later version. + * + * matrix-glib-sdk is distributed in the hope that it will be + * useful, but WITHOUT ANY WARRANTY; without even the implied + * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with matrix-glib-sdk. If not, see + * . + */ + +/** + * 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); + } +}