client: add option to disable bridging view-once and disappearing media
Signed-off-by: Sumner Evans <sumner.evans@automattic.com>
This commit is contained in:
@@ -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")
|
||||
|
||||
@@ -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
|
||||
|
||||
+45
-15
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user