diff --git a/.gitignore b/.gitignore index 02f1170..f3e7ed8 100644 --- a/.gitignore +++ b/.gitignore @@ -71,7 +71,6 @@ Makefile.in /src/matrix-event-call-hangup.c /src/matrix-event-call-base.c /src/matrix-glib-0.0.pc -/src/matrix-message-emote.c /src/matrix-message-notice.c /src/matrix-message-file.c /src/matrix-message-image.c diff --git a/src/Makefile.am b/src/Makefile.am index ebac33e..2594c30 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -38,7 +38,6 @@ libmatrix_glib_0_0_la_VALA_SOURCES = \ matrix-event-call-candidates.vala \ matrix-event-call-answer.vala \ matrix-event-call-hangup.vala \ - matrix-message-emote.vala \ matrix-message-notice.vala \ matrix-message-file.vala \ matrix-message-image.vala \ @@ -104,6 +103,7 @@ INST_H_SRC_FILES = \ matrix-message-base.h \ matrix-message-text.h \ matrix-message-location.h \ + matrix-message-emote.h \ matrix-event-room-base.h \ matrix-event-state-base.h \ matrix-event-tag.h \ @@ -139,6 +139,7 @@ libmatrix_glib_0_0_la_SOURCES = \ matrix-message-base.c \ matrix-message-text.c \ matrix-message-location.c \ + matrix-message-emote.c \ matrix-event-tag.c \ matrix-event-presence.c \ matrix-event-room-member.c \ diff --git a/src/matrix-event-types.c b/src/matrix-event-types.c index 8e450b9..c14f05b 100644 --- a/src/matrix-event-types.c +++ b/src/matrix-event-types.c @@ -28,6 +28,7 @@ #include "matrix-message-text.h" #include "matrix-message-location.h" +#include "matrix-message-emote.h" /* Borrowed from GLib diff --git a/src/matrix-message-emote.c b/src/matrix-message-emote.c new file mode 100644 index 0000000..e272e7c --- /dev/null +++ b/src/matrix-message-emote.c @@ -0,0 +1,67 @@ +/* + * 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 + * . + */ + +#include "matrix-message-emote.h" + +/** + * SECTION:matrix-message-emote + * @short_description: message type to handle emotes + * + * This is the default message handler for `m.emote` messages. + * + * This message is similar to `m.text` (see #MatrixMessageText) except that the sender is + * “performing” the action contained in the `body` key, similar to the `/me` command in IRC. + * When displaying this message, it should be prefixed by the name of the sender, eg. “John + * Doe thinks”. This message could also be represented in a different colour to distinguish + * it from regular `m.text` messages. + */ +G_DEFINE_TYPE(MatrixMessageEmote, matrix_message_emote, MATRIX_MESSAGE_TYPE_BASE); + +static void +matrix_message_emote_real_from_json(MatrixMessageBase *matrix_message_base, JsonNode *json_data, GError **error) +{ + MATRIX_MESSAGE_BASE_CLASS(matrix_message_emote_parent_class)->from_json(matrix_message_base, json_data, error); +} + +static void +matrix_message_emote_real_to_json(MatrixMessageBase *matrix_message_base, JsonNode *json_data, GError **error) +{ + MATRIX_MESSAGE_BASE_CLASS(matrix_message_emote_parent_class)->to_json(matrix_message_base, json_data, error); +} + +MatrixMessageEmote * +matrix_message_emote_construct(GType object_type) +{ + return (MatrixMessageEmote *)matrix_message_base_construct(object_type); +} + +MatrixMessageEmote * +matrix_message_emote_new(void) { + return matrix_message_emote_construct(MATRIX_MESSAGE_TYPE_EMOTE); +} + +static void +matrix_message_emote_class_init(MatrixMessageEmoteClass *klass) +{ + ((MatrixMessageBaseClass *)klass)->from_json = matrix_message_emote_real_from_json; + ((MatrixMessageBaseClass *)klass)->to_json = matrix_message_emote_real_to_json; +} + +static void +matrix_message_emote_init(MatrixMessageEmote *matrix_message_emote) +{} diff --git a/src/matrix-message-emote.vala b/src/matrix-message-emote.h similarity index 51% rename from src/matrix-message-emote.vala rename to src/matrix-message-emote.h index 15e3e31..252dd05 100644 --- a/src/matrix-message-emote.vala +++ b/src/matrix-message-emote.h @@ -16,27 +16,25 @@ * . */ -/** - * 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); - } +#ifndef __MATRIX_GLIB_SDK_MESSAGE_EMOTE_H___ +# define __MATRIX_GLIB_SDK_MESSAGE_EMOTE_H___ - public override void - to_json(Json.Node json_data) - throws Matrix.Error - { - base.to_json(json_data); - } -} +# include +# include "matrix-message-base.h" + +G_BEGIN_DECLS + +# define MATRIX_MESSAGE_TYPE_EMOTE matrix_message_emote_get_type() +G_DECLARE_DERIVABLE_TYPE(MatrixMessageEmote, matrix_message_emote, MATRIX_MESSAGE, EMOTE, MatrixMessageBase); + +struct _MatrixMessageEmoteClass { + MatrixMessageBaseClass parent_class; +}; + +MatrixMessageEmote *matrix_message_emote_new(void); +MatrixMessageEmote *matrix_message_emote_construct(GType object_type); + +G_END_DECLS + + +#endif /* __MATRIX_GLIB_SDK_MESSAGE_EMOTE_H___ */ diff --git a/vapi/c-api.vapi b/vapi/c-api.vapi index dbd1e6e..e745475 100644 --- a/vapi/c-api.vapi +++ b/vapi/c-api.vapi @@ -665,5 +665,14 @@ namespace Matrix { to_json(Json.Node json_data) throws Matrix.Error; } + + [CCode (cheader_filename = "matrix-message-emote.h")] + public class Emote : Base { + public override void from_json(Json.Node json_data) + throws Matrix.Error; + + public override void to_json(Json.Node json_data) + throws Matrix.Error; + } } }