diff options
author | Eric Bailey <git@esb.lol> | 2024-07-04 16:28:38 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-07-04 22:28:38 +0100 |
commit | 3407206f52a03223b9eba925f030cf371833a8ed (patch) | |
tree | 33060612a4a5b23232d85b966906ad7f0a1ba35d /src/state/userActionHistory.ts | |
parent | 1c6bfc02fb9da56281bdc449a951725fb2ec808d (diff) | |
download | voidsky-3407206f52a03223b9eba925f030cf371833a8ed.tar.zst |
[D1X] Use user action and viewing history to inform suggested follows (#4727)
* Use user action and viewing history to inform suggested follows * Remove dynamic spreads * Track more info about seen posts * Add ranking --------- Co-authored-by: Dan Abramov <dan.abramov@gmail.com>
Diffstat (limited to 'src/state/userActionHistory.ts')
-rw-r--r-- | src/state/userActionHistory.ts | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/src/state/userActionHistory.ts b/src/state/userActionHistory.ts new file mode 100644 index 000000000..d82b3723a --- /dev/null +++ b/src/state/userActionHistory.ts @@ -0,0 +1,71 @@ +import React from 'react' + +const LIKE_WINDOW = 100 +const FOLLOW_WINDOW = 100 +const SEEN_WINDOW = 100 + +export type SeenPost = { + uri: string + likeCount: number + repostCount: number + replyCount: number + isFollowedBy: boolean + feedContext: string | undefined +} + +export type UserActionHistory = { + /** + * The last 100 post URIs the user has liked + */ + likes: string[] + /** + * The last 100 DIDs the user has followed + */ + follows: string[] + /** + * The last 100 post URIs the user has seen from the Discover feed only + */ + seen: SeenPost[] +} + +const userActionHistory: UserActionHistory = { + likes: [], + follows: [], + seen: [], +} + +export function getActionHistory() { + return userActionHistory +} + +export function useActionHistorySnapshot() { + return React.useState(() => getActionHistory())[0] +} + +export function like(postUris: string[]) { + userActionHistory.likes = userActionHistory.likes + .concat(postUris) + .slice(-LIKE_WINDOW) +} +export function unlike(postUris: string[]) { + userActionHistory.likes = userActionHistory.likes.filter( + uri => !postUris.includes(uri), + ) +} + +export function follow(dids: string[]) { + userActionHistory.follows = userActionHistory.follows + .concat(dids) + .slice(-FOLLOW_WINDOW) +} +export function unfollow(dids: string[]) { + userActionHistory.follows = userActionHistory.follows.filter( + uri => !dids.includes(uri), + ) +} + +export function seen(posts: SeenPost[]) { + userActionHistory.seen = userActionHistory.seen + .concat(posts) + .slice(-SEEN_WINDOW) +} |