notifications.proto 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  1. syntax = "proto3";
  2. package chatto.api.v1;
  3. import "buf/validate/validate.proto";
  4. import "chatto/api/v1/pagination.proto";
  5. import "chatto/api/v1/rooms.proto";
  6. import "chatto/api/v1/users.proto";
  7. import "google/protobuf/descriptor.proto";
  8. import "google/protobuf/timestamp.proto";
  9. // Direct-message notification payload.
  10. message DirectMessageNotification {
  11. reserved 1;
  12. reserved "room_id";
  13. // Message event ID.
  14. string event_id = 2;
  15. // DM room where the message was posted.
  16. RoomSummary room = 3;
  17. }
  18. // Mention notification payload.
  19. message MentionNotification {
  20. // Room where the mention occurred.
  21. RoomSummary room = 1;
  22. // Message event ID.
  23. string event_id = 2;
  24. // Thread root event ID when the mention happened inside a thread.
  25. optional string thread_root_event_id = 3;
  26. }
  27. // Reply notification payload.
  28. message ReplyNotification {
  29. // Room where the reply occurred.
  30. RoomSummary room = 1;
  31. // Reply event ID.
  32. string event_id = 2;
  33. // Event ID of the message being replied to.
  34. string in_reply_to_id = 3;
  35. // Thread root event ID when the reply happened inside a thread.
  36. optional string thread_root_event_id = 4;
  37. }
  38. // All-messages room notification payload.
  39. message RoomMessageNotification {
  40. // Room where the message was posted.
  41. RoomSummary room = 1;
  42. // Message event ID.
  43. string event_id = 2;
  44. }
  45. // One pending notification for the authenticated viewer.
  46. message NotificationItem {
  47. reserved 4;
  48. reserved "summary";
  49. // Stable notification ID.
  50. string id = 1;
  51. // Creation time.
  52. google.protobuf.Timestamp created_at = 2;
  53. // User who triggered the notification, when still resolvable.
  54. User actor = 3;
  55. oneof kind {
  56. // Direct-message notification.
  57. DirectMessageNotification direct_message = 10;
  58. // Mention notification.
  59. MentionNotification mention = 11;
  60. // Reply notification.
  61. ReplyNotification reply = 12;
  62. // All-messages room notification.
  63. RoomMessageNotification room_message = 13;
  64. }
  65. }
  66. // Request for the authenticated viewer's pending notifications.
  67. message ListNotificationsRequest {
  68. reserved 1, 2;
  69. reserved "limit", "offset";
  70. // Page request. Defaults to 50 results when absent or limit is zero.
  71. PageRequest page = 3;
  72. }
  73. // Request for pending notifications scoped to one room.
  74. message ListRoomNotificationsRequest {
  75. reserved 2, 3;
  76. reserved "limit", "offset";
  77. // Required. Room whose notifications should be listed.
  78. string room_id = 1 [(buf.validate.field).string.min_len = 1];
  79. // Page request. Defaults to 50 results when absent or limit is zero.
  80. PageRequest page = 4;
  81. }
  82. // Pending notification page.
  83. message ListNotificationsResponse {
  84. reserved 2, 3, 4;
  85. reserved "total_count", "has_more", "server_name";
  86. // Page notifications, newest first.
  87. repeated NotificationItem notifications = 1;
  88. // Page metadata.
  89. PageInfo page = 5;
  90. }
  91. // Request one pending notification for the authenticated viewer.
  92. message GetNotificationRequest {
  93. // Required notification ID.
  94. string notification_id = 1 [(buf.validate.field).string.min_len = 1];
  95. }
  96. // Pending notification response.
  97. message GetNotificationResponse {
  98. reserved 2;
  99. reserved "server_name";
  100. // Requested notification.
  101. NotificationItem notification = 1;
  102. }
  103. // Request pending notifications for a set of stable notification IDs.
  104. message BatchGetNotificationsRequest {
  105. // Required notification IDs. Unknown or dismissed IDs are omitted from the
  106. // response.
  107. repeated string notification_ids = 1 [(buf.validate.field).repeated = {
  108. min_items: 1
  109. max_items: 100
  110. items: {
  111. string: {min_len: 1}
  112. }
  113. }];
  114. }
  115. // Batch pending notification response.
  116. message BatchGetNotificationsResponse {
  117. reserved 2;
  118. reserved "server_name";
  119. // Found notifications. The server preserves first-seen request order and
  120. // de-duplicates repeated IDs.
  121. repeated NotificationItem notifications = 1;
  122. }
  123. // Pending notification page scoped to one room.
  124. message ListRoomNotificationsResponse {
  125. reserved 2, 3, 4;
  126. reserved "total_count", "has_more", "server_name";
  127. // Page notifications, newest first.
  128. repeated NotificationItem notifications = 1;
  129. // Page metadata.
  130. PageInfo page = 5;
  131. }
  132. // Request for a lightweight pending notification check.
  133. message HasNotificationsRequest {}
  134. // Lightweight pending notification check.
  135. message HasNotificationsResponse {
  136. // True when the authenticated viewer has at least one pending notification.
  137. bool has_notifications = 1;
  138. }
  139. // Pending notification count for one room.
  140. message RoomNotificationCount {
  141. // Room ID.
  142. string room_id = 1;
  143. // Pending notification count for the authenticated viewer in this room.
  144. int32 total_count = 2;
  145. }
  146. // Request for pending notification counts grouped by room.
  147. message ListRoomNotificationCountsRequest {}
  148. // Finite snapshot of pending notification counts grouped by room.
  149. message ListRoomNotificationCountsResponse {
  150. // Counts for rooms with at least one pending notification.
  151. repeated RoomNotificationCount room_counts = 1;
  152. }
  153. // Request to dismiss one pending notification.
  154. message DismissNotificationRequest {
  155. // Required. Notification to dismiss.
  156. string notification_id = 1 [(buf.validate.field).string.min_len = 1];
  157. }
  158. // Result of dismissing one pending notification.
  159. message DismissNotificationResponse {
  160. // True when the notification is no longer pending.
  161. bool dismissed = 1;
  162. }
  163. // Request to dismiss all pending notifications.
  164. message DismissAllNotificationsRequest {}
  165. // Result of dismissing all pending notifications.
  166. message DismissAllNotificationsResponse {
  167. // Number of notifications dismissed.
  168. int32 dismissed_count = 1;
  169. }
  170. // Reads and dismisses pending notifications for the authenticated viewer.
  171. service NotificationService {
  172. // Lists the authenticated viewer's pending notifications.
  173. rpc ListNotifications(ListNotificationsRequest) returns (ListNotificationsResponse);
  174. // Gets one pending notification. Returns NOT_FOUND when the notification is
  175. // unknown or has been dismissed.
  176. rpc GetNotification(GetNotificationRequest) returns (GetNotificationResponse);
  177. // Gets pending notifications by ID.
  178. rpc BatchGetNotifications(BatchGetNotificationsRequest) returns (BatchGetNotificationsResponse);
  179. // Lists pending notifications for one room. Non-members receive an empty page.
  180. rpc ListRoomNotifications(ListRoomNotificationsRequest) returns (ListRoomNotificationsResponse);
  181. // Lists pending notification counts grouped by room as a finite snapshot.
  182. rpc ListRoomNotificationCounts(ListRoomNotificationCountsRequest) returns (ListRoomNotificationCountsResponse);
  183. // Checks whether the authenticated viewer has any pending notifications.
  184. rpc HasNotifications(HasNotificationsRequest) returns (HasNotificationsResponse);
  185. // Dismisses one pending notification. Already-dismissed notifications are
  186. // treated as idempotent success.
  187. rpc DismissNotification(DismissNotificationRequest) returns (DismissNotificationResponse) {
  188. option idempotency_level = IDEMPOTENT;
  189. }
  190. // Dismisses all pending notifications.
  191. rpc DismissAllNotifications(DismissAllNotificationsRequest) returns (DismissAllNotificationsResponse);
  192. }