vaegram 0.2.0

Telegram MTProto client library for users and bots
Documentation
use crate::Client;
use crate::errors::Result;
use crate::raw::{base, functions};
use crate::types::{ChatBackground, PeerRef};

/// Request built by [`Client::set_chat_wallpaper`].
#[must_use = "a request does nothing until it is awaited"]
pub struct SetChatWallpaper<'a> {
    client: &'a Client,
    chat_id: PeerRef,
    wallpaper: base::InputWallPaper,
    settings: base::WallPaperSettings,
    for_both: bool,
}

impl Client {
    /// Sets the wallpaper of a chat from a [`ChatBackground`].
    pub fn set_chat_wallpaper(&self, chat_id: impl Into<PeerRef>, wallpaper: &ChatBackground) -> SetChatWallpaper<'_> {
        let (settings, wallpaper) = (wallpaper.write_settings(), wallpaper.write());
        SetChatWallpaper { client: self, chat_id: chat_id.into(), wallpaper, settings, for_both: false }
    }
}

impl SetChatWallpaper<'_> {
    /// Applies the wallpaper for the other user in the chat too.
    pub fn for_both(mut self) -> Self {
        self.for_both = true;
        self
    }

    async fn send(self) -> Result<()> {
        let request = functions::messages::SetChatWallPaper {
            for_both: self.for_both,
            revert: false,
            peer: self.client.resolve_peer(self.chat_id).await?,
            wallpaper: Some(self.wallpaper),
            settings: Some(self.settings),
            id: None,
        };
        self.client.invoke(&request).await?;
        Ok(())
    }
}

into_future!(SetChatWallpaper, ());