Refuse to start bridge if server is missing features

This commit is contained in:
Tulir Asokan 2022-06-23 20:25:09 +03:00
parent 1aed6aa94d
commit 83d41a4e12
3 changed files with 18 additions and 3 deletions

2
go.mod
View file

@ -15,7 +15,7 @@ require (
golang.org/x/net v0.0.0-20220513224357-95641704303c
google.golang.org/protobuf v1.28.0
maunium.net/go/maulogger/v2 v2.3.2
maunium.net/go/mautrix v0.11.1-0.20220623114205-916294467210
maunium.net/go/mautrix v0.11.1-0.20220623172243-579a4753b77a
)
require (

4
go.sum
View file

@ -107,5 +107,5 @@ 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.3.2 h1:1XmIYmMd3PoQfp9J+PaHhpt80zpfmMqaShzUTC7FwY0=
maunium.net/go/maulogger/v2 v2.3.2/go.mod h1:TYWy7wKwz/tIXTpsx8G3mZseIRiC5DoMxSZazOHy68A=
maunium.net/go/mautrix v0.11.1-0.20220623114205-916294467210 h1:kGfVCBSV1QLMk09/4ufnGk7lMYAZuLNdlFOS+5D7XHU=
maunium.net/go/mautrix v0.11.1-0.20220623114205-916294467210/go.mod h1:CiKpMhAx5QZFHK03jpWb0iKI3sGU8x6+LfsOjDrcO8I=
maunium.net/go/mautrix v0.11.1-0.20220623172243-579a4753b77a h1:KcGbhXMmBO1WOLwaDRf4awKYCQcNp0178Km0qEHlj0s=
maunium.net/go/mautrix v0.11.1-0.20220623172243-579a4753b77a/go.mod h1:CiKpMhAx5QZFHK03jpWb0iKI3sGU8x6+LfsOjDrcO8I=

15
main.go
View file

@ -33,6 +33,7 @@ import (
"go.mau.fi/whatsmeow/store/sqlstore"
"go.mau.fi/whatsmeow/types"
"maunium.net/go/mautrix"
"maunium.net/go/mautrix/bridge"
"maunium.net/go/mautrix/bridge/commands"
"maunium.net/go/mautrix/event"
@ -253,6 +254,20 @@ func (br *WABridge) GetConfigPtr() interface{} {
return br.Config
}
const unstableFeatureBatchSending = "org.matrix.msc2716"
func (br *WABridge) CheckFeatures(versions *mautrix.RespVersions) (string, bool) {
if br.Config.Bridge.HistorySync.Backfill {
supported, known := versions.UnstableFeatures[unstableFeatureBatchSending]
if !known {
return "Backfilling is enabled in bridge config, but server does not support MSC2716 batch sending", false
} else if !supported {
return "Backfilling is enabled in bridge config, but MSC2716 batch sending is not enabled on server", false
}
}
return "", true
}
func main() {
br := &WABridge{
usersByMXID: make(map[id.UserID]*User),