fix(core)!: nullable lastMessage in Dialog

This commit is contained in:
alina 🌸 2024-05-30 17:43:58 +03:00
parent 974739f2d5
commit c39be7dcd3
Signed by: teidesu
SSH key fingerprint: SHA256:uNeCpw6aTSU4aIObXLvHfLkDa82HWH9EiOj9AXOIRpI
2 changed files with 7 additions and 5 deletions

View file

@ -253,7 +253,10 @@ export async function* iterDialogs(
const last = dialogs[dialogs.length - 1]
offsetPeer = last.chat.inputPeer
offsetId = last.raw.topMessage
offsetDate = last.lastMessage.raw.date
if (last.lastMessage) {
offsetDate = last.lastMessage.raw.date
}
for (const d of dialogs) {
if (filterFolder && !filterFolder(d)) continue

View file

@ -4,7 +4,6 @@ import { getMarkedPeerId } from '../../../utils/peer-utils.js'
import { assertTypeIsNot, hasValueAtKey } from '../../../utils/type-assertions.js'
import { makeInspectable } from '../../utils/index.js'
import { memoizeGetters } from '../../utils/memoize.js'
import { MtMessageNotFoundError } from '../errors.js'
import { Chat } from '../peers/chat.js'
import { PeersIndex } from '../peers/peers-index.js'
import { DraftMessage } from './draft-message.js'
@ -198,16 +197,16 @@ export class Dialog {
}
/**
* The latest message sent in this chat
* The latest message sent in this chat (if any)
*/
get lastMessage(): Message {
get lastMessage(): Message | null {
const cid = this.chat.id
if (this._messages.has(cid)) {
return new Message(this._messages.get(cid)!, this._peers)
}
throw new MtMessageNotFoundError(cid, 0)
return null
}
/**