From 476963069a116732ff1f91186498bce56075a717 Mon Sep 17 00:00:00 2001 From: TheOneWithTheBraid Date: Tue, 15 Nov 2022 11:13:21 +0100 Subject: [PATCH] feat: support MSC 3935: cute events - add cute event skeletron (`im.fluffychat.cute_events`) - add cute events to default command batch - this way, all SDK users can profit from cute events - supported events: `hug`, `googly_eyes`, `cuddle` Fixes: https://rail.chat/@AgathaSorceress@eldritch.cafe/109336005433123570 Signed-off-by: TheOneWithTheBraid --- lib/encryption/encryption.dart | 3 +- lib/encryption/utils/bootstrap.dart | 1 - lib/matrix.dart | 3 ++ lib/msc_extensions/README.md | 3 ++ .../msc_3935_cute_events.dart | 21 ++++++++++++++ lib/src/utils/commands_extension.dart | 28 +++++++++++++++++++ test/commands_test.dart | 21 ++++++++++++++ 7 files changed, 78 insertions(+), 2 deletions(-) create mode 100644 lib/msc_extensions/msc_3935_cute_events/msc_3935_cute_events.dart diff --git a/lib/encryption/encryption.dart b/lib/encryption/encryption.dart index b852363a..2c15485a 100644 --- a/lib/encryption/encryption.dart +++ b/lib/encryption/encryption.dart @@ -354,7 +354,8 @@ class Encryption { Future> encryptGroupMessagePayload( String roomId, Map payload, {String type = EventTypes.Message}) async { - final Map? mRelatesTo = payload.remove('m.relates_to'); + final Map? mRelatesTo = + Map.from(payload).remove('m.relates_to'); // Events which only contain a m.relates_to like reactions don't need to // be encrypted. if (payload.isEmpty && mRelatesTo != null) { diff --git a/lib/encryption/utils/bootstrap.dart b/lib/encryption/utils/bootstrap.dart index c61f0fcd..c6c91a24 100644 --- a/lib/encryption/utils/bootstrap.dart +++ b/lib/encryption/utils/bootstrap.dart @@ -27,7 +27,6 @@ import 'package:matrix/encryption/key_manager.dart'; import 'package:matrix/encryption/ssss.dart'; import 'package:matrix/encryption/utils/base64_unpadded.dart'; import 'package:matrix/matrix.dart'; -import 'package:matrix/msc_extensions/msc_3814_dehydrated_devices/msc_3814_dehydrated_devices.dart'; enum BootstrapState { /// Is loading. diff --git a/lib/matrix.dart b/lib/matrix.dart index 97ec21da..26452956 100644 --- a/lib/matrix.dart +++ b/lib/matrix.dart @@ -56,7 +56,10 @@ export 'src/utils/uia_request.dart'; export 'src/utils/uri_extension.dart'; export 'msc_extensions/extension_recent_emoji/recent_emoji.dart'; +export 'msc_extensions/msc_3935_cute_events/msc_3935_cute_events.dart'; export 'msc_extensions/msc_1236_widgets/msc_1236_widgets.dart'; +export 'msc_extensions/msc_2835_uia_login/msc_2835_uia_login.dart'; +export 'msc_extensions/msc_3814_dehydrated_devices/msc_3814_dehydrated_devices.dart'; export 'src/utils/web_worker/web_worker_stub.dart' if (dart.library.html) 'src/utils/web_worker/web_worker.dart'; diff --git a/lib/msc_extensions/README.md b/lib/msc_extensions/README.md index 44934b35..1fa96848 100644 --- a/lib/msc_extensions/README.md +++ b/lib/msc_extensions/README.md @@ -18,4 +18,7 @@ Please try to cover the following conventions: ## Implemented non-spec features - MSC 1236 - Widget API V2 +- MSC 2835 - UIA login +- MSC 3814 - Dehydrated Devices +- MSC 3935 - Cute Events - `io.element.recent_emoji` - recent emoji sync in account data \ No newline at end of file diff --git a/lib/msc_extensions/msc_3935_cute_events/msc_3935_cute_events.dart b/lib/msc_extensions/msc_3935_cute_events/msc_3935_cute_events.dart new file mode 100644 index 00000000..2c1c1d4a --- /dev/null +++ b/lib/msc_extensions/msc_3935_cute_events/msc_3935_cute_events.dart @@ -0,0 +1,21 @@ +abstract class CuteEventContent { + static const String eventType = 'im.fluffychat.cute_event'; + + const CuteEventContent._(); + + static Map get googlyEyes => { + 'msgtype': CuteEventContent.eventType, + 'cute_type': 'googly_eyes', + 'body': '👀' + }; + static Map get cuddle => { + 'msgtype': CuteEventContent.eventType, + 'cute_type': 'cuddle', + 'body': '😊' + }; + static Map get hug => { + 'msgtype': CuteEventContent.eventType, + 'cute_type': 'hug', + 'body': '🤗', + }; +} diff --git a/lib/src/utils/commands_extension.dart b/lib/src/utils/commands_extension.dart index 7e50c20f..27ac03ac 100644 --- a/lib/src/utils/commands_extension.dart +++ b/lib/src/utils/commands_extension.dart @@ -227,6 +227,33 @@ extension CommandsClientExtension on Client { await args.room.removeFromDirectChat(); return; }); + addCommand('hug', (CommandArgs args) async { + final content = CuteEventContent.hug; + return await args.room.sendEvent( + content, + inReplyTo: args.inReplyTo, + editEventId: args.editEventId, + txid: args.txid, + ); + }); + addCommand('googly', (CommandArgs args) async { + final content = CuteEventContent.googlyEyes; + return await args.room.sendEvent( + content, + inReplyTo: args.inReplyTo, + editEventId: args.editEventId, + txid: args.txid, + ); + }); + addCommand('cuddle', (CommandArgs args) async { + final content = CuteEventContent.cuddle; + return await args.room.sendEvent( + content, + inReplyTo: args.inReplyTo, + editEventId: args.editEventId, + txid: args.txid, + ); + }); } } @@ -236,6 +263,7 @@ class CommandArgs { Event? inReplyTo; Room room; String? txid; + CommandArgs( {required this.msg, this.editEventId, diff --git a/test/commands_test.dart b/test/commands_test.dart index e8c7ab53..33068ab8 100644 --- a/test/commands_test.dart +++ b/test/commands_test.dart @@ -378,6 +378,27 @@ void main() { expect(room.client.prevBatch, null); }); + test('cute events - googly eyes', () async { + FakeMatrixApi.calledEndpoints.clear(); + await room.sendTextEvent('/googly'); + final sent = getLastMessagePayload(); + expect(sent, CuteEventContent.googlyEyes); + }); + + test('cute events - hug', () async { + FakeMatrixApi.calledEndpoints.clear(); + await room.sendTextEvent('/hug'); + final sent = getLastMessagePayload(); + expect(sent, CuteEventContent.hug); + }); + + test('cute events - hug', () async { + FakeMatrixApi.calledEndpoints.clear(); + await room.sendTextEvent('/cuddle'); + final sent = getLastMessagePayload(); + expect(sent, CuteEventContent.cuddle); + }); + test('dispose client', () async { await client.dispose(closeDatabase: true); });