From c9fbe473374bf2f711ae02c2c9978dc0ed556cf5 Mon Sep 17 00:00:00 2001 From: LittleSheep Date: Tue, 17 Sep 2024 13:50:04 +0800 Subject: [PATCH] :sparkles: Channel isPublic and isCommunity --- assets/locales/en_us.json | 3 +- assets/locales/zh_cn.json | 3 +- lib/models/channel.dart | 6 ++-- lib/models/channel.g.dart | 6 ++-- lib/screens/channel/channel_organize.dart | 43 +++++++++++++---------- 5 files changed, 37 insertions(+), 24 deletions(-) diff --git a/assets/locales/en_us.json b/assets/locales/en_us.json index 196cb82..7195ce5 100644 --- a/assets/locales/en_us.json +++ b/assets/locales/en_us.json @@ -253,7 +253,8 @@ "channelName": "Name", "channelDescription": "Description", "channelDirectDescription": "Direct message with @username", - "channelEncrypted": "Encrypted Channel", + "channelPublic": "Public channel", + "channelCommunity": "Community channel", "channelMember": "Channel member", "channelMembers": "Channel members", "channelMembersAdd": "Add channel members", diff --git a/assets/locales/zh_cn.json b/assets/locales/zh_cn.json index a349c30..844f8ec 100644 --- a/assets/locales/zh_cn.json +++ b/assets/locales/zh_cn.json @@ -254,7 +254,8 @@ "channelName": "显示名称", "channelDescription": "频道简介", "channelDirectDescription": "与 @username 的私聊", - "channelEncrypted": "加密频道", + "channelPublic": "公开频道", + "channelCommunity": "社区频道", "channelMember": "频道成员", "channelMembers": "频道成员", "channelMembersAdd": "添加频道成员", diff --git a/lib/models/channel.dart b/lib/models/channel.dart index 91ba7ba..d16d692 100644 --- a/lib/models/channel.dart +++ b/lib/models/channel.dart @@ -19,7 +19,8 @@ class Channel { int accountId; Realm? realm; int? realmId; - bool isEncrypted; + bool isPublic; + bool isCommunity; @JsonKey(includeFromJson: false, includeToJson: true) bool isAvailable = false; @@ -36,7 +37,8 @@ class Channel { required this.members, required this.account, required this.accountId, - required this.isEncrypted, + required this.isPublic, + required this.isCommunity, required this.realm, required this.realmId, }); diff --git a/lib/models/channel.g.dart b/lib/models/channel.g.dart index 8bc0cb4..bc998f4 100644 --- a/lib/models/channel.g.dart +++ b/lib/models/channel.g.dart @@ -22,7 +22,8 @@ Channel _$ChannelFromJson(Map json) => Channel( .toList(), account: Account.fromJson(json['account'] as Map), accountId: (json['account_id'] as num).toInt(), - isEncrypted: json['is_encrypted'] as bool, + isPublic: json['is_public'] as bool, + isCommunity: json['is_community'] as bool, realm: json['realm'] == null ? null : Realm.fromJson(json['realm'] as Map), @@ -43,7 +44,8 @@ Map _$ChannelToJson(Channel instance) => { 'account_id': instance.accountId, 'realm': instance.realm?.toJson(), 'realm_id': instance.realmId, - 'is_encrypted': instance.isEncrypted, + 'is_public': instance.isPublic, + 'is_community': instance.isCommunity, 'is_available': instance.isAvailable, }; diff --git a/lib/screens/channel/channel_organize.dart b/lib/screens/channel/channel_organize.dart index d0c7a26..36263be 100644 --- a/lib/screens/channel/channel_organize.dart +++ b/lib/screens/channel/channel_organize.dart @@ -35,13 +35,14 @@ class _ChannelOrganizeScreenState extends State { final _nameController = TextEditingController(); final _descriptionController = TextEditingController(); - bool _isEncrypted = false; + bool _isPublic = false; + bool _isCommunity = false; - void applyChannel() async { + void _applyChannel() async { final AuthProvider auth = Get.find(); if (auth.isAuthorized.isFalse) return; - if (_aliasController.value.text.isEmpty) randomizeAlias(); + if (_aliasController.value.text.isEmpty) _randomizeAlias(); setState(() => _isBusy = true); @@ -52,7 +53,7 @@ class _ChannelOrganizeScreenState extends State { 'alias': _aliasController.value.text.toLowerCase(), 'name': _nameController.value.text, 'description': _descriptionController.value.text, - 'is_encrypted': _isEncrypted, + 'is_encrypted': _isPublic, }; Response? resp; @@ -71,27 +72,28 @@ class _ChannelOrganizeScreenState extends State { setState(() => _isBusy = false); } - void randomizeAlias() { + void _randomizeAlias() { _aliasController.text = const Uuid().v4().replaceAll('-', '').substring(0, 12); } - void syncWidget() { + 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; + _isPublic = widget.edit!.isPublic; + _isCommunity = widget.edit!.isCommunity; } } - void cancelAction() { + void _cancelAction() { AppRouter.instance.pop(); } @override void initState() { - syncWidget(); + _syncWidget(); super.initState(); } @@ -99,7 +101,7 @@ class _ChannelOrganizeScreenState extends State { Widget build(BuildContext context) { final notifyBannerActions = [ TextButton( - onPressed: cancelAction, + onPressed: _cancelAction, child: Text('cancel'.tr), ), ]; @@ -113,7 +115,7 @@ class _ChannelOrganizeScreenState extends State { toolbarHeight: AppTheme.toolbarHeight(context), actions: [ TextButton( - onPressed: _isBusy ? null : () => applyChannel(), + onPressed: _isBusy ? null : () => _applyChannel(), child: Text('apply'.tr.toUpperCase()), ) ], @@ -164,7 +166,7 @@ class _ChannelOrganizeScreenState extends State { visualDensity: const VisualDensity(horizontal: -2, vertical: -2), ), - onPressed: () => randomizeAlias(), + onPressed: () => _randomizeAlias(), child: const Icon(Icons.refresh), ) ], @@ -196,12 +198,17 @@ class _ChannelOrganizeScreenState extends State { ), const Divider(thickness: 0.3), CheckboxListTile( - title: Text('channelEncrypted'.tr), - value: _isEncrypted, - onChanged: (widget.edit?.isEncrypted ?? false) - ? null - : (newValue) => - setState(() => _isEncrypted = newValue ?? false), + title: Text('channelPublic'.tr), + value: _isPublic, + onChanged: (value) => + setState(() => _isPublic = value ?? false), + controlAffinity: ListTileControlAffinity.leading, + ), + CheckboxListTile( + title: Text('channelCommunity'.tr), + value: _isCommunity, + onChanged: (value) => + setState(() => _isCommunity = value ?? false), controlAffinity: ListTileControlAffinity.leading, ), ],