Commit a4532e27 authored by Eugen Rochko's avatar Eugen Rochko

Handle some unexpected errors and add "follow all" button

parent fcbfcb51
...@@ -385,6 +385,30 @@ h4 { ...@@ -385,6 +385,30 @@ h4 {
} }
} }
.candy-button {
font-weight: 500;
background: $vibrant;
color: #fff;
border-radius: 4px;
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
font-family: inherit;
display: inline-block;
text-align: center;
font-size: 16px;
text-decoration: none;
line-height: 36px;
padding: 4px 16px;
margin: 0 auto;
border: 0;
cursor: pointer;
&:hover,
&:active,
&:focus {
color: #fff;
}
}
.connections { .connections {
li { li {
padding: 0 10px; padding: 0 10px;
......
...@@ -26,6 +26,25 @@ class FriendsController < ApplicationController ...@@ -26,6 +26,25 @@ class FriendsController < ApplicationController
render json: Sidekiq::Status::get_all(job_id) render json: Sidekiq::Status::get_all(job_id)
end end
def follow_all
if Sidekiq::Status::complete?(job_id)
_friends = friends
_friends.each do |friend|
next if friend.relative_account_id.blank? || friend.following
relationship = current_user.mastodon_client.perform_request(:post, "/api/v1/accounts/#{friend.relative_account_id}/follow")
friend.following = relationship['following'] || relationship['requested']
rescue HTTP::Error, OpenSSL::SSL::SSLError, Oj::ParseError
next
end
Rails.cache.write("#{current_user.id}/friends", _friends.map { |f| [f.id, f.relative_account_id, f.following] })
end
redirect_to friends_path
end
private private
def job_id def job_id
......
...@@ -69,10 +69,14 @@ export default class HelloWorld extends React.PureComponent { ...@@ -69,10 +69,14 @@ export default class HelloWorld extends React.PureComponent {
Right now, there are no results to be shown here. But maybe your friends haven't used this tool yet! Or maybe you are the trendsetter! Right now, there are no results to be shown here. But maybe your friends haven't used this tool yet! Or maybe you are the trendsetter!
</p>} </p>}
{results.length > 0 && mastodonIsConnected && <div style={{ textAlign: 'center', marginTop: -10, marginBottom: 20 }}>
<a className='candy-button' href='/friends/follow_all' data-method='post'>Follow all friends on Mastodon</a>
</div>}
{results.length > 0 && <StaggeredMotion defaultStyles={results.map(_ => ({ scale: 0 }))} styles={prevInterpolatedStyles => prevInterpolatedStyles.map((_, i) => { {results.length > 0 && <StaggeredMotion defaultStyles={results.map(_ => ({ scale: 0 }))} styles={prevInterpolatedStyles => prevInterpolatedStyles.map((_, i) => {
return i == 0 return i == 0
? { scale: spring(1, presets.wobbly) } ? { scale: spring(1, presets.gentle) }
: { scale: spring(prevInterpolatedStyles[i - 1].scale, presets.wobbly) }; : { scale: spring(prevInterpolatedStyles[i - 1].scale, presets.gentle) };
})}> })}>
{interpolatingStyles => ( {interpolatingStyles => (
<div className='grid'> <div className='grid'>
......
...@@ -21,7 +21,7 @@ class Authorization < ApplicationRecord ...@@ -21,7 +21,7 @@ class Authorization < ApplicationRecord
else else
@info = {} @info = {}
end end
rescue Mastodon::Error, HTTP::Error, OpenSSL::SSL::SSLError rescue Mastodon::Error, HTTP::Error, OpenSSL::SSL::SSLError, Oj::ParseError, NoMethodError
@info = {} @info = {}
end end
end end
...@@ -13,6 +13,8 @@ Rails.application.routes.draw do ...@@ -13,6 +13,8 @@ Rails.application.routes.draw do
get :status get :status
get :results get :results
get :domains get :domains
post :follow_all
end end
member do member do
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment