morpheus

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

commit 88b70805d9fbc76ee04cfacf18dfcfeceb248cc5
parent 9178ecf86a24b150cc39dad966e21201e1471a4b
Author: MTRNord <mtrnord1@gmail.com>
Date:   Tue, 22 Aug 2017 16:17:11 +0200

Prepare Cache/State DB

Diffstat:
M.gitignore | 1+
Mmain.go | 5+++++
Amatrix/db.go | 24++++++++++++++++++++++++
Mmatrix/login.go | 13+++++++++++++
Muis.go | 6++++--
5 files changed, 47 insertions(+), 2 deletions(-)

diff --git a/.gitignore b/.gitignore @@ -17,3 +17,4 @@ windows/ rcc* debug* log/ +data/ diff --git a/main.go b/main.go @@ -4,6 +4,7 @@ import ( "log" "os" + "github.com/Nordgedanken/Neo/matrix" "github.com/Nordgedanken/Neo/util" "github.com/therecipe/qt/widgets" ) @@ -16,6 +17,10 @@ func main() { localLog = util.Logger() localLog, file = util.StartFileLog(localLog) defer file.Close() + + db := matrix.OpenDB() + defer db.Close() + localLog.Println("Starting Neo") widgets.NewQApplication(len(os.Args), os.Args) diff --git a/matrix/db.go b/matrix/db.go @@ -0,0 +1,24 @@ +package matrix + +import ( + "log" + "os" + + "github.com/tidwall/buntdb" +) + +var db *buntdb.DB + +func OpenDB() (expDB *buntdb.DB) { + // Open the data.db file. It will be created if it doesn't exist. + if _, err := os.Stat("./data/"); os.IsNotExist(err) { + os.Mkdir("./data/", 0666) + } + expDB, err := buntdb.Open("./data/data.db") + if err != nil { + log.Fatal(err) + } + db = expDB + + return +} diff --git a/matrix/login.go b/matrix/login.go @@ -5,6 +5,7 @@ import ( "sync" "github.com/matrix-org/gomatrix" + "github.com/tidwall/buntdb" ) var clientInstance *gomatrix.Client @@ -19,6 +20,18 @@ func getClient(homeserverURL, userID, accessToken string) (*gomatrix.Client, err if err != nil { return nil, err } + + DBerr := db.Update(func(tx *buntdb.Tx) error { + tx.Set("user:accessToken", clientInstance.AccessToken, nil) + tx.Set("user:homeserverURL", clientInstance.HomeserverURL.String(), nil) + tx.Set("user:userID", clientInstance.UserID, nil) + return nil + }) + + if DBerr != nil { + return nil, DBerr + } + return clientInstance, nil } diff --git a/uis.go b/uis.go @@ -33,12 +33,14 @@ func NewLoginUI(windowWidth, windowHeight int) *widgets.QWidget { // UsernameInput-Label usernameLabel := widgets.NewQLabel(nil, 0) usernameLabel.SetText("Username: ") - usernameLabel.SetBuddy(usernameLabel) + usernameLabel.SetBuddy(usernameInput) + layout.AddWidget(usernameLabel, 0, 0) // PasswordInput-Label passwordLabel := widgets.NewQLabel(nil, 0) passwordLabel.SetText("Password: ") - passwordLabel.SetBuddy(passwordLabel) + passwordLabel.SetBuddy(passwordInput) + layout.AddWidget(passwordLabel, 0, 0) // loginButton loginButton := widgets.NewQPushButton2("LOGIN", nil)