feat: Try again uploading file events for one minute
This also refactors the code for sending events with the same Duration of one minute.
This commit is contained in:
parent
118f2e6b97
commit
f86b242dcf
|
|
@ -102,6 +102,8 @@ class Client extends MatrixApi {
|
||||||
return await function(arg);
|
return await function(arg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
final Duration sendTimelineEventTimeout;
|
||||||
|
|
||||||
/// Create a client
|
/// Create a client
|
||||||
/// [clientName] = unique identifier of this client
|
/// [clientName] = unique identifier of this client
|
||||||
/// [databaseBuilder]: A function that creates the database instance, that will be used.
|
/// [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.
|
/// will use lazy_load_members.
|
||||||
/// Set [compute] to the Flutter compute method to enable the SDK to run some
|
/// Set [compute] to the Flutter compute method to enable the SDK to run some
|
||||||
/// code in background.
|
/// 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(
|
Client(
|
||||||
this.clientName, {
|
this.clientName, {
|
||||||
this.databaseBuilder,
|
this.databaseBuilder,
|
||||||
|
|
@ -158,6 +162,7 @@ class Client extends MatrixApi {
|
||||||
this.formatLocalpart = true,
|
this.formatLocalpart = true,
|
||||||
this.compute,
|
this.compute,
|
||||||
Filter? syncFilter,
|
Filter? syncFilter,
|
||||||
|
this.sendTimelineEventTimeout = const Duration(minutes: 1),
|
||||||
@deprecated bool? debug,
|
@deprecated bool? debug,
|
||||||
}) : syncFilter = syncFilter ??
|
}) : syncFilter = syncFilter ??
|
||||||
Filter(
|
Filter(
|
||||||
|
|
|
||||||
|
|
@ -718,18 +718,34 @@ class Room {
|
||||||
uploadThumbnail = encryptedThumbnail.toMatrixFile();
|
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,
|
uploadFile.bytes,
|
||||||
filename: uploadFile.name,
|
filename: uploadFile.name,
|
||||||
contentType: uploadFile.mimeType,
|
contentType: uploadFile.mimeType,
|
||||||
);
|
);
|
||||||
final thumbnailUploadResp = uploadThumbnail != null
|
thumbnailUploadResp = uploadThumbnail != null
|
||||||
? await client.uploadContent(
|
? await client.uploadContent(
|
||||||
uploadThumbnail.bytes,
|
uploadThumbnail.bytes,
|
||||||
filename: uploadThumbnail.name,
|
filename: uploadThumbnail.name,
|
||||||
contentType: uploadThumbnail.mimeType,
|
contentType: uploadThumbnail.mimeType,
|
||||||
)
|
)
|
||||||
: null;
|
: 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
|
// Send event
|
||||||
final content = <String, dynamic>{
|
final content = <String, dynamic>{
|
||||||
|
|
@ -916,6 +932,7 @@ class Room {
|
||||||
);
|
);
|
||||||
await _handleFakeSync(syncUpdate);
|
await _handleFakeSync(syncUpdate);
|
||||||
|
|
||||||
|
final timeoutDate = DateTime.now().add(client.sendTimelineEventTimeout);
|
||||||
// Send the text and on success, store and display a *sent* event.
|
// Send the text and on success, store and display a *sent* event.
|
||||||
String? res;
|
String? res;
|
||||||
while (res == null) {
|
while (res == null) {
|
||||||
|
|
@ -926,20 +943,15 @@ class Room {
|
||||||
txid: messageID,
|
txid: messageID,
|
||||||
);
|
);
|
||||||
} catch (e, s) {
|
} catch (e, s) {
|
||||||
if ((DateTime.now().millisecondsSinceEpoch -
|
if (e is MatrixException || DateTime.now().isAfter(timeoutDate)) {
|
||||||
sentDate.millisecondsSinceEpoch) <
|
Logs().w('Problem while sending message', e, s);
|
||||||
(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);
|
|
||||||
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;
|
||||||
await _handleFakeSync(syncUpdate);
|
await _handleFakeSync(syncUpdate);
|
||||||
return null;
|
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
|
syncUpdate.rooms!.join!.values.first.timeline!.events!.first
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue