Better post display

🐛 Fix realm with post
This commit is contained in:
2024-06-23 01:52:05 +08:00
parent 4144bb307e
commit bb67edd227
12 changed files with 271 additions and 210 deletions

View File

@ -75,8 +75,8 @@ class Post {
json["reply_to"] != null ? Post.fromJson(json["reply_to"]) : null,
repostTo:
json["repost_to"] != null ? Post.fromJson(json["repost_to"]) : null,
realm: json["realm"],
publishedAt: json["published_at"],
realm: json["realm"] != null ? Realm.fromJson(json["realm"]) : null,
publishedAt: json["published_at"] != null ? DateTime.parse(json["published_at"]) : null,
authorId: json["author_id"],
author: Account.fromJson(json["author"]),
replyCount: json["reply_count"],
@ -108,8 +108,8 @@ class Post {
"realm_id": realmId,
"reply_to": replyTo?.toJson(),
"repost_to": repostTo?.toJson(),
"realm": realm,
"published_at": publishedAt,
"realm": realm?.toJson(),
"published_at": publishedAt?.toIso8601String(),
"author_id": authorId,
"author": author.toJson(),
"reply_count": replyCount,

View File

@ -7,7 +7,7 @@ import 'package:solian/screens/account/personalize.dart';
import 'package:solian/screens/channel/channel_chat.dart';
import 'package:solian/screens/channel/channel_detail.dart';
import 'package:solian/screens/channel/channel_organize.dart';
import 'package:solian/screens/contact.dart';
import 'package:solian/screens/chat.dart';
import 'package:solian/screens/posts/post_detail.dart';
import 'package:solian/screens/realms.dart';
import 'package:solian/screens/realms/realm_detail.dart';
@ -31,9 +31,9 @@ abstract class AppRouter {
builder: (context, state) => const SocialScreen(),
),
GoRoute(
path: '/contact',
name: 'contact',
builder: (context, state) => const ContactScreen(),
path: '/chat',
name: 'chat',
builder: (context, state) => const ChatScreen(),
),
GoRoute(
path: '/realms',

View File

@ -15,14 +15,14 @@ import 'package:solian/widgets/channel/channel_list.dart';
import 'package:solian/widgets/chat/call/chat_call_indicator.dart';
import 'package:solian/widgets/current_state_action.dart';
class ContactScreen extends StatefulWidget {
const ContactScreen({super.key});
class ChatScreen extends StatefulWidget {
const ChatScreen({super.key});
@override
State<ContactScreen> createState() => _ContactScreenState();
State<ChatScreen> createState() => _ChatScreenState();
}
class _ContactScreenState extends State<ContactScreen> {
class _ChatScreenState extends State<ChatScreen> {
bool _isBusy = true;
int? _accountId;
@ -85,7 +85,7 @@ class _ContactScreenState extends State<ContactScreen> {
child: CustomScrollView(
slivers: [
SliverAppBar(
title: AppBarTitle('contact'.tr),
title: AppBarTitle('chat'.tr),
centerTitle: false,
floating: true,
titleSpacing: SolianTheme.titleSpacing(context),

View File

@ -50,6 +50,7 @@ class _PostDetailScreenState extends State<PostDetailScreen> {
child: PostItem(
item: item!,
isClickable: true,
isFullDate: true,
isShowReply: false,
),
),

View File

@ -83,69 +83,67 @@ class _RealmViewScreenState extends State<RealmViewScreen> {
color: Theme.of(context).colorScheme.surface,
child: DefaultTabController(
length: 2,
child: SafeArea(
child: NestedScrollView(
headerSliverBuilder: (context, innerBoxIsScrolled) {
return [
SliverOverlapAbsorber(
handle:
NestedScrollView.sliverOverlapAbsorberHandleFor(context),
sliver: SliverAppBar(
title: Text(_realm?.name ?? 'loading'.tr),
centerTitle: false,
actions: [
IconButton(
icon: const Icon(Icons.more_vert),
onPressed: () {
AppRouter.instance
.pushNamed(
'realmDetail',
pathParameters: {'alias': widget.alias},
extra: _realm,
)
.then((value) {
if (value == false) AppRouter.instance.pop();
if (value != null) {
final resp =
Realm.fromJson(value as Map<String, dynamic>);
getRealm(overrideAlias: resp.alias);
}
});
},
),
SizedBox(
width: SolianTheme.isLargeScreen(context) ? 8 : 16,
),
],
bottom: const TabBar(
isScrollable: true,
tabs: [
Tab(icon: Icon(Icons.feed)),
Tab(icon: Icon(Icons.chat)),
],
child: NestedScrollView(
headerSliverBuilder: (context, innerBoxIsScrolled) {
return [
SliverOverlapAbsorber(
handle:
NestedScrollView.sliverOverlapAbsorberHandleFor(context),
sliver: SliverAppBar(
title: Text(_realm?.name ?? 'loading'.tr),
centerTitle: false,
actions: [
IconButton(
icon: const Icon(Icons.more_vert),
onPressed: () {
AppRouter.instance
.pushNamed(
'realmDetail',
pathParameters: {'alias': widget.alias},
extra: _realm,
)
.then((value) {
if (value == false) AppRouter.instance.pop();
if (value != null) {
final resp =
Realm.fromJson(value as Map<String, dynamic>);
getRealm(overrideAlias: resp.alias);
}
});
},
),
),
)
];
},
body: Builder(
builder: (context) {
if (_isBusy) {
return const Center(child: CircularProgressIndicator());
}
return TabBarView(
children: [
RealmPostListWidget(realm: _realm!),
RealmChannelListWidget(
realm: _realm!,
channels: _channels,
onRefresh: () => getChannels(),
SizedBox(
width: SolianTheme.isLargeScreen(context) ? 8 : 16,
),
],
);
},
),
bottom: const TabBar(
isScrollable: true,
tabs: [
Tab(icon: Icon(Icons.feed)),
Tab(icon: Icon(Icons.chat)),
],
),
),
)
];
},
body: Builder(
builder: (context) {
if (_isBusy) {
return const Center(child: CircularProgressIndicator());
}
return TabBarView(
children: [
RealmPostListWidget(realm: _realm!),
RealmChannelListWidget(
realm: _realm!,
channels: _channels,
onRefresh: () => getChannels(),
),
],
);
},
),
),
),

View File

@ -3,7 +3,6 @@ import 'package:get/get.dart';
import 'package:infinite_scroll_pagination/infinite_scroll_pagination.dart';
import 'package:solian/models/pagination.dart';
import 'package:solian/models/post.dart';
import 'package:solian/platform.dart';
import 'package:solian/providers/auth.dart';
import 'package:solian/providers/content/post.dart';
import 'package:solian/router.dart';

View File

@ -10,7 +10,7 @@ class SolianMessages extends Translations {
'reset': 'Reset',
'page': 'Page',
'social': 'Social',
'contact': 'Contact',
'chat': 'Chat',
'apply': 'Apply',
'cancel': 'Cancel',
'confirm': 'Confirm',
@ -72,6 +72,8 @@ class SolianMessages extends Translations {
'postNew': 'Create a new post',
'postNewInRealmHint': 'Add post in realm @realm',
'postAction': 'Post',
'postEdited': 'Edited at @date',
'postInRealm': 'In realm @realm',
'postDetail': 'Post',
'postReplies': 'Replies',
'postPublishing': 'Post post',
@ -226,7 +228,7 @@ class SolianMessages extends Translations {
'delete': '删除',
'page': '页面',
'social': '社交',
'contact': '联系',
'chat': '聊天',
'apply': '应用',
'search': '搜索',
'reply': '回复',
@ -275,6 +277,8 @@ class SolianMessages extends Translations {
'postNew': '创建新帖子',
'postNewInRealmHint': '在领域 @realm 里发表新帖子',
'postAction': '发表',
'postEdited': '帖子编辑于 @date',
'postInRealm': '发表于 @realm',
'postDetail': '帖子详情',
'postReplies': '帖子回复',
'postPublishing': '发表帖子',

View File

@ -11,9 +11,16 @@ import 'package:solian/widgets/attachments/attachment_list_fullscreen.dart';
class AttachmentList extends StatefulWidget {
final String parentId;
final List<int> attachmentsId;
final bool divided;
final double dividedPadding;
const AttachmentList(
{super.key, required this.parentId, required this.attachmentsId});
const AttachmentList({
super.key,
required this.parentId,
required this.attachmentsId,
this.divided = false,
this.dividedPadding = 16,
});
@override
State<AttachmentList> createState() => _AttachmentListState();
@ -91,6 +98,83 @@ class _AttachmentListState extends State<AttachmentList> {
}
}
Widget buildEntry(Attachment element, int idx) {
return GestureDetector(
child: Container(
width: MediaQuery.of(context).size.width,
decoration: BoxDecoration(
color: Theme.of(context).colorScheme.surfaceContainerHigh,
),
child: Stack(
fit: StackFit.expand,
children: [
AttachmentItem(
parentId: widget.parentId,
key: Key('a${element.uuid}'),
item: element,
badge: _attachmentsMeta.length > 1
? '${idx + 1}/${_attachmentsMeta.length}'
: null,
showHideButton: !element.isMature || _showMature,
onHide: () {
setState(() => _showMature = false);
},
),
if (element.isMature && !_showMature)
BackdropFilter(
filter: ImageFilter.blur(sigmaX: 100, sigmaY: 100),
child: Container(
decoration: BoxDecoration(
color: Colors.black.withOpacity(0.5),
),
),
),
if (element.isMature && !_showMature)
Center(
child: Container(
constraints: const BoxConstraints(maxWidth: 280),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
const Icon(Icons.visibility_off,
color: Colors.white, size: 32),
const SizedBox(height: 8),
Text(
'matureContent'.tr,
style: const TextStyle(
color: Colors.white,
fontWeight: FontWeight.bold,
fontSize: 16),
),
Text(
'matureContentCaption'.tr,
style: const TextStyle(color: Colors.white),
textAlign: TextAlign.center,
),
],
),
),
),
],
),
),
onTap: () {
if (!_showMature && _attachmentsMeta.any((e) => e!.isMature)) {
setState(() => _showMature = true);
} else if (['image'].contains(element.mimetype.split('/').first)) {
Navigator.of(context, rootNavigator: true).push(
MaterialPageRoute(
builder: (context) => AttachmentListFullScreen(
parentId: widget.parentId,
attachment: element,
),
),
);
}
},
);
}
@override
void initState() {
super.initState();
@ -145,80 +229,21 @@ class _AttachmentListState extends State<AttachmentList> {
);
}
return GestureDetector(
child: Container(
width: MediaQuery.of(context).size.width,
if (widget.divided) {
const radius = BorderRadius.all(Radius.circular(16));
return Container(
decoration: BoxDecoration(
color: Theme.of(context).colorScheme.surfaceContainerHigh,
border: Border.all(color: Theme.of(context).dividerColor, width: 1),
borderRadius: radius,
),
child: Stack(
fit: StackFit.expand,
children: [
AttachmentItem(
parentId: widget.parentId,
key: Key('a${element.uuid}'),
item: element,
badge: _attachmentsMeta.length > 1
? '${idx + 1}/${_attachmentsMeta.length}'
: null,
showHideButton: !element.isMature || _showMature,
onHide: () {
setState(() => _showMature = false);
},
),
if (element.isMature && !_showMature)
BackdropFilter(
filter: ImageFilter.blur(sigmaX: 100, sigmaY: 100),
child: Container(
decoration: BoxDecoration(
color: Colors.black.withOpacity(0.5),
),
),
),
if (element.isMature && !_showMature)
Center(
child: Container(
constraints: const BoxConstraints(maxWidth: 280),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
const Icon(Icons.visibility_off,
color: Colors.white, size: 32),
const SizedBox(height: 8),
Text(
'matureContent'.tr,
style: const TextStyle(
color: Colors.white,
fontWeight: FontWeight.bold,
fontSize: 16),
),
Text(
'matureContentCaption'.tr,
style: const TextStyle(color: Colors.white),
textAlign: TextAlign.center,
),
],
),
),
),
],
child: ClipRRect(
borderRadius: radius,
child: buildEntry(element, idx),
),
),
onTap: () {
if (!_showMature && _attachmentsMeta.any((e) => e!.isMature)) {
setState(() => _showMature = true);
} else if (['image'].contains(element.mimetype.split('/').first)) {
Navigator.of(context, rootNavigator: true).push(
MaterialPageRoute(
builder: (context) => AttachmentListFullScreen(
parentId: widget.parentId,
attachment: element,
),
),
);
}
},
);
).paddingSymmetric(horizontal: widget.dividedPadding);
} else {
return buildEntry(element, idx);
}
},
);
}

View File

@ -9,9 +9,9 @@ abstract class AppNavigation {
page: 'social',
),
AppNavigationDestination(
icon: const Icon(Icons.contacts),
label: 'contact'.tr,
page: 'contact',
icon: const Icon(Icons.forum),
label: 'chat'.tr,
page: 'chat',
),
AppNavigationDestination(
icon: const Icon(Icons.workspaces),

View File

@ -2,6 +2,7 @@ import 'package:flutter/material.dart';
import 'package:flutter_markdown/flutter_markdown.dart';
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
import 'package:get/get_utils/get_utils.dart';
import 'package:intl/intl.dart';
import 'package:solian/models/post.dart';
import 'package:solian/router.dart';
import 'package:solian/widgets/account/account_avatar.dart';
@ -18,6 +19,7 @@ class PostItem extends StatefulWidget {
final bool isReactable;
final bool isShowReply;
final bool isShowEmbed;
final bool isFullDate;
final String? overrideAttachmentParent;
const PostItem({
@ -28,6 +30,7 @@ class PostItem extends StatefulWidget {
this.isReactable = true,
this.isShowReply = true,
this.isShowEmbed = true,
this.isFullDate = false,
this.overrideAttachmentParent,
});
@ -44,6 +47,69 @@ class _PostItemState extends State<PostItem> {
super.initState();
}
Widget buildDate() {
if (widget.isFullDate) {
return Text(DateFormat('y/M/d H:m').format(item.createdAt));
} else {
return Text(format(item.createdAt, locale: 'en_short'));
}
}
Widget buildHeader() {
return Row(
children: [
Text(
item.author.nick,
style: const TextStyle(fontWeight: FontWeight.bold),
).paddingOnly(left: 12),
buildDate().paddingOnly(left: 4),
],
);
}
Widget buildBody() {
return Markdown(
shrinkWrap: true,
physics: const NeverScrollableScrollPhysics(),
data: item.content,
padding: const EdgeInsets.all(0),
onTapLink: (text, href, title) async {
if (href == null) return;
await launchUrlString(
href,
mode: LaunchMode.externalApplication,
);
},
);
}
Widget buildFooter() {
List<String> labels = List.empty(growable: true);
if (widget.item.createdAt != widget.item.updatedAt) {
labels.add('postEdited'.trParams({
'date': DateFormat('yy/M/d H:m').format(item.updatedAt),
}));
}
if (widget.item.realm != null) {
labels.add('postInRealm'.trParams({
'realm': '#${widget.item.realm!.alias}',
}));
}
if (labels.isNotEmpty) {
return Text(
labels.join(" · "),
textAlign: TextAlign.left,
style: TextStyle(
fontSize: 12,
color: Theme.of(context).colorScheme.onSurface.withOpacity(0.75),
),
).paddingOnly(top: 8);
} else {
return const SizedBox();
}
}
Widget buildReply(BuildContext context) {
return Column(
children: [
@ -116,39 +182,20 @@ class _PostItemState extends State<PostItem> {
if (widget.isCompact) {
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
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),
onTapLink: (text, href, title) async {
if (href == null) return;
await launchUrlString(
href,
mode: LaunchMode.externalApplication,
);
},
).paddingOnly(
buildHeader().paddingSymmetric(horizontal: 12),
buildBody().paddingOnly(
left: 16,
right: 12,
top: 2,
bottom: hasAttachment ? 4 : 0,
),
buildFooter().paddingOnly(left: 16),
AttachmentList(
parentId: widget.overrideAttachmentParent ?? widget.item.alias,
attachmentsId: item.attachments ?? List.empty(),
divided: true,
),
],
);
@ -175,23 +222,10 @@ class _PostItemState extends State<PostItem> {
),
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
children: [
Text(
item.author.nick,
style: const TextStyle(fontWeight: FontWeight.bold),
).paddingOnly(left: 12),
Text(format(item.createdAt, locale: 'en_short'))
.paddingOnly(left: 4),
],
),
Markdown(
shrinkWrap: true,
physics: const NeverScrollableScrollPhysics(),
data: item.content,
padding: const EdgeInsets.all(0),
).paddingOnly(left: 12, right: 8),
buildHeader(),
buildBody().paddingOnly(left: 12, right: 8),
if (widget.item.replyTo != null && widget.isShowEmbed)
GestureDetector(
child: buildReply(context).paddingOnly(top: 4),
@ -218,6 +252,7 @@ class _PostItemState extends State<PostItem> {
);
},
),
buildFooter().paddingOnly(left: 12),
],
),
)
@ -231,6 +266,7 @@ class _PostItemState extends State<PostItem> {
AttachmentList(
parentId: widget.item.alias,
attachmentsId: item.attachments ?? List.empty(),
divided: true,
),
PostQuickAction(
isShowReply: widget.isShowReply,

View File

@ -32,9 +32,7 @@ class PostListWidget extends StatelessWidget {
item: item,
isShowEmbed: isShowEmbed,
isClickable: isNestedClickable,
).paddingSymmetric(
vertical: (item.attachments?.isEmpty ?? false) ? 8 : 0,
),
).paddingSymmetric(vertical: 8),
onTap: () {
if (!isClickable) return;
AppRouter.instance.pushNamed(