Delete account

This commit is contained in:
LittleSheep 2024-11-28 23:51:13 +08:00
parent 36013a3a57
commit 041be961c4
5 changed files with 81 additions and 34 deletions

View File

@ -177,6 +177,8 @@
"channelEditProfile": "Edit Channel Profile",
"channelEdit": "Edit Channel",
"channelEditDescription": "Change the basic information of the channel, metadata, etc.",
"channelActionDelete": "Delete Channel",
"channelActionDeleteDescription": "Delete the entire channel, and also delete messages in the channel.",
"fieldRealmAlias": "Realm Alias",
"fieldRealmAliasHint": "The unique realm alias within the site, used to represent the realm in URL, leave blank to auto generate. Should be URL-Safe.",
"fieldRealmName": "Name",

View File

@ -177,6 +177,8 @@
"channelEditProfile": "更改频道身份",
"channelEdit": "编辑频道",
"channelEditDescription": "更改频道基本信息,元数据等。",
"channelActionDelete": "删除频道",
"channelActionDeleteDescription": "删除整个频道,并且删除频道里的所有信息。",
"fieldRealmAlias": "领域别名",
"fieldRealmAliasHint": "全站范围内唯一的领域别名,用于在 URL 中表示该领域,留空则自动生成。应遵循 URL-Safe 的原则。",
"fieldRealmName": "名称",

View File

@ -21,9 +21,7 @@ class _ChatScreenState extends State<ChatScreen> {
List<SnChannel>? _channels;
@override
void initState() {
super.initState();
void _refreshChannels() {
final chan = context.read<ChatChannelProvider>();
chan.fetchChannels().listen((channels) {
if (mounted) setState(() => _channels = channels);
@ -39,6 +37,12 @@ class _ChatScreenState extends State<ChatScreen> {
});
}
@override
void initState() {
super.initState();
_refreshChannels();
}
@override
Widget build(BuildContext context) {
return Scaffold(
@ -48,13 +52,17 @@ class _ChatScreenState extends State<ChatScreen> {
floatingActionButton: FloatingActionButton(
child: const Icon(Symbols.chat_add_on),
onPressed: () {
GoRouter.of(context).pushNamed('chatManage');
GoRouter.of(context).pushNamed('chatManage').then((value) {
if (value != null && context.mounted) _refreshChannels();
});
},
),
body: Column(
children: [
LoadingIndicator(isActive: _isBusy),
Expanded(
child: RefreshIndicator(
onRefresh: () => Future.sync(() => _refreshChannels()),
child: ListView.builder(
itemCount: _channels?.length ?? 0,
itemBuilder: (context, idx) {
@ -78,12 +86,15 @@ class _ChatScreenState extends State<ChatScreen> {
'scope': channel.realm?.alias ?? 'global',
'alias': channel.alias,
},
);
).then((value) {
if (value == true) _refreshChannels();
});
},
);
},
),
),
),
],
),
);

View File

@ -65,6 +65,27 @@ class _ChannelDetailScreenState extends State<ChannelDetailScreen> {
}
}
Future<void> _deleteChannel() async {
final confirm = await context.showConfirmDialog(
'channelDelete'.tr(args: [_channel!.name]),
'channelDeleteDescription'.tr(),
);
if (!confirm) return;
if (!mounted) return;
try {
final sn = context.read<SnNetworkProvider>();
await sn.client.delete(
'/cgi/im/channels/${_channel!.realm?.alias ?? 'global'}/${_channel!.id}',
);
if (!mounted) return;
Navigator.pop(context, false);
} catch (err) {
if (!mounted) return;
context.showErrorDialog(err);
}
}
@override
void initState() {
super.initState();
@ -119,8 +140,9 @@ class _ChannelDetailScreenState extends State<ChannelDetailScreen> {
trailing: const Icon(Symbols.chevron_right),
title: Text('channelEditProfile').tr(),
subtitle: Text(
_profile?.nick ??
ud.getAccountFromCache(_profile!.accountId)!.nick,
(_profile?.nick?.isEmpty ?? true)
? ud.getAccountFromCache(_profile!.accountId)!.nick
: _profile!.nick!,
),
contentPadding: const EdgeInsets.only(left: 20, right: 20),
onTap: () {},
@ -152,6 +174,14 @@ class _ChannelDetailScreenState extends State<ChannelDetailScreen> {
});
},
),
ListTile(
leading: const Icon(Symbols.delete),
trailing: const Icon(Symbols.chevron_right),
title: Text('channelActionDelete').tr(),
subtitle: Text('channelActionDeleteDescription').tr(),
contentPadding: const EdgeInsets.symmetric(horizontal: 24),
onTap: _deleteChannel,
),
],
),
],

View File

@ -205,7 +205,9 @@ class _ChatRoomScreenState extends State<ChatRoomScreen> {
'scope': widget.scope,
'alias': widget.alias,
}).then((value) {
if (value != null) {
if (value == false && context.mounted) {
Navigator.pop(context, true);
} else if (value != null && context.mounted) {
_fetchChannel();
}
});