From 497e5077835a649223869a5ecafe1cc6fae0c2f4 Mon Sep 17 00:00:00 2001 From: Tulir Asokan Date: Sun, 27 Oct 2024 23:37:07 +0200 Subject: [PATCH] hicli/sync: create implicit read receipts for own events --- pkg/hicli/sync.go | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/pkg/hicli/sync.go b/pkg/hicli/sync.go index 580c6ba..b8cf259 100644 --- a/pkg/hicli/sync.go +++ b/pkg/hicli/sync.go @@ -666,11 +666,24 @@ func (h *HiClient) processStateAndTimeline( timelineIDs := make([]database.EventRowID, len(timeline.Events)) readUpToIndex := -1 for i := len(timeline.Events) - 1; i >= 0; i-- { - if slices.Contains(newOwnReceipts, timeline.Events[i].ID) { + evt := timeline.Events[i] + isRead := slices.Contains(newOwnReceipts, evt.ID) + isOwnEvent := evt.Sender == h.Account.UserID + if isRead || isOwnEvent { readUpToIndex = i // Reset unread counts if we see our own read receipt in the timeline. // It'll be updated with new unreads (if any) at the end. updatedRoom.UnreadCounts = database.UnreadCounts{} + if !isRead { + receipts = append(receipts, &database.Receipt{ + RoomID: room.ID, + UserID: h.Account.UserID, + ReceiptType: event.ReceiptTypeRead, + EventID: evt.ID, + Timestamp: jsontime.UM(time.UnixMilli(evt.Timestamp)), + }) + newOwnReceipts = append(newOwnReceipts, evt.ID) + } break } }