morpheus

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

commit 108435c89fbcecca336325a9b82835ad45606270
parent 8ed3fff7cf76f8dc3103d66c3c32f532725e5f39
Author: MTRNord <mtrnord1@gmail.com>
Date:   Thu, 24 Aug 2017 23:29:14 +0200

Not working sync commit :(

Diffstat:
Mmain.go | 7+++----
Mmatrix/login.go | 17++++++++---------
Mmatrix/types.go | 1+
Mtags | 59+++++++++++++++++++++++++++++++----------------------------
Muis.go | 40++++++++++++++++++++++++++++++++++------
5 files changed, 77 insertions(+), 47 deletions(-)

diff --git a/main.go b/main.go @@ -36,10 +36,6 @@ func main() { window = widgets.NewQMainWindow(nil, 0) window.SetMinimumSize2(windowWidth, windowHeight) - loginUI := NewLoginUI(windowWidth, windowHeight) - loginUI.Resize2(windowWidth, windowHeight) - loginUI.SetMinimumSize2(windowWidth, windowHeight) - var accessToken string var homeserverURL string var userID string @@ -88,6 +84,9 @@ func main() { } } else { //Show loginUI + loginUI := NewLoginUI(windowWidth, windowHeight) + loginUI.Resize2(windowWidth, windowHeight) + loginUI.SetMinimumSize2(windowWidth, windowHeight) window.SetCentralWidget(loginUI) } window.Show() diff --git a/matrix/login.go b/matrix/login.go @@ -7,29 +7,28 @@ import ( "github.com/tidwall/buntdb" ) -var clientInstance *Client - //GetClient returns a Client -func GetClient(homeserverURL, userID, accessToken string) (*Client, error) { - var err error +func GetClient(homeserverURL, userID, accessToken string) (clientInstance *Client, err error) { var client *gomatrix.Client client, err = gomatrix.NewClient(homeserverURL, userID, accessToken) if err != nil { - return nil, err + clientInstance = nil + return } clientInstance = &Client{client} - DBerr := db.Update(func(tx *buntdb.Tx) error { + err = 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 + if err != nil { + clientInstance = nil + return } - return clientInstance, nil + return } //LoginUser Creates a Session for the User diff --git a/matrix/types.go b/matrix/types.go @@ -5,6 +5,7 @@ import ( "github.com/therecipe/qt/gui" ) +// Client is the Client type extender toadd new methods to it which gomatrix lacks currently type Client struct { *gomatrix.Client } diff --git a/tags b/tags @@ -4,56 +4,57 @@ !_TAG_PROGRAM_NAME gotags !_TAG_PROGRAM_URL https://github.com/jstemmer/gotags !_TAG_PROGRAM_VERSION 1.4.1 /go1.8.3/ -*gomatrix.Client matrix\types.go 9;" e access:public ctype:Client language:Go line:9 type:*gomatrix.Client -Client matrix\types.go 8;" t access:public language:Go line:8 type:struct -DisplayName matrix\types.go 14;" w access:public ctype:RespUserDisplayName language:Go line:14 type:string -DoLogin uis.go 18;" f access:public language:Go line:18 signature:(username, password, homeserverURL, userID, accessToken string, localLog *log.Logger, results chan *matrix.Client) +*gomatrix.Client matrix\types.go 10;" e access:public ctype:Client language:Go line:10 type:*gomatrix.Client +Client matrix\types.go 9;" t access:public language:Go line:9 type:struct +ClientInstance matrix\login.go 10;" v access:public language:Go line:10 type:*Client +DisplayName matrix\types.go 15;" w access:public ctype:RespUserDisplayName language:Go line:15 type:string +DoLogin ui\uis.go 20;" f access:public language:Go line:20 signature:(username, password, homeserverURL, userID, accessToken string, localLog *log.Logger, results chan *matrix.Client) GetClient matrix\login.go 13;" f access:public language:Go line:13 signature:(homeserverURL, userID, accessToken string) type:*Client, error -GetOwnUserAvatar matrix\types.go 24;" m access:public ctype:Client language:Go line:24 signature:() type:*gui.QPixmap -GetUserDisplayName matrix\types.go 18;" m access:public ctype:Client language:Go line:18 signature:(mxid string) type:string, error +GetOwnUserAvatar matrix\types.go 25;" m access:public ctype:Client language:Go line:25 signature:() type:*gui.QPixmap +GetUserDisplayName matrix\types.go 19;" m access:public ctype:Client language:Go line:19 signature:(mxid string) type:string, error Logger util\logger.go 18;" f access:public language:Go line:18 signature:() type:*log.Logger LoginUser matrix\login.go 36;" f access:public language:Go line:36 signature:(username, password string) type:*Client, error -NewLoginUI uis.go 46;" f access:public language:Go line:46 signature:(windowWidth, windowHeight int) type:*widgets.QWidget -NewMainUI uis.go 141;" f access:public language:Go line:141 signature:(windowWidth, windowHeight int, cli *matrix.Client) type:*widgets.QWidget +NewLoginUI ui\uis.go 48;" f access:public language:Go line:48 signature:(windowWidth, windowHeight int) type:*widgets.QWidget +NewMainUI ui\uis.go 143;" f access:public language:Go line:143 signature:(windowWidth, windowHeight int, cli *matrix.Client) type:*widgets.QWidget OpenDB matrix\db.go 14;" f access:public language:Go line:14 signature:() type:*buntdb.DB -RespUserDisplayName matrix\types.go 13;" t access:public language:Go line:13 type:struct +RespUserDisplayName matrix\types.go 14;" t access:public language:Go line:14 type:struct StartFileLog util\logger.go 26;" f access:public language:Go line:26 signature:(localLog *log.Logger) type:*log.Logger, *os.File -clientInstance matrix\login.go 10;" v access:private language:Go line:10 type:*Client -db main.go 15;" v access:private language:Go line:15 type:*buntdb.DB +db main.go 16;" v access:private language:Go line:16 type:*buntdb.DB db matrix\db.go 12;" v access:private language:Go line:12 type:*buntdb.DB getOwnUserAvatar matrix\ownUser.go 55;" f access:private language:Go line:55 signature:(cli *Client) type:*gui.QPixmap getUserDisplayName matrix\ownUser.go 23;" f access:private language:Go line:23 signature:(mxid string, cli *Client) type:string, error github.com/Nordgedanken/Neo/matrix main.go 7;" i language:Go line:7 -github.com/Nordgedanken/Neo/matrix uis.go 8;" i language:Go line:8 -github.com/Nordgedanken/Neo/util main.go 8;" i language:Go line:8 +github.com/Nordgedanken/Neo/matrix ui\uis.go 9;" i language:Go line:9 +github.com/Nordgedanken/Neo/ui main.go 8;" i language:Go line:8 +github.com/Nordgedanken/Neo/util main.go 9;" i language:Go line:9 github.com/Nordgedanken/Neo/util matrix\ownUser.go 8;" i language:Go line:8 github.com/matrix-org/gomatrix matrix\login.go 6;" i language:Go line:6 github.com/matrix-org/gomatrix matrix\types.go 4;" i language:Go line:4 +github.com/matrix-org/gomatrix ui\uis.go 10;" i language:Go line:10 github.com/shibukawa/configdir matrix\db.go 8;" i language:Go line:8 github.com/shibukawa/configdir util\logger.go 11;" i language:Go line:11 -github.com/therecipe/qt/core uis.go 9;" i language:Go line:9 +github.com/therecipe/qt/core ui\uis.go 11;" i language:Go line:11 github.com/therecipe/qt/gui matrix\ownUser.go 9;" i language:Go line:9 github.com/therecipe/qt/gui matrix\types.go 5;" i language:Go line:5 -github.com/therecipe/qt/widgets main.go 9;" i language:Go line:9 -github.com/therecipe/qt/widgets uis.go 10;" i language:Go line:10 -github.com/tidwall/buntdb main.go 10;" i language:Go line:10 +github.com/therecipe/qt/widgets main.go 10;" i language:Go line:10 +github.com/therecipe/qt/widgets ui\uis.go 12;" i language:Go line:12 +github.com/tidwall/buntdb main.go 11;" i language:Go line:11 github.com/tidwall/buntdb matrix\db.go 9;" i language:Go line:9 github.com/tidwall/buntdb matrix\login.go 7;" i language:Go line:7 github.com/tidwall/buntdb matrix\ownUser.go 10;" i language:Go line:10 -github.com/tidwall/buntdb uis.go 11;" i language:Go line:11 +github.com/tidwall/buntdb ui\uis.go 13;" i language:Go line:13 init matrix\ownUser.go 15;" f access:private language:Go line:15 signature:() io util\logger.go 4;" i language:Go line:4 -localLog main.go 14;" v access:private language:Go line:14 type:*log.Logger +localLog main.go 15;" v access:private language:Go line:15 type:*log.Logger localLog matrix\ownUser.go 13;" v access:private language:Go line:13 type:*log.Logger log main.go 4;" i language:Go line:4 log matrix\db.go 4;" i language:Go line:4 log matrix\ownUser.go 4;" i language:Go line:4 -log uis.go 4;" i language:Go line:4 +log ui\uis.go 4;" i language:Go line:4 log util\logger.go 5;" i language:Go line:5 logInstance util\logger.go 14;" v access:private language:Go line:14 type:*log.Logger -main main.go 17;" f access:private language:Go line:17 signature:() +main main.go 18;" f access:private language:Go line:18 signature:() main main.go 1;" p language:Go line:1 -main uis.go 1;" p language:Go line:1 matrix matrix\db.go 1;" p language:Go line:1 matrix matrix\login.go 1;" p language:Go line:1 matrix matrix\ownUser.go 1;" p language:Go line:1 @@ -63,16 +64,18 @@ os main.go 5;" i language:Go line:5 os matrix\db.go 5;" i language:Go line:5 os matrix\ownUser.go 5;" i language:Go line:5 os util\logger.go 6;" i language:Go line:6 -password uis.go 15;" v access:private language:Go line:15 type:string +password ui\uis.go 17;" v access:private language:Go line:17 type:string path/filepath matrix\db.go 6;" i language:Go line:6 path/filepath util\logger.go 7;" i language:Go line:7 strings matrix\login.go 4;" i language:Go line:4 strings matrix\ownUser.go 6;" i language:Go line:6 -strings uis.go 5;" i language:Go line:5 -sync uis.go 6;" i language:Go line:6 +strings ui\uis.go 5;" i language:Go line:5 +sync ui\uis.go 6;" i language:Go line:6 sync util\logger.go 8;" i language:Go line:8 +time ui\uis.go 7;" i language:Go line:7 time util\logger.go 9;" i language:Go line:9 -username uis.go 14;" v access:private language:Go line:14 type:string +ui ui\uis.go 1;" p language:Go line:1 +username ui\uis.go 16;" v access:private language:Go line:16 type:string util util\logger.go 1;" p language:Go line:1 -wg uis.go 16;" v access:private language:Go line:16 type:sync.WaitGroup -window main.go 13;" v access:private language:Go line:13 type:*widgets.QMainWindow +wg ui\uis.go 18;" v access:private language:Go line:18 type:sync.WaitGroup +window main.go 14;" v access:private language:Go line:14 type:*widgets.QMainWindow diff --git a/uis.go b/uis.go @@ -4,8 +4,10 @@ import ( "log" "strings" "sync" + "time" "github.com/Nordgedanken/Neo/matrix" + "github.com/matrix-org/gomatrix" "github.com/therecipe/qt/core" "github.com/therecipe/qt/widgets" "github.com/tidwall/buntdb" @@ -191,12 +193,38 @@ func NewMainUI(windowWidth, windowHeight int, cli *matrix.Client) *widgets.QWidg messageScroll.SetWidget(messageView) messageScroll.SetWidgetResizable(true) - // Fake Message - mesageWidget := widgets.NewQWidget(nil, 0) - messageLayout := widgets.NewQVBoxLayout2(mesageWidget) - message := widgets.NewQLabel2("test", nil, 0) - messageLayout.AddWidget(message, 0, core.Qt__AlignTop) - messageViewLayout.AddWidget(message, 0, 0, core.Qt__AlignTop) + // Messages + syncer := cli.Syncer.(*gomatrix.DefaultSyncer) + cli.Store = gomatrix.NewInMemoryStore() + syncer.Store = gomatrix.NewInMemoryStore() + syncer.OnEventType("m.room.message", func(ev *gomatrix.Event) { + localLog.Println(ev) + // TODO Later needs to match current Room + if ev.RoomID == "!zTIXGmDjyRcAqbrWab:matrix.ffslfl.net" { + messageBody, messageOk := ev.Body() + if messageOk == true { + mesageWidget := widgets.NewQWidget(nil, 0) + messageLayout := widgets.NewQVBoxLayout2(mesageWidget) + message := widgets.NewQLabel2(messageBody, nil, 0) + messageLayout.AddWidget(message, 0, core.Qt__AlignTop) + messageViewLayout.AddWidget(message, 0, 0, core.Qt__AlignTop) + } else { + localLog.Println("Message not ok: ", messageOk) + } + } + }) + + // Start Non-blocking sync + localLog.Println("Syncing now") + go func(localLog *log.Logger, cli *matrix.Client) { + if err := cli.Sync(); err != nil { + localLog.Println("Sync() returned ", err) + time.Sleep(10 * time.Second) + } else { + localLog.Println("Stopping Sync()") + } + }(localLog, cli) + localLog.Println("Started Syncing") wrapperLayout.AddWidget(messageScroll, 0, 1, 0)