Add event handler for m.room.canonical_alias
This commit is contained in:
		
							
								
								
									
										1
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										1
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							| @@ -67,3 +67,4 @@ Makefile.in | ||||
| /src/matrix-event-room-join-rules.c | ||||
| /src/matrix-event-room-name.c | ||||
| /src/matrix-event-tag.c | ||||
| /src/matrix-event-room-canonical-alias.c | ||||
|   | ||||
| @@ -37,6 +37,7 @@ libmatrix_glib_0_0_la_VALA_SOURCES = \ | ||||
| 	matrix-event-room-join-rules.vala \ | ||||
| 	matrix-event-room-name.vala \ | ||||
| 	matrix-event-tag.vala \ | ||||
| 	matrix-event-room-canonical-alias.vala \ | ||||
| 	$(NULL) | ||||
|  | ||||
| AM_CPPFLAGS += \ | ||||
|   | ||||
							
								
								
									
										57
									
								
								src/matrix-event-room-canonical-alias.vala
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										57
									
								
								src/matrix-event-room-canonical-alias.vala
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,57 @@ | ||||
| /* | ||||
|  * 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.room.canonical_alias event | ||||
|  * | ||||
|  * This event is used to inform the room about which alias should be | ||||
|  * considered the canonical one. This could be for display purposes or | ||||
|  * as suggestion to users which alias to use to advertise the room. | ||||
|  */ | ||||
| public class Matrix.Event.RoomCanonicalAlias : Matrix.Event.State { | ||||
|     public string? canonical_alias { get; set; default = null; } | ||||
|  | ||||
|     protected override void | ||||
|     from_json(Json.Node json_data) | ||||
|         throws Matrix.Error | ||||
|     { | ||||
|         var content_root = json_data.get_object() | ||||
|             .get_member("content").get_object(); | ||||
|         Json.Node? node; | ||||
|  | ||||
|         if ((node = content_root.get_member("alias")) != null) { | ||||
|             _canonical_alias = node.get_string(); | ||||
|         } | ||||
|  | ||||
|         base.from_json(json_data); | ||||
|     } | ||||
|  | ||||
|     protected override void | ||||
|     to_json(Json.Node json_data) | ||||
|         throws Matrix.Error | ||||
|     { | ||||
|         var content_root = json_data.get_object() | ||||
|             .get_member("content").get_object(); | ||||
|  | ||||
|         if (_canonical_alias != null) { | ||||
|             content_root.set_string_member("alias", _canonical_alias); | ||||
|         } | ||||
|  | ||||
|         base.to_json(json_data); | ||||
|     } | ||||
| } | ||||
| @@ -185,6 +185,9 @@ matrix_event_types_ctor(void) | ||||
|     matrix_event_register_type("m.tag", | ||||
|                                MATRIX_EVENT_TYPE_TAG, | ||||
|                                NULL); | ||||
|     matrix_event_register_type("m.room.canonical_alias", | ||||
|                                MATRIX_EVENT_TYPE_ROOM_CANONICAL_ALIAS, | ||||
|                                NULL); | ||||
| } | ||||
|  | ||||
| void | ||||
|   | ||||
		Reference in New Issue
	
	Block a user