Skip to content
This repository has been archived by the owner on Nov 13, 2024. It is now read-only.

Commit

Permalink
Merge tag 'v0.5.1' into element-main
Browse files Browse the repository at this point in the history
  • Loading branch information
Half-Shot committed Mar 21, 2024
2 parents eda3536 + cdab7f8 commit 2972a5f
Show file tree
Hide file tree
Showing 24 changed files with 1,177 additions and 877 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
# v0.5.1 (2024-03-16)

* Updated to libsignal v0.41.0.
* Fixed sending messages to groups.
* Fixed some cases of ghost user info changing repeatedly on multi-user
instances.
* Fixed migrating SQLite databases from Python version.

# v0.5.0 (2024-02-16)

* Rewrote bridge in Go.
Expand Down
19 changes: 9 additions & 10 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,22 @@ go 1.21

require (
github.com/beeper/libserv v0.0.0-20231231202820-c7303abfc32c
github.com/element-hq/mautrix-go v0.18.0-beta.1-mod-2.0.20240305190819-c6ec91b05c3c
github.com/element-hq/mautrix-go v0.18.0-mod-1
github.com/emersion/go-vcard v0.0.0-20230815062825-8fda7d206ec9
github.com/google/uuid v1.6.0
github.com/gorilla/mux v1.8.0
github.com/lib/pq v1.10.9
github.com/mattn/go-pointer v0.0.1
github.com/mattn/go-sqlite3 v1.14.22
github.com/prometheus/client_golang v1.18.0
github.com/prometheus/client_golang v1.19.0
github.com/rs/zerolog v1.32.0
github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e
github.com/stretchr/testify v1.8.4
github.com/stretchr/testify v1.9.0
github.com/tidwall/gjson v1.17.1
go.mau.fi/util v0.4.1-0.20240222202553-953608f657a3
golang.org/x/crypto v0.19.0
golang.org/x/exp v0.0.0-20240213143201-ec583247a57a
golang.org/x/net v0.21.0
go.mau.fi/util v0.4.1
golang.org/x/crypto v0.21.0
golang.org/x/exp v0.0.0-20240314144324-c7f7c6466f7f
golang.org/x/net v0.22.0
google.golang.org/protobuf v1.32.0
nhooyr.io/websocket v1.8.10
)
Expand All @@ -33,18 +33,17 @@ require (
github.com/kr/text v0.2.0 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.19 // indirect
github.com/matttproud/golang_protobuf_extensions/v2 v2.0.0 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/prometheus/client_model v0.5.0 // indirect
github.com/prometheus/common v0.45.0 // indirect
github.com/prometheus/common v0.48.0 // indirect
github.com/prometheus/procfs v0.12.0 // indirect
github.com/rs/xid v1.5.0 // indirect
github.com/tidwall/match v1.1.1 // indirect
github.com/tidwall/pretty v1.2.0 // indirect
github.com/tidwall/sjson v1.2.5 // indirect
github.com/yuin/goldmark v1.7.0 // indirect
go.mau.fi/zeroconfig v0.1.2 // indirect
golang.org/x/sys v0.17.0 // indirect
golang.org/x/sys v0.18.0 // indirect
gopkg.in/natefinch/lumberjack.v2 v2.2.1 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
maunium.net/go/mauflag v1.0.0 // indirect
Expand Down
38 changes: 24 additions & 14 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ github.com/coreos/go-systemd/v22 v22.5.0/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSV
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/element-hq/mautrix-go v0.18.0-beta.1-mod-2.0.20240305190819-c6ec91b05c3c h1:xA1shDsjlmCuE1YQnXMCr9++Rm6U8nL6RleuOUmx/80=
github.com/element-hq/mautrix-go v0.18.0-beta.1-mod-2.0.20240305190819-c6ec91b05c3c/go.mod h1:eJu6JOtGbObkSyDpiBL58nuDyjLrIBbrrLa9aDbpsaI=
github.com/element-hq/mautrix-go v0.18.0-mod-1 h1:1r781J054eiVNlmt3iQnGnpCMfAX0SQTqDfM1b+n+yw=
github.com/element-hq/mautrix-go v0.18.0-mod-1/go.mod h1:8psd9ZH1FYYdgPO3L2pmk/7jdhi0BX3gdrn+qAqfyw4=
github.com/emersion/go-vcard v0.0.0-20230815062825-8fda7d206ec9 h1:ATgqloALX6cHCranzkLb8/zjivwQ9DWWDCQRnxTPfaA=
github.com/emersion/go-vcard v0.0.0-20230815062825-8fda7d206ec9/go.mod h1:HMJKR5wlh/ziNp+sHEDV2ltblO4JD2+IdDOWtGcQBTM=
github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/gorilla/mux v1.8.0 h1:i40aqfkR1h2SlN9hojwV5ZA91wcXFOvkdNIeFDP5koI=
Expand All @@ -39,17 +39,15 @@ github.com/mattn/go-pointer v0.0.1 h1:n+XhsuGeVO6MEAp7xyEukFINEa+Quek5psIR/ylA6o
github.com/mattn/go-pointer v0.0.1/go.mod h1:2zXcozF6qYGgmsG+SeTZz3oAbFLdD3OWqnUbNvJZAlc=
github.com/mattn/go-sqlite3 v1.14.22 h1:2gZY6PC6kBnID23Tichd1K+Z0oS6nE/XwU+Vz/5o4kU=
github.com/mattn/go-sqlite3 v1.14.22/go.mod h1:Uh1q+B4BYcTPb+yiD3kU8Ct7aC0hY9fxUwlHK0RXw+Y=
github.com/matttproud/golang_protobuf_extensions/v2 v2.0.0 h1:jWpvCLoY8Z/e3VKvlsiIGKtc+UG6U5vzxaoagmhXfyg=
github.com/matttproud/golang_protobuf_extensions/v2 v2.0.0/go.mod h1:QUyp042oQthUoa9bqDv0ER0wrtXnBruoNd7aNjkbP+k=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/prometheus/client_golang v1.18.0 h1:HzFfmkOzH5Q8L8G+kSJKUx5dtG87sewO+FoDDqP5Tbk=
github.com/prometheus/client_golang v1.18.0/go.mod h1:T+GXkCk5wSJyOqMIzVgvvjFDlkOQntgjkJWKrN5txjA=
github.com/prometheus/client_golang v1.19.0 h1:ygXvpU1AoN1MhdzckN+PyD9QJOSD4x7kmXYlnfbA6JU=
github.com/prometheus/client_golang v1.19.0/go.mod h1:ZRM9uEAypZakd+q/x7+gmsvXdURP+DABIEIjnmDdp+k=
github.com/prometheus/client_model v0.5.0 h1:VQw1hfvPvk3Uv6Qf29VrPF32JB6rtbgI6cYPYQjL0Qw=
github.com/prometheus/client_model v0.5.0/go.mod h1:dTiFglRmd66nLR9Pv9f0mZi7B7fk5Pm3gvsjB5tr+kI=
github.com/prometheus/common v0.45.0 h1:2BGz0eBc2hdMDLnO/8n0jeB3oPrt2D08CekT0lneoxM=
github.com/prometheus/common v0.45.0/go.mod h1:YJmSTw9BoKxJplESWWxlbyttQR4uaEcGyv9MZjVOJsY=
github.com/prometheus/common v0.48.0 h1:QO8U2CdOzSn1BBsmXJXduaaW+dY/5QLjfB8svtSzKKE=
github.com/prometheus/common v0.48.0/go.mod h1:0/KsvlIEfPQCQ5I2iNSAWKPZziNCvRs5EC6ILDTlAPc=
github.com/prometheus/procfs v0.12.0 h1:jluTpSng7V9hY0O2R9DzzJHYb2xULk9VTR1V1R/k6Bo=
github.com/prometheus/procfs v0.12.0/go.mod h1:pcuDEFsWDnvcgNzo4EEweacyhjeA9Zk3cnaOZAZEfOo=
github.com/rogpeppe/go-internal v1.10.0 h1:TMyTOH3F/DB16zRVcYyreMH6GnZZrwQVAoYjRBZyWFQ=
Expand All @@ -60,8 +58,8 @@ github.com/rs/zerolog v1.32.0 h1:keLypqrlIjaFsbmJOBdB/qvyF8KEtCWHwobLp5l/mQ0=
github.com/rs/zerolog v1.32.0/go.mod h1:/7mN4D5sKwJLZQ2b/znpjC3/GQWY/xaDXUM0kKWRHss=
github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e h1:MRM5ITcdelLK2j1vwZ3Je0FKVCfqOLp5zO6trqMLYs0=
github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e/go.mod h1:XV66xRDqSt+GTGFMVlhk3ULuV0y9ZmzeVGR4mloJI3M=
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
github.com/tidwall/gjson v1.14.2/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk=
github.com/tidwall/gjson v1.17.1 h1:wlYEnwqAHgzmhNUFfw7Xalt2JzQvsMx2Se4PcoFCT/U=
github.com/tidwall/gjson v1.17.1/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk=
Expand All @@ -75,21 +73,31 @@ github.com/yuin/goldmark v1.7.0 h1:EfOIvIMZIzHdB/R/zVrikYLPPwJlfMcNczJFMs1m6sA=
github.com/yuin/goldmark v1.7.0/go.mod h1:uzxRWxtg69N339t3louHJ7+O03ezfj6PlliRlaOzY1E=
go.mau.fi/util v0.4.1-0.20240222202553-953608f657a3 h1:NcRrdzORHKab5bP1Z8BpH0nxsxsvH0iPPZLpOUN+UIc=
go.mau.fi/util v0.4.1-0.20240222202553-953608f657a3/go.mod h1:leeiHtgVBuN+W9aDii3deAXnfC563iN3WK6BF8/AjNw=
go.mau.fi/util v0.4.1 h1:3EC9KxIXo5+h869zDGf5OOZklRd/FjeVnimTwtm3owg=
go.mau.fi/util v0.4.1/go.mod h1:GjkTEBsehYZbSh2LlE6cWEn+6ZIZTGrTMM/5DMNlmFY=
go.mau.fi/zeroconfig v0.1.2 h1:DKOydWnhPMn65GbXZOafgkPm11BvFashZWLct0dGFto=
go.mau.fi/zeroconfig v0.1.2/go.mod h1:NcSJkf180JT+1IId76PcMuLTNa1CzsFFZ0nBygIQM70=
golang.org/x/crypto v0.19.0 h1:ENy+Az/9Y1vSrlrvBSyna3PITt4tiZLf7sgCjZBX7Wo=
golang.org/x/crypto v0.19.0/go.mod h1:Iy9bg/ha4yyC70EfRS8jz+B6ybOBKMaSxLj6P6oBDfU=
golang.org/x/crypto v0.21.0 h1:X31++rzVUdKhX5sWmSOFZxx8UW/ldWx55cbf08iNAMA=
golang.org/x/crypto v0.21.0/go.mod h1:0BP7YvVV9gBbVKyeTG0Gyn+gZm94bibOW5BjDEYAOMs=
golang.org/x/exp v0.0.0-20240213143201-ec583247a57a h1:HinSgX1tJRX3KsL//Gxynpw5CTOAIPhgL4W8PNiIpVE=
golang.org/x/exp v0.0.0-20240213143201-ec583247a57a/go.mod h1:CxmFvTBINI24O/j8iY7H1xHzx2i4OsyguNBmN/uPtqc=
golang.org/x/exp v0.0.0-20240314144324-c7f7c6466f7f h1:3CW0unweImhOzd5FmYuRsD4Y4oQFKZIjAnKbjV4WIrw=
golang.org/x/exp v0.0.0-20240314144324-c7f7c6466f7f/go.mod h1:CxmFvTBINI24O/j8iY7H1xHzx2i4OsyguNBmN/uPtqc=
golang.org/x/net v0.21.0 h1:AQyQV4dYCvJ7vGmJyKki9+PBdyvhkSd8EIx/qb0AYv4=
golang.org/x/net v0.21.0/go.mod h1:bIjVDfnllIU7BJ2DNgfnXvpSvtn8VRwhlsaeUTyUS44=
golang.org/x/net v0.22.0 h1:9sGLhx7iRIHEiX0oAJ3MRZMUCElJgy7Br1nO+AMN3Tc=
golang.org/x/net v0.22.0/go.mod h1:JKghWKKOSdJwpW2GEx0Ja7fmaKnMsbu+MWVZTokSYmg=
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.17.0 h1:25cE3gD+tdBA7lp7QfhuV+rJiE9YXTcS3VG1SqssI/Y=
golang.org/x/sys v0.17.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.18.0 h1:DBdB3niSjOA/O0blCZBqDefyWNYveAYMNF1Wum0DYQ4=
golang.org/x/sys v0.18.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
google.golang.org/protobuf v1.32.0 h1:pPC6BG5ex8PDFnkbrGU3EixyhKcQ2aDuBS36lqK/C7I=
google.golang.org/protobuf v1.32.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos=
google.golang.org/protobuf v1.33.0 h1:uNO2rsAINq/JlFpSdYEKIZ0uKD/R9cpdv0T+yoGwGmI=
google.golang.org/protobuf v1.33.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
Expand All @@ -101,5 +109,7 @@ maunium.net/go/mauflag v1.0.0 h1:YiaRc0tEI3toYtJMRIfjP+jklH45uDHtT80nUamyD4M=
maunium.net/go/mauflag v1.0.0/go.mod h1:nLivPOpTpHnpzEh8jEdSL9UqO9+/KBJFmNRlwKfkPeA=
maunium.net/go/maulogger/v2 v2.4.1 h1:N7zSdd0mZkB2m2JtFUsiGTQQAdP0YeFWT7YMc80yAL8=
maunium.net/go/maulogger/v2 v2.4.1/go.mod h1:omPuYwYBILeVQobz8uO3XC8DIRuEb5rXYlQSuqrbCho=
maunium.net/go/mautrix v0.18.0 h1:sNsApeSWB8x0hLjGcdmi5JqO6Tvp2PVkiSStz+Yas6k=
maunium.net/go/mautrix v0.18.0/go.mod h1:STwJZ+6CAeiEQs7fYCkd5aC12XR5DXANE6Swy/PBKGo=
nhooyr.io/websocket v1.8.10 h1:mv4p+MnGrLDcPlBoWsvPP7XCzTYMXP9F9eIGoKbgx7Q=
nhooyr.io/websocket v1.8.10/go.mod h1:rN9OFWIUwuxg4fR5tELlYC04bXYowCP9GX47ivo2l+c=
6 changes: 3 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ func (br *SignalBridge) Init() {
br.MatrixHandler.TrackEventDuration = br.Metrics.TrackMatrixEvent

signalFormatParams = &signalfmt.FormatParams{
GetUserInfo: func(u uuid.UUID) signalfmt.UserInfo {
GetUserInfo: func(ctx context.Context, u uuid.UUID) signalfmt.UserInfo {
puppet := br.GetPuppetBySignalID(u)
if puppet == nil {
return signalfmt.UserInfo{}
Expand All @@ -147,7 +147,7 @@ func (br *SignalBridge) Init() {
},
}
matrixFormatParams = &matrixfmt.HTMLParser{
GetUUIDFromMXID: func(userID id.UserID) uuid.UUID {
GetUUIDFromMXID: func(ctx context.Context, userID id.UserID) uuid.UUID {
parsed, ok := br.ParsePuppetMXID(userID)
if ok {
return parsed
Expand Down Expand Up @@ -476,7 +476,7 @@ func main() {
Name: "mautrix-signal",
URL: "https://github.com/element-hq/mautrix-signal",
Description: "A Matrix-Signal puppeting bridge.",
Version: "0.5.0-mod-2",
Version: "0.5.1-mod-1",
ProtocolName: "Signal",
BeeperServiceName: "signal",
BeeperNetworkName: "signal",
Expand Down
2 changes: 1 addition & 1 deletion msgconv/from-matrix.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func (mc *MessageConverter) ToSignal(ctx context.Context, evt *event.Event, cont
content.FormattedBody = "/me " + content.FormattedBody
}
}
body, bodyRanges := matrixfmt.Parse(mc.MatrixFmtParams, content)
body, bodyRanges := matrixfmt.Parse(ctx, mc.MatrixFmtParams, content)
switch content.MsgType {
case event.MsgText, event.MsgNotice, event.MsgEmote:
dm.Body = proto.String(body)
Expand Down
6 changes: 3 additions & 3 deletions msgconv/from-signal.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ func (mc *MessageConverter) ConvertDisappearingTimerChangeToMatrix(ctx context.C
}

func (mc *MessageConverter) convertTextToMatrix(ctx context.Context, dm *signalpb.DataMessage) *ConvertedMessagePart {
content := signalfmt.Parse(dm.GetBody(), dm.GetBodyRanges(), mc.SignalFmtParams)
content := signalfmt.Parse(ctx, dm.GetBody(), dm.GetBodyRanges(), mc.SignalFmtParams)
extra := map[string]any{}
if len(dm.Preview) > 0 {
extra["com.beeper.linkpreviews"] = mc.convertURLPreviewsToBeeper(ctx, dm.Preview)
Expand All @@ -189,7 +189,7 @@ func (mc *MessageConverter) convertTextToMatrix(ctx context.Context, dm *signalp
}
}

func (mc *MessageConverter) convertPaymentToMatrix(ctx context.Context, payment *signalpb.DataMessage_Payment) *ConvertedMessagePart {
func (mc *MessageConverter) convertPaymentToMatrix(_ context.Context, payment *signalpb.DataMessage_Payment) *ConvertedMessagePart {
return &ConvertedMessagePart{
Type: event.EventMessage,
Content: &event.MessageEventContent{
Expand All @@ -202,7 +202,7 @@ func (mc *MessageConverter) convertPaymentToMatrix(ctx context.Context, payment
}
}

func (mc *MessageConverter) convertGiftBadgeToMatrix(ctx context.Context, giftBadge *signalpb.DataMessage_GiftBadge) *ConvertedMessagePart {
func (mc *MessageConverter) convertGiftBadgeToMatrix(_ context.Context, giftBadge *signalpb.DataMessage_GiftBadge) *ConvertedMessagePart {
return &ConvertedMessagePart{
Type: event.EventMessage,
Content: &event.MessageEventContent{
Expand Down
9 changes: 5 additions & 4 deletions msgconv/matrixfmt/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,19 @@
package matrixfmt

import (
"context"
"github.com/element-hq/mautrix-go/event"

signalpb "github.com/element-hq/mautrix-signal/pkg/signalmeow/protobuf"
)

func Parse(parser *HTMLParser, content *event.MessageEventContent) (string, []*signalpb.BodyRange) {
func Parse(ctx context.Context, parser *HTMLParser, content *event.MessageEventContent) (string, []*signalpb.BodyRange) {
if content.Format != event.FormatHTML {
return content.Body, nil
}
ctx := NewContext()
ctx.AllowedMentions = content.Mentions
parsed := parser.Parse(content.FormattedBody, ctx)
parseCtx := NewContext(ctx)
parseCtx.AllowedMentions = content.Mentions
parsed := parser.Parse(content.FormattedBody, parseCtx)
if parsed == nil {
return "", nil
}
Expand Down
11 changes: 6 additions & 5 deletions msgconv/matrixfmt/convert_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package matrixfmt_test

import (
"context"
"fmt"
"testing"

Expand All @@ -15,7 +16,7 @@ import (
)

var formatParams = &matrixfmt.HTMLParser{
GetUUIDFromMXID: func(id id.UserID) uuid.UUID {
GetUUIDFromMXID: func(_ context.Context, id id.UserID) uuid.UUID {
if id.Homeserver() == "signal" {
return uuid.MustParse(id.Localpart())
}
Expand All @@ -24,7 +25,7 @@ var formatParams = &matrixfmt.HTMLParser{
}

func TestParse_Empty(t *testing.T) {
text, entities := matrixfmt.Parse(formatParams, &event.MessageEventContent{
text, entities := matrixfmt.Parse(context.TODO(), formatParams, &event.MessageEventContent{
MsgType: event.MsgText,
Body: "",
})
Expand All @@ -33,7 +34,7 @@ func TestParse_Empty(t *testing.T) {
}

func TestParse_EmptyHTML(t *testing.T) {
text, entities := matrixfmt.Parse(formatParams, &event.MessageEventContent{
text, entities := matrixfmt.Parse(context.TODO(), formatParams, &event.MessageEventContent{
MsgType: event.MsgText,
Body: "",
Format: event.FormatHTML,
Expand All @@ -44,7 +45,7 @@ func TestParse_EmptyHTML(t *testing.T) {
}

func TestParse_Plaintext(t *testing.T) {
text, entities := matrixfmt.Parse(formatParams, &event.MessageEventContent{
text, entities := matrixfmt.Parse(context.TODO(), formatParams, &event.MessageEventContent{
MsgType: event.MsgText,
Body: "Hello world!",
})
Expand Down Expand Up @@ -153,7 +154,7 @@ func TestParse_HTML(t *testing.T) {
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
fmt.Println("--------------------------------------------------------------------------------")
parsed := formatParams.Parse(test.in, matrixfmt.NewContext())
parsed := formatParams.Parse(test.in, matrixfmt.NewContext(context.TODO()))
assert.Equal(t, test.out, parsed.String.String())
assert.Equal(t, test.ent, parsed.Entities)
})
Expand Down
9 changes: 6 additions & 3 deletions msgconv/matrixfmt/html.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package matrixfmt

import (
"context"
"fmt"
"math"
"strconv"
Expand Down Expand Up @@ -202,13 +203,15 @@ func (ts TagStack) Has(tag string) bool {
}

type Context struct {
Ctx context.Context
AllowedMentions *event.Mentions
TagStack TagStack
PreserveWhitespace bool
}

func NewContext() Context {
func NewContext(ctx context.Context) Context {
return Context{
Ctx: ctx,
TagStack: make(TagStack, 0, 4),
}
}
Expand All @@ -225,7 +228,7 @@ func (ctx Context) WithWhitespace() Context {

// HTMLParser is a somewhat customizable Matrix HTML parser.
type HTMLParser struct {
GetUUIDFromMXID func(id.UserID) uuid.UUID
GetUUIDFromMXID func(context.Context, id.UserID) uuid.UUID
}

// TaggedString is a string that also contains a HTML tag.
Expand Down Expand Up @@ -356,7 +359,7 @@ func (parser *HTMLParser) linkToString(node *html.Node, ctx Context) *EntityStri
// Mention not allowed, use name as-is
return str
}
u := parser.GetUUIDFromMXID(mxid)
u := parser.GetUUIDFromMXID(ctx.Ctx, mxid)
if u == uuid.Nil {
// Don't include the link for mentions of non-Signal users, the name is enough
return str
Expand Down
7 changes: 4 additions & 3 deletions msgconv/signalfmt/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package signalfmt

import (
"context"
"html"
"strings"

Expand All @@ -36,7 +37,7 @@ type UserInfo struct {
}

type FormatParams struct {
GetUserInfo func(uuid uuid.UUID) UserInfo
GetUserInfo func(ctx context.Context, uuid uuid.UUID) UserInfo
}

type formatContext struct {
Expand All @@ -50,7 +51,7 @@ func (ctx formatContext) TextToHTML(text string) string {
return event.TextToHTML(text)
}

func Parse(message string, ranges []*signalpb.BodyRange, params *FormatParams) *event.MessageEventContent {
func Parse(ctx context.Context, message string, ranges []*signalpb.BodyRange, params *FormatParams) *event.MessageEventContent {
content := &event.MessageEventContent{
MsgType: event.MsgText,
Body: message,
Expand Down Expand Up @@ -93,7 +94,7 @@ func Parse(message string, ranges []*signalpb.BodyRange, params *FormatParams) *
if err != nil {
continue
}
userInfo := params.GetUserInfo(parsed)
userInfo := params.GetUserInfo(ctx, parsed)
if userInfo.MXID == "" {
continue
}
Expand Down
5 changes: 3 additions & 2 deletions msgconv/signalfmt/convert_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package signalfmt_test

import (
"context"
"testing"

"github.com/google/uuid"
Expand All @@ -34,7 +35,7 @@ var realUser = uuid.New()

func TestParse(t *testing.T) {
formatParams := &signalfmt.FormatParams{
GetUserInfo: func(uuid uuid.UUID) signalfmt.UserInfo {
GetUserInfo: func(ctx context.Context, uuid uuid.UUID) signalfmt.UserInfo {
if uuid == realUser {
return signalfmt.UserInfo{
MXID: "@test:example.com",
Expand Down Expand Up @@ -169,7 +170,7 @@ func TestParse(t *testing.T) {
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
parsed := signalfmt.Parse(test.ins, test.ine, formatParams)
parsed := signalfmt.Parse(context.TODO(), test.ins, test.ine, formatParams)
assert.Equal(t, test.body, parsed.Body)
assert.Equal(t, test.html, parsed.FormattedBody)
})
Expand Down
Loading

0 comments on commit 2972a5f

Please sign in to comment.