From 467c65a4a828968a19016a96cb4fb81e7ee9d7f8 Mon Sep 17 00:00:00 2001 From: Eric Bailey Date: Sun, 19 May 2024 17:12:06 -0500 Subject: [PATCH 1/4] Move comment, remove unused code --- src/state/messages/convo/agent.ts | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/src/state/messages/convo/agent.ts b/src/state/messages/convo/agent.ts index 0a75401c2e..79cc23ee40 100644 --- a/src/state/messages/convo/agent.ts +++ b/src/state/messages/convo/agent.ts @@ -679,6 +679,9 @@ export class Convo { } } }, + /* + * This is VERY important — we only want events for this convo. + */ {convoId: this.convoId}, ) } @@ -725,12 +728,6 @@ export class Convo { */ this.latestRev = ev.rev - /* - * This is VERY important. We don't want to insert any messages from - * your other chats. - */ - if (ev.convoId !== this.convoId) continue - if ( ChatBskyConvoDefs.isLogCreateMessage(ev) && ChatBskyConvoDefs.isMessageView(ev.message) From eb4a5d5816e9da07ddfddf501c6403a19e1153dd Mon Sep 17 00:00:00 2001 From: Eric Bailey Date: Sun, 19 May 2024 18:06:31 -0500 Subject: [PATCH 2/4] Clean up sending --- src/state/messages/convo/agent.ts | 12 +++++++----- src/state/messages/convo/types.ts | 2 +- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/state/messages/convo/agent.ts b/src/state/messages/convo/agent.ts index 79cc23ee40..70a03a3f41 100644 --- a/src/state/messages/convo/agent.ts +++ b/src/state/messages/convo/agent.ts @@ -772,7 +772,7 @@ export class Convo { private pendingMessageFailure: 'recoverable' | 'unrecoverable' | null = null - async sendMessage(message: ChatBskyConvoSendMessage.InputSchema['message']) { + sendMessage(message: ChatBskyConvoSendMessage.InputSchema['message']) { // Ignore empty messages for now since they have no other purpose atm if (!message.text.trim()) return @@ -825,6 +825,9 @@ export class Convo { }) const res = response.data + // remove from queue + this.pendingMessages.delete(id) + /* * Insert into `newMessages` as soon as we have a real ID. That way, when * we get an event log back, we can replace in situ. @@ -833,15 +836,14 @@ export class Convo { ...res, $type: 'chat.bsky.convo.defs#messageView', }) - this.pendingMessages.delete(id) + // render new message state, prior to firehose + this.commit() + // continue queue processing await this.processPendingMessages() - - this.commit() } catch (e: any) { logger.error(e, {context: `Convo: failed to send message`}) this.handleSendMessageFailure(e) - } finally { this.isProcessingPendingMessages = false } } diff --git a/src/state/messages/convo/types.ts b/src/state/messages/convo/types.ts index 6197a3b424..53e205e211 100644 --- a/src/state/messages/convo/types.ts +++ b/src/state/messages/convo/types.ts @@ -124,7 +124,7 @@ export type ConvoItem = type DeleteMessage = (messageId: string) => Promise type SendMessage = ( message: ChatBskyConvoSendMessage.InputSchema['message'], -) => Promise +) => void type FetchMessageHistory = () => Promise export type ConvoStateUninitialized = { From 464f83caeb846b8c55a0153496f7e156a88cc8bb Mon Sep 17 00:00:00 2001 From: Eric Bailey Date: Sun, 19 May 2024 18:16:37 -0500 Subject: [PATCH 3/4] Remove temp hack --- src/state/messages/convo/agent.ts | 9 --------- 1 file changed, 9 deletions(-) diff --git a/src/state/messages/convo/agent.ts b/src/state/messages/convo/agent.ts index 70a03a3f41..df1d9b5ec6 100644 --- a/src/state/messages/convo/agent.ts +++ b/src/state/messages/convo/agent.ts @@ -602,15 +602,6 @@ export class Convo { this.isFetchingHistory = true this.commit() - /* - * Delay if paginating while scrolled to prevent momentum scrolling from - * jerking the list around, plus makes it feel a little more human. - */ - if (this.pastMessages.size > 0) { - await new Promise(y => setTimeout(y, 500)) - // throw new Error('UNCOMMENT TO TEST RETRY') - } - const nextCursor = this.oldestRev // for TS const response = await networkRetry(2, () => { return this.agent.api.chat.bsky.convo.getMessages( From 4fadea6cd8281890586a1c999a66a7d56300a432 Mon Sep 17 00:00:00 2001 From: Eric Bailey Date: Sun, 19 May 2024 18:18:10 -0500 Subject: [PATCH 4/4] Remove debug --- src/state/messages/convo/agent.ts | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/src/state/messages/convo/agent.ts b/src/state/messages/convo/agent.ts index df1d9b5ec6..4418eaae77 100644 --- a/src/state/messages/convo/agent.ts +++ b/src/state/messages/convo/agent.ts @@ -34,9 +34,6 @@ import {MessagesEventBus} from '#/state/messages/events/agent' import {MessagesEventBusError} from '#/state/messages/events/types' import {DM_SERVICE_HEADERS} from '#/state/queries/messages/const' -// TODO temporary -let DEBUG_ACTIVE_CHAT: string | undefined - export function isConvoItemMessage( item: ConvoItem, ): item is ConvoItem & {type: 'message'} { @@ -102,14 +99,6 @@ export class Convo { this.ingestFirehose = this.ingestFirehose.bind(this) this.onFirehoseConnect = this.onFirehoseConnect.bind(this) this.onFirehoseError = this.onFirehoseError.bind(this) - - if (DEBUG_ACTIVE_CHAT) { - logger.error(`Convo: another chat was already active`, { - convoId: this.convoId, - }) - } else { - DEBUG_ACTIVE_CHAT = this.convoId - } } private commit() { @@ -494,7 +483,6 @@ export class Convo { suspend() { this.dispatch({event: ConvoDispatchEvent.Suspend}) - DEBUG_ACTIVE_CHAT = undefined } /**