From 194f26f3b4503494702be4e8148a166f61730c4d Mon Sep 17 00:00:00 2001 From: Pascal Precht <445106+PascalPrecht@users.noreply.github.com> Date: Thu, 1 Dec 2022 15:02:17 +0100 Subject: [PATCH] feat: add signal for starting history archive downloads --- protocol/communities/manager.go | 7 +++++++ protocol/messenger_communities.go | 6 +++++- protocol/messenger_config.go | 1 + services/ext/signal.go | 4 ++++ signal/events_community_archives.go | 13 +++++++++++++ 5 files changed, 30 insertions(+), 1 deletion(-) diff --git a/protocol/communities/manager.go b/protocol/communities/manager.go index 35a2d652e..45617d3b5 100644 --- a/protocol/communities/manager.go +++ b/protocol/communities/manager.go @@ -135,6 +135,7 @@ type Subscription struct { HistoryArchivesSeedingSignal *signal.HistoryArchivesSeedingSignal HistoryArchivesUnseededSignal *signal.HistoryArchivesUnseededSignal HistoryArchiveDownloadedSignal *signal.HistoryArchiveDownloadedSignal + DownloadingHistoryArchivesStartedSignal *signal.DownloadingHistoryArchivesStartedSignal DownloadingHistoryArchivesFinishedSignal *signal.DownloadingHistoryArchivesFinishedSignal } @@ -2107,6 +2108,12 @@ func (m *Manager) DownloadHistoryArchivesByMagnetlink(communityID types.HexBytes sort.Sort(sort.Reverse(archiveHashes)) + m.publish(&Subscription{ + DownloadingHistoryArchivesStartedSignal: &signal.DownloadingHistoryArchivesStartedSignal{ + CommunityID: communityID.String(), + }, + }) + for _, hd := range archiveHashes { hash := hd.hash metadata := index.Archives[hash] diff --git a/protocol/messenger_communities.go b/protocol/messenger_communities.go index 48aecd4a5..871d777eb 100644 --- a/protocol/messenger_communities.go +++ b/protocol/messenger_communities.go @@ -140,7 +140,11 @@ func (m *Messenger) handleCommunitiesHistoryArchivesSubscription(c chan *communi } if sub.DownloadingHistoryArchivesFinishedSignal != nil { - m.config.messengerSignalsHandler.DownloadingHistoryArchivesFinished(sub.HistoryArchiveDownloadedSignal.CommunityID) + m.config.messengerSignalsHandler.DownloadingHistoryArchivesFinished(sub.DownloadingHistoryArchivesFinishedSignal.CommunityID) + } + + if sub.DownloadingHistoryArchivesStartedSignal != nil { + m.config.messengerSignalsHandler.DownloadingHistoryArchivesStarted(sub.DownloadingHistoryArchivesStartedSignal.CommunityID) } case <-m.quit: return diff --git a/protocol/messenger_config.go b/protocol/messenger_config.go index 43e84bef8..222b88c55 100644 --- a/protocol/messenger_config.go +++ b/protocol/messenger_config.go @@ -44,6 +44,7 @@ type MessengerSignalsHandler interface { HistoryArchivesSeeding(communityID string) HistoryArchivesUnseeded(communityID string) HistoryArchiveDownloaded(communityID string, from int, to int) + DownloadingHistoryArchivesStarted(communityID string) DownloadingHistoryArchivesFinished(communityID string) StatusUpdatesTimedOut(statusUpdates *[]UserStatus) DiscordCategoriesAndChannelsExtracted(categories []*discord.Category, channels []*discord.Channel, oldestMessageTimestamp int64, errors map[string]*discord.ImportError) diff --git a/services/ext/signal.go b/services/ext/signal.go index 02399df1d..b04d6b1bf 100644 --- a/services/ext/signal.go +++ b/services/ext/signal.go @@ -112,6 +112,10 @@ func (m *MessengerSignalsHandler) HistoryArchiveDownloaded(communityID string, f signal.SendHistoryArchiveDownloaded(communityID, from, to) } +func (m *MessengerSignalsHandler) DownloadingHistoryArchivesStarted(communityID string) { + signal.SendDownloadingHistoryArchivesStarted(communityID) +} + func (m *MessengerSignalsHandler) DownloadingHistoryArchivesFinished(communityID string) { signal.SendDownloadingHistoryArchivesFinished(communityID) } diff --git a/signal/events_community_archives.go b/signal/events_community_archives.go index e05eaf450..7234643ea 100644 --- a/signal/events_community_archives.go +++ b/signal/events_community_archives.go @@ -24,6 +24,9 @@ const ( // EventHistoryArchivesUnseeded is triggered when the community owner node // drops a torrent for a particular community EventHistoryArchivesUnseeded = "community.historyArchivesUnseeded" + // EventDownloadingHistoryArchivesFinished is triggered when the community member node + // has downloaded all archives + EventDownloadingHistoryArchivesStarted = "community.downloadingHistoryArchivesStarted" // EventHistoryArchiveDownloaded is triggered when the community member node // has downloaded an individual community archive EventHistoryArchiveDownloaded = "community.historyArchiveDownloaded" @@ -62,6 +65,10 @@ type HistoryArchiveDownloadedSignal struct { To int `json:"to"` } +type DownloadingHistoryArchivesStartedSignal struct { + CommunityID string `json:"communityId"` +} + type DownloadingHistoryArchivesFinishedSignal struct { CommunityID string `json:"communityId"` } @@ -110,6 +117,12 @@ func SendHistoryArchiveDownloaded(communityID string, from int, to int) { }) } +func SendDownloadingHistoryArchivesStarted(communityID string) { + send(EventDownloadingHistoryArchivesStarted, DownloadingHistoryArchivesStartedSignal{ + CommunityID: communityID, + }) +} + func SendDownloadingHistoryArchivesFinished(communityID string) { send(EventDownloadingHistoryArchivesFinished, DownloadingHistoryArchivesFinishedSignal{ CommunityID: communityID,