refactor: Check config at file sending after placing fake event and add error handling
This should fix the unresponsivness of apps for a few seconds when trying to send a file
This commit is contained in:
parent
d981fcd2f9
commit
bdedef9379
|
|
@ -697,12 +697,6 @@ class Room {
|
||||||
MatrixImageFile? thumbnail,
|
MatrixImageFile? thumbnail,
|
||||||
Map<String, dynamic>? extraContent,
|
Map<String, dynamic>? extraContent,
|
||||||
}) async {
|
}) async {
|
||||||
final mediaConfig = await client.getConfig();
|
|
||||||
final maxMediaSize = mediaConfig.mUploadSize;
|
|
||||||
if (maxMediaSize != null && maxMediaSize < file.bytes.lengthInBytes) {
|
|
||||||
throw FileTooBigMatrixException(file.bytes.lengthInBytes, maxMediaSize);
|
|
||||||
}
|
|
||||||
|
|
||||||
txid ??= client.generateUniqueTransactionId();
|
txid ??= client.generateUniqueTransactionId();
|
||||||
sendingFilePlaceholders[txid] = file;
|
sendingFilePlaceholders[txid] = file;
|
||||||
if (thumbnail != null) {
|
if (thumbnail != null) {
|
||||||
|
|
@ -745,6 +739,22 @@ class Room {
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// Check media config of the server before sending the file. Stop if the
|
||||||
|
// Media config is unreachable or the file is bigger than the given maxsize.
|
||||||
|
try {
|
||||||
|
final mediaConfig = await client.getConfig();
|
||||||
|
final maxMediaSize = mediaConfig.mUploadSize;
|
||||||
|
if (maxMediaSize != null && maxMediaSize < file.bytes.lengthInBytes) {
|
||||||
|
throw FileTooBigMatrixException(file.bytes.lengthInBytes, maxMediaSize);
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
Logs().d('Config error while sending file', e);
|
||||||
|
syncUpdate.rooms!.join!.values.first.timeline!.events!.first
|
||||||
|
.unsigned![messageSendingStatusKey] = EventStatus.error.intValue;
|
||||||
|
await _handleFakeSync(syncUpdate);
|
||||||
|
rethrow;
|
||||||
|
}
|
||||||
|
|
||||||
MatrixFile uploadFile = file; // ignore: omit_local_variable_types
|
MatrixFile uploadFile = file; // ignore: omit_local_variable_types
|
||||||
// computing the thumbnail in case we can
|
// computing the thumbnail in case we can
|
||||||
if (file is MatrixImageFile &&
|
if (file is MatrixImageFile &&
|
||||||
|
|
@ -958,7 +968,7 @@ class Room {
|
||||||
String? editEventId,
|
String? editEventId,
|
||||||
}) async {
|
}) async {
|
||||||
// Create new transaction id
|
// Create new transaction id
|
||||||
String messageID;
|
final String messageID;
|
||||||
if (txid == null) {
|
if (txid == null) {
|
||||||
messageID = client.generateUniqueTransactionId();
|
messageID = client.generateUniqueTransactionId();
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue