forked from jmug/stoatchat
Servers: Fetch and edit members.
Permissions: Use bit representation for permissions.
This commit is contained in:
@@ -9,12 +9,12 @@ use std::ops;
|
||||
#[derive(Debug, PartialEq, Eq, TryFromPrimitive, Copy, Clone)]
|
||||
#[repr(u32)]
|
||||
pub enum ChannelPermission {
|
||||
View = 1,
|
||||
SendMessage = 2,
|
||||
ManageMessages = 4,
|
||||
ManageChannel = 8,
|
||||
VoiceCall = 16,
|
||||
InviteOthers = 32,
|
||||
View = 0b00000000000000000000000000000001, // 1
|
||||
SendMessage = 0b00000000000000000000000000000010, // 2
|
||||
ManageMessages = 0b00000000000000000000000000000100, // 4
|
||||
ManageChannel = 0b00000000000000000000000000001000, // 8
|
||||
VoiceCall = 0b00000000000000000000000000010000, // 16
|
||||
InviteOthers = 0b00000000000000000000000000100000, // 32
|
||||
}
|
||||
|
||||
impl_op_ex!(+ |a: &ChannelPermission, b: &ChannelPermission| -> u32 { *a as u32 | *b as u32 });
|
||||
|
||||
@@ -8,8 +8,15 @@ use std::ops;
|
||||
#[derive(Debug, PartialEq, Eq, TryFromPrimitive, Copy, Clone)]
|
||||
#[repr(u32)]
|
||||
pub enum ServerPermission {
|
||||
View = 1,
|
||||
ManageServer = 8,
|
||||
View = 0b00000000000000000000000000000001, // 1
|
||||
// 2 bits of space
|
||||
ManageServer = 0b00000000000000000000000000001000, // 8
|
||||
// 8 bits of space
|
||||
ChangeNickname = 0b00000000000000000001000000000000, // 4096
|
||||
ManageNicknames = 0b00000000000000000010000000000000, // 8192
|
||||
ChangeAvatar = 0b00000000000000000100000000000000, // 16392
|
||||
RemoveAvatars = 0b00000000000000001000000000000000, // 32784
|
||||
// 16 bits of space
|
||||
}
|
||||
|
||||
impl_op_ex!(+ |a: &ServerPermission, b: &ServerPermission| -> u32 { *a as u32 | *b as u32 });
|
||||
@@ -20,6 +27,11 @@ bitfield! {
|
||||
u32;
|
||||
pub get_view, _: 31;
|
||||
pub get_manage_server, _: 28;
|
||||
|
||||
pub get_change_nickname, _: 19;
|
||||
pub get_manage_nicknames, _: 18;
|
||||
pub get_change_avatar, _: 17;
|
||||
pub get_remove_avatars, _: 16;
|
||||
}
|
||||
|
||||
impl<'a> PermissionCalculator<'a> {
|
||||
@@ -33,7 +45,7 @@ impl<'a> PermissionCalculator<'a> {
|
||||
if self.perspective.id == server.owner {
|
||||
Ok(u32::MAX)
|
||||
} else {
|
||||
Ok(ServerPermission::View as u32)
|
||||
Ok(ServerPermission::View + ServerPermission::ChangeNickname + ServerPermission::ChangeAvatar)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -10,10 +10,10 @@ use std::ops;
|
||||
#[derive(Debug, PartialEq, Eq, TryFromPrimitive, Copy, Clone)]
|
||||
#[repr(u32)]
|
||||
pub enum UserPermission {
|
||||
Access = 1,
|
||||
ViewProfile = 2,
|
||||
SendMessage = 4,
|
||||
Invite = 8,
|
||||
Access = 0b00000000000000000000000000000001, // 1
|
||||
ViewProfile = 0b00000000000000000000000000000010, // 2
|
||||
SendMessage = 0b00000000000000000000000000000100, // 4
|
||||
Invite = 0b00000000000000000000000000001000, // 8
|
||||
}
|
||||
|
||||
bitfield! {
|
||||
|
||||
Reference in New Issue
Block a user