Solian/lib/widgets/chat/chat_event_message.dart

79 lines
2.0 KiB
Dart
Raw Normal View History

2024-06-27 16:59:11 +00:00
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:solian/models/event.dart';
2024-07-11 16:44:57 +00:00
import 'package:solian/widgets/markdown_text_content.dart';
2024-06-27 16:59:11 +00:00
class ChatEventMessage extends StatelessWidget {
final Event item;
final bool isContentPreviewing;
final bool isQuote;
final bool isMerged;
final bool isHasMerged;
const ChatEventMessage({
super.key,
required this.item,
this.isContentPreviewing = false,
this.isMerged = false,
this.isHasMerged = false,
this.isQuote = false,
});
Widget _buildContent(BuildContext context) {
2024-06-27 16:59:11 +00:00
final body = EventMessageBody.fromJson(item.body);
final hasAttachment = body.attachments?.isNotEmpty ?? false;
2024-08-07 06:27:23 +00:00
if (body.text.isEmpty &&
hasAttachment &&
!isContentPreviewing &&
!isQuote) {
final unFocusColor =
Theme.of(context).colorScheme.onSurface.withOpacity(0.75);
return Row(
children: [
Icon(
2024-08-07 06:27:23 +00:00
Icons.file_copy,
size: 15,
color: unFocusColor,
2024-08-07 06:27:23 +00:00
).paddingOnly(right: 5),
Text(
'attachmentHint'.trParams(
{'count': body.attachments?.length.toString() ?? 0.toString()},
),
style: TextStyle(color: unFocusColor),
)
],
);
}
2024-06-27 16:59:11 +00:00
return MarkdownTextContent(
parentId: 'm${item.id}',
isSelectable: true,
content: body.text,
);
}
2024-06-27 16:59:11 +00:00
Widget _buildBody(BuildContext context) {
if (isMerged) {
return _buildContent(context).paddingOnly(left: 52);
2024-06-27 16:59:11 +00:00
} else {
return _buildContent(context);
2024-06-27 16:59:11 +00:00
}
}
@override
Widget build(BuildContext context) {
final body = EventMessageBody.fromJson(item.body);
final hasAttachment = body.attachments?.isNotEmpty ?? false;
return _buildBody(context).paddingOnly(
left: isQuote ? 0 : 12,
right: isQuote ? 0 : 12,
top: body.quoteEvent == null ? 2 : 0,
2024-08-06 12:00:13 +00:00
bottom: hasAttachment && !isContentPreviewing && !isQuote
? 4
: (isHasMerged ? 2 : 0),
);
2024-06-27 16:59:11 +00:00
}
}