mirror of
https://github.com/pushbits/server.git
synced 2025-05-25 06:46:35 +02:00
send first message via mautrix
This commit is contained in:
parent
0ee3f69d15
commit
e48cbae59b
4 changed files with 101 additions and 11 deletions
|
@ -5,6 +5,8 @@ import (
|
|||
|
||||
"github.com/matrix-org/gomatrix"
|
||||
"github.com/pushbits/server/internal/configuration"
|
||||
"maunium.net/go/mautrix"
|
||||
"maunium.net/go/mautrix/id"
|
||||
)
|
||||
|
||||
var (
|
||||
|
@ -13,14 +15,16 @@ var (
|
|||
|
||||
// Dispatcher holds information for sending notifications to clients.
|
||||
type Dispatcher struct {
|
||||
client *gomatrix.Client
|
||||
formatting configuration.Formatting
|
||||
client *gomatrix.Client // TODO get rid of this client as a dependency
|
||||
mautrixClient *mautrix.Client
|
||||
formatting configuration.Formatting
|
||||
}
|
||||
|
||||
// Create instanciates a dispatcher connection.
|
||||
func Create(homeserver, username, password string, formatting configuration.Formatting) (*Dispatcher, error) {
|
||||
log.Println("Setting up dispatcher.")
|
||||
|
||||
// TODO remove from here
|
||||
client, err := gomatrix.NewClient(homeserver, "", "")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
@ -36,8 +40,25 @@ func Create(homeserver, username, password string, formatting configuration.Form
|
|||
}
|
||||
|
||||
client.SetCredentials(response.UserID, response.AccessToken)
|
||||
// To here
|
||||
|
||||
return &Dispatcher{client: client, formatting: formatting}, nil
|
||||
matrixClient, err := mautrix.NewClient(homeserver, "", "")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
_, err = matrixClient.Login(&mautrix.ReqLogin{
|
||||
Type: "m.login.password",
|
||||
Identifier: mautrix.UserIdentifier{Type: mautrix.IdentifierTypeUser, User: username},
|
||||
Password: password,
|
||||
DeviceID: id.DeviceID("my-device"), // TODO make device ID configurable
|
||||
StoreCredentials: true,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &Dispatcher{client: client, formatting: formatting, mautrixClient: matrixClient}, nil
|
||||
}
|
||||
|
||||
// Close closes the dispatcher connection.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue