Solian/lib/widgets/chat/message.dart

128 lines
3.5 KiB
Dart
Raw Normal View History

2024-04-17 15:00:53 +00:00
import 'package:flutter/material.dart';
import 'package:solian/models/message.dart';
import 'package:solian/widgets/account/account_avatar.dart';
import 'package:solian/widgets/chat/message_content.dart';
2024-04-17 15:00:53 +00:00
import 'package:solian/widgets/posts/content/attachment.dart';
import 'package:timeago/timeago.dart' as timeago;
2024-04-19 09:51:00 +00:00
import 'dart:math' as math;
2024-04-17 15:00:53 +00:00
class ChatMessage extends StatelessWidget {
final Message item;
final bool underMerged;
const ChatMessage({super.key, required this.item, required this.underMerged});
Widget renderAttachment() {
if (item.attachments != null && item.attachments!.isNotEmpty) {
return Padding(
padding: const EdgeInsets.symmetric(vertical: 6),
child: AttachmentList(items: item.attachments!, provider: 'messaging'),
);
} else {
return Container();
}
}
2024-04-19 09:51:00 +00:00
Widget renderReply() {
if (item.replyTo != null) {
return Row(
children: [
Container(
2024-04-19 11:36:03 +00:00
padding: const EdgeInsets.only(left: 8, right: 8),
2024-04-19 09:51:00 +00:00
child: Row(
2024-04-19 11:48:31 +00:00
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Transform(
alignment: Alignment.center,
transform: Matrix4.rotationY(math.pi),
child: const Icon(Icons.reply, size: 16),
),
const SizedBox(width: 8),
2024-04-26 12:49:21 +00:00
AccountAvatar(
2024-04-19 11:48:31 +00:00
radius: 10,
2024-04-26 12:49:21 +00:00
source: item.replyTo!.sender.account.avatar,
direct: true,
2024-04-19 11:48:31 +00:00
),
],
),
2024-04-19 09:51:00 +00:00
),
Expanded(
child: Column(
children: [
Padding(
padding: const EdgeInsets.only(right: 12, top: 2),
child: ChatMessageContent(item: item.replyTo!),
),
renderAttachment()
],
),
),
],
);
} else {
return Container();
}
}
2024-04-17 15:00:53 +00:00
@override
Widget build(BuildContext context) {
final contentPart = Padding(
padding: const EdgeInsets.only(left: 12, right: 12, top: 2),
child: ChatMessageContent(item: item),
);
final userinfoPart = Padding(
padding: const EdgeInsets.symmetric(horizontal: 12),
child: Row(
children: [
Text(
item.sender.account.nick,
style: const TextStyle(fontWeight: FontWeight.bold),
),
const SizedBox(width: 4),
Text(timeago.format(item.createdAt))
],
),
);
if (underMerged) {
return Row(
children: [
const SizedBox(width: 40),
Expanded(
child: Column(
2024-04-19 09:51:00 +00:00
children: [renderReply(), contentPart, renderAttachment()],
),
),
2024-04-17 15:00:53 +00:00
],
);
} else {
2024-04-19 09:51:00 +00:00
return Column(
2024-04-17 15:00:53 +00:00
children: [
2024-04-19 09:51:00 +00:00
renderReply(),
Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
2024-04-26 12:49:21 +00:00
AccountAvatar(
source: item.sender.account.avatar,
direct: true,
2024-04-19 09:51:00 +00:00
),
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
userinfoPart,
contentPart,
renderAttachment(),
],
),
),
],
2024-04-17 15:00:53 +00:00
),
],
);
}
}
}