stop clobbering saved keys

This commit is contained in:
Aaron Bieber 2020-02-04 19:02:18 -07:00
parent 0c6fba31d5
commit 8df9149e98

View File

@ -3,6 +3,7 @@ package main
import (
"bytes"
"encoding/gob"
"fmt"
"github.com/matrix-org/gomatrix"
"github.com/peterbourgon/diskv"
@ -61,36 +62,36 @@ func (s *MCStore) decodeRoom(room []byte) (*gomatrix.Room, error) {
// SaveFilterID exposed for gomatrix
func (s *MCStore) SaveFilterID(userID, filterID string) {
s.set(userID, filterID)
s.set(fmt.Sprintf("filter_%s", userID), filterID)
}
// LoadFilterID exposed for gomatrix
func (s *MCStore) LoadFilterID(userID string) string {
filter, _ := s.get(userID)
filter, _ := s.get(fmt.Sprintf("filter_%s", userID))
return string(filter)
}
// SaveNextBatch exposed for gomatrix
func (s *MCStore) SaveNextBatch(userID, nextBatchToken string) {
s.set(userID, nextBatchToken)
s.set(fmt.Sprintf("batch_%s", userID), nextBatchToken)
}
// LoadNextBatch exposed for gomatrix
func (s *MCStore) LoadNextBatch(userID string) string {
batch, _ := s.get(userID)
batch, _ := s.get(fmt.Sprintf("batch_%s", userID))
return string(batch)
}
// SaveRoom exposed for gomatrix
func (s *MCStore) SaveRoom(room *gomatrix.Room) {
b, _ := s.encodeRoom(room)
s.set(room.ID, string(b))
s.set(fmt.Sprintf("room_%s", room.ID), string(b))
}
// LoadRoom exposed for gomatrix
func (s *MCStore) LoadRoom(roomID string) *gomatrix.Room {
b, _ := s.get(roomID)
b, _ := s.get(fmt.Sprintf("room_%s", roomID))
room, _ := s.decodeRoom([]byte(b))
return room
}