summaryrefslogtreecommitdiffstats
path: root/vendor/github.com/matrix-org/gomatrix/store.go
diff options
context:
space:
mode:
authorTilo Spannagel <development@tilosp.de>2020-08-30 14:01:52 +0200
committerGitHub <noreply@github.com>2020-08-30 14:01:52 +0200
commitf9928c9e259fefee5bd049dbc8d8e5d98107f136 (patch)
treea593a2376ca4debdecb31b431e9d3928383d89e6 /vendor/github.com/matrix-org/gomatrix/store.go
parenta0741d99b80d7da1c063853382756b3a9689f6a7 (diff)
downloadmatterbridge-msglm-f9928c9e259fefee5bd049dbc8d8e5d98107f136.tar.gz
matterbridge-msglm-f9928c9e259fefee5bd049dbc8d8e5d98107f136.tar.bz2
matterbridge-msglm-f9928c9e259fefee5bd049dbc8d8e5d98107f136.zip
Switch to upstream gomatrix (#1219)
Signed-off-by: Tilo Spannagel <development@tilosp.de>
Diffstat (limited to 'vendor/github.com/matrix-org/gomatrix/store.go')
-rw-r--r--vendor/github.com/matrix-org/gomatrix/store.go65
1 files changed, 65 insertions, 0 deletions
diff --git a/vendor/github.com/matrix-org/gomatrix/store.go b/vendor/github.com/matrix-org/gomatrix/store.go
new file mode 100644
index 00000000..6dc687e5
--- /dev/null
+++ b/vendor/github.com/matrix-org/gomatrix/store.go
@@ -0,0 +1,65 @@
+package gomatrix
+
+// Storer is an interface which must be satisfied to store client data.
+//
+// You can either write a struct which persists this data to disk, or you can use the
+// provided "InMemoryStore" which just keeps data around in-memory which is lost on
+// restarts.
+type Storer interface {
+ SaveFilterID(userID, filterID string)
+ LoadFilterID(userID string) string
+ SaveNextBatch(userID, nextBatchToken string)
+ LoadNextBatch(userID string) string
+ SaveRoom(room *Room)
+ LoadRoom(roomID string) *Room
+}
+
+// InMemoryStore implements the Storer interface.
+//
+// Everything is persisted in-memory as maps. It is not safe to load/save filter IDs
+// or next batch tokens on any goroutine other than the syncing goroutine: the one
+// which called Client.Sync().
+type InMemoryStore struct {
+ Filters map[string]string
+ NextBatch map[string]string
+ Rooms map[string]*Room
+}
+
+// SaveFilterID to memory.
+func (s *InMemoryStore) SaveFilterID(userID, filterID string) {
+ s.Filters[userID] = filterID
+}
+
+// LoadFilterID from memory.
+func (s *InMemoryStore) LoadFilterID(userID string) string {
+ return s.Filters[userID]
+}
+
+// SaveNextBatch to memory.
+func (s *InMemoryStore) SaveNextBatch(userID, nextBatchToken string) {
+ s.NextBatch[userID] = nextBatchToken
+}
+
+// LoadNextBatch from memory.
+func (s *InMemoryStore) LoadNextBatch(userID string) string {
+ return s.NextBatch[userID]
+}
+
+// SaveRoom to memory.
+func (s *InMemoryStore) SaveRoom(room *Room) {
+ s.Rooms[room.ID] = room
+}
+
+// LoadRoom from memory.
+func (s *InMemoryStore) LoadRoom(roomID string) *Room {
+ return s.Rooms[roomID]
+}
+
+// NewInMemoryStore constructs a new InMemoryStore.
+func NewInMemoryStore() *InMemoryStore {
+ return &InMemoryStore{
+ Filters: make(map[string]string),
+ NextBatch: make(map[string]string),
+ Rooms: make(map[string]*Room),
+ }
+}