@atproto/bsky 0.1.6 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (283) hide show
  1. package/CHANGELOG.md +58 -0
  2. package/dist/api/app/bsky/actor/getProfile.js +1 -1
  3. package/dist/api/app/bsky/actor/getProfile.js.map +1 -1
  4. package/dist/api/app/bsky/actor/getProfiles.js +1 -1
  5. package/dist/api/app/bsky/actor/getProfiles.js.map +1 -1
  6. package/dist/api/app/bsky/actor/getSuggestions.js +2 -2
  7. package/dist/api/app/bsky/actor/getSuggestions.js.map +1 -1
  8. package/dist/api/app/bsky/embed/getEmbedExternalView.d.ts.map +1 -1
  9. package/dist/api/app/bsky/embed/getEmbedExternalView.js +132 -53
  10. package/dist/api/app/bsky/embed/getEmbedExternalView.js.map +1 -1
  11. package/dist/api/app/bsky/feed/getAuthorFeed.d.ts.map +1 -1
  12. package/dist/api/app/bsky/feed/getAuthorFeed.js +4 -2
  13. package/dist/api/app/bsky/feed/getAuthorFeed.js.map +1 -1
  14. package/dist/api/app/bsky/graph/getSuggestedFollowsByActor.js +2 -2
  15. package/dist/api/app/bsky/graph/getSuggestedFollowsByActor.js.map +1 -1
  16. package/dist/api/app/bsky/notification/constants.d.ts +4 -1
  17. package/dist/api/app/bsky/notification/constants.d.ts.map +1 -1
  18. package/dist/api/app/bsky/notification/constants.js +3 -0
  19. package/dist/api/app/bsky/notification/constants.js.map +1 -1
  20. package/dist/api/app/bsky/notification/getGroupedNotifications.js +19 -7
  21. package/dist/api/app/bsky/notification/getGroupedNotifications.js.map +1 -1
  22. package/dist/api/app/bsky/notification/grouping/spotlight.d.ts +1 -1
  23. package/dist/api/app/bsky/notification/grouping/spotlight.d.ts.map +1 -1
  24. package/dist/api/app/bsky/notification/grouping/spotlight.js +114 -80
  25. package/dist/api/app/bsky/notification/grouping/spotlight.js.map +1 -1
  26. package/dist/api/app/bsky/notification/listActivitySubscriptions.js +3 -2
  27. package/dist/api/app/bsky/notification/listActivitySubscriptions.js.map +1 -1
  28. package/dist/api/app/bsky/unspecced/getAtmosphereExploreTab.d.ts +4 -0
  29. package/dist/api/app/bsky/unspecced/getAtmosphereExploreTab.d.ts.map +1 -0
  30. package/dist/api/app/bsky/unspecced/getAtmosphereExploreTab.js +142 -0
  31. package/dist/api/app/bsky/unspecced/getAtmosphereExploreTab.js.map +1 -0
  32. package/dist/api/index.d.ts.map +1 -1
  33. package/dist/api/index.js +2 -0
  34. package/dist/api/index.js.map +1 -1
  35. package/dist/api/internal/bsky/actor/getProfiles.js +4 -1
  36. package/dist/api/internal/bsky/actor/getProfiles.js.map +1 -1
  37. package/dist/config.d.ts +4 -0
  38. package/dist/config.d.ts.map +1 -1
  39. package/dist/config.js +12 -0
  40. package/dist/config.js.map +1 -1
  41. package/dist/data-plane/server/indexing/index.d.ts +3 -1
  42. package/dist/data-plane/server/indexing/index.d.ts.map +1 -1
  43. package/dist/data-plane/server/indexing/index.js +2 -0
  44. package/dist/data-plane/server/indexing/index.js.map +1 -1
  45. package/dist/data-plane/server/indexing/plugins/profile-link.d.ts +8 -0
  46. package/dist/data-plane/server/indexing/plugins/profile-link.d.ts.map +1 -0
  47. package/dist/data-plane/server/indexing/plugins/profile-link.js +30 -0
  48. package/dist/data-plane/server/indexing/plugins/profile-link.js.map +1 -0
  49. package/dist/data-plane/server/routes/records.d.ts.map +1 -1
  50. package/dist/data-plane/server/routes/records.js +1 -0
  51. package/dist/data-plane/server/routes/records.js.map +1 -1
  52. package/dist/hydration/actor.d.ts +4 -1
  53. package/dist/hydration/actor.d.ts.map +1 -1
  54. package/dist/hydration/actor.js +11 -0
  55. package/dist/hydration/actor.js.map +1 -1
  56. package/dist/hydration/external.d.ts +74 -70
  57. package/dist/hydration/external.d.ts.map +1 -1
  58. package/dist/hydration/external.js +79 -133
  59. package/dist/hydration/external.js.map +1 -1
  60. package/dist/hydration/hydrator.d.ts +57 -14
  61. package/dist/hydration/hydrator.d.ts.map +1 -1
  62. package/dist/hydration/hydrator.js +417 -105
  63. package/dist/hydration/hydrator.js.map +1 -1
  64. package/dist/lexicons/app/bsky/actor/defs.defs.d.ts +24 -0
  65. package/dist/lexicons/app/bsky/actor/defs.defs.d.ts.map +1 -1
  66. package/dist/lexicons/app/bsky/actor/defs.defs.js +13 -0
  67. package/dist/lexicons/app/bsky/actor/defs.defs.js.map +1 -1
  68. package/dist/lexicons/app/bsky/actor/link.d.ts +3 -0
  69. package/dist/lexicons/app/bsky/actor/link.d.ts.map +1 -0
  70. package/dist/lexicons/app/bsky/actor/link.defs.d.ts +105 -0
  71. package/dist/lexicons/app/bsky/actor/link.defs.d.ts.map +1 -0
  72. package/dist/lexicons/app/bsky/actor/link.defs.js +34 -0
  73. package/dist/lexicons/app/bsky/actor/link.defs.js.map +1 -0
  74. package/dist/lexicons/app/bsky/actor/link.js +6 -0
  75. package/dist/lexicons/app/bsky/actor/link.js.map +1 -0
  76. package/dist/lexicons/app/bsky/actor/profile.defs.d.ts +14 -0
  77. package/dist/lexicons/app/bsky/actor/profile.defs.d.ts.map +1 -1
  78. package/dist/lexicons/app/bsky/actor/profile.defs.js +3 -0
  79. package/dist/lexicons/app/bsky/actor/profile.defs.js.map +1 -1
  80. package/dist/lexicons/app/bsky/actor.d.ts +1 -0
  81. package/dist/lexicons/app/bsky/actor.d.ts.map +1 -1
  82. package/dist/lexicons/app/bsky/actor.js +1 -0
  83. package/dist/lexicons/app/bsky/actor.js.map +1 -1
  84. package/dist/lexicons/app/bsky/authFullApp.defs.d.ts.map +1 -1
  85. package/dist/lexicons/app/bsky/authFullApp.defs.js +1 -0
  86. package/dist/lexicons/app/bsky/authFullApp.defs.js.map +1 -1
  87. package/dist/lexicons/app/bsky/authManageProfile.defs.d.ts.map +1 -1
  88. package/dist/lexicons/app/bsky/authManageProfile.defs.js +1 -0
  89. package/dist/lexicons/app/bsky/authManageProfile.defs.js.map +1 -1
  90. package/dist/lexicons/app/bsky/embed/external.defs.d.ts +130 -0
  91. package/dist/lexicons/app/bsky/embed/external.defs.d.ts.map +1 -1
  92. package/dist/lexicons/app/bsky/embed/external.defs.js +135 -0
  93. package/dist/lexicons/app/bsky/embed/external.defs.js.map +1 -1
  94. package/dist/lexicons/app/bsky/embed/getEmbedExternalView.defs.d.ts +15 -3
  95. package/dist/lexicons/app/bsky/embed/getEmbedExternalView.defs.d.ts.map +1 -1
  96. package/dist/lexicons/app/bsky/embed/getEmbedExternalView.defs.js +18 -3
  97. package/dist/lexicons/app/bsky/embed/getEmbedExternalView.defs.js.map +1 -1
  98. package/dist/lexicons/app/bsky/notification/getGroupedNotifications.defs.d.ts +62 -3
  99. package/dist/lexicons/app/bsky/notification/getGroupedNotifications.defs.d.ts.map +1 -1
  100. package/dist/lexicons/app/bsky/notification/getGroupedNotifications.defs.js +53 -2
  101. package/dist/lexicons/app/bsky/notification/getGroupedNotifications.defs.js.map +1 -1
  102. package/dist/lexicons/app/bsky/unspecced/getAtmosphereExploreTab.d.ts +3 -0
  103. package/dist/lexicons/app/bsky/unspecced/getAtmosphereExploreTab.d.ts.map +1 -0
  104. package/dist/lexicons/app/bsky/unspecced/getAtmosphereExploreTab.defs.d.ts +103 -0
  105. package/dist/lexicons/app/bsky/unspecced/getAtmosphereExploreTab.defs.d.ts.map +1 -0
  106. package/dist/lexicons/app/bsky/unspecced/getAtmosphereExploreTab.defs.js +95 -0
  107. package/dist/lexicons/app/bsky/unspecced/getAtmosphereExploreTab.defs.js.map +1 -0
  108. package/dist/lexicons/app/bsky/unspecced/getAtmosphereExploreTab.js +6 -0
  109. package/dist/lexicons/app/bsky/unspecced/getAtmosphereExploreTab.js.map +1 -0
  110. package/dist/lexicons/app/bsky/unspecced.d.ts +1 -0
  111. package/dist/lexicons/app/bsky/unspecced.d.ts.map +1 -1
  112. package/dist/lexicons/app/bsky/unspecced.js +1 -0
  113. package/dist/lexicons/app/bsky/unspecced.js.map +1 -1
  114. package/dist/lexicons/index.d.ts +2 -0
  115. package/dist/lexicons/index.d.ts.map +1 -1
  116. package/dist/lexicons/index.js +2 -0
  117. package/dist/lexicons/index.js.map +1 -1
  118. package/dist/lexicons/place/stream/badge/defs.d.ts +2 -0
  119. package/dist/lexicons/place/stream/badge/defs.d.ts.map +1 -0
  120. package/dist/lexicons/place/stream/badge/defs.defs.d.ts +131 -0
  121. package/dist/lexicons/place/stream/badge/defs.defs.d.ts.map +1 -0
  122. package/dist/lexicons/place/stream/badge/defs.defs.js +73 -0
  123. package/dist/lexicons/place/stream/badge/defs.defs.js.map +1 -0
  124. package/dist/lexicons/place/stream/badge/defs.js +5 -0
  125. package/dist/lexicons/place/stream/badge/defs.js.map +1 -0
  126. package/dist/lexicons/place/stream/badge.d.ts +2 -0
  127. package/dist/lexicons/place/stream/badge.d.ts.map +1 -0
  128. package/dist/lexicons/place/stream/badge.js +5 -0
  129. package/dist/lexicons/place/stream/badge.js.map +1 -0
  130. package/dist/lexicons/place/stream/chat/defs.d.ts +2 -0
  131. package/dist/lexicons/place/stream/chat/defs.d.ts.map +1 -0
  132. package/dist/lexicons/place/stream/chat/defs.defs.d.ts +44 -0
  133. package/dist/lexicons/place/stream/chat/defs.defs.d.ts.map +1 -0
  134. package/dist/lexicons/place/stream/chat/defs.defs.js +41 -0
  135. package/dist/lexicons/place/stream/chat/defs.defs.js.map +1 -0
  136. package/dist/lexicons/place/stream/chat/defs.js +5 -0
  137. package/dist/lexicons/place/stream/chat/defs.js.map +1 -0
  138. package/dist/lexicons/place/stream/chat/pinnedRecord.d.ts +3 -0
  139. package/dist/lexicons/place/stream/chat/pinnedRecord.d.ts.map +1 -0
  140. package/dist/lexicons/place/stream/chat/pinnedRecord.defs.d.ts +108 -0
  141. package/dist/lexicons/place/stream/chat/pinnedRecord.defs.d.ts.map +1 -0
  142. package/dist/lexicons/place/stream/chat/pinnedRecord.defs.js +31 -0
  143. package/dist/lexicons/place/stream/chat/pinnedRecord.defs.js.map +1 -0
  144. package/dist/lexicons/place/stream/chat/pinnedRecord.js +6 -0
  145. package/dist/lexicons/place/stream/chat/pinnedRecord.js.map +1 -0
  146. package/dist/lexicons/place/stream/chat/profile.d.ts +3 -0
  147. package/dist/lexicons/place/stream/chat/profile.d.ts.map +1 -0
  148. package/dist/lexicons/place/stream/chat/profile.defs.d.ts +143 -0
  149. package/dist/lexicons/place/stream/chat/profile.defs.d.ts.map +1 -0
  150. package/dist/lexicons/place/stream/chat/profile.defs.js +62 -0
  151. package/dist/lexicons/place/stream/chat/profile.defs.js.map +1 -0
  152. package/dist/lexicons/place/stream/chat/profile.js +6 -0
  153. package/dist/lexicons/place/stream/chat/profile.js.map +1 -0
  154. package/dist/lexicons/place/stream/chat.d.ts +4 -0
  155. package/dist/lexicons/place/stream/chat.d.ts.map +1 -0
  156. package/dist/lexicons/place/stream/chat.js +7 -0
  157. package/dist/lexicons/place/stream/chat.js.map +1 -0
  158. package/dist/lexicons/place/stream/defs.d.ts +2 -0
  159. package/dist/lexicons/place/stream/defs.d.ts.map +1 -0
  160. package/dist/lexicons/place/stream/defs.defs.d.ts +54 -0
  161. package/dist/lexicons/place/stream/defs.defs.d.ts.map +1 -0
  162. package/dist/lexicons/place/stream/defs.defs.js +40 -0
  163. package/dist/lexicons/place/stream/defs.defs.js.map +1 -0
  164. package/dist/lexicons/place/stream/defs.js +5 -0
  165. package/dist/lexicons/place/stream/defs.js.map +1 -0
  166. package/dist/lexicons/place/stream/livestream.d.ts +3 -0
  167. package/dist/lexicons/place/stream/livestream.d.ts.map +1 -0
  168. package/dist/lexicons/place/stream/livestream.defs.d.ts +312 -0
  169. package/dist/lexicons/place/stream/livestream.defs.d.ts.map +1 -0
  170. package/dist/lexicons/place/stream/livestream.defs.js +105 -0
  171. package/dist/lexicons/place/stream/livestream.defs.js.map +1 -0
  172. package/dist/lexicons/place/stream/livestream.js +6 -0
  173. package/dist/lexicons/place/stream/livestream.js.map +1 -0
  174. package/dist/lexicons/place/stream.d.ts +5 -0
  175. package/dist/lexicons/place/stream.d.ts.map +1 -0
  176. package/dist/lexicons/place/stream.js +8 -0
  177. package/dist/lexicons/place/stream.js.map +1 -0
  178. package/dist/lexicons/place.d.ts +2 -0
  179. package/dist/lexicons/place.d.ts.map +1 -0
  180. package/dist/lexicons/place.js +5 -0
  181. package/dist/lexicons/place.js.map +1 -0
  182. package/dist/lexicons/site/standard/document.defs.d.ts +127 -127
  183. package/dist/lexicons/site/standard/document.defs.d.ts.map +1 -1
  184. package/dist/lexicons/site/standard/document.defs.js +28 -28
  185. package/dist/lexicons/site/standard/document.defs.js.map +1 -1
  186. package/dist/lexicons/site/standard/graph/recommend.defs.d.ts +11 -11
  187. package/dist/lexicons/site/standard/graph/recommend.defs.d.ts.map +1 -1
  188. package/dist/lexicons/site/standard/graph/recommend.defs.js +1 -1
  189. package/dist/lexicons/site/standard/graph/recommend.defs.js.map +1 -1
  190. package/dist/lexicons/site/standard/publication.defs.d.ts +52 -52
  191. package/dist/lexicons/site/standard/publication.defs.d.ts.map +1 -1
  192. package/dist/lexicons/site/standard/publication.defs.js +6 -6
  193. package/dist/lexicons/site/standard/publication.defs.js.map +1 -1
  194. package/dist/lexicons/site/standard/theme/basic.defs.d.ts +14 -14
  195. package/dist/lexicons/site/standard/theme/basic.defs.d.ts.map +1 -1
  196. package/dist/lexicons/site/standard/theme/basic.defs.js +1 -1
  197. package/dist/lexicons/site/standard/theme/basic.defs.js.map +1 -1
  198. package/dist/lexicons/social/grain/defs.d.ts +2 -0
  199. package/dist/lexicons/social/grain/defs.d.ts.map +1 -0
  200. package/dist/lexicons/social/grain/defs.defs.d.ts +15 -0
  201. package/dist/lexicons/social/grain/defs.defs.d.ts.map +1 -0
  202. package/dist/lexicons/social/grain/defs.defs.js +14 -0
  203. package/dist/lexicons/social/grain/defs.defs.js.map +1 -0
  204. package/dist/lexicons/social/grain/defs.js +5 -0
  205. package/dist/lexicons/social/grain/defs.js.map +1 -0
  206. package/dist/lexicons/social/grain/favorite.d.ts +3 -0
  207. package/dist/lexicons/social/grain/favorite.d.ts.map +1 -0
  208. package/dist/lexicons/social/grain/favorite.defs.d.ts +72 -0
  209. package/dist/lexicons/social/grain/favorite.defs.d.ts.map +1 -0
  210. package/dist/lexicons/social/grain/favorite.defs.js +26 -0
  211. package/dist/lexicons/social/grain/favorite.defs.js.map +1 -0
  212. package/dist/lexicons/social/grain/favorite.js +6 -0
  213. package/dist/lexicons/social/grain/favorite.js.map +1 -0
  214. package/dist/lexicons/social/grain/gallery/item.d.ts +3 -0
  215. package/dist/lexicons/social/grain/gallery/item.d.ts.map +1 -0
  216. package/dist/lexicons/social/grain/gallery/item.defs.d.ts +94 -0
  217. package/dist/lexicons/social/grain/gallery/item.defs.d.ts.map +1 -0
  218. package/dist/lexicons/social/grain/gallery/item.defs.js +29 -0
  219. package/dist/lexicons/social/grain/gallery/item.defs.js.map +1 -0
  220. package/dist/lexicons/social/grain/gallery/item.js +6 -0
  221. package/dist/lexicons/social/grain/gallery/item.js.map +1 -0
  222. package/dist/lexicons/social/grain/gallery.d.ts +4 -0
  223. package/dist/lexicons/social/grain/gallery.d.ts.map +1 -0
  224. package/dist/lexicons/social/grain/gallery.defs.d.ts +98 -0
  225. package/dist/lexicons/social/grain/gallery.defs.d.ts.map +1 -0
  226. package/dist/lexicons/social/grain/gallery.defs.js +33 -0
  227. package/dist/lexicons/social/grain/gallery.defs.js.map +1 -0
  228. package/dist/lexicons/social/grain/gallery.js +7 -0
  229. package/dist/lexicons/social/grain/gallery.js.map +1 -0
  230. package/dist/lexicons/social/grain/photo.d.ts +3 -0
  231. package/dist/lexicons/social/grain/photo.d.ts.map +1 -0
  232. package/dist/lexicons/social/grain/photo.defs.d.ts +98 -0
  233. package/dist/lexicons/social/grain/photo.defs.d.ts.map +1 -0
  234. package/dist/lexicons/social/grain/photo.defs.js +31 -0
  235. package/dist/lexicons/social/grain/photo.defs.js.map +1 -0
  236. package/dist/lexicons/social/grain/photo.js +6 -0
  237. package/dist/lexicons/social/grain/photo.js.map +1 -0
  238. package/dist/lexicons/social/grain.d.ts +5 -0
  239. package/dist/lexicons/social/grain.d.ts.map +1 -0
  240. package/dist/lexicons/social/grain.js +8 -0
  241. package/dist/lexicons/social/grain.js.map +1 -0
  242. package/dist/lexicons/social.d.ts +2 -0
  243. package/dist/lexicons/social.d.ts.map +1 -0
  244. package/dist/lexicons/social.js +5 -0
  245. package/dist/lexicons/social.js.map +1 -0
  246. package/dist/proto/bsky_connect.d.ts +10 -1
  247. package/dist/proto/bsky_connect.d.ts.map +1 -1
  248. package/dist/proto/bsky_connect.js +10 -1
  249. package/dist/proto/bsky_connect.js.map +1 -1
  250. package/dist/proto/bsky_pb.d.ts +34 -0
  251. package/dist/proto/bsky_pb.d.ts.map +1 -1
  252. package/dist/proto/bsky_pb.js +60 -0
  253. package/dist/proto/bsky_pb.js.map +1 -1
  254. package/dist/telemetry/events.d.ts +30 -0
  255. package/dist/telemetry/events.d.ts.map +1 -1
  256. package/dist/telemetry/events.js +37 -0
  257. package/dist/telemetry/events.js.map +1 -1
  258. package/dist/util/external/index.d.ts +8 -0
  259. package/dist/util/external/index.d.ts.map +1 -0
  260. package/dist/util/external/index.js +50 -0
  261. package/dist/util/external/index.js.map +1 -0
  262. package/dist/util/{standard-site.d.ts → external/standard-site.d.ts} +30 -4
  263. package/dist/util/external/standard-site.d.ts.map +1 -0
  264. package/dist/util/{standard-site.js → external/standard-site.js} +73 -4
  265. package/dist/util/external/standard-site.js.map +1 -0
  266. package/dist/views/external.d.ts +8 -0
  267. package/dist/views/external.d.ts.map +1 -0
  268. package/dist/views/external.js +260 -0
  269. package/dist/views/external.js.map +1 -0
  270. package/dist/views/index.d.ts +12 -6
  271. package/dist/views/index.d.ts.map +1 -1
  272. package/dist/views/index.js +89 -42
  273. package/dist/views/index.js.map +1 -1
  274. package/dist/views/profile-link-rules.d.ts +10 -0
  275. package/dist/views/profile-link-rules.d.ts.map +1 -0
  276. package/dist/views/profile-link-rules.js +48 -0
  277. package/dist/views/profile-link-rules.js.map +1 -0
  278. package/dist/views/types.d.ts +3 -0
  279. package/dist/views/types.d.ts.map +1 -1
  280. package/dist/views/types.js.map +1 -1
  281. package/package.json +4 -4
  282. package/dist/util/standard-site.d.ts.map +0 -1
  283. package/dist/util/standard-site.js.map +0 -1
@@ -74,7 +74,7 @@ const hydration = async (input) => {
74
74
  const { ctx, params, skeleton } = input;
75
75
  const { suggestedDids } = skeleton;
76
76
  if (params.hydrateCtx.features.checkGate(params.hydrateCtx.features.Gate.SuggestedUsersSocialProofEnable)) {
77
- return ctx.hydrator.hydrateProfilesDetailed(suggestedDids, params.hydrateCtx);
77
+ return ctx.hydrator.hydrateProfilesDetailed(suggestedDids, params.hydrateCtx, { knownFollowersDids: suggestedDids, activitySubscriptions: true });
78
78
  }
79
79
  else {
80
80
  return ctx.hydrator.hydrateProfiles(suggestedDids, params.hydrateCtx);
@@ -89,7 +89,7 @@ const noBlocksOrMutes = (input) => {
89
89
  const presentation = (input) => {
90
90
  const { ctx, hydration, skeleton } = input;
91
91
  const { suggestedDids, contentLanguage } = skeleton;
92
- const suggestions = mapDefined(suggestedDids, (did) => ctx.views.profileKnownFollowers(did, hydration));
92
+ const suggestions = mapDefined(suggestedDids, (did) => ctx.views.profile(did, hydration));
93
93
  return {
94
94
  recIdStr: skeleton.recIdStr,
95
95
  contentLanguage,
@@ -1 +1 @@
1
- {"version":3,"file":"getSuggestedFollowsByActor.js","sourceRoot":"","sources":["../../../../../src/api/app/bsky/graph/getSuggestedFollowsByActor.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAA;AAE7D,OAAO,EAEL,mBAAmB,EACnB,mBAAmB,GAEpB,MAAM,sBAAsB,CAAA;AAG7B,OAAO,EAAE,GAAG,EAAE,MAAM,+BAA+B,CAAA;AACnD,OAAO,EAKL,cAAc,GACf,MAAM,yBAAyB,CAAA;AAChC,OAAO,EAAE,4BAA4B,EAAE,MAAM,6BAA6B,CAAA;AAE1E,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAk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AM,eAAe,GAAG,CACtB,KAAmD,EACnD,EAAE;IACF,MAAM,EAAE,GAAG,EAAE,QAAQ,EAAE,SAAS,EAAE,GAAG,KAAK,CAAA;IAC1C,QAAQ,CAAC,aAAa,GAAG,QAAQ,CAAC,aAAa,CAAC,MAAM,CACpD,CAAC,GAAG,EAAE,EAAE,CACN,CAAC,GAAG,CAAC,KAAK,CAAC,iBAAiB,CAAC,GAAG,EAAE,SAAS,CAAC;QAC5C,CAAC,GAAG,CAAC,KAAK,CAAC,gBAAgB,CAAC,GAAG,EAAE,SAAS,CAAC,CAC9C,CAAA;IACD,OAAO,QAAQ,CAAA;AACjB,CAAC,CAAA;AAED,MAAM,YAAY,GAAG,CACnB,KAA0D,EAC1D,EAAE;IACF,MAAM,EAAE,GAAG,EAAE,SAAS,EAAE,QAAQ,EAAE,GAAG,KAAK,CAAA;IAC1C,MAAM,EAAE,aAAa,EAAE,eAAe,EAAE,GAAG,QAAQ,CAAA;IACnD,MAAM,WAAW,GAAG,UAAU,CAAC,aAAa,EAAE,CAAC,GAAG,EAAE,EAAE,CACpD,GAAG,CAAC,KAAK,CAAC,qBAAqB,CAAC,GAAG,EAAE,SAAS,CAAC,CAChD,CAAA;IACD,OAAO;QACL,QAAQ,EAAE,QAAQ,CAAC,QAAQ;QAC3B,eAAe;QACf,WAAW;KACZ,CAAA;AACH,CAAC,CAAA","sourcesContent":["import { mapDefined, noUndefinedVals } from '@atproto/common'\nimport type { Client, DidString } from '@atproto/lex'\nimport {\n type Headers as HeadersMap,\n InternalServerError,\n InvalidRequestError,\n type Server,\n} from '@atproto/xrpc-server'\nimport type { AppContext } from '../../../../context.js'\nimport type { HydrateCtx, Hydrator } from '../../../../hydration/hydrator.js'\nimport { app } from '../../../../lexicons/index.js'\nimport {\n type HydrationFnInput,\n type PresentationFnInput,\n type RulesFnInput,\n type SkeletonFnInput,\n createPipeline,\n} from '../../../../pipeline.js'\nimport { getAtprotoPassthroughHeaders } from '../../../../util/headers.js'\nimport type { Views } from '../../../../views/index.js'\nimport { resHeaders } from '../../../util.js'\n\nexport default function (server: Server, ctx: AppContext) {\n const getSuggestedFollowsByActor = createPipeline(\n skeleton,\n hydration,\n noBlocksOrMutes,\n presentation,\n )\n server.add(app.bsky.graph.getSuggestedFollowsByActor, {\n auth: ctx.authVerifier.standardOptional,\n handler: async ({ auth, params, req, signal }) => {\n const viewer = auth.credentials.iss\n const labelers = ctx.reqLabelers(req)\n const hydrateCtx = await ctx.hydrator.createContext({\n labelers,\n viewer,\n features: ctx.featureGatesClient.scope(\n ctx.featureGatesClient.parseUserContextFromHandler({\n viewer,\n req,\n }),\n ),\n })\n\n const useIris = hydrateCtx.features.checkGate(\n hydrateCtx.features.Gate.SuggestedUsersIrisEnable,\n )\n const client = useIris ? ctx.irisClient : ctx.suggestionsClient\n\n if (!client) {\n return {\n encoding: 'application/json',\n body: { suggestions: [] },\n headers: resHeaders({ labelers: hydrateCtx.labelers }),\n }\n }\n\n const headers = noUndefinedVals({\n 'accept-language': req.headers['accept-language'],\n ...getAtprotoPassthroughHeaders(req),\n })\n\n const { contentLanguage, ...body } = await getSuggestedFollowsByActor(\n { ...params, hydrateCtx, headers, signal },\n ctx,\n )\n\n return {\n encoding: 'application/json',\n body,\n headers: {\n ...(contentLanguage ? { 'content-language': contentLanguage } : null),\n ...resHeaders({ labelers: hydrateCtx.labelers }),\n },\n }\n },\n })\n}\n\nconst skeleton = async (\n input: SkeletonFnInput<Context, Params>,\n): Promise<SkeletonState> => {\n const { params, ctx } = input\n\n const useIris = params.hydrateCtx.features.checkGate(\n params.hydrateCtx.features.Gate.SuggestedUsersIrisEnable,\n )\n const client = useIris ? ctx.irisClient : ctx.suggestionsClient\n\n // handled above already, this branch should not be reached\n if (!client) {\n throw new InternalServerError('Suggestions service not configured')\n }\n\n const [relativeToDid] = await ctx.hydrator.actor.getDids([params.actor])\n if (!relativeToDid) {\n throw new InvalidRequestError('Actor not found')\n }\n\n const res = await client.xrpc(app.bsky.unspecced.getSuggestionsSkeleton, {\n params: {\n viewer: params.hydrateCtx.viewer ?? undefined,\n relativeToDid,\n },\n headers: params.headers,\n signal: params.signal,\n })\n\n return {\n recIdStr: res.body.recIdStr,\n suggestedDids: res.body.actors.map((a) => a.did),\n contentLanguage: res.headers.get('content-language') ?? undefined,\n }\n}\n\nconst hydration = async (\n input: HydrationFnInput<Context, Params, SkeletonState>,\n) => {\n const { ctx, params, skeleton } = input\n const { suggestedDids } = skeleton\n if (\n params.hydrateCtx.features.checkGate(\n params.hydrateCtx.features.Gate.SuggestedUsersSocialProofEnable,\n )\n ) {\n return ctx.hydrator.hydrateProfilesDetailed(\n suggestedDids,\n params.hydrateCtx,\n )\n } else {\n return ctx.hydrator.hydrateProfiles(suggestedDids, params.hydrateCtx)\n }\n}\n\nconst noBlocksOrMutes = (\n input: RulesFnInput<Context, Params, SkeletonState>,\n) => {\n const { ctx, skeleton, hydration } = input\n skeleton.suggestedDids = skeleton.suggestedDids.filter(\n (did) =>\n !ctx.views.viewerBlockExists(did, hydration) &&\n !ctx.views.viewerMuteExists(did, hydration),\n )\n return skeleton\n}\n\nconst presentation = (\n input: PresentationFnInput<Context, Params, SkeletonState>,\n) => {\n const { ctx, hydration, skeleton } = input\n const { suggestedDids, contentLanguage } = skeleton\n const suggestions = mapDefined(suggestedDids, (did) =>\n ctx.views.profileKnownFollowers(did, hydration),\n )\n return {\n recIdStr: skeleton.recIdStr,\n contentLanguage,\n suggestions,\n }\n}\n\ntype Context = {\n hydrator: Hydrator\n views: Views\n suggestionsClient: Client | undefined\n irisClient: Client | undefined\n}\n\ntype Params = app.bsky.graph.getSuggestedFollowsByActor.$Params & {\n hydrateCtx: HydrateCtx\n headers: HeadersMap\n signal: AbortSignal\n}\n\ntype SkeletonState = {\n suggestedDids: DidString[]\n recIdStr?: string\n contentLanguage?: string\n}\n"]}
1
+ {"version":3,"file":"getSuggestedFollowsByActor.js","sourceRoot":"","sources":["../../../../../src/api/app/bsky/graph/getSuggestedFollowsByActor.ts"],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,CAAA;AACH,CAAC,CAAA","sourcesContent":["import { mapDefined, noUndefinedVals } from '@atproto/common'\nimport type { Client, DidString } from '@atproto/lex'\nimport {\n type Headers as HeadersMap,\n InternalServerError,\n InvalidRequestError,\n type Server,\n} from '@atproto/xrpc-server'\nimport type { AppContext } from '../../../../context.js'\nimport type { HydrateCtx, Hydrator } from '../../../../hydration/hydrator.js'\nimport { app } from '../../../../lexicons/index.js'\nimport {\n type HydrationFnInput,\n type PresentationFnInput,\n type RulesFnInput,\n type SkeletonFnInput,\n createPipeline,\n} from '../../../../pipeline.js'\nimport { getAtprotoPassthroughHeaders } from '../../../../util/headers.js'\nimport type { Views } from '../../../../views/index.js'\nimport { resHeaders } from '../../../util.js'\n\nexport default function (server: Server, ctx: AppContext) {\n const getSuggestedFollowsByActor = createPipeline(\n skeleton,\n hydration,\n noBlocksOrMutes,\n presentation,\n )\n server.add(app.bsky.graph.getSuggestedFollowsByActor, {\n auth: ctx.authVerifier.standardOptional,\n handler: async ({ auth, params, req, signal }) => {\n const viewer = auth.credentials.iss\n const labelers = ctx.reqLabelers(req)\n const hydrateCtx = await ctx.hydrator.createContext({\n labelers,\n viewer,\n features: ctx.featureGatesClient.scope(\n ctx.featureGatesClient.parseUserContextFromHandler({\n viewer,\n req,\n }),\n ),\n })\n\n const useIris = hydrateCtx.features.checkGate(\n hydrateCtx.features.Gate.SuggestedUsersIrisEnable,\n )\n const client = useIris ? ctx.irisClient : ctx.suggestionsClient\n\n if (!client) {\n return {\n encoding: 'application/json',\n body: { suggestions: [] },\n headers: resHeaders({ labelers: hydrateCtx.labelers }),\n }\n }\n\n const headers = noUndefinedVals({\n 'accept-language': req.headers['accept-language'],\n ...getAtprotoPassthroughHeaders(req),\n })\n\n const { contentLanguage, ...body } = await getSuggestedFollowsByActor(\n { ...params, hydrateCtx, headers, signal },\n ctx,\n )\n\n return {\n encoding: 'application/json',\n body,\n headers: {\n ...(contentLanguage ? { 'content-language': contentLanguage } : null),\n ...resHeaders({ labelers: hydrateCtx.labelers }),\n },\n }\n },\n })\n}\n\nconst skeleton = async (\n input: SkeletonFnInput<Context, Params>,\n): Promise<SkeletonState> => {\n const { params, ctx } = input\n\n const useIris = params.hydrateCtx.features.checkGate(\n params.hydrateCtx.features.Gate.SuggestedUsersIrisEnable,\n )\n const client = useIris ? ctx.irisClient : ctx.suggestionsClient\n\n // handled above already, this branch should not be reached\n if (!client) {\n throw new InternalServerError('Suggestions service not configured')\n }\n\n const [relativeToDid] = await ctx.hydrator.actor.getDids([params.actor])\n if (!relativeToDid) {\n throw new InvalidRequestError('Actor not found')\n }\n\n const res = await client.xrpc(app.bsky.unspecced.getSuggestionsSkeleton, {\n params: {\n viewer: params.hydrateCtx.viewer ?? undefined,\n relativeToDid,\n },\n headers: params.headers,\n signal: params.signal,\n })\n\n return {\n recIdStr: res.body.recIdStr,\n suggestedDids: res.body.actors.map((a) => a.did),\n contentLanguage: res.headers.get('content-language') ?? undefined,\n }\n}\n\nconst hydration = async (\n input: HydrationFnInput<Context, Params, SkeletonState>,\n) => {\n const { ctx, params, skeleton } = input\n const { suggestedDids } = skeleton\n if (\n params.hydrateCtx.features.checkGate(\n params.hydrateCtx.features.Gate.SuggestedUsersSocialProofEnable,\n )\n ) {\n return ctx.hydrator.hydrateProfilesDetailed(\n suggestedDids,\n params.hydrateCtx,\n { knownFollowersDids: suggestedDids, activitySubscriptions: true },\n )\n } else {\n return ctx.hydrator.hydrateProfiles(suggestedDids, params.hydrateCtx)\n }\n}\n\nconst noBlocksOrMutes = (\n input: RulesFnInput<Context, Params, SkeletonState>,\n) => {\n const { ctx, skeleton, hydration } = input\n skeleton.suggestedDids = skeleton.suggestedDids.filter(\n (did) =>\n !ctx.views.viewerBlockExists(did, hydration) &&\n !ctx.views.viewerMuteExists(did, hydration),\n )\n return skeleton\n}\n\nconst presentation = (\n input: PresentationFnInput<Context, Params, SkeletonState>,\n) => {\n const { ctx, hydration, skeleton } = input\n const { suggestedDids, contentLanguage } = skeleton\n const suggestions = mapDefined(suggestedDids, (did) =>\n ctx.views.profile(did, hydration),\n )\n return {\n recIdStr: skeleton.recIdStr,\n contentLanguage,\n suggestions,\n }\n}\n\ntype Context = {\n hydrator: Hydrator\n views: Views\n suggestionsClient: Client | undefined\n irisClient: Client | undefined\n}\n\ntype Params = app.bsky.graph.getSuggestedFollowsByActor.$Params & {\n hydrateCtx: HydrateCtx\n headers: HeadersMap\n signal: AbortSignal\n}\n\ntype SkeletonState = {\n suggestedDids: DidString[]\n recIdStr?: string\n contentLanguage?: string\n}\n"]}
@@ -31,7 +31,10 @@ export declare const APPVIEW_NOTIFICATION_REASON: {
31
31
  readonly UNVERIFIED: 'unverified';
32
32
  readonly VERIFIED: 'verified';
33
33
  readonly MULTI_POST_LIKE: 'multi-post-like';
34
+ readonly MULTI_POST_REPOST: 'multi-post-repost';
35
+ readonly MULTI_POST_LIKE_VIA_REPOST: 'multi-post-like-via-repost';
36
+ readonly MULTI_POST_REPOST_VIA_REPOST: 'multi-post-repost-via-repost';
34
37
  };
35
- export type AppviewNotificationReason = DataplaneNotificationReason | typeof APPVIEW_NOTIFICATION_REASON.MULTI_POST_LIKE;
38
+ export type AppviewNotificationReason = (typeof APPVIEW_NOTIFICATION_REASON)[keyof typeof APPVIEW_NOTIFICATION_REASON];
36
39
  export declare const MARK_READ_GENERIC = "mark-read-generic";
37
40
  //# sourceMappingURL=constants.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../../../../src/api/app/bsky/notification/constants.ts"],"names":[],"mappings":"AACA,eAAO,MAAM,mBAAmB;aAC9B,aAAa,EAAE,eAAe;aAC9B,MAAM,EAAE,QAAQ;aAChB,WAAW,EAAE,aAAa;aAC1B,IAAI,EAAE,MAAM;aACZ,eAAe,EAAE,iBAAiB;aAClC,OAAO,EAAE,SAAS;aAClB,KAAK,EAAE,OAAO;aACd,KAAK,EAAE,OAAO;aACd,MAAM,EAAE,QAAQ;aAChB,iBAAiB,EAAE,mBAAmB;aACtC,kBAAkB,EAAE,oBAAoB;aACxC,eAAe,EAAE,iBAAiB;aAClC,UAAU,EAAE,YAAY;aACxB,QAAQ,EAAE,UAAU;CACZ,CAAA;AAEV,MAAM,MAAM,2BAA2B,GACrC,CAAC,OAAO,mBAAmB,CAAC,CAAC,MAAM,OAAO,mBAAmB,CAAC,CAAA;AAEhE,eAAO,MAAM,2BAA2B;4BAnBvB,eAAe;qBACtB,QAAQ;0BACH,aAAa;mBACpB,MAAM;8BACK,iBAAiB;sBACzB,SAAS;oBACX,OAAO;oBACP,OAAO;qBACN,QAAQ;gCACG,mBAAmB;iCAClB,oBAAoB;8BACvB,iBAAiB;yBACtB,YAAY;uBACd,UAAU;8BAQH,iBAAiB;CAC1B,CAAA;AAEV,MAAM,MAAM,yBAAyB,GACjC,2BAA2B,GAC3B,OAAO,2BAA2B,CAAC,eAAe,CAAA;AAGtD,eAAO,MAAM,iBAAiB,sBAAsB,CAAA"}
1
+ {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../../../../src/api/app/bsky/notification/constants.ts"],"names":[],"mappings":"AACA,eAAO,MAAM,mBAAmB;aAC9B,aAAa,EAAE,eAAe;aAC9B,MAAM,EAAE,QAAQ;aAChB,WAAW,EAAE,aAAa;aAC1B,IAAI,EAAE,MAAM;aACZ,eAAe,EAAE,iBAAiB;aAClC,OAAO,EAAE,SAAS;aAClB,KAAK,EAAE,OAAO;aACd,KAAK,EAAE,OAAO;aACd,MAAM,EAAE,QAAQ;aAChB,iBAAiB,EAAE,mBAAmB;aACtC,kBAAkB,EAAE,oBAAoB;aACxC,eAAe,EAAE,iBAAiB;aAClC,UAAU,EAAE,YAAY;aACxB,QAAQ,EAAE,UAAU;CACZ,CAAA;AAEV,MAAM,MAAM,2BAA2B,GACrC,CAAC,OAAO,mBAAmB,CAAC,CAAC,MAAM,OAAO,mBAAmB,CAAC,CAAA;AAEhE,eAAO,MAAM,2BAA2B;4BAnBvB,eAAe;qBACtB,QAAQ;0BACH,aAAa;mBACpB,MAAM;8BACK,iBAAiB;sBACzB,SAAS;oBACX,OAAO;oBACP,OAAO;qBACN,QAAQ;gCACG,mBAAmB;iCAClB,oBAAoB;8BACvB,iBAAiB;yBACtB,YAAY;uBACd,UAAU;8BAQH,iBAAiB;gCACf,mBAAmB;yCACV,4BAA4B;2CAC1B,8BAA8B;CACpD,CAAA;AAEV,MAAM,MAAM,yBAAyB,GACnC,CAAC,OAAO,2BAA2B,CAAC,CAAC,MAAM,OAAO,2BAA2B,CAAC,CAAA;AAGhF,eAAO,MAAM,iBAAiB,sBAAsB,CAAA"}
@@ -18,6 +18,9 @@ export const NOTIFICATION_REASON = {
18
18
  export const APPVIEW_NOTIFICATION_REASON = {
19
19
  ...NOTIFICATION_REASON,
20
20
  MULTI_POST_LIKE: 'multi-post-like',
21
+ MULTI_POST_REPOST: 'multi-post-repost',
22
+ MULTI_POST_LIKE_VIA_REPOST: 'multi-post-like-via-repost',
23
+ MULTI_POST_REPOST_VIA_REPOST: 'multi-post-repost-via-repost',
21
24
  };
22
25
  // Not a real notification the users see, but used to mark as read across user devices.
23
26
  export const MARK_READ_GENERIC = 'mark-read-generic';
@@ -1 +1 @@
1
- {"version":3,"file":"constants.js","sourceRoot":"","sources":["../../../../../src/api/app/bsky/notification/constants.ts"],"names":[],"mappings":"AAAA,mCAAmC;AACnC,MAAM,CAAC,MAAM,mBAAmB,GAAG;IACjC,aAAa,EAAE,eAAe;IAC9B,MAAM,EAAE,QAAQ;IAChB,WAAW,EAAE,aAAa;IAC1B,IAAI,EAAE,MAAM;IACZ,eAAe,EAAE,iBAAiB;IAClC,OAAO,EAAE,SAAS;IAClB,KAAK,EAAE,OAAO;IACd,KAAK,EAAE,OAAO;IACd,MAAM,EAAE,QAAQ;IAChB,iBAAiB,EAAE,mBAAmB;IACtC,kBAAkB,EAAE,oBAAoB;IACxC,eAAe,EAAE,iBAAiB;IAClC,UAAU,EAAE,YAAY;IACxB,QAAQ,EAAE,UAAU;CACZ,CAAA;AAKV,MAAM,CAAC,MAAM,2BAA2B,GAAG;IACzC,GAAG,mBAAmB;IACtB,eAAe,EAAE,iBAAiB;CAC1B,CAAA;AAMV,uFAAuF;AACvF,MAAM,CAAC,MAAM,iBAAiB,GAAG,mBAAmB,CAAA","sourcesContent":["// As they come from the dataplane.\nexport const NOTIFICATION_REASON = {\n CONTACT_MATCH: 'contact-match',\n FOLLOW: 'follow',\n FOLLOW_BACK: 'follow-back',\n LIKE: 'like',\n LIKE_VIA_REPOST: 'like-via-repost',\n MENTION: 'mention',\n QUOTE: 'quote',\n REPLY: 'reply',\n REPOST: 'repost',\n REPOST_VIA_REPOST: 'repost-via-repost',\n STARTERPACK_JOINED: 'starterpack-joined',\n SUBSCRIBED_POST: 'subscribed-post',\n UNVERIFIED: 'unverified',\n VERIFIED: 'verified',\n} as const\n\nexport type DataplaneNotificationReason =\n (typeof NOTIFICATION_REASON)[keyof typeof NOTIFICATION_REASON]\n\nexport const APPVIEW_NOTIFICATION_REASON = {\n ...NOTIFICATION_REASON,\n MULTI_POST_LIKE: 'multi-post-like',\n} as const\n\nexport type AppviewNotificationReason =\n | DataplaneNotificationReason\n | typeof APPVIEW_NOTIFICATION_REASON.MULTI_POST_LIKE\n\n// Not a real notification the users see, but used to mark as read across user devices.\nexport const MARK_READ_GENERIC = 'mark-read-generic'\n"]}
1
+ {"version":3,"file":"constants.js","sourceRoot":"","sources":["../../../../../src/api/app/bsky/notification/constants.ts"],"names":[],"mappings":"AAAA,mCAAmC;AACnC,MAAM,CAAC,MAAM,mBAAmB,GAAG;IACjC,aAAa,EAAE,eAAe;IAC9B,MAAM,EAAE,QAAQ;IAChB,WAAW,EAAE,aAAa;IAC1B,IAAI,EAAE,MAAM;IACZ,eAAe,EAAE,iBAAiB;IAClC,OAAO,EAAE,SAAS;IAClB,KAAK,EAAE,OAAO;IACd,KAAK,EAAE,OAAO;IACd,MAAM,EAAE,QAAQ;IAChB,iBAAiB,EAAE,mBAAmB;IACtC,kBAAkB,EAAE,oBAAoB;IACxC,eAAe,EAAE,iBAAiB;IAClC,UAAU,EAAE,YAAY;IACxB,QAAQ,EAAE,UAAU;CACZ,CAAA;AAKV,MAAM,CAAC,MAAM,2BAA2B,GAAG;IACzC,GAAG,mBAAmB;IACtB,eAAe,EAAE,iBAAiB;IAClC,iBAAiB,EAAE,mBAAmB;IACtC,0BAA0B,EAAE,4BAA4B;IACxD,4BAA4B,EAAE,8BAA8B;CACpD,CAAA;AAKV,uFAAuF;AACvF,MAAM,CAAC,MAAM,iBAAiB,GAAG,mBAAmB,CAAA","sourcesContent":["// As they come from the dataplane.\nexport const NOTIFICATION_REASON = {\n CONTACT_MATCH: 'contact-match',\n FOLLOW: 'follow',\n FOLLOW_BACK: 'follow-back',\n LIKE: 'like',\n LIKE_VIA_REPOST: 'like-via-repost',\n MENTION: 'mention',\n QUOTE: 'quote',\n REPLY: 'reply',\n REPOST: 'repost',\n REPOST_VIA_REPOST: 'repost-via-repost',\n STARTERPACK_JOINED: 'starterpack-joined',\n SUBSCRIBED_POST: 'subscribed-post',\n UNVERIFIED: 'unverified',\n VERIFIED: 'verified',\n} as const\n\nexport type DataplaneNotificationReason =\n (typeof NOTIFICATION_REASON)[keyof typeof NOTIFICATION_REASON]\n\nexport const APPVIEW_NOTIFICATION_REASON = {\n ...NOTIFICATION_REASON,\n MULTI_POST_LIKE: 'multi-post-like',\n MULTI_POST_REPOST: 'multi-post-repost',\n MULTI_POST_LIKE_VIA_REPOST: 'multi-post-like-via-repost',\n MULTI_POST_REPOST_VIA_REPOST: 'multi-post-repost-via-repost',\n} as const\n\nexport type AppviewNotificationReason =\n (typeof APPVIEW_NOTIFICATION_REASON)[keyof typeof APPVIEW_NOTIFICATION_REASON]\n\n// Not a real notification the users see, but used to mark as read across user devices.\nexport const MARK_READ_GENERIC = 'mark-read-generic'\n"]}
@@ -1,5 +1,5 @@
1
1
  import { createHash } from 'node:crypto';
2
- import { mapDefined } from '@atproto/common';
2
+ import { dedupeStrs, mapDefined } from '@atproto/common';
3
3
  import { asDatetimeString, } from '@atproto/lex';
4
4
  import { AtUri } from '@atproto/syntax';
5
5
  import { app } from '../../../../lexicons/index.js';
@@ -133,7 +133,15 @@ const skeleton = async (input) => {
133
133
  const hydration = async (input) => {
134
134
  const { ctx, params, skeleton } = input;
135
135
  const notifs = skeleton.groups.flatMap((group) => group.items.map((item) => item.raw));
136
- return ctx.hydrator.hydrateGroupedNotifications(notifs, params.hydrateCtx);
136
+ // Optimization: instead of fetching known followers for all users in all notifications,
137
+ // only fetch for the notifications type that want it (follow type), and only for the ones
138
+ // that appear before truncation.
139
+ const knownFollowersDids = dedupeStrs(skeleton.groups.flatMap((group) => group.kind === NOTIFICATION_REASON.FOLLOW
140
+ ? truncateRelatedViewsItems(group.items).map((item) => item.actorDid)
141
+ : []));
142
+ return ctx.hydrator.hydrateGroupedNotifications(notifs, params.hydrateCtx, {
143
+ knownFollowersDids,
144
+ });
137
145
  };
138
146
  const rules = (input) => {
139
147
  const { ctx, params, skeleton, hydration } = input;
@@ -240,6 +248,7 @@ const presentation = (input) => {
240
248
  const { ctx, params, skeleton, hydration } = input;
241
249
  const defs = app.bsky.notification.getGroupedNotifications;
242
250
  const groups = mapDefined(skeleton.groups, (group) => ctx.views.notificationGroup(group, hydration));
251
+ // Build related profiles, records.
243
252
  const profileDids = new Set();
244
253
  const recordUris = new Set();
245
254
  for (const { kind } of groups) {
@@ -252,7 +261,10 @@ const presentation = (input) => {
252
261
  profileDids.add(item.actor);
253
262
  }
254
263
  }
255
- else if (defs.multiPostLikeGroup.$isTypeOf(kind)) {
264
+ else if (defs.multiPostLikeGroup.$isTypeOf(kind) ||
265
+ defs.multiPostRepostGroup.$isTypeOf(kind) ||
266
+ defs.multiPostLikeViaRepostGroup.$isTypeOf(kind) ||
267
+ defs.multiPostRepostViaRepostGroup.$isTypeOf(kind)) {
256
268
  profileDids.add(kind.actor);
257
269
  for (const item of truncateRelatedViewsItems(kind.items)) {
258
270
  recordUris.add(item.post);
@@ -300,10 +312,10 @@ const presentation = (input) => {
300
312
  groups,
301
313
  relatedViews: [
302
314
  ...mapDefined([...profileDids], (did) => {
303
- const view = ctx.views.profileDetailed(did, hydration);
315
+ const view = ctx.views.profileBasic(did, hydration);
304
316
  if (!view)
305
317
  return;
306
- return app.bsky.actor.defs.profileViewDetailed.$build(view);
318
+ return app.bsky.actor.defs.profileViewBasic.$build(view);
307
319
  }),
308
320
  ...mapDefined([...recordUris], (uri) => {
309
321
  const collection = new AtUri(uri).collection;
@@ -314,10 +326,10 @@ const presentation = (input) => {
314
326
  return view;
315
327
  }
316
328
  else if (collection === app.bsky.graph.starterpack.$type) {
317
- const view = ctx.views.starterPack(uri, hydration);
329
+ const view = ctx.views.starterPackBasic(uri, hydration);
318
330
  if (!view)
319
331
  return;
320
- return app.bsky.graph.defs.starterPackView.$build(view);
332
+ return app.bsky.graph.defs.starterPackViewBasic.$build(view);
321
333
  }
322
334
  else if (collection === app.bsky.feed.generator.$type) {
323
335
  const view = ctx.views.feedGenerator(uri, hydration);
@@ -1 +1 @@
1
- {"version":3,"file":"getGroupedNotifications.js","sourceRoot":"","sources":["../../../../../src/api/app/bsky/notification/getGroupedNotifications.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AACxC,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAA;AAC5C,OAAO,EAIL,gBAAgB,GACjB,MAAM,cAAc,CAAA;AACrB,OAAO,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAA;AASvC,OAAO,EAAE,GAAG,EAAE,MAAM,+BAA+B,CAAA;AACnD,OAAO,EAKL,cAAc,GACf,MAAM,yBAAyB,CAAA;AAChC,OAAO,EAAE,gBAAgB,EAAE,MAAM,8BAA8B,CAAA;AAC/D,OAAO,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAA;AAEnD,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAA;AAC7C,OAAO,EAAE,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GAAG,CAAC,IAAY,EAAoB,EAAE;IACvD,QAAQ,IAAI,EAAE,CAAC;QACb,KAAK,iBAAiB;YACpB,OAAO,gBAAgB,CAAC,eAAe,CAAA;QACzC,KAAK,eAAe;YAClB,OAAO,gBAAgB,CAAC,aAAa,CAAA;QACvC,KAAK,WAAW;YACd,OAAO,gBAAgB,CAAC,SAAS,CAAA;QACnC,KAAK,UAAU;YACb,OAAO,gBAAgB,CAAC,QAAQ,CAAA;QAClC;YACE,OAAO,gBAAgB,CAAC,GAAG,CAAA;IAC/B,CAAC;AACH,CAAC,CAAA","sourcesContent":["import { createHash } from 'node:crypto'\nimport { mapDefined } from '@atproto/common'\nimport {\n type AtUriString,\n type DatetimeString,\n type DidString,\n asDatetimeString,\n} from '@atproto/lex'\nimport { AtUri } from '@atproto/syntax'\nimport type { Server } from '@atproto/xrpc-server'\nimport type { ServerConfig } from '../../../../config.js'\nimport type { AppContext } from '../../../../context.js'\nimport type {\n HydrateCtxWithViewer,\n HydrationState,\n Hydrator,\n} from '../../../../hydration/hydrator.js'\nimport { app } from '../../../../lexicons/index.js'\nimport {\n type HydrationFnInput,\n type PresentationFnInput,\n type RulesFnInput,\n type SkeletonFnInput,\n createPipeline,\n} from '../../../../pipeline.js'\nimport { NotificationFeed } from '../../../../proto/bsky_pb.js'\nimport { uriToDid } from '../../../../util/uris.js'\nimport type { Views } from '../../../../views/index.js'\nimport { resHeaders } from '../../../util.js'\nimport { NOTIFICATION_REASON } from './constants.js'\nimport {\n type NotificationGroup,\n type NotificationItem,\n type RawNotification,\n buildGroups,\n parseRawNotification,\n} from './grouping/grouping.js'\nimport {\n compareNotificationGroupsNewestFirst,\n isNotificationRead,\n} from './grouping/shared.js'\nimport { buildSpotlight } from './grouping/spotlight.js'\nimport {\n delayCursor,\n shouldFilterForNeedsReview,\n shouldFilterHiddenThreadTag,\n shouldFilterReplyByThreadgate,\n} from './util.js'\n\nconst MIN_RAW_LIMIT = 300\nconst MAX_RAW_ITEMS = 3000\nconst MAX_READS = 3\nconst MAX_GROUP_ITEMS_WITH_RELATED_VIEWS = 10\n\nexport const getNextRawLimit = (\n itemsFetched: number,\n groupsBuilt: number,\n groupsNeeded: number,\n): number => {\n // How many raw items we still can fetch until hit the max.\n const remainingItems = MAX_RAW_ITEMS - itemsFetched\n if (remainingItems <= 0) return 0\n\n // Defensive fallback to avoid a division by 0 later.\n // This is for the scenario where fetched items but couldn't build any groups with them\n // (let's say all notifications are missing data and are filtered out, shouldn't happen in practice).\n if (groupsBuilt === 0) return Math.min(MIN_RAW_LIMIT, remainingItems)\n\n // How many groups still to be built - note that we might still fit items into existing groups.\n const groupsMissing = Math.max(0, groupsNeeded - groupsBuilt)\n\n const averagePerGroup = itemsFetched / groupsBuilt\n\n // Estimate additional raw notifications from the average group size.\n const estimatedRawItems = Math.ceil(averagePerGroup * groupsMissing)\n\n // Keep the estimate above the minimum batch and within the total raw-item budget.\n return Math.min(remainingItems, Math.max(MIN_RAW_LIMIT, estimatedRawItems))\n}\n\nexport default function (server: Server, ctx: AppContext) {\n const getGroupedNotifications = createPipeline(\n skeleton,\n hydration,\n rules,\n presentation,\n )\n server.add(app.bsky.notification.getGroupedNotifications, {\n auth: ctx.authVerifier.standard,\n handler: async ({ params, auth, req }) => {\n const viewer = auth.credentials.iss\n const features = ctx.featureGatesClient.scope(\n ctx.featureGatesClient.parseUserContextFromHandler({ viewer, req }),\n )\n const labelers = ctx.reqLabelers(req)\n const hydrateCtx = await ctx.hydrator.createContext({\n labelers,\n viewer,\n features,\n })\n const lastSeenRes = await ctx.hydrator.dataplane.getNotificationSeen({\n actorDid: viewer,\n })\n const seenAt = lastSeenRes.timestamp\n ? asDatetimeString(lastSeenRes.timestamp.toJson() as string)\n : undefined\n const body = await getGroupedNotifications(\n { ...params, hydrateCtx, seenAt },\n ctx,\n )\n return {\n encoding: 'application/json',\n headers: resHeaders({ labelers: hydrateCtx.labelers }),\n body,\n }\n },\n })\n}\n\nconst skeleton = async (\n input: SkeletonFnInput<Context, Params>,\n): Promise<SkeletonState> => {\n const { ctx, params } = input\n const now = Date.now()\n const feed = normalizeFeed(params.feed)\n const seenAt = params.seenAt ? Date.parse(params.seenAt) : undefined\n const delayedCursor = delayCursor(undefined, ctx.cfg.notificationsDelayMs)\n let cursor = params.cursor\n if (!cursor || Date.parse(cursor) > Date.parse(delayedCursor)) {\n cursor = delayedCursor\n }\n\n const items: NotificationItem[] = []\n let groups: NotificationGroup[] = []\n let nextCursor: string | undefined\n let itemsFetched = 0\n let rawLimit = MIN_RAW_LIMIT\n\n for (let read = 0; read < MAX_READS; read++) {\n const response = await ctx.hydrator.dataplane.getNotificationsV2({\n actorDid: params.hydrateCtx.viewer,\n feed,\n cursor,\n limit: rawLimit,\n })\n itemsFetched += response.notifications.length\n\n for (const notification of response.notifications) {\n const notif = parseRawNotification(notification)\n if (!notif) continue\n const uri = notif.uri\n const actorDid = uriToDid(uri)\n const indexedAt = notif.indexedAt\n // Hashing keeps IDs within the lexicon's length limit for long record URIs.\n const id = createHash('sha256')\n .update(`${indexedAt}\\0${uri}`)\n .digest('base64url')\n\n let groupingKey: string = notif.reasonSubject || uri\n if (notif.reason === NOTIFICATION_REASON.FOLLOW) {\n groupingKey = NOTIFICATION_REASON.FOLLOW\n }\n if (notif.reason === NOTIFICATION_REASON.SUBSCRIBED_POST) {\n groupingKey = actorDid\n }\n\n items.push({\n raw: notif,\n id,\n groupingKey,\n actorDid,\n })\n }\n\n const groupingResult = buildGroups(\n items,\n params.limit,\n now,\n seenAt,\n ctx.cfg.notificationsV2Algorithm,\n feed,\n )\n groups = groupingResult.groups\n\n // After fetching a page from the dataplane and attempting to group, 2 situations can happen:\n // 1. The first unconsumed notification would create an additional group beyond params.limit.\n // result.cursor points before that notification; use it so the next request processes it.\n // 2. Every fetched notification was consumed into the groups.\n // result.cursor is undefined, so use response.cursor to fetch the next dataplane page.\n nextCursor = groupingResult.cursor ?? (response.cursor || undefined)\n\n const groupingFoundUnconsumedNotification =\n groupingResult.cursor !== undefined\n const dataplaneHasMoreNotifications = !!response.cursor\n const shouldContinueBuildingPage =\n !groupingFoundUnconsumedNotification && dataplaneHasMoreNotifications\n if (!shouldContinueBuildingPage) break\n\n cursor = response.cursor\n rawLimit = getNextRawLimit(itemsFetched, groups.length, params.limit)\n if (rawLimit === 0) break\n }\n\n return buildSpotlight(items, groups, nextCursor, params.limit, seenAt)\n}\n\nconst hydration = async (\n input: HydrationFnInput<Context, Params, SkeletonState>,\n) => {\n const { ctx, params, skeleton } = input\n const notifs = skeleton.groups.flatMap((group) =>\n group.items.map((item) => item.raw),\n )\n return ctx.hydrator.hydrateGroupedNotifications(notifs, params.hydrateCtx)\n}\n\nconst rules = (\n input: RulesFnInput<Context, Params, SkeletonState>,\n): SkeletonState => {\n const { ctx, params, skeleton, hydration } = input\n const seenAt = params.seenAt ? Date.parse(params.seenAt) : undefined\n const groups = mapDefined(\n skeleton.groups,\n (group): NotificationGroup | undefined => {\n const items = group.items.filter((item) => {\n const notif = item.raw\n const uri = notif.uri\n const did = item.actorDid\n if (\n ctx.views.viewerBlockExists(did, hydration) ||\n ctx.views.viewerMuteExists(did, hydration)\n ) {\n return false\n }\n if (\n shouldFilterReplyByThreadgate(\n notif.reason,\n uri,\n params.hydrateCtx.viewer,\n hydration,\n ctx.views,\n )\n ) {\n return false\n }\n if (\n shouldFilterHiddenThreadTag(\n notif.reason,\n uri,\n did,\n hydration,\n ctx.cfg.threadTagsHide,\n )\n ) {\n return false\n }\n if (\n shouldFilterForNeedsReview(\n notif.reason,\n did,\n uri,\n hydration,\n ctx.views,\n )\n ) {\n return false\n }\n\n // After hydration, notificationAvailable checks whether each notification’s required records exist.\n // If its actor, post, repost, follow, or starter pack is missing or blocked, rules removes that notification from the returned group.\n return notificationAvailable(notif, hydration, ctx.views)\n })\n\n const newest = items[0]\n const oldest = items.at(-1)\n\n // If it has no more elements, drop this group.\n if (!newest || !oldest) return\n\n // Filtering may remove notifications from this group; build a new group with only the remaining items and their updated metadata.\n return {\n ...group,\n id: newest.id,\n items,\n actorDids: items.map((item) => item.actorDid),\n itemCount: items.length,\n indexedAt: newest.raw.indexedAt,\n firstIndexedAt: oldest.raw.indexedAt,\n isRead: isNotificationRead(newest.raw.indexedAt, seenAt),\n }\n },\n )\n\n groups.sort(compareNotificationGroupsNewestFirst)\n\n return { ...skeleton, groups }\n}\n\n// Checks that the notification’s actor and required records exist and referenced posts aren’t viewer-blocked.\nconst notificationAvailable = (\n notif: RawNotification,\n state: HydrationState,\n views: Views,\n): boolean => {\n const uri = notif.uri\n const actor = state.actors?.get(uriToDid(uri))\n if (!actor) return false\n\n const postAvailable = (postUri: AtUriString) =>\n !!state.posts?.get(postUri) &&\n !!state.actors?.get(uriToDid(postUri)) &&\n !views.viewerBlockExists(uriToDid(postUri), state)\n\n const starterPackAvailable = (starterPackUri: AtUriString) =>\n !!state.starterPacks?.get(starterPackUri) &&\n !!state.actors?.get(uriToDid(starterPackUri))\n\n switch (notif.reason) {\n case NOTIFICATION_REASON.LIKE: {\n const subjectUri = notif.reasonSubject\n if (!state.likes?.get(uri)) return false\n if (new AtUri(subjectUri).collection === app.bsky.feed.generator.$type) {\n return (\n !!state.feedgens?.get(subjectUri) &&\n !!state.actors?.get(uriToDid(subjectUri))\n )\n }\n return postAvailable(subjectUri)\n }\n case NOTIFICATION_REASON.REPOST:\n return !!state.reposts?.get(uri) && postAvailable(notif.reasonSubject)\n case NOTIFICATION_REASON.LIKE_VIA_REPOST:\n case NOTIFICATION_REASON.REPOST_VIA_REPOST: {\n const recordInfo =\n notif.reason === NOTIFICATION_REASON.LIKE_VIA_REPOST\n ? state.likes?.get(uri)\n : state.reposts?.get(uri)\n const postUri = state.reposts?.get(notif.reasonSubject)?.record.subject\n .uri\n return !!recordInfo && !!postUri && postAvailable(postUri)\n }\n case NOTIFICATION_REASON.FOLLOW:\n case NOTIFICATION_REASON.FOLLOW_BACK:\n return !!state.follows?.get(uri)\n case NOTIFICATION_REASON.REPLY:\n return (\n postAvailable(uri) && !!state.posts?.get(uri)?.record.reply?.parent.uri\n )\n case NOTIFICATION_REASON.QUOTE:\n case NOTIFICATION_REASON.MENTION:\n case NOTIFICATION_REASON.SUBSCRIBED_POST:\n return postAvailable(uri)\n case NOTIFICATION_REASON.VERIFIED:\n case NOTIFICATION_REASON.UNVERIFIED:\n // Both notifications survive deletion of the verification record.\n return true\n case NOTIFICATION_REASON.STARTERPACK_JOINED:\n return (\n !!actor.profile &&\n !!actor.profileCid &&\n starterPackAvailable(notif.reasonSubject)\n )\n case NOTIFICATION_REASON.CONTACT_MATCH:\n return !!actor.profile && !!actor.profileCid\n default:\n return false\n }\n}\n\nconst presentation = (\n input: PresentationFnInput<Context, Params, SkeletonState>,\n): app.bsky.notification.getGroupedNotifications.$OutputBody => {\n const { ctx, params, skeleton, hydration } = input\n const defs = app.bsky.notification.getGroupedNotifications\n const groups = mapDefined(skeleton.groups, (group) =>\n ctx.views.notificationGroup(group, hydration),\n )\n const profileDids = new Set<DidString>()\n const recordUris = new Set<AtUriString>()\n for (const { kind } of groups) {\n if (\n defs.likeGroup.$isTypeOf(kind) ||\n defs.repostGroup.$isTypeOf(kind) ||\n defs.likeViaRepostGroup.$isTypeOf(kind) ||\n defs.repostViaRepostGroup.$isTypeOf(kind)\n ) {\n recordUris.add(kind.post)\n for (const item of truncateRelatedViewsItems(kind.items)) {\n profileDids.add(item.actor)\n }\n } else if (defs.multiPostLikeGroup.$isTypeOf(kind)) {\n profileDids.add(kind.actor)\n for (const item of truncateRelatedViewsItems(kind.items)) {\n recordUris.add(item.post)\n }\n } else if (defs.generatorLikeGroup.$isTypeOf(kind)) {\n recordUris.add(kind.generator)\n for (const item of truncateRelatedViewsItems(kind.items)) {\n profileDids.add(item.actor)\n }\n } else if (defs.followGroup.$isTypeOf(kind)) {\n for (const item of truncateRelatedViewsItems(kind.items)) {\n profileDids.add(item.actor)\n if (item.starterPack) recordUris.add(item.starterPack)\n }\n } else if (defs.subscribedPostGroup.$isTypeOf(kind)) {\n for (const item of truncateRelatedViewsItems(kind.items)) {\n profileDids.add(item.actor)\n recordUris.add(item.post)\n }\n } else if (\n defs.replyNotification.$isTypeOf(kind) ||\n defs.quoteNotification.$isTypeOf(kind) ||\n defs.mentionNotification.$isTypeOf(kind)\n ) {\n recordUris.add(kind.post)\n if (kind.parent) recordUris.add(kind.parent)\n } else if (\n defs.followBackNotification.$isTypeOf(kind) ||\n defs.starterPackJoinedNotification.$isTypeOf(kind)\n ) {\n profileDids.add(kind.actor)\n if (kind.starterPack) recordUris.add(kind.starterPack)\n } else if (\n defs.verifiedNotification.$isTypeOf(kind) ||\n defs.unverifiedNotification.$isTypeOf(kind) ||\n defs.contactMatchNotification.$isTypeOf(kind)\n ) {\n profileDids.add(kind.actor)\n }\n }\n return {\n groups,\n relatedViews: [\n ...mapDefined([...profileDids], (did) => {\n const view = ctx.views.profileDetailed(did, hydration)\n if (!view) return\n return app.bsky.actor.defs.profileViewDetailed.$build(view)\n }),\n ...mapDefined([...recordUris], (uri) => {\n const collection = new AtUri(uri).collection\n if (collection === app.bsky.feed.post.$type) {\n const view = ctx.views.maybePost(uri, hydration)\n if (!view) return\n return view\n } else if (collection === app.bsky.graph.starterpack.$type) {\n const view = ctx.views.starterPack(uri, hydration)\n if (!view) return\n return app.bsky.graph.defs.starterPackView.$build(view)\n } else if (collection === app.bsky.feed.generator.$type) {\n const view = ctx.views.feedGenerator(uri, hydration)\n if (!view) return\n return app.bsky.feed.defs.generatorView.$build(view)\n }\n }),\n ],\n cursor: skeleton.cursor,\n seenAt: params.seenAt,\n }\n}\n\nconst truncateRelatedViewsItems = <T extends unknown[]>(\n items: T,\n): T[number][] => items.slice(0, MAX_GROUP_ITEMS_WITH_RELATED_VIEWS)\n\nconst normalizeFeed = (feed: string): NotificationFeed => {\n switch (feed) {\n case 'people-i-follow':\n return NotificationFeed.PEOPLE_I_FOLLOW\n case 'conversations':\n return NotificationFeed.CONVERSATIONS\n case 'followers':\n return NotificationFeed.FOLLOWERS\n case 'activity':\n return NotificationFeed.ACTIVITY\n default:\n return NotificationFeed.ALL\n }\n}\n\ntype Context = {\n hydrator: Hydrator\n views: Views\n cfg: ServerConfig\n}\n\ntype Params = app.bsky.notification.getGroupedNotifications.$Params & {\n hydrateCtx: HydrateCtxWithViewer\n seenAt?: DatetimeString\n}\n\ntype SkeletonState = {\n groups: NotificationGroup[]\n cursor?: string\n}\n"]}
1
+ {"version":3,"file":"getGroupedNotifications.js","sourceRoot":"","sources":["../../../../../src/api/app/bsky/notification/getGroupedNotifications.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AACxC,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAA;AACxD,OAAO,EAIL,gBAAgB,GACjB,MAAM,cAAc,CAAA;AACrB,OAAO,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAA;AASvC,OAAO,EAAE,GAAG,EAAE,MAAM,+BAA+B,CAAA;AACnD,OAAO,EAKL,cAAc,GACf,MAAM,yBAAyB,CAAA;AAChC,OAAO,EAAE,gBAAgB,EAAE,MAAM,8BAA8B,CAAA;AAC/D,OAAO,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAA;AAEnD,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAA;AAC7C,OAAO,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAA;AACpD,OAAO,EAIL,WAAW,EACX,oBAAoB,GACrB,MAAM,wBAAwB,CAAA;AAC/B,OAAO,EACL,oCAAoC,EACpC,kBAAkB,GACnB,MAAM,sBAAsB,CAAA;AAC7B,OAAO,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAA;AACxD,OAAO,EACL,WAAW,EACX,0BAA0B,EAC1B,2BAA2B,EAC3B,6BAA6B,GAC9B,MAAM,WAAW,CAAA;AAElB,MAAM,aAAa,GAAG,GAAG,CAAA;AACzB,MAAM,aAAa,GAAG,IAAI,CAAA;AAC1B,MAAM,SAAS,GA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CAAC,MAAM;KACtB,CAAA;AACH,CAAC,CAAA;AAED,MAAM,yBAAyB,GAAG,CAChC,KAAQ,EACK,EAAE,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,EAAE,kCAAkC,CAAC,CAAA;AAEpE,MAAM,aAAa,GAAG,CAAC,IAAY,EAAoB,EAAE;IACvD,QAAQ,IAAI,EAAE,CAAC;QACb,KAAK,iBAAiB;YACpB,OAAO,gBAAgB,CAAC,eAAe,CAAA;QACzC,KAAK,eAAe;YAClB,OAAO,gBAAgB,CAAC,aAAa,CAAA;QACvC,KAAK,WAAW;YACd,OAAO,gBAAgB,CAAC,SAAS,CAAA;QACnC,KAAK,UAAU;YACb,OAAO,gBAAgB,CAAC,QAAQ,CAAA;QAClC;YACE,OAAO,gBAAgB,CAAC,GAAG,CAAA;IAC/B,CAAC;AACH,CAAC,CAAA","sourcesContent":["import { createHash } from 'node:crypto'\nimport { dedupeStrs, mapDefined } from '@atproto/common'\nimport {\n type AtUriString,\n type DatetimeString,\n type DidString,\n asDatetimeString,\n} from '@atproto/lex'\nimport { AtUri } from '@atproto/syntax'\nimport type { Server } from '@atproto/xrpc-server'\nimport type { ServerConfig } from '../../../../config.js'\nimport type { AppContext } from '../../../../context.js'\nimport type {\n HydrateCtxWithViewer,\n HydrationState,\n Hydrator,\n} from '../../../../hydration/hydrator.js'\nimport { app } from '../../../../lexicons/index.js'\nimport {\n type HydrationFnInput,\n type PresentationFnInput,\n type RulesFnInput,\n type SkeletonFnInput,\n createPipeline,\n} from '../../../../pipeline.js'\nimport { NotificationFeed } from '../../../../proto/bsky_pb.js'\nimport { uriToDid } from '../../../../util/uris.js'\nimport type { Views } from '../../../../views/index.js'\nimport { resHeaders } from '../../../util.js'\nimport { NOTIFICATION_REASON } from './constants.js'\nimport {\n type NotificationGroup,\n type NotificationItem,\n type RawNotification,\n buildGroups,\n parseRawNotification,\n} from './grouping/grouping.js'\nimport {\n compareNotificationGroupsNewestFirst,\n isNotificationRead,\n} from './grouping/shared.js'\nimport { buildSpotlight } from './grouping/spotlight.js'\nimport {\n delayCursor,\n shouldFilterForNeedsReview,\n shouldFilterHiddenThreadTag,\n shouldFilterReplyByThreadgate,\n} from './util.js'\n\nconst MIN_RAW_LIMIT = 300\nconst MAX_RAW_ITEMS = 3000\nconst MAX_READS = 3\nconst MAX_GROUP_ITEMS_WITH_RELATED_VIEWS = 10\n\nexport const getNextRawLimit = (\n itemsFetched: number,\n groupsBuilt: number,\n groupsNeeded: number,\n): number => {\n // How many raw items we still can fetch until hit the max.\n const remainingItems = MAX_RAW_ITEMS - itemsFetched\n if (remainingItems <= 0) return 0\n\n // Defensive fallback to avoid a division by 0 later.\n // This is for the scenario where fetched items but couldn't build any groups with them\n // (let's say all notifications are missing data and are filtered out, shouldn't happen in practice).\n if (groupsBuilt === 0) return Math.min(MIN_RAW_LIMIT, remainingItems)\n\n // How many groups still to be built - note that we might still fit items into existing groups.\n const groupsMissing = Math.max(0, groupsNeeded - groupsBuilt)\n\n const averagePerGroup = itemsFetched / groupsBuilt\n\n // Estimate additional raw notifications from the average group size.\n const estimatedRawItems = Math.ceil(averagePerGroup * groupsMissing)\n\n // Keep the estimate above the minimum batch and within the total raw-item budget.\n return Math.min(remainingItems, Math.max(MIN_RAW_LIMIT, estimatedRawItems))\n}\n\nexport default function (server: Server, ctx: AppContext) {\n const getGroupedNotifications = createPipeline(\n skeleton,\n hydration,\n rules,\n presentation,\n )\n server.add(app.bsky.notification.getGroupedNotifications, {\n auth: ctx.authVerifier.standard,\n handler: async ({ params, auth, req }) => {\n const viewer = auth.credentials.iss\n const features = ctx.featureGatesClient.scope(\n ctx.featureGatesClient.parseUserContextFromHandler({ viewer, req }),\n )\n const labelers = ctx.reqLabelers(req)\n const hydrateCtx = await ctx.hydrator.createContext({\n labelers,\n viewer,\n features,\n })\n const lastSeenRes = await ctx.hydrator.dataplane.getNotificationSeen({\n actorDid: viewer,\n })\n const seenAt = lastSeenRes.timestamp\n ? asDatetimeString(lastSeenRes.timestamp.toJson() as string)\n : undefined\n const body = await getGroupedNotifications(\n { ...params, hydrateCtx, seenAt },\n ctx,\n )\n return {\n encoding: 'application/json',\n headers: resHeaders({ labelers: hydrateCtx.labelers }),\n body,\n }\n },\n })\n}\n\nconst skeleton = async (\n input: SkeletonFnInput<Context, Params>,\n): Promise<SkeletonState> => {\n const { ctx, params } = input\n const now = Date.now()\n const feed = normalizeFeed(params.feed)\n const seenAt = params.seenAt ? Date.parse(params.seenAt) : undefined\n const delayedCursor = delayCursor(undefined, ctx.cfg.notificationsDelayMs)\n let cursor = params.cursor\n if (!cursor || Date.parse(cursor) > Date.parse(delayedCursor)) {\n cursor = delayedCursor\n }\n\n const items: NotificationItem[] = []\n let groups: NotificationGroup[] = []\n let nextCursor: string | undefined\n let itemsFetched = 0\n let rawLimit = MIN_RAW_LIMIT\n\n for (let read = 0; read < MAX_READS; read++) {\n const response = await ctx.hydrator.dataplane.getNotificationsV2({\n actorDid: params.hydrateCtx.viewer,\n feed,\n cursor,\n limit: rawLimit,\n })\n itemsFetched += response.notifications.length\n\n for (const notification of response.notifications) {\n const notif = parseRawNotification(notification)\n if (!notif) continue\n const uri = notif.uri\n const actorDid = uriToDid(uri)\n const indexedAt = notif.indexedAt\n // Hashing keeps IDs within the lexicon's length limit for long record URIs.\n const id = createHash('sha256')\n .update(`${indexedAt}\\0${uri}`)\n .digest('base64url')\n\n let groupingKey: string = notif.reasonSubject || uri\n if (notif.reason === NOTIFICATION_REASON.FOLLOW) {\n groupingKey = NOTIFICATION_REASON.FOLLOW\n }\n if (notif.reason === NOTIFICATION_REASON.SUBSCRIBED_POST) {\n groupingKey = actorDid\n }\n\n items.push({\n raw: notif,\n id,\n groupingKey,\n actorDid,\n })\n }\n\n const groupingResult = buildGroups(\n items,\n params.limit,\n now,\n seenAt,\n ctx.cfg.notificationsV2Algorithm,\n feed,\n )\n groups = groupingResult.groups\n\n // After fetching a page from the dataplane and attempting to group, 2 situations can happen:\n // 1. The first unconsumed notification would create an additional group beyond params.limit.\n // result.cursor points before that notification; use it so the next request processes it.\n // 2. Every fetched notification was consumed into the groups.\n // result.cursor is undefined, so use response.cursor to fetch the next dataplane page.\n nextCursor = groupingResult.cursor ?? (response.cursor || undefined)\n\n const groupingFoundUnconsumedNotification =\n groupingResult.cursor !== undefined\n const dataplaneHasMoreNotifications = !!response.cursor\n const shouldContinueBuildingPage =\n !groupingFoundUnconsumedNotification && dataplaneHasMoreNotifications\n if (!shouldContinueBuildingPage) break\n\n cursor = response.cursor\n rawLimit = getNextRawLimit(itemsFetched, groups.length, params.limit)\n if (rawLimit === 0) break\n }\n\n return buildSpotlight(items, groups, nextCursor, params.limit, seenAt)\n}\n\nconst hydration = async (\n input: HydrationFnInput<Context, Params, SkeletonState>,\n) => {\n const { ctx, params, skeleton } = input\n const notifs = skeleton.groups.flatMap((group) =>\n group.items.map((item) => item.raw),\n )\n\n // Optimization: instead of fetching known followers for all users in all notifications,\n // only fetch for the notifications type that want it (follow type), and only for the ones\n // that appear before truncation.\n const knownFollowersDids = dedupeStrs(\n skeleton.groups.flatMap((group) =>\n group.kind === NOTIFICATION_REASON.FOLLOW\n ? truncateRelatedViewsItems(group.items).map((item) => item.actorDid)\n : [],\n ),\n )\n\n return ctx.hydrator.hydrateGroupedNotifications(notifs, params.hydrateCtx, {\n knownFollowersDids,\n })\n}\n\nconst rules = (\n input: RulesFnInput<Context, Params, SkeletonState>,\n): SkeletonState => {\n const { ctx, params, skeleton, hydration } = input\n const seenAt = params.seenAt ? Date.parse(params.seenAt) : undefined\n const groups = mapDefined(\n skeleton.groups,\n (group): NotificationGroup | undefined => {\n const items = group.items.filter((item) => {\n const notif = item.raw\n const uri = notif.uri\n const did = item.actorDid\n if (\n ctx.views.viewerBlockExists(did, hydration) ||\n ctx.views.viewerMuteExists(did, hydration)\n ) {\n return false\n }\n if (\n shouldFilterReplyByThreadgate(\n notif.reason,\n uri,\n params.hydrateCtx.viewer,\n hydration,\n ctx.views,\n )\n ) {\n return false\n }\n if (\n shouldFilterHiddenThreadTag(\n notif.reason,\n uri,\n did,\n hydration,\n ctx.cfg.threadTagsHide,\n )\n ) {\n return false\n }\n if (\n shouldFilterForNeedsReview(\n notif.reason,\n did,\n uri,\n hydration,\n ctx.views,\n )\n ) {\n return false\n }\n\n // After hydration, notificationAvailable checks whether each notification’s required records exist.\n // If its actor, post, repost, follow, or starter pack is missing or blocked, rules removes that notification from the returned group.\n return notificationAvailable(notif, hydration, ctx.views)\n })\n\n const newest = items[0]\n const oldest = items.at(-1)\n\n // If it has no more elements, drop this group.\n if (!newest || !oldest) return\n\n // Filtering may remove notifications from this group; build a new group with only the remaining items and their updated metadata.\n return {\n ...group,\n id: newest.id,\n items,\n actorDids: items.map((item) => item.actorDid),\n itemCount: items.length,\n indexedAt: newest.raw.indexedAt,\n firstIndexedAt: oldest.raw.indexedAt,\n isRead: isNotificationRead(newest.raw.indexedAt, seenAt),\n }\n },\n )\n\n groups.sort(compareNotificationGroupsNewestFirst)\n\n return { ...skeleton, groups }\n}\n\n// Checks that the notification’s actor and required records exist and referenced posts aren’t viewer-blocked.\nconst notificationAvailable = (\n notif: RawNotification,\n state: HydrationState,\n views: Views,\n): boolean => {\n const uri = notif.uri\n const actor = state.actors?.get(uriToDid(uri))\n if (!actor) return false\n\n const postAvailable = (postUri: AtUriString) =>\n !!state.posts?.get(postUri) &&\n !!state.actors?.get(uriToDid(postUri)) &&\n !views.viewerBlockExists(uriToDid(postUri), state)\n\n const starterPackAvailable = (starterPackUri: AtUriString) =>\n !!state.starterPacks?.get(starterPackUri) &&\n !!state.actors?.get(uriToDid(starterPackUri))\n\n switch (notif.reason) {\n case NOTIFICATION_REASON.LIKE: {\n const subjectUri = notif.reasonSubject\n if (!state.likes?.get(uri)) return false\n if (new AtUri(subjectUri).collection === app.bsky.feed.generator.$type) {\n return (\n !!state.feedgens?.get(subjectUri) &&\n !!state.actors?.get(uriToDid(subjectUri))\n )\n }\n return postAvailable(subjectUri)\n }\n case NOTIFICATION_REASON.REPOST:\n return !!state.reposts?.get(uri) && postAvailable(notif.reasonSubject)\n case NOTIFICATION_REASON.LIKE_VIA_REPOST:\n case NOTIFICATION_REASON.REPOST_VIA_REPOST: {\n const recordInfo =\n notif.reason === NOTIFICATION_REASON.LIKE_VIA_REPOST\n ? state.likes?.get(uri)\n : state.reposts?.get(uri)\n const postUri = state.reposts?.get(notif.reasonSubject)?.record.subject\n .uri\n return !!recordInfo && !!postUri && postAvailable(postUri)\n }\n case NOTIFICATION_REASON.FOLLOW:\n case NOTIFICATION_REASON.FOLLOW_BACK:\n return !!state.follows?.get(uri)\n case NOTIFICATION_REASON.REPLY:\n return (\n postAvailable(uri) && !!state.posts?.get(uri)?.record.reply?.parent.uri\n )\n case NOTIFICATION_REASON.QUOTE:\n case NOTIFICATION_REASON.MENTION:\n case NOTIFICATION_REASON.SUBSCRIBED_POST:\n return postAvailable(uri)\n case NOTIFICATION_REASON.VERIFIED:\n case NOTIFICATION_REASON.UNVERIFIED:\n // Both notifications survive deletion of the verification record.\n return true\n case NOTIFICATION_REASON.STARTERPACK_JOINED:\n return (\n !!actor.profile &&\n !!actor.profileCid &&\n starterPackAvailable(notif.reasonSubject)\n )\n case NOTIFICATION_REASON.CONTACT_MATCH:\n return !!actor.profile && !!actor.profileCid\n default:\n return false\n }\n}\n\nconst presentation = (\n input: PresentationFnInput<Context, Params, SkeletonState>,\n): app.bsky.notification.getGroupedNotifications.$OutputBody => {\n const { ctx, params, skeleton, hydration } = input\n const defs = app.bsky.notification.getGroupedNotifications\n const groups = mapDefined(skeleton.groups, (group) =>\n ctx.views.notificationGroup(group, hydration),\n )\n\n // Build related profiles, records.\n const profileDids = new Set<DidString>()\n const recordUris = new Set<AtUriString>()\n for (const { kind } of groups) {\n if (\n defs.likeGroup.$isTypeOf(kind) ||\n defs.repostGroup.$isTypeOf(kind) ||\n defs.likeViaRepostGroup.$isTypeOf(kind) ||\n defs.repostViaRepostGroup.$isTypeOf(kind)\n ) {\n recordUris.add(kind.post)\n for (const item of truncateRelatedViewsItems(kind.items)) {\n profileDids.add(item.actor)\n }\n } else if (\n defs.multiPostLikeGroup.$isTypeOf(kind) ||\n defs.multiPostRepostGroup.$isTypeOf(kind) ||\n defs.multiPostLikeViaRepostGroup.$isTypeOf(kind) ||\n defs.multiPostRepostViaRepostGroup.$isTypeOf(kind)\n ) {\n profileDids.add(kind.actor)\n for (const item of truncateRelatedViewsItems(kind.items)) {\n recordUris.add(item.post)\n }\n } else if (defs.generatorLikeGroup.$isTypeOf(kind)) {\n recordUris.add(kind.generator)\n for (const item of truncateRelatedViewsItems(kind.items)) {\n profileDids.add(item.actor)\n }\n } else if (defs.followGroup.$isTypeOf(kind)) {\n for (const item of truncateRelatedViewsItems(kind.items)) {\n profileDids.add(item.actor)\n if (item.starterPack) recordUris.add(item.starterPack)\n }\n } else if (defs.subscribedPostGroup.$isTypeOf(kind)) {\n for (const item of truncateRelatedViewsItems(kind.items)) {\n profileDids.add(item.actor)\n recordUris.add(item.post)\n }\n } else if (\n defs.replyNotification.$isTypeOf(kind) ||\n defs.quoteNotification.$isTypeOf(kind) ||\n defs.mentionNotification.$isTypeOf(kind)\n ) {\n recordUris.add(kind.post)\n if (kind.parent) recordUris.add(kind.parent)\n } else if (\n defs.followBackNotification.$isTypeOf(kind) ||\n defs.starterPackJoinedNotification.$isTypeOf(kind)\n ) {\n profileDids.add(kind.actor)\n if (kind.starterPack) recordUris.add(kind.starterPack)\n } else if (\n defs.verifiedNotification.$isTypeOf(kind) ||\n defs.unverifiedNotification.$isTypeOf(kind) ||\n defs.contactMatchNotification.$isTypeOf(kind)\n ) {\n profileDids.add(kind.actor)\n }\n }\n\n return {\n groups,\n relatedViews: [\n ...mapDefined([...profileDids], (did) => {\n const view = ctx.views.profileBasic(did, hydration)\n if (!view) return\n return app.bsky.actor.defs.profileViewBasic.$build(view)\n }),\n ...mapDefined([...recordUris], (uri) => {\n const collection = new AtUri(uri).collection\n if (collection === app.bsky.feed.post.$type) {\n const view = ctx.views.maybePost(uri, hydration)\n if (!view) return\n return view\n } else if (collection === app.bsky.graph.starterpack.$type) {\n const view = ctx.views.starterPackBasic(uri, hydration)\n if (!view) return\n return app.bsky.graph.defs.starterPackViewBasic.$build(view)\n } else if (collection === app.bsky.feed.generator.$type) {\n const view = ctx.views.feedGenerator(uri, hydration)\n if (!view) return\n return app.bsky.feed.defs.generatorView.$build(view)\n }\n }),\n ],\n cursor: skeleton.cursor,\n seenAt: params.seenAt,\n }\n}\n\nconst truncateRelatedViewsItems = <T extends unknown[]>(\n items: T,\n): T[number][] => items.slice(0, MAX_GROUP_ITEMS_WITH_RELATED_VIEWS)\n\nconst normalizeFeed = (feed: string): NotificationFeed => {\n switch (feed) {\n case 'people-i-follow':\n return NotificationFeed.PEOPLE_I_FOLLOW\n case 'conversations':\n return NotificationFeed.CONVERSATIONS\n case 'followers':\n return NotificationFeed.FOLLOWERS\n case 'activity':\n return NotificationFeed.ACTIVITY\n default:\n return NotificationFeed.ALL\n }\n}\n\ntype Context = {\n hydrator: Hydrator\n views: Views\n cfg: ServerConfig\n}\n\ntype Params = app.bsky.notification.getGroupedNotifications.$Params & {\n hydrateCtx: HydrateCtxWithViewer\n seenAt?: DatetimeString\n}\n\ntype SkeletonState = {\n groups: NotificationGroup[]\n cursor?: string\n}\n"]}
@@ -1,3 +1,3 @@
1
1
  import type { GroupingResult, NotificationGroup, NotificationItem } from './grouping.js';
2
- export declare const buildSpotlight: (items: NotificationItem[], groups: NotificationGroup[], cursor: string | undefined, limit: number, seenAt: number | undefined) => GroupingResult;
2
+ export declare function buildSpotlight(items: NotificationItem[], groups: NotificationGroup[], cursor: string | undefined, limit: number, seenAt: number | undefined): GroupingResult;
3
3
  //# sourceMappingURL=spotlight.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"spotlight.d.ts","sourceRoot":"","sources":["../../../../../../src/api/app/bsky/notification/grouping/spotlight.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EACV,cAAc,EACd,iBAAiB,EACjB,gBAAgB,EACjB,MAAM,eAAe,CAAA;AAsBtB,eAAO,MAAM,cAAc,UAClB,gBAAgB,EAAE,UACjB,iBAAiB,EAAE,UACnB,MAAM,GAAG,SAAS,SACnB,MAAM,UACL,MAAM,GAAG,SAAS,KACzB,cAuEF,CAAA"}
1
+ {"version":3,"file":"spotlight.d.ts","sourceRoot":"","sources":["../../../../../../src/api/app/bsky/notification/grouping/spotlight.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EACV,cAAc,EACd,iBAAiB,EACjB,gBAAgB,EACjB,MAAM,eAAe,CAAA;AAiCtB,wBAAgB,cAAc,CAC5B,KAAK,EAAE,gBAAgB,EAAE,EACzB,MAAM,EAAE,iBAAiB,EAAE,EAC3B,MAAM,EAAE,MAAM,GAAG,SAAS,EAC1B,KAAK,EAAE,MAAM,EACb,MAAM,EAAE,MAAM,GAAG,SAAS,GACzB,cAAc,CAyGhB"}
@@ -3,112 +3,146 @@ import { AtUri } from '@atproto/syntax';
3
3
  import { app } from '../../../../../lexicons/index.js';
4
4
  import { APPVIEW_NOTIFICATION_REASON, NOTIFICATION_REASON, } from '../constants.js';
5
5
  import { MAX_GROUP_SIZE, compareNotificationGroupsNewestFirst, isNotificationRead, } from './shared.js';
6
- const MULTI_POST_LIKE_RANGES = [
6
+ const MAX_SPOTLIGHTS = 3;
7
+ const MULTI_POST_RANGES = [
7
8
  { maxItems: 200, requiredPosts: 4 },
8
9
  { maxItems: 500, requiredPosts: 8 },
9
10
  ];
10
- export const buildSpotlight = (items, groups, cursor, limit, seenAt) => {
11
- const noSpotlightPage = { groups, cursor };
11
+ const SPOTLIGHT_KINDS = {
12
+ [NOTIFICATION_REASON.LIKE]: APPVIEW_NOTIFICATION_REASON.MULTI_POST_LIKE,
13
+ [NOTIFICATION_REASON.REPOST]: APPVIEW_NOTIFICATION_REASON.MULTI_POST_REPOST,
14
+ [NOTIFICATION_REASON.LIKE_VIA_REPOST]: APPVIEW_NOTIFICATION_REASON.MULTI_POST_LIKE_VIA_REPOST,
15
+ [NOTIFICATION_REASON.REPOST_VIA_REPOST]: APPVIEW_NOTIFICATION_REASON.MULTI_POST_REPOST_VIA_REPOST,
16
+ };
17
+ const SPOTLIGHT_REASONS = Object.keys(SPOTLIGHT_KINDS);
18
+ export function buildSpotlight(items, groups, cursor, limit, seenAt) {
19
+ // @NOTE Try one spotlight at a time, keeping the last page where all spotlights pass validation.
20
+ let lastGoodPage = { groups, cursor };
12
21
  const itemCount = groups.reduce((count, group) => count + group.items.length, 0);
13
- // Grouping consumes a continuous raw prefix, even when groups interleave.
22
+ // @NOTE Grouping consumes a continuous raw prefix, even when groups interleave.
14
23
  // items contains all fetched notifications, but grouping may stop before consuming them all;
15
24
  // itemCount counts notifications included in the ordinary groups, and pageItems contains the notifications on the page.
16
25
  const pageItems = items.slice(0, itemCount);
17
- const spotlight = selectMultiPostLikeSpotlight(pageItems);
18
- if (!spotlight)
19
- return noSpotlightPage;
20
- const selectedItems = new Set(spotlight.items);
21
26
  const positions = new Map(pageItems.map((item, index) => [item, index]));
22
- const proposedGroups = mapDefined([
23
- ...groups.map((group) => ({
24
- // Filtering may remove notifications from this group; build a new group with only the remaining items and their updated metadata.
25
- kind: group.kind,
26
- groupingKey: group.groupingKey,
27
- items: group.items.filter((item) => !selectedItems.has(item)),
28
- })),
29
- spotlight,
30
- ], (group) => {
31
- const newest = group.items[0];
32
- const oldest = group.items.at(-1);
33
- if (!newest || !oldest)
34
- return;
35
- // Filtering may remove notifications from this group; build a new group with only the remaining items and their updated metadata.
36
- return {
37
- kind: group.kind,
38
- groupingKey: group.groupingKey,
39
- id: newest.id,
40
- items: group.items,
41
- actorDids: group.items.map((item) => item.actorDid),
42
- itemCount: group.items.length,
43
- indexedAt: newest.raw.indexedAt,
44
- firstIndexedAt: oldest.raw.indexedAt,
45
- isRead: isNotificationRead(newest.raw.indexedAt, seenAt),
46
- };
47
- }).sort(compareNotificationGroupsNewestFirst);
48
- let retainedItems = pageItems;
49
- const extraGroup = proposedGroups[limit];
50
- if (extraGroup) {
51
- const cutoff = positions.get(extraGroup.items[0]);
52
- retainedItems = pageItems.slice(0, cutoff);
53
- cursor = pageItems[cutoff - 1].raw.indexedAt;
54
- // Trimming every group at one raw position preserves the page prefix.
55
- for (const group of proposedGroups) {
56
- group.items = group.items.filter((item) => positions.get(item) < cutoff);
57
- group.actorDids = group.items.map((item) => item.actorDid);
58
- group.itemCount = group.items.length;
27
+ // @NOTE Rank each reason's top actor by full count, then recency, before capping spotlight size.
28
+ const candidates = mapDefined(SPOTLIGHT_REASONS, (reason) => selectSpotlight(pageItems, reason))
29
+ .sort((left, right) => right.items.length - left.items.length ||
30
+ positions.get(left.items[0]) - positions.get(right.items[0]))
31
+ .map((candidate) => ({
32
+ ...candidate,
33
+ items: candidate.items.slice(0, MAX_GROUP_SIZE),
34
+ }));
35
+ let lastGoodItems = pageItems;
36
+ const acceptedSpotlights = [];
37
+ for (const candidate of candidates) {
38
+ if (acceptedSpotlights.length === MAX_SPOTLIGHTS)
39
+ break;
40
+ // @NOTE 1. Tentatively add this spotlight using only notifications retained on the last accepted page.
41
+ const candidateItems = candidate.items.filter((item) => positions.get(item) < lastGoodItems.length);
42
+ const selectedItems = new Set(candidateItems);
43
+ const proposedGroups = mapDefined([
44
+ ...lastGoodPage.groups.map((group) => ({
45
+ // @NOTE Filtering may remove notifications from this group; build a new group with only the remaining items and their updated metadata.
46
+ kind: group.kind,
47
+ groupingKey: group.groupingKey,
48
+ items: group.items.filter((item) => !selectedItems.has(item)),
49
+ })),
50
+ { ...candidate, items: candidateItems },
51
+ ], (group) => {
52
+ const newest = group.items[0];
59
53
  const oldest = group.items.at(-1);
60
- if (oldest)
61
- group.firstIndexedAt = oldest.raw.indexedAt;
54
+ if (!newest || !oldest)
55
+ return;
56
+ // @NOTE Filtering may remove notifications from this group; build a new group with only the remaining items and their updated metadata.
57
+ return {
58
+ kind: group.kind,
59
+ groupingKey: group.groupingKey,
60
+ id: newest.id,
61
+ items: group.items,
62
+ actorDids: group.items.map((item) => item.actorDid),
63
+ itemCount: group.items.length,
64
+ indexedAt: newest.raw.indexedAt,
65
+ firstIndexedAt: oldest.raw.indexedAt,
66
+ isRead: isNotificationRead(newest.raw.indexedAt, seenAt),
67
+ };
68
+ }).sort(compareNotificationGroupsNewestFirst);
69
+ // @NOTE 2. Trim the tentative page to the group limit without changing the saved state.
70
+ let retainedItems = lastGoodItems;
71
+ let nextCursor = lastGoodPage.cursor;
72
+ const extraGroup = proposedGroups[limit];
73
+ if (extraGroup) {
74
+ const cutoff = positions.get(extraGroup.items[0]);
75
+ retainedItems = lastGoodItems.slice(0, cutoff);
76
+ nextCursor = pageItems[cutoff - 1].raw.indexedAt;
77
+ // @NOTE Trimming every group at one raw position preserves the page prefix.
78
+ for (const group of proposedGroups) {
79
+ group.items = group.items.filter((item) => positions.get(item) < cutoff);
80
+ group.actorDids = group.items.map((item) => item.actorDid);
81
+ group.itemCount = group.items.length;
82
+ const oldest = group.items.at(-1);
83
+ if (oldest)
84
+ group.firstIndexedAt = oldest.raw.indexedAt;
85
+ }
62
86
  }
87
+ const retained = new Set(retainedItems);
88
+ // @NOTE 3. Reject the attempt if any spotlight fails, preserving the previously accepted page and cursor.
89
+ const allEligible = [...acceptedSpotlights, candidate].every((spotlight) => spotlight.isEligibleAfterTrimming(spotlight.items.filter((item) => retained.has(item)), retainedItems));
90
+ if (!allEligible)
91
+ continue;
92
+ // @NOTE 4. Save the valid page, cursor, and remaining notifications for the next attempt.
93
+ lastGoodPage = {
94
+ cursor: nextCursor,
95
+ groups: proposedGroups.filter((group) => group.items.length > 0),
96
+ };
97
+ lastGoodItems = retainedItems;
98
+ acceptedSpotlights.push(candidate);
63
99
  }
64
- const spotlightItems = retainedItems.filter((item) => selectedItems.has(item));
65
- if (!spotlight.isEligibleAfterTrimming(spotlightItems, retainedItems)) {
66
- return noSpotlightPage;
67
- }
68
- return {
69
- cursor,
70
- groups: proposedGroups.filter((group) => group.items.length > 0),
71
- };
72
- };
73
- const selectMultiPostLikeSpotlight = (items) => {
74
- const range = MULTI_POST_LIKE_RANGES.find(({ maxItems }) => items.length <= maxItems);
100
+ return lastGoodPage;
101
+ }
102
+ function selectSpotlight(items, reason) {
103
+ const range = MULTI_POST_RANGES.find(({ maxItems }) => items.length <= maxItems);
75
104
  if (!range)
76
105
  return;
77
- // Eligibility uses the ordinary page's volume, including after trimming.
106
+ // @NOTE Eligibility uses the ordinary page's volume, including after trimming.
78
107
  const { requiredPosts } = range;
79
- const likesByTopLiker = getLikeNotificationsByTopLiker(items);
80
- if (likesByTopLiker.length < requiredPosts)
108
+ const topItems = getNotificationsByTopActor(items, reason);
109
+ if (topItems.length < requiredPosts)
81
110
  return;
82
- const actorDid = likesByTopLiker[0].actorDid;
111
+ const actorDid = topItems[0].actorDid;
83
112
  return {
84
- kind: APPVIEW_NOTIFICATION_REASON.MULTI_POST_LIKE,
113
+ kind: SPOTLIGHT_KINDS[reason],
85
114
  groupingKey: actorDid,
86
- items: likesByTopLiker.slice(0, MAX_GROUP_SIZE),
115
+ items: topItems,
87
116
  isEligibleAfterTrimming: (spotlightItems, retainedItems) =>
88
- // Check if after trimming it still satisfies the requirements.
117
+ // @NOTE Check if after trimming it still satisfies the requirements.
89
118
  spotlightItems.length >= requiredPosts &&
90
- getLikeNotificationsByTopLiker(retainedItems)[0]?.actorDid === actorDid,
119
+ getNotificationsByTopActor(retainedItems, reason)[0]?.actorDid ===
120
+ actorDid,
91
121
  };
92
- };
93
- const getLikeNotificationsByTopLiker = (items) => {
94
- const likesByActor = new Map();
122
+ }
123
+ function getNotificationsByTopActor(items, reason) {
124
+ const collection = reason === NOTIFICATION_REASON.LIKE_VIA_REPOST ||
125
+ reason === NOTIFICATION_REASON.REPOST_VIA_REPOST
126
+ ? app.bsky.feed.repost.$type
127
+ : app.bsky.feed.post.$type;
128
+ const itemsByActor = new Map();
95
129
  for (const item of items) {
96
- if (item.raw.reason !== NOTIFICATION_REASON.LIKE ||
97
- new AtUri(item.raw.reasonSubject).collection !== app.bsky.feed.post.$type) {
130
+ if (item.raw.reason !== reason ||
131
+ new AtUri(item.raw.reasonSubject).collection !== collection) {
98
132
  continue;
99
133
  }
100
- const likes = likesByActor.get(item.actorDid);
101
- if (likes)
102
- likes.push(item);
134
+ const actorItems = itemsByActor.get(item.actorDid);
135
+ if (actorItems)
136
+ actorItems.push(item);
103
137
  else
104
- likesByActor.set(item.actorDid, [item]);
138
+ itemsByActor.set(item.actorDid, [item]);
105
139
  }
106
- // Each actor likes a post once; insertion order breaks ties by newest like.
140
+ // @NOTE Each actor likes or reposts a post once per reason; insertion order breaks ties by newest notification.
107
141
  let top = [];
108
- for (const likes of likesByActor.values()) {
109
- if (likes.length > top.length)
110
- top = likes;
142
+ for (const actorItems of itemsByActor.values()) {
143
+ if (actorItems.length > top.length)
144
+ top = actorItems;
111
145
  }
112
146
  return top;
113
- };
147
+ }
114
148
  //# sourceMappingURL=spotlight.js.map