Browse Source

Merge branch 'master' into glitch-soc/merge-upstream

Conflicts:
- `app/javascript/mastodon/features/compose/components/poll_form.js`
  conflict because of the poll option limit being different than upstream's
master^2^2
Thibaut Girka 1 week ago
parent
commit
83774367d2

+ 5
- 3
app/javascript/mastodon/actions/compose.js View File

@@ -205,10 +205,11 @@ export function uploadCompose(files) {
return function (dispatch, getState) {
const uploadLimit = 4;
const media = getState().getIn(['compose', 'media_attachments']);
const pending = getState().getIn(['compose', 'pending_media_attachments']);
const progress = new Array(files.length).fill(0);
let total = Array.from(files).reduce((a, v) => a + v.size, 0);

if (files.length + media.size > uploadLimit) {
if (files.length + media.size + pending > uploadLimit) {
dispatch(showAlert(undefined, messages.uploadErrorLimit));
return;
}
@@ -235,7 +236,7 @@ export function uploadCompose(files) {
dispatch(uploadComposeProgress(progress.reduce((a, v) => a + v, 0), total));
},
}).then(({ data }) => dispatch(uploadComposeSuccess(data, f)));
}).catch(error => dispatch(uploadComposeFail(error)));
}).catch(error => dispatch(uploadComposeFail(error, true)));
};
};
};
@@ -266,10 +267,11 @@ export function changeUploadComposeSuccess(media) {
};
};

export function changeUploadComposeFail(error) {
export function changeUploadComposeFail(error, decrement = false) {
return {
type: COMPOSE_UPLOAD_CHANGE_FAIL,
error: error,
decrement: decrement,
skipLoading: true,
};
};

+ 1
- 3
app/javascript/mastodon/features/compose/components/poll_form.js View File

@@ -142,9 +142,7 @@ class PollForm extends ImmutablePureComponent {
</ul>

<div className='poll__footer'>
{options.size < 5 && (
<button className='button button-secondary' onClick={this.handleAddOption}><Icon id='plus' /> <FormattedMessage {...messages.add_option} /></button>
)}
<button disabled={options.size >= 5} className='button button-secondary' onClick={this.handleAddOption}><Icon id='plus' /> <FormattedMessage {...messages.add_option} /></button>

<select value={expiresIn} onChange={this.handleSelectDuration}>
<option value={300}>{intl.formatMessage(messages.minutes, { number: 5 })}</option>

+ 1
- 1
app/javascript/mastodon/features/compose/containers/upload_button_container.js View File

@@ -3,7 +3,7 @@ import UploadButton from '../components/upload_button';
import { uploadCompose } from '../../../actions/compose';

const mapStateToProps = state => ({
disabled: state.getIn(['compose', 'is_uploading']) || (state.getIn(['compose', 'media_attachments']).size > 3 || state.getIn(['compose', 'media_attachments']).some(m => ['video', 'audio'].includes(m.get('type')))),
disabled: state.getIn(['compose', 'is_uploading']) || (state.getIn(['compose', 'media_attachments']).size + state.getIn(['compose', 'pending_media_attachments']) > 3 || state.getIn(['compose', 'media_attachments']).some(m => ['video', 'audio'].includes(m.get('type')))),
unavailable: state.getIn(['compose', 'poll']) !== null,
resetFileKey: state.getIn(['compose', 'resetFileKey']),
});

+ 4
- 2
app/javascript/mastodon/reducers/compose.js View File

@@ -61,6 +61,7 @@ const initialState = ImmutableMap({
is_uploading: false,
progress: 0,
media_attachments: ImmutableList(),
pending_media_attachments: 0,
poll: null,
suggestion_token: null,
suggestions: ImmutableList(),
@@ -114,6 +115,7 @@ function appendMedia(state, media, file) {
map.set('is_uploading', false);
map.set('resetFileKey', Math.floor((Math.random() * 0x10000)));
map.set('idempotencyKey', uuid());
map.update('pending_media_attachments', n => n - 1);

if (prevSize === 0 && (state.get('default_sensitive') || state.get('spoiler'))) {
map.set('sensitive', true);
@@ -322,11 +324,11 @@ export default function compose(state = initialState, action) {
case COMPOSE_UPLOAD_CHANGE_FAIL:
return state.set('is_changing_upload', false);
case COMPOSE_UPLOAD_REQUEST:
return state.set('is_uploading', true);
return state.set('is_uploading', true).update('pending_media_attachments', n => n + 1);
case COMPOSE_UPLOAD_SUCCESS:
return appendMedia(state, fromJS(action.media), action.file);
case COMPOSE_UPLOAD_FAIL:
return state.set('is_uploading', false);
return state.set('is_uploading', false).update('pending_media_attachments', n => action.decrement ? n - 1 : n);
case COMPOSE_UPLOAD_UNDO:
return removeMedia(state, action.media_id);
case COMPOSE_UPLOAD_PROGRESS:

+ 1
- 0
app/javascript/styles/mastodon/components.scss View File

@@ -392,6 +392,7 @@
.autosuggest-input,
.spoiler-input {
position: relative;
width: 100%;
}

.spoiler-input {

+ 1
- 1
app/presenters/account_relationships_presenter.rb View File

@@ -6,7 +6,7 @@ class AccountRelationshipsPresenter
:endorsed

def initialize(account_ids, current_account_id, **options)
@account_ids = account_ids.map { |a| a.is_a?(Account) ? a.id : a }
@account_ids = account_ids.map { |a| a.is_a?(Account) ? a.id : a.to_i }
@current_account_id = current_account_id

@following = cached[:following].merge(Account.following_map(@uncached_account_ids, @current_account_id))

+ 2
- 2
app/services/follow_service.rb View File

@@ -8,7 +8,7 @@ class FollowService < BaseService
# @param [Account] source_account From which to follow
# @param [String, Account] uri User URI to follow in the form of username@domain (or account record)
# @param [true, false, nil] reblogs Whether or not to show reblogs, defaults to true
def call(source_account, target_account, reblogs: nil)
def call(source_account, target_account, reblogs: nil, bypass_locked: false)
reblogs = true if reblogs.nil?
target_account = ResolveAccountService.new.call(target_account, skip_webfinger: true)

@@ -30,7 +30,7 @@ class FollowService < BaseService

ActivityTracker.increment('activity:interactions')

if target_account.locked? || source_account.silenced? || target_account.activitypub?
if (target_account.locked? && !bypass_locked) || source_account.silenced? || target_account.activitypub?
request_follow(source_account, target_account, reblogs: reblogs)
elsif target_account.local?
direct_follow(source_account, target_account, reblogs: reblogs)

+ 6
- 2
app/workers/move_worker.rb View File

@@ -7,7 +7,7 @@ class MoveWorker
@source_account = Account.find(source_account_id)
@target_account = Account.find(target_account_id)

if @target_account.local?
if @target_account.local? && @source_account.local?
rewrite_follows!
else
queue_follow_unfollows!
@@ -21,13 +21,17 @@ class MoveWorker
def rewrite_follows!
@source_account.passive_relationships
.where(account: Account.local)
.where.not(account: @target_account.followers.local)
.where.not(account_id: @target_account.id)
.in_batches
.update_all(target_account_id: @target_account.id)
end

def queue_follow_unfollows!
bypass_locked = @target_account.local?

@source_account.followers.local.select(:id).find_in_batches do |accounts|
UnfollowFollowWorker.push_bulk(accounts.map(&:id)) { |follower_id| [follower_id, @source_account.id, @target_account.id] }
UnfollowFollowWorker.push_bulk(accounts.map(&:id)) { |follower_id| [follower_id, @source_account.id, @target_account.id, bypass_locked] }
end
end
end

+ 5
- 2
app/workers/unfollow_follow_worker.rb View File

@@ -5,12 +5,15 @@ class UnfollowFollowWorker

sidekiq_options queue: 'pull'

def perform(follower_account_id, old_target_account_id, new_target_account_id)
def perform(follower_account_id, old_target_account_id, new_target_account_id, bypass_locked = false)
follower_account = Account.find(follower_account_id)
old_target_account = Account.find(old_target_account_id)
new_target_account = Account.find(new_target_account_id)

FollowService.new.call(follower_account, new_target_account)
follow = follower_account.active_relationships.find_by(target_account: old_target_account)
reblogs = follow&.show_reblogs?

FollowService.new.call(follower_account, new_target_account, reblogs: reblogs, bypass_locked: bypass_locked)
UnfollowService.new.call(follower_account, old_target_account, skip_unmerge: true)
rescue ActiveRecord::RecordNotFound, Mastodon::NotPermittedError
true

+ 8
- 8
package.json View File

@@ -69,9 +69,9 @@
"@babel/plugin-transform-react-jsx-self": "^7.2.0",
"@babel/plugin-transform-react-jsx-source": "^7.5.0",
"@babel/plugin-transform-runtime": "^7.5.5",
"@babel/preset-env": "^7.6.0",
"@babel/preset-react": "^7.0.0",
"@babel/runtime": "^7.5.4",
"@babel/preset-env": "^7.7.1",
"@babel/preset-react": "^7.6.3",
"@babel/runtime": "^7.7.1",
"@clusterws/cws": "^0.15.2",
"array-includes": "^3.0.3",
"atrament": "^0.2.3",
@@ -101,7 +101,7 @@
"file-loader": "^4.2.0",
"favico.js": "^0.3.10",
"font-awesome": "^4.7.0",
"glob": "^7.1.1",
"glob": "^7.1.5",
"history": "^4.10.1",
"http-link-header": "^1.0.2",
"immutable": "^3.8.2",
@@ -156,17 +156,17 @@
"requestidlecallback": "^0.3.0",
"reselect": "^4.0.0",
"rimraf": "^3.0.0",
"sass": "^1.23.1",
"sass-loader": "^7.0.3",
"sass": "^1.23.3",
"sass-loader": "^8.0.0",
"stringz": "^2.0.0",
"substring-trie": "^1.0.2",
"terser-webpack-plugin": "^2.2.1",
"tesseract.js": "^2.0.0-alpha.16",
"tesseract.js": "^2.0.0-beta.2",
"throng": "^4.0.0",
"tiny-queue": "^0.2.1",
"uuid": "^3.1.0",
"wavesurfer.js": "^3.2.0",
"webpack": "^4.35.3",
"webpack": "^4.41.2",
"webpack-assets-manifest": "^3.1.1",
"webpack-bundle-analyzer": "^3.6.0",
"webpack-cli": "^3.3.10",

+ 63
- 0
spec/workers/move_worker_spec.rb View File

@@ -0,0 +1,63 @@
# frozen_string_literal: true

require 'rails_helper'

describe MoveWorker do
let(:local_follower) { Fabricate(:user, email: 'bob@example.com', account: Fabricate(:account, username: 'bob')).account }
let(:source_account) { Fabricate(:account, protocol: :activitypub, domain: 'example.com') }
let(:target_account) { Fabricate(:account, protocol: :activitypub, domain: 'example.com') }

subject { described_class.new }

before do
local_follower.follow!(source_account)
end

context 'both accounts are distant' do
describe 'perform' do
it 'calls UnfollowFollowWorker' do
allow(UnfollowFollowWorker).to receive(:push_bulk)
subject.perform(source_account.id, target_account.id)
expect(UnfollowFollowWorker).to have_received(:push_bulk).with([local_follower.id])
end
end
end

context 'target account is local' do
let(:target_account) { Fabricate(:user, email: 'alice@example.com', account: Fabricate(:account, username: 'alice')).account }

describe 'perform' do
it 'calls UnfollowFollowWorker' do
allow(UnfollowFollowWorker).to receive(:push_bulk)
subject.perform(source_account.id, target_account.id)
expect(UnfollowFollowWorker).to have_received(:push_bulk).with([local_follower.id])
end
end
end

context 'both target and source accounts are local' do
let(:target_account) { Fabricate(:user, email: 'alice@example.com', account: Fabricate(:account, username: 'alice')).account }
let(:source_account) { Fabricate(:user, email: 'alice_@example.com', account: Fabricate(:account, username: 'alice_')).account }

describe 'perform' do
it 'calls makes local followers follow the target account' do
subject.perform(source_account.id, target_account.id)
expect(local_follower.following?(target_account)).to be true
end

it 'does not fail when a local user is already following both accounts' do
double_follower = Fabricate(:user, email: 'eve@example.com', account: Fabricate(:account, username: 'eve')).account
double_follower.follow!(source_account)
double_follower.follow!(target_account)
subject.perform(source_account.id, target_account.id)
expect(local_follower.following?(target_account)).to be true
end

it 'does not allow the moved account to follow themselves' do
source_account.follow!(target_account)
subject.perform(source_account.id, target_account.id)
expect(target_account.following?(target_account)).to be false
end
end
end
end

+ 50
- 0
spec/workers/unfollow_follow_worker_spec.rb View File

@@ -0,0 +1,50 @@
# frozen_string_literal: true

require 'rails_helper'

describe UnfollowFollowWorker do
let(:local_follower) { Fabricate(:user, email: 'bob@example.com', account: Fabricate(:account, username: 'bob')).account }
let(:source_account) { Fabricate(:account) }
let(:target_account) { Fabricate(:account) }
let(:show_reblogs) { true }

subject { described_class.new }

before do
local_follower.follow!(source_account, reblogs: show_reblogs)
end

context 'when show_reblogs is true' do
let(:show_reblogs) { true }

describe 'perform' do
it 'unfollows source account and follows target account' do
subject.perform(local_follower.id, source_account.id, target_account.id)
expect(local_follower.following?(source_account)).to be false
expect(local_follower.following?(target_account)).to be true
end

it 'preserves show_reblogs' do
subject.perform(local_follower.id, source_account.id, target_account.id)
expect(Follow.find_by(account: local_follower, target_account: target_account).show_reblogs?).to be show_reblogs
end
end
end

context 'when show_reblogs is false' do
let(:show_reblogs) { false }

describe 'perform' do
it 'unfollows source account and follows target account' do
subject.perform(local_follower.id, source_account.id, target_account.id)
expect(local_follower.following?(source_account)).to be false
expect(local_follower.following?(target_account)).to be true
end

it 'preserves show_reblogs' do
subject.perform(local_follower.id, source_account.id, target_account.id)
expect(Follow.find_by(account: local_follower, target_account: target_account).show_reblogs?).to be show_reblogs
end
end
end
end

+ 338
- 258
yarn.lock
File diff suppressed because it is too large
View File


Loading…
Cancel
Save