Add config option for max age of chats to sync
This commit is contained in:
parent
239de25bf0
commit
0408db5c07
@ -41,6 +41,7 @@ type BridgeConfig struct {
|
|||||||
InitialHistoryFill int `yaml:"initial_history_fill_count"`
|
InitialHistoryFill int `yaml:"initial_history_fill_count"`
|
||||||
RecoverChatSync int `yaml:"recovery_chat_sync_count"`
|
RecoverChatSync int `yaml:"recovery_chat_sync_count"`
|
||||||
RecoverHistory bool `yaml:"recovery_history_backfill"`
|
RecoverHistory bool `yaml:"recovery_history_backfill"`
|
||||||
|
SyncChatMaxAge uint64 `yaml:"sync_max_chat_age"`
|
||||||
|
|
||||||
CommandPrefix string `yaml:"command_prefix"`
|
CommandPrefix string `yaml:"command_prefix"`
|
||||||
|
|
||||||
@ -59,6 +60,7 @@ func (bc *BridgeConfig) setDefaults() {
|
|||||||
bc.InitialHistoryFill = 20
|
bc.InitialHistoryFill = 20
|
||||||
bc.RecoverChatSync = -1
|
bc.RecoverChatSync = -1
|
||||||
bc.RecoverHistory = true
|
bc.RecoverHistory = true
|
||||||
|
bc.SyncChatMaxAge = 259200
|
||||||
}
|
}
|
||||||
|
|
||||||
type umBridgeConfig BridgeConfig
|
type umBridgeConfig BridgeConfig
|
||||||
|
@ -75,6 +75,11 @@ bridge:
|
|||||||
recovery_chat_sync_limit: -1
|
recovery_chat_sync_limit: -1
|
||||||
# Whether or not to sync history when recovering from downtime.
|
# Whether or not to sync history when recovering from downtime.
|
||||||
recovery_history_backfill: true
|
recovery_history_backfill: true
|
||||||
|
# Maximum number of seconds since last message in chat to skip
|
||||||
|
# syncing the chat in any case. This setting will take priority
|
||||||
|
# over both recovery_chat_sync_limit and initial_chat_sync_count.
|
||||||
|
# Default is 3 days = 259200 seconds
|
||||||
|
sync_max_chat_age: 259200
|
||||||
|
|
||||||
# The prefix for commands. Only required in non-management rooms.
|
# The prefix for commands. Only required in non-management rooms.
|
||||||
command_prefix: "!wa"
|
command_prefix: "!wa"
|
||||||
|
4
user.go
4
user.go
@ -312,7 +312,11 @@ func (user *User) syncPortals() {
|
|||||||
if limit < 0 {
|
if limit < 0 {
|
||||||
limit = len(chats)
|
limit = len(chats)
|
||||||
}
|
}
|
||||||
|
now := uint64(time.Now().Unix())
|
||||||
for i, chat := range chats {
|
for i, chat := range chats {
|
||||||
|
if chat.LastMessageTime + user.bridge.Config.Bridge.SyncChatMaxAge < now {
|
||||||
|
break
|
||||||
|
}
|
||||||
create := (chat.LastMessageTime >= user.LastConnection && user.LastConnection > 0) || i < limit
|
create := (chat.LastMessageTime >= user.LastConnection && user.LastConnection > 0) || i < limit
|
||||||
if len(chat.Portal.MXID) > 0 || create {
|
if len(chat.Portal.MXID) > 0 || create {
|
||||||
chat.Portal.Sync(user, chat.Contact)
|
chat.Portal.Sync(user, chat.Contact)
|
||||||
|
Loading…
Reference in New Issue
Block a user