3 Chats are a way to represent an IM-style conversation between two actors. They are not the same as direct messages and they are not `Status`es, even though they have a lot in common.
7 There are no 'visibility levels' in ActivityPub, their definition is purely a Mastodon convention. Direct Messaging between users on the fediverse has mostly been modeled by using ActivityPub addressing following Mastodon conventions on normal `Note` objects. In this case, a 'direct message' would be a message that has no followers addressed and also does not address the special public actor, but just the recipients in the `to` field. It would still be a `Note` and is presented with other `Note`s as a `Status` in the API.
9 This is an awkward setup for a few reasons:
11 - As DMs generally still follow the usual `Status` conventions, it is easy to accidentally pull somebody into a DM thread by mentioning them. (e.g. "I hate @badguy so much")
12 - It is possible to go from a publicly addressed `Status` to a DM reply, back to public, then to a 'followers only' reply, and so on. This can be become very confusing, as it is unclear which user can see which part of the conversation.
13 - The standard `Status` format of implicit addressing also leads to rather ugly results if you try to display the messages as a chat, because all the recipients are always mentioned by name in the message.
14 - As direct messages are posted with the same api call (and usually same frontend component) as public messages, accidentally making a public message private or vice versa can happen easily. Client bugs can also lead to this, accidentally making private messages public.
16 As a measure to improve this situation, the `Conversation` concept and related Pleroma extensions were introduced. While it made it possible to work around a few of the issues, many of the problems remained and it didn't see much adoption because it was too complicated to use correctly.
19 For this reasons, Chats are a new and different entity, both in the API as well as in ActivityPub. A quick overview:
21 - Chats are meant to represent an instant message conversation between two actors. For now these are only 1-on-1 conversations, but the other actor can be a group in the future.
22 - Chat messages have the ActivityPub type `ChatMessage`. They are not `Note`s. Servers that don't understand them will just drop them.
23 - The only addressing allowed in `ChatMessage`s is one single ActivityPub actor in the `to` field.
24 - There's always only one Chat between two actors. If you start chatting with someone and later start a 'new' Chat, the old Chat will be continued.
25 - `ChatMessage`s are posted with a different api, making it very hard to accidentally send a message to the wrong person.
26 - `ChatMessage`s don't show up in the existing timelines.
27 - Chats can never go from private to public. They are always private between the two actors.
31 - Chats are NOT E2E encrypted (yet). Security is still the same as email.
35 In general, the way to send a `ChatMessage` is to first create a `Chat`, then post a message to that `Chat`. The actors in the API are generally given by their ActivityPub id to make it easier to support later `Group` scenarios.
37 This is the overview of using the API. The API is also documented via OpenAPI, so you can view it and play with it by pointing SwaggerUI or a similar OpenAPI tool to `https://yourinstance.tld/api/openapi`.
39 ### Creating or getting a chat.
41 To create or get an existing Chat for a certain recipient (identified by AP ID)
44 `POST /api/v1/pleroma/chats/by-ap-id/{ap_id}`
46 The ap_id of the recipients needs to be www-form encoded, so
49 https://originalpatchou.li/user/lambda
55 https%3A%2F%2Foriginalpatchou.li%2Fuser%2Flambda
58 The full call would then be
61 POST /api/v1/pleroma/chats/by-ap-id/https%3A%2F%2Foriginalpatchou.li%2Fuser%2Flambda
64 There will only ever be ONE Chat for you and a given recipient, so this call
65 will return the same Chat if you already have one with that user.
71 "recipient" : "https://dontbulling.me/users/lain",
72 "recipient_account": {
74 "username": "somenick",
82 ### Getting a list of Chats
84 `GET /api/v1/pleroma/chats`
86 This will return a list of chats that you have been involved in, sorted by their
87 last update (so new chats will be at the top).
94 "recipient" : "https://dontbulling.me/users/lain",
95 "recipient_account": {
97 "username": "somenick",
106 The recipient of messages that are sent to this chat is given by their AP ID.
107 The usual pagination options are implemented.
109 ### Getting the messages for a Chat
111 For a given Chat id, you can get the associated messages with
113 `GET /api/v1/pleroma/chats/{id}/messages`
115 This will return all messages, sorted by most recent to least recent. The usual
116 pagination options are implemented
123 "actor": "https://dontbulling.me/users/lain",
125 "content": "Check this out :firefox:",
126 "created_at": "2020-04-21T15:11:46.000Z",
129 "shortcode": "firefox",
130 "static_url": "https://dontbulling.me/emoji/Firefox.gif",
131 "url": "https://dontbulling.me/emoji/Firefox.gif",
132 "visible_in_picker": false
138 "actor": "https://dontbulling.me/users/lain",
140 "content": "Whats' up?",
141 "created_at": "2020-04-21T15:06:45.000Z",
148 ### Posting a chat message
150 Posting a chat message for given Chat id works like this:
152 `POST /api/v1/pleroma/chats/{id}/messages`
155 - content: The text content of the message
157 Currently, no formatting beyond basic escaping and emoji is implemented, as well as no
158 attachments. This will most probably change.
164 "actor": "https://dontbulling.me/users/lain",
166 "content": "Check this out :firefox:",
167 "created_at": "2020-04-21T15:11:46.000Z",
170 "shortcode": "firefox",
171 "static_url": "https://dontbulling.me/emoji/Firefox.gif",
172 "url": "https://dontbulling.me/emoji/Firefox.gif",
173 "visible_in_picker": false
182 There's a new `pleroma:chat_mention` notification, which has this form:
187 "type": "pleroma:chat_mention",
188 "account": { ... } // User account of the sender,
193 "actor": "https://dontbulling.me/users/lain"
195 "created_at": "somedate"