morpheus

A Matrix client written in Go-QT
git clone git://archive.git.mtrnord.blog/Nordgedanken/morpheus.git
Log | Files | Refs | README | LICENSE

store.go (1049B)


      1 package syncer
      2 
      3 import (
      4 	"github.com/Nordgedanken/Morpheus/matrix/db"
      5 	"github.com/matrix-org/gomatrix"
      6 	log "github.com/sirupsen/logrus"
      7 )
      8 
      9 // MorpheusStore implements the gomatrix.Storer interface.
     10 //
     11 // It persists the next batch token in the database, and includes a ClientConfig for the client.
     12 type MorpheusStore struct {
     13 	gomatrix.InMemoryStore
     14 	CacheDatabase db.Storer
     15 }
     16 
     17 // SaveNextBatch saves to the database.
     18 func (m *MorpheusStore) SaveNextBatch(userID, nextBatch string) {
     19 	if err := m.CacheDatabase.UpdateNextBatch(userID, nextBatch); err != nil {
     20 		log.WithFields(log.Fields{
     21 			log.ErrorKey: err,
     22 			"user_id":    userID,
     23 			"next_batch": nextBatch,
     24 		}).Error("Failed to persist next_batch token")
     25 	}
     26 }
     27 
     28 // LoadNextBatch loads from the database.
     29 func (m *MorpheusStore) LoadNextBatch(userID string) string {
     30 	token, err := m.CacheDatabase.LoadNextBatch(userID)
     31 	if err != nil {
     32 		log.WithFields(log.Fields{
     33 			log.ErrorKey: err,
     34 			"user_id":    userID,
     35 		}).Error("Failed to load next_batch token")
     36 		return ""
     37 	}
     38 	return token
     39 }