From b36c31c9920a71242bc698fc24a9384c7ce83324 Mon Sep 17 00:00:00 2001 From: Salvatore Giordano Date: Mon, 1 Mar 2021 11:55:37 +0100 Subject: [PATCH] debounce updateAttachment --- packages/stream_chat/lib/src/api/channel.dart | 12 +++++++++--- packages/stream_chat/lib/src/debounce.dart | 2 +- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/packages/stream_chat/lib/src/api/channel.dart b/packages/stream_chat/lib/src/api/channel.dart index c45ec409..90cc2f4f 100644 --- a/packages/stream_chat/lib/src/api/channel.dart +++ b/packages/stream_chat/lib/src/api/channel.dart @@ -238,9 +238,15 @@ class Channel { } void onSendProgress(int sent, int total) { - updateAttachment(it.copyWith( - uploadState: UploadState.inProgress(uploaded: sent, total: total), - )); + debounce( + timeout: Duration(seconds: 1), + target: updateAttachment, + arguments: [ + it.copyWith( + uploadState: UploadState.inProgress(uploaded: sent, total: total), + ), + ], + ); } final isImage = it.type == 'image'; diff --git a/packages/stream_chat/lib/src/debounce.dart b/packages/stream_chat/lib/src/debounce.dart index c0375cf5..6bf90658 100644 --- a/packages/stream_chat/lib/src/debounce.dart +++ b/packages/stream_chat/lib/src/debounce.dart @@ -3,7 +3,7 @@ import 'dart:async'; import 'package:meta/meta.dart'; /// Map of timeouts being debounced -Map timeouts = {}; +Map timeouts = {}; /// Runs a function avoiding calling it too many times in a [timeoutMS] window void debounce({