Struct wicrs_server::hub::Hub[][src]

pub struct Hub {
    pub channels: HashMap<ID, Channel>,
    pub members: HashMap<ID, HubMember>,
    pub bans: HashSet<ID>,
    pub mutes: HashSet<ID>,
    pub owner: ID,
    pub groups: HashMap<ID, PermissionGroup>,
    pub default_group: ID,
    pub name: String,
    pub id: ID,
    pub created: u128,
}

Represents a group of users, permission groups and channels.

Fields

channels: HashMap<ID, Channel>

Map of channels to their IDs.

members: HashMap<ID, HubMember>

Map of hub members to their corresponding user’s IDs.

bans: HashSet<ID>

List of IDs of all users that are banned from the hub.

mutes: HashSet<ID>

List of IDs of all the users who cannot send any messages in the hub.

owner: ID

ID of the user who owns the hub, also the creator.

groups: HashMap<ID, PermissionGroup>

Map of permission groups to their IDs.

default_group: ID

ID of the default permission group to be given to new hub members, for now this is always the “everyone” group.

name: String

Name of the hub.

id: ID

ID of the hub.

created: u128

Time the hub was created in milliseconds since Unix Epoch.

Implementations

impl Hub[src]

pub fn new(name: String, id: ID, creator: &User) -> Self[src]

Creates a new hub given the ID of the user who should be the owner, the name and the ID the hub should have.

pub async fn new_channel(&mut self, member_id: &ID, name: String) -> Result<ID>[src]

Creates a new channel.

Errors

This function will return an error in the following situations, but is not limited to just these cases:

pub fn get_channel(&self, member_id: &ID, channel_id: &ID) -> Result<&Channel>[src]

Gets a reference to the channel. Returns an error if the channel could not be found or the user did not have permission to view the channel.

pub fn get_channel_mut(
    &mut self,
    member_id: &ID,
    channel_id: &ID
) -> Result<&mut Channel>
[src]

Gets a mutable reference to the channel. Returns an error if the channel could not be found or the user did not have permission to view the channel.

pub fn get_member(&self, member_id: &ID) -> Result<HubMember>[src]

Gets a reference to the hub member, returns an error if the member could not be found.

pub fn get_member_mut(&mut self, member_id: &ID) -> Result<&mut HubMember>[src]

Gets a mutable reference to the hub member, returns an error if the member could not be found.

pub async fn rename_channel(
    &mut self,
    user_id: &ID,
    channel_id: &ID,
    name: String
) -> Result<String>
[src]

Renames a channel.

Errors

This function will return an error in the following situations, but is not limited to just these cases:

  • Failed to pass check_name_validity.
  • The user it not in the hub.
  • The user does not have permission to view the channel.
  • The user does not have permission to configure (rename) the channel.
  • The channel does not exist.

pub async fn delete_channel(
    &mut self,
    user_id: &ID,
    channel_id: &ID
) -> Result<()>
[src]

Deletes a channel while checking that the given user has permission to view it and to delete it.

Errors

This function will return an error in the following situations, but is not limited to just these cases:

  • The user is not in the hub.
  • The channel does not exist.
  • THe user does not have permission to view the channel.
  • The user does not have permission to delete the channel.

pub async fn send_message(
    &mut self,
    user_id: &ID,
    channel_id: &ID,
    message: String
) -> Result<ID>
[src]

Sends a message as a user while checking that the user has permission to view the given channel and to write to it.

Errors

This function will return an error in the following situations, but is not limited to just these cases:

  • The user is not in the hub.
  • THe user is muted and cannot send messages.
  • The channel does not exist.
  • The user does not have permission to view the channel.
  • The user does not have permission to send messages in the channel.
  • The message could not be added to the channel for any of the reasons outlined in Channel::add_message.

pub fn get_info_path(&self) -> String[src]

Gets the file path to be used for storing the hub’s data.

pub fn get_data_path(&self) -> String[src]

Gets the path of the directory in which channel folders should be stored.

pub async fn save(&self) -> Result<()>[src]

Saves the hub’s data to disk.

Errors

This function will return an error in the following situations, but is not limited to just these cases:

  • The hub data could not be serialized.
  • The hub info folder does not exist and could not be created.
  • The data could not be written to the disk.

pub async fn load(id: &ID) -> Result<Self>[src]

Loads a hub’s data given its ID.

Errors

This function will return an error in the following situations, but is not limited to just these cases:

  • There is no hub with that ID.
  • The hub’s data file was corrupt and could not be deserialized.

pub fn user_join(&mut self, user: &User) -> Result<HubMember>[src]

Adds a user to a hub, creating and returning the resulting hub member.

Errors

This function will return an error in the following situations, but is not limited to just this case:

  • The default permission group could not be found.

pub fn user_leave(&mut self, user: &User) -> Result<()>[src]

Removes the given user from the hub.

Errors

This function will return an error in the following situations, but is not limited to just these cases:

  • The user is not in the hub.
  • One of the permission groups the user was in could not be found in the hub.

pub async fn kick_user(&mut self, user_id: &ID) -> Result<()>[src]

Kicks the given user from the hub, forcing them to leave.

Errors

This function will return an error in the following situations, but is not limited to just these cases:

  • The user could not be removed from the hub for any of the reasons outlined in Hub::user_leave.
  • The user’s data failed to load for any of the reasons outlined in User::load.
  • The user’s data failed to save for any of the reasons outlined in User::save.

pub async fn ban_user(&mut self, user_id: ID) -> Result<()>[src]

Kicks the given user and adds them to the banned list.

Errors

Possible errors outlined by Hub::kick_user.

pub fn unban_user(&mut self, user_id: &ID)[src]

Removes the given user from the banned lis.

pub fn mute_user(&mut self, user_id: ID)[src]

Adds the given user to the mute list, preventing them from sending messages.

pub fn unmute_user(&mut self, user_id: &ID)[src]

Removes the given user from the mutes list, allowing them to send messages.

pub fn get_channels_for_user(
    &self,
    user_id: &ID
) -> Result<HashMap<ID, Channel>>
[src]

Gets a list of the channels that the given user has permission to view.

Errors

This function will only return an error if the given user is not in the hub.

pub fn strip(&self, user_id: &ID) -> Result<Self>[src]

Returns a hub object with only the items that the given user is allowed to view. Only hides channels that the user does not have permission to view.

Errors

Possible errors are outlined by Hub::get_channels_for_user.

Trait Implementations

impl Clone for Hub[src]

impl Debug for Hub[src]

impl<'de> Deserialize<'de> for Hub[src]

impl PartialEq<Hub> for Hub[src]

impl Serialize for Hub[src]

impl StructuralPartialEq for Hub[src]

Auto Trait Implementations

impl RefUnwindSafe for Hub

impl Send for Hub

impl Sync for Hub

impl Unpin for Hub

impl UnwindSafe for Hub

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> DeserializeOwned for T where
    T: for<'de> Deserialize<'de>, 
[src]

impl<T> From<T> for T[src]

impl<T> Instrument for T[src]

impl<T> Instrument for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> Pointable for T

type Init = T

The type for initializers.

impl<T> Same<T> for T

type Output = T

Should always be Self

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 

type Err = <U as TryFrom<T>>::Err

impl<V, T> VZip<V> for T where
    V: MultiLane<T>,