MOBILE-3320 messages: Fix contacts page

main
Noel De Martin 2021-06-02 13:16:24 +02:00
parent 28bf6d7e87
commit c1930a39ff
1 changed files with 57 additions and 20 deletions

View File

@ -37,16 +37,18 @@ import { IonRefresher } from '@ionic/angular';
}) })
export class AddonMessagesContactsPage implements OnInit, OnDestroy { export class AddonMessagesContactsPage implements OnInit, OnDestroy {
selected = 'confirmed'; selected: 'confirmed' | 'requests' = 'confirmed';
requestsBadge = ''; requestsBadge = '';
selectedUserId?: number; // User id of the conversation opened in the split view. selectedUserId?: number; // User id of the conversation opened in the split view.
confirmedLoaded = false; confirmedLoaded = false;
confirmedInitialising = false;
confirmedCanLoadMore = false; confirmedCanLoadMore = false;
confirmedLoadMoreError = false; confirmedLoadMoreError = false;
confirmedContacts: AddonMessagesConversationMember[] = []; confirmedContacts: AddonMessagesConversationMember[] = [];
requestsLoaded = false; requestsLoaded = false;
requestsInitialising = false;
requestsCanLoadMore = false; requestsCanLoadMore = false;
requestsLoadMoreError = false; requestsLoadMoreError = false;
requests: AddonMessagesConversationMember[] = []; requests: AddonMessagesConversationMember[] = [];
@ -83,7 +85,7 @@ export class AddonMessagesContactsPage implements OnInit, OnDestroy {
this.confirmedContacts.splice(index, 1); this.confirmedContacts.splice(index, 1);
} }
} else if (data.contactRequestConfirmed) { } else if (data.contactRequestConfirmed) {
this.refreshData(); this.confirmedFetchData(true);
} }
if (data.contactRequestConfirmed || data.contactRequestDeclined) { if (data.contactRequestConfirmed || data.contactRequestDeclined) {
@ -104,25 +106,52 @@ export class AddonMessagesContactsPage implements OnInit, OnDestroy {
async ngOnInit(): Promise<void> { async ngOnInit(): Promise<void> {
AddonMessages.getContactRequestsCount(this.siteId); // Badge already updated by the observer. AddonMessages.getContactRequestsCount(this.siteId); // Badge already updated by the observer.
if (this.selected == 'confirmed') { this.selected === 'confirmed'
try { ? await this.initConfirmed()
: await this.initRequests();
}
await this.confirmedFetchData(); /**
if (this.confirmedContacts.length && CoreScreen.isTablet) { * Initialise confirmed contacts.
this.selectUser(this.confirmedContacts[0].id, true); */
} async initConfirmed(): Promise<void> {
} finally { if (this.confirmedInitialising) {
this.confirmedLoaded = true; return;
}
try {
this.confirmedInitialising = true;
await this.confirmedFetchData();
if (this.confirmedContacts.length && CoreScreen.isTablet) {
this.selectUser(this.confirmedContacts[0].id, true);
} }
} else { } finally {
try { this.confirmedInitialising = false;
await this.requestsFetchData(); this.confirmedLoaded = true;
if (this.requests.length && CoreScreen.isTablet) { }
this.selectUser(this.requests[0].id, true); }
}
} finally { /**
this.requestsLoaded = true; * Initialise contact requests.
*/
async initRequests(): Promise<void> {
if (this.requestsInitialising) {
return;
}
try {
this.requestsInitialising = true;
await this.requestsFetchData();
if (this.requests.length && CoreScreen.isTablet) {
this.selectUser(this.requests[0].id, true);
} }
} finally {
this.requestsInitialising = false;
this.requestsLoaded = true;
} }
} }
@ -228,10 +257,18 @@ export class AddonMessagesContactsPage implements OnInit, OnDestroy {
} }
selectTab(selected: string): void { selectTab(selected: string): void {
if (selected !== 'confirmed' && selected !== 'requests') {
return;
}
this.selected = selected; this.selected = selected;
if ((this.selected == 'confirmed' && !this.confirmedLoaded) || (this.selected != 'confirmed' && !this.requestsLoaded)) { if (this.selected == 'confirmed' && !this.confirmedLoaded) {
this.ngOnInit(); this.initConfirmed();
}
if (this.selected == 'requests' && !this.requestsLoaded) {
this.initRequests();
} }
} }