mirror of
https://github.com/tulir/gomuks.git
synced 2025-04-19 18:13:41 -05:00
hicli/sync: create implicit read receipts for own events
This commit is contained in:
parent
0742feb365
commit
497e507783
1 changed files with 14 additions and 1 deletions
|
@ -666,11 +666,24 @@ func (h *HiClient) processStateAndTimeline(
|
||||||
timelineIDs := make([]database.EventRowID, len(timeline.Events))
|
timelineIDs := make([]database.EventRowID, len(timeline.Events))
|
||||||
readUpToIndex := -1
|
readUpToIndex := -1
|
||||||
for i := len(timeline.Events) - 1; i >= 0; i-- {
|
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
|
readUpToIndex = i
|
||||||
// Reset unread counts if we see our own read receipt in the timeline.
|
// 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.
|
// It'll be updated with new unreads (if any) at the end.
|
||||||
updatedRoom.UnreadCounts = database.UnreadCounts{}
|
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
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue