Port MatrixMessageEmote to C
This commit is contained in:
		
							
								
								
									
										1
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										1
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							| @@ -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 | ||||
|   | ||||
| @@ -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 \ | ||||
|   | ||||
| @@ -28,6 +28,7 @@ | ||||
|  | ||||
| #include "matrix-message-text.h" | ||||
| #include "matrix-message-location.h" | ||||
| #include "matrix-message-emote.h" | ||||
|  | ||||
| /* | ||||
|   Borrowed from GLib | ||||
|   | ||||
							
								
								
									
										67
									
								
								src/matrix-message-emote.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										67
									
								
								src/matrix-message-emote.c
									
									
									
									
									
										Normal file
									
								
							| @@ -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 | ||||
|  * <http://www.gnu.org/licenses/>. | ||||
|  */ | ||||
|  | ||||
| #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) | ||||
| {} | ||||
| @@ -16,27 +16,25 @@ | ||||
|  * <http://www.gnu.org/licenses/>.
 | ||||
|  */ | ||||
| 
 | ||||
| /**
 | ||||
|  * 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 <glib-object.h> | ||||
| # 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___ */ | ||||
| @@ -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; | ||||
|         } | ||||
|     } | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user