mirror of
https://github.com/pushbits/server.git
synced 2025-07-28 05:48:00 +02:00
Update Go dependencies
This commit is contained in:
parent
6903bdb62e
commit
c8705b146e
5 changed files with 94 additions and 92 deletions
|
@ -1,6 +1,7 @@
|
|||
package dispatcher
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/pushbits/server/internal/configuration"
|
||||
|
@ -20,7 +21,7 @@ func buildRoomTopic(id uint) string {
|
|||
func (d *Dispatcher) RegisterApplication(id uint, name, user string) (string, error) {
|
||||
log.L.Printf("Registering application %s, notifications will be relayed to user %s.\n", name, user)
|
||||
|
||||
resp, err := d.mautrixClient.CreateRoom(&mautrix.ReqCreateRoom{
|
||||
resp, err := d.mautrixClient.CreateRoom(context.Background(), &mautrix.ReqCreateRoom{
|
||||
Visibility: "private",
|
||||
Invite: []mId.UserID{mId.UserID(user)},
|
||||
IsDirect: true,
|
||||
|
@ -44,7 +45,7 @@ func (d *Dispatcher) DeregisterApplication(a *model.Application, u *model.User)
|
|||
|
||||
// The user might have left the channel, but we can still try to remove them.
|
||||
|
||||
if _, err := d.mautrixClient.KickUser(mId.RoomID(a.MatrixID), &mautrix.ReqKickUser{
|
||||
if _, err := d.mautrixClient.KickUser(context.Background(), mId.RoomID(a.MatrixID), &mautrix.ReqKickUser{
|
||||
Reason: "This application was deleted",
|
||||
UserID: mId.UserID(u.MatrixID),
|
||||
}); err != nil {
|
||||
|
@ -52,12 +53,12 @@ func (d *Dispatcher) DeregisterApplication(a *model.Application, u *model.User)
|
|||
return err
|
||||
}
|
||||
|
||||
if _, err := d.mautrixClient.LeaveRoom(mId.RoomID(a.MatrixID)); err != nil {
|
||||
if _, err := d.mautrixClient.LeaveRoom(context.Background(), mId.RoomID(a.MatrixID)); err != nil {
|
||||
log.L.Print(err)
|
||||
return err
|
||||
}
|
||||
|
||||
if _, err := d.mautrixClient.ForgetRoom(mId.RoomID(a.MatrixID)); err != nil {
|
||||
if _, err := d.mautrixClient.ForgetRoom(context.Background(), mId.RoomID(a.MatrixID)); err != nil {
|
||||
log.L.Print(err)
|
||||
return err
|
||||
}
|
||||
|
@ -66,7 +67,7 @@ func (d *Dispatcher) DeregisterApplication(a *model.Application, u *model.User)
|
|||
}
|
||||
|
||||
func (d *Dispatcher) sendRoomEvent(roomID, eventType string, content interface{}) error {
|
||||
if _, err := d.mautrixClient.SendStateEvent(mId.RoomID(roomID), event.NewEventType(eventType), "", content); err != nil {
|
||||
if _, err := d.mautrixClient.SendStateEvent(context.Background(), mId.RoomID(roomID), event.NewEventType(eventType), "", content); err != nil {
|
||||
log.L.Print(err)
|
||||
return err
|
||||
}
|
||||
|
@ -107,7 +108,7 @@ func (d *Dispatcher) UpdateApplication(a *model.Application, behavior *configura
|
|||
|
||||
// IsOrphan checks if the user is still connected to the channel.
|
||||
func (d *Dispatcher) IsOrphan(a *model.Application, u *model.User) (bool, error) {
|
||||
resp, err := d.mautrixClient.JoinedMembers(mId.RoomID(a.MatrixID))
|
||||
resp, err := d.mautrixClient.JoinedMembers(context.Background(), mId.RoomID(a.MatrixID))
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
@ -123,7 +124,7 @@ func (d *Dispatcher) IsOrphan(a *model.Application, u *model.User) (bool, error)
|
|||
|
||||
// RepairApplication re-invites the user to the channel.
|
||||
func (d *Dispatcher) RepairApplication(a *model.Application, u *model.User) error {
|
||||
_, err := d.mautrixClient.InviteUser(mId.RoomID(a.MatrixID), &mautrix.ReqInviteUser{
|
||||
_, err := d.mautrixClient.InviteUser(context.Background(), mId.RoomID(a.MatrixID), &mautrix.ReqInviteUser{
|
||||
UserID: mId.UserID(u.MatrixID),
|
||||
})
|
||||
if err != nil {
|
||||
|
|
|
@ -2,6 +2,8 @@
|
|||
package dispatcher
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"maunium.net/go/mautrix"
|
||||
"maunium.net/go/mautrix/id"
|
||||
|
||||
|
@ -24,7 +26,7 @@ func Create(homeserver, username, password string, formatting configuration.Form
|
|||
return nil, err
|
||||
}
|
||||
|
||||
_, err = matrixClient.Login(&mautrix.ReqLogin{
|
||||
_, err = matrixClient.Login(context.Background(), &mautrix.ReqLogin{
|
||||
Type: mautrix.AuthTypePassword,
|
||||
Identifier: mautrix.UserIdentifier{Type: mautrix.IdentifierTypeUser, User: username},
|
||||
Password: password,
|
||||
|
@ -42,7 +44,7 @@ func Create(homeserver, username, password string, formatting configuration.Form
|
|||
func (d *Dispatcher) Close() {
|
||||
log.L.Printf("Logging out.")
|
||||
|
||||
_, err := d.mautrixClient.Logout()
|
||||
_, err := d.mautrixClient.Logout(context.Background())
|
||||
if err != nil {
|
||||
log.L.Printf("Error while logging out: %s", err)
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package dispatcher
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"html"
|
||||
"strings"
|
||||
|
@ -71,7 +72,7 @@ func (d *Dispatcher) SendNotification(a *model.Application, n *model.Notificatio
|
|||
Format: MessageFormatHTML,
|
||||
}
|
||||
|
||||
evt, err := d.mautrixClient.SendMessageEvent(mId.RoomID(a.MatrixID), event.EventMessage, &messageEvent)
|
||||
evt, err := d.mautrixClient.SendMessageEvent(context.Background(), mId.RoomID(a.MatrixID), event.EventMessage, &messageEvent)
|
||||
if err != nil {
|
||||
log.L.Errorln(err)
|
||||
return "", err
|
||||
|
@ -185,7 +186,7 @@ func (d *Dispatcher) getMessage(a *model.Application, id string) (*event.Event,
|
|||
maxPages := 10 // Maximum pages to request (10 messages per page)
|
||||
|
||||
for i := 0; i < maxPages; i++ {
|
||||
messages, err := d.mautrixClient.Messages(mId.RoomID(a.MatrixID), start, end, 'b', nil, 10)
|
||||
messages, err := d.mautrixClient.Messages(context.Background(), mId.RoomID(a.MatrixID), start, end, 'b', nil, 10)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -224,7 +225,7 @@ func (d *Dispatcher) replaceMessage(a *model.Application, newBody, newFormattedB
|
|||
Format: MessageFormatHTML,
|
||||
}
|
||||
|
||||
sendEvent, err := d.mautrixClient.SendMessageEvent(mId.RoomID(a.MatrixID), event.EventMessage, &replaceEvent)
|
||||
sendEvent, err := d.mautrixClient.SendMessageEvent(context.Background(), mId.RoomID(a.MatrixID), event.EventMessage, &replaceEvent)
|
||||
if err != nil {
|
||||
log.L.Errorln(err)
|
||||
return nil, err
|
||||
|
@ -259,7 +260,7 @@ func (d *Dispatcher) respondToMessage(a *model.Application, body, formattedBody
|
|||
}
|
||||
notificationEvent.RelatesTo = ¬ificationRelation
|
||||
|
||||
sendEvent, err := d.mautrixClient.SendMessageEvent(mId.RoomID(a.MatrixID), event.EventMessage, ¬ificationEvent)
|
||||
sendEvent, err := d.mautrixClient.SendMessageEvent(context.Background(), mId.RoomID(a.MatrixID), event.EventMessage, ¬ificationEvent)
|
||||
if err != nil {
|
||||
log.L.Errorln(err)
|
||||
return nil, err
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue