mirror of https://git.lenooby09.tech/LeNooby09/social-app.git
0
fork

Configure Feed

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

[🐴] Convo agent cleanup (#4109)

* Move comment, remove unused code

* Clean up sending

* Remove temp hack

* Remove debug

authored by

Eric Bailey and committed by
GitHub
7de0b0a5 3ca671d9

+11 -33
+10 -32
src/state/messages/convo/agent.ts
··· 34 34 import {MessagesEventBusError} from '#/state/messages/events/types' 35 35 import {DM_SERVICE_HEADERS} from '#/state/queries/messages/const' 36 36 37 - // TODO temporary 38 - let DEBUG_ACTIVE_CHAT: string | undefined 39 - 40 37 export function isConvoItemMessage( 41 38 item: ConvoItem, 42 39 ): item is ConvoItem & {type: 'message'} { ··· 102 99 this.ingestFirehose = this.ingestFirehose.bind(this) 103 100 this.onFirehoseConnect = this.onFirehoseConnect.bind(this) 104 101 this.onFirehoseError = this.onFirehoseError.bind(this) 105 - 106 - if (DEBUG_ACTIVE_CHAT) { 107 - logger.error(`Convo: another chat was already active`, { 108 - convoId: this.convoId, 109 - }) 110 - } else { 111 - DEBUG_ACTIVE_CHAT = this.convoId 112 - } 113 102 } 114 103 115 104 private commit() { ··· 494 483 495 484 suspend() { 496 485 this.dispatch({event: ConvoDispatchEvent.Suspend}) 497 - DEBUG_ACTIVE_CHAT = undefined 498 486 } 499 487 500 488 /** ··· 601 589 try { 602 590 this.isFetchingHistory = true 603 591 this.commit() 604 - 605 - /* 606 - * Delay if paginating while scrolled to prevent momentum scrolling from 607 - * jerking the list around, plus makes it feel a little more human. 608 - */ 609 - if (this.pastMessages.size > 0) { 610 - await new Promise(y => setTimeout(y, 500)) 611 - // throw new Error('UNCOMMENT TO TEST RETRY') 612 - } 613 592 614 593 const nextCursor = this.oldestRev // for TS 615 594 const response = await networkRetry(2, () => { ··· 679 658 } 680 659 } 681 660 }, 661 + /* 662 + * This is VERY important — we only want events for this convo. 663 + */ 682 664 {convoId: this.convoId}, 683 665 ) 684 666 } ··· 725 707 */ 726 708 this.latestRev = ev.rev 727 709 728 - /* 729 - * This is VERY important. We don't want to insert any messages from 730 - * your other chats. 731 - */ 732 - if (ev.convoId !== this.convoId) continue 733 - 734 710 if ( 735 711 ChatBskyConvoDefs.isLogCreateMessage(ev) && 736 712 ChatBskyConvoDefs.isMessageView(ev.message) ··· 775 751 776 752 private pendingMessageFailure: 'recoverable' | 'unrecoverable' | null = null 777 753 778 - async sendMessage(message: ChatBskyConvoSendMessage.InputSchema['message']) { 754 + sendMessage(message: ChatBskyConvoSendMessage.InputSchema['message']) { 779 755 // Ignore empty messages for now since they have no other purpose atm 780 756 if (!message.text.trim()) return 781 757 ··· 828 804 }) 829 805 const res = response.data 830 806 807 + // remove from queue 808 + this.pendingMessages.delete(id) 809 + 831 810 /* 832 811 * Insert into `newMessages` as soon as we have a real ID. That way, when 833 812 * we get an event log back, we can replace in situ. ··· 836 815 ...res, 837 816 $type: 'chat.bsky.convo.defs#messageView', 838 817 }) 839 - this.pendingMessages.delete(id) 818 + // render new message state, prior to firehose 819 + this.commit() 840 820 821 + // continue queue processing 841 822 await this.processPendingMessages() 842 - 843 - this.commit() 844 823 } catch (e: any) { 845 824 logger.error(e, {context: `Convo: failed to send message`}) 846 825 this.handleSendMessageFailure(e) 847 - } finally { 848 826 this.isProcessingPendingMessages = false 849 827 } 850 828 }
+1 -1
src/state/messages/convo/types.ts
··· 124 124 type DeleteMessage = (messageId: string) => Promise<void> 125 125 type SendMessage = ( 126 126 message: ChatBskyConvoSendMessage.InputSchema['message'], 127 - ) => Promise<void> 127 + ) => void 128 128 type FetchMessageHistory = () => Promise<void> 129 129 130 130 export type ConvoStateUninitialized = {