Pleroma uses 128-bit ids as opposed to Mastodon's 64 bits. However just like Mastodon's ids they are lexically sortable strings
- ## Attachment cap
-
- Some apps operate under the assumption that no more than 4 attachments can be returned or uploaded. Pleroma however does not enforce any limits on attachment count neither when returning the status object nor when posting.
-
## Timelines
Adding the parameter `with_muted=true` to the timeline queries will also return activities by muted (not by blocked!) users.
- `thread_muted`: true if the thread the post belongs to is muted
- `emoji_reactions`: A list with emoji / reaction maps. The format is `{name: "☕", count: 1, me: true}`. Contains no information about the reacting users, for that use the `/statuses/:id/reactions` endpoint.
- ## Attachments
+ ## Media Attachments
Has these additional fields under the `pleroma` object:
- `mime_type`: mime type of the attachment.
+ ### Attachment cap
+
+ Some apps operate under the assumption that no more than 4 attachments can be returned or uploaded. Pleroma however does not enforce any limits on attachment count neither when returning the status object nor when posting.
+
+ ### Limitations
+
+ Pleroma does not process remote images and therefore cannot include fields such as `meta` and `blurhash`. It does not support focal points or aspect ratios. The frontend is expected to handle it.
+
## Accounts
The `id` parameter can also be the `nickname` of the user. This only works in these endpoints, not the deeper nested ones for following etc.
Has these additional fields under the `pleroma` object:
- `unread_count`: contains number unread notifications
+
+## Streaming
+
+There is an additional `user:pleroma_chat` stream. Incoming chat messages will make the current chat be sent to this `user` stream. The `event` of an incoming chat message is `pleroma:chat_update`. The payload is the updated chat with the incoming chat message in the `last_message` field.
This module encodes our addressing policies and general shape of our objects.
"""
+ alias Pleroma.Emoji
alias Pleroma.Object
alias Pleroma.User
+ alias Pleroma.Web.ActivityPub.Relay
alias Pleroma.Web.ActivityPub.Utils
alias Pleroma.Web.ActivityPub.Visibility
}, []}
end
+ def create(actor, object, recipients) do
+ {:ok,
+ %{
+ "id" => Utils.generate_activity_id(),
+ "actor" => actor.ap_id,
+ "to" => recipients,
+ "object" => object,
+ "type" => "Create",
+ "published" => DateTime.utc_now() |> DateTime.to_iso8601()
+ }, []}
+ end
+
+ def chat_message(actor, recipient, content, opts \\ []) do
+ basic = %{
+ "id" => Utils.generate_object_id(),
+ "actor" => actor.ap_id,
+ "type" => "ChatMessage",
+ "to" => [recipient],
+ "content" => content,
+ "published" => DateTime.utc_now() |> DateTime.to_iso8601(),
+ "emoji" => Emoji.Formatter.get_emoji_map(content)
+ }
+
+ case opts[:attachment] do
+ %Object{data: attachment_data} ->
+ {
+ :ok,
+ Map.put(basic, "attachment", attachment_data),
+ []
+ }
+
+ _ ->
+ {:ok, basic, []}
+ end
+ end
+
@spec tombstone(String.t(), String.t()) :: {:ok, map(), keyword()}
def tombstone(actor, id) do
{:ok,
end
end
+ @spec announce(User.t(), Object.t(), keyword()) :: {:ok, map(), keyword()}
def announce(actor, object, options \\ []) do
public? = Keyword.get(options, :public, false)
- to = [actor.follower_address, object.data["actor"]]
to =
- if public? do
- [Pleroma.Constants.as_public() | to]
- else
- to
+ cond do
+ actor.ap_id == Relay.relay_ap_id() ->
+ [actor.follower_address]
+
+ public? ->
+ [actor.follower_address, object.data["actor"], Pleroma.Constants.as_public()]
+
+ true ->
+ [actor.follower_address, object.data["actor"]]
end
{:ok,
collection, and so on.
"""
alias Pleroma.Activity
+ alias Pleroma.Chat
alias Pleroma.Notification
alias Pleroma.Object
alias Pleroma.Repo
alias Pleroma.User
alias Pleroma.Web.ActivityPub.ActivityPub
+ alias Pleroma.Web.ActivityPub.Pipeline
alias Pleroma.Web.ActivityPub.Utils
+ alias Pleroma.Web.Streamer
def handle(object, meta \\ [])
{:ok, object, meta}
end
+ # Tasks this handles
+ # - Actually create object
+ # - Rollback if we couldn't create it
+ # - Set up notifications
+ def handle(%{data: %{"type" => "Create"}} = activity, meta) do
+ with {:ok, _object, _meta} <- handle_object_creation(meta[:object_data], meta) do
+ Notification.create_notifications(activity)
+ {:ok, activity, meta}
+ else
+ e -> Repo.rollback(e)
+ end
+ end
+
# Tasks this handles:
# - Add announce to object
# - Set up notification
# - Stream out the announce
def handle(%{data: %{"type" => "Announce"}} = object, meta) do
announced_object = Object.get_by_ap_id(object.data["object"])
+ user = User.get_cached_by_ap_id(object.data["actor"])
Utils.add_announce_to_object(object, announced_object)
- Notification.create_notifications(object)
- ActivityPub.stream_out(object)
+ if !User.is_internal_user?(user) do
+ Notification.create_notifications(object)
+ ActivityPub.stream_out(object)
+ end
{:ok, object, meta}
end
{:ok, object, meta}
end
+ def handle_object_creation(%{"type" => "ChatMessage"} = object, meta) do
+ with {:ok, object, meta} <- Pipeline.common_pipeline(object, meta) do
+ actor = User.get_cached_by_ap_id(object.data["actor"])
+ recipient = User.get_cached_by_ap_id(hd(object.data["to"]))
+
+ [[actor, recipient], [recipient, actor]]
+ |> Enum.each(fn [user, other_user] ->
+ if user.local do
+ if user.ap_id == actor.ap_id do
+ Chat.get_or_create(user.id, other_user.ap_id)
+ else
+ Chat.bump_or_create(user.id, other_user.ap_id)
+ end
+ end
+ end)
+
+ Streamer.stream(["user", "user:pleroma_chat"], object)
+ {:ok, object, meta}
+ end
+ end
+
+ # Nothing to do
+ def handle_object_creation(object) do
+ {:ok, object}
+ end
+
def handle_undoing(%{data: %{"type" => "Like"}} = object) do
with %Object{} = liked_object <- Object.get_by_ap_id(object.data["object"]),
{:ok, _} <- Utils.remove_like_from_object(object, liked_object),
alias Pleroma.Conversation.Participation
alias Pleroma.Notification
alias Pleroma.Object
+ alias Pleroma.Repo
alias Pleroma.User
alias Pleroma.Web.ActivityPub.ActivityPub
alias Pleroma.Web.ActivityPub.Visibility
def registry, do: @registry
@public_streams ["public", "public:local", "public:media", "public:local:media"]
- @user_streams ["user", "user:notification", "direct"]
+ @user_streams ["user", "user:notification", "direct", "user:pleroma_chat"]
@doc "Expands and authorizes a stream, and registers the process for streaming."
@spec get_topic_and_add_socket(stream :: String.t(), User.t() | nil, Map.t() | nil) ::
false <- Pleroma.Web.ActivityPub.MRF.subdomain_match?(domain_blocks, item_host),
false <- Pleroma.Web.ActivityPub.MRF.subdomain_match?(domain_blocks, parent_host),
true <- thread_containment(item, user),
- false <- CommonAPI.thread_muted?(user, item) do
+ false <- CommonAPI.thread_muted?(user, parent) do
false
else
_ -> true
end)
end
+ defp do_stream(topic, %{data: %{"type" => "ChatMessage"}} = object)
+ when topic in ["user", "user:pleroma_chat"] do
+ recipients = [object.data["actor"] | object.data["to"]]
+
+ topics =
+ %{ap_id: recipients, local: true}
+ |> Pleroma.User.Query.build()
+ |> Repo.all()
+ |> Enum.map(fn %{id: id} = user -> {user, "#{topic}:#{id}"} end)
+
+ Enum.each(topics, fn {user, topic} ->
+ Registry.dispatch(@registry, topic, fn list ->
+ Enum.each(list, fn {pid, _auth} ->
+ text = StreamerView.render("chat_update.json", object, user, recipients)
+ send(pid, {:text, text})
+ end)
+ end)
+ end)
+ end
+
defp do_stream("user", item) do
Logger.debug("Trying to push to users")
alias Pleroma.Conversation.Participation
alias Pleroma.List
+ alias Pleroma.Object
alias Pleroma.User
alias Pleroma.Web.CommonAPI
alias Pleroma.Web.Streamer
+ alias Pleroma.Web.StreamerView
@moduletag needs_streamer: true, capture_log: true
refute Streamer.filtered_by_user?(user, announce)
end
+ test "it streams boosts of mastodon user in the 'user' stream", %{user: user} do
+ Streamer.get_topic_and_add_socket("user", user)
+
+ other_user = insert(:user)
+ {:ok, activity} = CommonAPI.post(other_user, %{status: "hey"})
+
+ data =
+ File.read!("test/fixtures/mastodon-announce.json")
+ |> Poison.decode!()
+ |> Map.put("object", activity.data["object"])
+ |> Map.put("actor", user.ap_id)
+
+ {:ok, %Pleroma.Activity{data: _data, local: false} = announce} =
+ Pleroma.Web.ActivityPub.Transmogrifier.handle_incoming(data)
+
+ assert_receive {:render_with_user, Pleroma.Web.StreamerView, "update.json", ^announce}
+ refute Streamer.filtered_by_user?(user, announce)
+ end
+
test "it sends notify to in the 'user' stream", %{user: user, notify: notify} do
Streamer.get_topic_and_add_socket("user", user)
Streamer.stream("user", notify)
refute Streamer.filtered_by_user?(user, notify)
end
+ test "it sends chat messages to the 'user:pleroma_chat' stream", %{user: user} do
+ other_user = insert(:user)
+
+ {:ok, create_activity} = CommonAPI.post_chat_message(other_user, user, "hey")
+ object = Object.normalize(create_activity, false)
+ Streamer.get_topic_and_add_socket("user:pleroma_chat", user)
+ Streamer.stream("user:pleroma_chat", object)
+ text = StreamerView.render("chat_update.json", object, user, [user.ap_id, other_user.ap_id])
+ assert_receive {:text, ^text}
+ end
+
+ test "it sends chat messages to the 'user' stream", %{user: user} do
+ other_user = insert(:user)
+
+ {:ok, create_activity} = CommonAPI.post_chat_message(other_user, user, "hey")
+ object = Object.normalize(create_activity, false)
+ Streamer.get_topic_and_add_socket("user", user)
+ Streamer.stream("user", object)
+ text = StreamerView.render("chat_update.json", object, user, [user.ap_id, other_user.ap_id])
+ assert_receive {:text, ^text}
+ end
+
+ test "it sends chat message notifications to the 'user:notification' stream", %{user: user} do
+ other_user = insert(:user)
+
+ {:ok, create_activity} = CommonAPI.post_chat_message(other_user, user, "hey")
+
+ notify =
+ Repo.get_by(Pleroma.Notification, user_id: user.id, activity_id: create_activity.id)
+ |> Repo.preload(:activity)
+
+ Streamer.get_topic_and_add_socket("user:notification", user)
+ Streamer.stream("user:notification", notify)
+ assert_receive {:render_with_user, _, _, ^notify}
+ refute Streamer.filtered_by_user?(user, notify)
+ end
+
test "it doesn't send notify to the 'user:notification' stream when a user is blocked", %{
user: user
} do