Merge branch 'develop' of git.pleroma.social:pleroma/pleroma into feature/pinned-posts

This commit is contained in:
Egor Kislitsyn 2019-01-08 16:32:07 +07:00
commit 0c750bc432
7 changed files with 76 additions and 3 deletions

View file

@ -367,6 +367,15 @@ defmodule Pleroma.User do
Repo.get_by(User, ap_id: ap_id)
end
# This is mostly an SPC migration fix. This guesses the user nickname (by taking the last part of the ap_id and the domain) and tries to get that user
def get_by_guessed_nickname(ap_id) do
domain = URI.parse(ap_id).host
name = List.last(String.split(ap_id, "/"))
nickname = "#{name}@#{domain}"
get_by_nickname(nickname)
end
def update_and_set_cache(changeset) do
with {:ok, user} <- Repo.update(changeset) do
Cachex.put(:user_cache, "ap_id:#{user.ap_id}", user)

View file

@ -94,11 +94,27 @@ defmodule Pleroma.Web.TwitterAPI.ActivityView do
ap_id == "https://www.w3.org/ns/activitystreams#Public" ->
nil
user = User.get_cached_by_ap_id(ap_id) ->
user
user = User.get_by_guessed_nickname(ap_id) ->
user
true ->
User.get_cached_by_ap_id(ap_id)
error_user(ap_id)
end
end
defp error_user(ap_id) do
%User{
name: ap_id,
ap_id: ap_id,
info: %User.Info{},
nickname: "erroruser@example.com",
inserted_at: NaiveDateTime.utc_now()
}
end
def render("index.json", opts) do
context_ids = collect_context_ids(opts.activities)
users = collect_users(opts.activities)