end
end
- def follow(%User{} = follower, %User{} = followed) do
+ def follow(%User{} = follower, %User{info: info} = followed) do
ap_followers = followed.follower_address
- if following?(follower, followed) do
+ if following?(follower, followed) or info["deactivated"] do
{:error,
"Could not follow user: #{followed.nickname} is already on your list."}
else
def unfollow(%User{} = follower, %User{} = followed) do
ap_followers = followed.follower_address
- if following?(follower, followed) do
+ if following?(follower, followed) and follower.ap_id != followed.ap_id do
following = follower.following
|> List.delete(ap_followers)
def update_follower_count(%User{} = user) do
follower_count_query = from u in User,
where: fragment("? @> ?", u.following, ^user.follower_address),
+ where: u.id != ^user.id,
select: count(u.id)
follower_count = Repo.one(follower_count_query)
def get_recipients_from_activity(%Activity{data: %{"to" => to}}) do
query = from u in User,
- where: u.local == true
-
- query = from u in query,
where: u.ap_id in ^to,
or_where: fragment("? \\\?| ?", u.following, ^to)
+ query = from u in query,
+ where: u.local == true
+
Repo.all(query)
end
Enum.member?(blocks, ap_id)
end
+ def local_user_query() do
+ from u in User,
+ where: u.local == true
+ end
+
+ def deactivate (%User{} = user) do
+ new_info = Map.put(user.info, "deactivated", true)
+ cs = User.info_changeset(user, %{info: new_info})
+ Repo.update(cs)
+ end
+
+ def delete (%User{} = user) do
+ {:ok, user} = User.deactivate(user)
+
+ # Remove all relationships
+ {:ok, followers } = User.get_followers(user)
+ followers
+ |> Enum.each(fn (follower) -> User.unfollow(follower, user) end)
+
+ {:ok, friends} = User.get_friends(user)
+ friends
+ |> Enum.each(fn (followed) -> User.unfollow(user, followed) end)
+
+ :ok
+ end
end