mirror of
https://github.com/tulir/mautrix-whatsapp
synced 2024-12-15 01:43:49 +01:00
Add option to disable notifications during initial backfill
This commit is contained in:
parent
c6180660c2
commit
934f98119f
5 changed files with 62 additions and 7 deletions
|
@ -50,11 +50,12 @@ type BridgeConfig struct {
|
|||
End bool `yaml:"end"`
|
||||
} `yaml:"call_notices"`
|
||||
|
||||
InitialChatSync int `yaml:"initial_chat_sync_count"`
|
||||
InitialHistoryFill int `yaml:"initial_history_fill_count"`
|
||||
RecoverChatSync int `yaml:"recovery_chat_sync_count"`
|
||||
RecoverHistory bool `yaml:"recovery_history_backfill"`
|
||||
SyncChatMaxAge uint64 `yaml:"sync_max_chat_age"`
|
||||
InitialChatSync int `yaml:"initial_chat_sync_count"`
|
||||
InitialHistoryFill int `yaml:"initial_history_fill_count"`
|
||||
HistoryDisableNotifs bool `yaml:"initial_history_disable_notifications"`
|
||||
RecoverChatSync int `yaml:"recovery_chat_sync_count"`
|
||||
RecoverHistory bool `yaml:"recovery_history_backfill"`
|
||||
SyncChatMaxAge uint64 `yaml:"sync_max_chat_age"`
|
||||
|
||||
SyncWithCustomPuppets bool `yaml:"sync_with_custom_puppets"`
|
||||
LoginSharedSecret string `yaml:"login_shared_secret"`
|
||||
|
|
|
@ -108,6 +108,9 @@ bridge:
|
|||
initial_chat_sync_count: 10
|
||||
# Number of old messages to fill when creating new portal rooms.
|
||||
initial_history_fill_count: 20
|
||||
# Whether or not notifications should be turned off while filling initial history.
|
||||
# Only applicable when using double puppeting.
|
||||
initial_history_disable_notifications: false
|
||||
# Maximum number of chats to sync when recovering from downtime.
|
||||
# Set to -1 to sync all new chats during downtime.
|
||||
recovery_chat_sync_limit: -1
|
||||
|
|
4
go.mod
4
go.mod
|
@ -12,10 +12,10 @@ require (
|
|||
github.com/shurcooL/sanitized_anchor_name v1.0.0 // indirect
|
||||
github.com/skip2/go-qrcode v0.0.0-20191027152451-9434209cb086
|
||||
golang.org/x/image v0.0.0-20200430140353-33d19683fad8
|
||||
gopkg.in/yaml.v2 v2.2.8
|
||||
gopkg.in/yaml.v2 v2.3.0
|
||||
maunium.net/go/mauflag v1.0.0
|
||||
maunium.net/go/maulogger/v2 v2.1.1
|
||||
maunium.net/go/mautrix v0.4.9
|
||||
maunium.net/go/mautrix v0.4.11
|
||||
)
|
||||
|
||||
replace github.com/Rhymen/go-whatsapp => github.com/tulir/go-whatsapp v0.2.8
|
||||
|
|
9
go.sum
9
go.sum
|
@ -24,6 +24,7 @@ github.com/skip2/go-qrcode v0.0.0-20191027152451-9434209cb086 h1:RYiqpb2ii2Z6J4x
|
|||
github.com/skip2/go-qrcode v0.0.0-20191027152451-9434209cb086/go.mod h1:PLPIyL7ikehBD1OAjmKKiOEhbvWyHGaNDjquXMcYABo=
|
||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
|
||||
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||
github.com/tidwall/gjson v1.6.0 h1:9VEQWz6LLMUsUl6PueE49ir4Ka6CzLymOAZDxpFsTDc=
|
||||
github.com/tidwall/gjson v1.6.0/go.mod h1:P256ACg0Mn+j1RXIDXoss50DeIABTYK1PULOJHhxOls=
|
||||
github.com/tidwall/match v1.0.1 h1:PnKP62LPNxHKTwvHHZZzdOAOCtsJTjo6dZLCwpKm5xc=
|
||||
|
@ -41,13 +42,19 @@ golang.org/x/image v0.0.0-20200430140353-33d19683fad8/go.mod h1:FeLwcggjj3mMvU+o
|
|||
golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||
golang.org/x/net v0.0.0-20200301022130-244492dfa37a h1:GuSPYbZzB5/dcLNCwLQLsg3obCJtX9IJhpXkvY7kzk0=
|
||||
golang.org/x/net v0.0.0-20200301022130-244492dfa37a/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||
golang.org/x/net v0.0.0-20200602114024-627f9648deb9 h1:pNX+40auqi2JqRfOP1akLGtYcn15TUbkhwuCO3foqqM=
|
||||
golang.org/x/net v0.0.0-20200602114024-627f9648deb9/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A=
|
||||
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||
gopkg.in/yaml.v2 v2.2.8 h1:obN1ZagJSUGI0Ek/LBmuj4SNLPfIny3KsKFopxRdj10=
|
||||
gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||
gopkg.in/yaml.v2 v2.3.0 h1:clyUAQHOM3G0M3f5vQj7LuJrETvjVot3Z5el9nffUtU=
|
||||
gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
maunium.net/go/mauflag v1.0.0 h1:YiaRc0tEI3toYtJMRIfjP+jklH45uDHtT80nUamyD4M=
|
||||
maunium.net/go/mauflag v1.0.0/go.mod h1:nLivPOpTpHnpzEh8jEdSL9UqO9+/KBJFmNRlwKfkPeA=
|
||||
maunium.net/go/maulogger/v2 v2.1.1 h1:NAZNc6XUFJzgzfewCzVoGkxNAsblLCSSEdtDuIjP0XA=
|
||||
|
@ -56,3 +63,5 @@ maunium.net/go/mautrix v0.4.8 h1:ut6Bx+FB1z8tq3XPRS4aTaBhlMESD0y3P8f6fmO6WH4=
|
|||
maunium.net/go/mautrix v0.4.8/go.mod h1:8Y+NqmROJyWYvvP4yPfX9tLM59VCfgE/kcQ0SeX68ho=
|
||||
maunium.net/go/mautrix v0.4.9 h1:zp4ihCuSfonsTbwOmBH5/akWwp4QEii+SU5QRAC9Foo=
|
||||
maunium.net/go/mautrix v0.4.9/go.mod h1:8Y+NqmROJyWYvvP4yPfX9tLM59VCfgE/kcQ0SeX68ho=
|
||||
maunium.net/go/mautrix v0.4.11 h1:cONVoAkD7AOvtzEMvuuq79Y+2vRrNKfpKZoR8HdyPAw=
|
||||
maunium.net/go/mautrix v0.4.11/go.mod h1:LnkFnB1yjCbb8V+upoEHDGvI/F38NHSTWYCe2RRJgSY=
|
||||
|
|
42
portal.go
42
portal.go
|
@ -45,6 +45,7 @@ import (
|
|||
"maunium.net/go/mautrix/event"
|
||||
"maunium.net/go/mautrix/format"
|
||||
"maunium.net/go/mautrix/id"
|
||||
"maunium.net/go/mautrix/pushrules"
|
||||
|
||||
"maunium.net/go/mautrix-whatsapp/database"
|
||||
"maunium.net/go/mautrix-whatsapp/types"
|
||||
|
@ -648,6 +649,45 @@ func (portal *Portal) beginBackfill() func() {
|
|||
}
|
||||
}
|
||||
|
||||
func (portal *Portal) disableNotifications(user *User) {
|
||||
if !portal.bridge.Config.Bridge.HistoryDisableNotifs {
|
||||
return
|
||||
}
|
||||
puppet := portal.bridge.GetPuppetByCustomMXID(user.MXID)
|
||||
if puppet == nil || puppet.customIntent == nil {
|
||||
return
|
||||
}
|
||||
portal.log.Debugfln("Disabling notifications for %s for backfilling", user.MXID)
|
||||
ruleID := fmt.Sprintf("net.maunium.silence_while_backfilling.%s", portal.MXID)
|
||||
err := puppet.customIntent.PutPushRule("global", pushrules.OverrideRule, ruleID, &mautrix.ReqPutPushRule{
|
||||
Actions: []pushrules.PushActionType{pushrules.ActionDontNotify},
|
||||
Conditions: []pushrules.PushCondition{{
|
||||
Kind: pushrules.KindEventMatch,
|
||||
Key: "room_id",
|
||||
Pattern: string(portal.MXID),
|
||||
}},
|
||||
})
|
||||
if err != nil {
|
||||
portal.log.Warnfln("Failed to disable notifications for %s while backfilling: %v", user.MXID, err)
|
||||
}
|
||||
}
|
||||
|
||||
func (portal *Portal) enableNotifications(user *User) {
|
||||
if !portal.bridge.Config.Bridge.HistoryDisableNotifs {
|
||||
return
|
||||
}
|
||||
puppet := portal.bridge.GetPuppetByCustomMXID(user.MXID)
|
||||
if puppet == nil || puppet.customIntent == nil {
|
||||
return
|
||||
}
|
||||
portal.log.Debugfln("Re-enabling notifications for %s after backfilling", user.MXID)
|
||||
ruleID := fmt.Sprintf("net.maunium.silence_while_backfilling.%s", portal.MXID)
|
||||
err := puppet.customIntent.DeletePushRule("global", pushrules.OverrideRule, ruleID)
|
||||
if err != nil {
|
||||
portal.log.Warnfln("Failed to re-enable notifications for %s after backfilling: %v", user.MXID, err)
|
||||
}
|
||||
}
|
||||
|
||||
func (portal *Portal) FillInitialHistory(user *User) error {
|
||||
if portal.bridge.Config.Bridge.InitialHistoryFill == 0 {
|
||||
return nil
|
||||
|
@ -693,7 +733,9 @@ func (portal *Portal) FillInitialHistory(user *User) error {
|
|||
break
|
||||
}
|
||||
}
|
||||
portal.disableNotifications(user)
|
||||
portal.handleHistory(user, messages)
|
||||
portal.enableNotifications(user)
|
||||
portal.log.Infoln("Initial history fill complete")
|
||||
return nil
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue