forked from mirror/mautrix-discord
Fix backfill things
This commit is contained in:
parent
a0fb4a45d2
commit
587ac68f60
5 changed files with 34 additions and 18 deletions
25
backfill.go
25
backfill.go
|
@ -33,6 +33,7 @@ func (portal *Portal) forwardBackfillInitial(source *User) {
|
|||
|
||||
log := portal.zlog.With().
|
||||
Str("action", "initial backfill").
|
||||
Str("room_id", portal.MXID.String()).
|
||||
Int("limit", limit).
|
||||
Logger()
|
||||
|
||||
|
@ -40,6 +41,10 @@ func (portal *Portal) forwardBackfillInitial(source *User) {
|
|||
}
|
||||
|
||||
func (portal *Portal) ForwardBackfillMissed(source *User, meta *discordgo.Channel) {
|
||||
if portal.MXID == "" {
|
||||
return
|
||||
}
|
||||
|
||||
limit := portal.bridge.Config.Bridge.Backfill.Limits.Missed.Channel
|
||||
if portal.GuildID == "" {
|
||||
limit = portal.bridge.Config.Bridge.Backfill.Limits.Missed.DM
|
||||
|
@ -49,6 +54,7 @@ func (portal *Portal) ForwardBackfillMissed(source *User, meta *discordgo.Channe
|
|||
}
|
||||
log := portal.zlog.With().
|
||||
Str("action", "missed event backfill").
|
||||
Str("room_id", portal.MXID.String()).
|
||||
Int("limit", limit).
|
||||
Logger()
|
||||
|
||||
|
@ -110,6 +116,7 @@ func (portal *Portal) collectBackfillMessages(log zerolog.Logger, source *User,
|
|||
before = newMessages[len(newMessages)-1].ID
|
||||
}
|
||||
if len(messages) > limit {
|
||||
foundAll = false
|
||||
messages = messages[:limit]
|
||||
}
|
||||
return messages, foundAll, nil
|
||||
|
@ -202,7 +209,7 @@ func (portal *Portal) forwardBatchSend(log zerolog.Logger, source *User, message
|
|||
if i == 0 {
|
||||
partName = ""
|
||||
}
|
||||
evts = append(evts, &event.Event{
|
||||
evt := &event.Event{
|
||||
ID: portal.deterministicEventID(msg.ID, partName),
|
||||
Type: part.Type,
|
||||
Sender: intent.UserID,
|
||||
|
@ -211,7 +218,15 @@ func (portal *Portal) forwardBatchSend(log zerolog.Logger, source *User, message
|
|||
Parsed: part.Content,
|
||||
Raw: part.Extra,
|
||||
},
|
||||
})
|
||||
}
|
||||
var err error
|
||||
evt.Type, err = portal.encrypt(intent, &evt.Content, evt.Type)
|
||||
if err != nil {
|
||||
log.Err(err).Msg("Failed to encrypt event")
|
||||
continue
|
||||
}
|
||||
intent.AddDoublePuppetValue(&evt.Content)
|
||||
evts = append(evts, evt)
|
||||
dbMessages = append(dbMessages, database.Message{
|
||||
Channel: portal.Key,
|
||||
DiscordID: msg.ID,
|
||||
|
@ -221,7 +236,11 @@ func (portal *Portal) forwardBatchSend(log zerolog.Logger, source *User, message
|
|||
})
|
||||
}
|
||||
}
|
||||
log.Info().Int("parts", len(evts)).Msg("Converted messages to backfill")
|
||||
if len(evts) == 0 {
|
||||
log.Warn().Msg("Didn't get any events to backfill")
|
||||
return
|
||||
}
|
||||
log.Info().Int("events", len(evts)).Msg("Converted messages to backfill")
|
||||
resp, err := portal.MainIntent().BatchSend(portal.MXID, &mautrix.ReqBatchSend{
|
||||
BeeperNewMessages: true,
|
||||
Events: evts,
|
||||
|
|
|
@ -67,11 +67,10 @@ type BridgeConfig struct {
|
|||
ManagementRoomText bridgeconfig.ManagementRoomTexts `yaml:"management_room_text"`
|
||||
|
||||
Backfill struct {
|
||||
Enabled bool `yaml:"enabled"`
|
||||
Limits struct {
|
||||
Limits struct {
|
||||
Initial BackfillLimitPart `yaml:"initial"`
|
||||
Missed BackfillLimitPart `yaml:"missed"`
|
||||
} `yaml:"limits"`
|
||||
} `yaml:"forward_limits"`
|
||||
} `yaml:"backfill"`
|
||||
|
||||
Encryption bridgeconfig.EncryptionConfig `yaml:"encryption"`
|
||||
|
|
|
@ -68,10 +68,10 @@ func DoUpgrade(helper *up.Helper) {
|
|||
helper.Copy(up.Str, "bridge", "management_room_text", "welcome_unconnected")
|
||||
helper.Copy(up.Str|up.Null, "bridge", "management_room_text", "additional_help")
|
||||
helper.Copy(up.Bool, "bridge", "backfill", "enabled")
|
||||
helper.Copy(up.Int, "bridge", "backfill", "limits", "initial", "dm")
|
||||
helper.Copy(up.Int, "bridge", "backfill", "limits", "initial", "channel")
|
||||
helper.Copy(up.Int, "bridge", "backfill", "limits", "missed", "dm")
|
||||
helper.Copy(up.Int, "bridge", "backfill", "limits", "missed", "channel")
|
||||
helper.Copy(up.Int, "bridge", "backfill", "forward_limits", "initial", "dm")
|
||||
helper.Copy(up.Int, "bridge", "backfill", "forward_limits", "initial", "channel")
|
||||
helper.Copy(up.Int, "bridge", "backfill", "forward_limits", "missed", "dm")
|
||||
helper.Copy(up.Int, "bridge", "backfill", "forward_limits", "missed", "channel")
|
||||
helper.Copy(up.Bool, "bridge", "encryption", "allow")
|
||||
helper.Copy(up.Bool, "bridge", "encryption", "default")
|
||||
helper.Copy(up.Bool, "bridge", "encryption", "require")
|
||||
|
|
|
@ -99,7 +99,7 @@ func (mq *MessageQuery) MassInsert(key PortalKey, msgs []Message) {
|
|||
if len(msgs) == 0 {
|
||||
return
|
||||
}
|
||||
valueStringFormat := "($%d, $%d, $1, $2, $%d, $%d, $%d, $%d, $%d)"
|
||||
valueStringFormat := "($%d, $%d, $%d, $1, $2, $%d, $%d, $%d, $%d)"
|
||||
if mq.db.Dialect == dbutil.SQLite {
|
||||
valueStringFormat = strings.ReplaceAll(valueStringFormat, "$", "?")
|
||||
}
|
||||
|
@ -113,7 +113,7 @@ func (mq *MessageQuery) MassInsert(key PortalKey, msgs []Message) {
|
|||
params[baseIndex+1] = msg.AttachmentID
|
||||
params[baseIndex+2] = msg.EditIndex
|
||||
params[baseIndex+3] = msg.SenderID
|
||||
params[baseIndex+4] = msg.Timestamp
|
||||
params[baseIndex+4] = msg.Timestamp.UnixMilli()
|
||||
params[baseIndex+5] = msg.ThreadID
|
||||
params[baseIndex+6] = msg.MXID
|
||||
placeholders[i] = fmt.Sprintf(valueStringFormat, baseIndex+1, baseIndex+2, baseIndex+3, baseIndex+4, baseIndex+5, baseIndex+6, baseIndex+7)
|
||||
|
|
|
@ -187,22 +187,20 @@ bridge:
|
|||
additional_help: ""
|
||||
|
||||
backfill:
|
||||
# Should backfill be enabled at all?
|
||||
enabled: false
|
||||
# Limits for backfilling.
|
||||
limits:
|
||||
# Limits for forward backfilling.
|
||||
forward_limits:
|
||||
# Initial backfill (when creating portal). 0 means backfill is disabled.
|
||||
# A special unlimited value is not supported, you must set a limit. Initial backfill will
|
||||
# fetch all messages first before backfilling anything, so high limits can take a lot of time.
|
||||
initial:
|
||||
dm: 50
|
||||
dm: 0
|
||||
channel: 0
|
||||
# Missed message backfill (on startup).
|
||||
# 0 means backfill is disabled, -1 means fetch all messages since last bridged message.
|
||||
# When using unlimited backfill (-1), messages are backfilled as they are fetched.
|
||||
# With limits, all messages up to the limit are fetched first and backfilled afterwards.
|
||||
missed:
|
||||
dm: 50
|
||||
dm: 0
|
||||
channel: 0
|
||||
|
||||
# End-to-bridge encryption support options.
|
||||
|
|
Loading…
Reference in a new issue