Add support for sending replies
This commit is contained in:
parent
a350e4fc00
commit
b4103e9ba8
2 changed files with 18 additions and 3 deletions
|
@ -3,7 +3,7 @@
|
|||
* [ ] Message content
|
||||
* [x] Plain text
|
||||
* [ ] Media/files
|
||||
* [ ] Replies (RCS)
|
||||
* [x] Replies (RCS)
|
||||
* [ ] Reactions (RCS)
|
||||
* [ ] Typing notifications (RCS)
|
||||
* [ ] Read receipts (RCS)
|
||||
|
|
19
portal.go
19
portal.go
|
@ -29,7 +29,7 @@ import (
|
|||
|
||||
"github.com/gabriel-vasile/mimetype"
|
||||
"github.com/rs/zerolog"
|
||||
log "maunium.net/go/maulogger/v2"
|
||||
"maunium.net/go/maulogger/v2"
|
||||
|
||||
"maunium.net/go/mautrix"
|
||||
"maunium.net/go/mautrix/appservice"
|
||||
|
@ -220,7 +220,7 @@ type Portal struct {
|
|||
|
||||
bridge *GMBridge
|
||||
// Deprecated: use zerolog
|
||||
log log.Logger
|
||||
log maulogger.Logger
|
||||
zlog zerolog.Logger
|
||||
|
||||
roomCreateLock sync.Mutex
|
||||
|
@ -999,6 +999,7 @@ func (portal *Portal) HandleMatrixMessage(sender *User, evt *event.Event, timing
|
|||
ms := metricSender{portal: portal, timings: &timings}
|
||||
|
||||
log := portal.zlog.With().Str("event_id", evt.ID.String()).Logger()
|
||||
ctx := log.WithContext(context.TODO())
|
||||
log.Debug().Dur("age", timings.totalReceive).Msg("Handling Matrix message")
|
||||
|
||||
content, ok := evt.Content.Parsed.(*event.MessageEventContent)
|
||||
|
@ -1006,6 +1007,19 @@ func (portal *Portal) HandleMatrixMessage(sender *User, evt *event.Event, timing
|
|||
return
|
||||
}
|
||||
|
||||
var replyToID string
|
||||
replyToMXID := content.RelatesTo.GetReplyTo()
|
||||
if replyToMXID != "" {
|
||||
replyToMsg, err := portal.bridge.DB.Message.GetByMXID(ctx, replyToMXID)
|
||||
if err != nil {
|
||||
log.Err(err).Str("reply_to_mxid", replyToMXID.String()).Msg("Failed to get reply target message")
|
||||
} else if replyToMsg == nil {
|
||||
log.Warn().Str("reply_to_mxid", replyToMXID.String()).Msg("Reply target message not found")
|
||||
} else {
|
||||
replyToID = replyToMsg.ID
|
||||
}
|
||||
}
|
||||
|
||||
txnID := util.GenerateTmpId()
|
||||
portal.outgoingMessagesLock.Lock()
|
||||
portal.outgoingMessages[txnID] = evt.ID
|
||||
|
@ -1020,6 +1034,7 @@ func (portal *Portal) HandleMatrixMessage(sender *User, evt *event.Event, timing
|
|||
sender.Client.NewMessageBuilder().
|
||||
SetConversationID(portal.ID).
|
||||
SetSelfParticipantID(portal.SelfUserID).
|
||||
SetReplyMessage(replyToID).
|
||||
SetContent(text).
|
||||
SetTmpID(txnID),
|
||||
)
|
||||
|
|
Loading…
Reference in a new issue