diff options
author | Tulir Asokan <tulir@maunium.net> | 2018-05-17 16:29:15 +0300 |
---|---|---|
committer | Tulir Asokan <tulir@maunium.net> | 2018-05-17 16:29:18 +0300 |
commit | 76cff9554001ca3727e2ba11b790e9bba27d6b77 (patch) | |
tree | 325015fa4b331aeb4487d2ed0aaf94f2f3d40fe4 /matrix/rooms | |
parent | a1f9ee23fa07bdeb548953cdadb7e2cfb0fa05de (diff) |
Move all cache to ~/.cache/gomuks
Now `rm -rf ~/.cache/gomuks` has the same effect as `/clearcache`
Diffstat (limited to 'matrix/rooms')
-rw-r--r-- | matrix/rooms/room.go | 41 |
1 files changed, 34 insertions, 7 deletions
diff --git a/matrix/rooms/room.go b/matrix/rooms/room.go index 17bf21b..8a543e8 100644 --- a/matrix/rooms/room.go +++ b/matrix/rooms/room.go @@ -24,12 +24,19 @@ import ( "maunium.net/go/gomatrix" "maunium.net/go/gomuks/debug" + "os" + "encoding/gob" ) +func init() { + gob.Register([]interface{}{}) + gob.Register(map[string]interface{}{}) +} + type RoomNameSource int const ( - ExplicitRoomName RoomNameSource = iota + ExplicitRoomName RoomNameSource = iota CanonicalAliasRoomName AliasRoomName MemberRoomName @@ -44,8 +51,8 @@ type RoomTag struct { } type UnreadMessage struct { - EventID string - Counted bool + EventID string + Counted bool Highlight bool } @@ -63,9 +70,9 @@ type Room struct { SessionUserID string // The number of unread messages that were notified about. - UnreadMessages []UnreadMessage + UnreadMessages []UnreadMessage unreadCountCache *int - highlightCache *bool + highlightCache *bool // Whether or not this room is marked as a direct chat. IsDirect bool @@ -113,6 +120,26 @@ func (room *Room) UnlockHistory() { } } +func (room *Room) Load(path string) error { + file, err := os.OpenFile(path, os.O_RDONLY, 0600) + if err != nil { + return err + } + defer file.Close() + dec := gob.NewDecoder(file) + return dec.Decode(room) +} + +func (room *Room) Save(path string) error { + file, err := os.OpenFile(path, os.O_WRONLY|os.O_CREATE, 0600) + if err != nil { + return err + } + defer file.Close() + enc := gob.NewEncoder(file) + return enc.Encode(room) +} + // MarkRead clears the new message statuses on this room. func (room *Room) MarkRead(eventID string) { readToIndex := -1 @@ -159,8 +186,8 @@ func (room *Room) HasNewMessages() bool { func (room *Room) AddUnread(eventID string, counted, highlight bool) { room.UnreadMessages = append(room.UnreadMessages, UnreadMessage{ - EventID: eventID, - Counted: counted, + EventID: eventID, + Counted: counted, Highlight: highlight, }) if counted { |