Not easy to reproduce. I'm only able to reproduce this bug (?) when the app has been inactive on the phone for a while (~30min) and I open chrome again.
Here's the code
import { ChangeDetectionStrategy, Component, OnChanges } from '@angular/core';
@Component({
changeDetection: ChangeDetectionStrategy.OnPush,
selector: 'zyn-base-chat',
template: 'My component'
})
export class BaseChatComponent implements OnChanges {
lastSeenPostDate: Date;
constructor(
public chatProvider: ChatProvider
) {}
async ngOnChanges() {
console.log('this is printed right away');
this.lastSeenPostDate = await this.chatProvider.getLastSeenPostDate('MY_USER_UID', 'MY_CHAT_UID');
console.log('this can appear after 30scd to 5min in the given circumstances');
}
}
The provider
import { Injectable } from '@angular/core';
import { AngularFireDatabase } from '@angular/fire/database';
import { take } from 'rxjs/operators';
@Injectable({
providedIn: 'root'
})
export class ChapterPostProvider {
constructor(
private db: AngularFireDatabase
) { }
getLastSeenPostDate(userUid: string, chapterUid: string): Promise<Date> {
return this.db.object<string>(`usersLatestChapterPostSeenDate/${userUid}/${chapterUid}`)
.valueChanges()
.pipe(take(1))
.toPromise()
.then(val => val && new Date(val));
}
}
Expected behavior
We should be able to get a data from RTDB as a Promise without waiting for 5min after the application has been inactive for 30min.
Version info
Angular: 8.2.14
Firebase: 7.6.2
AngularFire: 5.4.2
How to reproduce these conditions
Not easy to reproduce. I'm only able to reproduce this bug (?) when the app has been inactive on the phone for a while (~30min) and I open chrome again.
Here's the code
The provider
Expected behavior
We should be able to get a data from RTDB as a Promise without waiting for 5min after the application has been inactive for 30min.