pub async fn load_current(mut self) -> Result<Self, InvocationError> {
        let s = self.inner_mut();
        if let Some(chan) = s.chat.try_to_input_channel() {
            let tl::enums::channels::ChannelParticipant::Participant(user) = s
                .client
                .invoke(&tl::functions::channels::GetParticipant {
                    channel: chan,
                    participant: s.peer.clone(),
                })
                .await?;
            match user.participant {
                tl::enums::ChannelParticipant::Creator(c) => {
                    s.rights = c.admin_rights.into();
                    s.rank = c.rank.unwrap_or_else(String::new);
                }
                tl::enums::ChannelParticipant::Admin(a) => {
                    s.rights = a.admin_rights.into();
                    s.rank = a.rank.unwrap_or_else(String::new);
                }
                _ => (),
            }
        } else if s.chat.try_to_chat_id().is_some() {
            let uid = match &s.user {
                tl::enums::InputUser::User(u) => u.user_id,
                tl::enums::InputUser::FromMessage(u) => u.user_id,
                _ => {
                    return Err(InvocationError::Rpc(RpcError {
                        code: 400,
                        name: "PEER_ID_INVALID".to_string(),
                        value: None,
                        caused_by: None,
                    }))
                }
            };

            let mut participants = s.client.iter_participants(s.chat);
            while let Some(participant) = participants.next().await? {
                if matches!(participant.role, Role::Creator(_) | Role::Admin(_))
                    && participant.user.id() == uid
                {
                    s.rights = tl::types::ChatAdminRights {
                        change_info: true,
                        post_messages: true,
                        edit_messages: false,
                        delete_messages: true,
                        ban_users: true,
                        invite_users: true,
                        pin_messages: true,
                        add_admins: true,
                        anonymous: false,
                        manage_call: true,
                        other: true,
                    };
                    break;
                }
            }
        }

        Ok(self)
    }
/// Load the current rights of the user. This lets you trivially grant or take away specific
/// permissions without changing any of the previous ones.
Load the current rights of the user. This lets you trivially grant or take away specific
permissions without changing any of the previous ones.
Load the current rights of the user . This lets you trivially grant or take away specific permissions without changing any of the previous ones .
pub async fn load_current(mut self) -> Result<Self, InvocationError> {
        let s = self.inner_mut();
        if let Some(chan) = s.chat.try_to_input_channel() {
            let tl::enums::channels::ChannelParticipant::Participant(user) = s
                .client
                .invoke(&tl::functions::channels::GetParticipant {
                    channel: chan,
                    participant: s.peer.clone(),
                })
                .await?;
            match user.participant {
                tl::enums::ChannelParticipant::Creator(c) => {
                    s.rights = c.admin_rights.into();
                    s.rank = c.rank.unwrap_or_else(String::new);
                }
                tl::enums::ChannelParticipant::Admin(a) => {
                    s.rights = a.admin_rights.into();
                    s.rank = a.rank.unwrap_or_else(String::new);
                }
                _ => (),
            }
        } else if s.chat.try_to_chat_id().is_some() {
            let uid = match &s.user {
                tl::enums::InputUser::User(u) => u.user_id,
                tl::enums::InputUser::FromMessage(u) => u.user_id,
                _ => {
                    return Err(InvocationError::Rpc(RpcError {
                        code: 400,
                        name: "PEER_ID_INVALID".to_string(),
                        value: None,
                        caused_by: None,
                    }))
                }
            };
            let mut participants = s.client.iter_participants(s.chat);
            while let Some(participant) = participants.next().await? {
                if matches!(participant.role, Role::Creator(_) | Role::Admin(_))
                    && participant.user.id() == uid
                {
                    s.rights = tl::types::ChatAdminRights {
                        change_info: true,
                        post_messages: true,
                        edit_messages: false,
                        delete_messages: true,
                        ban_users: true,
                        invite_users: true,
                        pin_messages: true,
                        add_admins: true,
                        anonymous: false,
                        manage_call: true,
                        other: true,
                    };
                    break;
                }
            }
        }
        Ok(self)
    }
pub async fn load_current ( mut self ) -> Result < Self , InvocationError > { let s = self . inner_mut ( ) ; if let Some ( chan ) = s . chat . try_to_input_channel ( ) { let tl :: enums :: channels :: ChannelParticipant :: Participant ( user ) = s . client . invoke ( & tl :: functions :: channels :: GetParticipant { channel : chan , participant : s . peer . clone ( ) , } ) . await ? ; match user . participant { tl :: enums :: ChannelParticipant :: Creator ( c ) => { s . rights = c . admin_rights . into ( ) ; s . rank = c . rank . unwrap_or_else ( String :: new ) ; } tl :: enums :: ChannelParticipant :: Admin ( a ) => { s . rights = a . admin_rights . into ( ) ; s . rank = a . rank . unwrap_or_else ( String :: new ) ; } _ => ( ) , } } else if s . chat . try_to_chat_id ( ) . is_some ( ) { let uid = match & s . user { tl :: enums :: InputUser :: User ( u ) => u . user_id , tl :: enums :: InputUser :: FromMessage ( u ) => u . user_id , _ => { return Err ( InvocationError :: Rpc ( RpcError { code : 400 , name : " " . to_string ( ) , value : None , caused_by : None , } ) ) } } ; let mut participants = s . client . iter_participants ( s . chat ) ; while let Some ( participant ) = participants . next ( ) . await ? { if matches ! ( participant role Role Creator ( ) Role Admin ( ) ) && participant . user . id ( ) == uid { s . rights = tl :: types :: ChatAdminRights { change_info : true , post_messages : true , edit_messages : false , delete_messages : true , ban_users : true , invite_users : true , pin_messages : true , add_admins : true , anonymous : false , manage_call : true , other : true , } ; break ; } } } Ok ( self ) }
Load the current rights of the user.
Load the current rights of the user .
mut self
mut self