Channel isPublic and isCommunity

This commit is contained in:
LittleSheep 2024-09-17 13:50:04 +08:00
parent 01db63e297
commit c9fbe47337
5 changed files with 37 additions and 24 deletions

View File

@ -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",

View File

@ -254,7 +254,8 @@
"channelName": "显示名称",
"channelDescription": "频道简介",
"channelDirectDescription": "与 @username 的私聊",
"channelEncrypted": "加密频道",
"channelPublic": "公开频道",
"channelCommunity": "社区频道",
"channelMember": "频道成员",
"channelMembers": "频道成员",
"channelMembersAdd": "添加频道成员",

View File

@ -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,
});

View File

@ -22,7 +22,8 @@ Channel _$ChannelFromJson(Map<String, dynamic> json) => Channel(
.toList(),
account: Account.fromJson(json['account'] as Map<String, dynamic>),
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<String, dynamic>),
@ -43,7 +44,8 @@ Map<String, dynamic> _$ChannelToJson(Channel instance) => <String, dynamic>{
'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,
};

View File

@ -35,13 +35,14 @@ class _ChannelOrganizeScreenState extends State<ChannelOrganizeScreen> {
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<ChannelOrganizeScreen> {
'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<ChannelOrganizeScreen> {
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<ChannelOrganizeScreen> {
Widget build(BuildContext context) {
final notifyBannerActions = [
TextButton(
onPressed: cancelAction,
onPressed: _cancelAction,
child: Text('cancel'.tr),
),
];
@ -113,7 +115,7 @@ class _ChannelOrganizeScreenState extends State<ChannelOrganizeScreen> {
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<ChannelOrganizeScreen> {
visualDensity:
const VisualDensity(horizontal: -2, vertical: -2),
),
onPressed: () => randomizeAlias(),
onPressed: () => _randomizeAlias(),
child: const Icon(Icons.refresh),
)
],
@ -196,12 +198,17 @@ class _ChannelOrganizeScreenState extends State<ChannelOrganizeScreen> {
),
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,
),
],