vaegram 0.2.0

Telegram MTProto client library for users and bots
Documentation
use crate::Client;
use crate::enums::BaseTheme;
use crate::errors::Result;
use crate::methods::accepted;
use crate::raw::{base, functions};
use crate::types::{THEME_FORMAT, Theme};

/// Request built by [`Client::install_theme`].
#[must_use = "a request does nothing until it is awaited"]
pub struct InstallTheme<'a> {
    client: &'a Client,
    theme: base::InputTheme,
    dark: bool,
    base_theme: Option<BaseTheme>,
}

impl Client {
    /// Installs a theme on the account.
    pub fn install_theme(&self, theme: &Theme) -> InstallTheme<'_> {
        InstallTheme { client: self, theme: theme.write(), dark: false, base_theme: None }
    }
}

impl InstallTheme<'_> {
    /// Installs the theme for dark mode.
    pub fn dark(mut self) -> Self {
        self.dark = true;
        self
    }

    /// Sets the built-in theme the installed one builds on.
    pub fn base_theme(mut self, base_theme: BaseTheme) -> Self {
        self.base_theme = Some(base_theme);
        self
    }

    async fn send(self) -> Result<()> {
        let request = functions::account::InstallTheme {
            dark: self.dark,
            theme: Some(self.theme),
            format: Some(THEME_FORMAT.into()),
            base_theme: self.base_theme.map(BaseTheme::write),
        };
        accepted(self.client.invoke(&request).await?)
    }
}

into_future!(InstallTheme, ());