Indicate if someone followed you via a starter pack (#11320)

This commit is contained in:
DS Boyce
2026-07-29 12:11:28 -07:00
committed by GitHub
parent 8e3b252b86
commit b4bad1187a
7 changed files with 304 additions and 216 deletions
@@ -0,0 +1,62 @@
import {type AppBskyNotificationListNotifications} from '@atproto/api'
import {describe, expect, it, jest} from '@jest/globals'
import {groupNotifications} from '../util'
jest.mock('#/state/queries/profile', () => ({precacheProfile: jest.fn()}))
type Notification = AppBskyNotificationListNotifications.Notification
function makeFollowNotification(
did: string,
starterPackUri?: string,
): Notification {
return {
uri: `at://${did}/app.bsky.graph.follow/follow`,
cid: `cid-${did}`,
author: {
did,
handle: `${did}.test`,
displayName: did,
avatar: undefined,
associated: undefined,
viewer: {},
labels: [],
createdAt: '2026-07-28T12:00:00.000Z',
},
reason: 'follow',
record: {},
starterPack: starterPackUri
? ({uri: starterPackUri} as Notification['starterPack'])
: undefined,
isRead: false,
indexedAt: '2026-07-28T12:00:00.000Z',
}
}
describe('groupNotifications', () => {
it('groups follows by starter pack', () => {
const packA = 'at://did:plc:alice/app.bsky.graph.starterpack/a'
const packB = 'at://did:plc:bob/app.bsky.graph.starterpack/b'
const grouped = groupNotifications([
makeFollowNotification('did:plc:a', packA),
makeFollowNotification('did:plc:b', packB),
makeFollowNotification('did:plc:c', packA),
makeFollowNotification('did:plc:d'),
makeFollowNotification('did:plc:e', packB),
makeFollowNotification('did:plc:f'),
])
expect(
grouped.map(item => [
item.notification.author.did,
...(item.additional ?? []).map(notification => notification.author.did),
]),
).toEqual([
['did:plc:a', 'did:plc:c'],
['did:plc:b', 'did:plc:e'],
['did:plc:d', 'did:plc:f'],
])
})
})
+3
View File
@@ -163,6 +163,9 @@ export function groupNotifications(
Math.abs(ts2 - ts) < MS_2DAY &&
notif.reason === groupedNotif.notification.reason &&
notif.reasonSubject === groupedNotif.notification.reasonSubject &&
(notif.reason !== 'follow' ||
notif.starterPack?.uri ===
groupedNotif.notification.starterPack?.uri) &&
(notif.author.did !== groupedNotif.notification.author.did ||
notif.reason === 'subscribed-post')
) {