implemented in-chat search with text highlighting, added search navigation UI, and integrated scrollable list for message jumping
This commit is contained in:
@@ -1,12 +1,12 @@
|
||||
import 'package:cached_network_image/cached_network_image.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_linkify/flutter_linkify.dart';
|
||||
|
||||
import '../../../../api/marianumcloud/talk/chat/get_chat_response.dart';
|
||||
import '../../../../api/marianumcloud/talk/chat/rich_object_string_processor.dart';
|
||||
import '../../../../model/account_data.dart';
|
||||
import '../../../../model/endpoint_data.dart';
|
||||
import '../../../../utils/url_opener.dart';
|
||||
import '../widgets/highlighted_linkify.dart';
|
||||
|
||||
class ChatMessage {
|
||||
String originalMessage;
|
||||
@@ -27,8 +27,13 @@ class ChatMessage {
|
||||
);
|
||||
}
|
||||
|
||||
Widget getWidget() {
|
||||
var contentWidget = Linkify(text: content, onOpen: UrlOpener.onOpen);
|
||||
Widget getWidget({String? highlightQuery, TextStyle? style}) {
|
||||
var contentWidget = HighlightedLinkify(
|
||||
text: content,
|
||||
onOpen: UrlOpener.onOpen,
|
||||
highlight: highlightQuery,
|
||||
style: style,
|
||||
);
|
||||
|
||||
if (originalData?['object']?.type == RichObjectStringObjectType.talkPoll) {
|
||||
return ListTile(
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
import '../../../../api/marianumcloud/talk/chat/get_chat_response.dart';
|
||||
import '../../../../api/marianumcloud/talk/chat/rich_object_string_processor.dart';
|
||||
import '../../../../api/marianumcloud/talk/room/get_room_response.dart';
|
||||
|
||||
class ChatSearchMatch {
|
||||
final int messageId;
|
||||
final int timestamp;
|
||||
|
||||
const ChatSearchMatch({required this.messageId, required this.timestamp});
|
||||
}
|
||||
|
||||
class ChatSearchController {
|
||||
static List<ChatSearchMatch> findMatches(
|
||||
GetChatResponse response,
|
||||
String query,
|
||||
) {
|
||||
final q = query.trim().toLowerCase();
|
||||
if (q.isEmpty) return const [];
|
||||
|
||||
final matches = <ChatSearchMatch>[];
|
||||
for (final element in response.sortByTimestamp()) {
|
||||
if (element.systemMessage.contains('reaction')) continue;
|
||||
if (element.systemMessage.contains('poll_voted')) continue;
|
||||
|
||||
final haystackText = RichObjectStringProcessor.parseToString(
|
||||
element.message,
|
||||
element.messageParameters,
|
||||
).toLowerCase();
|
||||
|
||||
var matched = haystackText.contains(q);
|
||||
if (!matched &&
|
||||
element.messageType != GetRoomResponseObjectMessageType.system) {
|
||||
matched = element.actorDisplayName.toLowerCase().contains(q);
|
||||
}
|
||||
|
||||
if (matched) {
|
||||
matches.add(
|
||||
ChatSearchMatch(
|
||||
messageId: element.id,
|
||||
timestamp: element.timestamp,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
matches.sort((a, b) => b.timestamp.compareTo(a.timestamp));
|
||||
return matches;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user