veilidchat/lib/contact_invitation/cubits/contact_request_inbox_cubit.dart

48 lines
1.9 KiB
Dart
Raw Normal View History

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
extends DefaultDHTRecordCubit<proto.SignedContactResponse?> {
2024-02-20 17:57:05 -05:00
ContactRequestInboxCubit(
{required this.activeAccountInfo, required this.contactInvitationRecord})
: super(
open: () => _open(
activeAccountInfo: activeAccountInfo,
contactInvitationRecord: contactInvitationRecord),
decodeState: (buf) => buf.isEmpty
? null
: proto.SignedContactResponse.fromBuffer(buf));
2024-02-20 17:57:05 -05:00
2024-04-01 09:04:54 -04:00
// ContactRequestInboxCubit.value(
// {required super.record,
// required this.activeAccountInfo,
// required this.contactInvitationRecord})
// : super.value(decodeState: proto.SignedContactResponse.fromBuffer);
2024-02-20 17:57:05 -05:00
static Future<DHTRecord> _open(
{required ActiveAccountInfo activeAccountInfo,
required proto.ContactInvitationRecord contactInvitationRecord}) async {
final pool = DHTRecordPool.instance;
final accountRecordKey =
activeAccountInfo.userLogin.accountRecordInfo.accountRecord.recordKey;
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);
return pool.openRecordRead(recordKey,
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 ActiveAccountInfo activeAccountInfo;
final proto.ContactInvitationRecord contactInvitationRecord;
}