Skip to content

Commit

Permalink
TW-1302: Apply for search in unencrypted chat
Browse files Browse the repository at this point in the history
  • Loading branch information
nqhhdev committed Jan 12, 2024
1 parent 22b3ada commit 107ac79
Show file tree
Hide file tree
Showing 8 changed files with 66 additions and 39 deletions.
45 changes: 29 additions & 16 deletions lib/pages/chat_search/chat_search_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import 'package:fluffychat/pages/chat_list/chat_list_header_style.dart';
import 'package:fluffychat/pages/chat_search/chat_search.dart';
import 'package:fluffychat/pages/chat_search/chat_search_style.dart';
import 'package:fluffychat/pages/search/server_search_controller.dart';
import 'package:fluffychat/presentation/model/search/presentation_server_side_empty_search.dart';
import 'package:fluffychat/presentation/model/search/presentation_server_side_search.dart';
import 'package:fluffychat/presentation/same_type_events_builder/same_type_events_builder.dart';
import 'package:fluffychat/presentation/same_type_events_builder/same_type_events_controller.dart';
Expand Down Expand Up @@ -84,23 +85,35 @@ class _ServerSearchView extends StatelessWidget {
ValueListenableBuilder(
valueListenable: serverSearchController.searchResultsNotifier,
builder: (context, searchResults, child) {
final events = (searchResults as PresentationServerSideSearch)
.searchResults
.map((result) => result.getEvent(context))
.whereNotNull()
.toList();
return SliverList.builder(
itemCount: events.length,
itemBuilder: (context, index) {
final event = events[index];
return _SearchItem(
event: event,
searchWord: controller.serverSearchController.debouncerValue,
onTap: controller.onEventTap,
);
},
);
if (searchResults is PresentationServerSideSearch) {
final events = searchResults.searchResults
.map((result) => result.getEvent(context))
.whereNotNull()
.toList();
return SliverList.builder(
itemCount: events.length,
itemBuilder: (context, index) {
final event = events[index];
return _SearchItem(
event: event,
searchWord:
controller.serverSearchController.debouncerValue,
onTap: controller.onEventTap,
);
},
);
}

if (searchResults is PresentationServerSideEmptySearch) {
return const SliverToBoxAdapter(
child: EmptySearchWidget(),
);
}
return child!;
},
child: const SliverToBoxAdapter(
child: SizedBox(),
),
),
ValueListenableBuilder(
valueListenable: serverSearchController.isLoadingMoreNotifier,
Expand Down
9 changes: 9 additions & 0 deletions lib/pages/search/search_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import 'package:fluffychat/pages/search/recent_item_widget.dart';
import 'package:fluffychat/pages/search/search.dart';
import 'package:fluffychat/pages/search/search_view_style.dart';
import 'package:fluffychat/pages/search/server_search_view.dart';
import 'package:fluffychat/presentation/model/search/presentation_server_side_empty_search.dart';
import 'package:fluffychat/presentation/model/search/presentation_server_side_search.dart';
import 'package:fluffychat/widgets/twake_components/twake_icon_button.dart';
import 'package:fluffychat/widgets/twake_components/twake_loading/center_loading_indicator.dart';
Expand Down Expand Up @@ -74,6 +75,14 @@ class SearchView extends StatelessWidget {
valueListenable:
searchController.serverSearchController.searchResultsNotifier,
builder: ((context, searchResults, child) {
if (searchResults is PresentationServerSideEmptySearch) {
return _SearchHeader(
header: L10n.of(context)!.messages,
searchController: searchController,
needShowMore: false,
);
}

if (searchResults is PresentationServerSideSearch) {
if (searchResults.searchResults.isEmpty) {
return child!;
Expand Down
19 changes: 11 additions & 8 deletions lib/pages/search/server_search_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import 'package:fluffychat/di/global/get_it_initializer.dart';
import 'package:fluffychat/domain/model/search/server_side_search_categories.dart';
import 'package:fluffychat/pages/search/search_debouncer_mixin.dart';
import 'package:fluffychat/domain/usecase/search/server_search_interactor.dart';
import 'package:fluffychat/presentation/model/search/presentation_server_side.dart';
import 'package:fluffychat/presentation/model/search/presentation_server_side_state.dart';
import 'package:fluffychat/presentation/model/search/presentation_server_side_empty_search.dart';
import 'package:fluffychat/presentation/model/search/presentation_server_side_search.dart';
import 'package:flutter/material.dart';
Expand All @@ -23,8 +23,8 @@ class ServerSearchController with SearchDebouncerMixin {

final _serverSearchInteractor = getIt.get<ServerSearchInteractor>();

final searchResultsNotifier = ValueNotifier<PresentationServerSide>(
PresentationServerSide(),
final searchResultsNotifier = ValueNotifier<PresentationServerSideUIState>(
PresentationServerSideInitial(),
);

static const int _limitServerSideSearchFilter = 20;
Expand Down Expand Up @@ -79,8 +79,10 @@ class ServerSearchController with SearchDebouncerMixin {
} else {
searchResultsNotifier.value = PresentationServerSideSearch(
searchResults: [
...(searchResultsNotifier.value as PresentationServerSideSearch)
.searchResults,
if (searchResultsNotifier.value is PresentationServerSideSearch)
...(searchResultsNotifier.value
as PresentationServerSideSearch)
.searchResults,
...success.results ?? [],
],
);
Expand Down Expand Up @@ -134,9 +136,10 @@ class ServerSearchController with SearchDebouncerMixin {
void loadMore() {
if (_searchCategories == null ||
isLoadingMoreNotifier.value ||
(searchResultsNotifier.value as PresentationServerSideSearch)
.searchResults
.isEmpty ||
((searchResultsNotifier.value is PresentationServerSideSearch) &&
(searchResultsNotifier.value as PresentationServerSideSearch)
.searchResults
.isEmpty) ||
_nextBatch == null) {
return;
}
Expand Down
10 changes: 5 additions & 5 deletions lib/pages/search/server_search_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,20 +26,20 @@ class ServerSearchMessagesList extends StatelessWidget {
child: ValueListenableBuilder(
valueListenable:
searchController.serverSearchController.searchResultsNotifier,
builder: (context, severSearchNotifier, child) {
if (severSearchNotifier is PresentationServerSideEmptySearch) {
builder: (context, serverSearchNotifier, child) {
if (serverSearchNotifier is PresentationServerSideEmptySearch) {
return child!;
}

if (severSearchNotifier is PresentationServerSideSearch) {
if (serverSearchNotifier is PresentationServerSideSearch) {
return ListView.builder(
shrinkWrap: true,
physics: const ClampingScrollPhysics(),
itemCount: severSearchNotifier.searchResults.length,
itemCount: serverSearchNotifier.searchResults.length,
padding: ServerSearchViewStyle.paddingListItem,
itemBuilder: ((context, index) {
final searchResult =
severSearchNotifier.searchResults[index].result;
serverSearchNotifier.searchResults[index].result;
final room = Matrix.of(context).client.getRoomById(
searchResult?.roomId ?? '',
);
Expand Down
6 changes: 0 additions & 6 deletions lib/presentation/model/search/presentation_server_side.dart

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import 'package:fluffychat/presentation/model/search/presentation_server_side.dart';
import 'package:fluffychat/presentation/model/search/presentation_server_side_state.dart';

class PresentationServerSideEmptySearch extends PresentationServerSide {
class PresentationServerSideEmptySearch extends PresentationServerSideUIState {
@override
List<Object> get props => [];
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import 'package:fluffychat/presentation/model/search/presentation_server_side.dart';
import 'package:fluffychat/presentation/model/search/presentation_server_side_state.dart';
import 'package:matrix/matrix.dart';

class PresentationServerSideSearch extends PresentationServerSide {
class PresentationServerSideSearch extends PresentationServerSideUIState {
final List<Result> searchResults;

PresentationServerSideSearch({
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import 'package:equatable/equatable.dart';

abstract class PresentationServerSideUIState with EquatableMixin {
@override
List<Object?> get props => [];
}

class PresentationServerSideInitial extends PresentationServerSideUIState {}

0 comments on commit 107ac79

Please sign in to comment.