[#483] User.get_by_nickname/1: allowed retrieving user by fully-qualified local nickname
authorIvan Tashkinov <ivantashkinov@gmail.com>
Sat, 29 Dec 2018 09:15:46 +0000 (12:15 +0300)
committerIvan Tashkinov <ivantashkinov@gmail.com>
Sat, 29 Dec 2018 09:15:46 +0000 (12:15 +0300)
(<nick>@<our_instance_host>).

lib/pleroma/user.ex

index 5580147609100af72856239126aaecf451e421aa..d4a6b13fb51676bc789f4dc02f0150944d7a5234 100644 (file)
@@ -387,7 +387,11 @@ defmodule Pleroma.User do
   end
 
   def get_by_nickname(nickname) do
-    Repo.get_by(User, nickname: nickname)
+    Repo.get_by(User, nickname: nickname) ||
+      if String.ends_with?(nickname, "@" <> Pleroma.Web.Endpoint.host()) 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