-
Notifications
You must be signed in to change notification settings - Fork 940
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[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>
- Loading branch information
1 parent
1c6bfc0
commit 3407206
Showing
6 changed files
with
196 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters