From 54a128d2c5cddc5b9837c7fe5dc60a841bd30b84 Mon Sep 17 00:00:00 2001 From: Sorunome Date: Sat, 5 Sep 2020 13:54:43 +0200 Subject: [PATCH] fix: Properly detect sicket message types --- lib/src/event.dart | 4 +++- test/event_test.dart | 5 +++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/src/event.dart b/lib/src/event.dart index a82c2b6..0299acd 100644 --- a/lib/src/event.dart +++ b/lib/src/event.dart @@ -229,7 +229,9 @@ class Event extends MatrixEvent { unsigned: unsigned, room: room); - String get messageType => content['msgtype'] ?? MessageTypes.Text; + String get messageType => type == EventTypes.Sticker + ? MessageTypes.Sticker + : content['msgtype'] ?? MessageTypes.Text; void setRedactionEvent(Event redactedBecause) { unsigned = { diff --git a/test/event_test.dart b/test/event_test.dart index c2b3fcd..9649b7c 100644 --- a/test/event_test.dart +++ b/test/event_test.dart @@ -167,6 +167,11 @@ void main() { event = Event.fromJson(jsonObj, null); expect(event.messageType, MessageTypes.Location); + jsonObj['type'] = 'm.sticker'; + jsonObj['content']['msgtype'] = null; + event = Event.fromJson(jsonObj, null); + expect(event.messageType, MessageTypes.Sticker); + jsonObj['type'] = 'm.room.message'; jsonObj['content']['msgtype'] = 'm.text'; jsonObj['content']['m.relates_to'] = {};