return chat messages from history fetch only if new found

This commit is contained in:
Felicio Mununga 2022-06-09 19:22:58 +02:00
parent 2ac11ab094
commit c84ed7ac7b
No known key found for this signature in database
GPG Key ID: 0EB8D75C775AB6F1
1 changed files with 16 additions and 3 deletions

View File

@ -114,12 +114,15 @@ export class Community {
const endTime = new Date() const endTime = new Date()
const _messages = this.channelMessages[channelId] || [] const _messages = this.channelMessages[channelId] || []
let _oldestMessageTime: Date | undefined = undefined
if (_messages.length) { if (_messages.length) {
const oldestMessageTime = new Date(Number(_messages[0].timestamp)) _oldestMessageTime = new Date(Number(_messages[0].timestamp))
if (oldestMessageTime <= options.start) { if (_oldestMessageTime <= options.start) {
callback(_messages) callback(_messages)
return
} }
} }
@ -140,8 +143,18 @@ export class Community {
}, },
}) })
// todo: call abck only if oldestMessageTime has changed
// callback // callback
if (
_oldestMessageTime &&
this.channelMessages[channelId]?.length &&
_oldestMessageTime >=
new Date(Number(this.channelMessages[channelId]![0].timestamp))
) {
callback([])
return
}
callback(this.channelMessages[channelId] ?? []) callback(this.channelMessages[channelId] ?? [])
} }
} }