From 1c42c077603dbd37cb10ebc5cccb755925fc812b Mon Sep 17 00:00:00 2001 From: Jonathan Rainville Date: Mon, 12 Feb 2024 16:04:12 -0500 Subject: [PATCH] feat(discord_import): send signal when the import was cleaned up (#4693) This is to let the front end know that the community was deleted so it can also delete it from the UI --- protocol/messenger_communities_import_discord.go | 1 + protocol/messenger_config.go | 1 + services/ext/signal.go | 4 ++++ signal/events_discord_import.go | 13 +++++++++++++ 4 files changed, 19 insertions(+) diff --git a/protocol/messenger_communities_import_discord.go b/protocol/messenger_communities_import_discord.go index d6baaf734..e34236d2b 100644 --- a/protocol/messenger_communities_import_discord.go +++ b/protocol/messenger_communities_import_discord.go @@ -382,6 +382,7 @@ func (m *Messenger) cleanUpImport(communityID string) { if deleteErr != nil { m.logger.Error("clean up failed, couldn't delete community messages", zap.Error(deleteErr)) } + m.config.messengerSignalsHandler.DiscordCommunityImportCleanedUp(communityID) } func (m *Messenger) cleanUpImportChannel(communityID string, channelID string) { diff --git a/protocol/messenger_config.go b/protocol/messenger_config.go index 6512ae39b..1388b6303 100644 --- a/protocol/messenger_config.go +++ b/protocol/messenger_config.go @@ -57,6 +57,7 @@ type MessengerSignalsHandler interface { DiscordCommunityImportProgress(importProgress *discord.ImportProgress) DiscordCommunityImportFinished(communityID string) DiscordCommunityImportCancelled(communityID string) + DiscordCommunityImportCleanedUp(communityID string) DiscordChannelImportProgress(importProgress *discord.ImportProgress) DiscordChannelImportFinished(communityID string, channelID string) DiscordChannelImportCancelled(channelID string) diff --git a/services/ext/signal.go b/services/ext/signal.go index 7ed07bc20..f7c62c6e6 100644 --- a/services/ext/signal.go +++ b/services/ext/signal.go @@ -153,6 +153,10 @@ func (m *MessengerSignalsHandler) DiscordCommunityImportCancelled(id string) { signal.SendDiscordCommunityImportCancelled(id) } +func (m *MessengerSignalsHandler) DiscordCommunityImportCleanedUp(id string) { + signal.SendDiscordCommunityImportCleanedUp(id) +} + func (m *MessengerSignalsHandler) DiscordChannelImportCancelled(id string) { signal.SendDiscordChannelImportCancelled(id) } diff --git a/signal/events_discord_import.go b/signal/events_discord_import.go index 3ad5b7dbd..60349b331 100644 --- a/signal/events_discord_import.go +++ b/signal/events_discord_import.go @@ -22,6 +22,9 @@ const ( // the discord community was cancelled EventDiscordCommunityImportCancelled = "community.discordCommunityImportCancelled" + // EventDiscordCommunityImportCleanedUp triggered when the community has been cleaned up (deleted) + EventDiscordCommunityImportCleanedUp = "community.discordCommunityImportCleanedUp" + // EventDiscordChannelImportProgress is triggered during the import // of a discord community channel as it progresses EventDiscordChannelImportProgress = "community.discordChannelImportProgress" @@ -54,6 +57,10 @@ type DiscordCommunityImportCancelledSignal struct { CommunityID string `json:"communityId"` } +type DiscordCommunityImportCleanedUpSignal struct { + CommunityID string `json:"communityId"` +} + type DiscordChannelImportProgressSignal struct { ImportProgress *discord.ImportProgress `json:"importProgress"` } @@ -107,6 +114,12 @@ func SendDiscordCommunityImportCancelled(communityID string) { }) } +func SendDiscordCommunityImportCleanedUp(communityID string) { + send(EventDiscordCommunityImportCleanedUp, DiscordCommunityImportCleanedUpSignal{ + CommunityID: communityID, + }) +} + func SendDiscordChannelImportCancelled(channelID string) { send(EventDiscordChannelImportCancelled, DiscordChannelImportCancelledSignal{ ChannelID: channelID,