Save follower count and note count in user.
[akkoma] / lib / pleroma / web / ostatus / handlers / note_handler.ex
index 82e60676f18c28851d464478216ee60e5bd12441..e55f972b21bc89d25046acf76658b9a346d9bfe9 100644 (file)
@@ -37,15 +37,31 @@ defmodule Pleroma.Web.OStatus.NoteHandler do
     end
   end
 
-  def get_mentions(entry) do
+  def get_people_mentions(entry) do
     :xmerl_xpath.string('//link[@rel="mentioned" and @ostatus:object-type="http://activitystrea.ms/schema/1.0/person"]', entry)
     |> Enum.map(fn(person) -> XML.string_from_xpath("@href", person) end)
   end
 
+  def get_collection_mentions(entry) do
+    transmogrify = fn
+      ("http://activityschema.org/collection/public") ->
+        "https://www.w3.org/ns/activitystreams#Public"
+      (group) ->
+        group
+    end
+
+    :xmerl_xpath.string('//link[@rel="mentioned" and @ostatus:object-type="http://activitystrea.ms/schema/1.0/collection"]', entry)
+    |> Enum.map(fn(collection) -> XML.string_from_xpath("@href", collection) |> transmogrify.() end)
+  end
+
+  def get_mentions(entry) do
+    get_people_mentions(entry)
+    ++ get_collection_mentions(entry)
+  end
+
   def make_to_list(actor, mentions) do
     [
-      "https://www.w3.org/ns/activitystreams#Public",
-      User.ap_followers(actor)
+      actor.follower_address
     ] ++ mentions
   end
 
@@ -76,7 +92,9 @@ defmodule Pleroma.Web.OStatus.NoteHandler do
          # TODO: Handle this case in make_note_data
          note <- (if inReplyTo && !inReplyToActivity, do: note |> Map.put("inReplyTo", inReplyTo), else: note)
       do
-      ActivityPub.create(to, actor, context, note, %{}, date, false)
+      res = ActivityPub.create(to, actor, context, note, %{}, date, false)
+      User.update_note_count(actor)
+      res
     else
       %Activity{} = activity -> {:ok, activity}
       e -> {:error, e}