Skip to content

Commit

Permalink
backfill: ignore read up to ts if unread flag is false
Browse files Browse the repository at this point in the history
  • Loading branch information
tulir committed Aug 14, 2024
1 parent 71c92d3 commit 7b7cdb3
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 7 deletions.
2 changes: 1 addition & 1 deletion pkg/connector/backfill.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ func (gc *GMClient) FetchMessages(ctx context.Context, params bridgev2.FetchMess
if meta != nil {
lastWrappedMsg := fetchResp.Messages[len(fetchResp.Messages)-1]
lastRawMsg := resp.Messages[len(resp.Messages)-1]
fetchResp.MarkRead = !meta.readUpToTS.Before(lastWrappedMsg.Timestamp) || meta.readUpTo == lastRawMsg.MessageID
fetchResp.MarkRead = !meta.unread || !meta.readUpToTS.Before(lastWrappedMsg.Timestamp) || meta.readUpTo == lastRawMsg.MessageID
}
gc.conversationMetaLock.Unlock()
} else {
Expand Down
8 changes: 2 additions & 6 deletions pkg/connector/chatsync.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,10 @@ func (gc *GMClient) syncConversationMeta(v *gmproto.Conversation) (meta *convers
meta = &conversationMeta{}
gc.conversationMeta[v.ConversationID] = meta
}
meta.unread = v.Unread
if !v.Unread {
meta.readUpTo = v.LatestMessageID
newLastMsgTS := time.UnixMicro(v.LastMessageTimestamp)
// Don't allow read up to timestamp to move backwards.
// There are some weird race conditions where it causes backfills to be left unread.
if meta.readUpToTS.Before(newLastMsgTS) {
meta.readUpToTS = newLastMsgTS
}
meta.readUpToTS = time.UnixMicro(v.LastMessageTimestamp)
} else if meta.readUpTo == v.LatestMessageID {
meta.readUpTo = ""
meta.readUpToTS = time.Time{}
Expand Down
1 change: 1 addition & 0 deletions pkg/connector/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import (
type conversationMeta struct {
markedSpamAt time.Time
cancelPendingBackfill atomic.Pointer[context.CancelFunc]
unread bool
readUpTo string
readUpToTS time.Time
}
Expand Down

0 comments on commit 7b7cdb3

Please sign in to comment.