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