Skip to content

Commit

Permalink
Merge pull request #154 from TogetherCrew/145-announcement-feautre
Browse files Browse the repository at this point in the history
[FEATURE]: add saga next to handleSendMessageToChannel
  • Loading branch information
Behzad-rabiei authored Jan 18, 2024
2 parents b5c0301 + 65f78fb commit 19194c3
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
2 changes: 0 additions & 2 deletions src/rabbitmq/events/sendMessageEvent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,10 @@ export async function handleSendMessageEvent(msg: any) {

const { content } = msg;
const saga = await MBConnection.models.Saga.findOne({ sagaId: content.uuid });

const platformId = saga.data['platformId'];
const platform = await platformService.getPlatform({ _id: platformId }); const discordId = saga.data['discordId'];
const message = saga.data['message'];
const useFallback = saga.data['useFallback'];

if (platform) {
await saga.next(() => notifyUserAboutAnalysisFinish(discordId, { guildId: platform.metadata?.id, message, useFallback }));
}
Expand Down
9 changes: 5 additions & 4 deletions src/rabbitmq/events/sendMessageToChannel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,14 @@ export async function handleSendMessageToChannel(msg: any) {

const { content } = msg;
const saga = await MBConnection.models.Saga.findOne({ sagaId: content.uuid });

const channels = saga.data['channels'];
const message = saga.data['message'];

for (let i = 0; i < channels.length; i++) {
await channelService.sendChannelMessage(channels[i], message)
}
await saga.next(async () => {
for await (const channel of channels) {
await channelService.sendChannelMessage(channel, message)
}
});

logger.info({ msg, event: Event.DISCORD_BOT.SEND_MESSAGE_TO_CHANNEL }, 'is done');
} catch (error) {
Expand Down

0 comments on commit 19194c3

Please sign in to comment.