feat: limit unfurls number (#4288)
This commit is contained in:
parent
2c954d42cf
commit
c3687acc84
|
@ -17,6 +17,8 @@ import (
|
||||||
"github.com/status-im/status-go/protocol/common"
|
"github.com/status-im/status-go/protocol/common"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const UnfurledLinksPerMessageLimit = 5
|
||||||
|
|
||||||
type UnfurlURLsResponse struct {
|
type UnfurlURLsResponse struct {
|
||||||
LinkPreviews []*common.LinkPreview `json:"linkPreviews,omitempty"`
|
LinkPreviews []*common.LinkPreview `json:"linkPreviews,omitempty"`
|
||||||
StatusLinkPreviews []*common.StatusLinkPreview `json:"statusLinkPreviews,omitempty"`
|
StatusLinkPreviews []*common.StatusLinkPreview `json:"statusLinkPreviews,omitempty"`
|
||||||
|
@ -123,6 +125,12 @@ func GetURLs(text string) []string {
|
||||||
indexed[idx] = nil
|
indexed[idx] = nil
|
||||||
urls = append(urls, idx)
|
urls = append(urls, idx)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// This is a temporary limitation solution,
|
||||||
|
// should be changed with https://github.com/status-im/status-go/issues/4235
|
||||||
|
if len(urls) == UnfurledLinksPerMessageLimit {
|
||||||
|
break
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return urls
|
return urls
|
||||||
|
|
|
@ -659,5 +659,17 @@ func (s *MessengerLinkPreviewsTestSuite) Test_UnfurlURLs_Settings() {
|
||||||
s.Require().Len(linkPreviews.LinkPreviews, 0)
|
s.Require().Len(linkPreviews.LinkPreviews, 0)
|
||||||
s.Require().Len(linkPreviews.StatusLinkPreviews, 1) // Status links are always unfurled
|
s.Require().Len(linkPreviews.StatusLinkPreviews, 1) // Status links are always unfurled
|
||||||
s.Require().Equal(requestsCount, 0)
|
s.Require().Equal(requestsCount, 0)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *MessengerLinkPreviewsTestSuite) Test_UnfurlURLs_Limit() {
|
||||||
|
linksToUnfurl := "https://www.youtube.com/watch?v=6dkDepLX0rk " +
|
||||||
|
"https://www.youtube.com/watch?v=ferZnZ0_rSM " +
|
||||||
|
"https://www.youtube.com/watch?v=bdneye4pzMw " +
|
||||||
|
"https://www.youtube.com/watch?v=pRERgcQe-fQ " +
|
||||||
|
"https://www.youtube.com/watch?v=j82L3pLjb_0 " +
|
||||||
|
"https://www.youtube.com/watch?v=hxsJvKYyVyg " +
|
||||||
|
"https://www.youtube.com/watch?v=jIIuzB11dsA"
|
||||||
|
|
||||||
|
urls := GetURLs(linksToUnfurl)
|
||||||
|
s.Require().Equal(UnfurledLinksPerMessageLimit, len(urls))
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue