Add olm error stream

This commit is contained in:
Christian Pauly 2020-05-22 15:51:45 +02:00
parent 09edda1f9f
commit c01f75bafa
2 changed files with 29 additions and 4 deletions

View file

@ -639,6 +639,10 @@ class Client {
final StreamController<MatrixException> onError = final StreamController<MatrixException> onError =
StreamController.broadcast(); StreamController.broadcast();
/// Synchronization erros are coming here.
final StreamController<ToDeviceEventDecryptionError> onOlmError =
StreamController.broadcast();
/// This is called once, when the first sync has received. /// This is called once, when the first sync has received.
final StreamController<bool> onFirstSync = StreamController.broadcast(); final StreamController<bool> onFirstSync = StreamController.broadcast();
@ -1134,11 +1138,18 @@ class Client {
if (toDeviceEvent.type == 'm.room.encrypted') { if (toDeviceEvent.type == 'm.room.encrypted') {
try { try {
toDeviceEvent = decryptToDeviceEvent(toDeviceEvent); toDeviceEvent = decryptToDeviceEvent(toDeviceEvent);
} catch (e) { } catch (e, s) {
print( print(
'[LibOlm] Could not decrypt to device event from ${toDeviceEvent.sender}: ' + '[LibOlm] Could not decrypt to device event from ${toDeviceEvent.sender} with content: ${toDeviceEvent.content}');
e.toString()); print(e);
print(toDeviceEvent.sender); print(s);
onOlmError.add(
ToDeviceEventDecryptionError(
exception: e,
stackTrace: s,
toDeviceEvent: toDeviceEvent,
),
);
toDeviceEvent = ToDeviceEvent.fromJson(events[i]); toDeviceEvent = ToDeviceEvent.fromJson(events[i]);
} }
} }

View file

@ -24,3 +24,17 @@ class ToDeviceEvent {
return data; return data;
} }
} }
class ToDeviceEventDecryptionError extends ToDeviceEvent {
Exception exception;
StackTrace stackTrace;
ToDeviceEventDecryptionError({
ToDeviceEvent toDeviceEvent,
this.exception,
this.stackTrace,
}) : super(
sender: toDeviceEvent.sender,
content: toDeviceEvent.content,
type: toDeviceEvent.type,
);
}