2022-10-21 14:18:02 +00:00
|
|
|
// mautrix-groupme - A Matrix-GroupMe puppeting bridge.
|
|
|
|
// Copyright (C) 2022 Sumner Evans, Karmanyaah Malhotra
|
2018-08-25 21:26:24 +00:00
|
|
|
//
|
|
|
|
// This program is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU Affero General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
//
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU Affero General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU Affero General Public License
|
|
|
|
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2023-09-07 03:17:06 +00:00
|
|
|
"go.mau.fi/util/variationselector"
|
2018-08-25 21:26:24 +00:00
|
|
|
|
2023-03-20 00:31:16 +00:00
|
|
|
"maunium.net/go/mautrix/event"
|
2019-01-11 19:17:31 +00:00
|
|
|
"maunium.net/go/mautrix/format"
|
2018-08-25 21:26:24 +00:00
|
|
|
)
|
|
|
|
|
2023-03-20 00:31:16 +00:00
|
|
|
const formatterContextAllowedMentionsKey = "com.beeper.groupme.allowed_mentions"
|
2018-08-28 21:40:54 +00:00
|
|
|
|
2023-03-20 00:31:16 +00:00
|
|
|
func (br *GMBridge) pillConverter(displayname, mxid, eventID string, ctx format.Context) string {
|
|
|
|
// GroupMe only supports user mentions.
|
|
|
|
if len(mxid) == 0 || mxid[0] != '@' {
|
|
|
|
return displayname
|
|
|
|
}
|
2018-08-28 21:40:54 +00:00
|
|
|
|
2023-03-20 00:31:16 +00:00
|
|
|
return fmt.Sprintf("@%s", displayname)
|
2018-08-28 21:40:54 +00:00
|
|
|
}
|
|
|
|
|
2023-03-20 00:31:16 +00:00
|
|
|
var matrixHTMLParser = &format.HTMLParser{
|
|
|
|
TabsToSpaces: 4,
|
|
|
|
Newline: "\n",
|
|
|
|
HorizontalLine: "\n---\n",
|
2018-08-28 21:40:54 +00:00
|
|
|
}
|
|
|
|
|
2023-03-20 00:31:16 +00:00
|
|
|
func (portal *Portal) parseMatrixHTML(content *event.MessageEventContent) string {
|
|
|
|
if content.Format == event.FormatHTML && len(content.FormattedBody) > 0 {
|
|
|
|
return variationselector.FullyQualify(matrixHTMLParser.Parse(content.FormattedBody, format.NewContext()))
|
|
|
|
} else {
|
|
|
|
return variationselector.FullyQualify(content.Body)
|
|
|
|
}
|
2018-08-25 21:26:24 +00:00
|
|
|
}
|