Browse Source

Add option to resend bridge info to all portals

Tulir Asokan 5 years ago
parent
commit
59e2015fa7
6 changed files with 30 additions and 1 deletions
  1. 1 0
      config/bridge.go
  2. 4 0
      example-config.yaml
  3. 1 1
      go.mod
  4. 2 0
      go.sum
  5. 17 0
      main.go
  6. 5 0
      portal.go

+ 1 - 0
config/bridge.go

@@ -62,6 +62,7 @@ type BridgeConfig struct {
 
 
 	InviteOwnPuppetForBackfilling bool `yaml:"invite_own_puppet_for_backfilling"`
 	InviteOwnPuppetForBackfilling bool `yaml:"invite_own_puppet_for_backfilling"`
 	PrivateChatPortalMeta         bool `yaml:"private_chat_portal_meta"`
 	PrivateChatPortalMeta         bool `yaml:"private_chat_portal_meta"`
+	ResendBridgeInfo              bool `yaml:"resend_bridge_info"`
 
 
 	WhatsappThumbnail bool `yaml:"whatsapp_thumbnail"`
 	WhatsappThumbnail bool `yaml:"whatsapp_thumbnail"`
 
 

+ 4 - 0
example-config.yaml

@@ -141,6 +141,10 @@ bridge:
     # chat portal rooms. This can be useful if the previous field works fine,
     # chat portal rooms. This can be useful if the previous field works fine,
     # but causes room avatar/name bugs.
     # but causes room avatar/name bugs.
     private_chat_portal_meta: false
     private_chat_portal_meta: false
+    # Set this to true to tell the bridge to re-send m.bridge events to all rooms on the next run.
+    # This field will automatically be changed back to false after it,
+    # except if the config file is not writable.
+    resend_bridge_info: false
 
 
     # Whether or not thumbnails from WhatsApp should be sent.
     # Whether or not thumbnails from WhatsApp should be sent.
     # They're disabled by default due to very low resolution.
     # They're disabled by default due to very low resolution.

+ 1 - 1
go.mod

@@ -15,7 +15,7 @@ require (
 	gopkg.in/yaml.v2 v2.3.0
 	gopkg.in/yaml.v2 v2.3.0
 	maunium.net/go/mauflag v1.0.0
 	maunium.net/go/mauflag v1.0.0
 	maunium.net/go/maulogger/v2 v2.1.1
 	maunium.net/go/maulogger/v2 v2.1.1
-	maunium.net/go/mautrix v0.5.0-rc.3
+	maunium.net/go/mautrix v0.5.0
 )
 )
 
 
 replace github.com/Rhymen/go-whatsapp => github.com/tulir/go-whatsapp v0.2.8
 replace github.com/Rhymen/go-whatsapp => github.com/tulir/go-whatsapp v0.2.8

+ 2 - 0
go.sum

@@ -69,3 +69,5 @@ maunium.net/go/mautrix v0.5.0-rc.2 h1:ohx+dprvMS6Txm+suMx5pbjl0rjDpfftFxgXhx/+Us
 maunium.net/go/mautrix v0.5.0-rc.2/go.mod h1:LnkFnB1yjCbb8V+upoEHDGvI/F38NHSTWYCe2RRJgSY=
 maunium.net/go/mautrix v0.5.0-rc.2/go.mod h1:LnkFnB1yjCbb8V+upoEHDGvI/F38NHSTWYCe2RRJgSY=
 maunium.net/go/mautrix v0.5.0-rc.3 h1:ltb6mF6pck1YzEkuC13V4UtSGDIxaq+XqzIdSg7vgMI=
 maunium.net/go/mautrix v0.5.0-rc.3 h1:ltb6mF6pck1YzEkuC13V4UtSGDIxaq+XqzIdSg7vgMI=
 maunium.net/go/mautrix v0.5.0-rc.3/go.mod h1:LnkFnB1yjCbb8V+upoEHDGvI/F38NHSTWYCe2RRJgSY=
 maunium.net/go/mautrix v0.5.0-rc.3/go.mod h1:LnkFnB1yjCbb8V+upoEHDGvI/F38NHSTWYCe2RRJgSY=
+maunium.net/go/mautrix v0.5.0 h1:lEVvdrF5leCon005PDs8yO8VTLgEFZ8lWATaRmwCj0M=
+maunium.net/go/mautrix v0.5.0/go.mod h1:LnkFnB1yjCbb8V+upoEHDGvI/F38NHSTWYCe2RRJgSY=

+ 17 - 0
main.go

@@ -283,6 +283,23 @@ func (bridge *Bridge) Start() {
 		go bridge.Crypto.Start()
 		go bridge.Crypto.Start()
 	}
 	}
 	go bridge.StartUsers()
 	go bridge.StartUsers()
+
+	if bridge.Config.Bridge.ResendBridgeInfo {
+		go bridge.ResendBridgeInfo()
+	}
+}
+
+func (bridge *Bridge) ResendBridgeInfo() {
+	bridge.Config.Bridge.ResendBridgeInfo = false
+	err := bridge.Config.Save(*configPath)
+	if err != nil {
+		bridge.Log.Errorln("Failed to save config after setting resend_bridge_info to false:", err)
+	}
+	bridge.Log.Infoln("Re-sending bridge info state event to all portals")
+	for _, portal := range bridge.GetAllPortals() {
+		portal.UpdateBridgeInfo()
+	}
+	bridge.Log.Infoln("Finished re-sending bridge info state events")
 }
 }
 
 
 func (bridge *Bridge) LoadRelaybot() {
 func (bridge *Bridge) LoadRelaybot() {

+ 5 - 0
portal.go

@@ -835,6 +835,11 @@ func (portal *Portal) getBridgeInfo() (string, event.Content) {
 }
 }
 
 
 func (portal *Portal) UpdateBridgeInfo() {
 func (portal *Portal) UpdateBridgeInfo() {
+	if len(portal.MXID) == 0 {
+		portal.log.Debugln("Not updating bridge info: no Matrix room created")
+		return
+	}
+	portal.log.Debugln("Updating bridge info...")
 	stateKey, content := portal.getBridgeInfo()
 	stateKey, content := portal.getBridgeInfo()
 	_, err := portal.MainIntent().SendStateEvent(portal.MXID, StateBridgeInfo, stateKey, content)
 	_, err := portal.MainIntent().SendStateEvent(portal.MXID, StateBridgeInfo, stateKey, content)
 	if err != nil {
 	if err != nil {