forked from MirrorHub/mautrix-whatsapp
Merge remote-tracking branch 'origin/sumner/bri-1873'
This commit is contained in:
commit
663abeeb04
2 changed files with 15 additions and 10 deletions
|
@ -1510,7 +1510,7 @@ func (portal *Portal) convertTextMessage(intent *appservice.IntentAPI, source *U
|
|||
}
|
||||
expiresIn = contextInfo.GetExpiration()
|
||||
|
||||
extraAttrs["com.beeper.linkpreview"] = portal.convertURLPreviewToBeeper(intent, source, msg.GetExtendedTextMessage())
|
||||
extraAttrs["com.beeper.linkpreviews"] = portal.convertURLPreviewToBeeper(intent, source, msg.GetExtendedTextMessage())
|
||||
}
|
||||
|
||||
return &ConvertedMessage{
|
||||
|
@ -2253,7 +2253,7 @@ func (portal *Portal) convertMatrixMessage(sender *User, evt *event.Event) (*waP
|
|||
if content.MsgType == event.MsgEmote && !relaybotFormatted {
|
||||
text = "/me " + text
|
||||
}
|
||||
if ctxInfo.StanzaId != nil || ctxInfo.MentionedJid != nil || ctxInfo.Expiration != nil || evt.Content.Raw["com.beeper.linkpreview"] != nil {
|
||||
if ctxInfo.StanzaId != nil || ctxInfo.MentionedJid != nil || ctxInfo.Expiration != nil || evt.Content.Raw["com.beeper.linkpreviews"] != nil {
|
||||
msg.ExtendedTextMessage = &waProto.ExtendedTextMessage{
|
||||
Text: &text,
|
||||
ContextInfo: &ctxInfo,
|
||||
|
|
|
@ -52,12 +52,12 @@ type BeeperLinkPreview struct {
|
|||
ImageType string `json:"og:image:type,omitempty"`
|
||||
}
|
||||
|
||||
func (portal *Portal) convertURLPreviewToBeeper(intent *appservice.IntentAPI, source *User, msg *waProto.ExtendedTextMessage) (output *BeeperLinkPreview) {
|
||||
func (portal *Portal) convertURLPreviewToBeeper(intent *appservice.IntentAPI, source *User, msg *waProto.ExtendedTextMessage) []*BeeperLinkPreview {
|
||||
if msg.GetMatchedText() == "" {
|
||||
return
|
||||
return []*BeeperLinkPreview{}
|
||||
}
|
||||
|
||||
output = &BeeperLinkPreview{
|
||||
output := &BeeperLinkPreview{
|
||||
MatchedURL: msg.GetMatchedText(),
|
||||
CanonicalURL: msg.GetCanonicalUrl(),
|
||||
Title: msg.GetTitle(),
|
||||
|
@ -111,16 +111,21 @@ func (portal *Portal) convertURLPreviewToBeeper(intent *appservice.IntentAPI, so
|
|||
output.Type = "video.other"
|
||||
}
|
||||
|
||||
return
|
||||
return []*BeeperLinkPreview{output}
|
||||
}
|
||||
|
||||
func (portal *Portal) convertURLPreviewToWhatsApp(sender *User, evt *event.Event, dest *waProto.ExtendedTextMessage) {
|
||||
rawPreview := gjson.GetBytes(evt.Content.VeryRaw, `com\.beeper\.linkpreview`)
|
||||
if !rawPreview.Exists() || !rawPreview.IsObject() {
|
||||
rawPreview := gjson.GetBytes(evt.Content.VeryRaw, `com\.beeper\.linkpreviews`)
|
||||
if !rawPreview.Exists() || !rawPreview.IsArray() {
|
||||
return
|
||||
}
|
||||
var preview BeeperLinkPreview
|
||||
if err := json.Unmarshal([]byte(rawPreview.Raw), &preview); err != nil || len(preview.MatchedURL) == 0 {
|
||||
var previews []BeeperLinkPreview
|
||||
if err := json.Unmarshal([]byte(rawPreview.Raw), &previews); err != nil || len(previews) == 0 {
|
||||
return
|
||||
}
|
||||
// WhatsApp only supports a single preview.
|
||||
preview := previews[0]
|
||||
if len(preview.MatchedURL) == 0 {
|
||||
return
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue