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,
|
txid: messageID,
|
||||||
);
|
);
|
||||||
} catch (e, s) {
|
} 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);
|
Logs().w('Problem while sending message', e, s);
|
||||||
syncUpdate.rooms!.join!.values.first.timeline!.events!.first
|
syncUpdate.rooms!.join!.values.first.timeline!.events!.first
|
||||||
.unsigned![messageSendingStatusKey] = EventStatus.error.intValue;
|
.unsigned![messageSendingStatusKey] = EventStatus.error.intValue;
|
||||||
|
|
@ -1108,9 +1117,11 @@ class Room {
|
||||||
completer.complete();
|
completer.complete();
|
||||||
_sendingQueue.remove(completer);
|
_sendingQueue.remove(completer);
|
||||||
return null;
|
return null;
|
||||||
|
} else {
|
||||||
|
Logs()
|
||||||
|
.w('Problem while sending message: $e Try again in 1 seconds...');
|
||||||
|
await Future.delayed(Duration(seconds: 1));
|
||||||
}
|
}
|
||||||
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
|
syncUpdate.rooms!.join!.values.first.timeline!.events!.first
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue