diff --git a/lib/pages/chat_list/chat_list.dart b/lib/pages/chat_list/chat_list.dart index ffd52b8a0d..8d6469bcdd 100644 --- a/lib/pages/chat_list/chat_list.dart +++ b/lib/pages/chat_list/chat_list.dart @@ -13,11 +13,11 @@ import 'package:fluffychat/pages/chat_list/chat_list_view.dart'; import 'package:fluffychat/pages/chat_list/receive_sharing_intent_mixin.dart'; import 'package:fluffychat/pages/settings_security/settings_security.dart'; import 'package:fluffychat/presentation/enum/chat_list/chat_list_enum.dart'; +import 'package:fluffychat/presentation/extensions/client_extension.dart'; import 'package:fluffychat/presentation/model/chat_list/chat_selection_actions.dart'; import 'package:fluffychat/utils/extension/build_context_extension.dart'; import 'package:fluffychat/utils/famedlysdk_store.dart'; import 'package:fluffychat/utils/localized_exception_extension.dart'; -import 'package:fluffychat/utils/matrix_sdk_extensions/client_stories_extension.dart'; import 'package:fluffychat/utils/matrix_sdk_extensions/matrix_locals.dart'; import 'package:fluffychat/utils/responsive/responsive_utils.dart'; import 'package:fluffychat/utils/tor_stub.dart' @@ -68,10 +68,6 @@ class ChatListController extends State bool get displayNavigationBar => false; - static const int _ascendingOrder = 1; - - static const int _descendingOrder = -1; - final responsive = getIt.get(); String? activeSpaceId; @@ -94,40 +90,8 @@ class ChatListController extends State ? ActiveFilter.messages : ActiveFilter.allChats; - bool Function(Room) getRoomFilterByActiveFilter(ActiveFilter activeFilter) { - switch (activeFilter) { - case ActiveFilter.allChats: - return (room) => !room.isSpace && !room.isStoryRoom; - case ActiveFilter.groups: - return (room) => - !room.isSpace && !room.isDirectChat && !room.isStoryRoom; - case ActiveFilter.messages: - return (room) => - !room.isSpace && room.isDirectChat && !room.isStoryRoom; - case ActiveFilter.spaces: - return (r) => r.isSpace; - } - } - - List get filteredRoomsForAll => Matrix.of(context) - .client - .rooms - .where(getRoomFilterByActiveFilter(activeFilter)) - .sorted(_sortListRomByTimeCreatedMessage) - .sorted(_sortListRoomByPinMessage) - .toList(); - - int _sortListRomByTimeCreatedMessage(Room currentRoom, Room nextRoom) { - return nextRoom.timeCreated.compareTo(currentRoom.timeCreated); - } - - int _sortListRoomByPinMessage(Room currentRoom, Room nextRoom) { - if (nextRoom.isFavourite && !currentRoom.isFavourite) { - return _ascendingOrder; - } else { - return _descendingOrder; - } - } + List get filteredRoomsForAll => + Matrix.of(context).client.filteredRoomsForAll(activeFilter); bool isSearchMode = false; Future? publicRoomsResponse; diff --git a/lib/pages/forward/forward.dart b/lib/pages/forward/forward.dart index 78d4869fcb..e9684d6ab9 100644 --- a/lib/pages/forward/forward.dart +++ b/lib/pages/forward/forward.dart @@ -9,7 +9,7 @@ import 'package:fluffychat/domain/usecase/forward/forward_message_interactor.dar import 'package:fluffychat/pages/chat/send_file_dialog.dart'; import 'package:fluffychat/pages/forward/forward_view.dart'; import 'package:fluffychat/presentation/enum/chat_list/chat_list_enum.dart'; -import 'package:fluffychat/utils/matrix_sdk_extensions/client_stories_extension.dart'; +import 'package:fluffychat/presentation/extensions/client_extension.dart'; import 'package:flutter/material.dart'; import 'package:go_router/go_router.dart'; import 'package:matrix/matrix.dart'; @@ -18,6 +18,7 @@ import 'package:fluffychat/widgets/matrix.dart'; class Forward extends StatefulWidget { final String? sendFromRoomId; + const Forward({Key? key, this.sendFromRoomId}) : super(key: key); @override @@ -71,26 +72,8 @@ class ForwardController extends State { final ActiveFilter _activeFilterAllChats = ActiveFilter.allChats; - bool Function(Room) getRoomFilterByActiveFilter(ActiveFilter activeFilter) { - switch (activeFilter) { - case ActiveFilter.allChats: - return (room) => !room.isSpace && !room.isStoryRoom; - case ActiveFilter.groups: - return (room) => - !room.isSpace && !room.isDirectChat && !room.isStoryRoom; - case ActiveFilter.messages: - return (room) => - !room.isSpace && room.isDirectChat && !room.isStoryRoom; - case ActiveFilter.spaces: - return (r) => r.isSpace; - } - } - - List get filteredRoomsForAll => Matrix.of(context) - .client - .rooms - .where(getRoomFilterByActiveFilter(_activeFilterAllChats)) - .toList(); + List get filteredRoomsForAll => + Matrix.of(context).client.filteredRoomsForAll(_activeFilterAllChats); void forwardAction() async { forwardMessageInteractorStreamSubscription = _forwardMessageInteractor diff --git a/lib/pages/share/share.dart b/lib/pages/share/share.dart index 76fad322d4..88fe678103 100644 --- a/lib/pages/share/share.dart +++ b/lib/pages/share/share.dart @@ -2,6 +2,8 @@ import 'package:collection/collection.dart'; import 'package:fluffychat/di/global/get_it_initializer.dart'; import 'package:fluffychat/domain/usecase/send_file_interactor.dart'; import 'package:fluffychat/pages/share/share_view.dart'; +import 'package:fluffychat/presentation/enum/chat_list/chat_list_enum.dart'; +import 'package:fluffychat/presentation/extensions/client_extension.dart'; import 'package:fluffychat/presentation/mixins/send_files_mixin.dart'; import 'package:fluffychat/presentation/model/chat/chat_router_input_argument.dart'; import 'package:fluffychat/widgets/matrix.dart'; @@ -74,6 +76,11 @@ class ShareController extends State with SendFilesMixin { } } + final ActiveFilter _activeFilterAllChats = ActiveFilter.allChats; + + List get filteredRoomsForAll => + Matrix.of(context).client.filteredRoomsForAll(_activeFilterAllChats); + @override Widget build(BuildContext context) { return ShareView(this); diff --git a/lib/pages/share/share_view.dart b/lib/pages/share/share_view.dart index 1109067e45..bc28330896 100644 --- a/lib/pages/share/share_view.dart +++ b/lib/pages/share/share_view.dart @@ -5,7 +5,6 @@ import 'package:fluffychat/pages/share/share.dart'; import 'package:fluffychat/resource/image_paths.dart'; import 'package:fluffychat/widgets/app_bars/searchable_app_bar.dart'; import 'package:fluffychat/widgets/app_bars/searchable_app_bar_style.dart'; -import 'package:fluffychat/widgets/matrix.dart'; import 'package:fluffychat/widgets/twake_components/twake_icon_button.dart'; import 'package:flutter/material.dart'; import 'package:flutter_gen/gen_l10n/l10n.dart'; @@ -39,7 +38,7 @@ class ShareView extends StatelessWidget { builder: (context, isShowRecentlyChat, child) { if (isShowRecentlyChat) { return RecentChatList( - rooms: Matrix.of(context).client.rooms, + rooms: controller.filteredRoomsForAll, selectedEventsNotifier: controller.selectedRoomsNotifier, onSelectedChat: (roomId) => controller.onSelectChat(roomId),