forked from MirrorHub/mautrix-whatsapp
media backfill: enable enqueue to media backfill buffer instead of immediately requesting retry receipt
This commit is contained in:
parent
b5551ee16a
commit
7de7fedc02
1 changed files with 15 additions and 10 deletions
|
@ -519,22 +519,27 @@ func (portal *Portal) backfill(source *User, messages []*waProto.WebMessageInfo,
|
|||
portal.finishBatch(resp.EventIDs, infos)
|
||||
portal.NextBatchID = resp.NextBatchID
|
||||
portal.Update()
|
||||
if portal.bridge.Config.Bridge.HistorySync.MediaRequests.AutoRequestMedia &&
|
||||
portal.bridge.Config.Bridge.HistorySync.MediaRequests.RequestMethod == config.MediaRequestMethodImmediate {
|
||||
go portal.requestMediaRetries(source, infos)
|
||||
if portal.bridge.Config.Bridge.HistorySync.MediaRequests.AutoRequestMedia {
|
||||
go portal.requestMediaRetries(source, resp.EventIDs, infos)
|
||||
}
|
||||
return resp
|
||||
}
|
||||
}
|
||||
|
||||
func (portal *Portal) requestMediaRetries(source *User, infos []*wrappedInfo) {
|
||||
for _, info := range infos {
|
||||
func (portal *Portal) requestMediaRetries(source *User, eventIDs []id.EventID, infos []*wrappedInfo) {
|
||||
for i, info := range infos {
|
||||
if info != nil && info.Error == database.MsgErrMediaNotFound && info.MediaKey != nil {
|
||||
err := source.Client.SendMediaRetryReceipt(info.MessageInfo, info.MediaKey)
|
||||
if err != nil {
|
||||
portal.log.Warnfln("Failed to send post-backfill media retry request for %s: %v", info.ID, err)
|
||||
} else {
|
||||
portal.log.Debugfln("Sent post-backfill media retry request for %s", info.ID)
|
||||
switch portal.bridge.Config.Bridge.HistorySync.MediaRequests.RequestMethod {
|
||||
case config.MediaRequestMethodImmediate:
|
||||
err := source.Client.SendMediaRetryReceipt(info.MessageInfo, info.MediaKey)
|
||||
if err != nil {
|
||||
portal.log.Warnfln("Failed to send post-backfill media retry request for %s: %v", info.ID, err)
|
||||
} else {
|
||||
portal.log.Debugfln("Sent post-backfill media retry request for %s", info.ID)
|
||||
}
|
||||
case config.MediaRequestMethodLocalTime:
|
||||
req := portal.bridge.DB.MediaBackfillRequest.NewMediaBackfillRequestWithValues(source.MXID, &portal.Key, eventIDs[i])
|
||||
req.Upsert()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue