Skip to content

Commit

Permalink
TW-570: Apply filter for chat list, forward, share
Browse files Browse the repository at this point in the history
  • Loading branch information
nqhhdev authored and hoangdat committed Sep 28, 2023
1 parent 3282540 commit 369fe20
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 62 deletions.
42 changes: 3 additions & 39 deletions lib/pages/chat_list/chat_list.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -68,10 +68,6 @@ class ChatListController extends State<ChatList>

bool get displayNavigationBar => false;

static const int _ascendingOrder = 1;

static const int _descendingOrder = -1;

final responsive = getIt.get<ResponsiveUtils>();

String? activeSpaceId;
Expand All @@ -94,40 +90,8 @@ class ChatListController extends State<ChatList>
? 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<Room> 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<Room> get filteredRoomsForAll =>
Matrix.of(context).client.filteredRoomsForAll(activeFilter);

bool isSearchMode = false;
Future<QueryPublicRoomsResponse>? publicRoomsResponse;
Expand Down
25 changes: 4 additions & 21 deletions lib/pages/forward/forward.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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
Expand Down Expand Up @@ -71,26 +72,8 @@ class ForwardController extends State<Forward> {

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<Room> get filteredRoomsForAll => Matrix.of(context)
.client
.rooms
.where(getRoomFilterByActiveFilter(_activeFilterAllChats))
.toList();
List<Room> get filteredRoomsForAll =>
Matrix.of(context).client.filteredRoomsForAll(_activeFilterAllChats);

void forwardAction() async {
forwardMessageInteractorStreamSubscription = _forwardMessageInteractor
Expand Down
7 changes: 7 additions & 0 deletions lib/pages/share/share.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -74,6 +76,11 @@ class ShareController extends State<Share> with SendFilesMixin {
}
}

final ActiveFilter _activeFilterAllChats = ActiveFilter.allChats;

List<Room> get filteredRoomsForAll =>
Matrix.of(context).client.filteredRoomsForAll(_activeFilterAllChats);

@override
Widget build(BuildContext context) {
return ShareView(this);
Expand Down
3 changes: 1 addition & 2 deletions lib/pages/share/share_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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),
Expand Down

0 comments on commit 369fe20

Please sign in to comment.