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,
|
|
|
|
});
|
|
|
|
|
2024-07-25 17:16:32 +00:00
|
|
|
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) {
|
2024-08-01 08:28:48 +00:00
|
|
|
final unFocusColor =
|
|
|
|
Theme.of(context).colorScheme.onSurface.withOpacity(0.75);
|
2024-07-25 17:16:32 +00:00
|
|
|
return Row(
|
|
|
|
children: [
|
|
|
|
Icon(
|
2024-08-07 06:27:23 +00:00
|
|
|
Icons.file_copy,
|
|
|
|
size: 15,
|
2024-07-25 17:16:32 +00:00
|
|
|
color: unFocusColor,
|
2024-08-07 06:27:23 +00:00
|
|
|
).paddingOnly(right: 5),
|
2024-07-25 17:16:32 +00:00
|
|
|
Text(
|
2024-08-01 08:28:48 +00:00
|
|
|
'attachmentHint'.trParams(
|
2024-07-25 17:16:32 +00:00
|
|
|
{'count': body.attachments?.length.toString() ?? 0.toString()},
|
|
|
|
),
|
|
|
|
style: TextStyle(color: unFocusColor),
|
|
|
|
)
|
|
|
|
],
|
|
|
|
);
|
|
|
|
}
|
2024-06-27 16:59:11 +00:00
|
|
|
|
2024-08-06 08:24:47 +00:00
|
|
|
return MarkdownTextContent(
|
|
|
|
parentId: 'm${item.id}',
|
|
|
|
isSelectable: true,
|
2024-09-23 14:43:13 +00:00
|
|
|
isAutoWarp: true,
|
2024-08-06 08:24:47 +00:00
|
|
|
content: body.text,
|
|
|
|
);
|
2024-07-25 17:16:32 +00:00
|
|
|
}
|
2024-06-27 16:59:11 +00:00
|
|
|
|
2024-07-25 17:16:32 +00:00
|
|
|
Widget _buildBody(BuildContext context) {
|
2024-08-01 08:28:48 +00:00
|
|
|
if (isMerged) {
|
2024-08-19 14:25:17 +00:00
|
|
|
return _buildContent(context).paddingOnly(left: 52);
|
2024-06-27 16:59:11 +00:00
|
|
|
} else {
|
2024-08-19 14:25:17 +00:00
|
|
|
return _buildContent(context);
|
2024-06-27 16:59:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2024-07-25 17:16:32 +00:00
|
|
|
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-07-25 17:16:32 +00:00
|
|
|
);
|
2024-06-27 16:59:11 +00:00
|
|
|
}
|
|
|
|
}
|