From ce15e0659e63217d482ef0448ef7629c76755c46 Mon Sep 17 00:00:00 2001 From: rinpatch Date: Tue, 15 Jan 2019 11:56:35 +0300 Subject: [PATCH] Fix some edge cases [nervous laughter] --- lib/pleroma/user.ex | 15 ++++++++++++++- lib/pleroma/web/metadata.ex | 10 ++++++++-- lib/pleroma/web/router.ex | 2 +- 3 files changed, 23 insertions(+), 4 deletions(-) diff --git a/lib/pleroma/user.ex b/lib/pleroma/user.ex index 26cef53ee..0e828a99e 100644 --- a/lib/pleroma/user.ex +++ b/lib/pleroma/user.ex @@ -454,7 +454,20 @@ defmodule Pleroma.User do end def get_cached_by_nickname_or_id(nickname_or_id) do - get_cached_by_id(nickname_or_id) || get_cached_by_nickname(nickname_or_id) + try do + # TODO: convert to UUIDs when !654 is merged + maybe_id = String.to_integer(nickname_or_id) + user = get_cached_by_id(maybe_id) + + if user == nil do + raise ArgumentError, message: "invalid argument foo" + else + user + end + rescue + _ in ArgumentError -> + get_cached_by_nickname(nickname_or_id) + end end def get_by_nickname(nickname) do diff --git a/lib/pleroma/web/metadata.ex b/lib/pleroma/web/metadata.ex index 9935726fc..b7052eec1 100644 --- a/lib/pleroma/web/metadata.ex +++ b/lib/pleroma/web/metadata.ex @@ -21,7 +21,13 @@ defmodule Pleroma.Web.Metadata do {:meta, [ property: "og:title", - content: "#{user.name} (@#{user.nickname}@#{pleroma_domain()}) post ##{activity.id}" + content: + "#{user.name}" <> + if user.local do + "(@#{user.nickname}@{pleroma_domain})" + else + "(@#{user.nickname})" + end ], []}, {:meta, [property: "og:url", content: activity.data["id"]], []}, {:meta, [property: "og:description", content: truncated_content], []}, @@ -35,7 +41,7 @@ defmodule Pleroma.Web.Metadata do # opengraph for user card defp opengraph_tags(%{user: user}) do - with truncated_bio = scrub_html_and_truncate(user.bio) do + with truncated_bio = scrub_html_and_truncate(user.bio || "") do [ {:meta, [ diff --git a/lib/pleroma/web/router.ex b/lib/pleroma/web/router.ex index 5ef99bec5..6cf689ce2 100644 --- a/lib/pleroma/web/router.ex +++ b/lib/pleroma/web/router.ex @@ -505,7 +505,7 @@ defmodule Pleroma.Web.Router do scope "/", Fallback do get("/registration/:token", RedirectController, :registration_page) - get("/*path", RedirectController, :redirector) + get("/*path", RedirectController, :redirector_with_meta) options("/*path", RedirectController, :empty) end