rooms.proto 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525
  1. syntax = "proto3";
  2. package chatto.api.v1;
  3. import "google/protobuf/field_mask.proto";
  4. import "buf/validate/validate.proto";
  5. import "chatto/api/v1/attachments.proto";
  6. import "chatto/api/v1/common.proto";
  7. import "chatto/api/v1/member_directory.proto";
  8. import "chatto/api/v1/pagination.proto";
  9. import "chatto/api/v1/read_state.proto";
  10. import "chatto/api/v1/room_timeline.proto";
  11. import "chatto/api/v1/message_types.proto";
  12. import "google/protobuf/timestamp.proto";
  13. // Kind of room represented by the public API.
  14. enum RoomKind {
  15. // The room kind was not specified.
  16. ROOM_KIND_UNSPECIFIED = 0;
  17. // A regular channel governed by server and room permissions.
  18. ROOM_KIND_CHANNEL = 1;
  19. // A direct-message conversation between members.
  20. ROOM_KIND_DM = 2;
  21. }
  22. // Public room metadata returned by room commands.
  23. message Room {
  24. // Stable room ID.
  25. string id = 1;
  26. // Room kind.
  27. RoomKind kind = 2;
  28. // Room name. Direct-message rooms may have an empty name because clients
  29. // derive their display label from participants.
  30. string name = 3;
  31. // Optional room description.
  32. string description = 4;
  33. // True when the room is archived and hidden from active room lists.
  34. bool archived = 5;
  35. // Room group ID for channel rooms. Empty for direct-message rooms.
  36. string group_id = 6;
  37. // True when a channel grants effective membership to eligible server members.
  38. bool universal = 7;
  39. // Minimum number of seconds a non-exempt member must wait between message
  40. // posts. Channel rooms only; zero means slow mode is disabled.
  41. uint32 slow_mode_seconds = 8;
  42. // Threading policy for this channel room. Direct-message rooms report
  43. // UNSPECIFIED because they do not support threads.
  44. RoomThreadingMode threading_mode = 9;
  45. }
  46. // Lightweight room reference for cross-resource rows.
  47. message RoomSummary {
  48. // Stable room ID.
  49. string id = 1;
  50. // Room kind.
  51. RoomKind kind = 2;
  52. // Room name. Direct-message rooms may have an empty name because clients
  53. // derive their display label from participants.
  54. string name = 3;
  55. }
  56. // Request to create a channel room.
  57. message CreateRoomRequest {
  58. // Required. Visible 1–30-code-point Unicode name of the new channel room.
  59. // The server trims and stores it in NFC form. Control characters and Unicode
  60. // line or paragraph separators are rejected.
  61. string name = 1 [(buf.validate.field).string = {
  62. min_len: 1
  63. max_len: 30
  64. }];
  65. // Optional room description.
  66. string description = 2 [(buf.validate.field).string.max_len = 500];
  67. // Required. Room group that should contain the new channel.
  68. string group_id = 3 [(buf.validate.field).string.min_len = 1];
  69. // Whether the new channel should grant effective membership to eligible
  70. // server members.
  71. bool universal = 4;
  72. // Threading policy for the new channel. UNSPECIFIED selects ENABLED.
  73. RoomThreadingMode threading_mode = 5;
  74. }
  75. // Result of creating a room.
  76. message CreateRoomResponse {
  77. // Created room.
  78. Room room = 1;
  79. }
  80. // Request to update a room's editable metadata.
  81. // update_mask selects editable fields to apply or reset. Fields outside the
  82. // mask stay unchanged.
  83. message UpdateRoomRequest {
  84. // Required. Room to update.
  85. string room_id = 1 [(buf.validate.field).string.min_len = 1];
  86. // New visible 1–30-code-point Unicode room name, when changing it. The server
  87. // trims and stores it in NFC form. Control characters and Unicode line or
  88. // paragraph separators are rejected.
  89. optional string name = 2 [(buf.validate.field).string = {
  90. min_len: 1
  91. max_len: 30
  92. }];
  93. // New room description, when changing it. Empty clears the description.
  94. optional string description = 3 [(buf.validate.field).string.max_len = 500];
  95. // New universal membership state, when changing it. Direct-message rooms
  96. // cannot be universal.
  97. optional bool universal = 4;
  98. // New per-user posting interval in seconds. Zero disables slow mode. The
  99. // maximum supported interval is six hours. Direct-message rooms cannot use
  100. // slow mode.
  101. optional uint32 slow_mode_seconds = 5 [(buf.validate.field).uint32.lte = 21600];
  102. // New threading policy. Direct-message rooms cannot set this field, and an
  103. // explicitly supplied UNSPECIFIED or unknown value is rejected.
  104. optional RoomThreadingMode threading_mode = 6;
  105. // Editable fields to apply or reset: name, description, universal, slow_mode_seconds, threading_mode.
  106. // Omit to infer populated fields; * selects all editable fields. An explicit
  107. // empty mask is invalid. Unselected values are ignored. Selected absent values
  108. // reset the field to its default, subject to field validation.
  109. google.protobuf.FieldMask update_mask = 7;
  110. }
  111. // Result of updating a room.
  112. message UpdateRoomResponse {
  113. // Updated room.
  114. Room room = 1;
  115. }
  116. // Request to archive a room.
  117. message ArchiveRoomRequest {
  118. // Required. Room to archive.
  119. string room_id = 1 [(buf.validate.field).string.min_len = 1];
  120. }
  121. // Result of archiving a room.
  122. message ArchiveRoomResponse {
  123. // Archived room.
  124. Room room = 1;
  125. }
  126. // Request to unarchive a room.
  127. message UnarchiveRoomRequest {
  128. // Required. Room to unarchive.
  129. string room_id = 1 [(buf.validate.field).string.min_len = 1];
  130. }
  131. // Result of unarchiving a room.
  132. message UnarchiveRoomResponse {
  133. // Unarchived room.
  134. Room room = 1;
  135. }
  136. // Request to join a room as the current user.
  137. message JoinRoomRequest {
  138. // Required. Room to join.
  139. string room_id = 1 [(buf.validate.field).string.min_len = 1];
  140. }
  141. // Result of joining a room.
  142. message JoinRoomResponse {
  143. // Joined room.
  144. Room room = 1;
  145. }
  146. // Request to join all joinable rooms in one room group.
  147. message JoinRoomGroupRequest {
  148. // Required. Room group whose rooms should be joined.
  149. string group_id = 1 [(buf.validate.field).string.min_len = 1];
  150. }
  151. // Result of joining all joinable rooms in one room group.
  152. message JoinRoomGroupResponse {
  153. // Room IDs that transitioned from not joined to joined.
  154. repeated string joined_room_ids = 1;
  155. }
  156. // Request to start a direct-message room for a human caller, or fetch an
  157. // existing one. A human caller can fetch an existing DM without message.post.
  158. // A valid request from a bot receives PERMISSION_DENIED, including when the
  159. // room already exists.
  160. message StartDMRequest {
  161. // Other participants to include in the direct-message room. The current user
  162. // is always included by the server. An empty list creates or fetches the
  163. // caller's self-DM.
  164. repeated string participant_ids = 1 [(buf.validate.field).repeated = {
  165. max_items: 9
  166. items: {
  167. string: {min_len: 1}
  168. }
  169. }];
  170. }
  171. // Result of starting or fetching a direct-message room.
  172. message StartDMResponse {
  173. // Direct-message room for the participant set.
  174. Room room = 1;
  175. }
  176. // Request to leave a room as the current user.
  177. message LeaveRoomRequest {
  178. // Required. Room to leave.
  179. string room_id = 1 [(buf.validate.field).string.min_len = 1];
  180. }
  181. // Result of leaving a room.
  182. message LeaveRoomResponse {
  183. reserved 1;
  184. reserved "left";
  185. }
  186. // Request to add a user to a channel room.
  187. message AddMemberRequest {
  188. // Required. Channel room to add the user to.
  189. string room_id = 1 [(buf.validate.field).string.min_len = 1];
  190. // Required. User to add as an explicit room member.
  191. string user_id = 2 [(buf.validate.field).string.min_len = 1];
  192. }
  193. // Result of adding a user to a room.
  194. message AddMemberResponse {
  195. // Added room member.
  196. DirectoryMember member = 1;
  197. }
  198. // Request to remove a user from a channel room.
  199. message RemoveMemberRequest {
  200. // Required. Channel room to remove the user from.
  201. string room_id = 1 [(buf.validate.field).string.min_len = 1];
  202. // Required. User to remove from the room's explicit members.
  203. string user_id = 2 [(buf.validate.field).string.min_len = 1];
  204. }
  205. // Result of removing a user from a room.
  206. message RemoveMemberResponse {
  207. // True when an explicit room membership was removed by this call.
  208. bool removed = 1;
  209. }
  210. // Request to ban a member from a channel room.
  211. message BanMemberRequest {
  212. // Required. Channel room to ban the user from.
  213. string room_id = 1 [(buf.validate.field).string.min_len = 1];
  214. // Required. User to ban from the room.
  215. string user_id = 2 [(buf.validate.field).string.min_len = 1];
  216. // Required moderator-entered reason stored for audit.
  217. string reason = 3 [(buf.validate.field).string = {
  218. min_len: 1
  219. max_len: 1000
  220. }];
  221. // Optional future time when the ban expires.
  222. google.protobuf.Timestamp expires_at = 4;
  223. }
  224. // Result of banning a room member.
  225. message BanMemberResponse {
  226. reserved 1;
  227. reserved "banned";
  228. }
  229. // Request to remove a channel room ban.
  230. message UnbanMemberRequest {
  231. // Required. Channel room to unban the user from.
  232. string room_id = 1 [(buf.validate.field).string.min_len = 1];
  233. // Required. User to unban.
  234. string user_id = 2 [(buf.validate.field).string.min_len = 1];
  235. // Required moderator-entered reason stored for audit.
  236. string reason = 3 [(buf.validate.field).string = {
  237. min_len: 1
  238. max_len: 1000
  239. }];
  240. }
  241. // Result of removing a room ban.
  242. message UnbanMemberResponse {
  243. reserved 1;
  244. reserved "unbanned";
  245. }
  246. // Active channel room ban with optional hydrated room and user references.
  247. message RoomBan {
  248. // Stable ban event ID.
  249. string id = 1;
  250. // Channel room ID.
  251. string room_id = 2;
  252. // Channel room metadata, when the referenced room still exists.
  253. Room room = 3;
  254. // Banned user ID.
  255. string user_id = 4;
  256. // Banned user profile, when the referenced user still exists.
  257. DirectoryMember user = 5;
  258. // Moderator user ID that created the ban.
  259. string moderator_id = 6;
  260. // Moderator profile, when the referenced user still exists.
  261. DirectoryMember moderator = 7;
  262. // Moderator-entered ban reason.
  263. string reason = 8;
  264. // Time the ban was created.
  265. google.protobuf.Timestamp created_at = 9;
  266. // Optional future time when the ban expires.
  267. google.protobuf.Timestamp expires_at = 10;
  268. }
  269. // Request to list active room bans.
  270. message ListBansRequest {
  271. // Optional channel room filter. Empty lists active bans across all rooms.
  272. string room_id = 1;
  273. // Defaults to 50 results when absent or limit is zero. Maximum: 100.
  274. PageRequest page = 2;
  275. }
  276. // Active room bans visible to the current moderator.
  277. message ListBansResponse {
  278. // Active bans by creation time, newest first; equal times use ban event ID
  279. // in ascending order.
  280. repeated RoomBan bans = 1;
  281. // Page metadata.
  282. PageInfo page = 2;
  283. }
  284. // Request for room-scoped attachment list pages.
  285. message ListRoomAttachmentsRequest {
  286. reserved 2, 3;
  287. reserved "limit", "offset";
  288. // Required room ID.
  289. string room_id = 1 [(buf.validate.field).string.min_len = 1];
  290. // Thumbnail URL options. Defaults are applied when absent.
  291. ImageTransformOptions thumbnail = 4;
  292. // Defaults to 50 results when absent or limit is zero. Maximum: 100.
  293. PageRequest page = 5;
  294. }
  295. // Room-scoped attachment list response.
  296. message ListRoomAttachmentsResponse {
  297. reserved 2, 3;
  298. reserved "total_count", "has_more";
  299. // Current attachments in newest message order.
  300. repeated RoomAttachmentListItem attachments = 1;
  301. // Page metadata.
  302. PageInfo page = 4;
  303. }
  304. // One current pinned message in a channel room.
  305. message PinnedMessage {
  306. // Current renderable message. Retracted messages are omitted from pin lists.
  307. Message message = 1;
  308. }
  309. // Request to list a channel room's current pinned messages.
  310. message ListPinnedMessagesRequest {
  311. // Required channel room ID.
  312. string room_id = 1 [(buf.validate.field).string.min_len = 1];
  313. // Defaults to 50 results when absent or limit is zero. Maximum: 100.
  314. PageRequest page = 2;
  315. }
  316. // Current pinned messages in one channel room.
  317. message ListPinnedMessagesResponse {
  318. // Pinned messages in newest-pin-first order.
  319. repeated PinnedMessage pinned_messages = 1;
  320. // Page metadata.
  321. PageInfo page = 2;
  322. // Opaque marker for the latest pin fact observed for this room. The value
  323. // remains stable when pins are removed so clients can detect new pins
  324. // without comparing wall-clock timestamps. Clients must not interpret it.
  325. string latest_pin_marker = 3;
  326. }
  327. // Request to pin a message in a channel room.
  328. message CreatePinnedMessageRequest {
  329. // Required channel room ID.
  330. string room_id = 1 [(buf.validate.field).string.min_len = 1];
  331. // Required canonical message event ID. Thread replies are supported.
  332. string message_event_id = 2 [(buf.validate.field).string.min_len = 1];
  333. }
  334. // Result of pinning a message.
  335. message CreatePinnedMessageResponse {
  336. // Current pinned-message resource. Repeating an existing pin returns it.
  337. PinnedMessage pinned_message = 1;
  338. }
  339. // Request to unpin a message from a channel room.
  340. message DeletePinnedMessageRequest {
  341. // Required channel room ID.
  342. string room_id = 1 [(buf.validate.field).string.min_len = 1];
  343. // Required canonical message event ID.
  344. string message_event_id = 2 [(buf.validate.field).string.min_len = 1];
  345. }
  346. // Result of unpinning a message.
  347. message DeletePinnedMessageResponse {
  348. // True when the message is not pinned after this call.
  349. bool deleted = 1;
  350. }
  351. // Request to refresh the current user's live-only typing indicator.
  352. message RefreshTypingIndicatorRequest {
  353. // Required. Room where the current user is typing.
  354. string room_id = 1 [(buf.validate.field).string.min_len = 1];
  355. // Event ID of the thread root when typing inside a thread.
  356. string thread_root_event_id = 2;
  357. }
  358. // Result of refreshing a typing indicator.
  359. message RefreshTypingIndicatorResponse {
  360. reserved 1;
  361. reserved "updated";
  362. }
  363. // Manages room-scoped operations for the current user.
  364. //
  365. // RoomService owns operations whose authorization and state are primarily scoped
  366. // to one room, including lifecycle, membership, moderation, room timeline reads,
  367. // room read state, attachments, and live typing. Resource-specific services
  368. // should still be preferred when an operation is not naturally room-scoped or
  369. // when the resource needs an independent CRUD/batch surface.
  370. service RoomService {
  371. // Reads the current viewer's stored marker without changing it. Requires the
  372. // same membership and read access as MarkRoomAsRead. Missing resources
  373. // return NOT_FOUND; inaccessible resources return PERMISSION_DENIED.
  374. rpc GetRoomReadState(GetRoomReadStateRequest) returns (GetRoomReadStateResponse);
  375. // Reads up to 100 states under the same authorization as GetRoomReadState.
  376. // Missing and inaccessible resources are omitted; duplicates use first-seen order.
  377. rpc BatchGetRoomReadStates(BatchGetRoomReadStatesRequest) returns (BatchGetRoomReadStatesResponse);
  378. // Creates a new channel room in a room group. The caller must be allowed to
  379. // create rooms in the target group.
  380. rpc CreateRoom(CreateRoomRequest) returns (CreateRoomResponse);
  381. // Updates a room's editable metadata. The caller must be allowed to manage
  382. // rooms. Direct-message rooms cannot be universal.
  383. rpc UpdateRoom(UpdateRoomRequest) returns (UpdateRoomResponse);
  384. // Archives a room so it is hidden from active room lists. The caller must be
  385. // allowed to manage rooms.
  386. rpc ArchiveRoom(ArchiveRoomRequest) returns (ArchiveRoomResponse);
  387. // Restores an archived room to active room lists. The caller must be allowed
  388. // to manage rooms.
  389. rpc UnarchiveRoom(UnarchiveRoomRequest) returns (UnarchiveRoomResponse);
  390. // Joins the room as the current user when room permissions allow it.
  391. rpc JoinRoom(JoinRoomRequest) returns (JoinRoomResponse);
  392. // Joins every unarchived room in a group that the current user can join.
  393. // Already-joined and non-joinable rooms are skipped.
  394. rpc JoinRoomGroup(JoinRoomGroupRequest) returns (JoinRoomGroupResponse);
  395. // Starts a direct-message room for the current human user and the requested
  396. // participant set, or fetches its existing DM. message.post is required
  397. // only when the DM must be created. A valid request from a bot receives
  398. // PERMISSION_DENIED and cannot use this RPC to fetch an existing DM.
  399. rpc StartDM(StartDMRequest) returns (StartDMResponse);
  400. // Leaves the room as the current user. Direct-message and universal rooms
  401. // cannot be left.
  402. rpc LeaveRoom(LeaveRoomRequest) returns (LeaveRoomResponse);
  403. // Lists effective room member IDs in ascending ID order. Resolve user details
  404. // with UserService.BatchGetUsers. Existing members and room.manage holders may
  405. // list a channel room; other nonmembers need both room.list and room.join.
  406. rpc ListMembers(ListMembersRequest) returns (ListMembersResponse);
  407. // Gets one effective member, including automatic universal membership.
  408. // Channel-room members, room.manage holders, and user.manage-accounts holders
  409. // may read members. Bot owners and bot.manage holders may read their target
  410. // bots only. DMs require caller membership. Returns NOT_FOUND for nonmembers.
  411. rpc GetMember(GetMemberRequest) returns (GetMemberResponse);
  412. // Gets effective member rows for the requested accounts. Uses the same
  413. // authorization as GetMember; omits unknown accounts and nonmembers.
  414. rpc BatchGetMembers(BatchGetMembersRequest) returns (BatchGetMembersResponse);
  415. // Adds an account as an explicit channel-room member. room.manage for this
  416. // room or user.manage-accounts overrides the target's missing room.join.
  417. // Bot owners and bot.manage holders may also add bots, but without either
  418. // override the bot needs effective room.join, bounded by its owner's authority.
  419. // Preserves permission grants. Bans, archived, universal, and DM rooms prevent adding.
  420. rpc AddMember(AddMemberRequest) returns (AddMemberResponse);
  421. // Removes an explicit channel-room member. Requires room.manage for this room,
  422. // user.manage-accounts, ownership of the target bot, or bot.manage.
  423. // Removal is allowed after room.join is lost and from archived rooms.
  424. // Preserves permission grants. Universal and DM membership cannot be edited.
  425. rpc RemoveMember(RemoveMemberRequest) returns (RemoveMemberResponse);
  426. // Lists active channel room bans. The caller must be allowed to moderate room
  427. // membership bans.
  428. rpc ListBans(ListBansRequest) returns (ListBansResponse);
  429. // Lists current message-owned room attachments. Authentication and room
  430. // membership are required. Attachments also require message.read or a
  431. // matching thread relationship with message.read-interactions. The server omits attachments from
  432. // inaccessible threads. Returns PERMISSION_DENIED when the room is
  433. // inaccessible to the caller.
  434. rpc ListRoomAttachments(ListRoomAttachmentsRequest) returns (ListRoomAttachmentsResponse);
  435. // Lists current pinned messages in a channel room. Room membership plus
  436. // message.read or message.read-interactions are required. The server omits
  437. // pins from threads that the caller cannot read. Direct-message rooms do not
  438. // support pins.
  439. rpc ListPinnedMessages(ListPinnedMessagesRequest) returns (ListPinnedMessagesResponse);
  440. // Pins a current message. The caller must have room.manage and must be able
  441. // to read the message. Repeating an existing pin is idempotent. Direct-message
  442. // rooms are rejected.
  443. rpc CreatePinnedMessage(CreatePinnedMessageRequest) returns (CreatePinnedMessageResponse);
  444. // Removes a current pin. The caller must have room.manage. Removing a
  445. // missing pin is idempotent. Direct-message rooms are rejected.
  446. rpc DeletePinnedMessage(DeletePinnedMessageRequest) returns (DeletePinnedMessageResponse);
  447. // Refreshes the current user's live-only typing indicator for a room or
  448. // thread. Room membership is required; message posting permission is not.
  449. // Send at most once every 2 seconds while typing. After posting a message,
  450. // the next typing activity can send immediately. Stop sending when typing
  451. // stops; receivers clear the indicator after 6 seconds without an event.
  452. rpc RefreshTypingIndicator(RefreshTypingIndicatorRequest) returns (RefreshTypingIndicatorResponse);
  453. // Returns one page of room timeline events, including related user data
  454. // needed to render the page. Room membership is required. Reads also require
  455. // message.read or message.read-interactions. The server returns only related
  456. // thread roots for an interaction-scoped caller.
  457. rpc GetRoomEvents(GetRoomEventsRequest) returns (GetRoomEventsResponse);
  458. // Returns a room timeline window centered around a specific event. Use this to
  459. // open a permalink, search result, or notification target in context. Returns
  460. // NOT_FOUND when the anchor event is missing or not visible in the room
  461. // timeline. Returns PERMISSION_DENIED when room membership or both read modes
  462. // are missing, or when the anchor is in an unrelated thread.
  463. rpc GetRoomEventsAround(GetRoomEventsAroundRequest) returns (GetRoomEventsAroundResponse);
  464. // Marks a room timeline as read through the supplied event. Room membership
  465. // is required. Reads also require message.read or
  466. // message.read-interactions. If no event
  467. // is supplied, the server marks through the latest root event that the caller
  468. // can read. Clients
  469. // usually call this after the user has viewed the latest visible event in the
  470. // room.
  471. rpc MarkRoomAsRead(MarkRoomAsReadRequest) returns (MarkRoomAsReadResponse);
  472. // Bans a member from a channel room. Direct-message rooms cannot be moderated
  473. // this way, and the target must currently be a room member.
  474. rpc BanMember(BanMemberRequest) returns (BanMemberResponse);
  475. // Removes an active channel room ban. Calling this when no active ban exists
  476. // is allowed and still returns success.
  477. rpc UnbanMember(UnbanMemberRequest) returns (UnbanMemberResponse);
  478. }