From 7981a11bd9a1c9a9278fbcdab37b7af37f61761e Mon Sep 17 00:00:00 2001 From: Tulir Asokan Date: Wed, 19 Jul 2023 23:33:45 +0300 Subject: [PATCH] Make initial chat sync count configurable --- config/bridge.go | 3 ++- config/upgrade.go | 1 + example-config.yaml | 2 ++ libgm/methods.go | 4 ++-- user.go | 4 +++- 5 files changed, 10 insertions(+), 4 deletions(-) diff --git a/config/bridge.go b/config/bridge.go index 8826414..0ef86b6 100644 --- a/config/bridge.go +++ b/config/bridge.go @@ -36,7 +36,8 @@ type BridgeConfig struct { MessageErrorNotices bool `yaml:"message_error_notices"` PortalMessageBuffer int `yaml:"portal_message_buffer"` - SyncDirectChatList bool `yaml:"sync_direct_chat_list"` + SyncDirectChatList bool `yaml:"sync_direct_chat_list"` + InitialChatSyncCount int `yaml:"initial_chat_sync_count"` DoublePuppetServerMap map[string]string `yaml:"double_puppet_server_map"` DoublePuppetAllowDiscovery bool `yaml:"double_puppet_allow_discovery"` diff --git a/config/upgrade.go b/config/upgrade.go index 3c4c65d..b0b4163 100644 --- a/config/upgrade.go +++ b/config/upgrade.go @@ -43,6 +43,7 @@ func DoUpgrade(helper *up.Helper) { helper.Copy(up.Bool, "bridge", "message_error_notices") 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.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 8c1563d..b4945fe 100644 --- a/example-config.yaml +++ b/example-config.yaml @@ -124,6 +124,8 @@ bridge: # Note that updating the m.direct event is not atomic (except with mautrix-asmux) # and is therefore prone to race conditions. sync_direct_chat_list: false + # Number of chats to sync when connecting to Google Messages. + initial_chat_sync_count: 25 # Servers to always allow double puppeting from double_puppet_server_map: diff --git a/libgm/methods.go b/libgm/methods.go index 4ed00b1..a3fe6b5 100644 --- a/libgm/methods.go +++ b/libgm/methods.go @@ -4,7 +4,7 @@ import ( "go.mau.fi/mautrix-gmessages/libgm/gmproto" ) -func (c *Client) ListConversations(count int64, folder gmproto.ListConversationsRequest_Folder) (*gmproto.ListConversationsResponse, error) { +func (c *Client) ListConversations(count int, folder gmproto.ListConversationsRequest_Folder) (*gmproto.ListConversationsResponse, error) { msgType := gmproto.MessageType_BUGLE_MESSAGE if !c.conversationsFetchedOnce { msgType = gmproto.MessageType_BUGLE_ANNOTATION @@ -12,7 +12,7 @@ func (c *Client) ListConversations(count int64, folder gmproto.ListConversations } return typedResponse[*gmproto.ListConversationsResponse](c.sessionHandler.sendMessageWithParams(SendMessageParams{ Action: gmproto.ActionType_LIST_CONVERSATIONS, - Data: &gmproto.ListConversationsRequest{Count: count, Folder: folder}, + Data: &gmproto.ListConversationsRequest{Count: int64(count), Folder: folder}, MessageType: msgType, })) } diff --git a/user.go b/user.go index c30a70d..21bdc49 100644 --- a/user.go +++ b/user.go @@ -654,11 +654,13 @@ func (user *User) aggressiveSetActive() { } func (user *User) fetchAndSyncConversations() { - resp, err := user.Client.ListConversations(25, gmproto.ListConversationsRequest_INBOX) + user.zlog.Info().Msg("Fetching conversation list") + resp, err := user.Client.ListConversations(user.bridge.Config.Bridge.InitialChatSyncCount, gmproto.ListConversationsRequest_INBOX) if err != nil { user.zlog.Err(err).Msg("Failed to get conversation list") return } + user.zlog.Info().Int("count", len(resp.GetConversations())).Msg("Syncing conversations") for _, conv := range resp.GetConversations() { user.syncConversation(conv) }