Solian/lib/widgets/chat/chat_event_message.dart

74 lines
1.9 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;
if (body.text.isEmpty && hasAttachment) {
final unFocusColor =
Theme.of(context).colorScheme.onSurface.withOpacity(0.75);
return Row(
children: [
Icon(
Icons.attachment,
size: 18,
color: unFocusColor,
).paddingOnly(right: 6),
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,
bottom: hasAttachment && !isContentPreviewing ? 4 : (isHasMerged ? 2 : 0),
);
2024-06-27 16:59:11 +00:00
}
}