diff --git a/pkg/connector/chatinfo.go b/pkg/connector/chatinfo.go index dcbf014d..e9e85c52 100644 --- a/pkg/connector/chatinfo.go +++ b/pkg/connector/chatinfo.go @@ -50,9 +50,9 @@ func (t *TelegramClient) getDMChatInfo(ctx context.Context, userID int64) (*brid return &chatInfo, nil } -func (t *TelegramClient) getGroupChatInfo(ctx context.Context, fullChat *tg.MessagesChatFull, chatID int64) (*bridgev2.ChatInfo, error) { +func (t *TelegramClient) getGroupChatInfo(ctx context.Context, fullChat *tg.MessagesChatFull, chatID int64) (*bridgev2.ChatInfo, bool, error) { if err := t.updateUsersFromResponse(ctx, fullChat); err != nil { - return nil, err + return nil, false, err } chatInfo := bridgev2.ChatInfo{ @@ -70,6 +70,7 @@ func (t *TelegramClient) getGroupChatInfo(ctx context.Context, fullChat *tg.Mess }, }, } + var isBroadcastChannel bool for _, c := range fullChat.GetChats() { if c.GetID() == chatID { switch chat := c.(type) { @@ -77,6 +78,7 @@ func (t *TelegramClient) getGroupChatInfo(ctx context.Context, fullChat *tg.Mess chatInfo.Name = &chat.Title case *tg.Channel: chatInfo.Name = &chat.Title + isBroadcastChannel = chat.Broadcast } break } @@ -93,7 +95,7 @@ func (t *TelegramClient) getGroupChatInfo(ctx context.Context, fullChat *tg.Mess chatInfo.Topic = &about } - return &chatInfo, nil + return &chatInfo, isBroadcastChannel, nil } func (t *TelegramClient) avatarFromPhoto(photo tg.PhotoClass) *bridgev2.Avatar { @@ -146,7 +148,7 @@ func (t *TelegramClient) GetChatInfo(ctx context.Context, portal *bridgev2.Porta if err != nil { return nil, err } - chatInfo, err := t.getGroupChatInfo(ctx, fullChat, id) + chatInfo, _, err := t.getGroupChatInfo(ctx, fullChat, id) if err != nil { return nil, err } @@ -199,7 +201,7 @@ func (t *TelegramClient) GetChatInfo(ctx context.Context, portal *bridgev2.Porta return nil, err } - chatInfo, err := t.getGroupChatInfo(ctx, fullChat, id) + chatInfo, isBroadcastChannel, err := t.getGroupChatInfo(ctx, fullChat, id) if err != nil { return nil, err } @@ -223,9 +225,15 @@ func (t *TelegramClient) GetChatInfo(ctx context.Context, portal *bridgev2.Porta chatInfo.Members.IsFull = false // Just return the current user as a member if we can't view the - // participants or the max initial sync is 0 or if channel member sync - // is disabled. - if t.main.Config.MemberList.MaxInitialSync == 0 || !t.main.Config.MemberList.SyncChannels || !channelFull.CanViewParticipants || channelFull.ParticipantsHidden { + // participants or the max initial sync is 0. + if t.main.Config.MemberList.MaxInitialSync == 0 || !channelFull.CanViewParticipants || channelFull.ParticipantsHidden { + return chatInfo, nil + } + + // If this is a broadcast channel and we're not syncing broadcast + // channels, just return the chat info without all of the participant + // info. + if isBroadcastChannel && !t.main.Config.MemberList.SyncBroadcastChannels { return chatInfo, nil } diff --git a/pkg/connector/config.go b/pkg/connector/config.go index fed7f4d5..ce89b351 100644 --- a/pkg/connector/config.go +++ b/pkg/connector/config.go @@ -15,9 +15,9 @@ import ( var _ bridgev2.ConfigValidatingNetwork = (*TelegramConnector)(nil) type MemberListConfig struct { - MaxInitialSync int `yaml:"max_initial_sync"` - SyncChannels bool `yaml:"sync_channels"` - SkipDeleted bool `yaml:"skip_deleted"` + MaxInitialSync int `yaml:"max_initial_sync"` + SyncBroadcastChannels bool `yaml:"sync_broadcast_channels"` + SkipDeleted bool `yaml:"skip_deleted"` } func (c MemberListConfig) NormalizedMaxInitialSync() int { @@ -54,7 +54,7 @@ func upgradeConfig(helper up.Helper) { helper.Copy(up.Int, "animated_sticker", "args", "height") helper.Copy(up.Int, "animated_sticker", "args", "fps") helper.Copy(up.Int, "member_list", "max_initial_sync") - helper.Copy(up.Bool, "member_list", "sync_channels") + helper.Copy(up.Bool, "member_list", "sync_broadcast_channels") helper.Copy(up.Bool, "member_list", "skip_deleted") helper.Copy(up.Int, "max_member_count") } diff --git a/pkg/connector/example-config.yaml b/pkg/connector/example-config.yaml index ccb48f57..d409d03e 100644 --- a/pkg/connector/example-config.yaml +++ b/pkg/connector/example-config.yaml @@ -31,12 +31,12 @@ member_list: # -1 means no limit (which means it's limited to 10000 by the server) max_initial_sync: 100 - # Whether or not to sync the member list in channels. If disabled, members - # will still be synced when they send messages. + # Whether or not to sync the member list in broadcast channels. If + # disabled, members will still be synced when they send messages. # # If no channel admins have logged into the bridge, the bridge won't be # able to sync the member list regardless of this setting. - sync_channels: false + sync_broadcast_channels: false # Whether or not to skip deleted members when syncing members. skip_deleted: true