From 657f36c1f83a020af8b938663b9eb5e3e43450ce Mon Sep 17 00:00:00 2001 From: LittleSheep Date: Sun, 26 May 2024 00:11:00 +0800 Subject: [PATCH] :sparkles: Channel organize --- lib/main.dart | 6 +- lib/models/channel.dart | 11 + lib/providers/content/channel.dart | 21 ++ .../content/{post_explore.dart => post.dart} | 0 lib/providers/content/realm.dart | 21 ++ lib/providers/friend.dart | 3 + lib/router.dart | 14 +- lib/screens/channel/channel_organize.dart | 292 ++++++++++++++++++ lib/screens/contact.dart | 117 ++++++- lib/screens/posts/post_detail.dart | 2 +- .../posts/{publish.dart => post_publish.dart} | 11 +- lib/screens/social.dart | 8 +- lib/services.dart | 10 +- lib/translations.dart | 22 ++ lib/widgets/account/account_avatar.dart | 3 +- lib/widgets/account/friend_select.dart | 81 +++++ lib/widgets/attachments/attachment_item.dart | 10 +- lib/widgets/attachments/attachment_list.dart | 8 +- .../attachment_list_fullscreen.dart | 13 +- lib/widgets/posts/post_action.dart | 2 +- lib/widgets/posts/post_item.dart | 18 +- lib/widgets/posts/post_replies.dart | 2 +- pubspec.lock | 8 + pubspec.yaml | 1 + 24 files changed, 650 insertions(+), 34 deletions(-) create mode 100644 lib/providers/content/channel.dart rename lib/providers/content/{post_explore.dart => post.dart} (100%) create mode 100644 lib/providers/content/realm.dart create mode 100644 lib/screens/channel/channel_organize.dart rename lib/screens/posts/{publish.dart => post_publish.dart} (97%) create mode 100644 lib/widgets/account/friend_select.dart diff --git a/lib/main.dart b/lib/main.dart index bd2fb8f..5a98b9b 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -3,7 +3,9 @@ import 'package:get/get.dart'; import 'package:solian/providers/account.dart'; import 'package:solian/providers/auth.dart'; import 'package:solian/providers/content/attachment.dart'; -import 'package:solian/providers/content/post_explore.dart'; +import 'package:solian/providers/content/channel.dart'; +import 'package:solian/providers/content/post.dart'; +import 'package:solian/providers/content/realm.dart'; import 'package:solian/providers/friend.dart'; import 'package:solian/router.dart'; import 'package:solian/theme.dart'; @@ -35,6 +37,8 @@ class SolianApp extends StatelessWidget { Get.lazyPut(() => PostProvider()); Get.lazyPut(() => AttachmentProvider()); Get.lazyPut(() => AccountProvider()); + Get.lazyPut(() => ChannelProvider()); + Get.lazyPut(() => RealmProvider()); final AuthProvider auth = Get.find(); auth.isAuthorized.then((value) async { diff --git a/lib/models/channel.dart b/lib/models/channel.dart index aa6a9e2..c6f47c4 100644 --- a/lib/models/channel.dart +++ b/lib/models/channel.dart @@ -1,3 +1,5 @@ +import 'package:flutter/material.dart'; +import 'package:font_awesome_flutter/font_awesome_flutter.dart'; import 'package:solian/models/account.dart'; class Channel { @@ -60,6 +62,15 @@ class Channel { 'realm_id': realmId, 'is_encrypted': isEncrypted, }; + + IconData get icon { + switch (type) { + case 1: + return FontAwesomeIcons.userGroup; + default: + return FontAwesomeIcons.hashtag; + } + } } class ChannelMember { diff --git a/lib/providers/content/channel.dart b/lib/providers/content/channel.dart new file mode 100644 index 0000000..4b523cc --- /dev/null +++ b/lib/providers/content/channel.dart @@ -0,0 +1,21 @@ +import 'package:get/get.dart'; +import 'package:solian/providers/auth.dart'; +import 'package:solian/services.dart'; + +class ChannelProvider extends GetxController { + Future listAvailableChannel({String realm = 'global'}) async { + final AuthProvider auth = Get.find(); + if (!await auth.isAuthorized) throw Exception('unauthorized'); + + final client = GetConnect(); + client.httpClient.baseUrl = ServiceFinder.services['messaging']; + client.httpClient.addAuthenticator(auth.requestAuthenticator); + + final resp = await client.get('/api/channels/$realm/me/available'); + if (resp.statusCode != 200) { + throw Exception(resp.bodyString); + } + + return resp; + } +} diff --git a/lib/providers/content/post_explore.dart b/lib/providers/content/post.dart similarity index 100% rename from lib/providers/content/post_explore.dart rename to lib/providers/content/post.dart diff --git a/lib/providers/content/realm.dart b/lib/providers/content/realm.dart new file mode 100644 index 0000000..694b297 --- /dev/null +++ b/lib/providers/content/realm.dart @@ -0,0 +1,21 @@ +import 'package:get/get.dart'; +import 'package:solian/providers/auth.dart'; +import 'package:solian/services.dart'; + +class RealmProvider extends GetxController { + Future listAvailableRealm() async { + final AuthProvider auth = Get.find(); + if (!await auth.isAuthorized) throw Exception('unauthorized'); + + final client = GetConnect(); + client.httpClient.baseUrl = ServiceFinder.services['passport']; + client.httpClient.addAuthenticator(auth.requestAuthenticator); + + final resp = await client.get('/realms/me/available'); + if (resp.statusCode != 200) { + throw Exception(resp.bodyString); + } + + return resp; + } +} diff --git a/lib/providers/friend.dart b/lib/providers/friend.dart index c3e0a68..2e0fcb4 100644 --- a/lib/providers/friend.dart +++ b/lib/providers/friend.dart @@ -14,6 +14,9 @@ class FriendProvider extends GetConnect { Future listFriendship() => get('/api/users/me/friends'); + Future listFriendshipWithStatus(int status) => + get('/api/users/me/friends?status=$status'); + Future createFriendship(String username) async { final resp = await post('/api/users/me/friends?related=$username', {}); if (resp.statusCode != 200) { diff --git a/lib/router.dart b/lib/router.dart index ab19ac7..e6c1bb7 100644 --- a/lib/router.dart +++ b/lib/router.dart @@ -2,10 +2,11 @@ import 'package:go_router/go_router.dart'; import 'package:solian/screens/account.dart'; import 'package:solian/screens/account/friend.dart'; import 'package:solian/screens/account/personalize.dart'; +import 'package:solian/screens/channel/channel_organize.dart'; import 'package:solian/screens/contact.dart'; import 'package:solian/screens/posts/post_detail.dart'; import 'package:solian/screens/social.dart'; -import 'package:solian/screens/posts/publish.dart'; +import 'package:solian/screens/posts/post_publish.dart'; import 'package:solian/shells/basic_shell.dart'; import 'package:solian/shells/nav_shell.dart'; @@ -75,6 +76,17 @@ abstract class AppRouter { ); }, ), + GoRoute( + path: '/chat/organize', + name: 'channelOrganizing', + builder: (context, state) { + final arguments = state.extra as ChannelOrganizeArguments?; + return ChannelOrganizeScreen( + edit: arguments?.edit, + realm: state.uri.queryParameters['realm'], + ); + }, + ), ], ); } diff --git a/lib/screens/channel/channel_organize.dart b/lib/screens/channel/channel_organize.dart new file mode 100644 index 0000000..49e8f48 --- /dev/null +++ b/lib/screens/channel/channel_organize.dart @@ -0,0 +1,292 @@ +import 'package:dropdown_button2/dropdown_button2.dart'; +import 'package:flutter/material.dart'; +import 'package:flutter_animate/flutter_animate.dart'; +import 'package:get/get.dart'; +import 'package:solian/exts.dart'; +import 'package:solian/models/account.dart'; +import 'package:solian/models/channel.dart'; +import 'package:solian/providers/auth.dart'; +import 'package:solian/router.dart'; +import 'package:solian/services.dart'; +import 'package:solian/widgets/account/friend_select.dart'; +import 'package:solian/widgets/prev_page.dart'; +import 'package:uuid/uuid.dart'; + +class ChannelOrganizeArguments { + final Channel? edit; + + ChannelOrganizeArguments({this.edit}); +} + +class ChannelOrganizeScreen extends StatefulWidget { + final Channel? edit; + final String? realm; + + const ChannelOrganizeScreen({super.key, this.edit, this.realm}); + + @override + State createState() => _ChannelOrganizeScreenState(); +} + +class _ChannelOrganizeScreenState extends State { + static Map channelTypes = { + 0: 'channelTypeCommon'.tr, + 1: 'channelTypeDirect'.tr, + }; + + bool _isBusy = false; + + final _aliasController = TextEditingController(); + final _nameController = TextEditingController(); + final _descriptionController = TextEditingController(); + + bool _isEncrypted = false; + int _channelType = 0; + + List _initialMembers = List.empty(growable: true); + + void selectInitialMembers() async { + final input = await showModalBottomSheet( + useRootNavigator: true, + isScrollControlled: true, + context: context, + builder: (context) => FriendSelect( + title: 'channelMember'.tr, + trailingBuilder: (item) { + if (_initialMembers.any((e) => e.id == item.id)) { + return const Icon(Icons.check); + } else { + return null; + } + }, + ), + ); + if (input == null) return; + + setState(() { + if (_initialMembers.any((e) => e.id == input.id)) { + _initialMembers = _initialMembers + .where((e) => e.id != input.id) + .toList(growable: true); + } else { + _initialMembers.add(input as Account); + } + }); + } + + void applyChannel() async { + final AuthProvider auth = Get.find(); + if (!await auth.isAuthorized) return; + + if (_aliasController.value.text.isEmpty) randomizeAlias(); + + setState(() => _isBusy = true); + + final client = GetConnect(); + client.httpClient.baseUrl = ServiceFinder.services['messaging']; + client.httpClient.addAuthenticator(auth.requestAuthenticator); + + final scope = (widget.realm?.isNotEmpty ?? false) ? widget.realm : 'global'; + final payload = { + 'alias': _aliasController.value.text.toLowerCase(), + 'name': _nameController.value.text, + 'description': _descriptionController.value.text, + 'is_encrypted': _isEncrypted, + if (_channelType == 1) + 'members': _initialMembers.map((e) => e.id).toList(), + }; + + Response resp; + if (widget.edit != null) { + resp = await client.put( + '/api/channels/$scope/${widget.edit!.id}', + payload, + ); + } else if (_channelType == 1) { + resp = await client.post('/api/channels/$scope/dm', payload); + } else { + resp = await client.post('/api/channels/$scope', payload); + } + if (resp.statusCode != 200) { + context.showErrorDialog(resp.bodyString); + } else { + AppRouter.instance.pop(resp.body); + } + + setState(() => _isBusy = false); + } + + void randomizeAlias() { + _aliasController.text = + const Uuid().v4().replaceAll('-', '').substring(0, 12); + } + + void syncWidget() { + if (widget.edit != null) { + _aliasController.text = widget.edit!.alias; + _nameController.text = widget.edit!.name; + _descriptionController.text = widget.edit!.description; + _isEncrypted = widget.edit!.isEncrypted; + _channelType = widget.edit!.type; + } + } + + void cancelAction() { + AppRouter.instance.pop(); + } + + @override + void initState() { + syncWidget(); + super.initState(); + } + + @override + Widget build(BuildContext context) { + return Material( + color: Theme.of(context).colorScheme.surface, + child: Scaffold( + appBar: AppBar( + title: Text('channelOrganizing'.tr), + leading: const PrevPageButton(), + actions: [ + TextButton( + onPressed: _isBusy ? null : () => applyChannel(), + child: Text('apply'.tr.toUpperCase()), + ) + ], + ), + body: SafeArea( + top: false, + child: Column( + children: [ + if (_isBusy) const LinearProgressIndicator().animate().scaleX(), + if (widget.edit != null) + MaterialBanner( + leading: const Icon(Icons.edit), + leadingPadding: const EdgeInsets.only(left: 10, right: 20), + dividerColor: Colors.transparent, + content: Text( + 'channelEditingNotify' + .trParams({'channel': '#${widget.edit!.alias}'}), + ), + actions: [ + TextButton( + onPressed: cancelAction, + child: Text('cancel'.tr), + ), + ], + ), + Row( + children: [ + Expanded( + child: TextField( + autofocus: true, + controller: _aliasController, + decoration: InputDecoration.collapsed( + hintText: 'channelAlias'.tr, + ), + onTapOutside: (_) => + FocusManager.instance.primaryFocus?.unfocus(), + ), + ), + TextButton( + style: TextButton.styleFrom( + shape: const CircleBorder(), + visualDensity: + const VisualDensity(horizontal: -2, vertical: -2), + ), + onPressed: () => randomizeAlias(), + child: const Icon(Icons.refresh), + ) + ], + ).paddingSymmetric(horizontal: 16, vertical: 2), + const Divider(thickness: 0.3), + TextField( + autocorrect: true, + controller: _nameController, + decoration: InputDecoration.collapsed( + hintText: 'channelName'.tr, + ), + onTapOutside: (_) => + FocusManager.instance.primaryFocus?.unfocus(), + ).paddingSymmetric(horizontal: 16, vertical: 8), + const Divider(thickness: 0.3), + Expanded( + child: TextField( + minLines: 5, + maxLines: null, + autocorrect: true, + keyboardType: TextInputType.multiline, + controller: _descriptionController, + decoration: InputDecoration.collapsed( + hintText: 'channelDescription'.tr, + ), + onTapOutside: (_) => + FocusManager.instance.primaryFocus?.unfocus(), + ).paddingSymmetric(horizontal: 16, vertical: 12), + ), + const Divider(thickness: 0.3), + if (_channelType == 1) + ListTile( + leading: const Icon(Icons.supervisor_account) + .paddingSymmetric(horizontal: 8), + title: Text('channelMember'.tr), + subtitle: _initialMembers.isNotEmpty + ? Text(_initialMembers.map((e) => e.name).join(' ')) + : null, + trailing: const Icon(Icons.chevron_right), + onTap: () => selectInitialMembers(), + ).animate().fadeIn().slideY( + begin: 1, + end: 0, + curve: Curves.fastEaseInToSlowEaseOut, + ), + ListTile( + leading: const Icon(Icons.mode).paddingSymmetric(horizontal: 8), + title: Text('channelType'.tr), + trailing: DropdownButtonHideUnderline( + child: DropdownButton2( + isExpanded: true, + items: channelTypes.entries + .map((item) => DropdownMenuItem( + value: item.key, + child: Text( + item.value, + style: const TextStyle( + fontSize: 14, + ), + ), + )) + .toList(), + value: _channelType, + onChanged: (int? value) { + setState(() => _channelType = value ?? 0); + }, + buttonStyleData: const ButtonStyleData( + padding: EdgeInsets.only(left: 16, right: 1), + height: 40, + width: 140, + ), + menuItemStyleData: const MenuItemStyleData( + height: 40, + ), + ), + ), + ), + CheckboxListTile( + title: Text('channelEncrypted'.tr), + value: _isEncrypted, + onChanged: (widget.edit?.isEncrypted ?? false) + ? null + : (newValue) => + setState(() => _isEncrypted = newValue ?? false), + controlAffinity: ListTileControlAffinity.leading, + ), + ], + ), + ), + ), + ); + } +} diff --git a/lib/screens/contact.dart b/lib/screens/contact.dart index 6d73f89..978e380 100644 --- a/lib/screens/contact.dart +++ b/lib/screens/contact.dart @@ -1,12 +1,127 @@ import 'package:flutter/material.dart'; +import 'package:flutter_animate/flutter_animate.dart'; +import 'package:font_awesome_flutter/font_awesome_flutter.dart'; +import 'package:get/get.dart'; +import 'package:solian/models/channel.dart'; +import 'package:solian/providers/auth.dart'; +import 'package:solian/providers/content/channel.dart'; +import 'package:solian/router.dart'; +import 'package:solian/screens/account/notification.dart'; +import 'package:solian/theme.dart'; -class ContactScreen extends StatelessWidget { +class ContactScreen extends StatefulWidget { const ContactScreen({super.key}); + @override + State createState() => _ContactScreenState(); +} + +class _ContactScreenState extends State { + bool _isBusy = true; + + final List _channels = List.empty(growable: true); + + getChannels() async { + setState(() => _isBusy = true); + + final ChannelProvider provider = Get.find(); + final resp = await provider.listAvailableChannel(); + + setState(() { + _channels.clear(); + _channels.addAll( + resp.body.map((e) => Channel.fromJson(e)).toList().cast(), + ); + }); + + setState(() => _isBusy = false); + } + + @override + void initState() { + super.initState(); + + getChannels(); + } + @override Widget build(BuildContext context) { + final AuthProvider auth = Get.find(); + + // TODO Un signed in tip + return Material( color: Theme.of(context).colorScheme.surface, + child: SafeArea( + child: NestedScrollView( + headerSliverBuilder: (context, innerBoxIsScrolled) { + return [ + SliverOverlapAbsorber( + handle: + NestedScrollView.sliverOverlapAbsorberHandleFor(context), + sliver: SliverAppBar( + title: Text('contact'.tr), + centerTitle: false, + titleSpacing: SolianTheme.isLargeScreen(context) ? null : 24, + forceElevated: innerBoxIsScrolled, + actions: [ + const NotificationButton(), + IconButton( + icon: const Icon(Icons.add_circle), + onPressed: () { + AppRouter.instance.pushNamed('channelOrganizing').then( + (value) { + if (value != null) { + getChannels(); + } + }, + ); + }, + ), + if (!SolianTheme.isLargeScreen(context)) + const SizedBox(width: 16), + ], + ), + ), + ]; + }, + body: MediaQuery.removePadding( + removeTop: true, + context: context, + child: Column( + children: [ + if (_isBusy) const LinearProgressIndicator().animate().scaleX(), + Expanded( + child: RefreshIndicator( + onRefresh: () => getChannels(), + child: ListView.builder( + itemCount: _channels.length, + itemBuilder: (context, index) { + final element = _channels[index]; + return ListTile( + leading: CircleAvatar( + backgroundColor: Colors.indigo, + child: FaIcon( + element.icon, + color: Colors.white, + size: 16, + ), + ), + contentPadding: + const EdgeInsets.symmetric(horizontal: 24), + title: Text(element.name), + subtitle: Text(element.description), + onTap: () {}, + ); + }, + ), + ), + ), + ], + ), + ), + ), + ), ); } } diff --git a/lib/screens/posts/post_detail.dart b/lib/screens/posts/post_detail.dart index c2f289a..615e471 100644 --- a/lib/screens/posts/post_detail.dart +++ b/lib/screens/posts/post_detail.dart @@ -2,7 +2,7 @@ import 'package:flutter/material.dart'; import 'package:get/get.dart'; import 'package:solian/exts.dart'; import 'package:solian/models/post.dart'; -import 'package:solian/providers/content/post_explore.dart'; +import 'package:solian/providers/content/post.dart'; import 'package:solian/widgets/posts/post_item.dart'; import 'package:solian/widgets/posts/post_replies.dart'; diff --git a/lib/screens/posts/publish.dart b/lib/screens/posts/post_publish.dart similarity index 97% rename from lib/screens/posts/publish.dart rename to lib/screens/posts/post_publish.dart index e40a5eb..5fc4d4a 100644 --- a/lib/screens/posts/publish.dart +++ b/lib/screens/posts/post_publish.dart @@ -41,7 +41,7 @@ class PostPublishingScreen extends StatefulWidget { class _PostPublishingScreenState extends State { final _contentController = TextEditingController(); - bool _isSubmitting = false; + bool _isBusy = false; List _attachments = List.empty(); @@ -61,7 +61,7 @@ class _PostPublishingScreenState extends State { if (!await auth.isAuthorized) return; if (_contentController.value.text.isEmpty) return; - setState(() => _isSubmitting = true); + setState(() => _isBusy = true); final client = GetConnect(); client.httpClient.baseUrl = ServiceFinder.services['interactive']; @@ -87,7 +87,7 @@ class _PostPublishingScreenState extends State { AppRouter.instance.pop(resp.body); } - setState(() => _isSubmitting = false); + setState(() => _isBusy = false); } void syncWidget() { @@ -126,8 +126,8 @@ class _PostPublishingScreenState extends State { leading: const PrevPageButton(), actions: [ TextButton( + onPressed: _isBusy ? null : () => applyPost(), child: Text('postAction'.tr.toUpperCase()), - onPressed: () => applyPost(), ) ], ), @@ -135,8 +135,7 @@ class _PostPublishingScreenState extends State { top: false, child: Column( children: [ - if (_isSubmitting) - const LinearProgressIndicator().animate().scaleX(), + if (_isBusy) const LinearProgressIndicator().animate().scaleX(), if (widget.edit != null) MaterialBanner( leading: const Icon(Icons.edit), diff --git a/lib/screens/social.dart b/lib/screens/social.dart index 923579f..3c02f75 100644 --- a/lib/screens/social.dart +++ b/lib/screens/social.dart @@ -4,7 +4,7 @@ import 'package:infinite_scroll_pagination/infinite_scroll_pagination.dart'; import 'package:solian/models/pagination.dart'; import 'package:solian/models/post.dart'; import 'package:solian/providers/auth.dart'; -import 'package:solian/providers/content/post_explore.dart'; +import 'package:solian/providers/content/post.dart'; import 'package:solian/router.dart'; import 'package:solian/screens/account/notification.dart'; import 'package:solian/theme.dart'; @@ -85,8 +85,10 @@ class _SocialScreenState extends State { titleSpacing: SolianTheme.isLargeScreen(context) ? null : 24, forceElevated: innerBoxIsScrolled, - actions: const [ - NotificationButton(), + actions: [ + const NotificationButton(), + if (!SolianTheme.isLargeScreen(context)) + const SizedBox(width: 16), ], ), ), diff --git a/lib/services.dart b/lib/services.dart index 27fda5a..e09f093 100644 --- a/lib/services.dart +++ b/lib/services.dart @@ -2,9 +2,11 @@ abstract class ServiceFinder { static const bool devFlag = true; static Map services = { - 'paperclip': devFlag ? 'http://localhost:8443' : 'https://usercontent.solsynth.dev', + 'paperclip': + devFlag ? 'http://localhost:8443' : 'https://usercontent.solsynth.dev', 'passport': devFlag ? 'http://localhost:8444' : 'https://id.solsynth.dev', - 'interactive': devFlag ? 'http://localhost:8445' : 'https://co.solsynth.dev', - 'messaging': devFlag ? 'http://localhost:8446' : 'https://im.solsynth.dev', + 'interactive': + devFlag ? 'http://localhost:8445' : 'https://co.solsynth.dev', + 'messaging': devFlag ? 'http://localhost:8447' : 'https://im.solsynth.dev', }; -} \ No newline at end of file +} diff --git a/lib/translations.dart b/lib/translations.dart index 4ba95e9..1378fb6 100644 --- a/lib/translations.dart +++ b/lib/translations.dart @@ -16,6 +16,7 @@ class SolianMessages extends Translations { 'confirm': 'Confirm', 'edit': 'Edit', 'delete': 'Delete', + 'search': 'Search', 'reply': 'Reply', 'repost': 'Repost', 'notification': 'Notification', @@ -89,6 +90,16 @@ class SolianMessages extends Translations { 'attachmentAddFile': 'Attach file', 'attachmentSetting': 'Adjust attachment', 'attachmentAlt': 'Alternative text', + 'channelOrganizing': 'Organize a channel', + 'channelEditingNotify': 'You\'re editing channel @channel', + 'channelAlias': 'Alias (Identifier)', + 'channelName': 'Name', + 'channelDescription': 'Description', + 'channelEncrypted': 'Encrypted Channel', + 'channelMember': 'Channel member', + 'channelType': 'Channel type', + 'channelTypeCommon': 'Regular', + 'channelTypeDirect': 'DM', }, 'zh_CN': { 'hide': '隐藏', @@ -103,6 +114,7 @@ class SolianMessages extends Translations { 'social': '社交', 'contact': '联系', 'apply': '应用', + 'search': '搜索', 'reply': '回复', 'repost': '转帖', 'notification': '通知', @@ -169,6 +181,16 @@ class SolianMessages extends Translations { 'attachmentAddFile': '附加文件', 'attachmentSetting': '调整附件', 'attachmentAlt': '替代文字', + 'channelOrganizing': '组织频道', + 'channelEditingNotify': '你正在编辑频道 @channel', + 'channelAlias': '别称(标识符)', + 'channelName': '显示名称', + 'channelDescription': '频道简介', + 'channelEncrypted': '加密频道', + 'channelMember': '频道成员', + 'channelType': '频道类型', + 'channelTypeCommon': '普通频道', + 'channelTypeDirect': '私信聊天', } }; } diff --git a/lib/widgets/account/account_avatar.dart b/lib/widgets/account/account_avatar.dart index f781af1..a273c34 100644 --- a/lib/widgets/account/account_avatar.dart +++ b/lib/widgets/account/account_avatar.dart @@ -15,7 +15,8 @@ class AccountAvatar extends StatelessWidget { bool isEmpty = content == null; if (content is String) { direct = content.startsWith('http'); - isEmpty = content.endsWith('/api/attachments/0'); + if (!isEmpty) isEmpty = content.isEmpty; + if (!isEmpty) isEmpty = content.endsWith('/api/attachments/0'); } return CircleAvatar( diff --git a/lib/widgets/account/friend_select.dart b/lib/widgets/account/friend_select.dart new file mode 100644 index 0000000..75b58ee --- /dev/null +++ b/lib/widgets/account/friend_select.dart @@ -0,0 +1,81 @@ +import 'package:flutter/material.dart'; +import 'package:get/get.dart'; +import 'package:solian/models/account.dart'; +import 'package:solian/models/friendship.dart'; +import 'package:solian/providers/auth.dart'; +import 'package:solian/providers/friend.dart'; +import 'package:solian/widgets/account/account_avatar.dart'; + +class FriendSelect extends StatefulWidget { + final String title; + final Widget? Function(Account item)? trailingBuilder; + + const FriendSelect({super.key, required this.title, this.trailingBuilder}); + + @override + State createState() => _FriendSelectState(); +} + +class _FriendSelectState extends State { + int _accountId = 0; + + List _friends = List.empty(growable: true); + + getFriends() async { + final AuthProvider auth = Get.find(); + final prof = await auth.getProfile(); + _accountId = prof.body['id']; + + final FriendProvider provider = Get.find(); + final resp = await provider.listFriendshipWithStatus(1); + + setState(() { + _friends.addAll(resp.body + .map((e) => Friendship.fromJson(e)) + .toList() + .cast()); + }); + } + + @override + void initState() { + super.initState(); + + getFriends(); + } + + @override + Widget build(BuildContext context) { + return SizedBox( + height: MediaQuery.of(context).size.height * 0.85, + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Text( + widget.title, + style: Theme.of(context).textTheme.headlineSmall, + ).paddingOnly(left: 24, right: 24, top: 32, bottom: 16), + Expanded( + child: ListView.builder( + itemCount: _friends.length, + itemBuilder: (context, index) { + var element = _friends[index].getOtherside(_accountId); + return ListTile( + title: Text(element.nick), + subtitle: Text(element.name), + leading: AccountAvatar(content: element.avatar), + trailing: widget.trailingBuilder != null + ? widget.trailingBuilder!(element) + : null, + onTap: () { + Navigator.pop(context, element); + }, + ); + }, + ), + ), + ], + ), + ); + } +} diff --git a/lib/widgets/attachments/attachment_item.dart b/lib/widgets/attachments/attachment_item.dart index 5539f6b..f624fe8 100644 --- a/lib/widgets/attachments/attachment_item.dart +++ b/lib/widgets/attachments/attachment_item.dart @@ -4,6 +4,7 @@ import 'package:solian/models/attachment.dart'; import 'package:solian/services.dart'; class AttachmentItem extends StatelessWidget { + final String parentId; final Attachment item; final bool showBadge; final bool showHideButton; @@ -13,6 +14,7 @@ class AttachmentItem extends StatelessWidget { const AttachmentItem({ super.key, + required this.parentId, required this.item, this.badge, this.fit = BoxFit.cover, @@ -24,7 +26,7 @@ class AttachmentItem extends StatelessWidget { @override Widget build(BuildContext context) { return Hero( - tag: Key('a${item.uuid}'), + tag: Key('a${item.uuid}p$parentId'), child: Stack( fit: StackFit.expand, children: [ @@ -48,8 +50,10 @@ class AttachmentItem extends StatelessWidget { child: Material( color: Colors.transparent, child: ActionChip( - visualDensity: const VisualDensity(vertical: -4, horizontal: -4), - avatar: Icon(Icons.visibility_off, color: Theme.of(context).colorScheme.onSurfaceVariant), + visualDensity: + const VisualDensity(vertical: -4, horizontal: -4), + avatar: Icon(Icons.visibility_off, + color: Theme.of(context).colorScheme.onSurfaceVariant), label: Text('hide'.tr), onPressed: () { if (onHide != null) onHide!(); diff --git a/lib/widgets/attachments/attachment_list.dart b/lib/widgets/attachments/attachment_list.dart index a4359b1..5cb25c9 100644 --- a/lib/widgets/attachments/attachment_list.dart +++ b/lib/widgets/attachments/attachment_list.dart @@ -9,9 +9,11 @@ import 'package:solian/providers/content/attachment.dart'; import 'package:solian/widgets/attachments/attachment_list_fullscreen.dart'; class AttachmentList extends StatefulWidget { + final String parentId; final List attachmentsId; - const AttachmentList({super.key, required this.attachmentsId}); + const AttachmentList( + {super.key, required this.parentId, required this.attachmentsId}); @override State createState() => _AttachmentListState(); @@ -126,6 +128,7 @@ class _AttachmentListState extends State { fit: StackFit.expand, children: [ AttachmentItem( + parentId: widget.parentId, key: Key('a${element!.uuid}'), item: element, badge: _attachmentsMeta.length > 1 @@ -180,7 +183,8 @@ class _AttachmentListState extends State { } else { Navigator.of(context, rootNavigator: true).push( MaterialPageRoute( - builder: (context) => AttachmentListFullscreen( + builder: (context) => AttachmentListFullScreen( + parentId: widget.parentId, attachment: element, ), ), diff --git a/lib/widgets/attachments/attachment_list_fullscreen.dart b/lib/widgets/attachments/attachment_list_fullscreen.dart index 65a333f..1f2d164 100644 --- a/lib/widgets/attachments/attachment_list_fullscreen.dart +++ b/lib/widgets/attachments/attachment_list_fullscreen.dart @@ -2,17 +2,19 @@ import 'package:flutter/material.dart'; import 'package:solian/models/attachment.dart'; import 'package:solian/widgets/attachments/attachment_item.dart'; -class AttachmentListFullscreen extends StatefulWidget { +class AttachmentListFullScreen extends StatefulWidget { + final String parentId; final Attachment attachment; - const AttachmentListFullscreen({super.key, required this.attachment}); + const AttachmentListFullScreen( + {super.key, required this.parentId, required this.attachment}); @override - State createState() => - _AttachmentListFullscreenState(); + State createState() => + _AttachmentListFullScreenState(); } -class _AttachmentListFullscreenState extends State { +class _AttachmentListFullScreenState extends State { @override void initState() { super.initState(); @@ -33,6 +35,7 @@ class _AttachmentListFullscreenState extends State { panEnabled: true, scaleEnabled: true, child: AttachmentItem( + parentId: widget.parentId, showHideButton: false, item: widget.attachment, fit: BoxFit.contain, diff --git a/lib/widgets/posts/post_action.dart b/lib/widgets/posts/post_action.dart index 2916cba..6c4821b 100644 --- a/lib/widgets/posts/post_action.dart +++ b/lib/widgets/posts/post_action.dart @@ -8,7 +8,7 @@ import 'package:solian/exts.dart'; import 'package:solian/models/post.dart'; import 'package:solian/providers/auth.dart'; import 'package:solian/router.dart'; -import 'package:solian/screens/posts/publish.dart'; +import 'package:solian/screens/posts/post_publish.dart'; import 'package:solian/services.dart'; class PostAction extends StatefulWidget { diff --git a/lib/widgets/posts/post_item.dart b/lib/widgets/posts/post_item.dart index 05aebd7..5c1a99d 100644 --- a/lib/widgets/posts/post_item.dart +++ b/lib/widgets/posts/post_item.dart @@ -17,6 +17,7 @@ class PostItem extends StatefulWidget { final bool isReactable; final bool isShowReply; final bool isShowEmbed; + final String? overrideAttachmentParent; const PostItem({ super.key, @@ -26,6 +27,7 @@ class PostItem extends StatefulWidget { this.isReactable = true, this.isShowReply = true, this.isShowEmbed = true, + this.overrideAttachmentParent, }); @override @@ -53,7 +55,7 @@ class _PostItemState extends State { ), Text( 'postRepliedNotify'.trParams( - {'username': '@${widget.item.author.name}'}, + {'username': '@${widget.item.replyTo!.author.name}'}, ), style: TextStyle( color: @@ -67,6 +69,7 @@ class _PostItemState extends State { child: PostItem( item: widget.item.replyTo!, isCompact: true, + overrideAttachmentParent: widget.item.alias, ).paddingSymmetric(vertical: 8), ), ], @@ -85,7 +88,7 @@ class _PostItemState extends State { ), Text( 'postRepostedNotify'.trParams( - {'username': '@${widget.item.author.name}'}, + {'username': '@${widget.item.repostTo!.author.name}'}, ), style: TextStyle( color: @@ -99,6 +102,7 @@ class _PostItemState extends State { child: PostItem( item: widget.item.repostTo!, isCompact: true, + overrideAttachmentParent: widget.item.alias, ).paddingSymmetric(vertical: 8), ), ], @@ -134,7 +138,10 @@ class _PostItemState extends State { top: 2, bottom: hasAttachment ? 4 : 0, ), - AttachmentList(attachmentsId: item.attachments ?? List.empty()), + AttachmentList( + parentId: widget.overrideAttachmentParent ?? widget.item.alias, + attachmentsId: item.attachments ?? List.empty(), + ), ], ); } @@ -200,7 +207,10 @@ class _PostItemState extends State { right: 16, left: 16, ), - AttachmentList(attachmentsId: item.attachments ?? List.empty()), + AttachmentList( + parentId: widget.item.alias, + attachmentsId: item.attachments ?? List.empty(), + ), PostQuickAction( isShowReply: widget.isShowReply, isReactable: widget.isReactable, diff --git a/lib/widgets/posts/post_replies.dart b/lib/widgets/posts/post_replies.dart index 5499ce8..c3a67a2 100644 --- a/lib/widgets/posts/post_replies.dart +++ b/lib/widgets/posts/post_replies.dart @@ -3,7 +3,7 @@ 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/providers/content/post_explore.dart'; +import 'package:solian/providers/content/post.dart'; import 'package:solian/widgets/posts/post_list.dart'; class PostReplyList extends StatefulWidget { diff --git a/pubspec.lock b/pubspec.lock index a196265..fbe7423 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -97,6 +97,14 @@ packages: url: "https://pub.dev" source: hosted version: "0.7.10" + dropdown_button2: + dependency: "direct main" + description: + name: dropdown_button2 + sha256: b0fe8d49a030315e9eef6c7ac84ca964250155a6224d491c1365061bc974a9e1 + url: "https://pub.dev" + source: hosted + version: "2.3.9" fake_async: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index 5fb3b59..e73d5ae 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -56,6 +56,7 @@ dependencies: flutter_local_notifications: ^17.1.2 permission_handler: ^11.3.1 uuid: ^4.4.0 + dropdown_button2: ^2.3.9 dev_dependencies: flutter_test: