Make initial chat sync count configurable

This commit is contained in:
Tulir Asokan 2023-07-19 23:33:45 +03:00
parent 498f210e10
commit 7981a11bd9
5 changed files with 10 additions and 4 deletions

View file

@ -36,7 +36,8 @@ type BridgeConfig struct {
MessageErrorNotices bool `yaml:"message_error_notices"` MessageErrorNotices bool `yaml:"message_error_notices"`
PortalMessageBuffer int `yaml:"portal_message_buffer"` 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"` DoublePuppetServerMap map[string]string `yaml:"double_puppet_server_map"`
DoublePuppetAllowDiscovery bool `yaml:"double_puppet_allow_discovery"` DoublePuppetAllowDiscovery bool `yaml:"double_puppet_allow_discovery"`

View file

@ -43,6 +43,7 @@ func DoUpgrade(helper *up.Helper) {
helper.Copy(up.Bool, "bridge", "message_error_notices") helper.Copy(up.Bool, "bridge", "message_error_notices")
helper.Copy(up.Int, "bridge", "portal_message_buffer") helper.Copy(up.Int, "bridge", "portal_message_buffer")
helper.Copy(up.Bool, "bridge", "sync_direct_chat_list") 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.Map, "bridge", "double_puppet_server_map")
helper.Copy(up.Bool, "bridge", "double_puppet_allow_discovery") helper.Copy(up.Bool, "bridge", "double_puppet_allow_discovery")
helper.Copy(up.Map, "bridge", "login_shared_secret_map") helper.Copy(up.Map, "bridge", "login_shared_secret_map")

View file

@ -124,6 +124,8 @@ bridge:
# Note that updating the m.direct event is not atomic (except with mautrix-asmux) # Note that updating the m.direct event is not atomic (except with mautrix-asmux)
# and is therefore prone to race conditions. # and is therefore prone to race conditions.
sync_direct_chat_list: false 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 # Servers to always allow double puppeting from
double_puppet_server_map: double_puppet_server_map:

View file

@ -4,7 +4,7 @@ import (
"go.mau.fi/mautrix-gmessages/libgm/gmproto" "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 msgType := gmproto.MessageType_BUGLE_MESSAGE
if !c.conversationsFetchedOnce { if !c.conversationsFetchedOnce {
msgType = gmproto.MessageType_BUGLE_ANNOTATION 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{ return typedResponse[*gmproto.ListConversationsResponse](c.sessionHandler.sendMessageWithParams(SendMessageParams{
Action: gmproto.ActionType_LIST_CONVERSATIONS, Action: gmproto.ActionType_LIST_CONVERSATIONS,
Data: &gmproto.ListConversationsRequest{Count: count, Folder: folder}, Data: &gmproto.ListConversationsRequest{Count: int64(count), Folder: folder},
MessageType: msgType, MessageType: msgType,
})) }))
} }

View file

@ -654,11 +654,13 @@ func (user *User) aggressiveSetActive() {
} }
func (user *User) fetchAndSyncConversations() { 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 { if err != nil {
user.zlog.Err(err).Msg("Failed to get conversation list") user.zlog.Err(err).Msg("Failed to get conversation list")
return return
} }
user.zlog.Info().Int("count", len(resp.GetConversations())).Msg("Syncing conversations")
for _, conv := range resp.GetConversations() { for _, conv := range resp.GetConversations() {
user.syncConversation(conv) user.syncConversation(conv)
} }