add: 8 achievements add: larger text setting fix: small infinite
timeline bugs
This commit is contained in:
parent
b860f74124
commit
5dd9fa01cb
19 changed files with 241 additions and 123 deletions
|
@ -712,7 +712,7 @@ impl DataManager {
|
|||
/// Add an achievement to a user.
|
||||
///
|
||||
/// Still returns `Ok` if the user already has the achievement.
|
||||
pub async fn add_achievement(&self, user: &User, achievement: Achievement) -> Result<()> {
|
||||
pub async fn add_achievement(&self, user: &mut User, achievement: Achievement) -> Result<()> {
|
||||
if user
|
||||
.achievements
|
||||
.iter()
|
||||
|
@ -734,9 +734,8 @@ impl DataManager {
|
|||
.await?;
|
||||
|
||||
// add achievement
|
||||
let mut user = user.clone();
|
||||
user.achievements.push(achievement);
|
||||
self.update_user_achievements(user.id, user.achievements)
|
||||
self.update_user_achievements(user.id, user.achievements.to_owned())
|
||||
.await?;
|
||||
|
||||
Ok(())
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
use oiseau::cache::Cache;
|
||||
use crate::model::{
|
||||
Error, Result,
|
||||
auth::{Notification, User},
|
||||
auth::{AchievementName, Notification, User},
|
||||
permissions::FinePermission,
|
||||
reactions::{AssetType, Reaction},
|
||||
Error, Result,
|
||||
};
|
||||
use crate::{auto_method, DataManager};
|
||||
|
||||
|
@ -148,6 +148,33 @@ impl DataManager {
|
|||
{
|
||||
return Err(Error::NotAllowed);
|
||||
}
|
||||
|
||||
// achievements
|
||||
if user.id != post.owner {
|
||||
let mut owner = self.get_user_by_id(post.owner).await?;
|
||||
self.add_achievement(&mut owner, AchievementName::Get1Like.into())
|
||||
.await?;
|
||||
|
||||
if post.likes >= 9 {
|
||||
self.add_achievement(&mut owner, AchievementName::Get10Likes.into())
|
||||
.await?;
|
||||
}
|
||||
|
||||
if post.likes >= 49 {
|
||||
self.add_achievement(&mut owner, AchievementName::Get50Likes.into())
|
||||
.await?;
|
||||
}
|
||||
|
||||
if post.likes >= 99 {
|
||||
self.add_achievement(&mut owner, AchievementName::Get100Likes.into())
|
||||
.await?;
|
||||
}
|
||||
|
||||
if post.dislikes >= 24 {
|
||||
self.add_achievement(&mut owner, AchievementName::Get25Dislikes.into())
|
||||
.await?;
|
||||
}
|
||||
}
|
||||
} else if data.asset_type == AssetType::Question {
|
||||
let question = self.get_question_by_id(data.asset).await?;
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
use oiseau::cache::Cache;
|
||||
use crate::model::auth::FollowResult;
|
||||
use crate::model::auth::{AchievementName, FollowResult};
|
||||
use crate::model::requests::{ActionRequest, ActionType};
|
||||
use crate::model::{Error, Result, auth::User, auth::UserFollow, permissions::FinePermission};
|
||||
use crate::{auto_method, DataManager};
|
||||
|
@ -238,9 +238,14 @@ impl DataManager {
|
|||
/// # Arguments
|
||||
/// * `data` - a mock [`UserFollow`] object to insert
|
||||
/// * `force` - if we should skip the request stage
|
||||
pub async fn create_userfollow(&self, data: UserFollow, force: bool) -> Result<FollowResult> {
|
||||
pub async fn create_userfollow(
|
||||
&self,
|
||||
data: UserFollow,
|
||||
initiator: &User,
|
||||
force: bool,
|
||||
) -> Result<FollowResult> {
|
||||
if !force {
|
||||
let other_user = self.get_user_by_id(data.receiver).await?;
|
||||
let mut other_user = self.get_user_by_id(data.receiver).await?;
|
||||
|
||||
if other_user.settings.private_profile {
|
||||
// send follow request instead
|
||||
|
@ -254,6 +259,12 @@ impl DataManager {
|
|||
|
||||
return Ok(FollowResult::Requested);
|
||||
}
|
||||
|
||||
// check if we're staff
|
||||
if initiator.permissions.check(FinePermission::STAFF_BADGE) {
|
||||
self.add_achievement(&mut other_user, AchievementName::FollowedByStaff.into())
|
||||
.await?;
|
||||
}
|
||||
}
|
||||
|
||||
// ...
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue