Skip to content

Commit c99449d

Browse files
committed
feat: Send state event to timeline on creating new megolm session
1 parent 0960e35 commit c99449d

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

lib/encryption/key_manager.dart

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,10 @@ class KeyManager {
348348
sess.outboundGroupSession!.session_id(),
349349
);
350350
if (inboundSess == null) {
351+
Logs().e(
352+
'No inbound session found for outbound group session!',
353+
sess.outboundGroupSession?.session_id(),
354+
);
351355
wipe = true;
352356
}
353357

@@ -601,6 +605,27 @@ class KeyManager {
601605
);
602606
await storeOutboundGroupSession(roomId, sess);
603607
_outboundGroupSessions[roomId] = sess;
608+
final devices = deviceKeys.map((keys) => keys.deviceId).toList();
609+
final users = deviceKeys.fold(
610+
<String>{},
611+
(users, keys) => users..add(keys.userId),
612+
).toList();
613+
client.onTimelineEvent.add(
614+
Event(
615+
eventId: 'fake_event_${rawSession['session_id']}',
616+
content: {
617+
'body':
618+
'🔒 Verschlüsselte Unterhaltung von ${users.length} Benutzern mit ${devices.length} Geräten',
619+
'devices': devices,
620+
'members': users,
621+
},
622+
type: 'sdk.dart.matrix.new_megolm_session',
623+
senderId: client.userID!,
624+
originServerTs: DateTime.now(),
625+
room: room,
626+
stateKey: '',
627+
),
628+
);
604629
} catch (e, s) {
605630
Logs().e(
606631
'[LibOlm] Unable to send the session key to the participating devices',

lib/src/utils/event_localizations.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ abstract class EventLocalizations {
119119
EventTypes.Sticker: (event, i18n, body) => i18n.sentASticker(
120120
event.senderFromMemoryOrFallback.calcDisplayname(i18n: i18n),
121121
),
122+
'sdk.dart.matrix.new_megolm_session': (event, i18n, body) => body,
122123
EventTypes.Redaction: (event, i18n, body) => i18n.redactedAnEvent(event),
123124
EventTypes.RoomAliases: (event, i18n, body) => i18n.changedTheRoomAliases(
124125
event.senderFromMemoryOrFallback.calcDisplayname(i18n: i18n),

0 commit comments

Comments
 (0)