2024-11-17 14:42:09 +00:00
|
|
|
import 'package:easy_localization/easy_localization.dart';
|
2024-11-16 17:16:54 +00:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:gap/gap.dart';
|
|
|
|
import 'package:provider/provider.dart';
|
|
|
|
import 'package:styled_widget/styled_widget.dart';
|
|
|
|
import 'package:surface/providers/user_directory.dart';
|
|
|
|
import 'package:surface/types/chat.dart';
|
|
|
|
import 'package:surface/widgets/account/account_image.dart';
|
2024-11-17 16:55:39 +00:00
|
|
|
import 'package:surface/widgets/attachment/attachment_list.dart';
|
2024-11-16 17:16:54 +00:00
|
|
|
import 'package:surface/widgets/markdown_content.dart';
|
|
|
|
|
|
|
|
class ChatMessage extends StatelessWidget {
|
|
|
|
final SnChatMessage data;
|
2024-11-17 14:42:09 +00:00
|
|
|
final bool isMerged;
|
|
|
|
final bool hasMerged;
|
2024-11-17 13:30:02 +00:00
|
|
|
final bool isPending;
|
2024-11-17 14:42:09 +00:00
|
|
|
const ChatMessage({
|
|
|
|
super.key,
|
|
|
|
required this.data,
|
|
|
|
this.isMerged = false,
|
|
|
|
this.hasMerged = false,
|
|
|
|
this.isPending = false,
|
|
|
|
});
|
2024-11-16 17:16:54 +00:00
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
final ud = context.read<UserDirectoryProvider>();
|
|
|
|
final user = ud.getAccountFromCache(data.sender.accountId);
|
|
|
|
|
2024-11-17 14:42:09 +00:00
|
|
|
final dateFormatter = DateFormat('MM/dd HH:mm');
|
|
|
|
|
2024-11-18 13:38:15 +00:00
|
|
|
return Column(
|
2024-11-16 17:16:54 +00:00
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
children: [
|
2024-11-18 13:38:15 +00:00
|
|
|
Row(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
children: [
|
|
|
|
if (!isMerged)
|
|
|
|
AccountImage(
|
|
|
|
content: user?.avatar,
|
|
|
|
)
|
|
|
|
else
|
|
|
|
const Gap(40),
|
|
|
|
const Gap(8),
|
|
|
|
Expanded(
|
|
|
|
child: Column(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
children: [
|
|
|
|
if (!isMerged)
|
|
|
|
Row(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.baseline,
|
|
|
|
textBaseline: TextBaseline.alphabetic,
|
|
|
|
children: [
|
|
|
|
Text(
|
|
|
|
(data.sender.nick?.isNotEmpty ?? false)
|
|
|
|
? data.sender.nick!
|
|
|
|
: user!.nick,
|
|
|
|
).bold(),
|
|
|
|
const Gap(6),
|
|
|
|
Text(
|
|
|
|
dateFormatter.format(data.createdAt.toLocal()),
|
|
|
|
).fontSize(13),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
if (data.body['text'] != null)
|
|
|
|
MarkdownTextContent(
|
|
|
|
content: data.body['text'],
|
|
|
|
isAutoWarp: true,
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
)
|
|
|
|
],
|
|
|
|
).opacity(isPending ? 0.5 : 1),
|
|
|
|
if (data.preload?.attachments?.isNotEmpty ?? false)
|
|
|
|
AttachmentList(
|
|
|
|
data: data.preload!.attachments!,
|
|
|
|
bordered: true,
|
|
|
|
noGrow: true,
|
|
|
|
maxHeight: 520,
|
|
|
|
listPadding: const EdgeInsets.only(top: 8),
|
2024-11-16 17:16:54 +00:00
|
|
|
),
|
2024-11-18 13:38:15 +00:00
|
|
|
if (!hasMerged) const Gap(8),
|
2024-11-16 17:16:54 +00:00
|
|
|
],
|
2024-11-18 13:38:15 +00:00
|
|
|
);
|
2024-11-16 17:16:54 +00:00
|
|
|
}
|
|
|
|
}
|