Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: pronouns #258

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions crates/core/database/src/models/users/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ auto_derived_partial!(
/// Bot information
#[serde(skip_serializing_if = "Option::is_none")]
pub bot: Option<BotInformation>,

// User's displayed pronouns
#[serde(skip_serializing_if = "Option::is_none")]
pub pronouns: Option<Vec<String>>,
},
"PartialUser"
);
Expand Down Expand Up @@ -114,6 +118,7 @@ auto_derived!(
StatusPresence,
ProfileContent,
ProfileBackground,
Pronouns,
}
);

Expand Down Expand Up @@ -180,6 +185,7 @@ impl User {
x.background = None;
}
}
FieldsUser::Pronouns => self.pronouns = None,
}
}

Expand All @@ -198,6 +204,7 @@ impl User {
FieldsUser::StatusPresence,
FieldsUser::ProfileContent,
FieldsUser::ProfileBackground,
FieldsUser::Pronouns,
],
)
.await
Expand Down
1 change: 1 addition & 0 deletions crates/core/database/src/models/users/ops/mongodb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,7 @@ impl IntoDocumentPath for FieldsUser {
FieldsUser::ProfileContent => "profile.content",
FieldsUser::StatusPresence => "status.presence",
FieldsUser::StatusText => "status.text",
FieldsUser::Pronouns => "pronouns",
})
}
}
3 changes: 3 additions & 0 deletions crates/core/database/src/util/bridge/v0.rs
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,9 @@ impl crate::User {
relationship,
online: can_see_profile && revolt_presence::is_online(&self.id).await,
id: self.id,
pronouns: self
.pronouns
.map(|pronouns| pronouns.iter().map(|pronoun| pronoun.to_owned()).collect()),
}
}
}
Expand Down
3 changes: 3 additions & 0 deletions crates/core/models/src/v0/users.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ auto_derived!(
#[serde(skip_serializing_if = "Option::is_none")]
pub bot: Option<BotInformation>,

// User's displayed pronouns
#[serde(skip_serializing_if = "Option::is_none")]
pub pronouns: Option<Vec<String>>,
/// Current session user's relationship with this user
pub relationship: RelationshipStatus,
/// Whether this user is currently online
Expand Down
7 changes: 7 additions & 0 deletions crates/delta/src/routes/users/edit_user.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@ pub struct DataEditUser {
/// Fields to remove from user object
#[validate(length(min = 1))]
remove: Option<Vec<FieldsUser>>,

// User's displayed pronouns
#[cfg_attr(feature = "validator", validate(length(min = 1, max = 5)))]
#[serde(skip_serializing_if = "Option::is_none")]
pub pronouns: Option<Vec<String>>,
}

/// # Edit User
Expand Down Expand Up @@ -96,6 +101,7 @@ pub async fn req(
&& data.badges.is_none()
&& data.flags.is_none()
&& data.remove.is_none()
&& data.pronouns.is_none()
{
return Ok(Json(user));
}
Expand Down Expand Up @@ -125,6 +131,7 @@ pub async fn req(
display_name: data.display_name,
badges: data.badges,
flags: data.flags,
pronouns: data.pronouns,
..Default::default()
};

Expand Down
1 change: 1 addition & 0 deletions crates/quark/src/impl/generic/users/user.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ impl User {
}
}
FieldsUser::DisplayName => self.display_name = None,
FieldsUser::Pronouns => self.pronouns = None,
}
}

Expand Down
1 change: 1 addition & 0 deletions crates/quark/src/impl/mongo/users/user.rs
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,7 @@ impl IntoDocumentPath for FieldsUser {
FieldsUser::StatusPresence => "status.presence",
FieldsUser::StatusText => "status.text",
FieldsUser::DisplayName => "display_name",
FieldsUser::Pronouns => "pronouns",
})
}
}
6 changes: 6 additions & 0 deletions crates/quark/src/models/users/user.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,11 @@ pub struct User {
/// Whether this user is currently online
#[serde(skip_serializing_if = "Option::is_none")]
pub online: Option<bool>,

// User's displayed pronouns
#[cfg_attr(feature = "validator", validate(length(min = 1, max = 5)))]
#[serde(skip_serializing_if = "Option::is_none")]
pub pronouns: Option<Vec<String>>,
}

/// Optional fields on user object
Expand All @@ -178,6 +183,7 @@ pub enum FieldsUser {
ProfileContent,
ProfileBackground,
DisplayName,
Pronouns,
}

/// Enumeration providing a hint to the type of user we are handling
Expand Down