Add avatar updating from incoming messages.
[akkoma] / lib / pleroma / object.ex
index f932034d7b99b2b9b8b0a4c90054fba43f71fc7f..949ccb0f66e172a6b4bece0983e55ef20fa52b8d 100644 (file)
@@ -13,4 +13,24 @@ defmodule Pleroma.Object do
     Repo.one(from object in Object,
       where: fragment("? @> ?", object.data, ^%{id: ap_id}))
   end
+
+  def get_cached_by_ap_id(ap_id) do
+    if Mix.env == :test do
+      get_by_ap_id(ap_id)
+    else
+      key = "object:#{ap_id}"
+      Cachex.get!(:user_cache, key, fallback: fn(_) ->
+        object = get_by_ap_id(ap_id)
+        if object do
+          {:commit, object}
+        else
+          {:ignore, object}
+        end
+      end)
+    end
+  end
+
+  def context_mapping(context) do
+    %Object{data: %{"id" => context}}
+  end
 end