Prechádzať zdrojové kódy

Expose history sync config struct in bridge config

Tulir Asokan 2 rokov pred
rodič
commit
7a0091bff2
4 zmenil súbory, kde vykonal 29 pridanie a 4 odobranie
  1. 9 4
      config/bridge.go
  2. 3 0
      config/upgrade.go
  3. 10 0
      example-config.yaml
  4. 7 0
      main.go

+ 9 - 4
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"`

+ 3 - 0
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")

+ 10 - 0
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.

+ 7 - 0
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])