diff --git a/Sources/TelegramVaporBot/Bot/Telegram/ModelExtensions/TGMaybeInaccessibleMessageExtensions.swift b/Sources/TelegramVaporBot/Bot/Telegram/ModelExtensions/TGMaybeInaccessibleMessageExtensions.swift new file mode 100644 index 0000000..e46f1a0 --- /dev/null +++ b/Sources/TelegramVaporBot/Bot/Telegram/ModelExtensions/TGMaybeInaccessibleMessageExtensions.swift @@ -0,0 +1,37 @@ +// Telegram-vapor-bot - Telegram Bot Swift SDK. + +/** + This extension adds common properties betwwen TGMessage and TGInaccessibleMessage (chat, messageId and date) to TGMaybeInaccessibleMessage. These properties are always accessible no mather TGInaccessibleMessage is TGMessage or TGInaccessibleMessage. + + SeeAlso Telegram Bot API Reference: + [MaybeInaccessibleMessage](https://core.telegram.org/bots/api#maybeinaccessiblemessage) + **/ + +public extension TGMaybeInaccessibleMessage { + var chat: TGChat { + switch self { + case .inaccessibleMessage(let msg): + return msg.chat + case .message(let msg): + return msg.chat + } + } + + var messageId: Int { + switch self { + case .inaccessibleMessage(let msg): + return msg.messageId + case .message(let msg): + return msg.messageId + } + } + + var date: Int { + switch self { + case .inaccessibleMessage(let msg): + return msg.date + case .message(let msg): + return msg.date + } + } +}