From 7ad2103f8f2c9b7e3d12554634a68db973a05b36 Mon Sep 17 00:00:00 2001 From: Tulir Asokan Date: Fri, 5 Apr 2019 23:44:17 +0300 Subject: Move history storage to matrix package. Fixes #90 --- matrix/rooms/room.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'matrix/rooms/room.go') diff --git a/matrix/rooms/room.go b/matrix/rooms/room.go index 16d4a9e..47f5602 100644 --- a/matrix/rooms/room.go +++ b/matrix/rooms/room.go @@ -57,6 +57,7 @@ type UnreadMessage struct { Highlight bool } + // Room represents a single Matrix room. type Room struct { *mautrix.Room @@ -74,6 +75,7 @@ type Room struct { UnreadMessages []UnreadMessage unreadCountCache *int highlightCache *bool + lastMarkedRead string // Whether or not this room is marked as a direct chat. IsDirect bool @@ -142,7 +144,11 @@ func (room *Room) Save(path string) error { } // MarkRead clears the new message statuses on this room. -func (room *Room) MarkRead(eventID string) { +func (room *Room) MarkRead(eventID string) bool { + if room.lastMarkedRead == eventID { + return false + } + room.lastMarkedRead = eventID readToIndex := -1 for index, unreadMessage := range room.UnreadMessages { if unreadMessage.EventID == eventID { @@ -154,6 +160,7 @@ func (room *Room) MarkRead(eventID string) { room.highlightCache = nil room.unreadCountCache = nil } + return true } func (room *Room) UnreadCount() int { -- cgit v1.2.3