Port MatrixMessageText to C
This commit is contained in:
parent
81521688e8
commit
49a2bf4aa9
1
.gitignore
vendored
1
.gitignore
vendored
@ -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
|
||||||
|
@ -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 \
|
||||||
|
@ -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
|
||||||
|
|
||||||
|
76
src/matrix-message-text.c
Normal file
76
src/matrix-message-text.c
Normal file
@ -0,0 +1,76 @@
|
|||||||
|
/*
|
||||||
|
* 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_construct(GType object_type)
|
||||||
|
{
|
||||||
|
return (MatrixMessageText *)matrix_message_base_construct(object_type);
|
||||||
|
}
|
||||||
|
|
||||||
|
MatrixMessageText *
|
||||||
|
matrix_message_text_new(void) {
|
||||||
|
return matrix_message_text_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)
|
||||||
|
{}
|
@ -16,23 +16,24 @@
|
|||||||
* <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);
|
||||||
|
MatrixMessageText* matrix_message_text_construct (GType object_type);
|
||||||
|
|
||||||
|
G_END_DECLS
|
||||||
|
|
||||||
|
#endif /* __MATRIX_GLIB_SDK_MESSAGE_TEXT_H__ */
|
@ -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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user