From c9175c3f3680ad424300945488015a7a20826352 Mon Sep 17 00:00:00 2001 From: Marco Alvarez Date: Fri, 29 Dec 2023 15:27:03 +0100 Subject: [PATCH 1/5] Always add URL field on media events Fixes https://github.com/mautrix/whatsapp/issues/662 Fixes https://github.com/element-hq/element-x-ios/issues/1047 --- portal.go | 1 + 1 file changed, 1 insertion(+) diff --git a/portal.go b/portal.go index f330bb4..18bc5d8 100644 --- a/portal.go +++ b/portal.go @@ -3434,6 +3434,7 @@ func (portal *Portal) uploadMedia(intent *appservice.IntentAPI, data []byte, con if file != nil { file.URL = mxc.CUString() content.File = file + content.URL = mxc.CUString() } else { content.URL = mxc.CUString() } From 598e6e68fc15ddcc7a3db8cac2a13231b015e3c3 Mon Sep 17 00:00:00 2001 From: Marco Alvarez Date: Tue, 2 Jan 2024 10:24:36 +0100 Subject: [PATCH 2/5] only add url field on sticker events --- portal.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/portal.go b/portal.go index 18bc5d8..bee936f 100644 --- a/portal.go +++ b/portal.go @@ -3434,7 +3434,12 @@ func (portal *Portal) uploadMedia(intent *appservice.IntentAPI, data []byte, con if file != nil { file.URL = mxc.CUString() content.File = file - content.URL = mxc.CUString() + // Sticker events require the URL field to be present https://spec.matrix.org/v1.9/client-server-api/#events-16 + // This seems to affect only clients based on the Rust SDK on encrypted channels (like Element X) + isSticker := string(content.MsgType) == event.EventSticker.Type + if isSticker { + content.URL = mxc.CUString() + } } else { content.URL = mxc.CUString() } From 0ebb235e61149474040c986f7a801c7e8f9adcf3 Mon Sep 17 00:00:00 2001 From: Marco Alvarez Date: Tue, 2 Jan 2024 10:53:19 +0100 Subject: [PATCH 3/5] only add url field on sticker events (properly) --- portal.go | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/portal.go b/portal.go index bee936f..d6d5322 100644 --- a/portal.go +++ b/portal.go @@ -3434,12 +3434,6 @@ func (portal *Portal) uploadMedia(intent *appservice.IntentAPI, data []byte, con if file != nil { file.URL = mxc.CUString() content.File = file - // Sticker events require the URL field to be present https://spec.matrix.org/v1.9/client-server-api/#events-16 - // This seems to affect only clients based on the Rust SDK on encrypted channels (like Element X) - isSticker := string(content.MsgType) == event.EventSticker.Type - if isSticker { - content.URL = mxc.CUString() - } } else { content.URL = mxc.CUString() } @@ -3506,6 +3500,13 @@ func (portal *Portal) convertMediaMessage(intent *appservice.IntentAPI, source * return portal.makeMediaBridgeFailureMessage(info, fmt.Errorf("failed to upload media: %w", err), converted, nil, "") } } + + // Sticker events require the URL field to be present https://spec.matrix.org/v1.9/client-server-api/#events-16 + // This seems to affect only clients based on the Rust SDK on encrypted channels (like Element X) + if typeName == "sticker" && converted.Content.File != nil { + converted.Content.URL = converted.Content.File.URL + } + return converted } From 995b3ea207c60bc1c0e232a638b37d223b966240 Mon Sep 17 00:00:00 2001 From: Marco Alvarez Date: Tue, 2 Jan 2024 11:35:37 +0100 Subject: [PATCH 4/5] fix lint --- portal.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/portal.go b/portal.go index d6d5322..8f22ab7 100644 --- a/portal.go +++ b/portal.go @@ -3502,7 +3502,7 @@ func (portal *Portal) convertMediaMessage(intent *appservice.IntentAPI, source * } // Sticker events require the URL field to be present https://spec.matrix.org/v1.9/client-server-api/#events-16 - // This seems to affect only clients based on the Rust SDK on encrypted channels (like Element X) + // This seems to affect only clients based on the Rust SDK on encrypted channels (like Element X) if typeName == "sticker" && converted.Content.File != nil { converted.Content.URL = converted.Content.File.URL } From 38128830cc06738870a5b7491590e0791f4ae580 Mon Sep 17 00:00:00 2001 From: Marco Alvarez Date: Wed, 3 Jan 2024 18:21:50 +0100 Subject: [PATCH 5/5] use an empty url field --- portal.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/portal.go b/portal.go index 8f22ab7..dfb41e2 100644 --- a/portal.go +++ b/portal.go @@ -3504,7 +3504,7 @@ func (portal *Portal) convertMediaMessage(intent *appservice.IntentAPI, source * // Sticker events require the URL field to be present https://spec.matrix.org/v1.9/client-server-api/#events-16 // This seems to affect only clients based on the Rust SDK on encrypted channels (like Element X) if typeName == "sticker" && converted.Content.File != nil { - converted.Content.URL = converted.Content.File.URL + converted.Extra["url"] = "" } return converted