[LLC] Refactor attachment_file_uploader usage in client and channel

Signed-off-by: Sahil Kumar <[email protected]>
This commit is contained in:
Sahil Kumar
2021-02-17 20:14:01 +05:30
parent 517c7e489d
commit b29f673e91
5 changed files with 144 additions and 71 deletions
+13 -8
View File
@@ -245,15 +245,20 @@ class Channel {
}
final isImage = it.type == 'image';
final uploader = _client.attachmentUploader;
final cancelToken = CancelToken();
Future<String> future;
if (isImage) {
future = uploader.uploadImage(it.file, id, type,
onSendProgress: onSendProgress, cancelToken: cancelToken);
future = sendImage(
it.file,
onSendProgress: onSendProgress,
cancelToken: cancelToken,
).then((it) => it.file);
} else {
future = uploader.uploadFile(it.file, id, type,
onSendProgress: onSendProgress, cancelToken: cancelToken);
future = sendFile(
it.file,
onSendProgress: onSendProgress,
cancelToken: cancelToken,
).then((it) => it.file);
}
_cancelableAttachmentUploadRequest[it.id] = cancelToken;
return future.then((url) {
@@ -446,7 +451,7 @@ class Channel {
/// Send a file to this channel
Future<SendFileResponse> sendFile(
MultipartFile file, {
AttachmentFile file, {
ProgressCallback onSendProgress,
CancelToken cancelToken,
}) {
@@ -461,12 +466,12 @@ class Channel {
/// Send an image to this channel
Future<SendImageResponse> sendImage(
MultipartFile image, {
AttachmentFile file, {
ProgressCallback onSendProgress,
CancelToken cancelToken,
}) {
return _client.sendImage(
image,
file,
id,
type,
onSendProgress: onSendProgress,