config: add settings for automatic media requests

This commit is contained in:
Sumner Evans 2022-05-10 12:18:01 -06:00
parent feaaf51970
commit e362743f18
No known key found for this signature in database
GPG key ID: 8904527AB50022FD
5 changed files with 36 additions and 7 deletions

View file

@ -34,6 +34,13 @@ type DeferredConfig struct {
BatchDelay int `yaml:"batch_delay"`
}
type MediaRequestMethod string
const (
MediaRequestMethodImmediate MediaRequestMethod = "immediate"
MediaRequestMethodLocalTime = "local_time"
)
type BridgeConfig struct {
UsernameTemplate string `yaml:"username_template"`
DisplaynameTemplate string `yaml:"displayname_template"`
@ -51,7 +58,6 @@ type BridgeConfig struct {
DoublePuppetBackfill bool `yaml:"double_puppet_backfill"`
RequestFullSync bool `yaml:"request_full_sync"`
AutoRequestMedia bool `yaml:"auto_request_media"`
MaxInitialConversations int `yaml:"max_initial_conversations"`
Immediate struct {
@ -59,6 +65,12 @@ type BridgeConfig struct {
MaxEvents int `yaml:"max_events"`
} `yaml:"immediate"`
MediaRequests struct {
AutoRequestMedia bool `yaml:"auto_request_media"`
RequestMethod MediaRequestMethod `yaml:"request_method"`
RequestLocalTime int `yaml:"request_local_time"`
} `yaml:"media_requests"`
Deferred []DeferredConfig `yaml:"deferred"`
} `yaml:"history_sync"`
UserAvatarSync bool `yaml:"user_avatar_sync"`

View file

@ -81,7 +81,9 @@ func (helper *UpgradeHelper) doUpgrade() {
helper.Copy(Bool, "bridge", "history_sync", "backfill")
helper.Copy(Bool, "bridge", "history_sync", "double_puppet_backfill")
helper.Copy(Bool, "bridge", "history_sync", "request_full_sync")
helper.Copy(Bool, "bridge", "history_sync", "auto_request_media")
helper.Copy(Bool, "bridge", "history_sync", "media_requests", "auto_request_media")
helper.Copy(Str, "bridge", "history_sync", "media_requests", "request_method")
helper.Copy(Int, "bridge", "history_sync", "media_requests", "request_local_time")
helper.Copy(Int, "bridge", "history_sync", "max_initial_conversations")
helper.Copy(Int, "bridge", "history_sync", "immediate", "worker_count")
helper.Copy(Int, "bridge", "history_sync", "immediate", "max_events")

View file

@ -133,9 +133,22 @@ bridge:
# Should the bridge request a full sync from the phone when logging in?
# This bumps the size of history syncs from 3 months to 1 year.
request_full_sync: false
# Should expired media be automatically requested from the server after backfilling?
# If false, media can still be requested by reacting with the ♻️ (recycle) emoji.
auto_request_media: true
# Settings for media requests. If the media expired, then it will not
# be on the WA servers.
# Media can always be requested by reacting with the ♻️ (recycle) emoji.
# These settings determine if the media requests should be done
# automatically during or after backfill.
media_requests:
# Should expired media be automatically requested from the server as
# part of the backfill process?
auto_request_media: true
# Whether to request the media immediately after the media message
# is backfilled ("immediate") or at a specific time of the day
# ("local_time").
request_method: immediate
# If request_method is "local_time", what time should the requests
# be sent (in minutes after midnight)?
request_local_time: 120
# The maximum number of initial conversations that should be synced.
# Other conversations will be backfilled on demand when the start PM
# provisioning endpoint is used or when a message comes in from that

View file

@ -28,6 +28,7 @@ import (
"maunium.net/go/mautrix/event"
"maunium.net/go/mautrix/id"
"maunium.net/go/mautrix-whatsapp/config"
"maunium.net/go/mautrix-whatsapp/database"
)
@ -518,7 +519,8 @@ 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.AutoRequestMedia {
if portal.bridge.Config.Bridge.HistorySync.MediaRequests.AutoRequestMedia &&
portal.bridge.Config.Bridge.HistorySync.MediaRequests.RequestMethod == config.MediaRequestMethodImmediate {
go portal.requestMediaRetries(source, infos)
}
return resp

View file

@ -2178,7 +2178,7 @@ func (portal *Portal) convertMediaMessage(intent *appservice.IntentAPI, source *
converted.MediaKey = msg.GetMediaKey()
errorText := fmt.Sprintf("Old %s.", typeName)
if portal.bridge.Config.Bridge.HistorySync.AutoRequestMedia && isBackfill {
if portal.bridge.Config.Bridge.HistorySync.MediaRequests.AutoRequestMedia && isBackfill {
errorText += " Media will be automatically requested from your phone later."
} else {
errorText += ` React with the \u267b (recycle) emoji to request this media from your phone.`