From 7a0091bff2dd66eab6ed82336d9f8f523da2ef03 Mon Sep 17 00:00:00 2001 From: Tulir Asokan Date: Wed, 4 Jan 2023 22:37:25 +0200 Subject: [PATCH] Expose history sync config struct in bridge config --- config/bridge.go | 13 +++++++++---- config/upgrade.go | 3 +++ example-config.yaml | 10 ++++++++++ main.go | 7 +++++++ 4 files changed, 29 insertions(+), 4 deletions(-) diff --git a/config/bridge.go b/config/bridge.go index 1ece1ed..e463a3c 100644 --- a/config/bridge.go +++ b/config/bridge.go @@ -60,10 +60,15 @@ type BridgeConfig struct { CreatePortals bool `yaml:"create_portals"` Backfill bool `yaml:"backfill"` - DoublePuppetBackfill bool `yaml:"double_puppet_backfill"` - RequestFullSync bool `yaml:"request_full_sync"` - MaxInitialConversations int `yaml:"max_initial_conversations"` - UnreadHoursThreshold int `yaml:"unread_hours_threshold"` + DoublePuppetBackfill bool `yaml:"double_puppet_backfill"` + RequestFullSync bool `yaml:"request_full_sync"` + FullSyncConfig struct { + DaysLimit uint32 `yaml:"days_limit"` + SizeLimit uint32 `yaml:"size_mb_limit"` + StorageQuota uint32 `yaml:"storage_quota_mb"` + } + MaxInitialConversations int `yaml:"max_initial_conversations"` + UnreadHoursThreshold int `yaml:"unread_hours_threshold"` Immediate struct { WorkerCount int `yaml:"worker_count"` diff --git a/config/upgrade.go b/config/upgrade.go index a465cfa..1a7ac62 100644 --- a/config/upgrade.go +++ b/config/upgrade.go @@ -48,6 +48,9 @@ func DoUpgrade(helper *up.Helper) { helper.Copy(up.Bool, "bridge", "history_sync", "backfill") helper.Copy(up.Bool, "bridge", "history_sync", "double_puppet_backfill") helper.Copy(up.Bool, "bridge", "history_sync", "request_full_sync") + helper.Copy(up.Int|up.Null, "bridge", "history_sync", "full_sync_config", "days_limit") + helper.Copy(up.Int|up.Null, "bridge", "history_sync", "full_sync_config", "size_mb_limit") + helper.Copy(up.Int|up.Null, "bridge", "history_sync", "full_sync_config", "storage_quota_mb") helper.Copy(up.Bool, "bridge", "history_sync", "media_requests", "auto_request_media") helper.Copy(up.Str, "bridge", "history_sync", "media_requests", "request_method") helper.Copy(up.Int, "bridge", "history_sync", "media_requests", "request_local_time") diff --git a/example-config.yaml b/example-config.yaml index 80b53ac..a5b669d 100644 --- a/example-config.yaml +++ b/example-config.yaml @@ -134,6 +134,16 @@ 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 + # Configuration parameters that are sent to the phone along with the request full sync flag. + # By default (when the values are null or 0), the config isn't sent at all. + full_sync_config: + # Number of days of history to request. + # The limit seems to be around 3 years, but using higher values doesn't break. + days_limit: null + # This is presumably the maximum size of the transferred history sync blob, which may affect what the phone includes in the blob. + size_mb_limit: null + # This is presumably the local storage quota, which may affect what the phone includes in the history sync blob. + storage_quota_mb: null # 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. diff --git a/main.go b/main.go index e4d5a67..0564e46 100644 --- a/main.go +++ b/main.go @@ -114,6 +114,13 @@ func (br *WABridge) Init() { store.BaseClientPayload.UserAgent.OsBuildNumber = proto.String(br.WAVersion) store.DeviceProps.Os = proto.String(br.Config.WhatsApp.OSName) store.DeviceProps.RequireFullSync = proto.Bool(br.Config.Bridge.HistorySync.RequestFullSync) + if fsc := br.Config.Bridge.HistorySync.FullSyncConfig; fsc.DaysLimit > 0 && fsc.SizeLimit > 0 && fsc.StorageQuota > 0 { + store.DeviceProps.HistorySyncConfig = &waProto.DeviceProps_HistorySyncConfig{ + FullSyncDaysLimit: proto.Uint32(fsc.DaysLimit), + FullSyncSizeMbLimit: proto.Uint32(fsc.SizeLimit), + StorageQuotaMb: proto.Uint32(fsc.StorageQuota), + } + } versionParts := strings.Split(br.WAVersion, ".") if len(versionParts) > 2 { primary, _ := strconv.Atoi(versionParts[0])