Online status #43
3 changed files with 40 additions and 1 deletions
|
@ -49,6 +49,7 @@ struct NewInfo {
|
|||
email: Option<String>,
|
||||
pronouns: Option<String>,
|
||||
about: Option<String>,
|
||||
online_status: Option<i16>,
|
||||
}
|
||||
|
||||
pub async fn update(
|
||||
|
@ -110,5 +111,10 @@ pub async fn update(
|
|||
.await?;
|
||||
}
|
||||
|
||||
if let Some(online_status) = &json.online_status {
|
||||
me.set_online_status(&mut conn, &app_state.cache_pool, *online_status)
|
||||
.await?;
|
||||
}
|
||||
|
||||
Ok(StatusCode::OK)
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
use axum::body::Bytes;
|
||||
use axum::{body::Bytes, http::StatusCode};
|
||||
use diesel::{
|
||||
ExpressionMethods, QueryDsl, Queryable, Selectable, SelectableHelper, delete, insert_into,
|
||||
update,
|
||||
|
@ -29,6 +29,7 @@ pub struct Me {
|
|||
avatar: Option<String>,
|
||||
pronouns: Option<String>,
|
||||
about: Option<String>,
|
||||
online_status: i16,
|
||||
pub email: String,
|
||||
pub email_verified: bool,
|
||||
}
|
||||
|
@ -277,6 +278,35 @@ impl Me {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
pub async fn set_online_status(
|
||||
&mut self,
|
||||
conn: &mut Conn,
|
||||
cache_pool: &redis::Client,
|
||||
new_status: i16,
|
||||
) -> Result<(), Error> {
|
||||
if new_status > 4 && new_status < 0 {
|
||||
return Err(Error::BadRequest("Invalid status code".to_string()));
|
||||
}
|
||||
self.online_status = new_status;
|
||||
|
||||
use users::dsl;
|
||||
update(users::table)
|
||||
.filter(dsl::uuid.eq(self.uuid))
|
||||
.set(dsl::online_status.eq(new_status))
|
||||
.execute(conn)
|
||||
.await?;
|
||||
|
||||
if cache_pool
|
||||
.get_cache_key::<User>(self.uuid.to_string())
|
||||
.await
|
||||
.is_ok()
|
||||
{
|
||||
cache_pool.del_cache_key(self.uuid.to_string()).await?
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub async fn friends_with(
|
||||
&self,
|
||||
conn: &mut Conn,
|
||||
|
|
|
@ -18,6 +18,7 @@ pub struct UserBuilder {
|
|||
avatar: Option<String>,
|
||||
pronouns: Option<String>,
|
||||
about: Option<String>,
|
||||
online_status: i16,
|
||||
}
|
||||
|
||||
impl UserBuilder {
|
||||
|
@ -29,6 +30,7 @@ impl UserBuilder {
|
|||
avatar: self.avatar,
|
||||
pronouns: self.pronouns,
|
||||
about: self.about,
|
||||
online_status: self.online_status,
|
||||
friends_since: None,
|
||||
}
|
||||
}
|
||||
|
@ -42,6 +44,7 @@ pub struct User {
|
|||
avatar: Option<String>,
|
||||
pronouns: Option<String>,
|
||||
about: Option<String>,
|
||||
online_status: i16,
|
||||
friends_since: Option<DateTime<Utc>>,
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue