forked from mirror/mautrix-discord
Send error messages in thread if applicable
This commit is contained in:
parent
45359853de
commit
5b8473b3de
1 changed files with 9 additions and 4 deletions
13
portal.go
13
portal.go
|
@ -1175,7 +1175,7 @@ func (portal *Portal) startThreadFromMatrix(sender *User, threadRoot id.EventID)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (portal *Portal) sendErrorMessage(msgType, message string, confirmed bool) id.EventID {
|
func (portal *Portal) sendErrorMessage(evt *event.Event, msgType, message string, confirmed bool) id.EventID {
|
||||||
if !portal.bridge.Config.Bridge.MessageErrorNotices {
|
if !portal.bridge.Config.Bridge.MessageErrorNotices {
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
@ -1186,10 +1186,15 @@ func (portal *Portal) sendErrorMessage(msgType, message string, confirmed bool)
|
||||||
if portal.RelayWebhookSecret != "" {
|
if portal.RelayWebhookSecret != "" {
|
||||||
message = strings.ReplaceAll(message, portal.RelayWebhookSecret, "<redacted>")
|
message = strings.ReplaceAll(message, portal.RelayWebhookSecret, "<redacted>")
|
||||||
}
|
}
|
||||||
resp, err := portal.sendMatrixMessage(portal.MainIntent(), event.EventMessage, &event.MessageEventContent{
|
content := &event.MessageEventContent{
|
||||||
MsgType: event.MsgNotice,
|
MsgType: event.MsgNotice,
|
||||||
Body: fmt.Sprintf("\u26a0 Your %s %s bridged: %v", msgType, certainty, message),
|
Body: fmt.Sprintf("\u26a0 Your %s %s bridged: %v", msgType, certainty, message),
|
||||||
}, nil, 0)
|
}
|
||||||
|
relatable, ok := evt.Content.Parsed.(event.Relatable)
|
||||||
|
if ok && relatable.OptionalGetRelatesTo().GetThreadParent() != "" {
|
||||||
|
content.GetRelatesTo().SetThread(relatable.OptionalGetRelatesTo().GetThreadParent(), evt.ID)
|
||||||
|
}
|
||||||
|
resp, err := portal.sendMatrixMessage(portal.MainIntent(), event.EventMessage, content, nil, 0)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
portal.log.Warn().Err(err).Msg("Failed to send bridging error message")
|
portal.log.Warn().Err(err).Msg("Failed to send bridging error message")
|
||||||
return ""
|
return ""
|
||||||
|
@ -1354,7 +1359,7 @@ func (portal *Portal) sendMessageMetrics(evt *event.Event, err error, part strin
|
||||||
if humanMessage == "" {
|
if humanMessage == "" {
|
||||||
humanMessage = err.Error()
|
humanMessage = err.Error()
|
||||||
}
|
}
|
||||||
portal.sendErrorMessage(msgType, humanMessage, isCertain)
|
portal.sendErrorMessage(evt, msgType, humanMessage, isCertain)
|
||||||
}
|
}
|
||||||
portal.sendStatusEvent(evt.ID, err)
|
portal.sendStatusEvent(evt.ID, err)
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Reference in a new issue