5
0
mirror of https://github.com/cwinfo/matterbridge.git synced 2024-11-22 09:20:27 +00:00

Make HTMLDisable work correct (matrix) (#1716)

This commit is contained in:
Wim 2022-02-06 20:58:13 +01:00 committed by GitHub
parent 9c43eff753
commit 7288f71201
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -48,8 +48,10 @@ type matrixUsername struct {
// SubTextMessage represents the new content of the message in edit messages. // SubTextMessage represents the new content of the message in edit messages.
type SubTextMessage struct { type SubTextMessage struct {
MsgType string `json:"msgtype"` MsgType string `json:"msgtype"`
Body string `json:"body"` Body string `json:"body"`
FormattedBody string `json:"formatted_body,omitempty"`
Format string `json:"format,omitempty"`
} }
// MessageRelation explains how the current message relates to a previous message. // MessageRelation explains how the current message relates to a previous message.
@ -151,7 +153,13 @@ func (b *Bmatrix) Send(msg config.Message) (string, error) {
m := matrix.TextMessage{ m := matrix.TextMessage{
MsgType: "m.emote", MsgType: "m.emote",
Body: username.plain + msg.Text, Body: username.plain + msg.Text,
FormattedBody: username.formatted + msg.Text, FormattedBody: username.formatted + helper.ParseMarkdown(msg.Text),
Format: "org.matrix.custom.html",
}
if b.GetBool("HTMLDisable") {
m.Format = ""
m.FormattedBody = ""
} }
msgID := "" msgID := ""
@ -214,20 +222,29 @@ func (b *Bmatrix) Send(msg config.Message) (string, error) {
// Edit message if we have an ID // Edit message if we have an ID
if msg.ID != "" { if msg.ID != "" {
rmsg := EditedMessage{TextMessage: matrix.TextMessage{ rmsg := EditedMessage{
Body: username.plain + msg.Text, TextMessage: matrix.TextMessage{
MsgType: "m.text", Body: username.plain + msg.Text,
}} MsgType: "m.text",
if b.GetBool("HTMLDisable") { Format: "org.matrix.custom.html",
rmsg.TextMessage.FormattedBody = username.formatted + "* " + msg.Text FormattedBody: username.formatted + helper.ParseMarkdown(msg.Text),
} else { },
rmsg.Format = "org.matrix.custom.html"
rmsg.TextMessage.FormattedBody = username.formatted + "* " + helper.ParseMarkdown(msg.Text)
} }
rmsg.NewContent = SubTextMessage{ rmsg.NewContent = SubTextMessage{
Body: rmsg.TextMessage.Body, Body: rmsg.TextMessage.Body,
MsgType: "m.text", FormattedBody: rmsg.TextMessage.FormattedBody,
Format: rmsg.TextMessage.Format,
MsgType: "m.text",
} }
if b.GetBool("HTMLDisable") {
rmsg.TextMessage.Format = ""
rmsg.TextMessage.FormattedBody = ""
rmsg.NewContent.Format = ""
rmsg.NewContent.FormattedBody = ""
}
rmsg.RelatedTo = MessageRelation{ rmsg.RelatedTo = MessageRelation{
EventID: msg.ID, EventID: msg.ID,
Type: "m.replace", Type: "m.replace",
@ -251,6 +268,50 @@ func (b *Bmatrix) Send(msg config.Message) (string, error) {
MsgType: "m.notice", MsgType: "m.notice",
Body: username.plain + msg.Text, Body: username.plain + msg.Text,
FormattedBody: username.formatted + msg.Text, FormattedBody: username.formatted + msg.Text,
Format: "org.matrix.custom.html",
}
if b.GetBool("HTMLDisable") {
m.Format = ""
m.FormattedBody = ""
}
var (
resp *matrix.RespSendEvent
err error
)
err = b.retry(func() error {
resp, err = b.mc.SendMessageEvent(channel, "m.room.message", m)
return err
})
if err != nil {
return "", err
}
return resp.EventID, err
}
if msg.ParentValid() {
m := ReplyMessage{
TextMessage: matrix.TextMessage{
MsgType: "m.text",
Body: username.plain + msg.Text,
FormattedBody: username.formatted + helper.ParseMarkdown(msg.Text),
Format: "org.matrix.custom.html",
},
}
if b.GetBool("HTMLDisable") {
m.TextMessage.Format = ""
m.TextMessage.FormattedBody = ""
}
m.RelatedTo = InReplyToRelation{
InReplyTo: InReplyToRelationContent{
EventID: msg.ParentID,
},
} }
var ( var (
@ -288,38 +349,6 @@ func (b *Bmatrix) Send(msg config.Message) (string, error) {
return resp.EventID, err return resp.EventID, err
} }
if msg.ParentValid() {
m := ReplyMessage{
TextMessage: matrix.TextMessage{
MsgType: "m.text",
Body: username.plain + msg.Text,
FormattedBody: username.formatted + helper.ParseMarkdown(msg.Text),
},
}
m.RelatedTo = InReplyToRelation{
InReplyTo: InReplyToRelationContent{
EventID: msg.ParentID,
},
}
var (
resp *matrix.RespSendEvent
err error
)
err = b.retry(func() error {
resp, err = b.mc.SendMessageEvent(channel, "m.room.message", m)
return err
})
if err != nil {
return "", err
}
return resp.EventID, err
}
// Post normal message with HTML support (eg riot.im) // Post normal message with HTML support (eg riot.im)
var ( var (
resp *matrix.RespSendEvent resp *matrix.RespSendEvent