Don't call get_relationship in relationships::queries::(un)follow
This commit is contained in:
parent
51aea90158
commit
3662d1a558
2 changed files with 20 additions and 15 deletions
|
@ -198,7 +198,7 @@ async fn follow(
|
|||
let profile = get_profile_by_id(db_client, &account_id).await?;
|
||||
let maybe_remote_actor = profile.remote_actor()
|
||||
.map_err(|_| HttpError::InternalError)?;
|
||||
let relationship = if let Some(remote_actor) = maybe_remote_actor {
|
||||
if let Some(remote_actor) = maybe_remote_actor {
|
||||
// Remote follow
|
||||
let request = follows::create_follow_request(db_client, ¤t_user.id, &profile.id).await?;
|
||||
let activity = create_activity_follow(
|
||||
|
@ -208,10 +208,14 @@ async fn follow(
|
|||
&remote_actor.id,
|
||||
);
|
||||
deliver_activity(&config, ¤t_user, activity, vec![remote_actor]);
|
||||
follows::get_relationship(db_client, ¤t_user.id, &profile.id).await?
|
||||
} else {
|
||||
follows::follow(db_client, ¤t_user.id, &profile.id).await?
|
||||
follows::follow(db_client, ¤t_user.id, &profile.id).await?;
|
||||
};
|
||||
let relationship = follows::get_relationship(
|
||||
db_client,
|
||||
¤t_user.id,
|
||||
&profile.id,
|
||||
).await?;
|
||||
Ok(HttpResponse::Ok().json(relationship))
|
||||
}
|
||||
|
||||
|
@ -227,14 +231,14 @@ async fn unfollow(
|
|||
let target_profile = get_profile_by_id(db_client, &account_id).await?;
|
||||
let maybe_remote_actor = target_profile.remote_actor()
|
||||
.map_err(|_| HttpError::InternalError)?;
|
||||
let relationship = if let Some(remote_actor) = maybe_remote_actor {
|
||||
if let Some(remote_actor) = maybe_remote_actor {
|
||||
// Remote follow
|
||||
let follow_request = follows::get_follow_request_by_path(
|
||||
db_client,
|
||||
¤t_user.id,
|
||||
&target_profile.id,
|
||||
).await?;
|
||||
let relationship = follows::unfollow(
|
||||
follows::unfollow(
|
||||
db_client,
|
||||
¤t_user.id,
|
||||
&target_profile.id,
|
||||
|
@ -247,11 +251,14 @@ async fn unfollow(
|
|||
&remote_actor.id,
|
||||
);
|
||||
deliver_activity(&config, ¤t_user, activity, vec![remote_actor]);
|
||||
// TODO: uncouple unfollow and get_relationship
|
||||
relationship
|
||||
} else {
|
||||
follows::unfollow(db_client, ¤t_user.id, &target_profile.id).await?
|
||||
follows::unfollow(db_client, ¤t_user.id, &target_profile.id).await?;
|
||||
};
|
||||
let relationship = follows::get_relationship(
|
||||
db_client,
|
||||
¤t_user.id,
|
||||
&target_profile.id,
|
||||
).await?;
|
||||
Ok(HttpResponse::Ok().json(relationship))
|
||||
}
|
||||
|
||||
|
|
|
@ -86,7 +86,7 @@ pub async fn follow(
|
|||
db_client: &mut impl GenericClient,
|
||||
source_id: &Uuid,
|
||||
target_id: &Uuid,
|
||||
) -> Result<Relationship, DatabaseError> {
|
||||
) -> Result<(), DatabaseError> {
|
||||
let transaction = db_client.transaction().await?;
|
||||
transaction.execute(
|
||||
"
|
||||
|
@ -99,17 +99,16 @@ pub async fn follow(
|
|||
update_following_count(&transaction, source_id, 1).await?;
|
||||
if target_profile.is_local() {
|
||||
create_follow_notification(&transaction, source_id, target_id).await?;
|
||||
}
|
||||
let relationship = get_relationship(&transaction, source_id, target_id).await?;
|
||||
};
|
||||
transaction.commit().await?;
|
||||
Ok(relationship)
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub async fn unfollow(
|
||||
db_client: &mut impl GenericClient,
|
||||
source_id: &Uuid,
|
||||
target_id: &Uuid,
|
||||
) -> Result<Relationship, DatabaseError> {
|
||||
) -> Result<(), DatabaseError> {
|
||||
let transaction = db_client.transaction().await?;
|
||||
let deleted_count = transaction.execute(
|
||||
"
|
||||
|
@ -133,9 +132,8 @@ pub async fn unfollow(
|
|||
update_follower_count(&transaction, target_id, -1).await?;
|
||||
update_following_count(&transaction, source_id, -1).await?;
|
||||
}
|
||||
let relationship = get_relationship(&transaction, source_id, target_id).await?;
|
||||
transaction.commit().await?;
|
||||
Ok(relationship)
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub async fn create_follow_request(
|
||||
|
|
Loading…
Reference in a new issue