From dc4538aab6d33543d552950b03c7fcb82e1d528a Mon Sep 17 00:00:00 2001 From: LeaPhant Date: Sat, 7 Jun 2025 23:27:29 +0200 Subject: [PATCH] Add support for MSC4193 media spoilers (#189) --- portal.go | 4 ++++ portal_convert.go | 17 ++++++++++------- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/portal.go b/portal.go index 4a45a63..94a2cf7 100644 --- a/portal.go +++ b/portal.go @@ -1639,6 +1639,10 @@ func (portal *Portal) handleMatrixMessage(sender *User, evt *event.Event) { sendReq.Content, sendReq.AllowedMentions = portal.parseMatrixHTML(content) } + if evt.Content.Raw["page.codeberg.everypizza.msc4193.spoiler"] == true { + filename = "SPOILER_" + filename + } + if portal.bridge.Config.Bridge.UseDiscordCDNUpload && !isWebhookSend && sess.IsUser { att := &discordgo.MessageAttachment{ ID: "0", diff --git a/portal_convert.go b/portal_convert.go index 62621ba..02218bd 100644 --- a/portal_convert.go +++ b/portal_convert.go @@ -154,24 +154,27 @@ func (portal *Portal) convertDiscordAttachment(ctx context.Context, intent *apps Size: att.Size, }, } + + var extra = make(map[string]any) + + if strings.HasPrefix(att.Filename, "SPOILER_") { + extra["page.codeberg.everypizza.msc4193.spoiler"] = true + } + if att.Description != "" { content.Body = att.Description content.FileName = att.Filename } - var extra map[string]any - switch strings.ToLower(strings.Split(att.ContentType, "/")[0]) { case "audio": content.MsgType = event.MsgAudio if att.Waveform != nil { // TODO convert waveform - extra = map[string]any{ - "org.matrix.msc1767.audio": map[string]any{ - "duration": int(att.DurationSeconds * 1000), - }, - "org.matrix.msc3245.voice": map[string]any{}, + extra["org.matrix.msc1767.audio"] = map[string]any{ + "duration": int(att.DurationSeconds * 1000), } + extra["org.matrix.msc3245.voice"] = map[string]any{} } case "image": content.MsgType = event.MsgImage