From c497b552942450aca3de315f84c207f280a98467 Mon Sep 17 00:00:00 2001 From: Ladd Hoffman Date: Sat, 27 Apr 2024 13:49:27 -0500 Subject: [PATCH] consolidate more into outbound queue --- backend/src/contract-listeners/proposals.js | 4 +++- backend/src/matrix-bot/index.js | 7 +------ backend/src/matrix-bot/outbound-queue.js | 5 +++++ 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/backend/src/contract-listeners/proposals.js b/backend/src/contract-listeners/proposals.js index 20a819a..eb40972 100644 --- a/backend/src/contract-listeners/proposals.js +++ b/backend/src/contract-listeners/proposals.js @@ -1,6 +1,6 @@ const { proposals } = require('../util/contracts'); const read = require('../api/read'); -const { sendNewProposalEvent } = require('../matrix-bot'); +const { sendNewProposalEvent } = require('../matrix-bot/outbound-queue'); // Subscribe to proposal events const start = () => { @@ -19,6 +19,8 @@ const start = () => { if (post.embeddedData && Object.entries(post.embeddedData).length) { message += `\n\n${JSON.stringify(post.embeddedData, null, 2)}`; } + + // The outbound queue handles deduplication sendNewProposalEvent(proposalIndex, message); }); }; diff --git a/backend/src/matrix-bot/index.js b/backend/src/matrix-bot/index.js index 3765ef5..3da0416 100644 --- a/backend/src/matrix-bot/index.js +++ b/backend/src/matrix-bot/index.js @@ -20,7 +20,7 @@ const cryptoProvider = new RustSdkCryptoStorageProvider(BOT_CRYPTO_STORAGE_PATH) let client; let joinedRooms; -const { outboundQueue, startOutboundQueue } = require('./outbound-queue'); +const { startOutboundQueue } = require('./outbound-queue'); const start = async () => { console.log('MATRIX_HOMESERVER_URL:', MATRIX_HOMESERVER_URL); @@ -50,11 +50,6 @@ const start = async () => { }); }; -const sendNewProposalEvent = (proposalIndex, text) => { - outboundQueue.push({ type: 'NewProposal', proposalIndex, text }); -}; - module.exports = { start, - sendNewProposalEvent, }; diff --git a/backend/src/matrix-bot/outbound-queue.js b/backend/src/matrix-bot/outbound-queue.js index 16646e8..f3885c0 100644 --- a/backend/src/matrix-bot/outbound-queue.js +++ b/backend/src/matrix-bot/outbound-queue.js @@ -42,8 +42,13 @@ const startOutboundQueue = (c) => { outboundQueue.resume(); }; +const sendNewProposalEvent = (proposalIndex, text) => { + outboundQueue.push({ type: 'NewProposal', proposalIndex, text }); +}; + module.exports = { setTargetRoomId, outboundQueue, startOutboundQueue, + sendNewProposalEvent, };