simplified code across the app and consolidated duplicated helpers
This commit is contained in:
@@ -20,7 +20,7 @@ class ChatBubbleStyles {
|
||||
? const Color(0xff182229)
|
||||
: Colors.white,
|
||||
elevation: 2,
|
||||
margin: const BubbleEdges.only(bottom: 20, top: 10),
|
||||
margin: const EdgeInsets.only(bottom: 20, top: 10),
|
||||
alignment: Alignment.center,
|
||||
);
|
||||
|
||||
@@ -30,7 +30,7 @@ class ChatBubbleStyles {
|
||||
? const Color(0xff202c33)
|
||||
: Colors.white,
|
||||
elevation: 1,
|
||||
margin: const BubbleEdges.only(bottom: 10, left: 10, right: 50),
|
||||
margin: const EdgeInsets.only(bottom: 10, left: 10, right: 50),
|
||||
alignment: Alignment.topLeft,
|
||||
);
|
||||
|
||||
@@ -40,7 +40,7 @@ class ChatBubbleStyles {
|
||||
? const Color(0xff005c4b)
|
||||
: const Color(0xffd3d3d3),
|
||||
elevation: 1,
|
||||
margin: const BubbleEdges.only(bottom: 10, right: 10, left: 50),
|
||||
margin: const EdgeInsets.only(bottom: 10, right: 10, left: 50),
|
||||
alignment: Alignment.topRight,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -11,27 +11,33 @@ import '../widgets/highlighted_linkify.dart';
|
||||
import '../widgets/message_markdown.dart';
|
||||
|
||||
class ChatMessage {
|
||||
String originalMessage;
|
||||
Map<String, RichObjectString>? originalData;
|
||||
final String originalMessage;
|
||||
final Map<String, RichObjectString>? originalData;
|
||||
|
||||
RichObjectString? file;
|
||||
String content = '';
|
||||
final RichObjectString? file;
|
||||
final String content;
|
||||
|
||||
ChatMessage({required this.originalMessage, this.originalData}) {
|
||||
if (originalData?.containsKey('file') ?? false) {
|
||||
file = originalData?['file'];
|
||||
}
|
||||
content = RichObjectStringProcessor.parseToString(
|
||||
originalMessage,
|
||||
originalData,
|
||||
);
|
||||
}
|
||||
ChatMessage({required this.originalMessage, this.originalData})
|
||||
: file = originalData?['file'],
|
||||
content = RichObjectStringProcessor.parseToString(
|
||||
originalMessage,
|
||||
originalData,
|
||||
);
|
||||
|
||||
Widget getWidget({
|
||||
String? highlightQuery,
|
||||
TextStyle? style,
|
||||
bool renderMarkdown = false,
|
||||
}) {
|
||||
final poll = originalData?['object'];
|
||||
if (poll?.type == RichObjectStringObjectType.talkPoll) {
|
||||
return ListTile(
|
||||
leading: const Icon(Icons.poll_outlined),
|
||||
title: Text(poll!.name),
|
||||
contentPadding: const EdgeInsets.only(left: 10),
|
||||
);
|
||||
}
|
||||
|
||||
final emojiFontSize = standaloneEmojiFontSize(content);
|
||||
final effectiveStyle = emojiFontSize == null
|
||||
? style
|
||||
@@ -64,14 +70,7 @@ class ChatMessage {
|
||||
);
|
||||
}
|
||||
|
||||
if (originalData?['object']?.type == RichObjectStringObjectType.talkPoll) {
|
||||
return ListTile(
|
||||
leading: const Icon(Icons.poll_outlined),
|
||||
title: Text(originalData!['object']!.name),
|
||||
contentPadding: const EdgeInsets.only(left: 10),
|
||||
);
|
||||
}
|
||||
|
||||
final file = this.file;
|
||||
if (file == null) return contentWidget;
|
||||
|
||||
return Padding(
|
||||
@@ -88,7 +87,7 @@ class ChatMessage {
|
||||
const SizedBox(width: 10),
|
||||
Flexible(
|
||||
child: Text(
|
||||
file!.name,
|
||||
file.name,
|
||||
maxLines: 2,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: const TextStyle(fontWeight: FontWeight.bold),
|
||||
@@ -107,7 +106,7 @@ class ChatMessage {
|
||||
errorListener: (value) {},
|
||||
httpHeaders: SessionManager().requireNextcloud().authHeaders,
|
||||
imageUrl:
|
||||
'https://${EndpointData().nextcloud().full()}/index.php/core/preview?fileId=${file!.id}&x=130&y=-1&a=1',
|
||||
'https://${EndpointData().nextcloud().full()}/index.php/core/preview?fileId=${file.id}&x=130&y=-1&a=1',
|
||||
),
|
||||
if (originalMessage != '{file}') ...[
|
||||
SizedBox(height: 5),
|
||||
|
||||
@@ -53,9 +53,11 @@ String markdownToPlainText(String source) {
|
||||
|
||||
final buffer = StringBuffer();
|
||||
_collect(nodes, buffer);
|
||||
return buffer.toString().replaceAll(RegExp(r'\s+'), ' ').trim();
|
||||
return buffer.toString().replaceAll(_whitespace, ' ').trim();
|
||||
}
|
||||
|
||||
final _whitespace = RegExp(r'\s+');
|
||||
|
||||
void _collect(List<md.Node> nodes, StringBuffer buffer) {
|
||||
for (final node in nodes) {
|
||||
if (node is md.Text) {
|
||||
|
||||
Reference in New Issue
Block a user