Port MatrixMessageText to C

This commit is contained in:
Gergely Polonkai 2017-11-18 11:49:04 +01:00
parent 93154a3e5e
commit 3e7979b905
6 changed files with 102 additions and 21 deletions

1
.gitignore vendored
View File

@ -71,7 +71,6 @@ Makefile.in
/src/matrix-event-call-hangup.c /src/matrix-event-call-hangup.c
/src/matrix-event-call-base.c /src/matrix-event-call-base.c
/src/matrix-glib-0.0.pc /src/matrix-glib-0.0.pc
/src/matrix-message-text.c
/src/matrix-message-emote.c /src/matrix-message-emote.c
/src/matrix-message-notice.c /src/matrix-message-notice.c
/src/matrix-message-file.c /src/matrix-message-file.c

View File

@ -38,7 +38,6 @@ libmatrix_glib_0_0_la_VALA_SOURCES = \
matrix-event-call-candidates.vala \ matrix-event-call-candidates.vala \
matrix-event-call-answer.vala \ matrix-event-call-answer.vala \
matrix-event-call-hangup.vala \ matrix-event-call-hangup.vala \
matrix-message-text.vala \
matrix-message-emote.vala \ matrix-message-emote.vala \
matrix-message-notice.vala \ matrix-message-notice.vala \
matrix-message-file.vala \ matrix-message-file.vala \
@ -104,6 +103,7 @@ INST_H_SRC_FILES = \
matrix-compacts.h \ matrix-compacts.h \
matrix-event-base.h \ matrix-event-base.h \
matrix-message-base.h \ matrix-message-base.h \
matrix-message-text.h \
matrix-event-room-base.h \ matrix-event-room-base.h \
matrix-event-state-base.h \ matrix-event-state-base.h \
matrix-event-tag.h \ matrix-event-tag.h \
@ -137,6 +137,7 @@ libmatrix_glib_0_0_la_SOURCES = \
matrix-compacts.c \ matrix-compacts.c \
matrix-event-base.c \ matrix-event-base.c \
matrix-message-base.c \ matrix-message-base.c \
matrix-message-text.c \
matrix-event-tag.c \ matrix-event-tag.c \
matrix-event-presence.c \ matrix-event-presence.c \
matrix-event-room-member.c \ matrix-event-room-member.c \

View File

@ -26,6 +26,8 @@
#include "matrix-event-room-topic.h" #include "matrix-event-room-topic.h"
#include "matrix-event-room-aliases.h" #include "matrix-event-room-aliases.h"
#include "matrix-message-text.h"
/* /*
Borrowed from GLib Borrowed from GLib

70
src/matrix-message-text.c Normal file
View File

@ -0,0 +1,70 @@
/*
* 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-message-text.h"
/**
* SECTION:matrix-message-text
* @short_description: message handler for plain text messages
*
* This is the default message handler for `m.text` messages.
*/
G_DEFINE_TYPE(MatrixMessageText, matrix_message_text, MATRIX_MESSAGE_TYPE_BASE);
static void
matrix_message_text_real_from_json(MatrixMessageBase *matrix_message_base, JsonNode *json_data, GError **error)
{
GError *inner_error = NULL;
g_return_if_fail(json_data != NULL);
MATRIX_MESSAGE_BASE_CLASS(matrix_message_text_parent_class)->from_json(matrix_message_base, json_data, &inner_error);
if (inner_error != NULL) {
g_propagate_error(error, inner_error);
}
}
static void
matrix_message_text_real_to_json(MatrixMessageBase *matrix_message_base, JsonNode *json_data, GError **error)
{
GError *inner_error = NULL;
g_return_if_fail(json_data != NULL);
MATRIX_MESSAGE_BASE_CLASS(matrix_message_text_parent_class)->to_json(matrix_message_base, json_data, &inner_error);
if (inner_error != NULL) {
g_propagate_error(error, inner_error);
}
}
MatrixMessageText *
matrix_message_text_new(void) {
return (MatrixMessageText *)matrix_message_base_construct(MATRIX_MESSAGE_TYPE_TEXT);
}
static void
matrix_message_text_class_init(MatrixMessageTextClass *klass)
{
((MatrixMessageBaseClass *)klass)->from_json = matrix_message_text_real_from_json;
((MatrixMessageBaseClass *)klass)->to_json = matrix_message_text_real_to_json;
}
static void matrix_message_text_init(MatrixMessageText *matrix_message_text)
{}

View File

@ -16,23 +16,23 @@
* <http://www.gnu.org/licenses/>. * <http://www.gnu.org/licenses/>.
*/ */
/** #ifndef __MATRIX_GLIB_SDK_MESSAGE_TEXT_H__
* Message handler for plain text messages # define __MATRIX_GLIB_SDK_MESSAGE_TEXT_H__
*
* 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 # include <glib-object.h>
to_json(Json.Node json_data) # include "matrix-message-base.h"
throws Matrix.Error
{ G_BEGIN_DECLS
base.to_json(json_data);
} # define MATRIX_MESSAGE_TYPE_TEXT matrix_message_text_get_type()
} G_DECLARE_DERIVABLE_TYPE(MatrixMessageText, matrix_message_text, MATRIX_MESSAGE, TEXT, MatrixMessageBase)
struct _MatrixMessageTextClass {
MatrixMessageBaseClass parent_class;
};
MatrixMessageText* matrix_message_text_new (void);
G_END_DECLS
#endif /* __MATRIX_GLIB_SDK_MESSAGE_TEXT_H__ */

View File

@ -641,5 +641,14 @@ namespace Matrix {
public virtual void to_json(Json.Node json_data) public virtual void to_json(Json.Node json_data)
throws Matrix.Error; throws Matrix.Error;
} }
[CCode (cheader_filename = "matrix-message-text.h")]
public class Text : 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;
}
} }
} }