From 0444e69c35ba77c551c3a54b702e7b1baad5b4a2 Mon Sep 17 00:00:00 2001 From: Eric Bailey Date: Thu, 16 May 2024 19:51:26 -0500 Subject: [PATCH] Revert "Aggregate quickly-sent messages into batches (#4061)" (#4069) This reverts commit d424945eed752a366ac201470fdbb66d02999c86. --- src/state/messages/convo/agent.ts | 40 +++++++++++++------------------ 1 file changed, 17 insertions(+), 23 deletions(-) diff --git a/src/state/messages/convo/agent.ts b/src/state/messages/convo/agent.ts index 8f520bc9..8673c70a 100644 --- a/src/state/messages/convo/agent.ts +++ b/src/state/messages/convo/agent.ts @@ -766,12 +766,12 @@ export class Convo { logger.DebugContext.convo, ) - const pendingMessages = Array.from(this.pendingMessages.values()) + const pendingMessage = Array.from(this.pendingMessages.values()).shift() /* * If there are no pending messages, we're done. */ - if (pendingMessages.length === 0) { + if (!pendingMessage) { this.isProcessingPendingMessages = false return } @@ -779,34 +779,28 @@ export class Convo { try { this.isProcessingPendingMessages = true + const {id, message} = pendingMessage + const response = await networkRetry(2, () => { - return this.agent.api.chat.bsky.convo.sendMessageBatch( + return this.agent.api.chat.bsky.convo.sendMessage( { - items: pendingMessages.map(({message}) => ({ - convoId: this.convoId, - message, - })), + convoId: this.convoId, + message, }, {encoding: 'application/json', headers: DM_SERVICE_HEADERS}, ) }) + const res = response.data - const {items} = response.data - - for (let i = 0; i < items.length; i++) { - const msg = items[i] - const tempId = pendingMessages[i].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. - */ - this.newMessages.set(msg.id, { - ...msg, - $type: 'chat.bsky.convo.defs#messageView', - }) - this.pendingMessages.delete(tempId) - } + /* + * 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. + */ + this.newMessages.set(res.id, { + ...res, + $type: 'chat.bsky.convo.defs#messageView', + }) + this.pendingMessages.delete(id) await this.processPendingMessages()