From 1e7d8f53bea6b57d372d680232ddae2726d6043e Mon Sep 17 00:00:00 2001 From: Malte E Date: Mon, 22 Apr 2024 22:04:43 +0200 Subject: [PATCH] add support for matrix -> signal location messages --- config/bridge.go | 1 + config/upgrade.go | 1 + example-config.yaml | 5 +++++ msgconv/from-matrix.go | 6 ++++-- msgconv/msgconv.go | 2 ++ portal.go | 1 + 6 files changed, 14 insertions(+), 2 deletions(-) diff --git a/config/bridge.go b/config/bridge.go index 2ce4bb9c..8754efc2 100644 --- a/config/bridge.go +++ b/config/bridge.go @@ -81,6 +81,7 @@ type BridgeConfig struct { usernameTemplate *template.Template `yaml:"-"` displaynameTemplate *template.Template `yaml:"-"` + LocationFormat string `yaml:"location_format"` } func (bc *BridgeConfig) GetResendBridgeInfo() bool { diff --git a/config/upgrade.go b/config/upgrade.go index 0d943d67..67ce2d47 100644 --- a/config/upgrade.go +++ b/config/upgrade.go @@ -144,6 +144,7 @@ func DoUpgrade(helper *up.Helper) { } else { helper.Copy(up.Map, "bridge", "relay", "message_formats") } + helper.Copy(up.Str, "bridge", "location_format") } var SpacedBlocks = [][]string{ diff --git a/example-config.yaml b/example-config.yaml index b61c355f..3833d4b0 100644 --- a/example-config.yaml +++ b/example-config.yaml @@ -299,6 +299,11 @@ bridge: m.video: "{{ .Sender.Displayname }} sent a video" m.location: "{{ .Sender.Displayname }} sent a location" + # Format for generating URLs from location messages for sending to Signal + # Google Maps: 'https://www.google.com/maps/place/%[1]s,%[2]s' + # OpenStreetMap: 'https://www.openstreetmap.org/?mlat=%[1]s&mlon=%[2]' + location_format: 'https://www.google.com/maps/place/%[1]s,%[2]s' + # Logging config. See https://github.com/tulir/zeroconfig for details. logging: min_level: debug diff --git a/msgconv/from-matrix.go b/msgconv/from-matrix.go index 791ea9e3..7d7f5d75 100644 --- a/msgconv/from-matrix.go +++ b/msgconv/from-matrix.go @@ -20,6 +20,7 @@ import ( "context" "errors" "fmt" + "strings" "time" "github.com/rs/zerolog" @@ -109,8 +110,9 @@ func (mc *MessageConverter) ToSignal(ctx context.Context, evt *event.Event, cont Emoji: emoji, } case event.MsgLocation: - // TODO implement - fallthrough + coords := strings.Split(content.GeoURI[len("geo:"):], ",") + locationString := fmt.Sprintf(mc.LocationFormat, coords[0], coords[1]) + dm.Body = &locationString default: return nil, fmt.Errorf("%w %s", ErrUnsupportedMsgType, content.MsgType) } diff --git a/msgconv/msgconv.go b/msgconv/msgconv.go index b7f97718..0e291576 100644 --- a/msgconv/msgconv.go +++ b/msgconv/msgconv.go @@ -54,6 +54,8 @@ type MessageConverter struct { ConvertGIFToAPNG bool MaxFileSize int64 AsyncFiles bool + + LocationFormat string } func (mc *MessageConverter) IsPrivateChat(ctx context.Context) bool { diff --git a/portal.go b/portal.go index 44f67bb0..2e90ac77 100644 --- a/portal.go +++ b/portal.go @@ -236,6 +236,7 @@ func (br *SignalBridge) NewPortal(dbPortal *database.Portal) *Portal { MatrixFmtParams: matrixFormatParams, ConvertVoiceMessages: true, MaxFileSize: br.MediaConfig.UploadSize, + LocationFormat: br.Config.Bridge.LocationFormat, } go portal.messageLoop()