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:
+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