Notify level in channel

This commit is contained in:
2024-06-09 00:09:01 +08:00
parent 6acbd1ee9e
commit 0f24ac03f7
12 changed files with 178 additions and 39 deletions

View File

@ -33,7 +33,6 @@ class _NotificationScreenState extends State<NotificationScreen> {
if (markList.isNotEmpty) {
final client = auth.configureClient(service: 'passport');
await client.put('/api/notifications/batch/read', {'messages': markList});
}
@ -129,6 +128,7 @@ class _NotificationScreenState extends State<NotificationScreen> {
),
title: Text(element.subject),
subtitle: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(element.content),
if (element.links != null)

View File

@ -25,6 +25,7 @@ class _SignInPopupState extends State<SignInPopup> {
if (username.isEmpty || password.isEmpty) return;
provider.signin(context, username, password).then((_) async {
await showDialog(
useRootNavigator: true,
context: context,
builder: (context) => const PushNotifyRegisterDialog(),
);

View File

@ -55,6 +55,7 @@ class _CallScreenState extends State<CallScreen> {
color: Theme.of(context).colorScheme.surface,
child: Scaffold(
appBar: AppBar(
centerTitle: true,
title: RichText(
textAlign: TextAlign.center,
text: TextSpan(children: [

View File

@ -15,6 +15,7 @@ import 'package:solian/providers/chat.dart';
import 'package:solian/providers/content/call.dart';
import 'package:solian/providers/content/channel.dart';
import 'package:solian/router.dart';
import 'package:solian/screens/channel/channel_detail.dart';
import 'package:solian/theme.dart';
import 'package:solian/widgets/chat/call/call_prejoin.dart';
import 'package:solian/widgets/chat/call/chat_call_action.dart';
@ -44,6 +45,7 @@ class _ChannelChatScreenState extends State<ChannelChatScreen> {
String? _overrideAlias;
Channel? _channel;
ChannelMember? _channelProfile;
Call? _ongoingCall;
StreamSubscription<NetworkPackage>? _subscription;
@ -61,16 +63,21 @@ class _ChannelChatScreenState extends State<ChannelChatScreen> {
setState(() => _isBusy = true);
if (overrideAlias != null) {
_overrideAlias = overrideAlias;
}
if (overrideAlias != null) _overrideAlias = overrideAlias;
try {
final resp = await provider.getChannel(
_overrideAlias ?? widget.alias,
realm: widget.realm,
);
setState(() => _channel = Channel.fromJson(resp.body));
final respProfile = await provider.getMyChannelProfile(
_overrideAlias ?? widget.alias,
realm: widget.realm,
);
setState(() {
_channel = Channel.fromJson(resp.body);
_channelProfile = ChannelMember.fromJson(respProfile.body);
});
} catch (e) {
context.showErrorDialog(e);
}
@ -192,7 +199,7 @@ class _ChannelChatScreenState extends State<ChannelChatScreen> {
Message? _messageToReplying;
Message? _messageToEditing;
Widget buildHistory(context, item, index) {
Widget buildHistory(context, Message item, index) {
bool isMerged = false, hasMerged = false;
if (index > 0) {
hasMerged = checkMessageMergeable(
@ -212,8 +219,8 @@ class _ChannelChatScreenState extends State<ChannelChatScreen> {
content = Column(
children: [
ChatMessage(
key: Key('m${item.replyTo.uuid}'),
item: item.replyTo,
key: Key('m${item.replyTo!.uuid}'),
item: item.replyTo!,
isReply: true,
).paddingOnly(left: 24, right: 4, bottom: 2),
ChatMessage(
@ -273,8 +280,11 @@ class _ChannelChatScreenState extends State<ChannelChatScreen> {
@override
Widget build(BuildContext context) {
if (_isBusy || _channel == null) {
return const Center(
child: CircularProgressIndicator(),
return Material(
color: Theme.of(context).colorScheme.surface,
child: const Center(
child: CircularProgressIndicator(),
),
);
}
@ -315,7 +325,10 @@ class _ChannelChatScreenState extends State<ChannelChatScreen> {
'channelDetail',
pathParameters: {'alias': widget.alias},
queryParameters: {'realm': widget.realm},
extra: _channel,
extra: ChannelDetailArguments(
profile: _channelProfile!,
channel: _channel!,
),
)
.then((value) {
if (value == false) AppRouter.instance.pop();

View File

@ -1,6 +1,8 @@
import 'package:dropdown_button2/dropdown_button2.dart';
import 'package:flutter/material.dart';
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
import 'package:get/get.dart';
import 'package:solian/exts.dart';
import 'package:solian/models/channel.dart';
import 'package:solian/providers/auth.dart';
import 'package:solian/router.dart';
@ -8,14 +10,23 @@ import 'package:solian/screens/channel/channel_organize.dart';
import 'package:solian/widgets/channel/channel_deletion.dart';
import 'package:solian/widgets/channel/channel_member.dart';
class ChannelDetailArguments {
final Channel channel;
final ChannelMember profile;
ChannelDetailArguments({required this.channel, required this.profile});
}
class ChannelDetailScreen extends StatefulWidget {
final String realm;
final Channel channel;
final ChannelMember profile;
const ChannelDetailScreen({
super.key,
required this.channel,
required this.realm,
required this.profile,
});
@override
@ -23,7 +34,10 @@ class ChannelDetailScreen extends StatefulWidget {
}
class _ChannelDetailScreenState extends State<ChannelDetailScreen> {
bool _isBusy = false;
bool _isOwned = false;
int _notifyLevel = 0;
void checkOwner() async {
final AuthProvider auth = Get.find();
@ -59,15 +73,43 @@ class _ChannelDetailScreenState extends State<ChannelDetailScreen> {
}
}
void applyProfileChanges() async {
final AuthProvider auth = Get.find();
if (!await auth.isAuthorized) return;
setState(() => _isBusy = true);
final client = auth.configureClient(service: 'messaging');
final resp = await client
.put('/api/channels/${widget.realm}/${widget.channel.alias}/members/me', {
'nick': null,
'notify_level': _notifyLevel,
});
if (resp.statusCode != 200) {
context.showErrorDialog(resp.bodyString);
} else {
context.showSnackbar('channelNotifyLevelApplied'.tr);
}
setState(() => _isBusy = false);
}
@override
void initState() {
_notifyLevel = widget.profile.notify;
super.initState();
checkOwner();
}
@override
Widget build(BuildContext context) {
final notifyTypes = {
0: 'channelNotifyLevelAll'.tr,
1: 'channelNotifyLevelMentioned'.tr,
2: 'channelNotifyLevelNone'.tr,
};
final ownerActions = [
ListTile(
leading: const Icon(Icons.edit),
@ -127,9 +169,38 @@ class _ChannelDetailScreenState extends State<ChannelDetailScreen> {
child: ListView(
children: [
ListTile(
leading: const Icon(Icons.settings),
trailing: const Icon(Icons.chevron_right),
title: Text('channelSettings'.tr.capitalize!),
leading: const Icon(Icons.notifications_active),
title: Text('channelNotifyLevel'.tr.capitalize!),
trailing: DropdownButtonHideUnderline(
child: DropdownButton2<int>(
isExpanded: true,
items: notifyTypes.entries
.map((item) => DropdownMenuItem<int>(
enabled: !_isBusy,
value: item.key,
child: Text(
item.value,
style: const TextStyle(
fontSize: 14,
),
),
))
.toList(),
value: _notifyLevel,
onChanged: (int? value) {
setState(() => _notifyLevel = value ?? 0);
applyProfileChanges();
},
buttonStyleData: const ButtonStyleData(
padding: EdgeInsets.only(left: 16, right: 1),
height: 40,
width: 140,
),
menuItemStyleData: const MenuItemStyleData(
height: 40,
),
),
),
),
ListTile(
leading: const Icon(Icons.supervisor_account),