Improved client events for feed interactions (#9695)
This commit is contained in:
@@ -244,6 +244,8 @@ export type MetricEvents = {
|
|||||||
isReply: boolean
|
isReply: boolean
|
||||||
}
|
}
|
||||||
'post:like': {
|
'post:like': {
|
||||||
|
uri: string
|
||||||
|
authorDid: string
|
||||||
doesLikerFollowPoster: boolean | undefined
|
doesLikerFollowPoster: boolean | undefined
|
||||||
doesPosterFollowLiker: boolean | undefined
|
doesPosterFollowLiker: boolean | undefined
|
||||||
likerClout: number | undefined
|
likerClout: number | undefined
|
||||||
@@ -252,14 +254,20 @@ export type MetricEvents = {
|
|||||||
feedDescriptor?: string
|
feedDescriptor?: string
|
||||||
}
|
}
|
||||||
'post:repost': {
|
'post:repost': {
|
||||||
|
uri: string
|
||||||
|
authorDid: string
|
||||||
logContext: 'FeedItem' | 'PostThreadItem' | 'Post' | 'ImmersiveVideo'
|
logContext: 'FeedItem' | 'PostThreadItem' | 'Post' | 'ImmersiveVideo'
|
||||||
feedDescriptor?: string
|
feedDescriptor?: string
|
||||||
}
|
}
|
||||||
'post:unlike': {
|
'post:unlike': {
|
||||||
|
uri: string
|
||||||
|
authorDid: string
|
||||||
logContext: 'FeedItem' | 'PostThreadItem' | 'Post' | 'ImmersiveVideo'
|
logContext: 'FeedItem' | 'PostThreadItem' | 'Post' | 'ImmersiveVideo'
|
||||||
feedDescriptor?: string
|
feedDescriptor?: string
|
||||||
}
|
}
|
||||||
'post:unrepost': {
|
'post:unrepost': {
|
||||||
|
uri: string
|
||||||
|
authorDid: string
|
||||||
logContext: 'FeedItem' | 'PostThreadItem' | 'Post' | 'ImmersiveVideo'
|
logContext: 'FeedItem' | 'PostThreadItem' | 'Post' | 'ImmersiveVideo'
|
||||||
feedDescriptor?: string
|
feedDescriptor?: string
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -111,7 +111,7 @@ export function usePostLikeMutationQueue(
|
|||||||
const postCid = post.cid
|
const postCid = post.cid
|
||||||
const initialLikeUri = post.viewer?.like
|
const initialLikeUri = post.viewer?.like
|
||||||
const likeMutation = usePostLikeMutation(feedDescriptor, logContext, post)
|
const likeMutation = usePostLikeMutation(feedDescriptor, logContext, post)
|
||||||
const unlikeMutation = usePostUnlikeMutation(feedDescriptor, logContext)
|
const unlikeMutation = usePostUnlikeMutation(feedDescriptor, logContext, post)
|
||||||
|
|
||||||
const queueToggle = useToggleMutationQueue({
|
const queueToggle = useToggleMutationQueue({
|
||||||
initialState: initialLikeUri,
|
initialState: initialLikeUri,
|
||||||
@@ -182,6 +182,8 @@ function usePostLikeMutation(
|
|||||||
ownProfile = findProfileQueryData(queryClient, currentAccount.did)
|
ownProfile = findProfileQueryData(queryClient, currentAccount.did)
|
||||||
}
|
}
|
||||||
logger.metric('post:like', {
|
logger.metric('post:like', {
|
||||||
|
uri,
|
||||||
|
authorDid: postAuthor.did,
|
||||||
logContext,
|
logContext,
|
||||||
doesPosterFollowLiker: postAuthor.viewer
|
doesPosterFollowLiker: postAuthor.viewer
|
||||||
? Boolean(postAuthor.viewer.followedBy)
|
? Boolean(postAuthor.viewer.followedBy)
|
||||||
@@ -206,11 +208,17 @@ function usePostLikeMutation(
|
|||||||
function usePostUnlikeMutation(
|
function usePostUnlikeMutation(
|
||||||
feedDescriptor: string | undefined,
|
feedDescriptor: string | undefined,
|
||||||
logContext: LogEvents['post:unlike']['logContext'],
|
logContext: LogEvents['post:unlike']['logContext'],
|
||||||
|
post: Shadow<AppBskyFeedDefs.PostView>,
|
||||||
) {
|
) {
|
||||||
const agent = useAgent()
|
const agent = useAgent()
|
||||||
return useMutation<void, Error, {postUri: string; likeUri: string}>({
|
return useMutation<void, Error, {postUri: string; likeUri: string}>({
|
||||||
mutationFn: ({likeUri}) => {
|
mutationFn: ({postUri, likeUri}) => {
|
||||||
logger.metric('post:unlike', {logContext, feedDescriptor})
|
logger.metric('post:unlike', {
|
||||||
|
uri: postUri,
|
||||||
|
authorDid: post.author.did,
|
||||||
|
logContext,
|
||||||
|
feedDescriptor,
|
||||||
|
})
|
||||||
return agent.deleteLike(likeUri)
|
return agent.deleteLike(likeUri)
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
@@ -227,8 +235,12 @@ export function usePostRepostMutationQueue(
|
|||||||
const postUri = post.uri
|
const postUri = post.uri
|
||||||
const postCid = post.cid
|
const postCid = post.cid
|
||||||
const initialRepostUri = post.viewer?.repost
|
const initialRepostUri = post.viewer?.repost
|
||||||
const repostMutation = usePostRepostMutation(feedDescriptor, logContext)
|
const repostMutation = usePostRepostMutation(feedDescriptor, logContext, post)
|
||||||
const unrepostMutation = usePostUnrepostMutation(feedDescriptor, logContext)
|
const unrepostMutation = usePostUnrepostMutation(
|
||||||
|
feedDescriptor,
|
||||||
|
logContext,
|
||||||
|
post,
|
||||||
|
)
|
||||||
|
|
||||||
const queueToggle = useToggleMutationQueue({
|
const queueToggle = useToggleMutationQueue({
|
||||||
initialState: initialRepostUri,
|
initialState: initialRepostUri,
|
||||||
@@ -280,6 +292,7 @@ export function usePostRepostMutationQueue(
|
|||||||
function usePostRepostMutation(
|
function usePostRepostMutation(
|
||||||
feedDescriptor: string | undefined,
|
feedDescriptor: string | undefined,
|
||||||
logContext: LogEvents['post:repost']['logContext'],
|
logContext: LogEvents['post:repost']['logContext'],
|
||||||
|
post: Shadow<AppBskyFeedDefs.PostView>,
|
||||||
) {
|
) {
|
||||||
const agent = useAgent()
|
const agent = useAgent()
|
||||||
return useMutation<
|
return useMutation<
|
||||||
@@ -288,7 +301,12 @@ function usePostRepostMutation(
|
|||||||
{uri: string; cid: string; via?: {uri: string; cid: string}} // the post's uri and cid, and the repost uri/cid if present
|
{uri: string; cid: string; via?: {uri: string; cid: string}} // the post's uri and cid, and the repost uri/cid if present
|
||||||
>({
|
>({
|
||||||
mutationFn: ({uri, cid, via}) => {
|
mutationFn: ({uri, cid, via}) => {
|
||||||
logger.metric('post:repost', {logContext, feedDescriptor})
|
logger.metric('post:repost', {
|
||||||
|
uri,
|
||||||
|
authorDid: post.author.did,
|
||||||
|
logContext,
|
||||||
|
feedDescriptor,
|
||||||
|
})
|
||||||
return agent.repost(uri, cid, via)
|
return agent.repost(uri, cid, via)
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
@@ -297,11 +315,17 @@ function usePostRepostMutation(
|
|||||||
function usePostUnrepostMutation(
|
function usePostUnrepostMutation(
|
||||||
feedDescriptor: string | undefined,
|
feedDescriptor: string | undefined,
|
||||||
logContext: LogEvents['post:unrepost']['logContext'],
|
logContext: LogEvents['post:unrepost']['logContext'],
|
||||||
|
post: Shadow<AppBskyFeedDefs.PostView>,
|
||||||
) {
|
) {
|
||||||
const agent = useAgent()
|
const agent = useAgent()
|
||||||
return useMutation<void, Error, {postUri: string; repostUri: string}>({
|
return useMutation<void, Error, {postUri: string; repostUri: string}>({
|
||||||
mutationFn: ({repostUri}) => {
|
mutationFn: ({postUri, repostUri}) => {
|
||||||
logger.metric('post:unrepost', {logContext, feedDescriptor})
|
logger.metric('post:unrepost', {
|
||||||
|
uri: postUri,
|
||||||
|
authorDid: post.author.did,
|
||||||
|
logContext,
|
||||||
|
feedDescriptor,
|
||||||
|
})
|
||||||
return agent.deleteRepost(repostUri)
|
return agent.deleteRepost(repostUri)
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user