forked from MirrorHub/mautrix-whatsapp
Add option to disable status bridging. Fixes #166
This commit is contained in:
parent
74e21b8e1d
commit
06b84c4bb9
5 changed files with 24 additions and 9 deletions
|
@ -75,6 +75,7 @@ type BridgeConfig struct {
|
||||||
PinnedTag string `yaml:"pinned_tag"`
|
PinnedTag string `yaml:"pinned_tag"`
|
||||||
TagOnlyOnCreate bool `yaml:"tag_only_on_create"`
|
TagOnlyOnCreate bool `yaml:"tag_only_on_create"`
|
||||||
MarkReadOnlyOnCreate bool `yaml:"mark_read_only_on_create"`
|
MarkReadOnlyOnCreate bool `yaml:"mark_read_only_on_create"`
|
||||||
|
EnableStatusBroadcast bool `yaml:"enable_status_broadcast"`
|
||||||
|
|
||||||
WhatsappThumbnail bool `yaml:"whatsapp_thumbnail"`
|
WhatsappThumbnail bool `yaml:"whatsapp_thumbnail"`
|
||||||
|
|
||||||
|
@ -134,6 +135,7 @@ func (bc *BridgeConfig) setDefaults() {
|
||||||
bc.InviteOwnPuppetForBackfilling = true
|
bc.InviteOwnPuppetForBackfilling = true
|
||||||
bc.PrivateChatPortalMeta = false
|
bc.PrivateChatPortalMeta = false
|
||||||
bc.BridgeNotices = true
|
bc.BridgeNotices = true
|
||||||
|
bc.EnableStatusBroadcast = true
|
||||||
}
|
}
|
||||||
|
|
||||||
type umBridgeConfig BridgeConfig
|
type umBridgeConfig BridgeConfig
|
||||||
|
|
|
@ -7,7 +7,7 @@ homeserver:
|
||||||
|
|
||||||
# The URL to push real-time bridge status to.
|
# 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.
|
# 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
|
status_endpoint: null
|
||||||
|
|
||||||
# Application service host/registration related details.
|
# Application service host/registration related details.
|
||||||
|
@ -195,6 +195,9 @@ bridge:
|
||||||
pinned_tag: null
|
pinned_tag: null
|
||||||
# Whether or not mute status and tags should only be bridged when the portal room is created.
|
# Whether or not mute status and tags should only be bridged when the portal room is created.
|
||||||
tag_only_on_create: true
|
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.
|
# 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.
|
||||||
|
|
|
@ -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) {
|
func (mx *MatrixHandler) createPrivatePortalFromInvite(roomID id.RoomID, inviter *User, puppet *Puppet, portal *Portal) {
|
||||||
portal.MXID = roomID
|
portal.MXID = roomID
|
||||||
portal.Topic = "WhatsApp private chat"
|
portal.Topic = PrivateChatTopic
|
||||||
_, _ = portal.MainIntent().SetRoomTopic(portal.MXID, portal.Topic)
|
_, _ = portal.MainIntent().SetRoomTopic(portal.MXID, portal.Topic)
|
||||||
if portal.bridge.Config.Bridge.PrivateChatPortalMeta {
|
if portal.bridge.Config.Bridge.PrivateChatPortalMeta {
|
||||||
portal.Name = puppet.Displayname
|
portal.Name = puppet.Displayname
|
||||||
|
|
17
portal.go
17
portal.go
|
@ -61,6 +61,8 @@ const StatusBroadcastTopic = "WhatsApp status updates from your contacts"
|
||||||
const StatusBroadcastName = "WhatsApp Status Broadcast"
|
const StatusBroadcastName = "WhatsApp Status Broadcast"
|
||||||
const BroadcastTopic = "WhatsApp broadcast list"
|
const BroadcastTopic = "WhatsApp broadcast list"
|
||||||
const UnnamedBroadcastName = "Unnamed 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 {
|
func (bridge *Bridge) GetPortalByMXID(mxid id.RoomID) *Portal {
|
||||||
bridge.portalsLock.Lock()
|
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)
|
portal.log.Infoln("Syncing portal for", user.MXID)
|
||||||
|
|
||||||
if user.IsRelaybot {
|
if user.IsRelaybot {
|
||||||
|
@ -670,7 +672,7 @@ func (portal *Portal) Sync(user *User, contact whatsapp.Contact) {
|
||||||
err := portal.CreateMatrixRoom(user)
|
err := portal.CreateMatrixRoom(user)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
portal.log.Errorln("Failed to create portal room:", err)
|
portal.log.Errorln("Failed to create portal room:", err)
|
||||||
return
|
return false
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
portal.ensureUserInvited(user)
|
portal.ensureUserInvited(user)
|
||||||
|
@ -685,6 +687,7 @@ func (portal *Portal) Sync(user *User, contact whatsapp.Contact) {
|
||||||
portal.Update()
|
portal.Update()
|
||||||
portal.UpdateBridgeInfo()
|
portal.UpdateBridgeInfo()
|
||||||
}
|
}
|
||||||
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
func (portal *Portal) GetBasePowerLevels() *event.PowerLevelsEventContent {
|
func (portal *Portal) GetBasePowerLevels() *event.PowerLevelsEventContent {
|
||||||
|
@ -1066,10 +1069,14 @@ func (portal *Portal) CreateMatrixRoom(user *User) error {
|
||||||
} else {
|
} else {
|
||||||
portal.Name = ""
|
portal.Name = ""
|
||||||
}
|
}
|
||||||
portal.Topic = "WhatsApp private chat"
|
portal.Topic = PrivateChatTopic
|
||||||
} else if portal.IsStatusBroadcastList() {
|
} else if portal.IsStatusBroadcastList() {
|
||||||
portal.Name = "WhatsApp Status Broadcast"
|
if !portal.bridge.Config.Bridge.EnableStatusBroadcast {
|
||||||
portal.Topic = "WhatsApp status updates from your contacts"
|
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() {
|
} else if portal.IsBroadcastList() {
|
||||||
var err error
|
var err error
|
||||||
broadcastMetadata, err = user.Conn.GetBroadcastMetadata(portal.Key.JID)
|
broadcastMetadata, err = user.Conn.GetBroadcastMetadata(portal.Key.JID)
|
||||||
|
|
7
user.go
7
user.go
|
@ -751,7 +751,7 @@ type CustomReadReceipt struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (user *User) syncChatDoublePuppetDetails(doublePuppet *Puppet, chat Chat, justCreated bool) {
|
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
|
return
|
||||||
}
|
}
|
||||||
intent := doublePuppet.CustomIntent()
|
intent := doublePuppet.CustomIntent()
|
||||||
|
@ -776,7 +776,10 @@ func (user *User) syncChatDoublePuppetDetails(doublePuppet *Puppet, chat Chat, j
|
||||||
func (user *User) syncPortal(chat Chat) {
|
func (user *User) syncPortal(chat Chat) {
|
||||||
// Don't sync unless chat meta sync is enabled or portal doesn't exist
|
// 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 {
|
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)
|
err := chat.Portal.BackfillHistory(user, chat.LastMessageTime)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
Loading…
Reference in a new issue