Selaa lähdekoodia

link previews: only include in Matrix event when there's an actual link

Sumner Evans 3 vuotta sitten
vanhempi
sitoutus
b6352c4991
2 muutettua tiedostoa jossa 5 lisäystä ja 7 poistoa
  1. 1 3
      portal.go
  2. 4 4
      urlpreview.go

+ 1 - 3
portal.go

@@ -1510,9 +1510,7 @@ func (portal *Portal) convertTextMessage(intent *appservice.IntentAPI, source *U
 		}
 		}
 		expiresIn = contextInfo.GetExpiration()
 		expiresIn = contextInfo.GetExpiration()
 
 
-		extraAttrs["com.beeper.linkpreviews"] = []*BeeperLinkPreview{
-			portal.convertURLPreviewToBeeper(intent, source, msg.GetExtendedTextMessage()),
-		}
+		extraAttrs["com.beeper.linkpreviews"] = portal.convertURLPreviewToBeeper(intent, source, msg.GetExtendedTextMessage())
 	}
 	}
 
 
 	return &ConvertedMessage{
 	return &ConvertedMessage{

+ 4 - 4
urlpreview.go

@@ -52,12 +52,12 @@ type BeeperLinkPreview struct {
 	ImageType   string `json:"og:image:type,omitempty"`
 	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() == "" {
 	if msg.GetMatchedText() == "" {
-		return
+		return []*BeeperLinkPreview{}
 	}
 	}
 
 
-	output = &BeeperLinkPreview{
+	output := &BeeperLinkPreview{
 		MatchedURL:   msg.GetMatchedText(),
 		MatchedURL:   msg.GetMatchedText(),
 		CanonicalURL: msg.GetCanonicalUrl(),
 		CanonicalURL: msg.GetCanonicalUrl(),
 		Title:        msg.GetTitle(),
 		Title:        msg.GetTitle(),
@@ -111,7 +111,7 @@ func (portal *Portal) convertURLPreviewToBeeper(intent *appservice.IntentAPI, so
 		output.Type = "video.other"
 		output.Type = "video.other"
 	}
 	}
 
 
-	return
+	return []*BeeperLinkPreview{output}
 }
 }
 
 
 func (portal *Portal) convertURLPreviewToWhatsApp(sender *User, evt *event.Event, dest *waProto.ExtendedTextMessage) {
 func (portal *Portal) convertURLPreviewToWhatsApp(sender *User, evt *event.Event, dest *waProto.ExtendedTextMessage) {