Merge pull request #2325 from krille-chan/krille/improved-search
feat: Improved search
This commit is contained in:
commit
b7374ff7f8
9 changed files with 431 additions and 506 deletions
|
|
@ -3466,5 +3466,15 @@
|
||||||
"skipChatBackup": "Skip chat backup",
|
"skipChatBackup": "Skip chat backup",
|
||||||
"skipChatBackupWarning": "Are you sure? Without enabling the chat backup you may lose access to your messages if you switch your device.",
|
"skipChatBackupWarning": "Are you sure? Without enabling the chat backup you may lose access to your messages if you switch your device.",
|
||||||
"loadingMessages": "Loading messages",
|
"loadingMessages": "Loading messages",
|
||||||
"setupChatBackup": "Set up chat backup"
|
"setupChatBackup": "Set up chat backup",
|
||||||
|
"noMoreResultsFound": "No more results found",
|
||||||
|
"chatSearchedUntil": "Chat searched until {time}",
|
||||||
|
"@chatSearchedUntil": {
|
||||||
|
"type": "String",
|
||||||
|
"placeholders": {
|
||||||
|
"time": {
|
||||||
|
"type": "String"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,167 +4,106 @@ import 'package:matrix/matrix.dart';
|
||||||
|
|
||||||
import 'package:fluffychat/config/app_config.dart';
|
import 'package:fluffychat/config/app_config.dart';
|
||||||
import 'package:fluffychat/l10n/l10n.dart';
|
import 'package:fluffychat/l10n/l10n.dart';
|
||||||
|
import 'package:fluffychat/pages/chat_search/search_footer.dart';
|
||||||
import 'package:fluffychat/utils/date_time_extension.dart';
|
import 'package:fluffychat/utils/date_time_extension.dart';
|
||||||
import 'package:fluffychat/utils/matrix_sdk_extensions/event_extension.dart';
|
import 'package:fluffychat/utils/matrix_sdk_extensions/event_extension.dart';
|
||||||
import 'package:fluffychat/utils/matrix_sdk_extensions/matrix_locals.dart';
|
|
||||||
|
|
||||||
class ChatSearchFilesTab extends StatelessWidget {
|
class ChatSearchFilesTab extends StatelessWidget {
|
||||||
final Room room;
|
final Room room;
|
||||||
final Stream<(List<Event>, String?)>? searchStream;
|
final List<Event> events;
|
||||||
final void Function({String? prevBatch, List<Event>? previousSearchResult})
|
final void Function() onStartSearch;
|
||||||
startSearch;
|
final bool endReached, isLoading;
|
||||||
|
final DateTime? searchedUntil;
|
||||||
|
|
||||||
const ChatSearchFilesTab({
|
const ChatSearchFilesTab({
|
||||||
required this.room,
|
required this.room,
|
||||||
required this.startSearch,
|
required this.events,
|
||||||
required this.searchStream,
|
required this.onStartSearch,
|
||||||
|
required this.endReached,
|
||||||
|
required this.isLoading,
|
||||||
super.key,
|
super.key,
|
||||||
|
required this.searchedUntil,
|
||||||
});
|
});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return StreamBuilder(
|
final theme = Theme.of(context);
|
||||||
stream: searchStream,
|
return SelectionArea(
|
||||||
builder: (context, snapshot) {
|
child: ListView.builder(
|
||||||
final theme = Theme.of(context);
|
padding: const EdgeInsets.all(8.0),
|
||||||
final events = snapshot.data?.$1;
|
itemCount: events.length + 1,
|
||||||
if (searchStream == null || events == null) {
|
itemBuilder: (context, i) {
|
||||||
return Column(
|
if (i == events.length) {
|
||||||
mainAxisAlignment: .center,
|
return SearchFooter(
|
||||||
children: [
|
searchedUntil: searchedUntil,
|
||||||
const CircularProgressIndicator.adaptive(strokeWidth: 2),
|
endReached: endReached,
|
||||||
const SizedBox(height: 8),
|
isLoading: isLoading,
|
||||||
Text(
|
onStartSearch: onStartSearch,
|
||||||
L10n.of(context).searchIn(
|
);
|
||||||
room.getLocalizedDisplayname(MatrixLocals(L10n.of(context))),
|
}
|
||||||
),
|
final event = events[i];
|
||||||
),
|
final filename =
|
||||||
],
|
event.content.tryGet<String>('filename') ??
|
||||||
);
|
event.content.tryGet<String>('body') ??
|
||||||
}
|
L10n.of(context).unknownEvent('File');
|
||||||
|
final filetype = (filename.contains('.')
|
||||||
if (events.isEmpty) {
|
? filename.split('.').last.toUpperCase()
|
||||||
return Column(
|
: event.content
|
||||||
mainAxisAlignment: .center,
|
.tryGetMap<String, dynamic>('info')
|
||||||
children: [
|
?.tryGet<String>('mimetype')
|
||||||
const Icon(Icons.file_present_outlined, size: 64),
|
?.toUpperCase() ??
|
||||||
const SizedBox(height: 8),
|
'UNKNOWN');
|
||||||
Text(L10n.of(context).nothingFound),
|
final sizeString = event.sizeString;
|
||||||
],
|
final prevEvent = i > 0 ? events[i - 1] : null;
|
||||||
);
|
final sameEnvironment = prevEvent == null
|
||||||
}
|
? false
|
||||||
|
: prevEvent.originServerTs.sameEnvironment(event.originServerTs);
|
||||||
return SelectionArea(
|
return Padding(
|
||||||
child: ListView.builder(
|
|
||||||
padding: const EdgeInsets.all(8.0),
|
padding: const EdgeInsets.all(8.0),
|
||||||
itemCount: events.length + 1,
|
child: Column(
|
||||||
itemBuilder: (context, i) {
|
mainAxisSize: MainAxisSize.min,
|
||||||
if (i == events.length) {
|
children: [
|
||||||
if (snapshot.connectionState != ConnectionState.done) {
|
if (!sameEnvironment) ...[
|
||||||
return const Padding(
|
Row(
|
||||||
padding: EdgeInsets.all(16.0),
|
children: [
|
||||||
child: Center(
|
Expanded(
|
||||||
child: CircularProgressIndicator.adaptive(strokeWidth: 2),
|
child: Container(height: 1, color: theme.dividerColor),
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
final nextBatch = snapshot.data?.$2;
|
|
||||||
if (nextBatch == null) {
|
|
||||||
return const SizedBox.shrink();
|
|
||||||
}
|
|
||||||
return Center(
|
|
||||||
child: Padding(
|
|
||||||
padding: const EdgeInsets.all(16.0),
|
|
||||||
child: TextButton.icon(
|
|
||||||
style: TextButton.styleFrom(
|
|
||||||
backgroundColor: theme.colorScheme.secondaryContainer,
|
|
||||||
foregroundColor: theme.colorScheme.onSecondaryContainer,
|
|
||||||
),
|
),
|
||||||
onPressed: () => startSearch(
|
Padding(
|
||||||
prevBatch: nextBatch,
|
padding: const EdgeInsets.all(8.0),
|
||||||
previousSearchResult: events,
|
child: Text(
|
||||||
),
|
event.originServerTs.localizedTime(context),
|
||||||
icon: const Icon(Icons.arrow_downward_outlined),
|
style: theme.textTheme.labelSmall,
|
||||||
label: Text(L10n.of(context).searchMore),
|
textAlign: TextAlign.center,
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
final event = events[i];
|
|
||||||
final filename =
|
|
||||||
event.content.tryGet<String>('filename') ??
|
|
||||||
event.content.tryGet<String>('body') ??
|
|
||||||
L10n.of(context).unknownEvent('File');
|
|
||||||
final filetype = (filename.contains('.')
|
|
||||||
? filename.split('.').last.toUpperCase()
|
|
||||||
: event.content
|
|
||||||
.tryGetMap<String, dynamic>('info')
|
|
||||||
?.tryGet<String>('mimetype')
|
|
||||||
?.toUpperCase() ??
|
|
||||||
'UNKNOWN');
|
|
||||||
final sizeString = event.sizeString;
|
|
||||||
final prevEvent = i > 0 ? events[i - 1] : null;
|
|
||||||
final sameEnvironment = prevEvent == null
|
|
||||||
? false
|
|
||||||
: prevEvent.originServerTs.sameEnvironment(
|
|
||||||
event.originServerTs,
|
|
||||||
);
|
|
||||||
return Padding(
|
|
||||||
padding: const EdgeInsets.all(8.0),
|
|
||||||
child: Column(
|
|
||||||
mainAxisSize: .min,
|
|
||||||
children: [
|
|
||||||
if (!sameEnvironment) ...[
|
|
||||||
Row(
|
|
||||||
children: [
|
|
||||||
Expanded(
|
|
||||||
child: Container(
|
|
||||||
height: 1,
|
|
||||||
color: theme.dividerColor,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
Padding(
|
|
||||||
padding: const EdgeInsets.all(8.0),
|
|
||||||
child: Text(
|
|
||||||
event.originServerTs.localizedTime(context),
|
|
||||||
style: theme.textTheme.labelSmall,
|
|
||||||
textAlign: TextAlign.center,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
Expanded(
|
|
||||||
child: Container(
|
|
||||||
height: 1,
|
|
||||||
color: theme.dividerColor,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
const SizedBox(height: 4),
|
|
||||||
],
|
|
||||||
Material(
|
|
||||||
borderRadius: BorderRadius.circular(
|
|
||||||
AppConfig.borderRadius,
|
|
||||||
),
|
|
||||||
color: theme.colorScheme.onInverseSurface,
|
|
||||||
clipBehavior: Clip.hardEdge,
|
|
||||||
child: ListTile(
|
|
||||||
leading: const Icon(Icons.file_present_outlined),
|
|
||||||
title: Text(
|
|
||||||
filename,
|
|
||||||
maxLines: 1,
|
|
||||||
overflow: TextOverflow.ellipsis,
|
|
||||||
),
|
),
|
||||||
subtitle: Text('$sizeString | $filetype'),
|
|
||||||
onTap: () => event.saveFile(context),
|
|
||||||
),
|
),
|
||||||
|
Expanded(
|
||||||
|
child: Container(height: 1, color: theme.dividerColor),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
const SizedBox(height: 4),
|
||||||
|
],
|
||||||
|
Material(
|
||||||
|
borderRadius: BorderRadius.circular(AppConfig.borderRadius),
|
||||||
|
color: theme.colorScheme.onInverseSurface,
|
||||||
|
clipBehavior: Clip.hardEdge,
|
||||||
|
child: ListTile(
|
||||||
|
leading: const Icon(Icons.file_present_outlined),
|
||||||
|
title: Text(
|
||||||
|
filename,
|
||||||
|
maxLines: 1,
|
||||||
|
overflow: TextOverflow.ellipsis,
|
||||||
),
|
),
|
||||||
],
|
subtitle: Text('$sizeString | $filetype'),
|
||||||
|
onTap: () => event.saveFile(context),
|
||||||
|
),
|
||||||
),
|
),
|
||||||
);
|
],
|
||||||
},
|
),
|
||||||
),
|
);
|
||||||
);
|
},
|
||||||
},
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,169 +6,147 @@ import 'package:matrix/matrix.dart';
|
||||||
import 'package:fluffychat/config/app_config.dart';
|
import 'package:fluffychat/config/app_config.dart';
|
||||||
import 'package:fluffychat/l10n/l10n.dart';
|
import 'package:fluffychat/l10n/l10n.dart';
|
||||||
import 'package:fluffychat/pages/chat/events/video_player.dart';
|
import 'package:fluffychat/pages/chat/events/video_player.dart';
|
||||||
|
import 'package:fluffychat/pages/chat_search/search_footer.dart';
|
||||||
import 'package:fluffychat/pages/image_viewer/image_viewer.dart';
|
import 'package:fluffychat/pages/image_viewer/image_viewer.dart';
|
||||||
import 'package:fluffychat/utils/matrix_sdk_extensions/matrix_locals.dart';
|
import 'package:fluffychat/utils/matrix_sdk_extensions/matrix_locals.dart';
|
||||||
import 'package:fluffychat/widgets/mxc_image.dart';
|
import 'package:fluffychat/widgets/mxc_image.dart';
|
||||||
|
|
||||||
class ChatSearchImagesTab extends StatelessWidget {
|
class ChatSearchImagesTab extends StatelessWidget {
|
||||||
final Room room;
|
final Room room;
|
||||||
final Stream<(List<Event>, String?)>? searchStream;
|
final List<Event> events;
|
||||||
final void Function({String? prevBatch, List<Event>? previousSearchResult})
|
final void Function() onStartSearch;
|
||||||
startSearch;
|
final bool endReached, isLoading;
|
||||||
|
final DateTime? searchedUntil;
|
||||||
|
|
||||||
const ChatSearchImagesTab({
|
const ChatSearchImagesTab({
|
||||||
required this.room,
|
required this.room,
|
||||||
required this.startSearch,
|
required this.events,
|
||||||
required this.searchStream,
|
required this.onStartSearch,
|
||||||
|
required this.endReached,
|
||||||
|
required this.isLoading,
|
||||||
super.key,
|
super.key,
|
||||||
|
required this.searchedUntil,
|
||||||
});
|
});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
final borderRadius = BorderRadius.circular(AppConfig.borderRadius / 2);
|
final borderRadius = BorderRadius.circular(AppConfig.borderRadius / 2);
|
||||||
return StreamBuilder(
|
final theme = Theme.of(context);
|
||||||
stream: searchStream,
|
if (events.isEmpty) {
|
||||||
builder: (context, snapshot) {
|
if (isLoading) {
|
||||||
final theme = Theme.of(context);
|
return const Center(child: CircularProgressIndicator.adaptive());
|
||||||
final events = snapshot.data?.$1;
|
}
|
||||||
if (searchStream == null || events == null) {
|
return Column(
|
||||||
return Column(
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
mainAxisAlignment: .center,
|
children: [
|
||||||
children: [
|
const CircularProgressIndicator.adaptive(strokeWidth: 2),
|
||||||
const CircularProgressIndicator.adaptive(strokeWidth: 2),
|
const SizedBox(height: 8),
|
||||||
const SizedBox(height: 8),
|
Text(
|
||||||
Text(
|
L10n.of(context).searchIn(
|
||||||
L10n.of(context).searchIn(
|
room.getLocalizedDisplayname(MatrixLocals(L10n.of(context))),
|
||||||
room.getLocalizedDisplayname(MatrixLocals(L10n.of(context))),
|
),
|
||||||
),
|
),
|
||||||
),
|
],
|
||||||
],
|
);
|
||||||
|
}
|
||||||
|
if (events.isEmpty) {
|
||||||
|
return Column(
|
||||||
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
|
children: [
|
||||||
|
const Icon(Icons.photo_outlined, size: 64),
|
||||||
|
const SizedBox(height: 8),
|
||||||
|
Text(L10n.of(context).nothingFound),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
final eventsByMonth = <DateTime, List<Event>>{};
|
||||||
|
for (final event in events) {
|
||||||
|
final month = DateTime(
|
||||||
|
event.originServerTs.year,
|
||||||
|
event.originServerTs.month,
|
||||||
|
);
|
||||||
|
eventsByMonth[month] ??= [];
|
||||||
|
eventsByMonth[month]!.add(event);
|
||||||
|
}
|
||||||
|
final eventsByMonthList = eventsByMonth.entries.toList();
|
||||||
|
|
||||||
|
const padding = 8.0;
|
||||||
|
|
||||||
|
return ListView.builder(
|
||||||
|
itemCount: eventsByMonth.length + 1,
|
||||||
|
itemBuilder: (context, i) {
|
||||||
|
if (i == eventsByMonth.length) {
|
||||||
|
return SearchFooter(
|
||||||
|
searchedUntil: searchedUntil,
|
||||||
|
endReached: endReached,
|
||||||
|
isLoading: isLoading,
|
||||||
|
onStartSearch: onStartSearch,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
if (events.isEmpty) {
|
|
||||||
return Column(
|
|
||||||
mainAxisAlignment: .center,
|
|
||||||
children: [
|
|
||||||
const Icon(Icons.photo_outlined, size: 64),
|
|
||||||
const SizedBox(height: 8),
|
|
||||||
Text(L10n.of(context).nothingFound),
|
|
||||||
],
|
|
||||||
);
|
|
||||||
}
|
|
||||||
final eventsByMonth = <DateTime, List<Event>>{};
|
|
||||||
for (final event in events) {
|
|
||||||
final month = DateTime(
|
|
||||||
event.originServerTs.year,
|
|
||||||
event.originServerTs.month,
|
|
||||||
);
|
|
||||||
eventsByMonth[month] ??= [];
|
|
||||||
eventsByMonth[month]!.add(event);
|
|
||||||
}
|
|
||||||
final eventsByMonthList = eventsByMonth.entries.toList();
|
|
||||||
|
|
||||||
const padding = 8.0;
|
final monthEvents = eventsByMonthList[i].value;
|
||||||
|
return Column(
|
||||||
return ListView.builder(
|
mainAxisSize: MainAxisSize.min,
|
||||||
itemCount: eventsByMonth.length + 1,
|
children: [
|
||||||
itemBuilder: (context, i) {
|
const SizedBox(height: 4),
|
||||||
if (i == eventsByMonth.length) {
|
Row(
|
||||||
if (snapshot.connectionState != ConnectionState.done) {
|
|
||||||
return const Padding(
|
|
||||||
padding: EdgeInsets.all(16.0),
|
|
||||||
child: Center(
|
|
||||||
child: CircularProgressIndicator.adaptive(strokeWidth: 2),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
final nextBatch = snapshot.data?.$2;
|
|
||||||
if (nextBatch == null) {
|
|
||||||
return const SizedBox.shrink();
|
|
||||||
}
|
|
||||||
return Center(
|
|
||||||
child: Padding(
|
|
||||||
padding: const EdgeInsets.all(16.0),
|
|
||||||
child: TextButton.icon(
|
|
||||||
style: TextButton.styleFrom(
|
|
||||||
backgroundColor: theme.colorScheme.secondaryContainer,
|
|
||||||
foregroundColor: theme.colorScheme.onSecondaryContainer,
|
|
||||||
),
|
|
||||||
onPressed: () => startSearch(
|
|
||||||
prevBatch: nextBatch,
|
|
||||||
previousSearchResult: events,
|
|
||||||
),
|
|
||||||
icon: const Icon(Icons.arrow_downward_outlined),
|
|
||||||
label: Text(L10n.of(context).searchMore),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
final monthEvents = eventsByMonthList[i].value;
|
|
||||||
return Column(
|
|
||||||
mainAxisSize: .min,
|
|
||||||
children: [
|
children: [
|
||||||
const SizedBox(height: 4),
|
Expanded(
|
||||||
Row(
|
child: Container(height: 1, color: theme.dividerColor),
|
||||||
children: [
|
|
||||||
Expanded(
|
|
||||||
child: Container(height: 1, color: theme.dividerColor),
|
|
||||||
),
|
|
||||||
Padding(
|
|
||||||
padding: const EdgeInsets.all(8.0),
|
|
||||||
child: Text(
|
|
||||||
DateFormat.yMMMM(
|
|
||||||
Localizations.localeOf(context).languageCode,
|
|
||||||
).format(eventsByMonthList[i].key),
|
|
||||||
style: theme.textTheme.labelSmall,
|
|
||||||
textAlign: TextAlign.center,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
Expanded(
|
|
||||||
child: Container(height: 1, color: theme.dividerColor),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
),
|
||||||
GridView.count(
|
Padding(
|
||||||
physics: const NeverScrollableScrollPhysics(),
|
padding: const EdgeInsets.all(8.0),
|
||||||
shrinkWrap: true,
|
child: Text(
|
||||||
mainAxisSpacing: padding,
|
DateFormat.yMMMM(
|
||||||
crossAxisSpacing: padding,
|
Localizations.localeOf(context).languageCode,
|
||||||
clipBehavior: Clip.hardEdge,
|
).format(eventsByMonthList[i].key),
|
||||||
padding: const EdgeInsets.all(padding),
|
style: theme.textTheme.labelSmall,
|
||||||
crossAxisCount: 3,
|
textAlign: TextAlign.center,
|
||||||
children: monthEvents.map((event) {
|
),
|
||||||
if (event.messageType == MessageTypes.Video) {
|
),
|
||||||
return Material(
|
Expanded(
|
||||||
clipBehavior: Clip.hardEdge,
|
child: Container(height: 1, color: theme.dividerColor),
|
||||||
borderRadius: borderRadius,
|
|
||||||
child: EventVideoPlayer(event),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
return InkWell(
|
|
||||||
onTap: () => showDialog(
|
|
||||||
context: context,
|
|
||||||
builder: (_) =>
|
|
||||||
ImageViewer(event, outerContext: context),
|
|
||||||
),
|
|
||||||
borderRadius: borderRadius,
|
|
||||||
child: Material(
|
|
||||||
clipBehavior: Clip.hardEdge,
|
|
||||||
borderRadius: borderRadius,
|
|
||||||
child: MxcImage(
|
|
||||||
event: event,
|
|
||||||
width: 128,
|
|
||||||
height: 128,
|
|
||||||
fit: BoxFit.cover,
|
|
||||||
animated: true,
|
|
||||||
isThumbnail: true,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}).toList(),
|
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
);
|
),
|
||||||
},
|
GridView.count(
|
||||||
|
physics: const NeverScrollableScrollPhysics(),
|
||||||
|
shrinkWrap: true,
|
||||||
|
mainAxisSpacing: padding,
|
||||||
|
crossAxisSpacing: padding,
|
||||||
|
clipBehavior: Clip.hardEdge,
|
||||||
|
padding: const EdgeInsets.all(padding),
|
||||||
|
crossAxisCount: 3,
|
||||||
|
children: monthEvents.map((event) {
|
||||||
|
if (event.messageType == MessageTypes.Video) {
|
||||||
|
return Material(
|
||||||
|
clipBehavior: Clip.hardEdge,
|
||||||
|
borderRadius: borderRadius,
|
||||||
|
child: EventVideoPlayer(event),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return InkWell(
|
||||||
|
onTap: () => showDialog(
|
||||||
|
context: context,
|
||||||
|
builder: (_) => ImageViewer(event, outerContext: context),
|
||||||
|
),
|
||||||
|
borderRadius: borderRadius,
|
||||||
|
child: Material(
|
||||||
|
clipBehavior: Clip.hardEdge,
|
||||||
|
borderRadius: borderRadius,
|
||||||
|
child: MxcImage(
|
||||||
|
event: event,
|
||||||
|
width: 128,
|
||||||
|
height: 128,
|
||||||
|
fit: BoxFit.cover,
|
||||||
|
animated: true,
|
||||||
|
isThumbnail: true,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}).toList(),
|
||||||
|
),
|
||||||
|
],
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@ import 'package:go_router/go_router.dart';
|
||||||
import 'package:matrix/matrix.dart';
|
import 'package:matrix/matrix.dart';
|
||||||
|
|
||||||
import 'package:fluffychat/l10n/l10n.dart';
|
import 'package:fluffychat/l10n/l10n.dart';
|
||||||
|
import 'package:fluffychat/pages/chat_search/search_footer.dart';
|
||||||
import 'package:fluffychat/utils/date_time_extension.dart';
|
import 'package:fluffychat/utils/date_time_extension.dart';
|
||||||
import 'package:fluffychat/utils/matrix_sdk_extensions/matrix_locals.dart';
|
import 'package:fluffychat/utils/matrix_sdk_extensions/matrix_locals.dart';
|
||||||
import 'package:fluffychat/utils/url_launcher.dart';
|
import 'package:fluffychat/utils/url_launcher.dart';
|
||||||
|
|
@ -13,93 +14,74 @@ import 'package:fluffychat/widgets/avatar.dart';
|
||||||
class ChatSearchMessageTab extends StatelessWidget {
|
class ChatSearchMessageTab extends StatelessWidget {
|
||||||
final String searchQuery;
|
final String searchQuery;
|
||||||
final Room room;
|
final Room room;
|
||||||
final Stream<(List<Event>, String?)>? searchStream;
|
final List<Event> events;
|
||||||
final void Function({String? prevBatch, List<Event>? previousSearchResult})
|
final void Function() onStartSearch;
|
||||||
startSearch;
|
final bool endReached, isLoading;
|
||||||
|
final DateTime? searchedUntil;
|
||||||
|
|
||||||
const ChatSearchMessageTab({
|
const ChatSearchMessageTab({
|
||||||
required this.searchQuery,
|
required this.searchQuery,
|
||||||
required this.room,
|
required this.room,
|
||||||
required this.searchStream,
|
required this.onStartSearch,
|
||||||
required this.startSearch,
|
required this.events,
|
||||||
|
required this.searchedUntil,
|
||||||
|
required this.endReached,
|
||||||
|
required this.isLoading,
|
||||||
super.key,
|
super.key,
|
||||||
});
|
});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return StreamBuilder(
|
final theme = Theme.of(context);
|
||||||
key: ValueKey(searchQuery),
|
if (events.isEmpty) {
|
||||||
stream: searchStream,
|
if (isLoading) {
|
||||||
builder: (context, snapshot) {
|
return const Center(child: CircularProgressIndicator.adaptive());
|
||||||
final theme = Theme.of(context);
|
}
|
||||||
if (searchStream == null) {
|
return Column(
|
||||||
return Column(
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
mainAxisAlignment: .center,
|
children: [
|
||||||
children: [
|
const Icon(Icons.search_outlined, size: 64),
|
||||||
const Icon(Icons.search_outlined, size: 64),
|
const SizedBox(height: 8),
|
||||||
const SizedBox(height: 8),
|
Padding(
|
||||||
Text(
|
padding: const EdgeInsets.symmetric(horizontal: 32.0),
|
||||||
L10n.of(context).searchIn(
|
child: Text(
|
||||||
room.getLocalizedDisplayname(MatrixLocals(L10n.of(context))),
|
L10n.of(context).searchIn(
|
||||||
),
|
room.getLocalizedDisplayname(MatrixLocals(L10n.of(context))),
|
||||||
),
|
),
|
||||||
],
|
textAlign: TextAlign.center,
|
||||||
);
|
),
|
||||||
}
|
|
||||||
final events = snapshot.data?.$1 ?? [];
|
|
||||||
|
|
||||||
return SelectionArea(
|
|
||||||
child: ListView.separated(
|
|
||||||
itemCount: events.length + 1,
|
|
||||||
separatorBuilder: (context, _) =>
|
|
||||||
Divider(color: theme.dividerColor, height: 1),
|
|
||||||
itemBuilder: (context, i) {
|
|
||||||
if (i == events.length) {
|
|
||||||
if (snapshot.connectionState != ConnectionState.done) {
|
|
||||||
return const Padding(
|
|
||||||
padding: EdgeInsets.all(16.0),
|
|
||||||
child: Center(
|
|
||||||
child: CircularProgressIndicator.adaptive(strokeWidth: 2),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
final nextBatch = snapshot.data?.$2;
|
|
||||||
if (nextBatch == null) {
|
|
||||||
return const SizedBox.shrink();
|
|
||||||
}
|
|
||||||
return Center(
|
|
||||||
child: Padding(
|
|
||||||
padding: const EdgeInsets.all(16.0),
|
|
||||||
child: TextButton.icon(
|
|
||||||
style: TextButton.styleFrom(
|
|
||||||
backgroundColor: theme.colorScheme.secondaryContainer,
|
|
||||||
foregroundColor: theme.colorScheme.onSecondaryContainer,
|
|
||||||
),
|
|
||||||
onPressed: () => startSearch(
|
|
||||||
prevBatch: nextBatch,
|
|
||||||
previousSearchResult: events,
|
|
||||||
),
|
|
||||||
icon: const Icon(Icons.arrow_downward_outlined),
|
|
||||||
label: Text(L10n.of(context).searchMore),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
final event = events[i];
|
|
||||||
final sender = event.senderFromMemoryOrFallback;
|
|
||||||
final displayname = sender.calcDisplayname(
|
|
||||||
i18n: MatrixLocals(L10n.of(context)),
|
|
||||||
);
|
|
||||||
return _MessageSearchResultListTile(
|
|
||||||
sender: sender,
|
|
||||||
displayname: displayname,
|
|
||||||
event: event,
|
|
||||||
room: room,
|
|
||||||
);
|
|
||||||
},
|
|
||||||
),
|
),
|
||||||
);
|
],
|
||||||
},
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return SelectionArea(
|
||||||
|
child: ListView.separated(
|
||||||
|
itemCount: events.length + 1,
|
||||||
|
separatorBuilder: (context, _) =>
|
||||||
|
Divider(color: theme.dividerColor, height: 1),
|
||||||
|
itemBuilder: (context, i) {
|
||||||
|
if (i == events.length) {
|
||||||
|
return SearchFooter(
|
||||||
|
searchedUntil: searchedUntil,
|
||||||
|
endReached: endReached,
|
||||||
|
isLoading: isLoading,
|
||||||
|
onStartSearch: onStartSearch,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
final event = events[i];
|
||||||
|
final sender = event.senderFromMemoryOrFallback;
|
||||||
|
final displayname = sender.calcDisplayname(
|
||||||
|
i18n: MatrixLocals(L10n.of(context)),
|
||||||
|
);
|
||||||
|
return _MessageSearchResultListTile(
|
||||||
|
sender: sender,
|
||||||
|
displayname: displayname,
|
||||||
|
event: event,
|
||||||
|
room: room,
|
||||||
|
);
|
||||||
|
},
|
||||||
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,3 @@
|
||||||
import 'dart:async';
|
|
||||||
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
import 'package:matrix/matrix.dart';
|
import 'package:matrix/matrix.dart';
|
||||||
|
|
@ -22,156 +20,100 @@ class ChatSearchController extends State<ChatSearchPage>
|
||||||
final TextEditingController searchController = TextEditingController();
|
final TextEditingController searchController = TextEditingController();
|
||||||
late final TabController tabController;
|
late final TabController tabController;
|
||||||
|
|
||||||
Timeline? timeline;
|
final List<Event> messages = [];
|
||||||
|
final List<Event> images = [];
|
||||||
Stream<(List<Event>, String?)>? searchStream;
|
final List<Event> files = [];
|
||||||
Stream<(List<Event>, String?)>? galleryStream;
|
String? messagesNextBatch, imagesNextBatch, filesNextBatch;
|
||||||
Stream<(List<Event>, String?)>? fileStream;
|
bool messagesEndReached = false;
|
||||||
|
bool imagesEndReached = false;
|
||||||
|
bool filesEndReached = false;
|
||||||
|
bool isLoading = false;
|
||||||
|
DateTime? searchedUntil;
|
||||||
|
|
||||||
void restartSearch() {
|
void restartSearch() {
|
||||||
if (searchController.text.isEmpty) {
|
|
||||||
setState(() {
|
|
||||||
searchStream = null;
|
|
||||||
});
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
setState(() {
|
setState(() {
|
||||||
searchStream = const Stream.empty();
|
messages.clear();
|
||||||
|
images.clear();
|
||||||
|
files.clear();
|
||||||
|
messagesNextBatch = imagesNextBatch = filesNextBatch = searchedUntil =
|
||||||
|
null;
|
||||||
|
messagesEndReached = imagesEndReached = filesEndReached = false;
|
||||||
});
|
});
|
||||||
WidgetsBinding.instance.addPostFrameCallback((timeStamp) {
|
WidgetsBinding.instance.addPostFrameCallback((timeStamp) {
|
||||||
startMessageSearch();
|
startSearch();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void startMessageSearch({
|
void startSearch() async {
|
||||||
String? prevBatch,
|
switch (tabController.index) {
|
||||||
List<Event>? previousSearchResult,
|
case 0:
|
||||||
}) async {
|
final searchQuery = searchController.text.trim();
|
||||||
final timeline = this.timeline ??= await room!.getTimeline();
|
if (searchQuery.isEmpty) return;
|
||||||
|
setState(() {
|
||||||
if (tabController.index == 0 && searchController.text.isEmpty) {
|
isLoading = true;
|
||||||
return;
|
});
|
||||||
|
final result = await room!.searchEvents(
|
||||||
|
searchTerm: searchController.text.trim(),
|
||||||
|
nextBatch: messagesNextBatch,
|
||||||
|
);
|
||||||
|
setState(() {
|
||||||
|
isLoading = false;
|
||||||
|
messages.addAll(result.events);
|
||||||
|
messagesNextBatch = result.nextBatch;
|
||||||
|
messagesEndReached = result.nextBatch == null;
|
||||||
|
searchedUntil = result.searchedUntil;
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
case 1:
|
||||||
|
setState(() {
|
||||||
|
isLoading = true;
|
||||||
|
});
|
||||||
|
final result = await room!.searchEvents(
|
||||||
|
searchFunc: (event) => {
|
||||||
|
MessageTypes.Image,
|
||||||
|
MessageTypes.Video,
|
||||||
|
}.contains(event.messageType),
|
||||||
|
nextBatch: imagesNextBatch,
|
||||||
|
);
|
||||||
|
setState(() {
|
||||||
|
isLoading = false;
|
||||||
|
images.addAll(result.events);
|
||||||
|
imagesNextBatch = result.nextBatch;
|
||||||
|
imagesEndReached = result.nextBatch == null;
|
||||||
|
searchedUntil = result.searchedUntil;
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
case 2:
|
||||||
|
setState(() {
|
||||||
|
isLoading = true;
|
||||||
|
});
|
||||||
|
final result = await room!.searchEvents(
|
||||||
|
searchFunc: (event) =>
|
||||||
|
event.messageType == MessageTypes.File ||
|
||||||
|
(event.messageType == MessageTypes.Audio &&
|
||||||
|
!event.content.containsKey('org.matrix.msc3245.voice')),
|
||||||
|
nextBatch: filesNextBatch,
|
||||||
|
);
|
||||||
|
setState(() {
|
||||||
|
isLoading = false;
|
||||||
|
files.addAll(result.events);
|
||||||
|
filesNextBatch = result.nextBatch;
|
||||||
|
filesEndReached = result.nextBatch == null;
|
||||||
|
searchedUntil = result.searchedUntil;
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
default:
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
setState(() {
|
|
||||||
searchStream = timeline
|
|
||||||
.startSearch(
|
|
||||||
searchTerm: searchController.text,
|
|
||||||
prevBatch: prevBatch,
|
|
||||||
requestHistoryCount: 1000,
|
|
||||||
limit: 32,
|
|
||||||
)
|
|
||||||
.map(
|
|
||||||
(result) => (
|
|
||||||
[
|
|
||||||
if (previousSearchResult != null) ...previousSearchResult,
|
|
||||||
...result.$1,
|
|
||||||
],
|
|
||||||
result.$2,
|
|
||||||
),
|
|
||||||
)
|
|
||||||
// Deduplication workaround for
|
|
||||||
// https://github.com/famedly/matrix-dart-sdk/issues/1831
|
|
||||||
.map(
|
|
||||||
(result) => (
|
|
||||||
<String, Event>{
|
|
||||||
for (final event in result.$1) event.eventId: event,
|
|
||||||
}.values.toList(),
|
|
||||||
result.$2,
|
|
||||||
),
|
|
||||||
)
|
|
||||||
.asBroadcastStream();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
void startGallerySearch({
|
|
||||||
String? prevBatch,
|
|
||||||
List<Event>? previousSearchResult,
|
|
||||||
}) async {
|
|
||||||
final timeline = this.timeline ??= await room!.getTimeline();
|
|
||||||
|
|
||||||
setState(() {
|
|
||||||
galleryStream = 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,
|
|
||||||
),
|
|
||||||
)
|
|
||||||
// Deduplication workaround for
|
|
||||||
// https://github.com/famedly/matrix-dart-sdk/issues/1831
|
|
||||||
.map(
|
|
||||||
(result) => (
|
|
||||||
<String, Event>{
|
|
||||||
for (final event in result.$1) event.eventId: event,
|
|
||||||
}.values.toList(),
|
|
||||||
result.$2,
|
|
||||||
),
|
|
||||||
)
|
|
||||||
.asBroadcastStream();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
void startFileSearch({
|
|
||||||
String? prevBatch,
|
|
||||||
List<Event>? previousSearchResult,
|
|
||||||
}) async {
|
|
||||||
final timeline = this.timeline ??= await room!.getTimeline();
|
|
||||||
|
|
||||||
setState(() {
|
|
||||||
fileStream = 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,
|
|
||||||
),
|
|
||||||
)
|
|
||||||
// Deduplication workaround for
|
|
||||||
// https://github.com/famedly/matrix-dart-sdk/issues/1831
|
|
||||||
.map(
|
|
||||||
(result) => (
|
|
||||||
<String, Event>{
|
|
||||||
for (final event in result.$1) event.eventId: event,
|
|
||||||
}.values.toList(),
|
|
||||||
result.$2,
|
|
||||||
),
|
|
||||||
)
|
|
||||||
.asBroadcastStream();
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void _onTabChanged() {
|
void _onTabChanged() {
|
||||||
switch (tabController.index) {
|
switch (tabController.index) {
|
||||||
case 1:
|
case 1:
|
||||||
startGallerySearch();
|
|
||||||
break;
|
|
||||||
case 2:
|
case 2:
|
||||||
startFileSearch();
|
startSearch();
|
||||||
break;
|
break;
|
||||||
|
case 0:
|
||||||
default:
|
default:
|
||||||
restartSearch();
|
restartSearch();
|
||||||
break;
|
break;
|
||||||
|
|
|
||||||
|
|
@ -85,18 +85,27 @@ class ChatSearchView extends StatelessWidget {
|
||||||
ChatSearchMessageTab(
|
ChatSearchMessageTab(
|
||||||
searchQuery: controller.searchController.text,
|
searchQuery: controller.searchController.text,
|
||||||
room: room,
|
room: room,
|
||||||
startSearch: controller.startMessageSearch,
|
onStartSearch: controller.startSearch,
|
||||||
searchStream: controller.searchStream,
|
events: controller.messages,
|
||||||
|
endReached: controller.messagesEndReached,
|
||||||
|
isLoading: controller.isLoading,
|
||||||
|
searchedUntil: controller.searchedUntil,
|
||||||
),
|
),
|
||||||
ChatSearchImagesTab(
|
ChatSearchImagesTab(
|
||||||
room: room,
|
room: room,
|
||||||
startSearch: controller.startGallerySearch,
|
onStartSearch: controller.startSearch,
|
||||||
searchStream: controller.galleryStream,
|
events: controller.images,
|
||||||
|
endReached: controller.imagesEndReached,
|
||||||
|
isLoading: controller.isLoading,
|
||||||
|
searchedUntil: controller.searchedUntil,
|
||||||
),
|
),
|
||||||
ChatSearchFilesTab(
|
ChatSearchFilesTab(
|
||||||
room: room,
|
room: room,
|
||||||
startSearch: controller.startFileSearch,
|
onStartSearch: controller.startSearch,
|
||||||
searchStream: controller.fileStream,
|
events: controller.files,
|
||||||
|
endReached: controller.filesEndReached,
|
||||||
|
isLoading: controller.isLoading,
|
||||||
|
searchedUntil: controller.searchedUntil,
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
|
|
|
||||||
63
lib/pages/chat_search/search_footer.dart
Normal file
63
lib/pages/chat_search/search_footer.dart
Normal file
|
|
@ -0,0 +1,63 @@
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
|
import 'package:fluffychat/l10n/l10n.dart';
|
||||||
|
import 'package:fluffychat/utils/date_time_extension.dart';
|
||||||
|
|
||||||
|
class SearchFooter extends StatelessWidget {
|
||||||
|
final DateTime? searchedUntil;
|
||||||
|
final bool endReached, isLoading;
|
||||||
|
final void Function() onStartSearch;
|
||||||
|
|
||||||
|
const SearchFooter({
|
||||||
|
super.key,
|
||||||
|
required this.searchedUntil,
|
||||||
|
required this.endReached,
|
||||||
|
required this.isLoading,
|
||||||
|
required this.onStartSearch,
|
||||||
|
});
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
if (endReached) {
|
||||||
|
return Center(
|
||||||
|
child: Padding(
|
||||||
|
padding: const EdgeInsets.all(16.0),
|
||||||
|
child: Text(L10n.of(context).noMoreResultsFound),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
final theme = Theme.of(context);
|
||||||
|
final searchedUntil = this.searchedUntil;
|
||||||
|
return Center(
|
||||||
|
child: Padding(
|
||||||
|
padding: const EdgeInsets.all(16.0),
|
||||||
|
child: Column(
|
||||||
|
mainAxisSize: .min,
|
||||||
|
children: [
|
||||||
|
if (searchedUntil != null)
|
||||||
|
Padding(
|
||||||
|
padding: const EdgeInsets.only(bottom: 8.0),
|
||||||
|
child: Text(
|
||||||
|
L10n.of(
|
||||||
|
context,
|
||||||
|
).chatSearchedUntil(searchedUntil.localizedTime(context)),
|
||||||
|
style: TextStyle(fontSize: 10.5),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
TextButton.icon(
|
||||||
|
style: TextButton.styleFrom(
|
||||||
|
backgroundColor: theme.colorScheme.secondaryContainer,
|
||||||
|
foregroundColor: theme.colorScheme.onSecondaryContainer,
|
||||||
|
),
|
||||||
|
onPressed: isLoading ? null : onStartSearch,
|
||||||
|
icon: isLoading
|
||||||
|
? const CircularProgressIndicator.adaptive()
|
||||||
|
: const Icon(Icons.arrow_downward_outlined),
|
||||||
|
label: Text(L10n.of(context).searchMore),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1087,10 +1087,11 @@ packages:
|
||||||
matrix:
|
matrix:
|
||||||
dependency: "direct main"
|
dependency: "direct main"
|
||||||
description:
|
description:
|
||||||
name: matrix
|
path: "."
|
||||||
sha256: "2f2f697a3e2d744e5deb43800eea59ac47df58b90275c31ba272f4115880e946"
|
ref: HEAD
|
||||||
url: "https://pub.dev"
|
resolved-ref: "9bf0a7fe207deb483ccb99c939a001fa9999036c"
|
||||||
source: hosted
|
url: "https://github.com/famedly/matrix-dart-sdk.git"
|
||||||
|
source: git
|
||||||
version: "4.0.1"
|
version: "4.0.1"
|
||||||
meta:
|
meta:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
|
|
|
||||||
|
|
@ -53,7 +53,8 @@ dependencies:
|
||||||
just_audio: ^0.10.5
|
just_audio: ^0.10.5
|
||||||
latlong2: ^0.9.1
|
latlong2: ^0.9.1
|
||||||
linkify: ^5.0.0
|
linkify: ^5.0.0
|
||||||
matrix: ^4.0.1
|
matrix: #^4.0.1
|
||||||
|
git: https://github.com/famedly/matrix-dart-sdk.git
|
||||||
mime: ^2.0.0
|
mime: ^2.0.0
|
||||||
native_imaging: ^0.2.0
|
native_imaging: ^0.2.0
|
||||||
opus_caf_converter_dart: ^1.0.1
|
opus_caf_converter_dart: ^1.0.1
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue