Merge branch 'develop' into chore/updateSharePlus

This commit is contained in:
Sahil Kumar
2023-02-09 15:20:00 +05:30
committed by GitHub
3 changed files with 29 additions and 2 deletions
+6
View File
@@ -1,3 +1,9 @@
## Upcoming
🔄 Changed
- Cancelling a attachment upload now removes the attachment from the message.
## 5.3.0 ## 5.3.0
🔄 Changed 🔄 Changed
@@ -463,12 +463,19 @@ class Channel {
client.logger.info('Found ${attachments.length} attachments'); client.logger.info('Found ${attachments.length} attachments');
void updateAttachment(Attachment attachment) { void updateAttachment(Attachment attachment, {bool remove = false}) {
final index = message!.attachments.indexWhere( final index = message!.attachments.indexWhere(
(it) => it.id == attachment.id, (it) => it.id == attachment.id,
); );
if (index != -1) { if (index != -1) {
final newAttachments = [...message!.attachments]..[index] = attachment; // update or remove attachment from message.
final List<Attachment> newAttachments;
if (remove) {
newAttachments = [...message!.attachments]..removeAt(index);
} else {
newAttachments = [...message!.attachments]..[index] = attachment;
}
final updatedMessage = message!.copyWith(attachments: newAttachments); final updatedMessage = message!.copyWith(attachments: newAttachments);
state?.updateMessage(updatedMessage); state?.updateMessage(updatedMessage);
// updating original message for next iteration // updating original message for next iteration
@@ -533,6 +540,14 @@ class Channel {
); );
} }
}).catchError((e, stk) { }).catchError((e, stk) {
if (e is StreamChatNetworkError && e.isRequestCancelledError) {
client.logger.info('Attachment ${it.id} upload cancelled');
// remove attachment from message if cancelled.
updateAttachment(it, remove: true);
return;
}
client.logger.severe('error uploading the attachment', e, stk); client.logger.severe('error uploading the attachment', e, stk);
updateAttachment( updateAttachment(
it.copyWith(uploadState: UploadState.failed(error: e.toString())), it.copyWith(uploadState: UploadState.failed(error: e.toString())),
@@ -74,6 +74,7 @@ class StreamChatNetworkError extends StreamChatError {
ChatErrorCode errorCode, { ChatErrorCode errorCode, {
int? statusCode, int? statusCode,
this.data, this.data,
this.isRequestCancelledError = false,
}) : code = errorCode.code, }) : code = errorCode.code,
statusCode = statusCode ?? data?.statusCode, statusCode = statusCode ?? data?.statusCode,
super(errorCode.message); super(errorCode.message);
@@ -84,6 +85,7 @@ class StreamChatNetworkError extends StreamChatError {
required String message, required String message,
this.statusCode, this.statusCode,
this.data, this.data,
this.isRequestCancelledError = false,
}) : super(message); }) : super(message);
/// ///
@@ -100,6 +102,7 @@ class StreamChatNetworkError extends StreamChatError {
errorResponse?.message ?? response?.statusMessage ?? error.message, errorResponse?.message ?? response?.statusMessage ?? error.message,
statusCode: errorResponse?.statusCode ?? response?.statusCode, statusCode: errorResponse?.statusCode ?? response?.statusCode,
data: errorResponse, data: errorResponse,
isRequestCancelledError: error.type == DioErrorType.cancel,
)..stackTrace = error.stackTrace; )..stackTrace = error.stackTrace;
} }
@@ -112,6 +115,9 @@ class StreamChatNetworkError extends StreamChatError {
/// Response body. please refer to [ErrorResponse]. /// Response body. please refer to [ErrorResponse].
final ErrorResponse? data; final ErrorResponse? data;
/// True, in case the error is due to a cancelled network request.
final bool isRequestCancelledError;
StackTrace? _stackTrace; StackTrace? _stackTrace;
/// ///