From f951acd79a090e9308800e45a6b7755c88181df0 Mon Sep 17 00:00:00 2001 From: Christien Rioux Date: Mon, 25 Sep 2023 22:59:28 -0400 Subject: [PATCH] note to self --- .../chat_single_contact_item_widget.dart | 4 +-- .../chat_single_contact_list_widget.dart | 3 -- lib/components/contact_item_widget.dart | 6 ++-- lib/components/paste_invite_dialog.dart | 29 ++++++++++++------- lib/components/profile_widget.dart | 2 -- lib/providers/contact_invite.dart | 26 ++++++++++------- lib/tools/theme_service.dart | 1 - 7 files changed, 39 insertions(+), 32 deletions(-) diff --git a/lib/components/chat_single_contact_item_widget.dart b/lib/components/chat_single_contact_item_widget.dart index ed48f96..5465629 100644 --- a/lib/components/chat_single_contact_item_widget.dart +++ b/lib/components/chat_single_contact_item_widget.dart @@ -1,11 +1,9 @@ import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; -import 'package:flutter_animate/flutter_animate.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:flutter_slidable/flutter_slidable.dart'; import 'package:flutter_translate/flutter_translate.dart'; import '../../entities/proto.dart' as proto; -import '../pages/main_pager/main_pager.dart'; import '../providers/account.dart'; import '../providers/chat.dart'; import '../tools/theme_service.dart'; @@ -19,7 +17,7 @@ class ChatSingleContactItemWidget extends ConsumerWidget { // ignore: prefer_expression_function_bodies Widget build(BuildContext context, WidgetRef ref) { final theme = Theme.of(context); - final textTheme = theme.textTheme; + //final textTheme = theme.textTheme; final scale = theme.extension()!; final activeChat = ref.watch(activeChatStateProvider).asData?.value; diff --git a/lib/components/chat_single_contact_list_widget.dart b/lib/components/chat_single_contact_list_widget.dart index 7cb047c..5e39353 100644 --- a/lib/components/chat_single_contact_list_widget.dart +++ b/lib/components/chat_single_contact_list_widget.dart @@ -1,6 +1,5 @@ import 'package:awesome_extensions/awesome_extensions.dart'; import 'package:fast_immutable_collections/fast_immutable_collections.dart'; -import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:flutter_translate/flutter_translate.dart'; @@ -9,9 +8,7 @@ import 'package:searchable_listview/searchable_listview.dart'; import '../../entities/proto.dart' as proto; import '../tools/tools.dart'; import 'chat_single_contact_item_widget.dart'; -import 'contact_item_widget.dart'; import 'empty_chat_list_widget.dart'; -import 'empty_contact_list_widget.dart'; class ChatSingleContactListWidget extends ConsumerWidget { ChatSingleContactListWidget( diff --git a/lib/components/contact_item_widget.dart b/lib/components/contact_item_widget.dart index 44d2b46..b986e01 100644 --- a/lib/components/contact_item_widget.dart +++ b/lib/components/contact_item_widget.dart @@ -20,7 +20,7 @@ class ContactItemWidget extends ConsumerWidget { // ignore: prefer_expression_function_bodies Widget build(BuildContext context, WidgetRef ref) { final theme = Theme.of(context); - final textTheme = theme.textTheme; + //final textTheme = theme.textTheme; final scale = theme.extension()!; final remoteConversationKey = @@ -78,7 +78,9 @@ class ContactItemWidget extends ConsumerWidget { await getOrCreateChatSingleContact( activeAccountInfo: activeAccountInfo, remoteConversationRecordKey: remoteConversationKey); - + ref + ..invalidate(fetchContactListProvider) + ..invalidate(fetchChatListProvider); // Click over to chats if (context.mounted) { await MainPager.of(context)?.pageController.animateToPage( diff --git a/lib/components/paste_invite_dialog.dart b/lib/components/paste_invite_dialog.dart index 40ddb4b..8e227df 100644 --- a/lib/components/paste_invite_dialog.dart +++ b/lib/components/paste_invite_dialog.dart @@ -5,7 +5,6 @@ import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:flutter_translate/flutter_translate.dart'; -import 'package:quickalert/quickalert.dart'; import '../entities/local_account.dart'; import '../providers/account.dart'; @@ -61,15 +60,22 @@ class PasteInviteDialogState extends ConsumerState { final acceptedContact = await acceptContactInvitation(activeAccountInfo, validInvitation); if (acceptedContact != null) { - await createContact( - activeAccountInfo: activeAccountInfo, - profile: acceptedContact.profile, - remoteIdentity: acceptedContact.remoteIdentity, - remoteConversationRecordKey: - acceptedContact.remoteConversationRecordKey, - localConversationRecordKey: - acceptedContact.localConversationRecordKey, - ); + // initiator when accept is received will create + // contact in the case of a 'note to self' + final isSelf = + activeAccountInfo.localAccount.identityMaster.identityPublicKey == + acceptedContact.remoteIdentity.identityPublicKey; + if (!isSelf) { + await createContact( + activeAccountInfo: activeAccountInfo, + profile: acceptedContact.profile, + remoteIdentity: acceptedContact.remoteIdentity, + remoteConversationRecordKey: + acceptedContact.remoteConversationRecordKey, + localConversationRecordKey: + acceptedContact.localConversationRecordKey, + ); + } ref ..invalidate(fetchContactInvitationRecordsProvider) ..invalidate(fetchContactListProvider); @@ -154,6 +160,8 @@ class PasteInviteDialogState extends ConsumerState { }); return; } + final contactInvitationRecords = + await ref.read(fetchContactInvitationRecordsProvider.future); setState(() { _validatingPaste = true; @@ -161,6 +169,7 @@ class PasteInviteDialogState extends ConsumerState { }); final validatedContactInvitation = await validateContactInvitation( activeAccountInfo: activeAccountInfo, + contactInvitationRecords: contactInvitationRecords, inviteData: inviteData, getEncryptionKeyCallback: (cs, encryptionKeyType, encryptedSecret) async { diff --git a/lib/components/profile_widget.dart b/lib/components/profile_widget.dart index 983f793..3446f0b 100644 --- a/lib/components/profile_widget.dart +++ b/lib/components/profile_widget.dart @@ -2,8 +2,6 @@ import 'package:awesome_extensions/awesome_extensions.dart'; import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; -import 'package:flutter_translate/flutter_translate.dart'; -import 'package:go_router/go_router.dart'; import '../tools/tools.dart'; diff --git a/lib/providers/contact_invite.dart b/lib/providers/contact_invite.dart index 054e1e9..ca1026e 100644 --- a/lib/providers/contact_invite.dart +++ b/lib/providers/contact_invite.dart @@ -147,7 +147,7 @@ Future checkAcceptRejectContact( activeAccountInfo: activeAccountInfo, contactInvitationRecord: contactInvitationRecord); - return null; + rethrow; } } @@ -327,6 +327,7 @@ typedef GetEncryptionKeyCallback = Future Function( Future validateContactInvitation( {required ActiveAccountInfo activeAccountInfo, + required IList? contactInvitationRecords, required Uint8List inviteData, required GetEncryptionKeyCallback getEncryptionKeyCallback}) async { final accountRecordKey = @@ -349,10 +350,13 @@ Future validateContactInvitation( final cs = await pool.veilid.getCryptoSystem(contactRequestInboxKey.kind); // See if we're chatting to ourselves, if so, don't delete it here - final ownKey = pool.getParentRecord(contactRequestInboxKey) != null; + final isSelf = contactInvitationRecords?.indexWhere((cir) => + proto.TypedKeyProto.fromProto(cir.contactRequestInbox.recordKey) == + contactRequestInboxKey) != + -1; await (await pool.openRead(contactRequestInboxKey, parent: accountRecordKey)) - .maybeDeleteScope(!ownKey, (contactRequestInbox) async { + .maybeDeleteScope(!isSelf, (contactRequestInbox) async { // final contactRequest = await contactRequestInbox.getProtobuf(proto.ContactRequest.fromBuffer); @@ -410,9 +414,9 @@ Future acceptContactInvitation( final pool = await DHTRecordPool.instance(); try { // Ensure we don't delete this if we're trying to chat to self - final ownKey = - pool.getParentRecord(validContactInvitation.contactRequestInboxKey) != - null; + final isSelf = + validContactInvitation.contactIdentityMaster.identityPublicKey == + activeAccountInfo.localAccount.identityMaster.identityPublicKey; final accountRecordKey = activeAccountInfo.userLogin.accountRecordInfo.accountRecord.recordKey; @@ -420,7 +424,7 @@ Future acceptContactInvitation( validContactInvitation.writer, parent: accountRecordKey)) // ignore: prefer_expression_function_bodies - .maybeDeleteScope(!ownKey, (contactRequestInbox) async { + .maybeDeleteScope(!isSelf, (contactRequestInbox) async { // Create local conversation key for this // contact and send via contact response return createConversation( @@ -475,16 +479,16 @@ Future rejectContactInvitation(ActiveAccountInfo activeAccountInfo, final pool = await DHTRecordPool.instance(); // Ensure we don't delete this if we're trying to chat to self - final ownKey = - pool.getParentRecord(validContactInvitation.contactRequestInboxKey) != - null; + final isSelf = + validContactInvitation.contactIdentityMaster.identityPublicKey == + activeAccountInfo.localAccount.identityMaster.identityPublicKey; final accountRecordKey = activeAccountInfo.userLogin.accountRecordInfo.accountRecord.recordKey; return (await pool.openWrite(validContactInvitation.contactRequestInboxKey, validContactInvitation.writer, parent: accountRecordKey)) - .maybeDeleteScope(!ownKey, (contactRequestInbox) async { + .maybeDeleteScope(!isSelf, (contactRequestInbox) async { final cs = await pool.veilid .getCryptoSystem(validContactInvitation.contactRequestInboxKey.kind); diff --git a/lib/tools/theme_service.dart b/lib/tools/theme_service.dart index b9d9f79..41b664e 100644 --- a/lib/tools/theme_service.dart +++ b/lib/tools/theme_service.dart @@ -3,7 +3,6 @@ import 'dart:convert'; import 'package:flutter/material.dart'; -import 'package:flutter_chat_ui/flutter_chat_ui.dart'; import 'package:riverpod_annotation/riverpod_annotation.dart'; import 'package:shared_preferences/shared_preferences.dart';