diff --git a/pkg/connector/config.go b/pkg/connector/config.go index cecc32cf..791d3afc 100644 --- a/pkg/connector/config.go +++ b/pkg/connector/config.go @@ -49,6 +49,9 @@ type TelegramConfig struct { AnimatedSticker media.AnimatedStickerConfig `yaml:"animated_sticker"` + DisableViewOnce bool `yaml:"disable_view_once"` + DisableDisappearing bool `yaml:"disable_disappearing"` + MemberList MemberListConfig `yaml:"member_list"` MaxMemberCount int `yaml:"max_member_count"` @@ -89,6 +92,8 @@ func upgradeConfig(helper up.Helper) { helper.Copy(up.Int, "animated_sticker", "args", "width") helper.Copy(up.Int, "animated_sticker", "args", "height") helper.Copy(up.Int, "animated_sticker", "args", "fps") + helper.Copy(up.Bool, "disable_view_once") + helper.Copy(up.Bool, "disable_disappearing") helper.Copy(up.Int, "member_list", "max_initial_sync") helper.Copy(up.Bool, "member_list", "sync_broadcast_channels") helper.Copy(up.Bool, "member_list", "skip_deleted") diff --git a/pkg/connector/example-config.yaml b/pkg/connector/example-config.yaml index 9d5775ac..0cf16f92 100644 --- a/pkg/connector/example-config.yaml +++ b/pkg/connector/example-config.yaml @@ -30,6 +30,11 @@ animated_sticker: height: 256 fps: 25 # only for webm, webp and gif (2, 5, 10, 20 or 25 recommended) +# Should view-once messages be disabled entirely? +disable_view_once: false +# Should disappearing messages be disabled entirely? +disable_disappearing: false + # Settings for syncing the member list for portals. member_list: # Maximum number of members to sync per portal when starting up. Other diff --git a/pkg/connector/tomatrix.go b/pkg/connector/tomatrix.go index 469d24eb..a7118e6c 100644 --- a/pkg/connector/tomatrix.go +++ b/pkg/connector/tomatrix.go @@ -232,12 +232,56 @@ func (c *TelegramClient) convertMediaRequiringUpload(ctx context.Context, portal transferer := media.NewTransferer(c.client.API()).WithRoomID(portal.MXID) var mediaTransferer *media.ReadyTransferer + var disappearingSetting *database.DisappearingSetting + if t, ok := msgMedia.(ttlable); ok { + if ttl, ok := t.GetTTLSeconds(); ok { + typeName := "photo" + if msgMedia.TypeID() == tg.MessageMediaDocumentTypeID { + typeName = "file" + } + + if ttl == 2147483647 { + // This is a view-once message, set a low TTL. + ttl = 15 + + if c.main.Config.DisableViewOnce { + return &bridgev2.ConvertedMessagePart{ + Type: event.EventMessage, + Content: &event.MessageEventContent{ + MsgType: event.MsgNotice, + Body: fmt.Sprintf("You received a view once %s. For added privacy, you can only open it on the Telegram app.", typeName), + }, + }, nil, nil + } + } + + if c.main.Config.DisableDisappearing { + return &bridgev2.ConvertedMessagePart{ + Type: event.EventMessage, + Content: &event.MessageEventContent{ + MsgType: event.MsgNotice, + Body: fmt.Sprintf("You received a disappearing %s. For added privacy, you can only open it on the Telegram app.", typeName), + }, + }, nil, nil + } + + disappearingSetting = &database.DisappearingSetting{ + Type: database.DisappearingTypeAfterRead, + Timer: time.Duration(ttl) * time.Second, + } + } + } + // Determine the filename and some other information switch msgMedia := msgMedia.(type) { case *tg.MessageMediaPhoto: partID = networkid.PartID("photo") content.MsgType = event.MsgImage - content.Body = "image" + if disappearingSetting != nil { + content.Body = "disappearing_image" + } else { + content.Body = "image" + } telegramMediaID = msgMedia.Photo.GetID() mediaTransferer = transferer.WithPhoto(msgMedia.Photo) case *tg.MessageMediaDocument: @@ -389,20 +433,6 @@ func (c *TelegramClient) convertMediaRequiringUpload(ctx context.Context, portal info["fi.mau.telegram.spoiler"] = true } - // Handle disappearing messages - var disappearingSetting *database.DisappearingSetting - if t, ok := msgMedia.(ttlable); ok { - if ttl, ok := t.GetTTLSeconds(); ok { - if msgMedia.TypeID() == tg.MessageMediaPhotoTypeID { - content.Body = "disappearing_" + content.Body - } - disappearingSetting = &database.DisappearingSetting{ - Type: database.DisappearingTypeAfterSend, - Timer: time.Duration(ttl) * time.Second, - } - } - } - return &bridgev2.ConvertedMessagePart{ ID: partID, Type: eventType,