feat(core): added missing fields to Message

This commit is contained in:
alina 🌸 2024-05-06 03:35:22 +03:00
parent 2a399532a3
commit f877e97d34
Signed by: teidesu
SSH key fingerprint: SHA256:uNeCpw6aTSU4aIObXLvHfLkDa82HWH9EiOj9AXOIRpI

View file

@ -57,6 +57,23 @@ export class Message {
return this.raw._ === 'message' ? this.raw.views ?? null : null return this.raw._ === 'message' ? this.raw.views ?? null : null
} }
/**
* For channel posts, number of forwards
*
* `null` for service messages and non-post messages, or
* if the current user is not an admin in the channel
*/
get forwards(): number | null {
return this.raw._ === 'message' ? this.raw.forwards ?? null : null
}
/**
* For channel posts with signatures enabled, name of the post author
*/
get signature(): string | null {
return this.raw._ === 'message' ? this.raw.postAuthor ?? null : null
}
/** /**
* Whether the message is incoming or outgoing: * Whether the message is incoming or outgoing:
* - Messages received from other chats are incoming (`outgoing = false`) * - Messages received from other chats are incoming (`outgoing = false`)
@ -87,6 +104,48 @@ export class Message {
return this.raw._ === 'message' && this.raw.offline! return this.raw._ === 'message' && this.raw.offline!
} }
/** Whether this is a silent message (no notification triggered) */
get isSilent(): boolean {
return this.raw.silent!
}
/** Whether there are unread media attachments in this message */
get hasUnreadMedia(): boolean {
return this.raw.mediaUnread!
}
/** Whether this is a broadcast channel post */
get isChannelPost(): boolean {
return this.raw._ === 'message' && this.raw.post!
}
/**
* Whether this message was automatically sent from a scheduled message.
*
* **Note**: for messages sent by other users, this is always `false`.
*/
get isFromScheduled(): boolean {
return this.raw._ === 'message' && this.raw.fromScheduled!
}
/** Whether the message is pinned in the current chat */
get isPinned(): boolean {
return this.raw._ === 'message' && this.raw.pinned!
}
/** Whether the message should be considered unedited, even if {@link editDate} ≠ null */
get hideEditMark(): boolean {
return this.raw._ === 'message' && this.raw.editHide!
}
/**
* If set, any eventual webpage preview should be shown on top of
* the message instead of at the bottom.
*/
get invertMedia(): boolean {
return this.raw._ === 'message' && this.raw.invertMedia!
}
/** /**
* Multiple media messages with the same grouped ID * Multiple media messages with the same grouped ID
* indicate an album or media group * indicate an album or media group
@ -151,12 +210,21 @@ export class Message {
} }
/** /**
* Date the message was sent * Date when the message was sent
*/ */
get date(): Date { get date(): Date {
return new Date(this.raw.date * 1000) return new Date(this.raw.date * 1000)
} }
/**
* Date when the message was last edited
*/
get editDate(): Date | null {
if (this.raw._ === 'messageService') return null
return this.raw.editDate ? new Date(this.raw.editDate * 1000) : null
}
/** /**
* If this message is a forward, contains info about it. * If this message is a forward, contains info about it.
*/ */