fix formatting

This commit is contained in:
Adam Van Ymeren 2022-02-04 06:56:32 +00:00
parent 3ab04e65c8
commit 779e591e60

View file

@ -1510,9 +1510,9 @@ func (portal *Portal) convertTextMessage(intent *appservice.IntentAPI, msg *waPr
} }
expiresIn = contextInfo.GetExpiration() expiresIn = contextInfo.GetExpiration()
preview := portal.convertUrlPreview(msg.GetExtendedTextMessage()); preview := portal.convertUrlPreview(msg.GetExtendedTextMessage())
if ( preview != nil ) { if preview != nil {
extraAttrs["com.beeper.linkpreview"] = preview extraAttrs["com.beeper.linkpreview"] = preview
} }
} }
@ -2070,26 +2070,26 @@ func (portal *Portal) convertWebPtoPNG(webpImage []byte) ([]byte, error) {
} }
func (portal *Portal) convertUrlPreview(source *waProto.ExtendedTextMessage) map[string]interface{} { func (portal *Portal) convertUrlPreview(source *waProto.ExtendedTextMessage) map[string]interface{} {
if ( source == nil ) { if source == nil {
return nil return nil
} }
matchedText := source.GetMatchedText() matchedText := source.GetMatchedText()
if ( matchedText == "" ) { if matchedText == "" {
return nil return nil
} }
canonicalUrl := source.GetCanonicalUrl() canonicalUrl := source.GetCanonicalUrl()
url := matchedText url := matchedText
if ( canonicalUrl != "" ) { if canonicalUrl != "" {
url = canonicalUrl url = canonicalUrl
} }
result := map[string]interface{}{ result := map[string]interface{}{
"og:title": source.GetTitle(), "og:title": source.GetTitle(),
"og:url": url, "og:url": url,
"og:description": source.GetDescription(), "og:description": source.GetDescription(),
} }
@ -2099,9 +2099,9 @@ func (portal *Portal) convertUrlPreview(source *waProto.ExtendedTextMessage) map
if uploadedThumbnail != nil { if uploadedThumbnail != nil {
cfg, _, _ := image.DecodeConfig(bytes.NewReader(source.GetJpegThumbnail())) cfg, _, _ := image.DecodeConfig(bytes.NewReader(source.GetJpegThumbnail()))
result["og:image"] = uploadedThumbnail.ContentURI.CUString() result["og:image"] = uploadedThumbnail.ContentURI.CUString()
result["og:image:width"] = cfg.Width; result["og:image:width"] = cfg.Width
result["og:image:height"] = cfg.Height; result["og:image:height"] = cfg.Height
result["og:image:type"] = thumbnailMime; result["og:image:type"] = thumbnailMime
} }
} }
@ -2109,13 +2109,13 @@ func (portal *Portal) convertUrlPreview(source *waProto.ExtendedTextMessage) map
} }
func (portal *Portal) updateExtendedMessageForUrlPreview(source *event.Content, dest *waProto.ExtendedTextMessage) { func (portal *Portal) updateExtendedMessageForUrlPreview(source *event.Content, dest *waProto.ExtendedTextMessage) {
if ( source == nil ) { if source == nil {
return return
} }
embeddedLink, ok := source.Raw["com.beeper.linkpreview"].(map[string]interface{}); embeddedLink, ok := source.Raw["com.beeper.linkpreview"].(map[string]interface{})
if ( !ok || embeddedLink == nil ) { if !ok || embeddedLink == nil {
return return
} }
@ -2128,9 +2128,9 @@ func (portal *Portal) updateExtendedMessageForUrlPreview(source *event.Content,
dest.MatchedText = &matchedUrl dest.MatchedText = &matchedUrl
canonical, ok := embeddedLink["og:url"].(string) canonical, ok := embeddedLink["og:url"].(string)
if ok { if ok {
dest.CanonicalUrl = &canonical; dest.CanonicalUrl = &canonical
} }
description, ok := embeddedLink["og:description"].(string) description, ok := embeddedLink["og:description"].(string)
@ -2158,7 +2158,7 @@ func (portal *Portal) updateExtendedMessageForUrlPreview(source *event.Content,
} }
height, ok := embeddedLink["og:image:height"].(float64) height, ok := embeddedLink["og:image:height"].(float64)
if !ok { if !ok {
portal.log.Errorfln("Height missing or invalid %v", embeddedLink["og:image:height"]) portal.log.Errorfln("Height missing or invalid %v", embeddedLink["og:image:height"])
return return
@ -2367,7 +2367,7 @@ func (portal *Portal) convertMatrixMessage(sender *User, evt *event.Event) (*waP
Text: &text, Text: &text,
ContextInfo: &ctxInfo, ContextInfo: &ctxInfo,
} }
portal.updateExtendedMessageForUrlPreview(&evt.Content, msg.ExtendedTextMessage) portal.updateExtendedMessageForUrlPreview(&evt.Content, msg.ExtendedTextMessage)
} else { } else {
msg.Conversation = &text msg.Conversation = &text