refactor(core/models): swap dependency order with db
feat(core/models): implement webhook model
This commit is contained in:
@@ -158,109 +158,3 @@ impl CheckRelationship for Vec<Relationship> {
|
||||
RelationshipStatus::None
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "from_database")]
|
||||
impl User {
|
||||
pub async fn from<P>(user: revolt_database::User, perspective: P) -> Self
|
||||
where
|
||||
P: Into<Option<revolt_database::User>>,
|
||||
{
|
||||
let relationship = if let Some(perspective) = perspective.into() {
|
||||
perspective
|
||||
.relations
|
||||
.unwrap_or_default()
|
||||
.into_iter()
|
||||
.find(|relationship| relationship.id == user.id)
|
||||
.map(|relationship| relationship.status.into())
|
||||
.unwrap_or_default()
|
||||
} else {
|
||||
RelationshipStatus::None
|
||||
};
|
||||
|
||||
// do permission stuff here
|
||||
// TODO: implement permissions =)
|
||||
let can_see_profile = false;
|
||||
|
||||
Self {
|
||||
username: user.username,
|
||||
avatar: user.avatar.map(|file| file.into()),
|
||||
relations: vec![],
|
||||
badges: user.badges.unwrap_or_default() as u32,
|
||||
status: None,
|
||||
profile: None,
|
||||
flags: user.flags.unwrap_or_default() as u32,
|
||||
privileged: user.privileged,
|
||||
bot: user.bot.map(|bot| bot.into()),
|
||||
relationship,
|
||||
online: can_see_profile && revolt_presence::is_online(&user.id).await,
|
||||
id: user.id,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "from_database")]
|
||||
impl From<revolt_database::RelationshipStatus> for RelationshipStatus {
|
||||
fn from(value: revolt_database::RelationshipStatus) -> Self {
|
||||
match value {
|
||||
revolt_database::RelationshipStatus::None => RelationshipStatus::None,
|
||||
revolt_database::RelationshipStatus::User => RelationshipStatus::User,
|
||||
revolt_database::RelationshipStatus::Friend => RelationshipStatus::Friend,
|
||||
revolt_database::RelationshipStatus::Outgoing => RelationshipStatus::Outgoing,
|
||||
revolt_database::RelationshipStatus::Incoming => RelationshipStatus::Incoming,
|
||||
revolt_database::RelationshipStatus::Blocked => RelationshipStatus::Blocked,
|
||||
revolt_database::RelationshipStatus::BlockedOther => RelationshipStatus::BlockedOther,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "from_database")]
|
||||
impl From<revolt_database::Relationship> for Relationship {
|
||||
fn from(value: revolt_database::Relationship) -> Self {
|
||||
Self {
|
||||
user_id: value.id,
|
||||
status: value.status.into(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "from_database")]
|
||||
impl From<revolt_database::Presence> for Presence {
|
||||
fn from(value: revolt_database::Presence) -> Self {
|
||||
match value {
|
||||
revolt_database::Presence::Online => Presence::Online,
|
||||
revolt_database::Presence::Idle => Presence::Idle,
|
||||
revolt_database::Presence::Focus => Presence::Focus,
|
||||
revolt_database::Presence::Busy => Presence::Busy,
|
||||
revolt_database::Presence::Invisible => Presence::Invisible,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "from_database")]
|
||||
impl From<revolt_database::UserStatus> for UserStatus {
|
||||
fn from(value: revolt_database::UserStatus) -> Self {
|
||||
UserStatus {
|
||||
text: value.text,
|
||||
presence: value.presence.map(|presence| presence.into()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "from_database")]
|
||||
impl From<revolt_database::UserProfile> for UserProfile {
|
||||
fn from(value: revolt_database::UserProfile) -> Self {
|
||||
UserProfile {
|
||||
content: value.content,
|
||||
background: value.background.map(|file| file.into()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "from_database")]
|
||||
impl From<revolt_database::BotInformation> for BotInformation {
|
||||
fn from(value: revolt_database::BotInformation) -> Self {
|
||||
BotInformation {
|
||||
owner_id: value.owner,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user