Fix backfill things
This commit is contained in:
25
backfill.go
25
backfill.go
@@ -33,6 +33,7 @@ func (portal *Portal) forwardBackfillInitial(source *User) {
|
|||||||
|
|
||||||
log := portal.zlog.With().
|
log := portal.zlog.With().
|
||||||
Str("action", "initial backfill").
|
Str("action", "initial backfill").
|
||||||
|
Str("room_id", portal.MXID.String()).
|
||||||
Int("limit", limit).
|
Int("limit", limit).
|
||||||
Logger()
|
Logger()
|
||||||
|
|
||||||
@@ -40,6 +41,10 @@ func (portal *Portal) forwardBackfillInitial(source *User) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (portal *Portal) ForwardBackfillMissed(source *User, meta *discordgo.Channel) {
|
func (portal *Portal) ForwardBackfillMissed(source *User, meta *discordgo.Channel) {
|
||||||
|
if portal.MXID == "" {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
limit := portal.bridge.Config.Bridge.Backfill.Limits.Missed.Channel
|
limit := portal.bridge.Config.Bridge.Backfill.Limits.Missed.Channel
|
||||||
if portal.GuildID == "" {
|
if portal.GuildID == "" {
|
||||||
limit = portal.bridge.Config.Bridge.Backfill.Limits.Missed.DM
|
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().
|
log := portal.zlog.With().
|
||||||
Str("action", "missed event backfill").
|
Str("action", "missed event backfill").
|
||||||
|
Str("room_id", portal.MXID.String()).
|
||||||
Int("limit", limit).
|
Int("limit", limit).
|
||||||
Logger()
|
Logger()
|
||||||
|
|
||||||
@@ -110,6 +116,7 @@ func (portal *Portal) collectBackfillMessages(log zerolog.Logger, source *User,
|
|||||||
before = newMessages[len(newMessages)-1].ID
|
before = newMessages[len(newMessages)-1].ID
|
||||||
}
|
}
|
||||||
if len(messages) > limit {
|
if len(messages) > limit {
|
||||||
|
foundAll = false
|
||||||
messages = messages[:limit]
|
messages = messages[:limit]
|
||||||
}
|
}
|
||||||
return messages, foundAll, nil
|
return messages, foundAll, nil
|
||||||
@@ -202,7 +209,7 @@ func (portal *Portal) forwardBatchSend(log zerolog.Logger, source *User, message
|
|||||||
if i == 0 {
|
if i == 0 {
|
||||||
partName = ""
|
partName = ""
|
||||||
}
|
}
|
||||||
evts = append(evts, &event.Event{
|
evt := &event.Event{
|
||||||
ID: portal.deterministicEventID(msg.ID, partName),
|
ID: portal.deterministicEventID(msg.ID, partName),
|
||||||
Type: part.Type,
|
Type: part.Type,
|
||||||
Sender: intent.UserID,
|
Sender: intent.UserID,
|
||||||
@@ -211,7 +218,15 @@ func (portal *Portal) forwardBatchSend(log zerolog.Logger, source *User, message
|
|||||||
Parsed: part.Content,
|
Parsed: part.Content,
|
||||||
Raw: part.Extra,
|
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{
|
dbMessages = append(dbMessages, database.Message{
|
||||||
Channel: portal.Key,
|
Channel: portal.Key,
|
||||||
DiscordID: msg.ID,
|
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{
|
resp, err := portal.MainIntent().BatchSend(portal.MXID, &mautrix.ReqBatchSend{
|
||||||
BeeperNewMessages: true,
|
BeeperNewMessages: true,
|
||||||
Events: evts,
|
Events: evts,
|
||||||
|
|||||||
@@ -67,11 +67,10 @@ type BridgeConfig struct {
|
|||||||
ManagementRoomText bridgeconfig.ManagementRoomTexts `yaml:"management_room_text"`
|
ManagementRoomText bridgeconfig.ManagementRoomTexts `yaml:"management_room_text"`
|
||||||
|
|
||||||
Backfill struct {
|
Backfill struct {
|
||||||
Enabled bool `yaml:"enabled"`
|
Limits struct {
|
||||||
Limits struct {
|
|
||||||
Initial BackfillLimitPart `yaml:"initial"`
|
Initial BackfillLimitPart `yaml:"initial"`
|
||||||
Missed BackfillLimitPart `yaml:"missed"`
|
Missed BackfillLimitPart `yaml:"missed"`
|
||||||
} `yaml:"limits"`
|
} `yaml:"forward_limits"`
|
||||||
} `yaml:"backfill"`
|
} `yaml:"backfill"`
|
||||||
|
|
||||||
Encryption bridgeconfig.EncryptionConfig `yaml:"encryption"`
|
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, "bridge", "management_room_text", "welcome_unconnected")
|
||||||
helper.Copy(up.Str|up.Null, "bridge", "management_room_text", "additional_help")
|
helper.Copy(up.Str|up.Null, "bridge", "management_room_text", "additional_help")
|
||||||
helper.Copy(up.Bool, "bridge", "backfill", "enabled")
|
helper.Copy(up.Bool, "bridge", "backfill", "enabled")
|
||||||
helper.Copy(up.Int, "bridge", "backfill", "limits", "initial", "dm")
|
helper.Copy(up.Int, "bridge", "backfill", "forward_limits", "initial", "dm")
|
||||||
helper.Copy(up.Int, "bridge", "backfill", "limits", "initial", "channel")
|
helper.Copy(up.Int, "bridge", "backfill", "forward_limits", "initial", "channel")
|
||||||
helper.Copy(up.Int, "bridge", "backfill", "limits", "missed", "dm")
|
helper.Copy(up.Int, "bridge", "backfill", "forward_limits", "missed", "dm")
|
||||||
helper.Copy(up.Int, "bridge", "backfill", "limits", "missed", "channel")
|
helper.Copy(up.Int, "bridge", "backfill", "forward_limits", "missed", "channel")
|
||||||
helper.Copy(up.Bool, "bridge", "encryption", "allow")
|
helper.Copy(up.Bool, "bridge", "encryption", "allow")
|
||||||
helper.Copy(up.Bool, "bridge", "encryption", "default")
|
helper.Copy(up.Bool, "bridge", "encryption", "default")
|
||||||
helper.Copy(up.Bool, "bridge", "encryption", "require")
|
helper.Copy(up.Bool, "bridge", "encryption", "require")
|
||||||
|
|||||||
@@ -99,7 +99,7 @@ func (mq *MessageQuery) MassInsert(key PortalKey, msgs []Message) {
|
|||||||
if len(msgs) == 0 {
|
if len(msgs) == 0 {
|
||||||
return
|
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 {
|
if mq.db.Dialect == dbutil.SQLite {
|
||||||
valueStringFormat = strings.ReplaceAll(valueStringFormat, "$", "?")
|
valueStringFormat = strings.ReplaceAll(valueStringFormat, "$", "?")
|
||||||
}
|
}
|
||||||
@@ -113,7 +113,7 @@ func (mq *MessageQuery) MassInsert(key PortalKey, msgs []Message) {
|
|||||||
params[baseIndex+1] = msg.AttachmentID
|
params[baseIndex+1] = msg.AttachmentID
|
||||||
params[baseIndex+2] = msg.EditIndex
|
params[baseIndex+2] = msg.EditIndex
|
||||||
params[baseIndex+3] = msg.SenderID
|
params[baseIndex+3] = msg.SenderID
|
||||||
params[baseIndex+4] = msg.Timestamp
|
params[baseIndex+4] = msg.Timestamp.UnixMilli()
|
||||||
params[baseIndex+5] = msg.ThreadID
|
params[baseIndex+5] = msg.ThreadID
|
||||||
params[baseIndex+6] = msg.MXID
|
params[baseIndex+6] = msg.MXID
|
||||||
placeholders[i] = fmt.Sprintf(valueStringFormat, baseIndex+1, baseIndex+2, baseIndex+3, baseIndex+4, baseIndex+5, baseIndex+6, baseIndex+7)
|
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: ""
|
additional_help: ""
|
||||||
|
|
||||||
backfill:
|
backfill:
|
||||||
# Should backfill be enabled at all?
|
# Limits for forward backfilling.
|
||||||
enabled: false
|
forward_limits:
|
||||||
# Limits for backfilling.
|
|
||||||
limits:
|
|
||||||
# Initial backfill (when creating portal). 0 means backfill is disabled.
|
# 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
|
# 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.
|
# fetch all messages first before backfilling anything, so high limits can take a lot of time.
|
||||||
initial:
|
initial:
|
||||||
dm: 50
|
dm: 0
|
||||||
channel: 0
|
channel: 0
|
||||||
# Missed message backfill (on startup).
|
# Missed message backfill (on startup).
|
||||||
# 0 means backfill is disabled, -1 means fetch all messages since last bridged message.
|
# 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.
|
# 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.
|
# With limits, all messages up to the limit are fetched first and backfilled afterwards.
|
||||||
missed:
|
missed:
|
||||||
dm: 50
|
dm: 0
|
||||||
channel: 0
|
channel: 0
|
||||||
|
|
||||||
# End-to-bridge encryption support options.
|
# End-to-bridge encryption support options.
|
||||||
|
|||||||
Reference in New Issue
Block a user