diff --git a/assets/translations/en.json b/assets/translations/en.json index 53f1827..aa5d199 100644 --- a/assets/translations/en.json +++ b/assets/translations/en.json @@ -64,6 +64,13 @@ "one": "{} character", "other": "{} characters" }, + "postVisibility": "Visibility", + "postVisibilityDescription": "Post visibility determines who can see this post.", + "postVisibilityAll": "Everyone", + "postVisibilityFriends": "Friends", + "postVisibilitySelected": "Selected User", + "postVisibilityFiltered": "Unselected User", + "postVisibilityNone": "Only Me", "fieldUsername": "Username", "fieldNickname": "Nickname", "fieldEmail": "Email address", diff --git a/assets/translations/zh.json b/assets/translations/zh.json index f13acc4..020dd02 100644 --- a/assets/translations/zh.json +++ b/assets/translations/zh.json @@ -121,6 +121,13 @@ "postPublish": "发布", "postPublishedAt": "发布于", "postPublishedUntil": "取消发布于", + "postVisibility": "可见性", + "postVisibilityDescription": "帖子可见性决定了谁能查看该篇帖子。", + "postVisibilityAll": "所有人可见", + "postVisibilityFriends": "仅限好友可见", + "postVisibilitySelected": "选定的用户可见", + "postVisibilityFiltered": "选定用户不可见", + "postVisibilityNone": "仅自己可见", "postEditingNotice": "你正在修改由 {} 发布的帖子。", "postReplyingNotice": "你正在回复由 {} 发布的帖子。", "postRepostingNotice": "你正在转发由 {} 发布的帖子。", diff --git a/lib/controllers/post_write_controller.dart b/lib/controllers/post_write_controller.dart index 818889a..8e1b0ae 100644 --- a/lib/controllers/post_write_controller.dart +++ b/lib/controllers/post_write_controller.dart @@ -172,6 +172,7 @@ class PostWriteController extends ChangeNotifier { SnPublisher? publisher; SnPost? editingPost, repostingPost, replyingPost; + int visibility = 0; List tags = List.empty(); List attachments = List.empty(growable: true); DateTime? publishedAt, publishedUntil; @@ -196,6 +197,7 @@ class PostWriteController extends ChangeNotifier { contentController.text = post.body['content'] ?? ''; publishedAt = post.publishedAt; publishedUntil = post.publishedUntil; + visibility = post.visibility; tags = List.from(post.tags.map((ele) => ele.alias)); attachments.addAll( post.preload?.attachments?.map((ele) => PostWriteMedia(ele)) ?? [], @@ -293,6 +295,7 @@ class PostWriteController extends ChangeNotifier { .map((e) => e.attachment!.rid) .toList(), 'tags': tags.map((ele) => {'alias': ele}).toList(), + 'visibility': visibility, if (publishedAt != null) 'published_at': publishedAt!.toUtc().toIso8601String(), if (publishedUntil != null) @@ -359,6 +362,11 @@ class PostWriteController extends ChangeNotifier { notifyListeners(); } + void setVisibility(int value) { + visibility = value; + notifyListeners(); + } + void setIsBusy(bool value) { isBusy = value; notifyListeners(); diff --git a/lib/widgets/post/post_meta_editor.dart b/lib/widgets/post/post_meta_editor.dart index 602635f..490f7fc 100644 --- a/lib/widgets/post/post_meta_editor.dart +++ b/lib/widgets/post/post_meta_editor.dart @@ -1,3 +1,4 @@ +import 'package:dropdown_button2/dropdown_button2.dart'; import 'package:easy_localization/easy_localization.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; @@ -11,6 +12,14 @@ class PostMetaEditor extends StatelessWidget { final PostWriteController controller; const PostMetaEditor({super.key, required this.controller}); + static Map kPostVisibilityLevel = { + 0: 'postVisibilityAll', + 1: 'postVisibilityFriends', + 2: 'postVisibilitySelected', + 3: 'postVisibilityFiltered', + 4: 'postVisibilityNone', + }; + Future _selectDate( BuildContext context, { DateTime? initialDateTime, @@ -79,6 +88,45 @@ class PostMetaEditor extends StatelessWidget { }, ).padding(horizontal: 24), const Gap(12), + ListTile( + contentPadding: const EdgeInsets.symmetric(horizontal: 24), + leading: const Icon(Symbols.visibility), + title: Text('postVisibility').tr(), + subtitle: Text('postVisibilityDescription').tr(), + trailing: SizedBox( + width: 180, + child: DropdownButtonHideUnderline( + child: DropdownButton2( + isExpanded: true, + items: kPostVisibilityLevel.entries + .map( + (entry) => DropdownMenuItem( + value: entry.key, + child: Text( + entry.value, + style: const TextStyle(fontSize: 14), + ).tr(), + ), + ) + .toList(), + value: controller.visibility, + onChanged: (int? value) { + if (value != null) { + controller.setVisibility(value); + } + }, + buttonStyleData: const ButtonStyleData( + height: 40, + padding: EdgeInsets.symmetric( + horizontal: 4, + vertical: 8, + ), + ), + menuItemStyleData: const MenuItemStyleData(height: 40), + ), + ), + ), + ), ListTile( leading: const Icon(Symbols.event_available), title: Text('postPublishedAt').tr(),