Better DM

This commit is contained in:
2024-05-29 00:14:41 +08:00
parent c50a49f37d
commit d4cbabeb31
17 changed files with 253 additions and 187 deletions

View File

@@ -96,11 +96,11 @@ class _ChannelDetailScreenState extends State<ChannelDetailScreen> {
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 12),
child: Row(
children: [
CircleAvatar(
const CircleAvatar(
radius: 28,
backgroundColor: Colors.teal,
child: FaIcon(
widget.channel.icon,
FontAwesomeIcons.hashtag,
color: Colors.white,
size: 18,
),

View File

@@ -1,14 +1,12 @@
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/providers/content/channel.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';
@@ -29,11 +27,6 @@ class ChannelOrganizeScreen extends StatefulWidget {
}
class _ChannelOrganizeScreenState extends State<ChannelOrganizeScreen> {
static Map<int, String> channelTypes = {
0: 'channelTypeCommon'.tr,
1: 'channelTypeDirect'.tr,
};
bool _isBusy = false;
final _aliasController = TextEditingController();
@@ -41,38 +34,6 @@ class _ChannelOrganizeScreenState extends State<ChannelOrganizeScreen> {
final _descriptionController = TextEditingController();
bool _isEncrypted = false;
int _channelType = 0;
List<Account> _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();
@@ -82,6 +43,8 @@ class _ChannelOrganizeScreenState extends State<ChannelOrganizeScreen> {
setState(() => _isBusy = true);
final ChannelProvider provider = Get.find();
final client = GetConnect(maxAuthRetries: 3);
client.httpClient.baseUrl = ServiceFinder.services['messaging'];
client.httpClient.addAuthenticator(auth.requestAuthenticator);
@@ -92,27 +55,21 @@ class _ChannelOrganizeScreenState extends State<ChannelOrganizeScreen> {
'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);
Response? resp;
try {
if (widget.edit != null) {
resp = await provider.updateChannel(scope!, widget.edit!.id, payload);
} else {
resp = await provider.createChannel(scope!, payload);
}
} catch (e) {
context.showErrorDialog(e);
}
AppRouter.instance.pop(resp!.body);
setState(() => _isBusy = false);
}
@@ -127,7 +84,6 @@ class _ChannelOrganizeScreenState extends State<ChannelOrganizeScreen> {
_nameController.text = widget.edit!.name;
_descriptionController.text = widget.edit!.description;
_isEncrypted = widget.edit!.isEncrypted;
_channelType = widget.edit!.type;
}
}
@@ -227,55 +183,6 @@ class _ChannelOrganizeScreenState extends State<ChannelOrganizeScreen> {
).paddingSymmetric(horizontal: 16, vertical: 12),
),
const Divider(thickness: 0.3),
if (_channelType == 1 && widget.edit == null)
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<int>(
isExpanded: true,
items: channelTypes.entries
.map((item) => DropdownMenuItem<int>(
enabled: widget.edit == null ||
item.key == widget.edit?.type,
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,

View File

@@ -8,6 +8,7 @@ import 'package:solian/providers/content/channel.dart';
import 'package:solian/router.dart';
import 'package:solian/screens/account/notification.dart';
import 'package:solian/theme.dart';
import 'package:solian/widgets/account/account_avatar.dart';
import 'package:solian/widgets/account/signin_required_overlay.dart';
class ContactScreen extends StatefulWidget {
@@ -19,9 +20,16 @@ class ContactScreen extends StatefulWidget {
class _ContactScreenState extends State<ContactScreen> {
bool _isBusy = true;
int? _accountId;
final List<Channel> _channels = List.empty(growable: true);
getProfile() async {
final AuthProvider auth = Get.find();
final prof = await auth.getProfile();
_accountId = prof.body['id'];
}
getChannels() async {
setState(() => _isBusy = true);
@@ -42,6 +50,7 @@ class _ContactScreenState extends State<ContactScreen> {
void initState() {
super.initState();
getProfile();
getChannels();
}
@@ -81,17 +90,48 @@ class _ContactScreenState extends State<ContactScreen> {
forceElevated: innerBoxIsScrolled,
actions: [
const NotificationButton(),
IconButton(
PopupMenuButton(
icon: const Icon(Icons.add_circle),
onPressed: () {
AppRouter.instance
.pushNamed('channelOrganizing')
.then(
(value) {
if (value != null) getChannels();
itemBuilder: (BuildContext context) => [
PopupMenuItem(
child: ListTile(
title: Text('channelOrganizeCommon'.tr),
leading: const Icon(Icons.tag),
contentPadding:
const EdgeInsets.symmetric(horizontal: 8),
),
onTap: () {
AppRouter.instance
.pushNamed('channelOrganizing')
.then(
(value) {
if (value != null) getChannels();
},
);
},
);
},
),
PopupMenuItem(
child: ListTile(
title: Text('channelOrganizeDirect'.tr),
leading: const FaIcon(
FontAwesomeIcons.userGroup,
size: 16,
),
contentPadding:
const EdgeInsets.symmetric(horizontal: 8),
),
onTap: () {
final ChannelProvider provider = Get.find();
provider
.createDirectChannel(context, 'global')
.then((resp) {
if (resp != null) {
getChannels();
}
});
},
),
],
),
SizedBox(
width: SolianTheme.isLargeScreen(context) ? 8 : 16,
@@ -115,30 +155,7 @@ class _ContactScreenState extends State<ContactScreen> {
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: () {
AppRouter.instance.pushNamed(
'channelChat',
pathParameters: {'alias': element.alias},
queryParameters: {
if (element.realmId != null)
'realm': element.realm!.alias,
},
);
},
);
return buildItem(element);
},
),
),
@@ -152,4 +169,58 @@ class _ContactScreenState extends State<ContactScreen> {
),
);
}
Widget buildItem(Channel element) {
if (element.type == 1) {
final otherside = element.members!
.where((e) => e.account.externalId != _accountId)
.first;
return ListTile(
leading: AccountAvatar(
content: otherside.account.avatar,
bgColor: Colors.indigo,
feColor: Colors.white,
),
contentPadding: const EdgeInsets.symmetric(horizontal: 24),
title: Text(otherside.account.name),
subtitle: Text(
'channelDirectDescription'
.trParams({'username': otherside.account.name}),
),
onTap: () {
AppRouter.instance.pushNamed(
'channelChat',
pathParameters: {'alias': element.alias},
queryParameters: {
if (element.realmId != null) 'realm': element.realm!.alias,
},
);
},
);
}
return ListTile(
leading: const CircleAvatar(
backgroundColor: Colors.indigo,
child: FaIcon(
FontAwesomeIcons.hashtag,
color: Colors.white,
size: 16,
),
),
contentPadding: const EdgeInsets.symmetric(horizontal: 24),
title: Text(element.name),
subtitle: Text(element.description),
onTap: () {
AppRouter.instance.pushNamed(
'channelChat',
pathParameters: {'alias': element.alias},
queryParameters: {
if (element.realmId != null) 'realm': element.realm!.alias,
},
);
},
);
}
}

View File

@@ -1,5 +1,4 @@
import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';
import 'package:flutter_animate/flutter_animate.dart';
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
import 'package:get/get.dart';