Make it possible to unfollow someone

I was sure it was already implemented, but it looks like it wasn't
This commit is contained in:
Bat
2018-09-04 11:37:58 +01:00
parent e12d3fdc2f
commit dcebc4653a
5 changed files with 67 additions and 18 deletions
+13 -13
View File
@@ -116,20 +116,20 @@ fn dashboard_auth() -> Flash<Redirect> {
#[get("/@/<name>/follow")]
fn follow(name: String, conn: DbConn, user: User, worker: Worker) -> Redirect {
let target = User::find_by_fqn(&*conn, name.clone()).unwrap();
let f = follows::Follow::insert(&*conn, follows::NewFollow {
follower_id: user.id,
following_id: target.id
});
f.notify(&*conn);
if let Some(follow) = follows::Follow::find(&*conn, user.id, target.id) {
let delete_act = follow.delete(&*conn);
worker.execute(Thunk::of(move || broadcast(&user, delete_act, vec![target])));
} else {
let f = follows::Follow::insert(&*conn, follows::NewFollow {
follower_id: user.id,
following_id: target.id,
ap_url: format!("{}/follow/{}", user.ap_url, target.ap_url),
});
f.notify(&*conn);
let mut act = Follow::default();
act.follow_props.set_actor_link::<Id>(user.clone().into_id()).unwrap();
act.follow_props.set_object_object(user.into_activity(&*conn)).unwrap();
act.object_props.set_id_string(format!("{}/follow/{}", user.ap_url, target.ap_url)).unwrap();
act.object_props.set_to_link(target.clone().into_id()).expect("New Follow error while setting 'to'");
act.object_props.set_cc_link_vec::<Id>(vec![]).expect("New Follow error while setting 'cc'");
worker.execute(Thunk::of(move || broadcast(&user, act, vec![target])));
let act = f.into_activity(&*conn);
worker.execute(Thunk::of(move || broadcast(&user, act, vec![target])));
}
Redirect::to(uri!(details: name = name))
}