Fix some edge cases [nervous laughter]
authorrinpatch <rinpatch@sdf.org>
Tue, 15 Jan 2019 08:56:35 +0000 (11:56 +0300)
committerrinpatch <rinpatch@sdf.org>
Tue, 15 Jan 2019 08:56:35 +0000 (11:56 +0300)
lib/pleroma/user.ex
lib/pleroma/web/metadata.ex
lib/pleroma/web/router.ex

index 26cef53ee6f1b64679c93f5fecdfee84a2d26093..0e828a99e1c11f35e131d2e6c489d4a7ee57445a 100644 (file)
@@ -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
index 9935726fc5008a58551234a86df2015d14564c38..b7052eec1b517aae57d03e8ed5fd3c9fbf34bc7f 100644 (file)
@@ -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,
          [
index 5ef99bec5c5c47cbd49e1db62c6c96ec27d5a42e..6cf689ce281315e4dd411fef7323c9f7ac3389e1 100644 (file)
@@ -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