mirror of
https://gitlab.com/veilid/veilidchat.git
synced 2025-01-27 16:27:08 -05:00
Merge branch 'tickupdates' into 'main'
Fix empty contact list problem See merge request veilid/veilidchat!20
This commit is contained in:
commit
975d5763b9
@ -38,6 +38,7 @@ class BackgroundTickerState extends ConsumerState<BackgroundTicker> {
|
|||||||
bool _inTick = false;
|
bool _inTick = false;
|
||||||
int _contactInvitationCheckTick = 0;
|
int _contactInvitationCheckTick = 0;
|
||||||
int _newMessageCheckTick = 0;
|
int _newMessageCheckTick = 0;
|
||||||
|
bool _hasRefreshedContactList = false;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
@ -77,6 +78,13 @@ class BackgroundTickerState extends ConsumerState<BackgroundTicker> {
|
|||||||
_inTick = true;
|
_inTick = true;
|
||||||
try {
|
try {
|
||||||
final unord = <Future<void>>[];
|
final unord = <Future<void>>[];
|
||||||
|
// If our contact list hasn't been refreshed yet, we need to
|
||||||
|
// refresh it. This happens every tick until it's non-empty.
|
||||||
|
// It will not happen until we are attached to Veilid.
|
||||||
|
if (_hasRefreshedContactList == false) {
|
||||||
|
unord.add(_doContactListRefresh());
|
||||||
|
}
|
||||||
|
|
||||||
// Check extant contact invitations once every N seconds
|
// Check extant contact invitations once every N seconds
|
||||||
_contactInvitationCheckTick += 1;
|
_contactInvitationCheckTick += 1;
|
||||||
if (_contactInvitationCheckTick >= ticksPerContactInvitationCheck) {
|
if (_contactInvitationCheckTick >= ticksPerContactInvitationCheck) {
|
||||||
@ -98,6 +106,25 @@ class BackgroundTickerState extends ConsumerState<BackgroundTicker> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Future<void> _doContactListRefresh() async {
|
||||||
|
// Don't refresh the contact list until we're connected to Veilid, because
|
||||||
|
// that's when we can actually communicate.
|
||||||
|
if (!connectionState.state.isAttached) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// Get the contact list, or an empty IList.
|
||||||
|
final contactList = ref.read(fetchContactListProvider).asData?.value ??
|
||||||
|
const IListConst([]);
|
||||||
|
if (contactList.isEmpty) {
|
||||||
|
ref.invalidate(fetchContactListProvider);
|
||||||
|
} else {
|
||||||
|
// This happens on the tick after it refreshes, because invalidation
|
||||||
|
// and refresh happens only once per tick, and we won't know if it
|
||||||
|
// worked until it has.
|
||||||
|
_hasRefreshedContactList = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Future<void> _doContactInvitationCheck() async {
|
Future<void> _doContactInvitationCheck() async {
|
||||||
if (!connectionState.state.isPublicInternetReady) {
|
if (!connectionState.state.isPublicInternetReady) {
|
||||||
return;
|
return;
|
||||||
@ -148,7 +175,9 @@ class BackgroundTickerState extends ConsumerState<BackgroundTicker> {
|
|||||||
if (!connectionState.state.isPublicInternetReady) {
|
if (!connectionState.state.isPublicInternetReady) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
final activeChat = ref.read(activeChatStateProvider);
|
final activeChat = ref.read(activeChatStateProvider);
|
||||||
|
|
||||||
if (activeChat == null) {
|
if (activeChat == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -159,7 +188,6 @@ class BackgroundTickerState extends ConsumerState<BackgroundTicker> {
|
|||||||
|
|
||||||
final contactList = ref.read(fetchContactListProvider).asData?.value ??
|
final contactList = ref.read(fetchContactListProvider).asData?.value ??
|
||||||
const IListConst([]);
|
const IListConst([]);
|
||||||
|
|
||||||
final activeChatContactIdx = contactList.indexWhere(
|
final activeChatContactIdx = contactList.indexWhere(
|
||||||
(c) =>
|
(c) =>
|
||||||
proto.TypedKeyProto.fromProto(c.remoteConversationRecordKey) ==
|
proto.TypedKeyProto.fromProto(c.remoteConversationRecordKey) ==
|
||||||
|
Loading…
x
Reference in New Issue
Block a user