feat: add signal for starting history archive downloads

This commit is contained in:
Pascal Precht 2022-12-01 15:02:17 +01:00 committed by r4bbit.eth
parent 6e96586bdb
commit 194f26f3b4
5 changed files with 30 additions and 1 deletions

View File

@ -135,6 +135,7 @@ type Subscription struct {
HistoryArchivesSeedingSignal *signal.HistoryArchivesSeedingSignal HistoryArchivesSeedingSignal *signal.HistoryArchivesSeedingSignal
HistoryArchivesUnseededSignal *signal.HistoryArchivesUnseededSignal HistoryArchivesUnseededSignal *signal.HistoryArchivesUnseededSignal
HistoryArchiveDownloadedSignal *signal.HistoryArchiveDownloadedSignal HistoryArchiveDownloadedSignal *signal.HistoryArchiveDownloadedSignal
DownloadingHistoryArchivesStartedSignal *signal.DownloadingHistoryArchivesStartedSignal
DownloadingHistoryArchivesFinishedSignal *signal.DownloadingHistoryArchivesFinishedSignal DownloadingHistoryArchivesFinishedSignal *signal.DownloadingHistoryArchivesFinishedSignal
} }
@ -2107,6 +2108,12 @@ func (m *Manager) DownloadHistoryArchivesByMagnetlink(communityID types.HexBytes
sort.Sort(sort.Reverse(archiveHashes)) sort.Sort(sort.Reverse(archiveHashes))
m.publish(&Subscription{
DownloadingHistoryArchivesStartedSignal: &signal.DownloadingHistoryArchivesStartedSignal{
CommunityID: communityID.String(),
},
})
for _, hd := range archiveHashes { for _, hd := range archiveHashes {
hash := hd.hash hash := hd.hash
metadata := index.Archives[hash] metadata := index.Archives[hash]

View File

@ -140,7 +140,11 @@ func (m *Messenger) handleCommunitiesHistoryArchivesSubscription(c chan *communi
} }
if sub.DownloadingHistoryArchivesFinishedSignal != nil { 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: case <-m.quit:
return return

View File

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

View File

@ -112,6 +112,10 @@ func (m *MessengerSignalsHandler) HistoryArchiveDownloaded(communityID string, f
signal.SendHistoryArchiveDownloaded(communityID, from, to) signal.SendHistoryArchiveDownloaded(communityID, from, to)
} }
func (m *MessengerSignalsHandler) DownloadingHistoryArchivesStarted(communityID string) {
signal.SendDownloadingHistoryArchivesStarted(communityID)
}
func (m *MessengerSignalsHandler) DownloadingHistoryArchivesFinished(communityID string) { func (m *MessengerSignalsHandler) DownloadingHistoryArchivesFinished(communityID string) {
signal.SendDownloadingHistoryArchivesFinished(communityID) signal.SendDownloadingHistoryArchivesFinished(communityID)
} }

View File

@ -24,6 +24,9 @@ const (
// EventHistoryArchivesUnseeded is triggered when the community owner node // EventHistoryArchivesUnseeded is triggered when the community owner node
// drops a torrent for a particular community // drops a torrent for a particular community
EventHistoryArchivesUnseeded = "community.historyArchivesUnseeded" 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 // EventHistoryArchiveDownloaded is triggered when the community member node
// has downloaded an individual community archive // has downloaded an individual community archive
EventHistoryArchiveDownloaded = "community.historyArchiveDownloaded" EventHistoryArchiveDownloaded = "community.historyArchiveDownloaded"
@ -62,6 +65,10 @@ type HistoryArchiveDownloadedSignal struct {
To int `json:"to"` To int `json:"to"`
} }
type DownloadingHistoryArchivesStartedSignal struct {
CommunityID string `json:"communityId"`
}
type DownloadingHistoryArchivesFinishedSignal struct { type DownloadingHistoryArchivesFinishedSignal struct {
CommunityID string `json:"communityId"` 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) { func SendDownloadingHistoryArchivesFinished(communityID string) {
send(EventDownloadingHistoryArchivesFinished, DownloadingHistoryArchivesFinishedSignal{ send(EventDownloadingHistoryArchivesFinished, DownloadingHistoryArchivesFinishedSignal{
CommunityID: communityID, CommunityID: communityID,