refactor to mautrix 0.17.x; update deps
This commit is contained in:
20
vendor/gitlab.com/etke.cc/linkpearl/send.go
generated
vendored
20
vendor/gitlab.com/etke.cc/linkpearl/send.go
generated
vendored
@@ -1,6 +1,8 @@
|
||||
package linkpearl
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"maunium.net/go/mautrix"
|
||||
"maunium.net/go/mautrix/event"
|
||||
"maunium.net/go/mautrix/format"
|
||||
@@ -10,9 +12,9 @@ import (
|
||||
// Send a message to the roomID and automatically try to encrypt it, if the destination room is encrypted
|
||||
//
|
||||
//nolint:unparam // it's public interface
|
||||
func (l *Linkpearl) Send(roomID id.RoomID, content interface{}) (id.EventID, error) {
|
||||
func (l *Linkpearl) Send(ctx context.Context, roomID id.RoomID, content interface{}) (id.EventID, error) {
|
||||
l.log.Debug().Str("roomID", roomID.String()).Any("content", content).Msg("sending event")
|
||||
resp, err := l.api.SendMessageEvent(roomID, event.EventMessage, content)
|
||||
resp, err := l.api.SendMessageEvent(ctx, roomID, event.EventMessage, content)
|
||||
if err != nil {
|
||||
return "", UnwrapError(err)
|
||||
}
|
||||
@@ -20,7 +22,7 @@ func (l *Linkpearl) Send(roomID id.RoomID, content interface{}) (id.EventID, err
|
||||
}
|
||||
|
||||
// SendNotice to a room with optional relations, markdown supported
|
||||
func (l *Linkpearl) SendNotice(roomID id.RoomID, message string, relates ...*event.RelatesTo) {
|
||||
func (l *Linkpearl) SendNotice(ctx context.Context, roomID id.RoomID, message string, relates ...*event.RelatesTo) {
|
||||
var withRelatesTo bool
|
||||
content := format.RenderMarkdown(message, true, true)
|
||||
content.MsgType = event.MsgNotice
|
||||
@@ -29,12 +31,12 @@ func (l *Linkpearl) SendNotice(roomID id.RoomID, message string, relates ...*eve
|
||||
content.RelatesTo = relates[0]
|
||||
}
|
||||
|
||||
_, err := l.Send(roomID, &content)
|
||||
_, err := l.Send(ctx, roomID, &content)
|
||||
if err != nil {
|
||||
l.log.Error().Err(UnwrapError(err)).Str("roomID", roomID.String()).Str("retries", "1/2").Msg("cannot send a notice into the room")
|
||||
if withRelatesTo {
|
||||
content.RelatesTo = nil
|
||||
_, err = l.Send(roomID, &content)
|
||||
_, err = l.Send(ctx, roomID, &content)
|
||||
if err != nil {
|
||||
l.log.Error().Err(UnwrapError(err)).Str("roomID", roomID.String()).Str("retries", "2/2").Msg("cannot send a notice into the room even without relations")
|
||||
}
|
||||
@@ -43,13 +45,13 @@ func (l *Linkpearl) SendNotice(roomID id.RoomID, message string, relates ...*eve
|
||||
}
|
||||
|
||||
// SendFile to a matrix room
|
||||
func (l *Linkpearl) SendFile(roomID id.RoomID, req *mautrix.ReqUploadMedia, msgtype event.MessageType, relates ...*event.RelatesTo) error {
|
||||
func (l *Linkpearl) SendFile(ctx context.Context, roomID id.RoomID, req *mautrix.ReqUploadMedia, msgtype event.MessageType, relates ...*event.RelatesTo) error {
|
||||
var relation *event.RelatesTo
|
||||
if len(relates) > 0 {
|
||||
relation = relates[0]
|
||||
}
|
||||
|
||||
resp, err := l.GetClient().UploadMedia(*req)
|
||||
resp, err := l.GetClient().UploadMedia(ctx, *req)
|
||||
if err != nil {
|
||||
err = UnwrapError(err)
|
||||
l.log.Error().Err(err).Str("file", req.FileName).Msg("cannot upload file")
|
||||
@@ -62,13 +64,13 @@ func (l *Linkpearl) SendFile(roomID id.RoomID, req *mautrix.ReqUploadMedia, msgt
|
||||
RelatesTo: relation,
|
||||
}
|
||||
|
||||
_, err = l.Send(roomID, content)
|
||||
_, err = l.Send(ctx, roomID, content)
|
||||
err = UnwrapError(err)
|
||||
if err != nil {
|
||||
l.log.Error().Err(err).Str("roomID", roomID.String()).Str("retries", "1/2").Msg("cannot send file into the room")
|
||||
if relation != nil {
|
||||
content.RelatesTo = nil
|
||||
_, err = l.Send(roomID, &content)
|
||||
_, err = l.Send(ctx, roomID, &content)
|
||||
err = UnwrapError(err)
|
||||
if err != nil {
|
||||
l.log.Error().Err(UnwrapError(err)).Str("roomID", roomID.String()).Str("retries", "2/2").Msg("cannot send file into the room even without relations")
|
||||
|
||||
Reference in New Issue
Block a user