Add message handler for m.audio
This commit is contained in:
parent
65dffc38da
commit
6e5c73c6ad
1
.gitignore
vendored
1
.gitignore
vendored
@ -88,3 +88,4 @@ Makefile.in
|
||||
/src/matrix-message-notice.c
|
||||
/src/matrix-message-file.c
|
||||
/src/matrix-message-image.c
|
||||
/src/matrix-message-audio.c
|
||||
|
@ -56,6 +56,7 @@ libmatrix_glib_0_0_la_VALA_SOURCES = \
|
||||
matrix-message-notice.vala \
|
||||
matrix-message-file.vala \
|
||||
matrix-message-image.vala \
|
||||
matrix-message-audio.vala \
|
||||
$(NULL)
|
||||
|
||||
AM_CPPFLAGS += \
|
||||
|
@ -237,6 +237,9 @@ matrix_event_types_ctor(void)
|
||||
matrix_message_register_type("m.image",
|
||||
MATRIX_MESSAGE_TYPE_IMAGE,
|
||||
NULL);
|
||||
matrix_message_register_type("m.audio",
|
||||
MATRIX_MESSAGE_TYPE_AUDIO,
|
||||
NULL);
|
||||
}
|
||||
|
||||
void
|
||||
|
75
src/matrix-message-audio.vala
Normal file
75
src/matrix-message-audio.vala
Normal file
@ -0,0 +1,75 @@
|
||||
/*
|
||||
* This file is part of matrix-glib-sdk
|
||||
*
|
||||
* matrix-glib-sdk is free software: you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation, either
|
||||
* version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* matrix-glib-sdk is distributed in the hope that it will be
|
||||
* useful, but WITHOUT ANY WARRANTY; without even the implied
|
||||
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
* See the GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with matrix-glib-sdk. If not, see
|
||||
* <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Class to hold a m.audio message
|
||||
*
|
||||
* This message represents a single audio clip.
|
||||
*/
|
||||
public class Matrix.Message.Audio : Matrix.Message.Base {
|
||||
/**
|
||||
* The URL to the audio clip.
|
||||
*/
|
||||
public string? url { get; set; default = null; }
|
||||
|
||||
/**
|
||||
* Metadata for the audio clip referred to in `url`.
|
||||
*/
|
||||
public AudioInfo? info { get; set; default = null; }
|
||||
|
||||
protected override void
|
||||
from_json(Json.Node json_data)
|
||||
throws Matrix.Error
|
||||
{
|
||||
var root = json_data.get_object();
|
||||
Json.Node? node;
|
||||
|
||||
if ((node = root.get_member("url")) != null) {
|
||||
_url = node.get_string();
|
||||
} else if (Config.DEBUG) {
|
||||
warning("url is missing from a m.audio message");
|
||||
}
|
||||
|
||||
if ((node = root.get_member("info")) != null) {
|
||||
_info = AudioInfo();
|
||||
_info.set_from_json(node);
|
||||
}
|
||||
|
||||
base.from_json(json_data);
|
||||
}
|
||||
|
||||
protected override void
|
||||
to_json(Json.Node json_data)
|
||||
throws Matrix.Error
|
||||
{
|
||||
if (_url == null) {
|
||||
throw new Matrix.Error.INCOMPLETE(
|
||||
"Won't generate a m.audio message without url");
|
||||
}
|
||||
|
||||
var root = json_data.get_object();
|
||||
|
||||
root.set_string_member("url", _url);
|
||||
|
||||
if (_info != null) {
|
||||
root.set_member("info", _info.get_json_node());
|
||||
}
|
||||
|
||||
base.to_json(json_data);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user