From 79660fb8162531deb5cdd0db0a52099971f7d139 Mon Sep 17 00:00:00 2001 From: Natty Date: Thu, 9 Nov 2023 21:53:03 +0100 Subject: [PATCH] Fixed user relation packing --- magnetar_sdk/src/types/user.rs | 2 +- magnetar_sdk/src/util_types.rs | 5 +-- src/model/data/user.rs | 78 +++++++++------------------------- src/model/processing/user.rs | 41 +++++++++--------- 4 files changed, 46 insertions(+), 80 deletions(-) diff --git a/magnetar_sdk/src/types/user.rs b/magnetar_sdk/src/types/user.rs index d9e4daf..9a647ec 100644 --- a/magnetar_sdk/src/types/user.rs +++ b/magnetar_sdk/src/types/user.rs @@ -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, diff --git a/magnetar_sdk/src/util_types.rs b/magnetar_sdk/src/util_types.rs index d8241e4..9f13015 100644 --- a/magnetar_sdk/src/util_types.rs +++ b/magnetar_sdk/src/util_types.rs @@ -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, D::Error> where - D: Deserializer<'de>, + D: serde::Deserializer<'de>, T: DeserializeOwned, { let str_raw = String::deserialize(deserializer)?; diff --git a/src/model/data/user.rs b/src/model/data/user.rs index c291bf2..d3a21ff 100644 --- a/src/model/data/user.rs +++ b/src/model/data/user.rs @@ -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> for UserRelationExt { +impl PackType 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, } } } diff --git a/src/model/processing/user.rs b/src/model/processing/user.rs index dd6845e..4df5536 100644 --- a/src/model/processing/user.rs +++ b/src/model/processing/user.rs @@ -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(