metadata: allow disabling channel memebr sync
Signed-off-by: Sumner Evans <sumner.evans@automattic.com>
This commit is contained in:
@@ -50,9 +50,9 @@ func (t *TelegramClient) getDMChatInfo(ctx context.Context, userID int64) (*brid
|
|||||||
return &chatInfo, nil
|
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 {
|
if err := t.updateUsersFromResponse(ctx, fullChat); err != nil {
|
||||||
return nil, err
|
return nil, false, err
|
||||||
}
|
}
|
||||||
|
|
||||||
chatInfo := bridgev2.ChatInfo{
|
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() {
|
for _, c := range fullChat.GetChats() {
|
||||||
if c.GetID() == chatID {
|
if c.GetID() == chatID {
|
||||||
switch chat := c.(type) {
|
switch chat := c.(type) {
|
||||||
@@ -77,6 +78,7 @@ func (t *TelegramClient) getGroupChatInfo(ctx context.Context, fullChat *tg.Mess
|
|||||||
chatInfo.Name = &chat.Title
|
chatInfo.Name = &chat.Title
|
||||||
case *tg.Channel:
|
case *tg.Channel:
|
||||||
chatInfo.Name = &chat.Title
|
chatInfo.Name = &chat.Title
|
||||||
|
isBroadcastChannel = chat.Broadcast
|
||||||
}
|
}
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
@@ -93,7 +95,7 @@ func (t *TelegramClient) getGroupChatInfo(ctx context.Context, fullChat *tg.Mess
|
|||||||
chatInfo.Topic = &about
|
chatInfo.Topic = &about
|
||||||
}
|
}
|
||||||
|
|
||||||
return &chatInfo, nil
|
return &chatInfo, isBroadcastChannel, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *TelegramClient) avatarFromPhoto(photo tg.PhotoClass) *bridgev2.Avatar {
|
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 {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
chatInfo, err := t.getGroupChatInfo(ctx, fullChat, id)
|
chatInfo, _, err := t.getGroupChatInfo(ctx, fullChat, id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -199,7 +201,7 @@ func (t *TelegramClient) GetChatInfo(ctx context.Context, portal *bridgev2.Porta
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
chatInfo, err := t.getGroupChatInfo(ctx, fullChat, id)
|
chatInfo, isBroadcastChannel, err := t.getGroupChatInfo(ctx, fullChat, id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -223,9 +225,15 @@ func (t *TelegramClient) GetChatInfo(ctx context.Context, portal *bridgev2.Porta
|
|||||||
chatInfo.Members.IsFull = false
|
chatInfo.Members.IsFull = false
|
||||||
|
|
||||||
// Just return the current user as a member if we can't view the
|
// 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
|
// participants or the max initial sync is 0.
|
||||||
// is disabled.
|
if t.main.Config.MemberList.MaxInitialSync == 0 || !channelFull.CanViewParticipants || channelFull.ParticipantsHidden {
|
||||||
if t.main.Config.MemberList.MaxInitialSync == 0 || !t.main.Config.MemberList.SyncChannels || !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
|
return chatInfo, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -15,9 +15,9 @@ import (
|
|||||||
var _ bridgev2.ConfigValidatingNetwork = (*TelegramConnector)(nil)
|
var _ bridgev2.ConfigValidatingNetwork = (*TelegramConnector)(nil)
|
||||||
|
|
||||||
type MemberListConfig struct {
|
type MemberListConfig struct {
|
||||||
MaxInitialSync int `yaml:"max_initial_sync"`
|
MaxInitialSync int `yaml:"max_initial_sync"`
|
||||||
SyncChannels bool `yaml:"sync_channels"`
|
SyncBroadcastChannels bool `yaml:"sync_broadcast_channels"`
|
||||||
SkipDeleted bool `yaml:"skip_deleted"`
|
SkipDeleted bool `yaml:"skip_deleted"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c MemberListConfig) NormalizedMaxInitialSync() int {
|
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", "height")
|
||||||
helper.Copy(up.Int, "animated_sticker", "args", "fps")
|
helper.Copy(up.Int, "animated_sticker", "args", "fps")
|
||||||
helper.Copy(up.Int, "member_list", "max_initial_sync")
|
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.Bool, "member_list", "skip_deleted")
|
||||||
helper.Copy(up.Int, "max_member_count")
|
helper.Copy(up.Int, "max_member_count")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -31,12 +31,12 @@ member_list:
|
|||||||
# -1 means no limit (which means it's limited to 10000 by the server)
|
# -1 means no limit (which means it's limited to 10000 by the server)
|
||||||
max_initial_sync: 100
|
max_initial_sync: 100
|
||||||
|
|
||||||
# Whether or not to sync the member list in channels. If disabled, members
|
# Whether or not to sync the member list in broadcast channels. If
|
||||||
# will still be synced when they send messages.
|
# disabled, members will still be synced when they send messages.
|
||||||
#
|
#
|
||||||
# If no channel admins have logged into the bridge, the bridge won't be
|
# If no channel admins have logged into the bridge, the bridge won't be
|
||||||
# able to sync the member list regardless of this setting.
|
# 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.
|
# Whether or not to skip deleted members when syncing members.
|
||||||
skip_deleted: true
|
skip_deleted: true
|
||||||
|
|||||||
Reference in New Issue
Block a user