Skip to content

Instantly share code, notes, and snippets.

@nicksergeant
Created November 5, 2022 13:58
Show Gist options
  • Save nicksergeant/92ab6931ea0a322d3f47eb54e945d9b2 to your computer and use it in GitHub Desktop.
Save nicksergeant/92ab6931ea0a322d3f47eb54e945d9b2 to your computer and use it in GitHub Desktop.
Show Mastodon accounts you're hiding reblogs for, and optionally re-show reblogs for all accounts.
domain = "mastodon.social"
your_account_id = "12345"
bearer_token = "Find this in Chrome Developer Tools -> Network -> an API request -> Headers -> Request Headers -> Authorization"
headers = [
Accept: "application/json",
"content-type": "application/json",
Authorization: "Bearer #{bearer_token}"
]
IO.puts("Fetching accounts you're following...")
following_accounts =
HTTPoison.get!(
"https://#{domain}/api/v1/accounts/#{your_account_id}/following?limit=10000",
headers
).body
|> Jason.decode!()
IO.puts("Fetching your relationships for those accounts...")
following_ids = following_accounts |> Enum.map(& &1["id"])
following_relationships =
HTTPoison.get!(
"https://#{domain}/api/v1/accounts/relationships?#{following_ids |> Enum.join("&id[]=")}",
headers
).body
|> Jason.decode!()
hiding_reblogs_accounts =
following_relationships
|> Enum.filter(&(&1["showing_reblogs"] == false))
|> Enum.map(fn r -> Enum.find(following_accounts, &(&1["id"] == r["id"])) end)
hiding_reblogs_names =
hiding_reblogs_accounts
|> Enum.map(& &1["display_name"])
IO.puts("""
You're hiding reblogs from #{Enum.count(hiding_reblogs_names)} accounts:
- #{hiding_reblogs_names |> Enum.join("\n- ")}
""")
input =
IO.gets("Press return to re-enable reblogs from all accounts, or input anything else to exit: ")
if input == "\n" do
Enum.each(hiding_reblogs_accounts, fn account ->
IO.puts("Re-enabling reblogs for #{account["display_name"]}...")
HTTPoison.post!(
"https://#{domain}/api/v1/accounts/#{account["id"]}/follow",
Jason.encode!(%{reblogs: true}),
headers
)
end)
end
@nicksergeant
Copy link
Author

iex(1)> c "mastodon_reblogs.exs"
Fetching accounts you're following...
Fetching your relationships for those accounts...
You're hiding reblogs from 2 accounts:

- Foo
- Bar

Press return to re-enable reblogs from all accounts, or input anything else to exit:
Re-enabling reblogs for Foo...
Re-enabling reblogs for Bar...
[]
iex(2)> 

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment