fix: Wait for rate limit to pass while sending messages
Otherwise the user can't handle that exception themselves, since we don't rethrow.
This commit is contained in:
parent
fa73ab3c6f
commit
97bf7723dd
|
|
@ -1100,7 +1100,16 @@ class Room {
|
|||
txid: messageID,
|
||||
);
|
||||
} catch (e, s) {
|
||||
if (e is MatrixException || DateTime.now().isAfter(timeoutDate)) {
|
||||
if (e is MatrixException &&
|
||||
e.retryAfterMs != null &&
|
||||
!DateTime.now()
|
||||
.add(Duration(milliseconds: e.retryAfterMs!))
|
||||
.isAfter(timeoutDate)) {
|
||||
Logs().w(
|
||||
'Ratelimited while sending message, waiting for ${e.retryAfterMs}ms');
|
||||
await Future.delayed(Duration(milliseconds: e.retryAfterMs!));
|
||||
} else if (e is MatrixException ||
|
||||
DateTime.now().isAfter(timeoutDate)) {
|
||||
Logs().w('Problem while sending message', e, s);
|
||||
syncUpdate.rooms!.join!.values.first.timeline!.events!.first
|
||||
.unsigned![messageSendingStatusKey] = EventStatus.error.intValue;
|
||||
|
|
@ -1108,11 +1117,13 @@ class Room {
|
|||
completer.complete();
|
||||
_sendingQueue.remove(completer);
|
||||
return null;
|
||||
}
|
||||
Logs().w('Problem while sending message: $e Try again in 1 seconds...');
|
||||
} else {
|
||||
Logs()
|
||||
.w('Problem while sending message: $e Try again in 1 seconds...');
|
||||
await Future.delayed(Duration(seconds: 1));
|
||||
}
|
||||
}
|
||||
}
|
||||
syncUpdate.rooms!.join!.values.first.timeline!.events!.first
|
||||
.unsigned![messageSendingStatusKey] = EventStatus.sent.intValue;
|
||||
syncUpdate.rooms!.join!.values.first.timeline!.events!.first.eventId = res;
|
||||
|
|
|
|||
Loading…
Reference in New Issue