chore: Follow up search
This commit is contained in:
parent
67f047ecfc
commit
d819128881
5 changed files with 105 additions and 45 deletions
|
|
@ -28,11 +28,12 @@ class ChatSearchFilesTab extends StatelessWidget {
|
||||||
return StreamBuilder(
|
return StreamBuilder(
|
||||||
stream: searchStream,
|
stream: searchStream,
|
||||||
builder: (context, snapshot) {
|
builder: (context, snapshot) {
|
||||||
if (searchStream == null) {
|
final events = snapshot.data?.$1;
|
||||||
|
if (searchStream == null || events == null) {
|
||||||
return Column(
|
return Column(
|
||||||
mainAxisAlignment: MainAxisAlignment.center,
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
children: [
|
children: [
|
||||||
const Icon(Icons.search_outlined, size: 64),
|
const CircularProgressIndicator.adaptive(strokeWidth: 2),
|
||||||
const SizedBox(height: 8),
|
const SizedBox(height: 8),
|
||||||
Text(
|
Text(
|
||||||
L10n.of(context)!.searchIn(
|
L10n.of(context)!.searchIn(
|
||||||
|
|
@ -44,10 +45,6 @@ class ChatSearchFilesTab extends StatelessWidget {
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
final events = snapshot.data?.$1
|
|
||||||
.where((event) => event.messageType == MessageTypes.File)
|
|
||||||
.toList() ??
|
|
||||||
[];
|
|
||||||
|
|
||||||
if (events.isEmpty) {
|
if (events.isEmpty) {
|
||||||
return Column(
|
return Column(
|
||||||
|
|
|
||||||
|
|
@ -27,11 +27,12 @@ class ChatSearchImagesTab extends StatelessWidget {
|
||||||
return StreamBuilder(
|
return StreamBuilder(
|
||||||
stream: searchStream,
|
stream: searchStream,
|
||||||
builder: (context, snapshot) {
|
builder: (context, snapshot) {
|
||||||
if (searchStream == null) {
|
final events = snapshot.data?.$1;
|
||||||
|
if (searchStream == null || events == null) {
|
||||||
return Column(
|
return Column(
|
||||||
mainAxisAlignment: MainAxisAlignment.center,
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
children: [
|
children: [
|
||||||
const Icon(Icons.search_outlined, size: 64),
|
const CircularProgressIndicator.adaptive(strokeWidth: 2),
|
||||||
const SizedBox(height: 8),
|
const SizedBox(height: 8),
|
||||||
Text(
|
Text(
|
||||||
L10n.of(context)!.searchIn(
|
L10n.of(context)!.searchIn(
|
||||||
|
|
@ -43,10 +44,6 @@ class ChatSearchImagesTab extends StatelessWidget {
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
final events = snapshot.data?.$1
|
|
||||||
.where((event) => event.messageType == MessageTypes.Image)
|
|
||||||
.toList() ??
|
|
||||||
[];
|
|
||||||
if (events.isEmpty) {
|
if (events.isEmpty) {
|
||||||
return Column(
|
return Column(
|
||||||
mainAxisAlignment: MainAxisAlignment.center,
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
|
|
|
||||||
|
|
@ -49,15 +49,7 @@ class ChatSearchMessageTab extends StatelessWidget {
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
final events = snapshot.data?.$1
|
final events = snapshot.data?.$1 ?? [];
|
||||||
.where(
|
|
||||||
(event) => {
|
|
||||||
MessageTypes.Text,
|
|
||||||
MessageTypes.Notice,
|
|
||||||
}.contains(event.messageType),
|
|
||||||
)
|
|
||||||
.toList() ??
|
|
||||||
[];
|
|
||||||
|
|
||||||
return SelectionArea(
|
return SelectionArea(
|
||||||
child: ListView.separated(
|
child: ListView.separated(
|
||||||
|
|
@ -166,14 +158,17 @@ class _MessageSearchResultListTile extends StatelessWidget {
|
||||||
decorationColor: Theme.of(context).colorScheme.primary,
|
decorationColor: Theme.of(context).colorScheme.primary,
|
||||||
),
|
),
|
||||||
onOpen: (url) => UrlLauncher(context, url.url).launchUrl(),
|
onOpen: (url) => UrlLauncher(context, url.url).launchUrl(),
|
||||||
text: event.calcLocalizedBodyFallback(
|
text: event
|
||||||
plaintextBody: true,
|
.calcLocalizedBodyFallback(
|
||||||
removeMarkdown: true,
|
plaintextBody: true,
|
||||||
MatrixLocals(
|
removeMarkdown: true,
|
||||||
L10n.of(context)!,
|
MatrixLocals(
|
||||||
),
|
L10n.of(context)!,
|
||||||
),
|
),
|
||||||
maxLines: 4,
|
)
|
||||||
|
.trim(),
|
||||||
|
maxLines: 7,
|
||||||
|
overflow: TextOverflow.ellipsis,
|
||||||
),
|
),
|
||||||
trailing: IconButton(
|
trailing: IconButton(
|
||||||
icon: const Icon(
|
icon: const Icon(
|
||||||
|
|
|
||||||
|
|
@ -25,9 +25,11 @@ class ChatSearchController extends State<ChatSearchPage>
|
||||||
Timeline? timeline;
|
Timeline? timeline;
|
||||||
|
|
||||||
Stream<(List<Event>, String?)>? searchStream;
|
Stream<(List<Event>, String?)>? searchStream;
|
||||||
|
Stream<(List<Event>, String?)>? galleryStream;
|
||||||
|
Stream<(List<Event>, String?)>? fileStream;
|
||||||
|
|
||||||
void restartSearch() {
|
void restartSearch() {
|
||||||
if (tabController.index == 0 && searchController.text.isEmpty) {
|
if (searchController.text.isEmpty) {
|
||||||
setState(() {
|
setState(() {
|
||||||
searchStream = null;
|
searchStream = null;
|
||||||
});
|
});
|
||||||
|
|
@ -37,11 +39,11 @@ class ChatSearchController extends State<ChatSearchPage>
|
||||||
searchStream = const Stream.empty();
|
searchStream = const Stream.empty();
|
||||||
});
|
});
|
||||||
WidgetsBinding.instance.addPostFrameCallback((timeStamp) {
|
WidgetsBinding.instance.addPostFrameCallback((timeStamp) {
|
||||||
startSearch();
|
startMessageSearch();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void startSearch({
|
void startMessageSearch({
|
||||||
String? prevBatch,
|
String? prevBatch,
|
||||||
List<Event>? previousSearchResult,
|
List<Event>? previousSearchResult,
|
||||||
}) async {
|
}) async {
|
||||||
|
|
@ -54,12 +56,7 @@ class ChatSearchController extends State<ChatSearchPage>
|
||||||
setState(() {
|
setState(() {
|
||||||
searchStream = timeline
|
searchStream = timeline
|
||||||
.startSearch(
|
.startSearch(
|
||||||
searchTerm: tabController.index == 0 ? searchController.text : null,
|
searchTerm: searchController.text,
|
||||||
searchFunc: switch (tabController.index) {
|
|
||||||
1 => (event) => event.messageType == MessageTypes.Image,
|
|
||||||
2 => (event) => event.messageType == MessageTypes.File,
|
|
||||||
int() => null,
|
|
||||||
},
|
|
||||||
prevBatch: prevBatch,
|
prevBatch: prevBatch,
|
||||||
requestHistoryCount: 1000,
|
requestHistoryCount: 1000,
|
||||||
limit: 32,
|
limit: 32,
|
||||||
|
|
@ -77,16 +74,90 @@ class ChatSearchController extends State<ChatSearchPage>
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void startGallerySearch({
|
||||||
|
String? prevBatch,
|
||||||
|
List<Event>? previousSearchResult,
|
||||||
|
}) async {
|
||||||
|
final timeline = this.timeline ??= await room!.getTimeline();
|
||||||
|
|
||||||
|
setState(() {
|
||||||
|
galleryStream = timeline
|
||||||
|
.startSearch(
|
||||||
|
searchFunc: (event) =>
|
||||||
|
event.messageType == MessageTypes.File ||
|
||||||
|
(event.messageType == MessageTypes.Audio &&
|
||||||
|
!event.content.containsKey('org.matrix.msc3245.voice')),
|
||||||
|
prevBatch: prevBatch,
|
||||||
|
requestHistoryCount: 1000,
|
||||||
|
limit: 32,
|
||||||
|
)
|
||||||
|
.map(
|
||||||
|
(result) => (
|
||||||
|
[
|
||||||
|
if (previousSearchResult != null) ...previousSearchResult,
|
||||||
|
...result.$1,
|
||||||
|
],
|
||||||
|
result.$2,
|
||||||
|
),
|
||||||
|
)
|
||||||
|
.asBroadcastStream();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
void startFileSearch({
|
||||||
|
String? prevBatch,
|
||||||
|
List<Event>? previousSearchResult,
|
||||||
|
}) async {
|
||||||
|
final timeline = this.timeline ??= await room!.getTimeline();
|
||||||
|
|
||||||
|
setState(() {
|
||||||
|
fileStream = timeline
|
||||||
|
.startSearch(
|
||||||
|
searchFunc: (event) => {
|
||||||
|
MessageTypes.Image,
|
||||||
|
MessageTypes.Video,
|
||||||
|
}.contains(event.messageType),
|
||||||
|
prevBatch: prevBatch,
|
||||||
|
requestHistoryCount: 1000,
|
||||||
|
limit: 32,
|
||||||
|
)
|
||||||
|
.map(
|
||||||
|
(result) => (
|
||||||
|
[
|
||||||
|
if (previousSearchResult != null) ...previousSearchResult,
|
||||||
|
...result.$1,
|
||||||
|
],
|
||||||
|
result.$2,
|
||||||
|
),
|
||||||
|
)
|
||||||
|
.asBroadcastStream();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
void _onTabChanged() {
|
||||||
|
switch (tabController.index) {
|
||||||
|
case 1:
|
||||||
|
startGallerySearch();
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
startFileSearch();
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
restartSearch();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
super.initState();
|
super.initState();
|
||||||
tabController = TabController(initialIndex: 0, length: 3, vsync: this);
|
tabController = TabController(initialIndex: 0, length: 3, vsync: this);
|
||||||
tabController.addListener(restartSearch);
|
tabController.addListener(_onTabChanged);
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void dispose() {
|
void dispose() {
|
||||||
tabController.removeListener(restartSearch);
|
tabController.removeListener(_onTabChanged);
|
||||||
super.dispose();
|
super.dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -81,18 +81,18 @@ class ChatSearchView extends StatelessWidget {
|
||||||
ChatSearchMessageTab(
|
ChatSearchMessageTab(
|
||||||
searchQuery: controller.searchController.text,
|
searchQuery: controller.searchController.text,
|
||||||
room: room,
|
room: room,
|
||||||
startSearch: controller.startSearch,
|
startSearch: controller.startMessageSearch,
|
||||||
searchStream: controller.searchStream,
|
searchStream: controller.searchStream,
|
||||||
),
|
),
|
||||||
ChatSearchImagesTab(
|
ChatSearchImagesTab(
|
||||||
room: room,
|
room: room,
|
||||||
startSearch: controller.startSearch,
|
startSearch: controller.startGallerySearch,
|
||||||
searchStream: controller.searchStream,
|
searchStream: controller.galleryStream,
|
||||||
),
|
),
|
||||||
ChatSearchFilesTab(
|
ChatSearchFilesTab(
|
||||||
room: room,
|
room: room,
|
||||||
startSearch: controller.startSearch,
|
startSearch: controller.startFileSearch,
|
||||||
searchStream: controller.searchStream,
|
searchStream: controller.fileStream,
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue