Disallow sending status broadcast messages by default

Sending to big contact lists doesn't really work yet
This commit is contained in:
Tulir Asokan 2022-06-13 20:01:39 +03:00
parent 0796d14133
commit 43d8fc5d2b
4 changed files with 22 additions and 1 deletions

View file

@ -107,6 +107,7 @@ type BridgeConfig struct {
FederateRooms bool `yaml:"federate_rooms"` FederateRooms bool `yaml:"federate_rooms"`
URLPreviews bool `yaml:"url_previews"` URLPreviews bool `yaml:"url_previews"`
DisableStatusBroadcastSend bool `yaml:"disable_status_broadcast_send"`
DisappearingMessagesInGroups bool `yaml:"disappearing_messages_in_groups"` DisappearingMessagesInGroups bool `yaml:"disappearing_messages_in_groups"`
DisableBridgeAlerts bool `yaml:"disable_bridge_alerts"` DisableBridgeAlerts bool `yaml:"disable_bridge_alerts"`

View file

@ -80,6 +80,7 @@ func DoUpgrade(helper *up.Helper) {
helper.Copy(up.Str|up.Null, "bridge", "pinned_tag") helper.Copy(up.Str|up.Null, "bridge", "pinned_tag")
helper.Copy(up.Bool, "bridge", "tag_only_on_create") helper.Copy(up.Bool, "bridge", "tag_only_on_create")
helper.Copy(up.Bool, "bridge", "enable_status_broadcast") helper.Copy(up.Bool, "bridge", "enable_status_broadcast")
helper.Copy(up.Bool, "bridge", "disable_status_broadcast_send")
helper.Copy(up.Bool, "bridge", "mute_status_broadcast") helper.Copy(up.Bool, "bridge", "mute_status_broadcast")
helper.Copy(up.Str|up.Null, "bridge", "status_broadcast_tag") helper.Copy(up.Str|up.Null, "bridge", "status_broadcast_tag")
helper.Copy(up.Bool, "bridge", "whatsapp_thumbnail") helper.Copy(up.Bool, "bridge", "whatsapp_thumbnail")

View file

@ -249,6 +249,9 @@ bridge:
# Should WhatsApp status messages be bridged into a Matrix room? # Should WhatsApp status messages be bridged into a Matrix room?
# Disabling this won't affect already created status broadcast rooms. # Disabling this won't affect already created status broadcast rooms.
enable_status_broadcast: true enable_status_broadcast: true
# Should sending WhatsApp status messages be allowed?
# This can cause issues if the user has lots of contacts, so it's disabled by default.
disable_status_broadcast_send: true
# Should the status broadcast room be muted and moved into low priority by default? # Should the status broadcast room be muted and moved into low priority by default?
# This is only applied when creating the room, the user can unmute it later. # This is only applied when creating the room, the user can unmute it later.
mute_status_broadcast: true mute_status_broadcast: true

View file

@ -2907,6 +2907,9 @@ var (
errTargetIsFake = errors.New("target is a fake event") errTargetIsFake = errors.New("target is a fake event")
errTargetSentBySomeoneElse = errors.New("target is a fake event") errTargetSentBySomeoneElse = errors.New("target is a fake event")
errBroadcastReactionNotSupported = errors.New("reacting to status messages is not currently supported")
errBroadcastSendDisabled = errors.New("sending status messages is disabled")
errMessageDisconnected = &whatsmeow.DisconnectedError{Action: "message send"} errMessageDisconnected = &whatsmeow.DisconnectedError{Action: "message send"}
errMessageRetryDisconnected = &whatsmeow.DisconnectedError{Action: "message send (retry)"} errMessageRetryDisconnected = &whatsmeow.DisconnectedError{Action: "message send (retry)"}
) )
@ -2918,7 +2921,9 @@ func errorToStatusReason(err error) (reason event.MessageStatusReason, isCertain
errors.Is(err, errUnknownMsgType), errors.Is(err, errUnknownMsgType),
errors.Is(err, errInvalidGeoURI), errors.Is(err, errInvalidGeoURI),
errors.Is(err, whatsmeow.ErrUnknownServer), errors.Is(err, whatsmeow.ErrUnknownServer),
errors.Is(err, whatsmeow.ErrRecipientADJID): errors.Is(err, whatsmeow.ErrRecipientADJID),
errors.Is(err, errBroadcastReactionNotSupported),
errors.Is(err, errBroadcastSendDisabled):
return event.MessageStatusUnsupported, true, false, true return event.MessageStatusUnsupported, true, false, true
case errors.Is(err, errTargetNotFound), case errors.Is(err, errTargetNotFound),
errors.Is(err, errTargetIsFake), errors.Is(err, errTargetIsFake),
@ -3033,6 +3038,9 @@ func (portal *Portal) HandleMatrixMessage(sender *User, evt *event.Event) {
if err := portal.canBridgeFrom(sender, true); err != nil { if err := portal.canBridgeFrom(sender, true); err != nil {
go portal.sendMessageMetrics(evt, err, "Ignoring") go portal.sendMessageMetrics(evt, err, "Ignoring")
return return
} else if portal.Key.JID == types.StatusBroadcastJID && portal.bridge.Config.Bridge.DisableStatusBroadcastSend {
go portal.sendMessageMetrics(evt, errBroadcastSendDisabled, "Ignoring")
return
} }
portal.log.Debugfln("Received message %s from %s", evt.ID, evt.Sender) portal.log.Debugfln("Received message %s from %s", evt.ID, evt.Sender)
msg, sender, err := portal.convertMatrixMessage(sender, evt) msg, sender, err := portal.convertMatrixMessage(sender, evt)
@ -3055,6 +3063,11 @@ func (portal *Portal) HandleMatrixReaction(sender *User, evt *event.Event) {
if err := portal.canBridgeFrom(sender, false); err != nil { if err := portal.canBridgeFrom(sender, false); err != nil {
go portal.sendMessageMetrics(evt, err, "Ignoring") go portal.sendMessageMetrics(evt, err, "Ignoring")
return return
} else if portal.Key.JID.Server == types.BroadcastServer {
// TODO implement this, probably by only sending the reaction to the sender of the status message?
// (whatsapp hasn't published the feature yet)
go portal.sendMessageMetrics(evt, errBroadcastReactionNotSupported, "Ignoring")
return
} }
content, ok := evt.Content.Parsed.(*event.ReactionEventContent) content, ok := evt.Content.Parsed.(*event.ReactionEventContent)
@ -3162,6 +3175,9 @@ func (portal *Portal) HandleMatrixRedaction(sender *User, evt *event.Event) {
go portal.sendMessageMetrics(evt, errTargetIsFake, "Ignoring") go portal.sendMessageMetrics(evt, errTargetIsFake, "Ignoring")
} else if msg.Sender.User != sender.JID.User { } else if msg.Sender.User != sender.JID.User {
go portal.sendMessageMetrics(evt, errTargetSentBySomeoneElse, "Ignoring") go portal.sendMessageMetrics(evt, errTargetSentBySomeoneElse, "Ignoring")
} else if portal.Key.JID == types.StatusBroadcastJID && portal.bridge.Config.Bridge.DisableStatusBroadcastSend {
go portal.sendMessageMetrics(evt, errBroadcastSendDisabled, "Ignoring")
return
} else if msg.Type == database.MsgReaction { } else if msg.Type == database.MsgReaction {
if reaction := portal.bridge.DB.Reaction.GetByMXID(evt.Redacts); reaction == nil { if reaction := portal.bridge.DB.Reaction.GetByMXID(evt.Redacts); reaction == nil {
go portal.sendMessageMetrics(evt, errReactionDatabaseNotFound, "Ignoring") go portal.sendMessageMetrics(evt, errReactionDatabaseNotFound, "Ignoring")