Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions pkg/connector/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ type TelegramConfig struct {
ContactAvatars bool `yaml:"contact_avatars"`
ContactNames bool `yaml:"contact_names"`
MaxMemberCount int `yaml:"max_member_count"`
MaxTelegramDelete int `yaml:"max_telegram_delete"`
AlwaysCustomEmojiReaction bool `yaml:"always_custom_emoji_reaction"`
SavedMessagesAvatar id.ContentURIString `yaml:"saved_message_avatar"`
AlwaysTombstoneOnSupergroupMigration bool `yaml:"always_tombstone_on_supergroup_migration"`
Expand All @@ -107,6 +108,10 @@ func (c TelegramConfig) ShouldBridge(participantCount int) bool {
return c.MaxMemberCount < 0 || participantCount <= c.MaxMemberCount
}

func (c TelegramConfig) ShouldBridgeDeletion(deletedMessageCount int) bool {
return c.MaxTelegramDelete < 0 || deletedMessageCount <= c.MaxTelegramDelete
}

type DisplaynameParams struct {
FullName string
FirstName string
Expand Down Expand Up @@ -185,6 +190,7 @@ func upgradeConfig(helper up.Helper) {
helper.Copy(up.Bool, "contact_avatars")
helper.Copy(up.Bool, "contact_names")
helper.Copy(up.Int, "max_member_count")
helper.Copy(up.Int, "max_telegram_delete")
helper.Copy(up.Bool, "always_custom_emoji_reaction")
helper.Copy(up.Str, "saved_message_avatar")
helper.Copy(up.Bool, "always_tombstone_on_supergroup_migration")
Expand Down
6 changes: 6 additions & 0 deletions pkg/connector/example-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,12 @@ takeout:
#
# -1 means no limit (which means all chats can be bridged)
max_member_count: -1
# The maximum number of simultaneous Telegram message deletions to handle.
# If a single Telegram update deletes more than this many messages, the entire
# deletion is ignored instead of being bridged as Matrix redactions.
#
# -1 means no limit
max_telegram_delete: -1
# Should personal avatars (that are only visible to specific users) be allowed?
contact_avatars: false
# Should contact names be updated from any source even if a name is already set?
Expand Down
13 changes: 12 additions & 1 deletion pkg/connector/handletelegram.go
Original file line number Diff line number Diff line change
Expand Up @@ -795,7 +795,18 @@ func (tc *TelegramClient) onUserName(ctx context.Context, e tg.Entities, update
}

func (tc *TelegramClient) onDeleteMessages(ctx context.Context, channelID int64, update IGetMessages) error {
for _, messageID := range update.GetMessages() {
messages := update.GetMessages()

if !tc.main.Config.ShouldBridgeDeletion(len(messages)) {
zerolog.Ctx(ctx).Info().
Int64("channel_id", channelID).
Int("deleted_message_count", len(messages)).
Int("max_telegram_delete", tc.main.Config.MaxTelegramDelete).
Msg("Ignoring mass deletion of messages on Telegram to preserve the Matrix history")
return nil
}

for _, messageID := range messages {
wrappedMessageID := ids.MakeMessageID(channelID, messageID)
var portalKey networkid.PortalKey
var ok bool
Expand Down