made the message page counter to only increment if the current requested page was not empty

This commit is contained in:
nova 2019-12-13 19:24:00 +05:30
parent d927f3441a
commit ddc7f15498

View File

@ -67,18 +67,18 @@ export class ChatModel implements Subject {
}
public async getMessages(contactName: string, passphrase: string, lastMessageTime: string | null): Promise<ChatMessageViewModel[]> {
if(this._messagePageMap.get(contactName) == null)
if (this._messagePageMap.get(contactName) == null)
this._messagePageMap.set(contactName, 0);
else {
log.debug('page number before = ' + this._messagePageMap.get(contactName)!)
this._messagePageMap.set(contactName, this._messagePageMap.get(contactName)! + 1);
log.debug('page number after = ' + this._messagePageMap.get(contactName)!)
}
const pageNumber = this._messagePageMap.get(contactName)
// else {
// log.debug('page number before = ' + this._messagePageMap.get(contactName)!)
// this._messagePageMap.set(contactName, this._messagePageMap.get(contactName)! + 1);
// log.debug('page number after = ' + this._messagePageMap.get(contactName)!)
// }
const pageNumber = this._messagePageMap.get(contactName)
const cVMs = await ChatModelHelper.getMessages(contactName, passphrase, pageNumber!, lastMessageTime, this);
if (cVMs != null) {
log.info('Subject: My state has just changed')
// this._messagesMap.set(userName, cVMs);
const existingMessages = this.getStoredUserMessages(contactName);
log.debug(existingMessages);
@ -101,6 +101,11 @@ export class ChatModel implements Subject {
else {
log.error('Messages were null');
}
if (cVMs.length != 0) {
// log.debug('page number before = ' + this._messagePageMap.get(contactName)!)
this._messagePageMap.set(contactName, this._messagePageMap.get(contactName)! + 1);
// log.debug('page number after = ' + this._messagePageMap.get(contactName)!)
}
return cVMs;
}