mirror of
https://gitlab.com/veilid/veilidchat.git
synced 2025-02-08 19:18:30 -05:00
refactor
This commit is contained in:
parent
1e6b9f4a43
commit
4a8958a868
@ -10,7 +10,6 @@ import '../../../layout/default_app_bar.dart';
|
|||||||
import '../../../tools/tools.dart';
|
import '../../../tools/tools.dart';
|
||||||
import '../../../veilid_processor/veilid_processor.dart';
|
import '../../../veilid_processor/veilid_processor.dart';
|
||||||
import '../../account_manager.dart';
|
import '../../account_manager.dart';
|
||||||
import '../../models/models.dart';
|
|
||||||
|
|
||||||
class NewAccountPage extends StatefulWidget {
|
class NewAccountPage extends StatefulWidget {
|
||||||
const NewAccountPage({super.key});
|
const NewAccountPage({super.key});
|
||||||
|
@ -1,25 +1,24 @@
|
|||||||
import 'package:awesome_extensions/awesome_extensions.dart';
|
import 'package:awesome_extensions/awesome_extensions.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
|
||||||
|
|
||||||
|
import '../../proto/proto.dart' as proto;
|
||||||
import '../../theme/theme.dart';
|
import '../../theme/theme.dart';
|
||||||
import '../../tools/tools.dart';
|
|
||||||
import '../cubit/cubit.dart';
|
|
||||||
|
|
||||||
class ProfileWidget extends StatelessWidget {
|
class ProfileWidget extends StatelessWidget {
|
||||||
const ProfileWidget({
|
const ProfileWidget({
|
||||||
|
required proto.Profile profile,
|
||||||
super.key,
|
super.key,
|
||||||
});
|
}) : _profile = profile;
|
||||||
|
|
||||||
|
//
|
||||||
|
|
||||||
|
final proto.Profile _profile;
|
||||||
|
|
||||||
|
//
|
||||||
|
|
||||||
@override
|
@override
|
||||||
// ignore: prefer_expression_function_bodies
|
// ignore: prefer_expression_function_bodies
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
final accountData = context.watch<AccountRecordCubit>().state.data;
|
|
||||||
if (accountData == null) {
|
|
||||||
return waitingPage(context);
|
|
||||||
}
|
|
||||||
final account = accountData.value;
|
|
||||||
|
|
||||||
final theme = Theme.of(context);
|
final theme = Theme.of(context);
|
||||||
final scale = theme.extension<ScaleScheme>()!;
|
final scale = theme.extension<ScaleScheme>()!;
|
||||||
final textTheme = theme.textTheme;
|
final textTheme = theme.textTheme;
|
||||||
@ -31,12 +30,12 @@ class ProfileWidget extends StatelessWidget {
|
|||||||
RoundedRectangleBorder(borderRadius: BorderRadius.circular(16))),
|
RoundedRectangleBorder(borderRadius: BorderRadius.circular(16))),
|
||||||
child: Column(children: [
|
child: Column(children: [
|
||||||
Text(
|
Text(
|
||||||
account.profile.name,
|
_profile.name,
|
||||||
style: textTheme.headlineSmall,
|
style: textTheme.headlineSmall,
|
||||||
textAlign: TextAlign.left,
|
textAlign: TextAlign.left,
|
||||||
).paddingAll(4),
|
).paddingAll(4),
|
||||||
if (account.profile.pronouns.isNotEmpty)
|
if (_profile.pronouns.isNotEmpty)
|
||||||
Text(account.profile.pronouns, style: textTheme.bodyMedium)
|
Text(_profile.pronouns, style: textTheme.bodyMedium)
|
||||||
.paddingLTRB(4, 0, 4, 4),
|
.paddingLTRB(4, 0, 4, 4),
|
||||||
]),
|
]),
|
||||||
);
|
);
|
||||||
|
@ -10,7 +10,7 @@ import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|||||||
import '../../old_to_refactor/proto/proto.dart' as proto;
|
import '../../old_to_refactor/proto/proto.dart' as proto;
|
||||||
import '../../old_to_refactor/providers/account.dart';
|
import '../../old_to_refactor/providers/account.dart';
|
||||||
import '../../old_to_refactor/providers/chat.dart';
|
import '../../old_to_refactor/providers/chat.dart';
|
||||||
import '../../old_to_refactor/providers/conversation.dart';
|
import '../../contacts/models/conversation.dart';
|
||||||
import '../../old_to_refactor/tools/tools.dart';
|
import '../../old_to_refactor/tools/tools.dart';
|
||||||
import '../../old_to_refactor/veilid_init.dart';
|
import '../../old_to_refactor/veilid_init.dart';
|
||||||
import '../../old_to_refactor/veilid_support/veilid_support.dart';
|
import '../../old_to_refactor/veilid_support/veilid_support.dart';
|
||||||
|
@ -26,6 +26,8 @@ class ValidContactInvitation {
|
|||||||
_contactIdentityMaster = contactIdentityMaster,
|
_contactIdentityMaster = contactIdentityMaster,
|
||||||
_writer = writer;
|
_writer = writer;
|
||||||
|
|
||||||
|
proto.Profile get remoteProfile => _contactRequestPrivate.profile;
|
||||||
|
|
||||||
Future<AcceptedContact?> accept() async {
|
Future<AcceptedContact?> accept() async {
|
||||||
final pool = DHTRecordPool.instance;
|
final pool = DHTRecordPool.instance;
|
||||||
try {
|
try {
|
||||||
|
@ -3,10 +3,12 @@ import 'dart:async';
|
|||||||
import 'package:awesome_extensions/awesome_extensions.dart';
|
import 'package:awesome_extensions/awesome_extensions.dart';
|
||||||
import 'package:flutter/foundation.dart';
|
import 'package:flutter/foundation.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
import 'package:flutter_translate/flutter_translate.dart';
|
import 'package:flutter_translate/flutter_translate.dart';
|
||||||
|
|
||||||
import '../../account_manager/account_manager.dart';
|
import '../../account_manager/account_manager.dart';
|
||||||
import '../../tools/tools.dart';
|
import '../../tools/tools.dart';
|
||||||
|
import '../contact_invitation.dart';
|
||||||
|
|
||||||
class InviteDialog extends StatefulWidget {
|
class InviteDialog extends StatefulWidget {
|
||||||
const InviteDialog(
|
const InviteDialog(
|
||||||
@ -66,22 +68,14 @@ class InviteDialogState extends State<InviteDialog> {
|
|||||||
|
|
||||||
Future<void> _onAccept() async {
|
Future<void> _onAccept() async {
|
||||||
final navigator = Navigator.of(context);
|
final navigator = Navigator.of(context);
|
||||||
|
final activeAccountInfo = context.read<ActiveAccountInfo>();
|
||||||
|
|
||||||
setState(() {
|
setState(() {
|
||||||
_isAccepting = true;
|
_isAccepting = true;
|
||||||
});
|
});
|
||||||
final activeAccountInfo = await ref.read(fetchActiveAccountProvider.future);
|
|
||||||
if (activeAccountInfo == null) {
|
|
||||||
setState(() {
|
|
||||||
_isAccepting = false;
|
|
||||||
});
|
|
||||||
navigator.pop();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
final validInvitation = _validInvitation;
|
final validInvitation = _validInvitation;
|
||||||
if (validInvitation != null) {
|
if (validInvitation != null) {
|
||||||
final acceptedContact =
|
final acceptedContact = await validInvitation.accept();
|
||||||
await acceptContactInvitation(activeAccountInfo, validInvitation);
|
|
||||||
if (acceptedContact != null) {
|
if (acceptedContact != null) {
|
||||||
// initiator when accept is received will create
|
// initiator when accept is received will create
|
||||||
// contact in the case of a 'note to self'
|
// contact in the case of a 'note to self'
|
||||||
@ -91,7 +85,7 @@ class InviteDialogState extends State<InviteDialog> {
|
|||||||
if (!isSelf) {
|
if (!isSelf) {
|
||||||
await createContact(
|
await createContact(
|
||||||
activeAccountInfo: activeAccountInfo,
|
activeAccountInfo: activeAccountInfo,
|
||||||
profile: acceptedContact.profile,
|
profile: acceptedContact.remoteProfile,
|
||||||
remoteIdentity: acceptedContact.remoteIdentity,
|
remoteIdentity: acceptedContact.remoteIdentity,
|
||||||
remoteConversationRecordKey:
|
remoteConversationRecordKey:
|
||||||
acceptedContact.remoteConversationRecordKey,
|
acceptedContact.remoteConversationRecordKey,
|
||||||
@ -99,9 +93,6 @@ class InviteDialogState extends State<InviteDialog> {
|
|||||||
acceptedContact.localConversationRecordKey,
|
acceptedContact.localConversationRecordKey,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
ref
|
|
||||||
..invalidate(fetchContactInvitationRecordsProvider)
|
|
||||||
..invalidate(fetchContactListProvider);
|
|
||||||
} else {
|
} else {
|
||||||
if (context.mounted) {
|
if (context.mounted) {
|
||||||
showErrorToast(context, 'invite_dialog.failed_to_accept');
|
showErrorToast(context, 'invite_dialog.failed_to_accept');
|
||||||
@ -120,17 +111,9 @@ class InviteDialogState extends State<InviteDialog> {
|
|||||||
setState(() {
|
setState(() {
|
||||||
_isAccepting = true;
|
_isAccepting = true;
|
||||||
});
|
});
|
||||||
final activeAccountInfo = await ref.read(fetchActiveAccountProvider.future);
|
|
||||||
if (activeAccountInfo == null) {
|
|
||||||
setState(() {
|
|
||||||
_isAccepting = false;
|
|
||||||
});
|
|
||||||
navigator.pop();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
final validInvitation = _validInvitation;
|
final validInvitation = _validInvitation;
|
||||||
if (validInvitation != null) {
|
if (validInvitation != null) {
|
||||||
if (await rejectContactInvitation(activeAccountInfo, validInvitation)) {
|
if (await validInvitation.reject()) {
|
||||||
// do nothing right now
|
// do nothing right now
|
||||||
} else {
|
} else {
|
||||||
if (context.mounted) {
|
if (context.mounted) {
|
||||||
@ -148,25 +131,15 @@ class InviteDialogState extends State<InviteDialog> {
|
|||||||
required Uint8List inviteData,
|
required Uint8List inviteData,
|
||||||
}) async {
|
}) async {
|
||||||
try {
|
try {
|
||||||
final activeAccountInfo =
|
final contactInvitationListCubit =
|
||||||
await ref.read(fetchActiveAccountProvider.future);
|
context.read<ContactInvitationListCubit>();
|
||||||
if (activeAccountInfo == null) {
|
|
||||||
setState(() {
|
|
||||||
_isValidating = false;
|
|
||||||
_validInvitation = null;
|
|
||||||
});
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
final contactInvitationRecords =
|
|
||||||
await ref.read(fetchContactInvitationRecordsProvider.future);
|
|
||||||
|
|
||||||
setState(() {
|
setState(() {
|
||||||
_isValidating = true;
|
_isValidating = true;
|
||||||
_validInvitation = null;
|
_validInvitation = null;
|
||||||
});
|
});
|
||||||
final validatedContactInvitation = await validateContactInvitation(
|
final validatedContactInvitation =
|
||||||
activeAccountInfo: activeAccountInfo,
|
await contactInvitationListCubit.validateInvitation(
|
||||||
contactInvitationRecords: contactInvitationRecords,
|
|
||||||
inviteData: inviteData,
|
inviteData: inviteData,
|
||||||
getEncryptionKeyCallback:
|
getEncryptionKeyCallback:
|
||||||
(cs, encryptionKeyType, encryptedSecret) async {
|
(cs, encryptionKeyType, encryptedSecret) async {
|
||||||
@ -203,10 +176,9 @@ class InviteDialogState extends State<InviteDialog> {
|
|||||||
}
|
}
|
||||||
encryptionKey = password;
|
encryptionKey = password;
|
||||||
}
|
}
|
||||||
return decryptSecretFromBytes(
|
return encryptionKeyType.decryptSecretFromBytes(
|
||||||
secretBytes: encryptedSecret,
|
secretBytes: encryptedSecret,
|
||||||
cryptoKind: cs.kind(),
|
cryptoKind: cs.kind(),
|
||||||
encryptionKeyType: encryptionKeyType,
|
|
||||||
encryptionKey: encryptionKey);
|
encryptionKey: encryptionKey);
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -300,11 +272,8 @@ class InviteDialogState extends State<InviteDialog> {
|
|||||||
constraints: const BoxConstraints(maxHeight: 64),
|
constraints: const BoxConstraints(maxHeight: 64),
|
||||||
width: double.infinity,
|
width: double.infinity,
|
||||||
child: ProfileWidget(
|
child: ProfileWidget(
|
||||||
name: _validInvitation!
|
profile: _validInvitation!.remoteProfile))
|
||||||
.contactRequestPrivate.profile.name,
|
.paddingLTRB(0, 0, 0, 8),
|
||||||
pronouns: _validInvitation!
|
|
||||||
.contactRequestPrivate.profile.pronouns,
|
|
||||||
)).paddingLTRB(0, 0, 0, 8),
|
|
||||||
Row(
|
Row(
|
||||||
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
|
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
|
||||||
children: [
|
children: [
|
||||||
|
@ -11,7 +11,7 @@ import 'package:veilid_support/veilid_support.dart';
|
|||||||
|
|
||||||
import '../../account_manager/account_manager.dart';
|
import '../../account_manager/account_manager.dart';
|
||||||
import '../../tools/tools.dart';
|
import '../../tools/tools.dart';
|
||||||
import 'contact_invitation_display.dart';
|
import '../contact_invitation.dart';
|
||||||
|
|
||||||
class SendInviteDialog extends StatefulWidget {
|
class SendInviteDialog extends StatefulWidget {
|
||||||
const SendInviteDialog({super.key});
|
const SendInviteDialog({super.key});
|
||||||
@ -130,17 +130,11 @@ class SendInviteDialogState extends State<SendInviteDialog> {
|
|||||||
Future<void> _onGenerateButtonPressed() async {
|
Future<void> _onGenerateButtonPressed() async {
|
||||||
final navigator = Navigator.of(context);
|
final navigator = Navigator.of(context);
|
||||||
|
|
||||||
xxx continue here
|
|
||||||
|
|
||||||
// Start generation
|
// Start generation
|
||||||
final activeAccountInfo = context.read<ActiveAccountInfo>();
|
final contactInvitationListCubit =
|
||||||
|
context.read<ContactInvitationListCubit>();
|
||||||
|
|
||||||
if (activeAccountInfo == null) {
|
final generator = contactInvitationListCubit.createInvitation(
|
||||||
navigator.pop();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
final generator = ContactInvitationRespositoryxxx.createContactInvitation(
|
|
||||||
activeAccountInfo: activeAccountInfo,
|
|
||||||
encryptionKeyType: _encryptionKeyType,
|
encryptionKeyType: _encryptionKeyType,
|
||||||
encryptionKey: _encryptionKey,
|
encryptionKey: _encryptionKey,
|
||||||
message: _messageTextController.text,
|
message: _messageTextController.text,
|
||||||
@ -152,14 +146,12 @@ xxx continue here
|
|||||||
await showDialog<void>(
|
await showDialog<void>(
|
||||||
context: context,
|
context: context,
|
||||||
builder: (context) => ContactInvitationDisplayDialog(
|
builder: (context) => ContactInvitationDisplayDialog(
|
||||||
name: activeAccountInfo.localAccount.name,
|
|
||||||
message: _messageTextController.text,
|
message: _messageTextController.text,
|
||||||
generator: generator,
|
generator: generator,
|
||||||
));
|
));
|
||||||
// if (ret == null) {
|
// if (ret == null) {
|
||||||
// return;
|
// return;
|
||||||
// }
|
// }
|
||||||
ref.invalidate(fetchContactInvitationRecordsProvider);
|
|
||||||
navigator.pop();
|
navigator.pop();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -34,7 +34,8 @@ class HomeAccountReadyState extends State<HomeAccountReady>
|
|||||||
return const Center(child: Text('unlock account'));
|
return const Center(child: Text('unlock account'));
|
||||||
}
|
}
|
||||||
|
|
||||||
Widget buildUserPanel(BuildContext context) {
|
Widget buildUserPanel() => Builder(builder: (context) {
|
||||||
|
final account = context.watch<AccountRecordCubit>().state;
|
||||||
final theme = Theme.of(context);
|
final theme = Theme.of(context);
|
||||||
final scale = theme.extension<ScaleScheme>()!;
|
final scale = theme.extension<ScaleScheme>()!;
|
||||||
|
|
||||||
@ -47,24 +48,28 @@ class HomeAccountReadyState extends State<HomeAccountReady>
|
|||||||
style: ButtonStyle(
|
style: ButtonStyle(
|
||||||
backgroundColor:
|
backgroundColor:
|
||||||
MaterialStateProperty.all(scale.secondaryScale.border),
|
MaterialStateProperty.all(scale.secondaryScale.border),
|
||||||
shape: MaterialStateProperty.all(const RoundedRectangleBorder(
|
shape: MaterialStateProperty.all(
|
||||||
borderRadius: BorderRadius.all(Radius.circular(16))))),
|
const RoundedRectangleBorder(
|
||||||
|
borderRadius:
|
||||||
|
BorderRadius.all(Radius.circular(16))))),
|
||||||
tooltip: translate('app_bar.settings_tooltip'),
|
tooltip: translate('app_bar.settings_tooltip'),
|
||||||
onPressed: () async {
|
onPressed: () async {
|
||||||
context.go('/home/settings');
|
context.go('/home/settings');
|
||||||
}).paddingLTRB(0, 0, 8, 0),
|
}).paddingLTRB(0, 0, 8, 0),
|
||||||
const ProfileWidget().expanded(),
|
asyncValueBuilder(account,
|
||||||
|
(_, account) => ProfileWidget(profile: account.profile))
|
||||||
|
.expanded(),
|
||||||
]).paddingAll(8),
|
]).paddingAll(8),
|
||||||
const MainPager().expanded()
|
const MainPager().expanded()
|
||||||
]);
|
]);
|
||||||
}
|
});
|
||||||
|
|
||||||
Widget buildPhone(BuildContext context) =>
|
Widget buildPhone(BuildContext context) =>
|
||||||
Material(color: Colors.transparent, child: buildUserPanel(context));
|
Material(color: Colors.transparent, child: buildUserPanel());
|
||||||
|
|
||||||
Widget buildTabletLeftPane(BuildContext context) => Builder(
|
Widget buildTabletLeftPane(BuildContext context) => Builder(
|
||||||
builder: (context) =>
|
builder: (context) =>
|
||||||
Material(color: Colors.transparent, child: buildUserPanel(context)));
|
Material(color: Colors.transparent, child: buildUserPanel()));
|
||||||
|
|
||||||
Widget buildTabletRightPane(BuildContext context) => buildChatComponent();
|
Widget buildTabletRightPane(BuildContext context) => buildChatComponent();
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user