Add option to disable status bridging. Fixes #166

This commit is contained in:
Tulir Asokan 2021-06-01 15:28:15 +03:00
parent 74e21b8e1d
commit 06b84c4bb9
5 changed files with 24 additions and 9 deletions

View file

@ -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

View file

@ -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.

View file

@ -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

View file

@ -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)

View file

@ -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 {