Skip to content

Commit

Permalink
Ignore unsent messages in backfill. Fixes #23
Browse files Browse the repository at this point in the history
  • Loading branch information
tulir committed Mar 1, 2024
1 parent 5660049 commit 682c4d7
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
6 changes: 5 additions & 1 deletion backfill.go
Original file line number Diff line number Diff line change
Expand Up @@ -556,6 +556,10 @@ func (portal *Portal) convertAndSendBackfill(ctx context.Context, source *User,
}
}
}
if len(events) == 0 {
log.Info().Msg("No events to send in backfill batch")
return
}
if unreadHoursThreshold := portal.bridge.Config.Bridge.Backfill.UnreadHoursThreshold; unreadHoursThreshold > 0 && !markRead && len(messages) > 0 {
markRead = messages[len(messages)-1].TimestampMs < time.Now().Add(-time.Duration(unreadHoursThreshold)*time.Hour).UnixMilli()
if markRead {
Expand All @@ -571,7 +575,7 @@ func (portal *Portal) convertAndSendBackfill(ctx context.Context, source *User,
log.Info().Int("event_count", len(events)).Msg("Sending events to Matrix one by one")
portal.sendBackfillLegacy(ctx, source, events, metas, markRead)
}
zerolog.Ctx(ctx).Info().Msg("Finished sending backfill batch")
log.Info().Msg("Finished sending backfill batch")
}

func (portal *Portal) sendBackfillLegacy(ctx context.Context, source *User, events []*event.Event, metas []*BackfillPartMetadata, markRead bool) {
Expand Down
3 changes: 3 additions & 0 deletions msgconv/from-meta.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,9 @@ func (mc *MessageConverter) ToMatrix(ctx context.Context, msg *table.WrappedMess
cm := &ConvertedMessage{
Parts: make([]*ConvertedMessagePart, 0),
}
if msg.IsUnsent {
return cm
}
for _, blobAtt := range msg.BlobAttachments {
cm.Parts = append(cm.Parts, mc.blobAttachmentToMatrix(ctx, blobAtt))
}
Expand Down

0 comments on commit 682c4d7

Please sign in to comment.