mirror of
https://github.com/stoatchat/stoatchat.git
synced 2026-07-14 21:47:02 +00:00
Breaking: Provide new user object instead of id.
Fix rustup complaining about join macros.
This commit is contained in:
@@ -82,6 +82,8 @@ pub struct User {
|
||||
impl User {
|
||||
/// Mutate the user object to include relationship as seen by user.
|
||||
pub fn from(mut self, user: &User) -> User {
|
||||
self.relationship = Some(RelationshipStatus::None);
|
||||
|
||||
if self.id == user.id {
|
||||
self.relationship = Some(RelationshipStatus::User);
|
||||
return self;
|
||||
@@ -102,12 +104,26 @@ impl User {
|
||||
pub fn with(mut self, permissions: UserPermissions<[u32; 1]>) -> User {
|
||||
if permissions.get_view_profile() {
|
||||
self.online = Some(is_online(&self.id));
|
||||
} else {
|
||||
self.status = None;
|
||||
}
|
||||
|
||||
self.profile = None;
|
||||
self
|
||||
}
|
||||
|
||||
/// Mutate the user object to appear as seen by user.
|
||||
/// Also overrides the relationship status.
|
||||
pub async fn from_override(mut self, user: &User, relationship: RelationshipStatus) -> Result<User> {
|
||||
let permissions = PermissionCalculator::new(&user)
|
||||
.with_relationship(&relationship)
|
||||
.for_user(&self.id).await?;
|
||||
|
||||
self.relations = None;
|
||||
self.relationship = Some(relationship);
|
||||
Ok(self.with(permissions))
|
||||
}
|
||||
|
||||
/// Utility function for checking claimed usernames.
|
||||
pub async fn is_username_taken(username: &str) -> Result<bool> {
|
||||
if username.to_lowercase() == "revolt" && username.to_lowercase() == "admin" {
|
||||
|
||||
@@ -9,6 +9,7 @@ pub struct PermissionCalculator<'a> {
|
||||
perspective: &'a User,
|
||||
|
||||
user: Option<&'a User>,
|
||||
relationship: Option<&'a RelationshipStatus>,
|
||||
channel: Option<&'a Channel>,
|
||||
|
||||
has_mutual_connection: bool,
|
||||
@@ -20,6 +21,7 @@ impl<'a> PermissionCalculator<'a> {
|
||||
perspective,
|
||||
|
||||
user: None,
|
||||
relationship: None,
|
||||
channel: None,
|
||||
|
||||
has_mutual_connection: false,
|
||||
@@ -33,6 +35,13 @@ impl<'a> PermissionCalculator<'a> {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn with_relationship(self, relationship: &'a RelationshipStatus) -> PermissionCalculator {
|
||||
PermissionCalculator {
|
||||
relationship: Some(&relationship),
|
||||
..self
|
||||
}
|
||||
}
|
||||
|
||||
pub fn with_channel(self, channel: &'a Channel) -> PermissionCalculator {
|
||||
PermissionCalculator {
|
||||
channel: Some(&channel),
|
||||
|
||||
@@ -49,7 +49,7 @@ impl<'a> PermissionCalculator<'a> {
|
||||
}
|
||||
|
||||
let mut permissions: u32 = 0;
|
||||
match get_relationship(&self.perspective, &target) {
|
||||
match self.relationship.clone().map(|v| v.to_owned()).unwrap_or_else(|| get_relationship(&self.perspective, &target)) {
|
||||
RelationshipStatus::Friend => return Ok(u32::MAX),
|
||||
RelationshipStatus::Blocked | RelationshipStatus::BlockedOther => {
|
||||
return Ok(UserPermission::Access as u32)
|
||||
|
||||
Reference in New Issue
Block a user