Lonami / grammers

(tele)gramme.rs - use Telegram's API from Rust
https://t.me/gramme_rs
Apache License 2.0
561 stars 116 forks source link

Add a method to allow using TL types for media in InputMessage #283

Closed er-azh closed 1 month ago

er-azh commented 1 month ago

Adds two new methods to InputMessage , photo_id and document_id. These new methods allow the user to include media in their messages using InputPhoto and InputDocument without having to copy the media from a message or re-uploading.

er-azh commented 1 month ago

Hmmm, what about adding something like this and then adding into_document and into_photo to Uploaded instead?

pub fn media<T: Into<tl::enums::InputMedia>>(mut self, media: T) -> Self {
    self.media = Some(media.into());
    self
}

The issue with using a generic parameter for the current document and photo methods is that I can't think of a way to differentiate between the media types (eg. InputMediaPhoto and InputMediaDocument) while accepting both uploaded and forwarded variants of InputMedia (eg. InputMediaPhoto and InputMediaUploadedPhoto) without adding at least one unnecessary wrapper type.

Lonami commented 1 month ago

I was thinking of two traits, IntoInputPhoto and IntoInputDocument, both implemented for Uploaded, but only one for the raw types.

er-azh commented 1 month ago

I've updated everything based on the telegram discussion.