Merge branch 'krille/try-again-sending' into 'main'
feat: Try again uploading file events for one minute See merge request famedly/company/frontend/famedlysdk!986
This commit is contained in:
commit
23e0d29a0d
|
|
@ -102,6 +102,8 @@ class Client extends MatrixApi {
|
|||
return await function(arg);
|
||||
}
|
||||
|
||||
final Duration sendTimelineEventTimeout;
|
||||
|
||||
/// Create a client
|
||||
/// [clientName] = unique identifier of this client
|
||||
/// [databaseBuilder]: A function that creates the database instance, that will be used.
|
||||
|
|
@ -137,6 +139,8 @@ class Client extends MatrixApi {
|
|||
/// will use lazy_load_members.
|
||||
/// Set [compute] to the Flutter compute method to enable the SDK to run some
|
||||
/// code in background.
|
||||
/// Set [timelineEventTimeout] to the preferred time the Client should retry
|
||||
/// sending events on connection problems or to `Duration.zero` to disable it.
|
||||
Client(
|
||||
this.clientName, {
|
||||
this.databaseBuilder,
|
||||
|
|
@ -159,6 +163,7 @@ class Client extends MatrixApi {
|
|||
this.compute,
|
||||
Level? logLevel,
|
||||
Filter? syncFilter,
|
||||
this.sendTimelineEventTimeout = const Duration(minutes: 1),
|
||||
@deprecated bool? debug,
|
||||
}) : syncFilter = syncFilter ??
|
||||
Filter(
|
||||
|
|
|
|||
|
|
@ -714,18 +714,34 @@ class Room {
|
|||
uploadThumbnail = encryptedThumbnail.toMatrixFile();
|
||||
}
|
||||
}
|
||||
final uploadResp = await client.uploadContent(
|
||||
Uri? uploadResp, thumbnailUploadResp;
|
||||
|
||||
final timeoutDate = DateTime.now().add(client.sendTimelineEventTimeout);
|
||||
while (uploadResp == null ||
|
||||
(uploadThumbnail != null && thumbnailUploadResp == null)) {
|
||||
try {
|
||||
uploadResp = await client.uploadContent(
|
||||
uploadFile.bytes,
|
||||
filename: uploadFile.name,
|
||||
contentType: uploadFile.mimeType,
|
||||
);
|
||||
final thumbnailUploadResp = uploadThumbnail != null
|
||||
thumbnailUploadResp = uploadThumbnail != null
|
||||
? await client.uploadContent(
|
||||
uploadThumbnail.bytes,
|
||||
filename: uploadThumbnail.name,
|
||||
contentType: uploadThumbnail.mimeType,
|
||||
)
|
||||
: null;
|
||||
} on MatrixException catch (_) {
|
||||
rethrow;
|
||||
} catch (_) {
|
||||
if (DateTime.now().isAfter(timeoutDate)) {
|
||||
rethrow;
|
||||
}
|
||||
Logs().v('Send File into room failed. Try again...');
|
||||
await Future.delayed(Duration(seconds: 1));
|
||||
}
|
||||
}
|
||||
|
||||
// Send event
|
||||
final content = <String, dynamic>{
|
||||
|
|
@ -912,6 +928,7 @@ class Room {
|
|||
);
|
||||
await _handleFakeSync(syncUpdate);
|
||||
|
||||
final timeoutDate = DateTime.now().add(client.sendTimelineEventTimeout);
|
||||
// Send the text and on success, store and display a *sent* event.
|
||||
String? res;
|
||||
while (res == null) {
|
||||
|
|
@ -922,20 +939,15 @@ class Room {
|
|||
txid: messageID,
|
||||
);
|
||||
} catch (e, s) {
|
||||
if ((DateTime.now().millisecondsSinceEpoch -
|
||||
sentDate.millisecondsSinceEpoch) <
|
||||
(1000 * client.sendMessageTimeoutSeconds)) {
|
||||
Logs().w('[Client] Problem while sending message because of "' +
|
||||
e.toString() +
|
||||
'". Try again in 1 seconds...');
|
||||
await Future.delayed(Duration(seconds: 1));
|
||||
} else {
|
||||
Logs().w('[Client] Problem while sending message', e, s);
|
||||
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;
|
||||
await _handleFakeSync(syncUpdate);
|
||||
return null;
|
||||
}
|
||||
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
|
||||
|
|
|
|||
Loading…
Reference in New Issue