Embedded reply post and repost

This commit is contained in:
LittleSheep 2024-05-22 20:56:10 +08:00
parent c7afa7e8e4
commit 57ff5e44ba
3 changed files with 117 additions and 5 deletions

View File

@ -47,6 +47,8 @@ class SolianMessages extends Translations {
'postContentPlaceholder': 'What\'s happened?!', 'postContentPlaceholder': 'What\'s happened?!',
'postReaction': 'Reactions of the Post', 'postReaction': 'Reactions of the Post',
'postActionList': 'Actions of Post', 'postActionList': 'Actions of Post',
'postRepliedNotify': 'Replied a post from @username.',
'postRepostedNotify': 'Reposted a post from @username.',
'postEditingNotify': 'You\'re editing as post from you.', 'postEditingNotify': 'You\'re editing as post from you.',
'postReplyingNotify': 'You\'re replying a post from @username.', 'postReplyingNotify': 'You\'re replying a post from @username.',
'postRepostingNotify': 'You\'re reposting a post from @username.', 'postRepostingNotify': 'You\'re reposting a post from @username.',
@ -105,6 +107,8 @@ class SolianMessages extends Translations {
'postContentPlaceholder': '发生什么事了?!', 'postContentPlaceholder': '发生什么事了?!',
'postReaction': '帖子的反应', 'postReaction': '帖子的反应',
'postActionList': '帖子的操作', 'postActionList': '帖子的操作',
'postRepliedNotify': '回了一个 @username 的帖子',
'postRepostedNotify': '转了一个 @username 的帖子',
'postEditingNotify': '你正在编辑一个你发布的帖子', 'postEditingNotify': '你正在编辑一个你发布的帖子',
'postReplyingNotify': '你正在回一个来自 @username 的帖子', 'postReplyingNotify': '你正在回一个来自 @username 的帖子',
'postRepostingNotify': '你正在转一个来自 @username 的帖子', 'postRepostingNotify': '你正在转一个来自 @username 的帖子',

View File

@ -6,7 +6,8 @@ class AccountAvatar extends StatelessWidget {
final Color? color; final Color? color;
final double? radius; final double? radius;
const AccountAvatar({super.key, required this.content, this.color, this.radius}); const AccountAvatar(
{super.key, required this.content, this.color, this.radius});
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
@ -21,10 +22,19 @@ class AccountAvatar extends StatelessWidget {
key: Key('a$content'), key: Key('a$content'),
radius: radius, radius: radius,
backgroundColor: color, backgroundColor: color,
backgroundImage: !isEmpty ? NetworkImage( backgroundImage: !isEmpty
direct ? content : '${ServiceFinder.services['paperclip']}/api/attachments/$content', ? NetworkImage(
) : null, direct
child: isEmpty ? const Icon(Icons.account_circle) : null, ? content
: '${ServiceFinder.services['paperclip']}/api/attachments/$content',
)
: null,
child: isEmpty
? Icon(
Icons.account_circle,
size: radius != null ? radius! * 1.2 : 24,
)
: null,
); );
} }
} }

View File

@ -10,11 +10,13 @@ import 'package:timeago/timeago.dart' show format;
class PostItem extends StatefulWidget { class PostItem extends StatefulWidget {
final Post item; final Post item;
final bool isCompact;
final bool isReactable; final bool isReactable;
const PostItem({ const PostItem({
super.key, super.key,
required this.item, required this.item,
this.isCompact = false,
this.isReactable = true, this.isReactable = true,
}); });
@ -31,10 +33,104 @@ class _PostItemState extends State<PostItem> {
super.initState(); super.initState();
} }
Widget buildReply(BuildContext context) {
return Column(
children: [
Row(
children: [
Icon(
Icons.reply,
size: 18,
color: Theme.of(context).colorScheme.onSurface.withOpacity(0.75),
),
Text(
'postRepliedNotify'.trParams(
{'username': '@${widget.item.author.name}'},
),
style: TextStyle(
color:
Theme.of(context).colorScheme.onSurface.withOpacity(0.75),
),
).paddingOnly(left: 6),
],
).paddingOnly(left: 12),
Card(
elevation: 1,
child: PostItem(
item: widget.item.replyTo!,
isCompact: true,
).paddingSymmetric(vertical: 8),
),
],
);
}
Widget buildRepost(BuildContext context) {
return Column(
children: [
Row(
children: [
Icon(
Icons.redo,
size: 18,
color: Theme.of(context).colorScheme.onSurface.withOpacity(0.75),
),
Text(
'postRepostedNotify'.trParams(
{'username': '@${widget.item.author.name}'},
),
style: TextStyle(
color:
Theme.of(context).colorScheme.onSurface.withOpacity(0.75),
),
).paddingOnly(left: 6),
],
).paddingOnly(left: 12),
Card(
elevation: 1,
child: PostItem(
item: widget.item.repostTo!,
isCompact: true,
).paddingSymmetric(vertical: 8),
),
],
);
}
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
final hasAttachment = item.attachments?.isNotEmpty ?? false; final hasAttachment = item.attachments?.isNotEmpty ?? false;
if (widget.isCompact) {
return Column(
children: [
Row(
children: [
AccountAvatar(content: item.author.avatar.toString(), radius: 10),
Text(
item.author.nick,
style: const TextStyle(fontWeight: FontWeight.bold),
).paddingOnly(left: 6),
Text(format(item.createdAt, locale: 'en_short'))
.paddingOnly(left: 4),
],
).paddingSymmetric(horizontal: 12),
Markdown(
shrinkWrap: true,
physics: const NeverScrollableScrollPhysics(),
data: item.content,
padding: const EdgeInsets.all(0),
).paddingOnly(
left: 16,
right: 12,
top: 2,
bottom: hasAttachment ? 4 : 0,
),
AttachmentList(attachmentsId: item.attachments ?? List.empty()),
],
);
}
return Column( return Column(
children: [ children: [
Row( Row(
@ -54,6 +150,8 @@ class _PostItemState extends State<PostItem> {
.paddingOnly(left: 4), .paddingOnly(left: 4),
], ],
), ),
if (widget.item.replyTo != null) buildReply(context),
if (widget.item.repostTo != null) buildRepost(context),
Markdown( Markdown(
shrinkWrap: true, shrinkWrap: true,
physics: const NeverScrollableScrollPhysics(), physics: const NeverScrollableScrollPhysics(),