From 83d41a4e1205378e94787f6103cdd48041739d5f Mon Sep 17 00:00:00 2001 From: Tulir Asokan Date: Thu, 23 Jun 2022 20:25:09 +0300 Subject: [PATCH] Refuse to start bridge if server is missing features --- go.mod | 2 +- go.sum | 4 ++-- main.go | 15 +++++++++++++++ 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index dd956c4..d37c403 100644 --- a/go.mod +++ b/go.mod @@ -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 ( diff --git a/go.sum b/go.sum index dd245f1..e810f55 100644 --- a/go.sum +++ b/go.sum @@ -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= diff --git a/main.go b/main.go index 30be7b6..8ffc4a9 100644 --- a/main.go +++ b/main.go @@ -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),