Bluesky app fork with some witchin' additions 💫
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Extend composer checks to all posts in a thread (#5955)

* Check all posts in a thread

* Use thread for more checks

authored by

dan and committed by
GitHub
27ff8543 96ba6456

+65 -50
+65 -50
src/view/com/composer/Composer.tsx
··· 167 167 ) 168 168 169 169 // TODO: Display drafts for other posts in the thread. 170 - const draft = composerState.thread.posts[composerState.activePostIndex] 170 + const thread = composerState.thread 171 + const draft = thread.posts[composerState.activePostIndex] 171 172 const dispatch = useCallback((postAction: PostAction) => { 172 173 composerDispatch({ 173 174 type: 'update_post', ··· 226 227 227 228 const onPressCancel = useCallback(() => { 228 229 if ( 229 - draft.shortenedGraphemeLength > 0 || 230 - draft.embed.media || 231 - draft.embed.link 230 + thread.posts.some( 231 + post => 232 + post.shortenedGraphemeLength > 0 || 233 + post.embed.media || 234 + post.embed.link, 235 + ) 232 236 ) { 233 237 closeAllDialogs() 234 238 Keyboard.dismiss() ··· 236 240 } else { 237 241 onClose() 238 242 } 239 - }, [draft, closeAllDialogs, discardPromptControl, onClose]) 243 + }, [thread, closeAllDialogs, discardPromptControl, onClose]) 240 244 241 245 useImperativeHandle(cancelRef, () => ({onPressCancel})) 242 246 ··· 261 265 }, [onPressCancel, closeAllDialogs, closeAllModals]) 262 266 263 267 const isAltTextRequiredAndMissing = useMemo(() => { 264 - const media = draft.embed.media 265 - if (!requireAltTextEnabled || !media) { 268 + if (!requireAltTextEnabled) { 266 269 return false 267 270 } 268 - if (media.type === 'images' && media.images.some(img => !img.alt)) { 269 - return true 270 - } 271 - if (media.type === 'gif' && !media.alt) { 272 - return true 273 - } 274 - return false 275 - }, [draft.embed.media, requireAltTextEnabled]) 276 - 277 - const isEmptyPost = 278 - draft.richtext.text.trim().length === 0 && 279 - !draft.embed.link && 280 - !draft.embed.media && 281 - !draft.embed.quote 271 + return thread.posts.some(post => { 272 + const media = post.embed.media 273 + if (media) { 274 + if (media.type === 'images' && media.images.some(img => !img.alt)) { 275 + return true 276 + } 277 + if (media.type === 'gif' && !media.alt) { 278 + return true 279 + } 280 + } 281 + }) 282 + }, [thread, requireAltTextEnabled]) 282 283 283 284 const canPost = 284 - draft.shortenedGraphemeLength <= MAX_GRAPHEME_LENGTH && 285 285 !isAltTextRequiredAndMissing && 286 - !isEmptyPost && 287 - videoState.status !== 'error' 286 + thread.posts.every( 287 + post => 288 + post.shortenedGraphemeLength <= MAX_GRAPHEME_LENGTH && 289 + !( 290 + post.richtext.text.trim().length === 0 && 291 + !post.embed.link && 292 + !post.embed.media && 293 + !post.embed.quote 294 + ) && 295 + !( 296 + post.embed.media?.type === 'video' && 297 + post.embed.media.video.status === 'error' 298 + ), 299 + ) 288 300 289 301 const onPressPublish = React.useCallback( 290 302 async (finishedUploading: boolean) => { ··· 298 310 299 311 if ( 300 312 !finishedUploading && 301 - videoState.asset && 302 - videoState.status !== 'done' 313 + thread.posts.some( 314 + post => 315 + post.embed.media?.type === 'video' && 316 + post.embed.media.video.asset && 317 + post.embed.media.video.status !== 'done', 318 + ) 303 319 ) { 304 320 setPublishOnUpload(true) 305 321 return ··· 307 323 308 324 setError('') 309 325 setIsPublishing(true) 310 - 311 - const imageCount = 312 - draft.embed.media?.type === 'images' 313 - ? draft.embed.media.images.length 314 - : 0 315 326 316 327 let postUri 317 328 try { 318 329 postUri = ( 319 330 await apilib.post(agent, queryClient, { 320 - thread: composerState.thread, 331 + thread, 321 332 replyTo: replyTo?.uri, 322 333 onStateChange: setPublishingStage, 323 334 langs: toPostLanguages(langPrefs.postLanguage), ··· 325 336 ).uri 326 337 try { 327 338 await whenAppViewReady(agent, postUri, res => { 328 - const thread = res.data.thread 329 - return AppBskyFeedDefs.isThreadViewPost(thread) 339 + const postedThread = res.data.thread 340 + return AppBskyFeedDefs.isThreadViewPost(postedThread) 330 341 }) 331 342 } catch (waitErr: any) { 332 343 logger.error(waitErr, { ··· 337 348 } catch (e: any) { 338 349 logger.error(e, { 339 350 message: `Composer: create post failed`, 340 - hasImages: imageCount > 0, 351 + hasImages: thread.posts.some(p => p.embed.media?.type === 'images'), 341 352 }) 342 353 343 354 let err = cleanError(e.message) ··· 353 364 return 354 365 } finally { 355 366 if (postUri) { 356 - logEvent('post:create', { 357 - imageCount, 358 - isReply: !!replyTo, 359 - hasLink: !!draft.embed.link, 360 - hasQuote: !!draft.embed.quote, 361 - langs: langPrefs.postLanguage, 362 - logContext: 'Composer', 363 - }) 367 + let index = 0 368 + for (let post of thread.posts) { 369 + logEvent('post:create', { 370 + imageCount: 371 + post.embed.media?.type === 'images' 372 + ? post.embed.media.images.length 373 + : 0, 374 + isReply: index > 0 || !!replyTo, 375 + hasLink: !!post.embed.link, 376 + hasQuote: !!post.embed.quote, 377 + langs: langPrefs.postLanguage, 378 + logContext: 'Composer', 379 + }) 380 + index++ 381 + } 364 382 } 365 383 } 366 384 if (postUri && !replyTo) { ··· 370 388 if (initQuote) { 371 389 // We want to wait for the quote count to update before we call `onPost`, which will refetch data 372 390 whenAppViewReady(agent, initQuote.uri, res => { 373 - const thread = res.data.thread 391 + const quotedThread = res.data.thread 374 392 if ( 375 - AppBskyFeedDefs.isThreadViewPost(thread) && 376 - thread.post.quoteCount !== initQuote.quoteCount 393 + AppBskyFeedDefs.isThreadViewPost(quotedThread) && 394 + quotedThread.post.quoteCount !== initQuote.quoteCount 377 395 ) { 378 396 onPost?.(postUri) 379 397 return true ··· 393 411 [ 394 412 _, 395 413 agent, 396 - composerState.thread, 397 - draft, 414 + thread, 398 415 canPost, 399 416 isPublishing, 400 417 langPrefs.postLanguage, ··· 403 420 initQuote, 404 421 replyTo, 405 422 setLangPrefs, 406 - videoState.asset, 407 - videoState.status, 408 423 queryClient, 409 424 ], 410 425 )