forked from MirrorHub/mautrix-whatsapp
Add option to limit age of chats to create portals for
This commit is contained in:
parent
4f11d41a60
commit
e3aed76f7a
|
@ -720,7 +720,7 @@ func (handler *CommandHandler) CommandDeleteAllPortals(ce *CommandEvent) {
|
||||||
var portalsToDelete []*Portal
|
var portalsToDelete []*Portal
|
||||||
|
|
||||||
if ce.User.Admin {
|
if ce.User.Admin {
|
||||||
portals = portalsToDelete
|
portalsToDelete = portals
|
||||||
} else {
|
} else {
|
||||||
portalsToDelete = portals[:0]
|
portalsToDelete = portals[:0]
|
||||||
for _, portal := range portals {
|
for _, portal := range portals {
|
||||||
|
|
|
@ -31,8 +31,8 @@ type BridgeConfig struct {
|
||||||
UsernameTemplate string `yaml:"username_template"`
|
UsernameTemplate string `yaml:"username_template"`
|
||||||
DisplaynameTemplate string `yaml:"displayname_template"`
|
DisplaynameTemplate string `yaml:"displayname_template"`
|
||||||
|
|
||||||
DeliveryReceipts bool `yaml:"delivery_receipts"`
|
DeliveryReceipts bool `yaml:"delivery_receipts"`
|
||||||
PortalMessageBuffer int `yaml:"portal_message_buffer"`
|
PortalMessageBuffer int `yaml:"portal_message_buffer"`
|
||||||
|
|
||||||
CallNotices struct {
|
CallNotices struct {
|
||||||
Start bool `yaml:"start"`
|
Start bool `yaml:"start"`
|
||||||
|
@ -40,9 +40,10 @@ type BridgeConfig struct {
|
||||||
} `yaml:"call_notices"`
|
} `yaml:"call_notices"`
|
||||||
|
|
||||||
HistorySync struct {
|
HistorySync struct {
|
||||||
CreatePortals bool `yaml:"create_portals"`
|
CreatePortals bool `yaml:"create_portals"`
|
||||||
Backfill bool `yaml:"backfill"`
|
MaxAge int64 `yaml:"max_age"`
|
||||||
DoublePuppetBackfill bool `yaml:"double_puppet_backfill"`
|
Backfill bool `yaml:"backfill"`
|
||||||
|
DoublePuppetBackfill bool `yaml:"double_puppet_backfill"`
|
||||||
} `yaml:"history_sync"`
|
} `yaml:"history_sync"`
|
||||||
UserAvatarSync bool `yaml:"user_avatar_sync"`
|
UserAvatarSync bool `yaml:"user_avatar_sync"`
|
||||||
BridgeMatrixLeave bool `yaml:"bridge_matrix_leave"`
|
BridgeMatrixLeave bool `yaml:"bridge_matrix_leave"`
|
||||||
|
@ -102,6 +103,7 @@ func (bc *BridgeConfig) setDefaults() {
|
||||||
bc.CallNotices.End = true
|
bc.CallNotices.End = true
|
||||||
|
|
||||||
bc.HistorySync.CreatePortals = true
|
bc.HistorySync.CreatePortals = true
|
||||||
|
bc.HistorySync.MaxAge = 604800
|
||||||
bc.UserAvatarSync = true
|
bc.UserAvatarSync = true
|
||||||
bc.BridgeMatrixLeave = true
|
bc.BridgeMatrixLeave = true
|
||||||
|
|
||||||
|
|
|
@ -98,6 +98,8 @@ bridge:
|
||||||
history_sync:
|
history_sync:
|
||||||
# Whether to create portals from history sync payloads from WhatsApp.
|
# Whether to create portals from history sync payloads from WhatsApp.
|
||||||
create_portals: true
|
create_portals: true
|
||||||
|
# Maximum age of chats in seconds to create portals for. Set to 0 to create portals for all chats in sync payload.
|
||||||
|
max_age: 604800
|
||||||
# Whether to enable backfilling history sync payloads from WhatsApp using batch sending
|
# Whether to enable backfilling history sync payloads from WhatsApp using batch sending
|
||||||
# This requires a server with MSC2716 support, which is currently an experimental feature in synapse.
|
# This requires a server with MSC2716 support, which is currently an experimental feature in synapse.
|
||||||
# It can be enabled by setting experimental_features -> enable_msc2716 to true in homeserver.yaml.
|
# It can be enabled by setting experimental_features -> enable_msc2716 to true in homeserver.yaml.
|
||||||
|
|
10
user.go
10
user.go
|
@ -347,6 +347,9 @@ func (user *User) handleHistorySync(evt *waProto.HistorySync) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
user.log.Infofln("Handling history sync with type %s, chunk order %d, progress %d%%", evt.GetSyncType(), evt.GetChunkOrder(), evt.GetProgress())
|
user.log.Infofln("Handling history sync with type %s, chunk order %d, progress %d%%", evt.GetSyncType(), evt.GetChunkOrder(), evt.GetProgress())
|
||||||
|
maxAge := user.bridge.Config.Bridge.HistorySync.MaxAge
|
||||||
|
minLastMsgToCreate := time.Now().Add(-time.Duration(maxAge) * time.Second)
|
||||||
|
createRooms := user.bridge.Config.Bridge.HistorySync.CreatePortals
|
||||||
for _, conv := range evt.GetConversations() {
|
for _, conv := range evt.GetConversations() {
|
||||||
jid, err := types.ParseJID(conv.GetId())
|
jid, err := types.ParseJID(conv.GetId())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -365,8 +368,13 @@ func (user *User) handleHistorySync(evt *waProto.HistorySync) {
|
||||||
_ = user.Client.Store.ChatSettings.PutPinned(jid, true)
|
_ = user.Client.Store.ChatSettings.PutPinned(jid, true)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
lastMsg := time.Unix(int64(conv.GetConversationTimestamp()), 0)
|
||||||
portal := user.GetPortalByJID(jid)
|
portal := user.GetPortalByJID(jid)
|
||||||
if user.bridge.Config.Bridge.HistorySync.CreatePortals && len(portal.MXID) == 0 {
|
if createRooms && len(portal.MXID) == 0 {
|
||||||
|
if maxAge > 0 && !lastMsg.After(minLastMsgToCreate) {
|
||||||
|
user.log.Debugfln("Not creating portal for %s: last message older than limit (%s)", portal.Key.JID, lastMsg)
|
||||||
|
continue
|
||||||
|
}
|
||||||
user.log.Debugln("Creating portal for", portal.Key.JID, "as part of history sync handling")
|
user.log.Debugln("Creating portal for", portal.Key.JID, "as part of history sync handling")
|
||||||
err = portal.CreateMatrixRoom(user)
|
err = portal.CreateMatrixRoom(user)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
Loading…
Reference in a new issue