+ update_and_set_cache(cs)
+ end
+
+ def get_notified_from_activity(%Activity{recipients: to}) do
+ query = from u in User,
+ where: u.ap_id in ^to,
+ where: u.local == true
+
+ Repo.all(query)
+ end
+
+ def get_recipients_from_activity(%Activity{recipients: to}) do
+ query = from u in User,
+ where: u.ap_id in ^to,
+ or_where: fragment("? \\\?| ?", u.following, ^to)
+
+ query = from u in query,
+ where: u.local == true
+
+ 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
+
+ def block(user, %{ap_id: ap_id}) do
+ blocks = user.info["blocks"] || []
+ new_blocks = Enum.uniq([ap_id | blocks])
+ new_info = Map.put(user.info, "blocks", new_blocks)
+
+ cs = User.info_changeset(user, %{info: new_info})
+ update_and_set_cache(cs)
+ end
+
+ def unblock(user, %{ap_id: ap_id}) do
+ blocks = user.info["blocks"] || []
+ new_blocks = List.delete(blocks, ap_id)
+ new_info = Map.put(user.info, "blocks", new_blocks)
+
+ cs = User.info_changeset(user, %{info: new_info})
+ update_and_set_cache(cs)
+ end
+
+ def blocks?(user, %{ap_id: ap_id}) do
+ blocks = user.info["blocks"] || []
+ Enum.member?(blocks, ap_id)
+ end
+
+ def local_user_query() do
+ from u in User,
+ where: u.local == true
+ end
+
+ def deactivate (%User{} = user) do
+ new_info = Map.put(user.info, "deactivated", true)
+ cs = User.info_changeset(user, %{info: new_info})
+ update_and_set_cache(cs)