mirror of
https://gitlab.com/veilid/veilidchat.git
synced 2025-07-22 14:10:37 -04:00
clean up windows and loading state
This commit is contained in:
parent
ad9a77d68f
commit
d00722433d
13 changed files with 130 additions and 175 deletions
146
lib/tick.dart
146
lib/tick.dart
|
@ -7,9 +7,6 @@ import 'package:veilid_support/veilid_support.dart';
|
|||
import 'init.dart';
|
||||
import 'veilid_processor/veilid_processor.dart';
|
||||
|
||||
const int ticksPerContactInvitationCheck = 5;
|
||||
const int ticksPerNewMessageCheck = 5;
|
||||
|
||||
class BackgroundTicker extends StatefulWidget {
|
||||
const BackgroundTicker({required this.builder, super.key});
|
||||
|
||||
|
@ -28,11 +25,6 @@ class BackgroundTicker extends StatefulWidget {
|
|||
class BackgroundTickerState extends State<BackgroundTicker> {
|
||||
Timer? _tickTimer;
|
||||
bool _inTick = false;
|
||||
bool _inDoContactInvitationCheck = false;
|
||||
bool _inDoNewMessageCheck = false;
|
||||
|
||||
int _contactInvitationCheckTick = 0;
|
||||
int _newMessageCheckTick = 0;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
|
@ -73,145 +65,9 @@ class BackgroundTickerState extends State<BackgroundTicker> {
|
|||
_inTick = true;
|
||||
try {
|
||||
// Tick DHT record pool
|
||||
if (!DHTRecordPool.instance.inTick) {
|
||||
unawaited(DHTRecordPool.instance.tick());
|
||||
}
|
||||
|
||||
// Check extant contact invitations once every N seconds
|
||||
_contactInvitationCheckTick += 1;
|
||||
if (_contactInvitationCheckTick >= ticksPerContactInvitationCheck) {
|
||||
_contactInvitationCheckTick = 0;
|
||||
if (!_inDoContactInvitationCheck) {
|
||||
unawaited(_doContactInvitationCheck());
|
||||
}
|
||||
}
|
||||
|
||||
// Check new messages once every N seconds
|
||||
_newMessageCheckTick += 1;
|
||||
if (_newMessageCheckTick >= ticksPerNewMessageCheck) {
|
||||
_newMessageCheckTick = 0;
|
||||
if (!_inDoNewMessageCheck) {
|
||||
unawaited(_doNewMessageCheck());
|
||||
}
|
||||
}
|
||||
unawaited(DHTRecordPool.instance.tick());
|
||||
} finally {
|
||||
_inTick = false;
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _doContactInvitationCheck() async {
|
||||
if (_inDoContactInvitationCheck) {
|
||||
return;
|
||||
}
|
||||
_inDoContactInvitationCheck = true;
|
||||
|
||||
if (!ProcessorRepository
|
||||
.instance.processorConnectionState.isPublicInternetReady) {
|
||||
return;
|
||||
}
|
||||
// final contactInvitationRecords =
|
||||
// await ref.read(fetchContactInvitationRecordsProvider.future);
|
||||
// if (contactInvitationRecords == null) {
|
||||
// return;
|
||||
// }
|
||||
try {
|
||||
// final activeAccountInfo =
|
||||
// await ref.read(fetchActiveAccountProvider.future);
|
||||
// if (activeAccountInfo == null) {
|
||||
// return;
|
||||
// }
|
||||
|
||||
// final allChecks = <Future<void>>[];
|
||||
// for (final contactInvitationRecord in contactInvitationRecords) {
|
||||
// allChecks.add(() async {
|
||||
// final acceptReject = await checkAcceptRejectContact(
|
||||
// activeAccountInfo: activeAccountInfo,
|
||||
// contactInvitationRecord: contactInvitationRecord);
|
||||
// if (acceptReject != null) {
|
||||
// final acceptedContact = acceptReject.acceptedContact;
|
||||
// if (acceptedContact != null) {
|
||||
// // Accept
|
||||
// await createContact(
|
||||
// activeAccountInfo: activeAccountInfo,
|
||||
// profile: acceptedContact.profile,
|
||||
// remoteIdentity: acceptedContact.remoteIdentity,
|
||||
// remoteConversationRecordKey:
|
||||
// acceptedContact.remoteConversationRecordKey,
|
||||
// localConversationRecordKey:
|
||||
// acceptedContact.localConversationRecordKey,
|
||||
// );
|
||||
// ref
|
||||
// ..invalidate(fetchContactInvitationRecordsProvider)
|
||||
// ..invalidate(fetchContactListProvider);
|
||||
// } else {
|
||||
// // Reject
|
||||
// ref.invalidate(fetchContactInvitationRecordsProvider);
|
||||
// }
|
||||
// }
|
||||
// }());
|
||||
// }
|
||||
// await Future.wait(allChecks);
|
||||
} finally {
|
||||
_inDoContactInvitationCheck = true;
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _doNewMessageCheck() async {
|
||||
if (_inDoNewMessageCheck) {
|
||||
return;
|
||||
}
|
||||
_inDoNewMessageCheck = true;
|
||||
|
||||
try {
|
||||
if (!ProcessorRepository
|
||||
.instance.processorConnectionState.isPublicInternetReady) {
|
||||
return;
|
||||
}
|
||||
// final activeChat = ref.read(activeChatStateProvider);
|
||||
// if (activeChat == null) {
|
||||
// return;
|
||||
// }
|
||||
// final activeAccountInfo =
|
||||
// await ref.read(fetchActiveAccountProvider.future);
|
||||
// if (activeAccountInfo == null) {
|
||||
// return;
|
||||
// }
|
||||
|
||||
// final contactList = ref.read(fetchContactListProvider).asData?.value ??
|
||||
// const IListConst([]);
|
||||
|
||||
// final activeChatContactIdx = contactList.indexWhere(
|
||||
// (c) =>
|
||||
// proto.TypedKeyProto.fromProto(c.remoteConversationRecordKey) ==
|
||||
// activeChat,
|
||||
// );
|
||||
// if (activeChatContactIdx == -1) {
|
||||
// return;
|
||||
// }
|
||||
// final activeChatContact = contactList[activeChatContactIdx];
|
||||
// final remoteIdentityPublicKey =
|
||||
// proto.TypedKeyProto.fromProto(activeChatContact.identityPublicKey);
|
||||
// final remoteConversationRecordKey = proto.TypedKeyProto.fromProto(
|
||||
// activeChatContact.remoteConversationRecordKey);
|
||||
// final localConversationRecordKey = proto.TypedKeyProto.fromProto(
|
||||
// activeChatContact.localConversationRecordKey);
|
||||
|
||||
// final newMessages = await getRemoteConversationMessages(
|
||||
// activeAccountInfo: activeAccountInfo,
|
||||
// remoteIdentityPublicKey: remoteIdentityPublicKey,
|
||||
// remoteConversationRecordKey: remoteConversationRecordKey);
|
||||
// if (newMessages != null && newMessages.isNotEmpty) {
|
||||
// final changed = await mergeLocalConversationMessages(
|
||||
// activeAccountInfo: activeAccountInfo,
|
||||
// localConversationRecordKey: localConversationRecordKey,
|
||||
// remoteIdentityPublicKey: remoteIdentityPublicKey,
|
||||
// newMessages: newMessages);
|
||||
// if (changed) {
|
||||
// ref.invalidate(activeConversationMessagesProvider);
|
||||
// }
|
||||
// }
|
||||
} finally {
|
||||
_inDoNewMessageCheck = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue