Merge branch 'develop' into dtluna/pleroma-feature/unfollow-activity
authorRoger Braun <roger@rogerbraun.net>
Sun, 7 May 2017 17:28:23 +0000 (19:28 +0200)
committerRoger Braun <roger@rogerbraun.net>
Sun, 7 May 2017 17:28:23 +0000 (19:28 +0200)
12 files changed:
1  2 
lib/pleroma/user.ex
lib/pleroma/web/activity_pub/activity_pub.ex
lib/pleroma/web/ostatus/activity_representer.ex
lib/pleroma/web/ostatus/ostatus.ex
lib/pleroma/web/twitter_api/representers/activity_representer.ex
lib/pleroma/web/twitter_api/twitter_api.ex
test/support/factory.ex
test/user_test.exs
test/web/activity_pub/activity_pub_test.exs
test/web/ostatus/activity_representer_test.exs
test/web/twitter_api/twitter_api_controller_test.exs
test/web/twitter_api/twitter_api_test.exs

index e1a7befaa7f0f2e7ae20455c72298ae964c101bd,551c23445067b6e73f2dd2ef3e406ca14df5a7aa..4510be77052129bdf32950d2903fe6847f9171e2
@@@ -1,9 -1,10 +1,11 @@@
  defmodule Pleroma.User do
    use Ecto.Schema
-   import Ecto.Changeset
-   import Ecto.Query
-   alias Pleroma.{Repo, User, Object}
+   import Ecto.{Changeset, Query}
+   alias Pleroma.{Repo, User, Object, Web}
+   alias Comeonin.Pbkdf2
+   alias Pleroma.Web.{OStatus, Websub}
 +  alias Pleroma.Web.ActivityPub.ActivityPub
  
    schema "users" do
      field :bio, :string
        following = follower.following
        |> List.delete(ap_followers)
  
 -      follower
 +      { :ok, follower } = follower
        |> follow_changeset(%{following: following})
        |> Repo.update
 +      { :ok, follower, ActivityPub.fetch_latest_follow(follower, followed)}
      else
-       { :error, "Not subscribed!" }
+       {:error, "Not subscribed!"}
      end
    end
  
index 5937ec88cf6e69189f1e8e22ea242b92ad2444f1,82aed7ce42a41eb08a39bd0f9bc557c6b419ee42..f3e94b1010c54f978af1ed088f0076ab8038da8a
@@@ -168,6 -205,6 +205,44 @@@ defmodule Pleroma.Web.ActivityPub.Activ
      {:ok, activity, object}
    end
  
++  def follow(%User{ap_id: follower_id, local: actor_local}, %User{ap_id: followed_id}, local \\ true) do
++    data = %{
++      "type" => "Follow",
++      "actor" => follower_id,
++      "to" => [followed_id],
++      "object" => followed_id,
++      "published" => make_date()
++    }
++
++    with {:ok, activity} <- insert(data, local) do
++      if actor_local do
++        Pleroma.Web.Federator.enqueue(:publish, activity)
++       end
++
++      {:ok, activity}
++    end
++  end
++
++  def unfollow(follower, followed, local \\ true) do
++    with follow_activity when not is_nil(follow_activity) <- fetch_latest_follow(follower, followed) do
++      data = %{
++        "type" => "Undo",
++        "actor" => follower.ap_id,
++        "to" => [followed.ap_id],
++        "object" => follow_activity.data["id"],
++        "published" => make_date()
++      }
++
++      with {:ok, activity} <- insert(data, local) do
++        if follower.local do
++          Pleroma.Web.Federator.enqueue(:publish, activity)
++        end
++
++        {:ok, activity}
++      end
++    end
++  end
++
    def fetch_activities_for_context(context) do
      query = from activity in Activity,
        where: fragment("? @> ?", activity.data, ^%{ context: context })
index 590abc8bbbad3cfc7135f6b9936466a2520671b1,66e9b0ec23e21450e04355ed048329c8c6417be7..02d15ea94a0bdc5c11bbc3f17571403be48fe0f2
@@@ -19,9 -49,114 +49,144 @@@ defmodule Pleroma.Web.OStatus.ActivityR
        {:title, ['New note by #{user.nickname}']},
        {:content, [type: 'html'], h.(activity.data["object"]["content"])},
        {:published, h.(inserted_at)},
-       {:updated, h.(updated_at)}
-     ] ++ attachments
+       {:updated, h.(updated_at)},
+       {:"ostatus:conversation", [], h.(activity.data["context"])},
+       {:link, [href: h.(activity.data["context"]), rel: 'ostatus:conversation'], []},
+       {:link, [type: ['application/atom+xml'], href: h.(activity.data["object"]["id"]), rel: 'self'], []}
+     ] ++ attachments ++ in_reply_to ++ author ++ mentions
+   end
+   def to_simple_form(%{data: %{"type" => "Like"}} = activity, user, with_author) do
+     h = fn(str) -> [to_charlist(str)] end
+     updated_at = activity.updated_at
+     |> NaiveDateTime.to_iso8601
+     inserted_at = activity.inserted_at
+     |> NaiveDateTime.to_iso8601
+     in_reply_to = get_in_reply_to(activity.data)
+     author = if with_author, do: [{:author, UserRepresenter.to_simple_form(user)}], else: []
+     mentions = activity.data["to"] |> get_mentions
+     [
+       {:"activity:verb", ['http://activitystrea.ms/schema/1.0/favorite']},
+       {:id, h.(activity.data["id"])},
+       {:title, ['New favorite by #{user.nickname}']},
+       {:content, [type: 'html'], ['#{user.nickname} favorited something']},
+       {:published, h.(inserted_at)},
+       {:updated, h.(updated_at)},
+       {:"activity:object", [
+         {:"activity:object-type", ['http://activitystrea.ms/schema/1.0/note']},
+         {:id, h.(activity.data["object"])}, # For notes, federate the object id.
+       ]},
+       {:"ostatus:conversation", [], h.(activity.data["context"])},
+       {:link, [href: h.(activity.data["context"]), rel: 'ostatus:conversation'], []},
+       {:link, [rel: 'self', type: ['application/atom+xml'], href: h.(activity.data["id"])], []},
+       {:"thr:in-reply-to", [ref: to_charlist(activity.data["object"])], []}
+     ] ++ author ++ mentions
+   end
+   def to_simple_form(%{data: %{"type" => "Announce"}} = activity, user, with_author) do
+     h = fn(str) -> [to_charlist(str)] end
+     updated_at = activity.updated_at
+     |> NaiveDateTime.to_iso8601
+     inserted_at = activity.inserted_at
+     |> NaiveDateTime.to_iso8601
+     in_reply_to = get_in_reply_to(activity.data)
+     author = if with_author, do: [{:author, UserRepresenter.to_simple_form(user)}], else: []
+     retweeted_activity = Activity.get_create_activity_by_object_ap_id(activity.data["object"])
+     retweeted_user = User.get_cached_by_ap_id(retweeted_activity.data["actor"])
+     retweeted_xml = to_simple_form(retweeted_activity, retweeted_user, true)
+     mentions = activity.data["to"] |> get_mentions
+     [
+       {:"activity:object-type", ['http://activitystrea.ms/schema/1.0/activity']},
+       {:"activity:verb", ['http://activitystrea.ms/schema/1.0/share']},
+       {:id, h.(activity.data["id"])},
+       {:title, ['#{user.nickname} repeated a notice']},
+       {:content, [type: 'html'], ['RT #{retweeted_activity.data["object"]["content"]}']},
+       {:published, h.(inserted_at)},
+       {:updated, h.(updated_at)},
+       {:"ostatus:conversation", [], h.(activity.data["context"])},
+       {:link, [href: h.(activity.data["context"]), rel: 'ostatus:conversation'], []},
+       {:link, [rel: 'self', type: ['application/atom+xml'], href: h.(activity.data["id"])], []},
+       {:"activity:object", retweeted_xml}
+     ] ++ mentions ++ author
+   end
+   def to_simple_form(%{data: %{"type" => "Follow"}} = activity, user, with_author) do
+     h = fn(str) -> [to_charlist(str)] end
+     updated_at = activity.updated_at
+     |> NaiveDateTime.to_iso8601
+     inserted_at = activity.inserted_at
+     |> NaiveDateTime.to_iso8601
+     author = if with_author, do: [{:author, UserRepresenter.to_simple_form(user)}], else: []
+     mentions = (activity.data["to"] || []) |> get_mentions
+     [
+       {:"activity:object-type", ['http://activitystrea.ms/schema/1.0/activity']},
+       {:"activity:verb", ['http://activitystrea.ms/schema/1.0/follow']},
+       {:id, h.(activity.data["id"])},
+       {:title, ['#{user.nickname} started following #{activity.data["object"]}']},
+       {:content, [type: 'html'], ['#{user.nickname} started following #{activity.data["object"]}']},
+       {:published, h.(inserted_at)},
+       {:updated, h.(updated_at)},
+       {:"activity:object", [
+         {:"activity:object-type", ['http://activitystrea.ms/schema/1.0/person']},
+         {:id, h.(activity.data["object"])},
+         {:uri, h.(activity.data["object"])},
+       ]},
+       {:link, [rel: 'self', type: ['application/atom+xml'], href: h.(activity.data["id"])], []},
+     ] ++ mentions ++ author
+   end
++  # Only undos of follow for now. Will need to get redone once there are more
++  def to_simple_form(%{data: %{"type" => "Undo"}} = activity, user, with_author) do
++    h = fn(str) -> [to_charlist(str)] end
++
++    updated_at = activity.updated_at
++    |> NaiveDateTime.to_iso8601
++    inserted_at = activity.inserted_at
++    |> NaiveDateTime.to_iso8601
++
++    author = if with_author, do: [{:author, UserRepresenter.to_simple_form(user)}], else: []
++    follow_activity = Activity.get_by_ap_id(activity.data["object"])
++
++    mentions = (activity.data["to"] || []) |> get_mentions
++    [
++      {:"activity:object-type", ['http://activitystrea.ms/schema/1.0/activity']},
++      {:"activity:verb", ['http://activitystrea.ms/schema/1.0/unfollow']},
++      {:id, h.(activity.data["id"])},
++      {:title, ['#{user.nickname} stopped following #{follow_activity.data["object"]}']},
++      {:content, [type: 'html'], ['#{user.nickname} stopped following #{follow_activity.data["object"]}']},
++      {:published, h.(inserted_at)},
++      {:updated, h.(updated_at)},
++      {:"activity:object", [
++        {:"activity:object-type", ['http://activitystrea.ms/schema/1.0/person']},
++        {:id, h.(follow_activity.data["object"])},
++        {:uri, h.(follow_activity.data["object"])},
++      ]},
++      {:link, [rel: 'self', type: ['application/atom+xml'], href: h.(activity.data["id"])], []},
++    ] ++ mentions ++ author
++  end
++
+   def wrap_with_entry(simple_form) do
+     [{
+       :entry, [
+         xmlns: 'http://www.w3.org/2005/Atom',
+         "xmlns:thr": 'http://purl.org/syndication/thread/1.0',
+         "xmlns:activity": 'http://activitystrea.ms/spec/1.0/',
+         "xmlns:poco": 'http://portablecontacts.net/spec/1.0',
+         "xmlns:ostatus": 'http://ostatus.org/schema/1.0'
+       ], simple_form
+     }]
    end
  
-   def to_simple_form(_,_), do: nil
+   def to_simple_form(_, _, _), do: nil
  end
index d21b9078f4bc81799c7aee86e648de56171ab177,a6d416b2cc65228053b7b228defff90aba18aa67..842ad0f0199abcd3bb071508a788c273ff634941
@@@ -9,6 -17,268 +17,268 @@@ defmodule Pleroma.Web.OStatus d
      "#{Web.base_url}/push/hub/#{user.nickname}"
    end
  
-   def user_path(user) do
+   def salmon_path(user) do
+     "#{user.ap_id}/salmon"
+   end
+   def handle_incoming(xml_string) do
+     doc = parse_document(xml_string)
+     entries = :xmerl_xpath.string('//entry', doc)
+     activities = Enum.map(entries, fn (entry) ->
+       {:xmlObj, :string, object_type} = :xmerl_xpath.string('string(/entry/activity:object-type[1])', entry)
+       {:xmlObj, :string, verb} = :xmerl_xpath.string('string(/entry/activity:verb[1])', entry)
+       case verb do
+         'http://activitystrea.ms/schema/1.0/share' ->
+           with {:ok, activity, retweeted_activity} <- handle_share(entry, doc), do: [activity, retweeted_activity]
+         'http://activitystrea.ms/schema/1.0/favorite' ->
+           with {:ok, activity, favorited_activity} <- handle_favorite(entry, doc), do: [activity, favorited_activity]
+         _ ->
+           case object_type do
+             'http://activitystrea.ms/schema/1.0/note' ->
+               with {:ok, activity} <- handle_note(entry, doc), do: activity
+             'http://activitystrea.ms/schema/1.0/comment' ->
+               with {:ok, activity} <- handle_note(entry, doc), do: activity
+             _ ->
+               Logger.error("Couldn't parse incoming document")
+               nil
+           end
+       end
+     end)
+     {:ok, activities}
+   end
+   def make_share(_entry, doc, retweeted_activity) do
+     with {:ok, actor} <- find_make_or_update_user(doc),
+          %Object{} = object <- Object.get_cached_by_ap_id(retweeted_activity.data["object"]["id"]),
+          {:ok, activity, _object} = ActivityPub.announce(actor, object, false) do
+       {:ok, activity}
+     end
+   end
+   def handle_share(entry, doc) do
+     with [object] <- :xmerl_xpath.string('/entry/activity:object', entry),
+          {:ok, retweeted_activity} <-  handle_note(object, object),
+          {:ok, activity} <- make_share(entry, doc, retweeted_activity) do
+       {:ok, activity, retweeted_activity}
+     else
+       e -> {:error, e}
+     end
+   end
+   def make_favorite(_entry, doc, favorited_activity) do
+     with {:ok, actor} <- find_make_or_update_user(doc),
+          %Object{} = object <- Object.get_cached_by_ap_id(favorited_activity.data["object"]["id"]),
+          {:ok, activity, _object} = ActivityPub.like(actor, object, false) do
+       {:ok, activity}
+     end
+   end
+   def get_or_try_fetching(entry) do
+     with id when not is_nil(id) <- string_from_xpath("//activity:object[1]/id", entry),
+          %Activity{} = activity <- Activity.get_create_activity_by_object_ap_id(id) do
+       {:ok, activity}
+     else _e ->
+         with href when not is_nil(href) <- string_from_xpath("//activity:object[1]/link[@type=\"text/html\"]/@href", entry),
+              {:ok, [favorited_activity]} <- fetch_activity_from_html_url(href) do
+           {:ok, favorited_activity}
+         end
+     end
+   end
+   def handle_favorite(entry, doc) do
+     with {:ok, favorited_activity} <- get_or_try_fetching(entry),
+          {:ok, activity} <- make_favorite(entry, doc, favorited_activity) do
+       {:ok, activity, favorited_activity}
+     else
+       e -> {:error, e}
+     end
+   end
+   def get_attachments(entry) do
+     :xmerl_xpath.string('/entry/link[@rel="enclosure"]', entry)
+     |> Enum.map(fn (enclosure) ->
+       with href when not is_nil(href) <- string_from_xpath("/link/@href", enclosure),
+            type when not is_nil(type) <- string_from_xpath("/link/@type", enclosure) do
+         %{
+           "type" => "Attachment",
+           "url" => [%{
+                        "type" => "Link",
+                        "mediaType" => type,
+                        "href" => href
+                     }]
+         }
+       end
+     end)
+     |> Enum.filter(&(&1))
+   end
+   def handle_note(entry, doc \\ nil) do
+     content_html = string_from_xpath("//content[1]", entry)
+     [author] = :xmerl_xpath.string('//author[1]', doc)
+     {:ok, actor} = find_make_or_update_user(author)
+     inReplyTo = string_from_xpath("//thr:in-reply-to[1]/@ref", entry)
+     if !Object.get_cached_by_ap_id(inReplyTo) do
+       inReplyToHref = string_from_xpath("//thr:in-reply-to[1]/@href", entry)
+       if inReplyToHref do
+         fetch_activity_from_html_url(inReplyToHref)
+       end
+     end
+     context = (string_from_xpath("//ostatus:conversation[1]", entry) || "") |> String.trim
+     attachments = get_attachments(entry)
+     context = with %{data: %{"context" => context}} <- Object.get_cached_by_ap_id(inReplyTo) do
+                 context
+               else _e ->
+                 if String.length(context) > 0 do
+                   context
+                 else
+                   ActivityPub.generate_context_id
+                 end
+               end
+     to = [
+       "https://www.w3.org/ns/activitystreams#Public",
+       User.ap_followers(actor)
+     ]
+     mentions = :xmerl_xpath.string('//link[@rel="mentioned" and @ostatus:object-type="http://activitystrea.ms/schema/1.0/person"]', entry)
+     |> Enum.map(fn(person) -> string_from_xpath("@href", person) end)
+     to = to ++ mentions
+     date = string_from_xpath("//published", entry)
+     id = string_from_xpath("//id", entry)
+     object = %{
+       "id" => id,
+       "type" => "Note",
+       "to" => to,
+       "content" => content_html,
+       "published" => date,
+       "context" => context,
+       "actor" => actor.ap_id,
+       "attachment" => attachments
+     }
+     object = if inReplyTo do
+       Map.put(object, "inReplyTo", inReplyTo)
+     else
+       object
+     end
+     # TODO: Bail out sooner and use transaction.
+     if Object.get_by_ap_id(id) do
+       {:error, "duplicate activity"}
+     else
+       ActivityPub.create(to, actor, context, object, %{}, date, false)
+     end
+   end
+   def find_make_or_update_user(doc) do
+     uri = string_from_xpath("//author/uri[1]", doc)
+     with {:ok, user} <- find_or_make_user(uri) do
+       avatar = make_avatar_object(doc)
 -      if user.avatar != avatar do
++      if !user.local && user.avatar != avatar do
+         change = Ecto.Changeset.change(user, %{avatar: avatar})
+         Repo.update(change)
+       else
+         {:ok, user}
+       end
+     end
+   end
+   def find_or_make_user(uri) do
+     query = from user in User,
+       where: user.ap_id == ^uri
+     user = Repo.one(query)
+     if is_nil(user) do
+       make_user(uri)
+     else
+       {:ok, user}
+     end
+   end
+   def make_user(uri) do
+     with {:ok, info} <- gather_user_info(uri) do
+       data = %{
+         local: false,
+         name: info["name"],
+         nickname: info["nickname"] <> "@" <> info["host"],
+         ap_id: info["uri"],
+         info: info,
+         avatar: info["avatar"]
+       }
+       # TODO: Make remote user changeset
+       # SHould enforce fqn nickname
+       Repo.insert(Ecto.Changeset.change(%User{}, data))
+     end
+   end
+   # TODO: Just takes the first one for now.
+   def make_avatar_object(author_doc) do
+     href = string_from_xpath("//author[1]/link[@rel=\"avatar\"]/@href", author_doc)
+     type = string_from_xpath("//author[1]/link[@rel=\"avatar\"]/@type", author_doc)
+     if href do
+       %{
+         "type" => "Image",
+         "url" =>
+           [%{
+               "type" => "Link",
+               "mediaType" => type,
+               "href" => href
+            }]
+       }
+     else
+       nil
+     end
+   end
+   def gather_user_info(username) do
+     with {:ok, webfinger_data} <- WebFinger.finger(username),
+          {:ok, feed_data} <- Websub.gather_feed_data(webfinger_data["topic"]) do
+       {:ok, Map.merge(webfinger_data, feed_data) |> Map.put("fqn", username)}
+     else e ->
+       Logger.debug(fn -> "Couldn't gather info for #{username}" end)
+       {:error, e}
+     end
+   end
+   # Regex-based 'parsing' so we don't have to pull in a full html parser
+   # It's a hack anyway. Maybe revisit this in the future
+   @mastodon_regex ~r/<link href='(.*)' rel='alternate' type='application\/atom\+xml'>/
+   @gs_regex ~r/<link title=.* href="(.*)" type="application\/atom\+xml" rel="alternate">/
+   @gs_classic_regex ~r/<link rel="alternate" href="(.*)" type="application\/atom\+xml" title=.*>/
+   def get_atom_url(body) do
+     cond do
+       Regex.match?(@mastodon_regex, body) ->
+         [[_, match]] = Regex.scan(@mastodon_regex, body)
+         {:ok, match}
+       Regex.match?(@gs_regex, body) ->
+         [[_, match]] = Regex.scan(@gs_regex, body)
+         {:ok, match}
+       Regex.match?(@gs_classic_regex, body) ->
+         [[_, match]] = Regex.scan(@gs_classic_regex, body)
+         {:ok, match}
+       true ->
+         Logger.debug(fn -> "Couldn't find atom link in #{inspect(body)}" end)
+         {:error, "Couldn't find the atom link"}
+     end
+   end
+   def fetch_activity_from_html_url(url) do
+     with {:ok, %{body: body}} <- @httpoison.get(url, [], follow_redirect: true),
+          {:ok, atom_url} <- get_atom_url(body),
+          {:ok, %{status_code: code, body: body}} when code in 200..299 <- @httpoison.get(atom_url, [], follow_redirect: true) do
+       handle_incoming(body)
+     end
    end
  end
index f2bf93abb26c5ba84879bc653aa36144dd6a7b1d,3fef8eec86653f1a7cc9641c08389b225f905419..affd435771e28d4f792d933b6041cd1bdbe58994
@@@ -1,8 -1,9 +1,10 @@@
  defmodule Pleroma.Web.TwitterAPI.Representers.ActivityRepresenter do
    use Pleroma.Web.TwitterAPI.Representers.BaseRepresenter
    alias Pleroma.Web.TwitterAPI.Representers.{UserRepresenter, ObjectRepresenter}
-   alias Pleroma.Activity
+   alias Pleroma.{Activity, User}
+   alias Calendar.Strftime
+   alias Pleroma.Web.TwitterAPI.TwitterAPI
++  alias Pleroma.Wi
  
    defp user_by_ap_id(user_list, ap_id) do
      Enum.find(user_list, fn (%{ap_id: user_id}) -> ap_id == user_id end)
index 8e2cd98ca8c19e4d1b08c9e2defb032f4c956983,3921c0d74e75adbb589695f2d8c81887b47896ea..793a55250ce7ca3af8a571c2a5d84706df8cc8b3
@@@ -116,32 -134,29 +134,27 @@@ defmodule Pleroma.Web.TwitterAPI.Twitte
    end
  
    def follow(%User{} = follower, params) do
-     with { :ok, %User{} = followed } <- get_user(params),
-          { :ok, follower } <- User.follow(follower, followed),
-          { :ok, activity } <- ActivityPub.insert(%{
-            "type" => "Follow",
-            "actor" => follower.ap_id,
-            "object" => followed.ap_id,
-            "published" => make_date()
-          })
+     with {:ok, %User{} = followed} <- get_user(params),
+          {:ok, follower} <- User.follow(follower, followed),
 -         {:ok, activity} <- ActivityPub.insert(%{
 -           "type" => "Follow",
 -           "actor" => follower.ap_id,
 -           "to" => [followed.ap_id],
 -           "object" => followed.ap_id,
 -           "published" => make_date()
 -         })
++         {:ok, activity} <- ActivityPub.follow(follower, followed)
      do
-       { :ok, follower, followed, activity }
 -      # TODO move all this to ActivityPub
 -      Pleroma.Web.Federator.enqueue(:publish, activity)
+       {:ok, follower, followed, activity}
      else
        err -> err
      end
    end
  
- def unfollow(%User{} = follower, params) do
  def unfollow(%User{} = follower, params) do
 -    with {:ok, %User{} = unfollowed} <- get_user(params),
 -         {:ok, follower} <- User.unfollow(follower, unfollowed)
 +    with { :ok, %User{} = unfollowed } <- get_user(params),
 +         { :ok, follower, follow_activity } <- User.unfollow(follower, unfollowed),
 +         { :ok, _activity } <- ActivityPub.insert(%{
 +           "type" => "Undo",
 +           "actor" => follower.ap_id,
-            "object" => follow_activity, # get latest Follow for these users
++           "object" => follow_activity.data["id"], # get latest Follow for these users
 +           "published" => make_date()
 +         })
      do
 -      {:ok, follower, unfollowed}
 +      { :ok, follower, unfollowed }
      else
        err -> err
      end
Simple merge
Simple merge
index bf9090d2f3dbe75b545e6f6b18f8bf337f2f0a76,dfa73b775bde52c338a8c92e1727b9aa81f32945..a9a6e13647cca2ac78fa680bbb740f044bf98a2a
@@@ -194,16 -203,6 +203,40 @@@ defmodule Pleroma.Web.ActivityPub.Activ
      end
    end
  
 +  describe "fetch the latest Follow" do
 +    test "fetches the latest Follow activity" do
 +      %Activity{data: %{"type" => "Follow"}} = activity = insert(:follow_activity)
 +      follower = Repo.get_by(User, ap_id: activity.data["actor"])
 +      followed = Repo.get_by(User, ap_id: activity.data["object"])
 +
 +      assert activity == ActivityPub.fetch_latest_follow(follower, followed)
 +    end
 +  end
 +
++  describe "following / unfollowing" do
++    test "creates a follow activity" do
++      follower = insert(:user)
++      followed = insert(:user)
++
++      {:ok, activity} = ActivityPub.follow(follower, followed)
++      assert activity.data["type"] == "Follow"
++      assert activity.data["actor"] == follower.ap_id
++      assert activity.data["object"] == followed.ap_id
++    end
++
++    test "creates an undo activity for the last follow" do
++      follower = insert(:user)
++      followed = insert(:user)
++
++      {:ok, follow_activity} = ActivityPub.follow(follower, followed)
++      {:ok, activity} = ActivityPub.unfollow(follower, followed)
++
++      assert activity.data["type"] == "Undo"
++      assert activity.data["actor"] == follower.ap_id
++      assert activity.data["object"] == follow_activity.data["id"]
++    end
++  end
++
    def data_uri do
      "data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD//gA7Q1JFQVRPUjogZ2QtanBlZyB2MS4wICh1c2luZyBJSkcgSlBFRyB2ODApLCBxdWFsaXR5ID0gODUK/9sAQwAFAwQEBAMFBAQEBQUFBgcMCAcHBwcPCwsJDBEPEhIRDxERExYcFxMUGhURERghGBodHR8fHxMXIiQiHiQcHh8e/9sAQwEFBQUHBgcOCAgOHhQRFB4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4e/8AAEQgA7ADsAwEiAAIRAQMRAf/EAB8AAAEFAQEBAQEBAAAAAAAAAAABAgMEBQYHCAkKC//EALUQAAIBAwMCBAMFBQQEAAABfQECAwAEEQUSITFBBhNRYQcicRQygZGhCCNCscEVUtHwJDNicoIJChYXGBkaJSYnKCkqNDU2Nzg5OkNERUZHSElKU1RVVldYWVpjZGVmZ2hpanN0dXZ3eHl6g4SFhoeIiYqSk5SVlpeYmZqio6Slpqeoqaqys7S1tre4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f5880b83b189ad5240045f2662
@@@ -32,6 -37,168 +37,206 @@@ defmodule Pleroma.Web.OStatus.ActivityR
      assert clean(res) == clean(expected)
    end
  
+   test "a reply note" do
+     note = insert(:note_activity)
+     answer = insert(:note_activity)
+     object = answer.data["object"]
+     object = Map.put(object, "inReplyTo", note.data["object"]["id"])
+     data = %{answer.data | "object" => object}
+     answer = %{answer | data: data}
+     updated_at = answer.updated_at
+     |> NaiveDateTime.to_iso8601
+     inserted_at = answer.inserted_at
+     |> NaiveDateTime.to_iso8601
+     user = User.get_cached_by_ap_id(answer.data["actor"])
+     expected = """
+     <activity:object-type>http://activitystrea.ms/schema/1.0/note</activity:object-type>
+     <activity:verb>http://activitystrea.ms/schema/1.0/post</activity:verb>
+     <id>#{answer.data["object"]["id"]}</id>
+     <title>New note by #{user.nickname}</title>
+     <content type="html">#{answer.data["object"]["content"]}</content>
+     <published>#{inserted_at}</published>
+     <updated>#{updated_at}</updated>
+     <ostatus:conversation>#{answer.data["context"]}</ostatus:conversation>
+     <link href="#{answer.data["context"]}" rel="ostatus:conversation" />
+     <link type="application/atom+xml" href="#{answer.data["object"]["id"]}" rel="self" />
+     <thr:in-reply-to ref="#{note.data["object"]["id"]}" />
+     <link rel="mentioned" ostatus:object-type="http://activitystrea.ms/schema/1.0/collection" href="http://activityschema.org/collection/public"/>
+     """
+     tuple = ActivityRepresenter.to_simple_form(answer, user)
+     res = :xmerl.export_simple_content(tuple, :xmerl_xml) |> IO.iodata_to_binary
+     assert clean(res) == clean(expected)
+   end
+   test "an announce activity" do
+     note = insert(:note_activity)
+     user = insert(:user)
+     object = Object.get_cached_by_ap_id(note.data["object"]["id"])
+     {:ok, announce, object} = ActivityPub.announce(user, object)
+     announce = Repo.get(Activity, announce.id)
+     note_user = User.get_cached_by_ap_id(note.data["actor"])
+     note = Repo.get(Activity, note.id)
+     note_xml = ActivityRepresenter.to_simple_form(note, note_user, true)
+     |> :xmerl.export_simple_content(:xmerl_xml)
+     |> to_string
+     updated_at = announce.updated_at
+     |> NaiveDateTime.to_iso8601
+     inserted_at = announce.inserted_at
+     |> NaiveDateTime.to_iso8601
+     expected = """
+     <activity:object-type>http://activitystrea.ms/schema/1.0/activity</activity:object-type>
+     <activity:verb>http://activitystrea.ms/schema/1.0/share</activity:verb>
+     <id>#{announce.data["id"]}</id>
+     <title>#{user.nickname} repeated a notice</title>
+     <content type="html">RT #{note.data["object"]["content"]}</content>
+     <published>#{inserted_at}</published>
+     <updated>#{updated_at}</updated>
+     <ostatus:conversation>#{announce.data["context"]}</ostatus:conversation>
+     <link href="#{announce.data["context"]}" rel="ostatus:conversation" />
+     <link rel="self" type="application/atom+xml" href="#{announce.data["id"]}"/>
+     <activity:object>
+       #{note_xml}
+     </activity:object>
+     <link rel="mentioned" ostatus:object-type="http://activitystrea.ms/schema/1.0/person" href="#{note.data["actor"]}"/>
+     """
+     announce_xml = ActivityRepresenter.to_simple_form(announce, user)
+     |> :xmerl.export_simple_content(:xmerl_xml)
+     |> to_string
+     assert clean(expected) == clean(announce_xml)
+   end
+   test "a like activity" do
+     note = insert(:note)
+     user = insert(:user)
+     {:ok, like, _note} = ActivityPub.like(user, note)
+     # TODO: Are these the correct dates?
+     updated_at = like.updated_at
+     |> NaiveDateTime.to_iso8601
+     inserted_at = like.inserted_at
+     |> NaiveDateTime.to_iso8601
+     tuple = ActivityRepresenter.to_simple_form(like, user)
+     refute is_nil(tuple)
+     res = :xmerl.export_simple_content(tuple, :xmerl_xml) |> IO.iodata_to_binary
+     expected = """
+     <activity:verb>http://activitystrea.ms/schema/1.0/favorite</activity:verb>
+     <id>#{like.data["id"]}</id>
+     <title>New favorite by #{user.nickname}</title>
+     <content type="html">#{user.nickname} favorited something</content>
+     <published>#{inserted_at}</published>
+     <updated>#{updated_at}</updated>
+     <activity:object>
+       <activity:object-type>http://activitystrea.ms/schema/1.0/note</activity:object-type>
+       <id>#{note.data["id"]}</id>
+     </activity:object>
+     <ostatus:conversation>#{like.data["context"]}</ostatus:conversation>
+     <link href="#{like.data["context"]}" rel="ostatus:conversation" />
+     <link rel="self" type="application/atom+xml" href="#{like.data["id"]}"/>
+     <thr:in-reply-to ref="#{note.data["id"]}" />
+     <link rel="mentioned" ostatus:object-type="http://activitystrea.ms/schema/1.0/person" href="#{note.data["actor"]}"/>
+     """
+     assert clean(res) == clean(expected)
+   end
+   test "a follow activity" do
+     follower = insert(:user)
+     followed = insert(:user)
+     {:ok, activity} = ActivityPub.insert(%{
+           "type" => "Follow",
+           "actor" => follower.ap_id,
+           "object" => followed.ap_id,
+           "to" => [followed.ap_id]
+     })
+     # TODO: Are these the correct dates?
+     updated_at = activity.updated_at
+     |> NaiveDateTime.to_iso8601
+     inserted_at = activity.inserted_at
+     |> NaiveDateTime.to_iso8601
+     tuple = ActivityRepresenter.to_simple_form(activity, follower)
+     refute is_nil(tuple)
+     res = :xmerl.export_simple_content(tuple, :xmerl_xml) |> IO.iodata_to_binary
+     expected = """
+     <activity:object-type>http://activitystrea.ms/schema/1.0/activity</activity:object-type>
+     <activity:verb>http://activitystrea.ms/schema/1.0/follow</activity:verb>
+     <id>#{activity.data["id"]}</id>
+     <title>#{follower.nickname} started following #{activity.data["object"]}</title>
+     <content type="html"> #{follower.nickname} started following #{activity.data["object"]}</content>
+     <published>#{inserted_at}</published>
+     <updated>#{updated_at}</updated>
+     <activity:object>
+       <activity:object-type>http://activitystrea.ms/schema/1.0/person</activity:object-type>
+       <id>#{activity.data["object"]}</id>
+       <uri>#{activity.data["object"]}</uri>
+     </activity:object>
+     <link rel="self" type="application/atom+xml" href="#{activity.data["id"]}"/>
+     <link rel="mentioned" ostatus:object-type="http://activitystrea.ms/schema/1.0/person" href="#{activity.data["object"]}"/>
+     """
+     assert clean(res) == clean(expected)
+   end
++  test "an unfollow activity" do
++    follower = insert(:user)
++    followed = insert(:user)
++    {:ok, _activity} = ActivityPub.follow(follower, followed)
++    {:ok, activity} = ActivityPub.unfollow(follower, followed)
++
++    # TODO: Are these the correct dates?
++    updated_at = activity.updated_at
++    |> NaiveDateTime.to_iso8601
++    inserted_at = activity.inserted_at
++    |> NaiveDateTime.to_iso8601
++
++    tuple = ActivityRepresenter.to_simple_form(activity, follower)
++
++    refute is_nil(tuple)
++
++    res = :xmerl.export_simple_content(tuple, :xmerl_xml) |> IO.iodata_to_binary
++
++    expected = """
++    <activity:object-type>http://activitystrea.ms/schema/1.0/activity</activity:object-type>
++    <activity:verb>http://activitystrea.ms/schema/1.0/unfollow</activity:verb>
++    <id>#{activity.data["id"]}</id>
++    <title>#{follower.nickname} stopped following #{followed.ap_id}</title>
++    <content type="html"> #{follower.nickname} stopped following #{followed.ap_id}</content>
++    <published>#{inserted_at}</published>
++    <updated>#{updated_at}</updated>
++    <activity:object>
++      <activity:object-type>http://activitystrea.ms/schema/1.0/person</activity:object-type>
++      <id>#{followed.ap_id}</id>
++      <uri>#{followed.ap_id}</uri>
++    </activity:object>
++    <link rel="self" type="application/atom+xml" href="#{activity.data["id"]}"/>
++    <link rel="mentioned" ostatus:object-type="http://activitystrea.ms/schema/1.0/person" href="#{followed.ap_id}"/>
++    """
++
++    assert clean(res) == clean(expected)
++  end
++
    test "an unknown activity" do
      tuple = ActivityRepresenter.to_simple_form(%Activity{}, nil)
      assert is_nil(tuple)
index 6c249be7d619a0807437b3ce5e795f080cc6e46f,05cd084b4fb9cb2c70837bb403a56a0a089f77fc..f8afbaee52b3d4a6995c8aeebb06bb0c6c6e76e9
@@@ -244,6 -245,6 +245,7 @@@ defmodule Pleroma.Web.TwitterAPI.Contro
  
        {:ok, current_user} = User.follow(current_user, followed)
        assert current_user.following == [User.ap_followers(followed)]
++      ActivityPub.follow(current_user, followed)
  
        conn = conn
        |> with_credentials(current_user.nickname, "test")
      header_content = "Basic " <> Base.encode64("#{username}:#{password}")
      put_req_header(conn, "authorization", header_content)
    end
--
--  setup do
--    Supervisor.terminate_child(Pleroma.Supervisor, ConCache)
--    Supervisor.restart_child(Pleroma.Supervisor, ConCache)
--    :ok
--  end
  end
index 590428423b2e3a23e97476c3cfba61d572be328b,a92440f32feda2ac00b18f3021744d1994894f77..9a7dc48dab42e472cd90e1413f21b8dd8509eb37
@@@ -180,6 -190,6 +190,7 @@@ defmodule Pleroma.Web.TwitterAPI.Twitte
    test "Unfollow another user using user_id" do
      unfollowed = insert(:user)
      user = insert(:user, %{following: [User.ap_followers(unfollowed)]})
++    ActivityPub.follow(user, unfollowed)
  
      {:ok, user, unfollowed } = TwitterAPI.unfollow(user, %{"user_id" => unfollowed.id})
      assert user.following == []
      unfollowed = insert(:user)
      user = insert(:user, %{following: [User.ap_followers(unfollowed)]})
  
++    ActivityPub.follow(user, unfollowed)
++
      {:ok, user, unfollowed } = TwitterAPI.unfollow(user, %{"screen_name" => unfollowed.nickname})
      assert user.following == []