[bugfix] Be more lenient when parsing mastodown following.csv (#3311)

* [bugfix] Be more lenient when parsing mastodown following.csv

* use follow.Notify
This commit is contained in:
tobi 2024-09-16 20:39:15 +02:00 committed by GitHub
parent 84279f6a6a
commit d4d6631435
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 58 additions and 10 deletions

View File

@ -160,9 +160,9 @@ type testCase struct {
token: suite.testTokens["local_account_1"], token: suite.testTokens["local_account_1"],
user: suite.testUsers["local_account_1"], user: suite.testUsers["local_account_1"],
account: suite.testAccounts["local_account_1"], account: suite.testAccounts["local_account_1"],
expect: `Account address,Show boosts expect: `Account address,Show boosts,Notify on new posts,Languages
admin@localhost:8080,true admin@localhost:8080,true,false,
1happyturtle@localhost:8080,true 1happyturtle@localhost:8080,true,false,
`, `,
}, },
// Export Followers. // Export Followers.

View File

@ -188,6 +188,10 @@ func importFollowingAsyncF(
// Show reblogs on // Show reblogs on
// the new follow. // the new follow.
showReblogs = follow.ShowReblogs showReblogs = follow.ShowReblogs
// Notify when new
// follow posts.
notify = follow.Notify
) )
if overwrite { if overwrite {
@ -218,6 +222,7 @@ func importFollowingAsyncF(
&apimodel.AccountFollowRequest{ &apimodel.AccountFollowRequest{
ID: targetAcct.ID, ID: targetAcct.ID,
Reblogs: showReblogs, Reblogs: showReblogs,
Notify: notify,
}, },
); errWithCode != nil { ); errWithCode != nil {
log.Errorf(ctx, "could not follow account: %v", errWithCode.Unwrap()) log.Errorf(ctx, "could not follow account: %v", errWithCode.Unwrap())

View File

@ -90,6 +90,8 @@ func (c *Converter) FollowingToCSV(
records[0] = []string{ records[0] = []string{
"Account address", "Account address",
"Show boosts", "Show boosts",
"Notify on new posts",
"Languages",
} }
// We need to know our own domain for this. // We need to know our own domain for this.
@ -130,6 +132,10 @@ func (c *Converter) FollowingToCSV(
follow.TargetAccount.Username + "@" + domain, follow.TargetAccount.Username + "@" + domain,
// Show boosts: eg., true // Show boosts: eg., true
strconv.FormatBool(*follow.ShowReblogs), strconv.FormatBool(*follow.ShowReblogs),
// Notify on new posts, eg., true
strconv.FormatBool(*follow.Notify),
// Languages: compat only, leave blank.
"",
}) })
} }
@ -387,12 +393,20 @@ func (c *Converter) CSVToFollowing(
) )
for _, record := range records { for _, record := range records {
if len(record) != 2 { recordLen := len(record)
// Older versions of this Masto CSV
// schema may not include "Show boosts",
// "Notify on new posts", or "Languages",
// so be lenient here in what we accept.
if recordLen == 0 ||
recordLen > 4 {
// Badly formatted, // Badly formatted,
// skip this one. // skip this one.
continue continue
} }
// "Account address"
namestring := record[0] namestring := record[0]
if namestring == "" { if namestring == "" {
// Badly formatted, // Badly formatted,
@ -400,6 +414,12 @@ func (c *Converter) CSVToFollowing(
continue continue
} }
if namestring == "Account address" {
// CSV header row,
// skip this one.
continue
}
// Prepend with "@" // Prepend with "@"
// if not included. // if not included.
if namestring[0] != '@' { if namestring[0] != '@' {
@ -419,12 +439,34 @@ func (c *Converter) CSVToFollowing(
domain = "" domain = ""
} }
showReblogs, err := strconv.ParseBool(record[1]) // "Show boosts"
var showReblogs *bool
if recordLen > 1 {
b, err := strconv.ParseBool(record[1])
if err != nil { if err != nil {
// Badly formatted, // Badly formatted,
// skip this one. // skip this one.
continue continue
} }
showReblogs = &b
}
// "Notify on new posts"
var notify *bool
if recordLen > 2 {
b, err := strconv.ParseBool(record[2])
if err != nil {
// Badly formatted,
// skip this one.
continue
}
notify = &b
}
// TODO: "Languages"
//
// Ignore this for now as we
// don't do anything with it.
// Looks good, whack it in the slice. // Looks good, whack it in the slice.
follows = append(follows, &gtsmodel.Follow{ follows = append(follows, &gtsmodel.Follow{
@ -432,7 +474,8 @@ func (c *Converter) CSVToFollowing(
Username: username, Username: username,
Domain: domain, Domain: domain,
}, },
ShowReblogs: &showReblogs, ShowReblogs: showReblogs,
Notify: notify,
}) })
} }