commit a44bb8784bd13789a69b8ab9e1a04e7828588488
parent 88b70805d9fbc76ee04cfacf18dfcfeceb248cc5
Author: MTRNord <mtrnord1@gmail.com>
Date: Tue, 22 Aug 2017 17:13:07 +0200
Rework custom matrix Commands and add Ctags (makes Atom happier)
Diffstat:
5 files changed, 106 insertions(+), 14 deletions(-)
diff --git a/matrix/login.go b/matrix/login.go
@@ -8,18 +8,20 @@ import (
"github.com/tidwall/buntdb"
)
-var clientInstance *gomatrix.Client
+var clientInstance *Client
var once sync.Once
//getClient returns a Client
-func getClient(homeserverURL, userID, accessToken string) (*gomatrix.Client, error) {
+func getClient(homeserverURL, userID, accessToken string) (*Client, error) {
var err error
+ var client *gomatrix.Client
once.Do(func() {
- clientInstance, err = gomatrix.NewClient(homeserverURL, userID, accessToken)
+ client, err = gomatrix.NewClient(homeserverURL, userID, accessToken)
})
if err != nil {
return nil, err
}
+ clientInstance = &Client{client}
DBerr := db.Update(func(tx *buntdb.Tx) error {
tx.Set("user:accessToken", clientInstance.AccessToken, nil)
@@ -36,7 +38,7 @@ func getClient(homeserverURL, userID, accessToken string) (*gomatrix.Client, err
}
//LoginUser Creates a Session for the User
-func LoginUser(username, password string) (*gomatrix.Client, error) {
+func LoginUser(username, password string) (*Client, error) {
usernameSplit := strings.Split(username, ":")
homeserverURL := usernameSplit[1]
cli, cliErr := getClient("https://"+homeserverURL, "", "")
diff --git a/matrix/ownUser.go b/matrix/ownUser.go
@@ -6,26 +6,25 @@ import (
"strings"
"github.com/Nordgedanken/Neo/util"
- "github.com/matrix-org/gomatrix"
"github.com/therecipe/qt/gui"
)
var localLog *log.Logger
-// RespUserDisplayName is the Response type of GetUserDisplayName()
+// RespUserDisplayName is the Response type of getUserDisplayName()
type RespUserDisplayName struct {
DisplayName string `json:"displayname"`
}
-// GetUserDisplayName returns the Dispaly name to a MXID
-func GetUserDisplayName(mxid string, cli *gomatrix.Client) (resp *RespUserDisplayName, err error) {
+// getUserDisplayName returns the Dispaly name to a MXID
+func getUserDisplayName(mxid string, cli *Client) (resp *RespUserDisplayName, err error) {
urlPath := cli.BuildURL("profile", mxid, "displayname")
_, err = cli.MakeRequest("GET", urlPath, nil, &resp)
return
}
-// GetOwnUserAvatar returns a *gui.QPixmap of an UserAvatar
-func GetOwnUserAvatar(cli *gomatrix.Client) *gui.QPixmap {
+// getOwnUserAvatar returns a *gui.QPixmap of an UserAvatar
+func getOwnUserAvatar(cli *Client) *gui.QPixmap {
var file *os.File
localLog = util.Logger()
localLog, file = util.StartFileLog(localLog)
diff --git a/matrix/types.go b/matrix/types.go
@@ -0,0 +1,22 @@
+package matrix
+
+import (
+ "github.com/matrix-org/gomatrix"
+ "github.com/therecipe/qt/gui"
+)
+
+type Client struct {
+ *gomatrix.Client
+}
+
+// GetUserDisplayName returns the Dispaly name to a MXID
+func (cli *Client) GetUserDisplayName(mxid string) (resp *RespUserDisplayName, err error) {
+ resp, err = getUserDisplayName(mxid, cli)
+ return
+}
+
+// GetOwnUserAvatar returns a *gui.QPixmap of an UserAvatar
+func (cli *Client) GetOwnUserAvatar() (img *gui.QPixmap) {
+ img = getOwnUserAvatar(cli)
+ return
+}
diff --git a/tags b/tags
@@ -0,0 +1,70 @@
+!_TAG_FILE_FORMAT 2
+!_TAG_FILE_SORTED 1 /0=unsorted, 1=sorted/
+!_TAG_PROGRAM_AUTHOR Joel Stemmer /stemmertech@gmail.com/
+!_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
+C rcc_cgo_windows_windows_386.go 11;" i language:Go line:11
+Client matrix\types.go 8;" t access:public language:Go line:8 type:struct
+DisplayName matrix\ownUser.go 16;" w access:public ctype:RespUserDisplayName language:Go line:16 type:string
+GetOwnUserAvatar matrix\types.go 19;" m access:public ctype:Client language:Go line:19 signature:() type:*gui.QPixmap
+GetUserDisplayName matrix\types.go 13;" m access:public ctype:Client language:Go line:13 signature:(mxid string) type:*RespUserDisplayName, error
+Logger util\logger.go 15;" f access:public language:Go line:15 signature:() type:*log.Logger
+LoginUser matrix\login.go 41;" f access:public language:Go line:41 signature:(username, password string) type:*Client, error
+NewLoginUI uis.go 16;" f access:public language:Go line:16 signature:(windowWidth, windowHeight int) type:*widgets.QWidget
+NewMainUI uis.go 74;" f access:public language:Go line:74 signature:(windowWidth, windowHeight int, cli *matrix.Client) type:*widgets.QWidget
+OpenDB matrix\db.go 12;" f access:public language:Go line:12 signature:() type:*buntdb.DB
+RespUserDisplayName matrix\ownUser.go 15;" t access:public language:Go line:15 type:struct
+StartFileLog util\logger.go 23;" f access:public language:Go line:23 signature:(localLog *log.Logger) type:*log.Logger, *os.File
+clientInstance matrix\login.go 11;" v access:private language:Go line:11 type:*Client
+db matrix\db.go 10;" v access:private language:Go line:10 type:*buntdb.DB
+fmt uis.go 4;" i language:Go line:4
+getClient matrix\login.go 15;" f access:private language:Go line:15 signature:(homeserverURL, userID, accessToken string) type:*Client, error
+getOwnUserAvatar matrix\ownUser.go 27;" f access:private language:Go line:27 signature:(cli *Client) type:*gui.QPixmap
+getUserDisplayName matrix\ownUser.go 20;" f access:private ctype:RespUserDisplayName language:Go line:20 signature:(mxid string, cli *Client) type:*RespUserDisplayName, error
+github.com/Nordgedanken/Neo/matrix main.go 7;" i language:Go line:7
+github.com/Nordgedanken/Neo/matrix uis.go 6;" i language:Go line:6
+github.com/Nordgedanken/Neo/util main.go 8;" i language:Go line:8
+github.com/Nordgedanken/Neo/util matrix\ownUser.go 8;" i language:Go line:8
+github.com/matrix-org/gomatrix matrix\login.go 7;" i language:Go line:7
+github.com/matrix-org/gomatrix matrix\types.go 4;" i language:Go line:4
+github.com/therecipe/qt/core uis.go 7;" i language:Go line:7
+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/uitools uis.go 8;" i language:Go line:8
+github.com/therecipe/qt/widgets main.go 9;" i language:Go line:9
+github.com/therecipe/qt/widgets uis.go 9;" i language:Go line:9
+github.com/tidwall/buntdb matrix\db.go 7;" i language:Go line:7
+github.com/tidwall/buntdb matrix\login.go 8;" i language:Go line:8
+io util\logger.go 4;" i language:Go line:4
+localLog main.go 12;" v access:private language:Go line:12 type:*log.Logger
+localLog matrix\ownUser.go 12;" v access:private language:Go line:12 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 util\logger.go 5;" i language:Go line:5
+logInstance util\logger.go 11;" v access:private language:Go line:11 type:*log.Logger
+main main.go 15;" f access:private language:Go line:15 signature:()
+main main.go 1;" p language:Go line:1
+main rcc_cgo_windows_windows_386.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
+matrix matrix\types.go 1;" p language:Go line:1
+once matrix\login.go 12;" v access:private language:Go line:12 type:sync.Once
+once util\logger.go 12;" v access:private language:Go line:12 type:sync.Once
+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 13;" v access:private language:Go line:13 type:string
+strings matrix\login.go 4;" i language:Go line:4
+strings matrix\ownUser.go 6;" i language:Go line:6
+sync matrix\login.go 5;" i language:Go line:5
+sync util\logger.go 7;" i language:Go line:7
+time util\logger.go 8;" i language:Go line:8
+username uis.go 12;" v access:private language:Go line:12 type:string
+util util\logger.go 1;" p language:Go line:1
+window main.go 13;" v access:private language:Go line:13 type:*widgets.QMainWindow
diff --git a/uis.go b/uis.go
@@ -4,7 +4,6 @@ import (
"fmt"
"github.com/Nordgedanken/Neo/matrix"
- "github.com/matrix-org/gomatrix"
"github.com/therecipe/qt/core"
"github.com/therecipe/qt/uitools"
"github.com/therecipe/qt/widgets"
@@ -72,7 +71,7 @@ func NewLoginUI(windowWidth, windowHeight int) *widgets.QWidget {
}
//NewMainUI initializes the login Screen
-func NewMainUI(windowWidth, windowHeight int, cli *gomatrix.Client) *widgets.QWidget {
+func NewMainUI(windowWidth, windowHeight int, cli *matrix.Client) *widgets.QWidget {
widget := widgets.NewQWidget(nil, 0)
loader := uitools.NewQUiLoader(nil)
@@ -92,7 +91,7 @@ func NewMainUI(windowWidth, windowHeight int, cli *gomatrix.Client) *widgets.QWi
mxidLabel.SetText(fmt.Sprint(username))
// Set Dispalyname Label
- DisplayNameResp, DisplayNameErr := matrix.GetUserDisplayName(username, cli)
+ DisplayNameResp, DisplayNameErr := cli.GetUserDisplayName(username)
if DisplayNameErr != nil {
localLog.Println(DisplayNameErr)
}
@@ -100,7 +99,7 @@ func NewMainUI(windowWidth, windowHeight int, cli *gomatrix.Client) *widgets.QWi
// Set Avatar
avatarLogo.SetAlignment(core.Qt__AlignBottom | core.Qt__AlignRight)
- avatarLogo.SetPixmap(matrix.GetOwnUserAvatar(cli))
+ avatarLogo.SetPixmap(cli.GetOwnUserAvatar())
layout := widgets.NewQVBoxLayout()
layout.AddWidget(mainWidget, 0, 0)