notifications.proto 6.9 KB

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