Skip to content
Snippets Groups Projects
Verified Commit 1553ab52 authored by Janne Mareike Koschinski's avatar Janne Mareike Koschinski
Browse files

fix: make pushurl/token public

parent 8b2f6a7b
No related branches found
Tags v0.1.1 v0.1.2 v0.1.3
No related merge requests found
......@@ -11,28 +11,28 @@ import (
)
type MatrixBot struct {
token *MatrixToken
pushUrl *url.URL
Token *MatrixToken
PushUrl *url.URL
handlers map[string]func(bot *MatrixBot, notification Notification) error
}
func NewMatrixBot(pushUrl *url.URL) *MatrixBot {
return &MatrixBot{
token: nil,
pushUrl: pushUrl,
Token: nil,
PushUrl: pushUrl,
handlers: make(map[string]func(bot *MatrixBot, notification Notification) error),
}
}
func (bot *MatrixBot) RefreshToken() error {
if bot.token == nil {
if bot.Token == nil {
return fmt.Errorf("no refresh token available")
}
userData, err := Refresh(bot.token.RefreshToken)
userData, err := Refresh(bot.Token.RefreshToken)
if err != nil {
return err
}
bot.token = &MatrixToken{
bot.Token = &MatrixToken{
AccessToken: userData.AccessToken,
Expires: time.Now().Add(time.Duration(userData.ExpiresInMs) / 2 * time.Millisecond),
RefreshToken: userData.RefreshToken,
......@@ -45,7 +45,7 @@ func (bot *MatrixBot) Login(username string, password string, deviceId string) e
if err != nil {
return err
}
bot.token = &MatrixToken{
bot.Token = &MatrixToken{
AccessToken: userData.AccessToken,
Expires: time.Now().Add(time.Duration(userData.ExpiresInMs) / 2 * time.Millisecond),
RefreshToken: userData.RefreshToken,
......@@ -55,7 +55,7 @@ func (bot *MatrixBot) Login(username string, password string, deviceId string) e
func (bot *MatrixBot) RefreshTask() {
for true {
if bot.token != nil && time.Now().After(bot.token.Expires) {
if bot.Token != nil && time.Now().After(bot.Token.Expires) {
if err := bot.RefreshToken(); err != nil {
log.Printf("error refresh token: %s\n", err.Error())
}
......@@ -65,7 +65,7 @@ func (bot *MatrixBot) RefreshTask() {
}
func (bot *MatrixBot) RegisterPusher() error {
return SetPusher(*bot.token, bot.pushUrl.String())
return SetPusher(*bot.Token, bot.PushUrl.String())
}
func (bot *MatrixBot) HandleFunc(command string, handler func(bot *MatrixBot, notification Notification) error) {
......@@ -76,8 +76,8 @@ func (bot *MatrixBot) Serve(endpoint string) {
http.HandleFunc("/healthz", func(writer http.ResponseWriter, request *http.Request) {
_, _ = io.WriteString(writer, "OK\n")
})
log.Printf("listening for push notifications on %s\n", bot.pushUrl.Path)
http.HandleFunc(bot.pushUrl.Path, func(writer http.ResponseWriter, request *http.Request) {
log.Printf("listening for push notifications on %s\n", bot.PushUrl.Path)
http.HandleFunc(bot.PushUrl.Path, func(writer http.ResponseWriter, request *http.Request) {
log.Println("Received push notification")
notification, err := ParseNotification(request.Body)
if err != nil {
......@@ -87,7 +87,7 @@ func (bot *MatrixBot) Serve(endpoint string) {
if notification.EventId == "" {
return
}
err = SetReadReceipt(*bot.token, notification.RoomId, notification.EventId)
err = SetReadReceipt(*bot.Token, notification.RoomId, notification.EventId)
if err != nil {
log.Println(err.Error())
return
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment