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 <the-one@with-the-braid.cf>
This commit is contained in:
TheOneWithTheBraid 2022-11-15 11:13:21 +01:00
parent c077062089
commit 476963069a
7 changed files with 78 additions and 2 deletions

View File

@ -354,7 +354,8 @@ class Encryption {
Future<Map<String, dynamic>> encryptGroupMessagePayload(
String roomId, Map<String, dynamic> payload,
{String type = EventTypes.Message}) async {
final Map<String, dynamic>? mRelatesTo = payload.remove('m.relates_to');
final Map<String, dynamic>? 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) {

View File

@ -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.

View File

@ -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';

View File

@ -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

View File

@ -0,0 +1,21 @@
abstract class CuteEventContent {
static const String eventType = 'im.fluffychat.cute_event';
const CuteEventContent._();
static Map<String, dynamic> get googlyEyes => {
'msgtype': CuteEventContent.eventType,
'cute_type': 'googly_eyes',
'body': '👀'
};
static Map<String, dynamic> get cuddle => {
'msgtype': CuteEventContent.eventType,
'cute_type': 'cuddle',
'body': '😊'
};
static Map<String, dynamic> get hug => {
'msgtype': CuteEventContent.eventType,
'cute_type': 'hug',
'body': '🤗',
};
}

View File

@ -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,

View File

@ -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);
});