2024-06-15 23:29:15 -04:00
|
|
|
import 'package:provider/provider.dart';
|
2024-02-20 17:57:05 -05:00
|
|
|
import 'package:veilid_support/veilid_support.dart';
|
|
|
|
|
|
|
|
import '../../account_manager/account_manager.dart';
|
|
|
|
import '../../proto/proto.dart' as proto;
|
|
|
|
|
2024-02-25 22:52:09 -05:00
|
|
|
// Watch subkey #1 of the ContactRequest record for accept/reject
|
2024-02-20 17:57:05 -05:00
|
|
|
class ContactRequestInboxCubit
|
2024-04-04 22:31:09 -04:00
|
|
|
extends DefaultDHTRecordCubit<proto.SignedContactResponse?> {
|
2024-02-20 17:57:05 -05:00
|
|
|
ContactRequestInboxCubit(
|
2024-06-15 23:29:15 -04:00
|
|
|
{required Locator locator, required this.contactInvitationRecord})
|
2024-02-20 17:57:05 -05:00
|
|
|
: super(
|
|
|
|
open: () => _open(
|
2024-06-15 23:29:15 -04:00
|
|
|
locator: locator,
|
2024-02-20 17:57:05 -05:00
|
|
|
contactInvitationRecord: contactInvitationRecord),
|
2024-04-04 22:31:09 -04:00
|
|
|
decodeState: (buf) => buf.isEmpty
|
|
|
|
? null
|
|
|
|
: proto.SignedContactResponse.fromBuffer(buf));
|
2024-02-20 17:57:05 -05:00
|
|
|
|
|
|
|
static Future<DHTRecord> _open(
|
2024-06-15 23:29:15 -04:00
|
|
|
{required Locator locator,
|
2024-02-20 17:57:05 -05:00
|
|
|
required proto.ContactInvitationRecord contactInvitationRecord}) async {
|
|
|
|
final pool = DHTRecordPool.instance;
|
2024-06-15 23:29:15 -04:00
|
|
|
|
|
|
|
final unlockedAccountInfo =
|
2024-06-16 22:12:24 -04:00
|
|
|
locator<AccountInfoCubit>().state.unlockedAccountInfo!;
|
2024-06-15 23:29:15 -04:00
|
|
|
final accountRecordKey = unlockedAccountInfo.accountRecordKey;
|
|
|
|
|
2024-02-20 17:57:05 -05:00
|
|
|
final writerSecret = contactInvitationRecord.writerSecret.toVeilid();
|
|
|
|
final recordKey =
|
|
|
|
contactInvitationRecord.contactRequestInbox.recordKey.toVeilid();
|
2024-05-27 22:58:37 -04:00
|
|
|
final writerTypedSecret =
|
|
|
|
TypedKey(kind: recordKey.kind, value: writerSecret);
|
2024-05-01 20:58:25 -04:00
|
|
|
return pool.openRecordRead(recordKey,
|
2024-04-03 21:55:49 -04:00
|
|
|
debugName: 'ContactRequestInboxCubit::_open::'
|
|
|
|
'ContactRequestInbox',
|
2024-05-27 22:58:37 -04:00
|
|
|
crypto:
|
|
|
|
await DHTRecordPool.privateCryptoFromTypedSecret(writerTypedSecret),
|
2024-02-20 17:57:05 -05:00
|
|
|
parent: accountRecordKey,
|
|
|
|
defaultSubkey: 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
final proto.ContactInvitationRecord contactInvitationRecord;
|
|
|
|
}
|