MastoAPI: Always return an url for statuses.
[akkoma] / lib / pleroma / user.ex
index 938b57d90c47322e754e02704cc8c459519e4edd..bf63a22b3f4075a16581bdfc7728654af8352ac5 100644 (file)
@@ -241,7 +241,7 @@ defmodule Pleroma.User do
 
   def update_note_count(%User{} = user) do
     note_count_query = from a in Object,
-      where: fragment("? @> ?", a.data, ^%{actor: user.ap_id, type: "Note"}),
+      where: fragment("?->>'actor' = ? and ?->>'type' = 'Note'", a.data, ^user.ap_id, a.data),
       select: count(a.id)
 
     note_count = Repo.one(note_count_query)
@@ -274,4 +274,14 @@ defmodule Pleroma.User do
 
     Repo.all(query)
   end
+
+  def search(query, resolve) do
+    if resolve do
+      User.get_or_fetch_by_nickname(query)
+    end
+    q = from u in User,
+      where: fragment("(to_tsvector('english', ?) || to_tsvector('english', ?)) @@ plainto_tsquery('english', ?)", u.nickname, u.name, ^query),
+      limit: 20
+    Repo.all(q)
+  end
 end