Cachex.fetch!(:user_cache, key, fn _ -> get_or_fetch_by_nickname(nickname) end)
end
+ def get_cached_by_nickname_or_id(nickname_or_id) do
+ get_cached_by_nickname(nickname_or_id) || get_cached_by_id(nickname_or_id)
+ end
+
def get_by_nickname(nickname) do
- Repo.get_by(User, nickname: nickname)
+ Repo.get_by(User, nickname: nickname) ||
+ if Regex.match?(~r(@#{Pleroma.Web.Endpoint.host()})i, nickname) do
+ [local_nickname, _] = String.split(nickname, "@")
+ Repo.get_by(User, nickname: local_nickname)
+ end
end
def get_by_nickname_or_email(nickname_or_email) do
|> response(404)
end
- test "gets an activity", %{conn: conn} do
- note_activity = insert(:note_activity)
- [_, uuid] = hd(Regex.scan(~r/.+\/([\w-]+)$/, note_activity.data["id"]))
-
- conn
- |> get("/activities/#{uuid}")
- |> response(200)
- end
-
+ test "gets an activity in xml format", %{conn: conn} do
+ note_activity = insert(:note_activity)
+ [_, uuid] = hd(Regex.scan(~r/.+\/([\w-]+)$/, note_activity.data["id"]))
+
+ conn
+ |> put_req_header("accept", "application/xml")
+ |> get("/activities/#{uuid}")
+ |> response(200)
+ end
+
+ test "404s on deleted objects", %{conn: conn} do
+ note_activity = insert(:note_activity)
+ [_, uuid] = hd(Regex.scan(~r/.+\/([\w-]+)$/, note_activity.data["object"]["id"]))
+ object = Object.get_by_ap_id(note_activity.data["object"]["id"])
+
+ conn
+ |> get("/objects/#{uuid}")
+ |> response(200)
+
+ Object.delete(object)
+
+ conn
+ |> get("/objects/#{uuid}")
+ |> response(404)
+ end
+
test "404s on private activities", %{conn: conn} do
note_activity = insert(:direct_note_activity)
[_, uuid] = hd(Regex.scan(~r/.+\/([\w-]+)$/, note_activity.data["id"]))