Merge branch 'develop' into chore/updateSharePlus
This commit is contained in:
@@ -1,3 +1,9 @@
|
||||
## Upcoming
|
||||
|
||||
🔄 Changed
|
||||
|
||||
- Cancelling a attachment upload now removes the attachment from the message.
|
||||
|
||||
## 5.3.0
|
||||
|
||||
🔄 Changed
|
||||
|
||||
@@ -463,12 +463,19 @@ class Channel {
|
||||
|
||||
client.logger.info('Found ${attachments.length} attachments');
|
||||
|
||||
void updateAttachment(Attachment attachment) {
|
||||
void updateAttachment(Attachment attachment, {bool remove = false}) {
|
||||
final index = message!.attachments.indexWhere(
|
||||
(it) => it.id == attachment.id,
|
||||
);
|
||||
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);
|
||||
state?.updateMessage(updatedMessage);
|
||||
// updating original message for next iteration
|
||||
@@ -533,6 +540,14 @@ class Channel {
|
||||
);
|
||||
}
|
||||
}).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);
|
||||
updateAttachment(
|
||||
it.copyWith(uploadState: UploadState.failed(error: e.toString())),
|
||||
|
||||
@@ -74,6 +74,7 @@ class StreamChatNetworkError extends StreamChatError {
|
||||
ChatErrorCode errorCode, {
|
||||
int? statusCode,
|
||||
this.data,
|
||||
this.isRequestCancelledError = false,
|
||||
}) : code = errorCode.code,
|
||||
statusCode = statusCode ?? data?.statusCode,
|
||||
super(errorCode.message);
|
||||
@@ -84,6 +85,7 @@ class StreamChatNetworkError extends StreamChatError {
|
||||
required String message,
|
||||
this.statusCode,
|
||||
this.data,
|
||||
this.isRequestCancelledError = false,
|
||||
}) : super(message);
|
||||
|
||||
///
|
||||
@@ -100,6 +102,7 @@ class StreamChatNetworkError extends StreamChatError {
|
||||
errorResponse?.message ?? response?.statusMessage ?? error.message,
|
||||
statusCode: errorResponse?.statusCode ?? response?.statusCode,
|
||||
data: errorResponse,
|
||||
isRequestCancelledError: error.type == DioErrorType.cancel,
|
||||
)..stackTrace = error.stackTrace;
|
||||
}
|
||||
|
||||
@@ -112,6 +115,9 @@ class StreamChatNetworkError extends StreamChatError {
|
||||
/// Response body. please refer to [ErrorResponse].
|
||||
final ErrorResponse? data;
|
||||
|
||||
/// True, in case the error is due to a cancelled network request.
|
||||
final bool isRequestCancelledError;
|
||||
|
||||
StackTrace? _stackTrace;
|
||||
|
||||
///
|
||||
|
||||
Reference in New Issue
Block a user