alias Pleroma.{Repo, User, Object, Web, Activity, Notification}
alias Comeonin.Pbkdf2
alias Pleroma.Web.{OStatus, Websub}
- alias Pleroma.Web.ActivityPub.ActivityPub
alias Pleroma.Web.ActivityPub.Utils
schema "users" do
end
def user_info(%User{} = user) do
+ oneself = if user.local, do: 1, else: 0
%{
- following_count: length(user.following),
+ following_count: length(user.following) - oneself,
note_count: user.info["note_count"] || 0,
follower_count: user.info["follower_count"] || 0
}
end
def update_changeset(struct, params \\ %{}) do
- changeset = struct
+ struct
|> cast(params, [:bio, :name])
|> unique_constraint(:nickname)
|> validate_format(:nickname, ~r/^[a-zA-Z\d]+$/)
|> follow_changeset(%{following: following})
|> Repo.update
- {:ok, followed} = update_follower_count(followed)
+ {:ok, _} = update_follower_count(followed)
follower
end
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)
with %User{} = user <- get_by_nickname(nickname) do
user
else _e ->
- with [nick, domain] <- String.split(nickname, "@"),
+ with [_nick, _domain] <- String.split(nickname, "@"),
{:ok, user} <- OStatus.make_user(nickname) do
user
else _e -> nil
Repo.update(cs)
end
- def get_notified_from_activity(%Activity{data: %{"to" => to}} = activity) do
+ def get_notified_from_activity(%Activity{data: %{"to" => to}}) do
+ query = from u in User,
+ where: u.ap_id in ^to,
+ where: u.local == true
+
+ Repo.all(query)
+ end
+
+ def get_recipients_from_activity(%Activity{data: %{"to" => to}}) do
query = from u in User,
where: u.ap_id in ^to,
+ or_where: fragment("? \\\?| ?", u.following, ^to)
+
+ query = from u in query,
where: u.local == true
Repo.all(query)