diff --git a/config/bridge.go b/config/bridge.go index 2ce4bb9c..e3e756c1 100644 --- a/config/bridge.go +++ b/config/bridge.go @@ -42,17 +42,18 @@ type BridgeConfig struct { PortalMessageBuffer int `yaml:"portal_message_buffer"` - PersonalFilteringSpaces bool `yaml:"personal_filtering_spaces"` - BridgeNotices bool `yaml:"bridge_notices"` - DeliveryReceipts bool `yaml:"delivery_receipts"` - MessageStatusEvents bool `yaml:"message_status_events"` - MessageErrorNotices bool `yaml:"message_error_notices"` - SyncDirectChatList bool `yaml:"sync_direct_chat_list"` - ResendBridgeInfo bool `yaml:"resend_bridge_info"` - PublicPortals bool `yaml:"public_portals"` - CaptionInMessage bool `yaml:"caption_in_message"` - FederateRooms bool `yaml:"federate_rooms"` - BridgeMatrixLeave bool `yaml:"bridge_matrix_leave"` + PersonalFilteringSpaces bool `yaml:"personal_filtering_spaces"` + BridgeNotices bool `yaml:"bridge_notices"` + DeliveryReceipts bool `yaml:"delivery_receipts"` + MessageStatusEvents bool `yaml:"message_status_events"` + MessageErrorNotices bool `yaml:"message_error_notices"` + SyncDirectChatList bool `yaml:"sync_direct_chat_list"` + ResendBridgeInfo bool `yaml:"resend_bridge_info"` + PublicPortals bool `yaml:"public_portals"` + CaptionInMessage bool `yaml:"caption_in_message"` + LocationFormat string `yaml:"location_format"` + FederateRooms bool `yaml:"federate_rooms"` + BridgeMatrixLeave bool `yaml:"bridge_matrix_leave"` DoublePuppetConfig bridgeconfig.DoublePuppetConfig `yaml:",inline"` diff --git a/config/upgrade.go b/config/upgrade.go index 0d943d67..114eb1d5 100644 --- a/config/upgrade.go +++ b/config/upgrade.go @@ -96,6 +96,7 @@ func DoUpgrade(helper *up.Helper) { helper.Copy(up.Bool, "bridge", "resend_bridge_info") helper.Copy(up.Bool, "bridge", "public_portals") helper.Copy(up.Bool, "bridge", "caption_in_message") + helper.Copy(up.Str, "bridge", "location_format") helper.Copy(up.Bool, "bridge", "federate_rooms") helper.Copy(up.Map, "bridge", "double_puppet_server_map") helper.Copy(up.Bool, "bridge", "double_puppet_allow_discovery") diff --git a/example-config.yaml b/example-config.yaml index b61c355f..71caa9c0 100644 --- a/example-config.yaml +++ b/example-config.yaml @@ -139,6 +139,10 @@ bridge: # Send captions in the same message as images. This will send data compatible with both MSC2530. # This is currently not supported in most clients. caption_in_message: false + # 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' # Whether or not created rooms should have federation enabled. # If false, created portal rooms will never be federated. federate_rooms: true diff --git a/msgconv/from-matrix.go b/msgconv/from-matrix.go index 791ea9e3..93241769 100644 --- a/msgconv/from-matrix.go +++ b/msgconv/from-matrix.go @@ -20,9 +20,11 @@ import ( "context" "errors" "fmt" + "strings" "time" "github.com/rs/zerolog" + "github.com/rs/zerolog/log" "go.mau.fi/util/exerrors" "go.mau.fi/util/exmime" "go.mau.fi/util/ffmpeg" @@ -109,8 +111,13 @@ func (mc *MessageConverter) ToSignal(ctx context.Context, evt *event.Event, cont Emoji: emoji, } case event.MsgLocation: - // TODO implement - fallthrough + lat, lon, err := parseGeoURI(content.GeoURI) + if err != nil { + log.Err(err).Msg("Failed to parse geo URI") + return nil, err + } + locationString := fmt.Sprintf(mc.LocationFormat, lat, lon) + dm.Body = &locationString default: return nil, fmt.Errorf("%w %s", ErrUnsupportedMsgType, content.MsgType) } @@ -190,3 +197,20 @@ func (mc *MessageConverter) convertFileToSignal(ctx context.Context, evt *event. } return att, nil } + +func parseGeoURI(uri string) (lat, long string, err error) { + if !strings.HasPrefix(uri, "geo:") { + err = fmt.Errorf("uri doesn't have geo: prefix") + return + } + // Remove geo: prefix and anything after ; + coordinates := strings.Split(strings.TrimPrefix(uri, "geo:"), ";")[0] + splitCoordinates := strings.Split(coordinates, ",") + if len(splitCoordinates) != 2 { + err = fmt.Errorf("didn't find exactly two numbers separated by a comma") + } else { + lat = splitCoordinates[0] + long = splitCoordinates[1] + } + return +} 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()