Skip to content

Commit

Permalink
TW-853: Create StreamSubscription for getContact
Browse files Browse the repository at this point in the history
  • Loading branch information
nqhhdev authored and hoangdat committed Oct 27, 2023
1 parent 9eb5800 commit 091e912
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
2 changes: 2 additions & 0 deletions lib/pages/new_private_chat/search_contacts_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -83,5 +83,7 @@ mixin class SearchContactsMixinController {
_debouncer.cancel();
_getContactController?.dispose();
textEditingController.dispose();
isSearchModeNotifier.dispose();
searchFocusNode.dispose();
}
}
10 changes: 8 additions & 2 deletions lib/pages/search/get_contacts_controller.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import 'dart:async';

import 'package:dartz/dartz.dart';
import 'package:fluffychat/app_state/failure.dart';
import 'package:fluffychat/app_state/success.dart';
Expand All @@ -18,6 +20,9 @@ class GetContactsController {
final contactsNotifier = ValueNotifier<Either<Failure, Success>>(
const Right(GetContactsInitial()),
);

StreamSubscription? _getContactsSubscription;

final refreshController = TwakeRefreshController();
bool _isLoadMore = false;
Success? _lastSuccess;
Expand All @@ -26,7 +31,7 @@ class GetContactsController {
required String keyword,
int limit = AppConfig.fetchContactsLimit,
}) {
_getContactsInteractor
_getContactsSubscription = _getContactsInteractor
.execute(keyword: keyword, offset: 0, limit: limit)
.listen((event) {
contactsNotifier.value = event.map((success) {
Expand All @@ -52,7 +57,7 @@ class GetContactsController {
return;
}
_isLoadMore = true;
_getContactsInteractor
_getContactsSubscription = _getContactsInteractor
.execute(
keyword: success.keyword,
offset: success.offset,
Expand All @@ -77,5 +82,6 @@ class GetContactsController {

void dispose() {
contactsNotifier.dispose();
_getContactsSubscription?.cancel();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,10 @@ class TwakeLinkPreviewItem extends StatelessWidget {
height: TwakeLinkPreviewItemStyle.heightMxcImagePreview,
width: TwakeLinkPreviewItemStyle.heightMxcImagePreview,
child: MxcImage(
height: TwakeLinkPreviewItemStyle.heightMxcImagePreview,
width: TwakeLinkPreviewItemStyle.heightMxcImagePreview,
uri: urlPreviewPresentation.imageUri,
fit: BoxFit.fill,
fit: BoxFit.cover,
isThumbnail: false,
placeholder: (_) => const SizedBox(),
),
Expand Down

0 comments on commit 091e912

Please sign in to comment.