Bluesky app fork with some witchin' additions 💫

Improved client events for feed interactions (#9695)

authored by

Alex Benzer and committed by
GitHub
e684c215 226b19ae

+40 -8
+8
src/logger/metrics.ts
··· 244 isReply: boolean 245 } 246 'post:like': { 247 doesLikerFollowPoster: boolean | undefined 248 doesPosterFollowLiker: boolean | undefined 249 likerClout: number | undefined ··· 252 feedDescriptor?: string 253 } 254 'post:repost': { 255 logContext: 'FeedItem' | 'PostThreadItem' | 'Post' | 'ImmersiveVideo' 256 feedDescriptor?: string 257 } 258 'post:unlike': { 259 logContext: 'FeedItem' | 'PostThreadItem' | 'Post' | 'ImmersiveVideo' 260 feedDescriptor?: string 261 } 262 'post:unrepost': { 263 logContext: 'FeedItem' | 'PostThreadItem' | 'Post' | 'ImmersiveVideo' 264 feedDescriptor?: string 265 }
··· 244 isReply: boolean 245 } 246 'post:like': { 247 + uri: string 248 + authorDid: string 249 doesLikerFollowPoster: boolean | undefined 250 doesPosterFollowLiker: boolean | undefined 251 likerClout: number | undefined ··· 254 feedDescriptor?: string 255 } 256 'post:repost': { 257 + uri: string 258 + authorDid: string 259 logContext: 'FeedItem' | 'PostThreadItem' | 'Post' | 'ImmersiveVideo' 260 feedDescriptor?: string 261 } 262 'post:unlike': { 263 + uri: string 264 + authorDid: string 265 logContext: 'FeedItem' | 'PostThreadItem' | 'Post' | 'ImmersiveVideo' 266 feedDescriptor?: string 267 } 268 'post:unrepost': { 269 + uri: string 270 + authorDid: string 271 logContext: 'FeedItem' | 'PostThreadItem' | 'Post' | 'ImmersiveVideo' 272 feedDescriptor?: string 273 }
+32 -8
src/state/queries/post.ts
··· 111 const postCid = post.cid 112 const initialLikeUri = post.viewer?.like 113 const likeMutation = usePostLikeMutation(feedDescriptor, logContext, post) 114 - const unlikeMutation = usePostUnlikeMutation(feedDescriptor, logContext) 115 116 const queueToggle = useToggleMutationQueue({ 117 initialState: initialLikeUri, ··· 182 ownProfile = findProfileQueryData(queryClient, currentAccount.did) 183 } 184 logger.metric('post:like', { 185 logContext, 186 doesPosterFollowLiker: postAuthor.viewer 187 ? Boolean(postAuthor.viewer.followedBy) ··· 206 function usePostUnlikeMutation( 207 feedDescriptor: string | undefined, 208 logContext: LogEvents['post:unlike']['logContext'], 209 ) { 210 const agent = useAgent() 211 return useMutation<void, Error, {postUri: string; likeUri: string}>({ 212 - mutationFn: ({likeUri}) => { 213 - logger.metric('post:unlike', {logContext, feedDescriptor}) 214 return agent.deleteLike(likeUri) 215 }, 216 }) ··· 227 const postUri = post.uri 228 const postCid = post.cid 229 const initialRepostUri = post.viewer?.repost 230 - const repostMutation = usePostRepostMutation(feedDescriptor, logContext) 231 - const unrepostMutation = usePostUnrepostMutation(feedDescriptor, logContext) 232 233 const queueToggle = useToggleMutationQueue({ 234 initialState: initialRepostUri, ··· 280 function usePostRepostMutation( 281 feedDescriptor: string | undefined, 282 logContext: LogEvents['post:repost']['logContext'], 283 ) { 284 const agent = useAgent() 285 return useMutation< ··· 288 {uri: string; cid: string; via?: {uri: string; cid: string}} // the post's uri and cid, and the repost uri/cid if present 289 >({ 290 mutationFn: ({uri, cid, via}) => { 291 - logger.metric('post:repost', {logContext, feedDescriptor}) 292 return agent.repost(uri, cid, via) 293 }, 294 }) ··· 297 function usePostUnrepostMutation( 298 feedDescriptor: string | undefined, 299 logContext: LogEvents['post:unrepost']['logContext'], 300 ) { 301 const agent = useAgent() 302 return useMutation<void, Error, {postUri: string; repostUri: string}>({ 303 - mutationFn: ({repostUri}) => { 304 - logger.metric('post:unrepost', {logContext, feedDescriptor}) 305 return agent.deleteRepost(repostUri) 306 }, 307 })
··· 111 const postCid = post.cid 112 const initialLikeUri = post.viewer?.like 113 const likeMutation = usePostLikeMutation(feedDescriptor, logContext, post) 114 + const unlikeMutation = usePostUnlikeMutation(feedDescriptor, logContext, post) 115 116 const queueToggle = useToggleMutationQueue({ 117 initialState: initialLikeUri, ··· 182 ownProfile = findProfileQueryData(queryClient, currentAccount.did) 183 } 184 logger.metric('post:like', { 185 + uri, 186 + authorDid: postAuthor.did, 187 logContext, 188 doesPosterFollowLiker: postAuthor.viewer 189 ? Boolean(postAuthor.viewer.followedBy) ··· 208 function usePostUnlikeMutation( 209 feedDescriptor: string | undefined, 210 logContext: LogEvents['post:unlike']['logContext'], 211 + post: Shadow<AppBskyFeedDefs.PostView>, 212 ) { 213 const agent = useAgent() 214 return useMutation<void, Error, {postUri: string; likeUri: string}>({ 215 + mutationFn: ({postUri, likeUri}) => { 216 + logger.metric('post:unlike', { 217 + uri: postUri, 218 + authorDid: post.author.did, 219 + logContext, 220 + feedDescriptor, 221 + }) 222 return agent.deleteLike(likeUri) 223 }, 224 }) ··· 235 const postUri = post.uri 236 const postCid = post.cid 237 const initialRepostUri = post.viewer?.repost 238 + const repostMutation = usePostRepostMutation(feedDescriptor, logContext, post) 239 + const unrepostMutation = usePostUnrepostMutation( 240 + feedDescriptor, 241 + logContext, 242 + post, 243 + ) 244 245 const queueToggle = useToggleMutationQueue({ 246 initialState: initialRepostUri, ··· 292 function usePostRepostMutation( 293 feedDescriptor: string | undefined, 294 logContext: LogEvents['post:repost']['logContext'], 295 + post: Shadow<AppBskyFeedDefs.PostView>, 296 ) { 297 const agent = useAgent() 298 return useMutation< ··· 301 {uri: string; cid: string; via?: {uri: string; cid: string}} // the post's uri and cid, and the repost uri/cid if present 302 >({ 303 mutationFn: ({uri, cid, via}) => { 304 + logger.metric('post:repost', { 305 + uri, 306 + authorDid: post.author.did, 307 + logContext, 308 + feedDescriptor, 309 + }) 310 return agent.repost(uri, cid, via) 311 }, 312 }) ··· 315 function usePostUnrepostMutation( 316 feedDescriptor: string | undefined, 317 logContext: LogEvents['post:unrepost']['logContext'], 318 + post: Shadow<AppBskyFeedDefs.PostView>, 319 ) { 320 const agent = useAgent() 321 return useMutation<void, Error, {postUri: string; repostUri: string}>({ 322 + mutationFn: ({postUri, repostUri}) => { 323 + logger.metric('post:unrepost', { 324 + uri: postUri, 325 + authorDid: post.author.did, 326 + logContext, 327 + feedDescriptor, 328 + }) 329 return agent.deleteRepost(repostUri) 330 }, 331 })