feat: add signal indicating that history messages are being imported

In order to give clients more insights about archive messages being
processed, we're adding this additional signal that informs clients when
the import of downloaded history archive messages has started.
This commit is contained in:
Pascal Precht 2022-12-02 13:45:41 +01:00 committed by r4bbit.eth
parent 684e9654de
commit 22b5690cda
6 changed files with 25 additions and 0 deletions

View File

@ -137,6 +137,7 @@ type Subscription struct {
HistoryArchiveDownloadedSignal *signal.HistoryArchiveDownloadedSignal
DownloadingHistoryArchivesStartedSignal *signal.DownloadingHistoryArchivesStartedSignal
DownloadingHistoryArchivesFinishedSignal *signal.DownloadingHistoryArchivesFinishedSignal
ImportingHistoryArchiveMessagesSignal *signal.ImportingHistoryArchiveMessagesSignal
}
type CommunityResponse struct {

View File

@ -146,6 +146,10 @@ func (m *Messenger) handleCommunitiesHistoryArchivesSubscription(c chan *communi
if sub.DownloadingHistoryArchivesStartedSignal != nil {
m.config.messengerSignalsHandler.DownloadingHistoryArchivesStarted(sub.DownloadingHistoryArchivesStartedSignal.CommunityID)
}
if sub.ImportingHistoryArchiveMessagesSignal != nil {
m.config.messengerSignalsHandler.ImportingHistoryArchiveMessages(sub.ImportingHistoryArchiveMessagesSignal.CommunityID)
}
case <-m.quit:
return
}

View File

@ -46,6 +46,7 @@ type MessengerSignalsHandler interface {
HistoryArchiveDownloaded(communityID string, from int, to int)
DownloadingHistoryArchivesStarted(communityID string)
DownloadingHistoryArchivesFinished(communityID string)
ImportingHistoryArchiveMessages(communityID string)
StatusUpdatesTimedOut(statusUpdates *[]UserStatus)
DiscordCategoriesAndChannelsExtracted(categories []*discord.Category, channels []*discord.Channel, oldestMessageTimestamp int64, errors map[string]*discord.ImportError)
DiscordCommunityImportProgress(importProgress *discord.ImportProgress)

View File

@ -963,6 +963,8 @@ func (m *Messenger) HandleHistoryArchiveMagnetlinkMessage(state *ReceivedMessage
}
}
m.config.messengerSignalsHandler.ImportingHistoryArchiveMessages(types.EncodeHex(id))
err = m.handleImportedMessages(importedMessages)
if err != nil {
log.Println("failed to handle imported messages", err)

View File

@ -116,6 +116,10 @@ func (m *MessengerSignalsHandler) DownloadingHistoryArchivesStarted(communityID
signal.SendDownloadingHistoryArchivesStarted(communityID)
}
func (m *MessengerSignalsHandler) ImportingHistoryArchiveMessages(communityID string) {
signal.SendImportingHistoryArchiveMessages(communityID)
}
func (m *MessengerSignalsHandler) DownloadingHistoryArchivesFinished(communityID string) {
signal.SendDownloadingHistoryArchivesFinished(communityID)
}

View File

@ -30,6 +30,9 @@ const (
// EventHistoryArchiveDownloaded is triggered when the community member node
// has downloaded an individual community archive
EventHistoryArchiveDownloaded = "community.historyArchiveDownloaded"
// EventImportingHistoryArchiveMessages is triggered when the community member node
// has starts importing downloaded archive messages into the database
EventImportingHistoryArchiveMessages = "community.importingHistoryArchiveMessages"
// EventDownloadingHistoryArchivesFinished is triggered when the community member node
// has downloaded all archives
EventDownloadingHistoryArchivesFinished = "community.downloadingHistoryArchivesFinished"
@ -69,6 +72,10 @@ type DownloadingHistoryArchivesStartedSignal struct {
CommunityID string `json:"communityId"`
}
type ImportingHistoryArchiveMessagesSignal struct {
CommunityID string `json:"communityId"`
}
type DownloadingHistoryArchivesFinishedSignal struct {
CommunityID string `json:"communityId"`
}
@ -123,6 +130,12 @@ func SendDownloadingHistoryArchivesStarted(communityID string) {
})
}
func SendImportingHistoryArchiveMessages(communityID string) {
send(EventImportingHistoryArchiveMessages, ImportingHistoryArchiveMessagesSignal{
CommunityID: communityID,
})
}
func SendDownloadingHistoryArchivesFinished(communityID string) {
send(EventDownloadingHistoryArchivesFinished, DownloadingHistoryArchivesFinishedSignal{
CommunityID: communityID,