Skip to content

Commit

Permalink
add support for matrix -> signal location messages
Browse files Browse the repository at this point in the history
  • Loading branch information
maltee1 committed Apr 22, 2024
1 parent 703beca commit 1e7d8f5
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 2 deletions.
1 change: 1 addition & 0 deletions config/bridge.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions config/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down
5 changes: 5 additions & 0 deletions example-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,11 @@ bridge:
m.video: "<b>{{ .Sender.Displayname }}</b> sent a video"
m.location: "<b>{{ .Sender.Displayname }}</b> 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
Expand Down
6 changes: 4 additions & 2 deletions msgconv/from-matrix.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"context"
"errors"
"fmt"
"strings"
"time"

"github.com/rs/zerolog"
Expand Down Expand Up @@ -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)
}
Expand Down
2 changes: 2 additions & 0 deletions msgconv/msgconv.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ type MessageConverter struct {
ConvertGIFToAPNG bool
MaxFileSize int64
AsyncFiles bool

LocationFormat string
}

func (mc *MessageConverter) IsPrivateChat(ctx context.Context) bool {
Expand Down
1 change: 1 addition & 0 deletions portal.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down

0 comments on commit 1e7d8f5

Please sign in to comment.