diff --git a/app/external/webmentionio.go b/app/external/webmentionio.go index 7b421f2..2b4f3f3 100644 --- a/app/external/webmentionio.go +++ b/app/external/webmentionio.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 diff --git a/app/external/webmentionio_test.go b/app/external/webmentionio_test.go index 508b73f..8a32db8 100644 --- a/app/external/webmentionio_test.go +++ b/app/external/webmentionio_test.go @@ -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 { diff --git a/rest/utils.go b/rest/utils.go index 0d301fc..7dc80ad 100644 --- a/rest/utils.go +++ b/rest/utils.go @@ -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",