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 {
}
}
.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 {
li {
padding: 0 10px;
......
......@@ -26,6 +26,25 @@ class FriendsController < ApplicationController
render json: Sidekiq::Status::get_all(job_id)
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
def job_id
......
......@@ -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!
</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) => {
return i == 0
? { scale: spring(1, presets.wobbly) }
: { scale: spring(prevInterpolatedStyles[i - 1].scale, presets.wobbly) };
? { scale: spring(1, presets.gentle) }
: { scale: spring(prevInterpolatedStyles[i - 1].scale, presets.gentle) };
})}>
{interpolatingStyles => (
<div className='grid'>
......
......@@ -21,7 +21,7 @@ class Authorization < ApplicationRecord
else
@info = {}
end
rescue Mastodon::Error, HTTP::Error, OpenSSL::SSL::SSLError
rescue Mastodon::Error, HTTP::Error, OpenSSL::SSL::SSLError, Oj::ParseError, NoMethodError
@info = {}
end
end
......@@ -13,6 +13,8 @@ Rails.application.routes.draw do
get :status
get :results
get :domains
post :follow_all
end
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