diff --git a/backfill.go b/backfill.go index 962de1d..cebc8d7 100644 --- a/backfill.go +++ b/backfill.go @@ -40,10 +40,14 @@ func (portal *Portal) initialForwardBackfill(user *User, markRead bool) { Logger() ctx := log.WithContext(context.TODO()) - portal.forwardBackfill(ctx, user, time.Time{}, 50, markRead) + portal.forwardBackfill(ctx, user, time.Time{}, portal.bridge.Config.Bridge.Backfill.InitialLimit, markRead) } func (portal *Portal) missedForwardBackfill(user *User, lastMessageTS time.Time, lastMessageID string, markRead bool) bool { + if portal.bridge.Config.Bridge.Backfill.MissedLimit == 0 { + return false + } + portal.forwardBackfillLock.Lock() defer portal.forwardBackfillLock.Unlock() log := portal.zlog.With(). @@ -76,7 +80,7 @@ func (portal *Portal) missedForwardBackfill(user *User, lastMessageTS time.Time, Str("latest_message_id", lastMessageID). Time("last_bridged_ts", portal.lastMessageTS). Msg("Backfilling missed messages") - return portal.forwardBackfill(ctx, user, portal.lastMessageTS, 100, markRead) + return portal.forwardBackfill(ctx, user, portal.lastMessageTS, portal.bridge.Config.Bridge.Backfill.MissedLimit, markRead) } func (portal *Portal) deterministicEventID(messageID string, part int) id.EventID { @@ -85,9 +89,13 @@ func (portal *Portal) deterministicEventID(messageID string, part int) id.EventI return id.EventID(fmt.Sprintf("$%s:messages.google.com", base64.RawURLEncoding.EncodeToString(sum[:]))) } -func (portal *Portal) forwardBackfill(ctx context.Context, user *User, after time.Time, limit int64, markRead bool) bool { +func (portal *Portal) forwardBackfill(ctx context.Context, user *User, after time.Time, limit int, markRead bool) bool { + if limit == 0 { + return false + } + log := zerolog.Ctx(ctx) - resp, err := user.Client.FetchMessages(portal.ID, limit, nil) + resp, err := user.Client.FetchMessages(portal.ID, int64(limit), nil) if err != nil { portal.zlog.Error().Err(err).Msg("Failed to fetch messages") return false diff --git a/config/bridge.go b/config/bridge.go index 0ef86b6..35da73e 100644 --- a/config/bridge.go +++ b/config/bridge.go @@ -39,6 +39,11 @@ type BridgeConfig struct { SyncDirectChatList bool `yaml:"sync_direct_chat_list"` InitialChatSyncCount int `yaml:"initial_chat_sync_count"` + Backfill struct { + InitialLimit int `yaml:"initial_limit"` + MissedLimit int `yaml:"missed_limit"` + } `yaml:"backfill"` + DoublePuppetServerMap map[string]string `yaml:"double_puppet_server_map"` DoublePuppetAllowDiscovery bool `yaml:"double_puppet_allow_discovery"` LoginSharedSecretMap map[string]string `yaml:"login_shared_secret_map"` diff --git a/config/upgrade.go b/config/upgrade.go index b0b4163..4a9dfe1 100644 --- a/config/upgrade.go +++ b/config/upgrade.go @@ -44,6 +44,8 @@ func DoUpgrade(helper *up.Helper) { helper.Copy(up.Int, "bridge", "portal_message_buffer") helper.Copy(up.Bool, "bridge", "sync_direct_chat_list") helper.Copy(up.Int, "bridge", "initial_chat_sync_count") + helper.Copy(up.Int, "bridge", "backfill", "initial_limit") + helper.Copy(up.Int, "bridge", "backfill", "missed_limit") helper.Copy(up.Map, "bridge", "double_puppet_server_map") helper.Copy(up.Bool, "bridge", "double_puppet_allow_discovery") helper.Copy(up.Map, "bridge", "login_shared_secret_map") diff --git a/example-config.yaml b/example-config.yaml index b4945fe..77f8d57 100644 --- a/example-config.yaml +++ b/example-config.yaml @@ -126,6 +126,12 @@ bridge: sync_direct_chat_list: false # Number of chats to sync when connecting to Google Messages. initial_chat_sync_count: 25 + # Backfill settings + backfill: + # Number of messages to backfill in new chats. + initial_limit: 50 + # Number of messages to backfill on startup if the last message ID in the chat sync doesn't match the last bridged message. + missed_limit: 100 # Servers to always allow double puppeting from double_puppet_server_map: