wmio import: in case of silo domains, use url instead of src

master
Wouter Groeneveld 5 months ago
parent 989495a18e
commit 6503037098
  1. 14
      app/external/webmentionio.go
  2. 34
      app/external/webmentionio_test.go
  3. 1
      rest/utils.go

@ -3,6 +3,7 @@ package external
import (
"brainbaking.com/go-jamming/app/mf"
"brainbaking.com/go-jamming/common"
"brainbaking.com/go-jamming/rest"
"encoding/json"
)
@ -99,12 +100,23 @@ func convert(wmio WebmentionIOMention) *mf.IndiewebData {
Content: contentOf(wmio, iType),
Published: publishedDate(wmio),
Url: wmio.Data.Url,
Source: wmio.Source,
Source: sourceOf(wmio),
Target: wmio.Target,
IndiewebType: iType,
}
}
// sourceOf returns wmio.Source unless it detects a silo link such as bridgy.
// In that case, it returns the data URL. This isn't entirely correct, as it technically never was the sender.
func sourceOf(wmio WebmentionIOMention) string {
srcDomain := rest.Domain(wmio.Source)
if common.Includes(rest.SiloDomains, srcDomain) {
return wmio.Data.Url
}
return wmio.Source
}
func nameOf(wmio WebmentionIOMention, iType mf.MfType) string {
if (iType == mf.TypeReply || iType == mf.TypeLike) && wmio.Data.Name == "" {
return wmio.Data.Content

@ -7,6 +7,40 @@ import (
"time"
)
func TestTryImportBridgyUrl(t *testing.T) {
wmio := &WebmentionIOImporter{}
cases := []struct {
label string
mention string
expectedSource string
}{
{
"conventional source URL does nothing special",
`{ "links": [ { "source": "https://brainbaking.com/lolz" } ] }`,
"https://brainbaking.com/lolz",
},
{
"Source URL from brid.gy takes data URL as source instead",
`{ "links": [ { "source": "https://brid.gy/like/twitter/iamchrisburnell/1298550501307486208/252048752", "data": { "url": "https://twitter.com/iamchrisburnell/status/1298550501307486208#favorited-by-252048752" } } ] }`,
"https://twitter.com/iamchrisburnell/status/1298550501307486208#favorited-by-252048752",
},
{
"Source URL from brid-gy.appspot.com takes URL as data source instead",
`{ "links": [ { "source": "https://brid-gy.appspot.com/post/twitter/iamchrisburnell/1103728693648809984", "data": { "url": "https://twitter.com/adactioLinks/status/1103728693648809984" } } ] }`,
"https://twitter.com/adactioLinks/status/1103728693648809984",
},
}
for _, tc := range cases {
t.Run(tc.label, func(t *testing.T) {
res, err := wmio.TryImport([]byte(tc.mention))
assert.NoError(t, err)
assert.Equal(t, tc.expectedSource, res[0].Source)
})
}
}
func TestTryImportPublishedDates(t *testing.T) {
wmio := &WebmentionIOImporter{}
cases := []struct {

@ -61,6 +61,7 @@ var (
// These are privacy issues and will be anonymized as such.
SiloDomains = []string{
"brid.gy",
"brid-gy.appspot.com",
"twitter.com",
"facebook.com",
"indieweb.social",

Loading…
Cancel
Save