Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/appview-v2-no-notif-seen' into a…
Browse files Browse the repository at this point in the history
…ppview-v2-testing
  • Loading branch information
devinivy committed Jan 25, 2024
2 parents 9211a91 + 9719a5d commit 6822634
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,16 @@ const skeleton = async (
actorDid: params.viewer,
}),
])
// @NOTE for the first page of results if there's no last-seen time, consider top notification unread
// rather than all notifications. bit of a hack to be more graceful when seen times are out of sync.
let lastSeenDate = lastSeenRes.timestamp?.toDate()
if (!lastSeenDate && !params.cursor) {
lastSeenDate = res.notifications.at(0)?.timestamp?.toDate()
}
return {
notifs: res.notifications,
cursor: res.cursor || undefined,
lastSeenNotifs: lastSeenRes.timestamp?.toDate().toISOString(),
lastSeenNotifs: lastSeenDate?.toISOString(),
}
}

Expand Down
5 changes: 4 additions & 1 deletion packages/bsky/src/views/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -811,7 +811,10 @@ export class Views {
reason: notif.reason,
reasonSubject: notif.reasonSubject || undefined,
record: recordInfo.record,
isRead: lastSeenAt ? lastSeenAt >= indexedAt : false,
// @NOTE works with a hack in listNotifications so that when there's no last-seen time,
// the user's first notification is marked unread, and all previous read. in this case,
// the last seen time will be equal to the first notification's indexed time.
isRead: lastSeenAt ? lastSeenAt > indexedAt : true,
indexedAt: notif.timestamp.toDate().toISOString(),
labels: [...labels, ...selfLabels],
}
Expand Down
28 changes: 14 additions & 14 deletions packages/bsky/tests/views/__snapshots__/notifications.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@ Array [
},
"cid": "cids(0)",
"indexedAt": "1970-01-01T00:00:00.000Z",
"isRead": false,
"isRead": true,
"labels": Array [],
"reason": "repost",
"reasonSubject": "record(2)",
Expand All @@ -407,7 +407,7 @@ Array [
},
"cid": "cids(2)",
"indexedAt": "1970-01-01T00:00:00.000Z",
"isRead": false,
"isRead": true,
"labels": Array [],
"reason": "repost",
"reasonSubject": "record(4)",
Expand All @@ -434,7 +434,7 @@ Array [
},
"cid": "cids(4)",
"indexedAt": "1970-01-01T00:00:00.000Z",
"isRead": false,
"isRead": true,
"labels": Array [],
"reason": "mention",
"record": Object {
Expand Down Expand Up @@ -478,7 +478,7 @@ Array [
},
"cid": "cids(6)",
"indexedAt": "1970-01-01T00:00:00.000Z",
"isRead": false,
"isRead": true,
"labels": Array [],
"reason": "like",
"reasonSubject": "record(4)",
Expand Down Expand Up @@ -506,7 +506,7 @@ Array [
},
"cid": "cids(7)",
"indexedAt": "1970-01-01T00:00:00.000Z",
"isRead": false,
"isRead": true,
"labels": Array [],
"reason": "follow",
"record": Object {
Expand Down Expand Up @@ -565,7 +565,7 @@ Array [
},
"cid": "cids(9)",
"indexedAt": "1970-01-01T00:00:00.000Z",
"isRead": false,
"isRead": true,
"labels": Array [],
"reason": "reply",
"reasonSubject": "record(4)",
Expand Down Expand Up @@ -600,7 +600,7 @@ Array [
},
"cid": "cids(10)",
"indexedAt": "1970-01-01T00:00:00.000Z",
"isRead": false,
"isRead": true,
"labels": Array [],
"reason": "like",
"reasonSubject": "record(13)",
Expand Down Expand Up @@ -628,7 +628,7 @@ Array [
},
"cid": "cids(12)",
"indexedAt": "1970-01-01T00:00:00.000Z",
"isRead": false,
"isRead": true,
"labels": Array [],
"reason": "like",
"reasonSubject": "record(4)",
Expand Down Expand Up @@ -660,7 +660,7 @@ Array [
},
"cid": "cids(13)",
"indexedAt": "1970-01-01T00:00:00.000Z",
"isRead": false,
"isRead": true,
"labels": Array [],
"reason": "follow",
"record": Object {
Expand Down Expand Up @@ -688,7 +688,7 @@ Array [
},
"cid": "cids(15)",
"indexedAt": "1970-01-01T00:00:00.000Z",
"isRead": false,
"isRead": true,
"labels": Array [
Object {
"cid": "cids(15)",
Expand Down Expand Up @@ -760,7 +760,7 @@ Array [
},
"cid": "cids(17)",
"indexedAt": "1970-01-01T00:00:00.000Z",
"isRead": false,
"isRead": true,
"labels": Array [],
"reason": "like",
"reasonSubject": "record(13)",
Expand Down Expand Up @@ -792,7 +792,7 @@ Array [
},
"cid": "cids(18)",
"indexedAt": "1970-01-01T00:00:00.000Z",
"isRead": false,
"isRead": true,
"labels": Array [],
"reason": "like",
"reasonSubject": "record(4)",
Expand Down Expand Up @@ -871,7 +871,7 @@ Array [
},
"cid": "cids(2)",
"indexedAt": "1970-01-01T00:00:00.000Z",
"isRead": false,
"isRead": true,
"labels": Array [],
"reason": "follow",
"record": Object {
Expand Down Expand Up @@ -915,7 +915,7 @@ Array [
},
"cid": "cids(5)",
"indexedAt": "1970-01-01T00:00:00.000Z",
"isRead": false,
"isRead": true,
"labels": Array [
Object {
"cid": "cids(5)",
Expand Down
4 changes: 2 additions & 2 deletions packages/bsky/tests/views/notifications.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ describe('notification views', () => {
expect(notifs.length).toBe(13)

const readStates = notifs.map((notif) => notif.isRead)
expect(readStates).toEqual(notifs.map(() => false))
expect(readStates).toEqual(notifs.map((_, i) => i !== 0)) // only first appears unread

expect(forSnapshot(sort(notifs))).toMatchSnapshot()
})
Expand Down Expand Up @@ -221,7 +221,7 @@ describe('notification views', () => {
expect(notifs.length).toBe(13)

const readStates = notifs.map((notif) => notif.isRead)
expect(readStates).toEqual(notifs.map((n) => n.indexedAt <= seenAt))
expect(readStates).toEqual(notifs.map((n) => n.indexedAt < seenAt))
// reset last-seen
await agent.api.app.bsky.notification.updateSeen(
{ seenAt: new Date(0).toISOString() },
Expand Down

0 comments on commit 6822634

Please sign in to comment.