Fixed user relation packing
ci/woodpecker/push/ociImagePush Pipeline was successful Details

This commit is contained in:
Natty 2023-11-09 21:53:03 +01:00
parent 81d0c678d8
commit 79660fb816
Signed by: natty
GPG Key ID: BF6CB659ADEE60EC
4 changed files with 46 additions and 80 deletions

View File

@ -96,8 +96,8 @@ pub struct UserProfilePinsEx {
pub struct UserRelationExt {
pub follows_you: bool,
pub you_follow: bool,
pub you_request_follow: bool,
pub they_request_follow: bool,
pub you_request_follow: bool,
pub blocks_you: bool,
pub you_block: bool,
pub mute: bool,

View File

@ -1,6 +1,5 @@
use serde::de::DeserializeOwned;
use serde::{Deserialize, Deserializer, Serialize};
use std::collections::HashMap;
use serde::{Deserialize, Serialize};
use std::hash::Hash;
use ts_rs::TS;
@ -84,7 +83,7 @@ pub(crate) fn deserialize_array_urlenc<'de, D, T: Eq + Hash>(
deserializer: D,
) -> Result<Vec<T>, D::Error>
where
D: Deserializer<'de>,
D: serde::Deserializer<'de>,
T: DeserializeOwned,
{
let str_raw = String::deserialize(deserializer)?;

View File

@ -137,76 +137,40 @@ impl PackType<&ck::user::Model> for UserDetailExt {
}
}
struct UserRelationExtSource<'a> {
pub follow_out: Option<&'a ck::following::Model>,
pub follow_in: Option<&'a ck::following::Model>,
pub block_out: Option<&'a ck::blocking::Model>,
pub block_in: Option<&'a ck::blocking::Model>,
pub mute: Option<&'a ck::muting::Model>,
pub renote_mute: Option<&'a ck::renote_muting::Model>,
pub follow_request_out: Option<&'a ck::follow_request::Model>,
pub follow_request_in: Option<&'a ck::follow_request::Model>,
pub struct UserRelationExtSource {
pub follow_out: bool,
pub follow_in: bool,
pub follow_request_in: bool,
pub follow_request_out: bool,
pub block_out: bool,
pub block_in: bool,
pub mute: bool,
pub renote_mute: bool,
}
impl PackType<UserRelationExtSource<'_>> for UserRelationExt {
impl PackType<UserRelationExtSource> for UserRelationExt {
fn extract(
context: &PackingContext,
_context: &PackingContext,
UserRelationExtSource {
follow_out,
follow_in,
follow_request_in,
follow_request_out,
block_out,
block_in,
mute,
renote_mute,
follow_request_in,
follow_request_out,
}: UserRelationExtSource,
) -> Self {
let self_user = context.self_user();
UserRelationExt {
follows_you: self_user.is_some_and(|self_user| {
follow_in.is_some_and(|follow_in| {
self_user.id == follow_in.followee_id && self_user.id != follow_in.follower_id
})
}),
you_follow: self_user.is_some_and(|self_user| {
follow_out.is_some_and(|follow_out| {
self_user.id == follow_out.follower_id && self_user.id != follow_out.followee_id
})
}),
blocks_you: self_user.is_some_and(|self_user| {
block_in.is_some_and(|block_in| {
self_user.id == block_in.blockee_id && self_user.id != block_in.blocker_id
})
}),
you_block: self_user.is_some_and(|self_user| {
block_out.is_some_and(|block_out| {
self_user.id == block_out.blocker_id && self_user.id != block_out.blockee_id
})
}),
mute: self_user.is_some_and(|self_user| {
mute.is_some_and(|mute| {
self_user.id == mute.muter_id && self_user.id != mute.mutee_id
})
}),
mute_renotes: self_user.is_some_and(|self_user| {
renote_mute.is_some_and(|renote_mute| {
self_user.id == renote_mute.muter_id && self_user.id != renote_mute.mutee_id
})
}),
you_request_follow: self_user.is_some_and(|self_user| {
follow_request_in.is_some_and(|follow_req_in| {
self_user.id == follow_req_in.followee_id
&& self_user.id != follow_req_in.follower_id
})
}),
they_request_follow: self_user.is_some_and(|self_user| {
follow_request_out.is_some_and(|follow_req_out| {
self_user.id == follow_req_out.follower_id
&& self_user.id != follow_req_out.followee_id
})
}),
follows_you: follow_in,
you_follow: follow_out,
they_request_follow: follow_request_in,
you_request_follow: follow_request_out,
blocks_you: block_in,
you_block: block_out,
mute,
mute_renotes: renote_mute,
}
}
}

View File

@ -1,4 +1,4 @@
use crate::model::data::user::{UserBaseSource, UserProfileExtSource};
use crate::model::data::user::{UserBaseSource, UserProfileExtSource, UserRelationExtSource};
use crate::model::processing::drive::DriveModel;
use crate::model::processing::emoji::EmojiModel;
use crate::model::processing::note::NoteModel;
@ -300,8 +300,8 @@ impl UserModel {
return Ok(UserRelationExt {
follows_you: false,
you_follow: false,
you_request_follow: false,
they_request_follow: false,
you_request_follow: false,
blocks_you: false,
you_block: false,
mute: false,
@ -313,14 +313,14 @@ impl UserModel {
let them = Either::Right(user);
let (
follows_you,
you_follow,
you_request_follow,
they_request_follow,
blocks_you,
you_block,
follow_in,
follow_out,
follow_request_in,
follow_request_out,
block_in,
block_out,
mute,
mute_renotes,
renote_mute,
) = try_join!(
ctx.is_relationship_between(them, me, UserRelationship::Follow),
ctx.is_relationship_between(me, them, UserRelationship::Follow),
@ -332,16 +332,19 @@ impl UserModel {
ctx.is_relationship_between(me, them, UserRelationship::RenoteMute)
)?;
Ok(UserRelationExt {
follows_you,
you_follow,
you_request_follow,
they_request_follow,
blocks_you,
you_block,
mute,
mute_renotes,
})
Ok(UserRelationExt::extract(
ctx,
UserRelationExtSource {
follow_in,
follow_out,
follow_request_in,
follow_request_out,
block_in,
block_out,
mute,
renote_mute,
},
))
}
pub fn auth_overview_from_profile(