diff --git a/config/bridge.go b/config/bridge.go index 4fc7c02..75656e2 100644 --- a/config/bridge.go +++ b/config/bridge.go @@ -75,6 +75,7 @@ type BridgeConfig struct { PinnedTag string `yaml:"pinned_tag"` TagOnlyOnCreate bool `yaml:"tag_only_on_create"` MarkReadOnlyOnCreate bool `yaml:"mark_read_only_on_create"` + EnableStatusBroadcast bool `yaml:"enable_status_broadcast"` WhatsappThumbnail bool `yaml:"whatsapp_thumbnail"` @@ -134,6 +135,7 @@ func (bc *BridgeConfig) setDefaults() { bc.InviteOwnPuppetForBackfilling = true bc.PrivateChatPortalMeta = false bc.BridgeNotices = true + bc.EnableStatusBroadcast = true } type umBridgeConfig BridgeConfig diff --git a/example-config.yaml b/example-config.yaml index 2fbf2ec..2971e33 100644 --- a/example-config.yaml +++ b/example-config.yaml @@ -7,7 +7,7 @@ homeserver: # The URL to push real-time bridge status to. # If set, the bridge will make POST requests to this URL whenever a user's whatsapp connection state changes. - # The bridge will use the as_token to authorize requests. + # The bridge will use the appservice as_token to authorize requests. status_endpoint: null # Application service host/registration related details. @@ -195,6 +195,9 @@ bridge: pinned_tag: null # Whether or not mute status and tags should only be bridged when the portal room is created. tag_only_on_create: true + # Whether or not WhatsApp status messages should be bridged into a Matrix room. + # Disabling this won't affect already created status broadcast rooms. + enable_status_broadcast: true # Whether or not thumbnails from WhatsApp should be sent. # They're disabled by default due to very low resolution. diff --git a/matrix.go b/matrix.go index b413e61..28376be 100644 --- a/matrix.go +++ b/matrix.go @@ -165,7 +165,7 @@ func (mx *MatrixHandler) handlePrivatePortal(roomID id.RoomID, inviter *User, pu func (mx *MatrixHandler) createPrivatePortalFromInvite(roomID id.RoomID, inviter *User, puppet *Puppet, portal *Portal) { portal.MXID = roomID - portal.Topic = "WhatsApp private chat" + portal.Topic = PrivateChatTopic _, _ = portal.MainIntent().SetRoomTopic(portal.MXID, portal.Topic) if portal.bridge.Config.Bridge.PrivateChatPortalMeta { portal.Name = puppet.Displayname diff --git a/portal.go b/portal.go index 48cf5ee..35afc87 100644 --- a/portal.go +++ b/portal.go @@ -61,6 +61,8 @@ const StatusBroadcastTopic = "WhatsApp status updates from your contacts" const StatusBroadcastName = "WhatsApp Status Broadcast" const BroadcastTopic = "WhatsApp broadcast list" const UnnamedBroadcastName = "Unnamed broadcast list" +const PrivateChatTopic = "WhatsApp private chat" +var ErrStatusBroadcastDisabled = errors.New("status bridging is disabled") func (bridge *Bridge) GetPortalByMXID(mxid id.RoomID) *Portal { bridge.portalsLock.Lock() @@ -655,7 +657,7 @@ func (portal *Portal) ensureUserInvited(user *User) { } } -func (portal *Portal) Sync(user *User, contact whatsapp.Contact) { +func (portal *Portal) Sync(user *User, contact whatsapp.Contact) bool { portal.log.Infoln("Syncing portal for", user.MXID) if user.IsRelaybot { @@ -670,7 +672,7 @@ func (portal *Portal) Sync(user *User, contact whatsapp.Contact) { err := portal.CreateMatrixRoom(user) if err != nil { portal.log.Errorln("Failed to create portal room:", err) - return + return false } } else { portal.ensureUserInvited(user) @@ -685,6 +687,7 @@ func (portal *Portal) Sync(user *User, contact whatsapp.Contact) { portal.Update() portal.UpdateBridgeInfo() } + return true } func (portal *Portal) GetBasePowerLevels() *event.PowerLevelsEventContent { @@ -1066,10 +1069,14 @@ func (portal *Portal) CreateMatrixRoom(user *User) error { } else { portal.Name = "" } - portal.Topic = "WhatsApp private chat" + portal.Topic = PrivateChatTopic } else if portal.IsStatusBroadcastList() { - portal.Name = "WhatsApp Status Broadcast" - portal.Topic = "WhatsApp status updates from your contacts" + if !portal.bridge.Config.Bridge.EnableStatusBroadcast { + portal.log.Debugln("Status bridging is disabled in config, not creating room after all") + return ErrStatusBroadcastDisabled + } + portal.Name = StatusBroadcastName + portal.Topic = StatusBroadcastTopic } else if portal.IsBroadcastList() { var err error broadcastMetadata, err = user.Conn.GetBroadcastMetadata(portal.Key.JID) diff --git a/user.go b/user.go index 7f8493e..eafd2ce 100644 --- a/user.go +++ b/user.go @@ -751,7 +751,7 @@ type CustomReadReceipt struct { } func (user *User) syncChatDoublePuppetDetails(doublePuppet *Puppet, chat Chat, justCreated bool) { - if doublePuppet == nil || doublePuppet.CustomIntent() == nil { + if doublePuppet == nil || doublePuppet.CustomIntent() == nil || len(chat.Portal.MXID) == 0 { return } intent := doublePuppet.CustomIntent() @@ -776,7 +776,10 @@ func (user *User) syncChatDoublePuppetDetails(doublePuppet *Puppet, chat Chat, j func (user *User) syncPortal(chat Chat) { // Don't sync unless chat meta sync is enabled or portal doesn't exist if user.bridge.Config.Bridge.ChatMetaSync || len(chat.Portal.MXID) == 0 { - chat.Portal.Sync(user, chat.Contact) + failedToCreate := chat.Portal.Sync(user, chat.Contact) + if failedToCreate { + return + } } err := chat.Portal.BackfillHistory(user, chat.LastMessageTime) if err != nil {