Merge branch 'master' into glitch-soc/merge-upstream
commit
1df392819d
6
Gemfile
6
Gemfile
|
@ -6,7 +6,7 @@ ruby '>= 2.3.0', '< 2.6.0'
|
||||||
gem 'pkg-config', '~> 1.3'
|
gem 'pkg-config', '~> 1.3'
|
||||||
|
|
||||||
gem 'puma', '~> 3.12'
|
gem 'puma', '~> 3.12'
|
||||||
gem 'rails', '~> 5.2.1'
|
gem 'rails', '~> 5.2.2'
|
||||||
gem 'thor', '~> 0.20'
|
gem 'thor', '~> 0.20'
|
||||||
|
|
||||||
gem 'hamlit-rails', '~> 0.2'
|
gem 'hamlit-rails', '~> 0.2'
|
||||||
|
@ -108,7 +108,7 @@ group :production, :test do
|
||||||
end
|
end
|
||||||
|
|
||||||
group :test do
|
group :test do
|
||||||
gem 'capybara', '~> 3.11'
|
gem 'capybara', '~> 3.12'
|
||||||
gem 'climate_control', '~> 0.2'
|
gem 'climate_control', '~> 0.2'
|
||||||
gem 'faker', '~> 1.9'
|
gem 'faker', '~> 1.9'
|
||||||
gem 'microformats', '~> 4.0'
|
gem 'microformats', '~> 4.0'
|
||||||
|
@ -128,7 +128,7 @@ group :development do
|
||||||
gem 'letter_opener', '~> 1.4'
|
gem 'letter_opener', '~> 1.4'
|
||||||
gem 'letter_opener_web', '~> 1.3'
|
gem 'letter_opener_web', '~> 1.3'
|
||||||
gem 'memory_profiler'
|
gem 'memory_profiler'
|
||||||
gem 'rubocop', '~> 0.60', require: false
|
gem 'rubocop', '~> 0.61', require: false
|
||||||
gem 'brakeman', '~> 4.3', require: false
|
gem 'brakeman', '~> 4.3', require: false
|
||||||
gem 'bundler-audit', '~> 0.6', require: false
|
gem 'bundler-audit', '~> 0.6', require: false
|
||||||
gem 'scss_lint', '~> 0.57', require: false
|
gem 'scss_lint', '~> 0.57', require: false
|
||||||
|
|
94
Gemfile.lock
94
Gemfile.lock
|
@ -15,25 +15,25 @@ GIT
|
||||||
GEM
|
GEM
|
||||||
remote: https://rubygems.org/
|
remote: https://rubygems.org/
|
||||||
specs:
|
specs:
|
||||||
actioncable (5.2.1.1)
|
actioncable (5.2.2)
|
||||||
actionpack (= 5.2.1.1)
|
actionpack (= 5.2.2)
|
||||||
nio4r (~> 2.0)
|
nio4r (~> 2.0)
|
||||||
websocket-driver (>= 0.6.1)
|
websocket-driver (>= 0.6.1)
|
||||||
actionmailer (5.2.1.1)
|
actionmailer (5.2.2)
|
||||||
actionpack (= 5.2.1.1)
|
actionpack (= 5.2.2)
|
||||||
actionview (= 5.2.1.1)
|
actionview (= 5.2.2)
|
||||||
activejob (= 5.2.1.1)
|
activejob (= 5.2.2)
|
||||||
mail (~> 2.5, >= 2.5.4)
|
mail (~> 2.5, >= 2.5.4)
|
||||||
rails-dom-testing (~> 2.0)
|
rails-dom-testing (~> 2.0)
|
||||||
actionpack (5.2.1.1)
|
actionpack (5.2.2)
|
||||||
actionview (= 5.2.1.1)
|
actionview (= 5.2.2)
|
||||||
activesupport (= 5.2.1.1)
|
activesupport (= 5.2.2)
|
||||||
rack (~> 2.0)
|
rack (~> 2.0)
|
||||||
rack-test (>= 0.6.3)
|
rack-test (>= 0.6.3)
|
||||||
rails-dom-testing (~> 2.0)
|
rails-dom-testing (~> 2.0)
|
||||||
rails-html-sanitizer (~> 1.0, >= 1.0.2)
|
rails-html-sanitizer (~> 1.0, >= 1.0.2)
|
||||||
actionview (5.2.1.1)
|
actionview (5.2.2)
|
||||||
activesupport (= 5.2.1.1)
|
activesupport (= 5.2.2)
|
||||||
builder (~> 3.1)
|
builder (~> 3.1)
|
||||||
erubi (~> 1.4)
|
erubi (~> 1.4)
|
||||||
rails-dom-testing (~> 2.0)
|
rails-dom-testing (~> 2.0)
|
||||||
|
@ -44,20 +44,20 @@ GEM
|
||||||
case_transform (>= 0.2)
|
case_transform (>= 0.2)
|
||||||
jsonapi-renderer (>= 0.1.1.beta1, < 0.3)
|
jsonapi-renderer (>= 0.1.1.beta1, < 0.3)
|
||||||
active_record_query_trace (1.5.4)
|
active_record_query_trace (1.5.4)
|
||||||
activejob (5.2.1.1)
|
activejob (5.2.2)
|
||||||
activesupport (= 5.2.1.1)
|
activesupport (= 5.2.2)
|
||||||
globalid (>= 0.3.6)
|
globalid (>= 0.3.6)
|
||||||
activemodel (5.2.1.1)
|
activemodel (5.2.2)
|
||||||
activesupport (= 5.2.1.1)
|
activesupport (= 5.2.2)
|
||||||
activerecord (5.2.1.1)
|
activerecord (5.2.2)
|
||||||
activemodel (= 5.2.1.1)
|
activemodel (= 5.2.2)
|
||||||
activesupport (= 5.2.1.1)
|
activesupport (= 5.2.2)
|
||||||
arel (>= 9.0)
|
arel (>= 9.0)
|
||||||
activestorage (5.2.1.1)
|
activestorage (5.2.2)
|
||||||
actionpack (= 5.2.1.1)
|
actionpack (= 5.2.2)
|
||||||
activerecord (= 5.2.1.1)
|
activerecord (= 5.2.2)
|
||||||
marcel (~> 0.3.1)
|
marcel (~> 0.3.1)
|
||||||
activesupport (5.2.1.1)
|
activesupport (5.2.2)
|
||||||
concurrent-ruby (~> 1.0, >= 1.0.2)
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
||||||
i18n (>= 0.7, < 2)
|
i18n (>= 0.7, < 2)
|
||||||
minitest (~> 5.1)
|
minitest (~> 5.1)
|
||||||
|
@ -126,7 +126,7 @@ GEM
|
||||||
sshkit (~> 1.3)
|
sshkit (~> 1.3)
|
||||||
capistrano-yarn (2.0.2)
|
capistrano-yarn (2.0.2)
|
||||||
capistrano (~> 3.0)
|
capistrano (~> 3.0)
|
||||||
capybara (3.11.1)
|
capybara (3.12.0)
|
||||||
addressable
|
addressable
|
||||||
mini_mime (>= 0.1.3)
|
mini_mime (>= 0.1.3)
|
||||||
nokogiri (~> 1.8)
|
nokogiri (~> 1.8)
|
||||||
|
@ -412,13 +412,13 @@ GEM
|
||||||
actionmailer (>= 3, < 6)
|
actionmailer (>= 3, < 6)
|
||||||
premailer (~> 1.7, >= 1.7.9)
|
premailer (~> 1.7, >= 1.7.9)
|
||||||
private_address_check (0.5.0)
|
private_address_check (0.5.0)
|
||||||
pry (0.12.0)
|
pry (0.12.2)
|
||||||
coderay (~> 1.1.0)
|
coderay (~> 1.1.0)
|
||||||
method_source (~> 0.9.0)
|
method_source (~> 0.9.0)
|
||||||
pry-byebug (3.6.0)
|
pry-byebug (3.6.0)
|
||||||
byebug (~> 10.0)
|
byebug (~> 10.0)
|
||||||
pry (~> 0.10)
|
pry (~> 0.10)
|
||||||
pry-rails (0.3.7)
|
pry-rails (0.3.8)
|
||||||
pry (>= 0.10.4)
|
pry (>= 0.10.4)
|
||||||
public_suffix (3.0.3)
|
public_suffix (3.0.3)
|
||||||
puma (3.12.0)
|
puma (3.12.0)
|
||||||
|
@ -435,23 +435,23 @@ GEM
|
||||||
rack
|
rack
|
||||||
rack-test (1.1.0)
|
rack-test (1.1.0)
|
||||||
rack (>= 1.0, < 3)
|
rack (>= 1.0, < 3)
|
||||||
rails (5.2.1.1)
|
rails (5.2.2)
|
||||||
actioncable (= 5.2.1.1)
|
actioncable (= 5.2.2)
|
||||||
actionmailer (= 5.2.1.1)
|
actionmailer (= 5.2.2)
|
||||||
actionpack (= 5.2.1.1)
|
actionpack (= 5.2.2)
|
||||||
actionview (= 5.2.1.1)
|
actionview (= 5.2.2)
|
||||||
activejob (= 5.2.1.1)
|
activejob (= 5.2.2)
|
||||||
activemodel (= 5.2.1.1)
|
activemodel (= 5.2.2)
|
||||||
activerecord (= 5.2.1.1)
|
activerecord (= 5.2.2)
|
||||||
activestorage (= 5.2.1.1)
|
activestorage (= 5.2.2)
|
||||||
activesupport (= 5.2.1.1)
|
activesupport (= 5.2.2)
|
||||||
bundler (>= 1.3.0)
|
bundler (>= 1.3.0)
|
||||||
railties (= 5.2.1.1)
|
railties (= 5.2.2)
|
||||||
sprockets-rails (>= 2.0.0)
|
sprockets-rails (>= 2.0.0)
|
||||||
rails-controller-testing (1.0.2)
|
rails-controller-testing (1.0.4)
|
||||||
actionpack (~> 5.x, >= 5.0.1)
|
actionpack (>= 5.0.1.x)
|
||||||
actionview (~> 5.x, >= 5.0.1)
|
actionview (>= 5.0.1.x)
|
||||||
activesupport (~> 5.x)
|
activesupport (>= 5.0.1.x)
|
||||||
rails-dom-testing (2.0.3)
|
rails-dom-testing (2.0.3)
|
||||||
activesupport (>= 4.2.0)
|
activesupport (>= 4.2.0)
|
||||||
nokogiri (>= 1.6)
|
nokogiri (>= 1.6)
|
||||||
|
@ -462,9 +462,9 @@ GEM
|
||||||
railties (>= 5.0, < 6)
|
railties (>= 5.0, < 6)
|
||||||
rails-settings-cached (0.6.6)
|
rails-settings-cached (0.6.6)
|
||||||
rails (>= 4.2.0)
|
rails (>= 4.2.0)
|
||||||
railties (5.2.1.1)
|
railties (5.2.2)
|
||||||
actionpack (= 5.2.1.1)
|
actionpack (= 5.2.2)
|
||||||
activesupport (= 5.2.1.1)
|
activesupport (= 5.2.2)
|
||||||
method_source
|
method_source
|
||||||
rake (>= 0.8.7)
|
rake (>= 0.8.7)
|
||||||
thor (>= 0.19.0, < 2.0)
|
thor (>= 0.19.0, < 2.0)
|
||||||
|
@ -527,7 +527,7 @@ GEM
|
||||||
rspec-core (~> 3.0, >= 3.0.0)
|
rspec-core (~> 3.0, >= 3.0.0)
|
||||||
sidekiq (>= 2.4.0)
|
sidekiq (>= 2.4.0)
|
||||||
rspec-support (3.8.0)
|
rspec-support (3.8.0)
|
||||||
rubocop (0.60.0)
|
rubocop (0.61.0)
|
||||||
jaro_winkler (~> 1.5.1)
|
jaro_winkler (~> 1.5.1)
|
||||||
parallel (~> 1.10)
|
parallel (~> 1.10)
|
||||||
parser (>= 2.5, != 2.5.1.1)
|
parser (>= 2.5, != 2.5.1.1)
|
||||||
|
@ -669,7 +669,7 @@ DEPENDENCIES
|
||||||
capistrano-rails (~> 1.4)
|
capistrano-rails (~> 1.4)
|
||||||
capistrano-rbenv (~> 2.1)
|
capistrano-rbenv (~> 2.1)
|
||||||
capistrano-yarn (~> 2.0)
|
capistrano-yarn (~> 2.0)
|
||||||
capybara (~> 3.11)
|
capybara (~> 3.12)
|
||||||
charlock_holmes (~> 0.7.6)
|
charlock_holmes (~> 0.7.6)
|
||||||
chewy (~> 5.0)
|
chewy (~> 5.0)
|
||||||
cld3 (~> 3.2.0)
|
cld3 (~> 3.2.0)
|
||||||
|
@ -735,7 +735,7 @@ DEPENDENCIES
|
||||||
pundit (~> 2.0)
|
pundit (~> 2.0)
|
||||||
rack-attack (~> 5.4)
|
rack-attack (~> 5.4)
|
||||||
rack-cors (~> 1.0)
|
rack-cors (~> 1.0)
|
||||||
rails (~> 5.2.1)
|
rails (~> 5.2.2)
|
||||||
rails-controller-testing (~> 1.0)
|
rails-controller-testing (~> 1.0)
|
||||||
rails-i18n (~> 5.1)
|
rails-i18n (~> 5.1)
|
||||||
rails-settings-cached (~> 0.6)
|
rails-settings-cached (~> 0.6)
|
||||||
|
@ -746,7 +746,7 @@ DEPENDENCIES
|
||||||
rqrcode (~> 0.10)
|
rqrcode (~> 0.10)
|
||||||
rspec-rails (~> 3.8)
|
rspec-rails (~> 3.8)
|
||||||
rspec-sidekiq (~> 3.0)
|
rspec-sidekiq (~> 3.0)
|
||||||
rubocop (~> 0.60)
|
rubocop (~> 0.61)
|
||||||
sanitize (~> 5.0)
|
sanitize (~> 5.0)
|
||||||
scss_lint (~> 0.57)
|
scss_lint (~> 0.57)
|
||||||
sidekiq (~> 5.2)
|
sidekiq (~> 5.2)
|
||||||
|
|
|
@ -67,12 +67,13 @@ class StatusesController < ApplicationController
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def create_descendant_thread(depth, statuses)
|
def create_descendant_thread(starting_depth, statuses)
|
||||||
|
depth = starting_depth + statuses.size
|
||||||
if depth < DESCENDANTS_DEPTH_LIMIT
|
if depth < DESCENDANTS_DEPTH_LIMIT
|
||||||
{ statuses: statuses }
|
{ statuses: statuses, starting_depth: starting_depth }
|
||||||
else
|
else
|
||||||
next_status = statuses.pop
|
next_status = statuses.pop
|
||||||
{ statuses: statuses, next_status: next_status }
|
{ statuses: statuses, starting_depth: starting_depth, next_status: next_status }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -104,15 +105,18 @@ class StatusesController < ApplicationController
|
||||||
|
|
||||||
if descendants.present?
|
if descendants.present?
|
||||||
statuses = [descendants.first]
|
statuses = [descendants.first]
|
||||||
depth = 1
|
starting_depth = 0
|
||||||
|
|
||||||
descendants.drop(1).each_with_index do |descendant, index|
|
descendants.drop(1).each_with_index do |descendant, index|
|
||||||
if descendants[index].id == descendant.in_reply_to_id
|
if descendants[index].id == descendant.in_reply_to_id
|
||||||
depth += 1
|
|
||||||
statuses << descendant
|
statuses << descendant
|
||||||
else
|
else
|
||||||
@descendant_threads << create_descendant_thread(depth, statuses)
|
@descendant_threads << create_descendant_thread(starting_depth, statuses)
|
||||||
|
|
||||||
|
# The thread is broken, assume it's a reply to the root status
|
||||||
|
starting_depth = 0
|
||||||
|
|
||||||
|
# ... unless we can find its ancestor in one of the already-processed threads
|
||||||
@descendant_threads.reverse_each do |descendant_thread|
|
@descendant_threads.reverse_each do |descendant_thread|
|
||||||
statuses = descendant_thread[:statuses]
|
statuses = descendant_thread[:statuses]
|
||||||
|
|
||||||
|
@ -121,18 +125,16 @@ class StatusesController < ApplicationController
|
||||||
end
|
end
|
||||||
|
|
||||||
if index.present?
|
if index.present?
|
||||||
depth += index - statuses.size
|
starting_depth = descendant_thread[:starting_depth] + index + 1
|
||||||
break
|
break
|
||||||
end
|
end
|
||||||
|
|
||||||
depth -= statuses.size
|
|
||||||
end
|
end
|
||||||
|
|
||||||
statuses = [descendant]
|
statuses = [descendant]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@descendant_threads << create_descendant_thread(depth, statuses)
|
@descendant_threads << create_descendant_thread(starting_depth, statuses)
|
||||||
end
|
end
|
||||||
|
|
||||||
@max_descendant_thread_id = @descendant_threads.pop[:statuses].first.id if descendants.size >= DESCENDANTS_LIMIT
|
@max_descendant_thread_id = @descendant_threads.pop[:statuses].first.id if descendants.size >= DESCENDANTS_LIMIT
|
||||||
|
|
|
@ -3,6 +3,7 @@ import PropTypes from 'prop-types';
|
||||||
import ImmutablePropTypes from 'react-immutable-proptypes';
|
import ImmutablePropTypes from 'react-immutable-proptypes';
|
||||||
import StatusContainer from '../../../containers/status_container';
|
import StatusContainer from '../../../containers/status_container';
|
||||||
import AccountContainer from '../../../containers/account_container';
|
import AccountContainer from '../../../containers/account_container';
|
||||||
|
import RelativeTimestamp from '../../../components/relative_timestamp';
|
||||||
import { injectIntl, FormattedMessage } from 'react-intl';
|
import { injectIntl, FormattedMessage } from 'react-intl';
|
||||||
import Permalink from '../../../components/permalink';
|
import Permalink from '../../../components/permalink';
|
||||||
import ImmutablePureComponent from 'react-immutable-pure-component';
|
import ImmutablePureComponent from 'react-immutable-pure-component';
|
||||||
|
@ -87,9 +88,11 @@ class Notification extends ImmutablePureComponent {
|
||||||
</div>
|
</div>
|
||||||
<span title={notification.get('created_at')}>
|
<span title={notification.get('created_at')}>
|
||||||
<FormattedMessage id='notification.follow' defaultMessage='{name} followed you' values={{ name: link }} />
|
<FormattedMessage id='notification.follow' defaultMessage='{name} followed you' values={{ name: link }} />
|
||||||
|
<span className='notification__relative_time'>
|
||||||
|
<RelativeTimestamp timestamp={notification.get('created_at')} />
|
||||||
|
</span>
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<AccountContainer id={account.get('id')} withNote={false} hidden={this.props.hidden} />
|
<AccountContainer id={account.get('id')} withNote={false} hidden={this.props.hidden} />
|
||||||
</div>
|
</div>
|
||||||
</HotKeys>
|
</HotKeys>
|
||||||
|
@ -120,6 +123,9 @@ class Notification extends ImmutablePureComponent {
|
||||||
<i className='fa fa-fw fa-star star-icon' />
|
<i className='fa fa-fw fa-star star-icon' />
|
||||||
</div>
|
</div>
|
||||||
<FormattedMessage id='notification.favourite' defaultMessage='{name} favourited your status' values={{ name: link }} />
|
<FormattedMessage id='notification.favourite' defaultMessage='{name} favourited your status' values={{ name: link }} />
|
||||||
|
<span className='notification__relative_time'>
|
||||||
|
<RelativeTimestamp className='notification__relative_time' timestamp={notification.get('created_at')} />
|
||||||
|
</span>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<StatusContainer id={notification.get('status')} account={notification.get('account')} muted withDismiss hidden={!!this.props.hidden} />
|
<StatusContainer id={notification.get('status')} account={notification.get('account')} muted withDismiss hidden={!!this.props.hidden} />
|
||||||
|
@ -139,6 +145,9 @@ class Notification extends ImmutablePureComponent {
|
||||||
<i className='fa fa-fw fa-retweet' />
|
<i className='fa fa-fw fa-retweet' />
|
||||||
</div>
|
</div>
|
||||||
<FormattedMessage id='notification.reblog' defaultMessage='{name} boosted your status' values={{ name: link }} />
|
<FormattedMessage id='notification.reblog' defaultMessage='{name} boosted your status' values={{ name: link }} />
|
||||||
|
<span className='notification__relative_time'>
|
||||||
|
<RelativeTimestamp className='notification__relative_time' timestamp={notification.get('created_at')} />
|
||||||
|
</span>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<StatusContainer id={notification.get('status')} account={notification.get('account')} muted withDismiss hidden={this.props.hidden} />
|
<StatusContainer id={notification.get('status')} account={notification.get('account')} muted withDismiss hidden={this.props.hidden} />
|
||||||
|
|
|
@ -1489,6 +1489,7 @@ a.account__display-name {
|
||||||
cursor: default;
|
cursor: default;
|
||||||
color: $darker-text-color;
|
color: $darker-text-color;
|
||||||
font-size: 15px;
|
font-size: 15px;
|
||||||
|
line-height: 22px;
|
||||||
position: relative;
|
position: relative;
|
||||||
|
|
||||||
.fa {
|
.fa {
|
||||||
|
@ -1496,7 +1497,7 @@ a.account__display-name {
|
||||||
}
|
}
|
||||||
|
|
||||||
> span {
|
> span {
|
||||||
display: block;
|
display: inline;
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
text-overflow: ellipsis;
|
text-overflow: ellipsis;
|
||||||
}
|
}
|
||||||
|
@ -1526,6 +1527,10 @@ a.account__display-name {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.notification__relative_time {
|
||||||
|
float: right;
|
||||||
|
}
|
||||||
|
|
||||||
.display-name {
|
.display-name {
|
||||||
display: block;
|
display: block;
|
||||||
max-width: 100%;
|
max-width: 100%;
|
||||||
|
|
|
@ -49,6 +49,7 @@ class Account < ApplicationRecord
|
||||||
USERNAME_RE = /[a-z0-9_]+([a-z0-9_\.-]+[a-z0-9_]+)?/i
|
USERNAME_RE = /[a-z0-9_]+([a-z0-9_\.-]+[a-z0-9_]+)?/i
|
||||||
MENTION_RE = /(?<=^|[^\/[:word:]])@((#{USERNAME_RE})(?:@[a-z0-9\.\-]+[a-z0-9]+)?)/i
|
MENTION_RE = /(?<=^|[^\/[:word:]])@((#{USERNAME_RE})(?:@[a-z0-9\.\-]+[a-z0-9]+)?)/i
|
||||||
|
|
||||||
|
include AccountAssociations
|
||||||
include AccountAvatar
|
include AccountAvatar
|
||||||
include AccountFinderConcern
|
include AccountFinderConcern
|
||||||
include AccountHeader
|
include AccountHeader
|
||||||
|
@ -63,9 +64,6 @@ class Account < ApplicationRecord
|
||||||
|
|
||||||
enum protocol: [:ostatus, :activitypub]
|
enum protocol: [:ostatus, :activitypub]
|
||||||
|
|
||||||
# Local users
|
|
||||||
has_one :user, inverse_of: :account
|
|
||||||
|
|
||||||
validates :username, presence: true
|
validates :username, presence: true
|
||||||
|
|
||||||
# Remote user validations
|
# Remote user validations
|
||||||
|
@ -80,46 +78,6 @@ class Account < ApplicationRecord
|
||||||
validate :note_length_does_not_exceed_length_limit, if: -> { local? && will_save_change_to_note? }
|
validate :note_length_does_not_exceed_length_limit, if: -> { local? && will_save_change_to_note? }
|
||||||
validates :fields, length: { maximum: MAX_FIELDS }, if: -> { local? && will_save_change_to_fields? }
|
validates :fields, length: { maximum: MAX_FIELDS }, if: -> { local? && will_save_change_to_fields? }
|
||||||
|
|
||||||
# Timelines
|
|
||||||
has_many :stream_entries, inverse_of: :account, dependent: :destroy
|
|
||||||
has_many :statuses, inverse_of: :account, dependent: :destroy
|
|
||||||
has_many :favourites, inverse_of: :account, dependent: :destroy
|
|
||||||
has_many :bookmarks, inverse_of: :account, dependent: :destroy
|
|
||||||
has_many :mentions, inverse_of: :account, dependent: :destroy
|
|
||||||
has_many :notifications, inverse_of: :account, dependent: :destroy
|
|
||||||
|
|
||||||
# Pinned statuses
|
|
||||||
has_many :status_pins, inverse_of: :account, dependent: :destroy
|
|
||||||
has_many :pinned_statuses, -> { reorder('status_pins.created_at DESC') }, through: :status_pins, class_name: 'Status', source: :status
|
|
||||||
|
|
||||||
# Endorsements
|
|
||||||
has_many :account_pins, inverse_of: :account, dependent: :destroy
|
|
||||||
has_many :endorsed_accounts, through: :account_pins, class_name: 'Account', source: :target_account
|
|
||||||
|
|
||||||
# Media
|
|
||||||
has_many :media_attachments, dependent: :destroy
|
|
||||||
|
|
||||||
# PuSH subscriptions
|
|
||||||
has_many :subscriptions, dependent: :destroy
|
|
||||||
|
|
||||||
# Report relationships
|
|
||||||
has_many :reports
|
|
||||||
has_many :targeted_reports, class_name: 'Report', foreign_key: :target_account_id
|
|
||||||
|
|
||||||
has_many :report_notes, dependent: :destroy
|
|
||||||
has_many :custom_filters, inverse_of: :account, dependent: :destroy
|
|
||||||
|
|
||||||
# Moderation notes
|
|
||||||
has_many :account_moderation_notes, dependent: :destroy
|
|
||||||
has_many :targeted_moderation_notes, class_name: 'AccountModerationNote', foreign_key: :target_account_id, dependent: :destroy
|
|
||||||
|
|
||||||
# Lists
|
|
||||||
has_many :list_accounts, inverse_of: :account, dependent: :destroy
|
|
||||||
has_many :lists, through: :list_accounts
|
|
||||||
|
|
||||||
# Account migrations
|
|
||||||
belongs_to :moved_to_account, class_name: 'Account', optional: true
|
|
||||||
|
|
||||||
scope :remote, -> { where.not(domain: nil) }
|
scope :remote, -> { where.not(domain: nil) }
|
||||||
scope :local, -> { where(domain: nil) }
|
scope :local, -> { where(domain: nil) }
|
||||||
scope :expiring, ->(time) { remote.where.not(subscription_expires_at: nil).where('subscription_expires_at < ?', time) }
|
scope :expiring, ->(time) { remote.where.not(subscription_expires_at: nil).where('subscription_expires_at < ?', time) }
|
||||||
|
@ -455,6 +413,7 @@ class Account < ApplicationRecord
|
||||||
before_create :generate_keys
|
before_create :generate_keys
|
||||||
before_validation :normalize_domain
|
before_validation :normalize_domain
|
||||||
before_validation :prepare_contents, if: :local?
|
before_validation :prepare_contents, if: :local?
|
||||||
|
before_destroy :clean_feed_manager
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
|
@ -496,4 +455,19 @@ class Account < ApplicationRecord
|
||||||
def emojifiable_text
|
def emojifiable_text
|
||||||
[note, display_name, fields.map(&:value)].join(' ')
|
[note, display_name, fields.map(&:value)].join(' ')
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def clean_feed_manager
|
||||||
|
reblog_key = FeedManager.instance.key(:home, id, 'reblogs')
|
||||||
|
reblogged_id_set = Redis.current.zrange(reblog_key, 0, -1)
|
||||||
|
|
||||||
|
Redis.current.pipelined do
|
||||||
|
Redis.current.del(FeedManager.instance.key(:home, id))
|
||||||
|
Redis.current.del(reblog_key)
|
||||||
|
|
||||||
|
reblogged_id_set.each do |reblogged_id|
|
||||||
|
reblog_set_key = FeedManager.instance.key(:home, id, "reblogs:#{reblogged_id}")
|
||||||
|
Redis.current.del(reblog_set_key)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -0,0 +1,54 @@
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
module AccountAssociations
|
||||||
|
extend ActiveSupport::Concern
|
||||||
|
|
||||||
|
included do
|
||||||
|
# Local users
|
||||||
|
has_one :user, inverse_of: :account, dependent: :destroy
|
||||||
|
|
||||||
|
# Timelines
|
||||||
|
has_many :stream_entries, inverse_of: :account, dependent: :destroy
|
||||||
|
has_many :statuses, inverse_of: :account, dependent: :destroy
|
||||||
|
has_many :favourites, inverse_of: :account, dependent: :destroy
|
||||||
|
has_many :bookmarks, inverse_of: :account, dependent: :destroy
|
||||||
|
has_many :mentions, inverse_of: :account, dependent: :destroy
|
||||||
|
has_many :notifications, inverse_of: :account, dependent: :destroy
|
||||||
|
has_many :conversations, class_name: 'AccountConversation', dependent: :destroy, inverse_of: :account
|
||||||
|
|
||||||
|
# Pinned statuses
|
||||||
|
has_many :status_pins, inverse_of: :account, dependent: :destroy
|
||||||
|
has_many :pinned_statuses, -> { reorder('status_pins.created_at DESC') }, through: :status_pins, class_name: 'Status', source: :status
|
||||||
|
|
||||||
|
# Endorsements
|
||||||
|
has_many :account_pins, inverse_of: :account, dependent: :destroy
|
||||||
|
has_many :endorsed_accounts, through: :account_pins, class_name: 'Account', source: :target_account
|
||||||
|
|
||||||
|
# Media
|
||||||
|
has_many :media_attachments, dependent: :destroy
|
||||||
|
|
||||||
|
# PuSH subscriptions
|
||||||
|
has_many :subscriptions, dependent: :destroy
|
||||||
|
|
||||||
|
# Report relationships
|
||||||
|
has_many :reports, dependent: :destroy, inverse_of: :account
|
||||||
|
has_many :targeted_reports, class_name: 'Report', foreign_key: :target_account_id, dependent: :destroy, inverse_of: :target_account
|
||||||
|
|
||||||
|
has_many :report_notes, dependent: :destroy
|
||||||
|
has_many :custom_filters, inverse_of: :account, dependent: :destroy
|
||||||
|
|
||||||
|
# Moderation notes
|
||||||
|
has_many :account_moderation_notes, dependent: :destroy, inverse_of: :account
|
||||||
|
has_many :targeted_moderation_notes, class_name: 'AccountModerationNote', foreign_key: :target_account_id, dependent: :destroy, inverse_of: :target_account
|
||||||
|
|
||||||
|
# Lists (that the account is on, not owned by the account)
|
||||||
|
has_many :list_accounts, inverse_of: :account, dependent: :destroy
|
||||||
|
has_many :lists, through: :list_accounts
|
||||||
|
|
||||||
|
# Lists (owned by the account)
|
||||||
|
has_many :owned_lists, class_name: 'List', dependent: :destroy, inverse_of: :account
|
||||||
|
|
||||||
|
# Account migrations
|
||||||
|
belongs_to :moved_to_account, class_name: 'Account', optional: true
|
||||||
|
end
|
||||||
|
end
|
|
@ -241,8 +241,8 @@ class Status < ApplicationRecord
|
||||||
update_status_stat!(key => [public_send(key) - 1, 0].max)
|
update_status_stat!(key => [public_send(key) - 1, 0].max)
|
||||||
end
|
end
|
||||||
|
|
||||||
after_create :increment_counter_caches
|
after_create_commit :increment_counter_caches
|
||||||
after_destroy :decrement_counter_caches
|
after_destroy_commit :decrement_counter_caches
|
||||||
|
|
||||||
after_create_commit :store_uri, if: :local?
|
after_create_commit :store_uri, if: :local?
|
||||||
after_create_commit :update_statistics, if: :local?
|
after_create_commit :update_statistics, if: :local?
|
||||||
|
@ -446,7 +446,7 @@ class Status < ApplicationRecord
|
||||||
end
|
end
|
||||||
|
|
||||||
def store_uri
|
def store_uri
|
||||||
update_attribute(:uri, ActivityPub::TagManager.instance.uri_for(self)) if uri.nil?
|
update_column(:uri, ActivityPub::TagManager.instance.uri_for(self)) if uri.nil?
|
||||||
end
|
end
|
||||||
|
|
||||||
def prepare_contents
|
def prepare_contents
|
||||||
|
|
|
@ -9,7 +9,9 @@ class BatchedRemoveStatusService < BaseService
|
||||||
# Remove statuses from home feeds
|
# Remove statuses from home feeds
|
||||||
# Push delete events to streaming API for home feeds and public feeds
|
# Push delete events to streaming API for home feeds and public feeds
|
||||||
# @param [Status] statuses A preferably batched array of statuses
|
# @param [Status] statuses A preferably batched array of statuses
|
||||||
def call(statuses)
|
# @param [Hash] options
|
||||||
|
# @option [Boolean] :skip_side_effects
|
||||||
|
def call(statuses, **options)
|
||||||
statuses = Status.where(id: statuses.map(&:id)).includes(:account, :stream_entry).flat_map { |status| [status] + status.reblogs.includes(:account, :stream_entry).to_a }
|
statuses = Status.where(id: statuses.map(&:id)).includes(:account, :stream_entry).flat_map { |status| [status] + status.reblogs.includes(:account, :stream_entry).to_a }
|
||||||
|
|
||||||
@mentions = statuses.each_with_object({}) { |s, h| h[s.id] = s.active_mentions.includes(:account).to_a }
|
@mentions = statuses.each_with_object({}) { |s, h| h[s.id] = s.active_mentions.includes(:account).to_a }
|
||||||
|
@ -26,6 +28,8 @@ class BatchedRemoveStatusService < BaseService
|
||||||
status.destroy
|
status.destroy
|
||||||
end
|
end
|
||||||
|
|
||||||
|
return if options[:skip_side_effects]
|
||||||
|
|
||||||
# Batch by source account
|
# Batch by source account
|
||||||
statuses.group_by(&:account_id).each_value do |account_statuses|
|
statuses.group_by(&:account_id).each_value do |account_statuses|
|
||||||
account = account_statuses.first.account
|
account = account_statuses.first.account
|
||||||
|
|
|
@ -1,6 +1,41 @@
|
||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
class SuspendAccountService < BaseService
|
class SuspendAccountService < BaseService
|
||||||
|
ASSOCIATIONS_ON_SUSPEND = %w(
|
||||||
|
account_pins
|
||||||
|
active_relationships
|
||||||
|
block_relationships
|
||||||
|
blocked_by_relationships
|
||||||
|
conversation_mutes
|
||||||
|
conversations
|
||||||
|
custom_filters
|
||||||
|
domain_blocks
|
||||||
|
favourites
|
||||||
|
follow_requests
|
||||||
|
list_accounts
|
||||||
|
media_attachments
|
||||||
|
mute_relationships
|
||||||
|
muted_by_relationships
|
||||||
|
notifications
|
||||||
|
owned_lists
|
||||||
|
passive_relationships
|
||||||
|
report_notes
|
||||||
|
status_pins
|
||||||
|
stream_entries
|
||||||
|
subscriptions
|
||||||
|
).freeze
|
||||||
|
|
||||||
|
ASSOCIATIONS_ON_DESTROY = %w(
|
||||||
|
reports
|
||||||
|
targeted_moderation_notes
|
||||||
|
targeted_reports
|
||||||
|
).freeze
|
||||||
|
|
||||||
|
# Suspend an account and remove as much of its data as possible
|
||||||
|
# @param [Account]
|
||||||
|
# @param [Hash] options
|
||||||
|
# @option [Boolean] :including_user Remove the user record as well
|
||||||
|
# @option [Boolean] :destroy Remove the account record instead of suspending
|
||||||
def call(account, **options)
|
def call(account, **options)
|
||||||
@account = account
|
@account = account
|
||||||
@options = options
|
@options = options
|
||||||
|
@ -8,60 +43,66 @@ class SuspendAccountService < BaseService
|
||||||
purge_user!
|
purge_user!
|
||||||
purge_profile!
|
purge_profile!
|
||||||
purge_content!
|
purge_content!
|
||||||
unsubscribe_push_subscribers!
|
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def purge_user!
|
def purge_user!
|
||||||
if @options[:remove_user]
|
return if !@account.local? || @account.user.nil?
|
||||||
@account.user&.destroy
|
|
||||||
|
if @options[:including_user]
|
||||||
|
@account.user.destroy
|
||||||
else
|
else
|
||||||
@account.user&.disable!
|
@account.user.disable!
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def purge_content!
|
def purge_content!
|
||||||
if @account.local?
|
distribute_delete_actor! if @account.local?
|
||||||
ActivityPub::DeliveryWorker.push_bulk(delivery_inboxes) do |inbox_url|
|
|
||||||
[delete_actor_json, @account.id, inbox_url]
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
@account.statuses.reorder(nil).find_in_batches do |statuses|
|
@account.statuses.reorder(nil).find_in_batches do |statuses|
|
||||||
BatchedRemoveStatusService.new.call(statuses)
|
BatchedRemoveStatusService.new.call(statuses, skip_side_effects: @options[:destroy])
|
||||||
end
|
end
|
||||||
|
|
||||||
[
|
associations_for_destruction.each do |association_name|
|
||||||
@account.media_attachments,
|
destroy_all(@account.public_send(association_name))
|
||||||
@account.stream_entries,
|
|
||||||
@account.notifications,
|
|
||||||
@account.favourites,
|
|
||||||
@account.active_relationships,
|
|
||||||
@account.passive_relationships,
|
|
||||||
].each do |association|
|
|
||||||
destroy_all(association)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@account.destroy if @options[:destroy]
|
||||||
end
|
end
|
||||||
|
|
||||||
def purge_profile!
|
def purge_profile!
|
||||||
|
# If the account is going to be destroyed
|
||||||
|
# there is no point wasting time updating
|
||||||
|
# its values first
|
||||||
|
|
||||||
|
return if @options[:destroy]
|
||||||
|
|
||||||
|
@account.silenced = false
|
||||||
@account.suspended = true
|
@account.suspended = true
|
||||||
|
@account.locked = false
|
||||||
@account.display_name = ''
|
@account.display_name = ''
|
||||||
@account.note = ''
|
@account.note = ''
|
||||||
|
@account.fields = {}
|
||||||
@account.statuses_count = 0
|
@account.statuses_count = 0
|
||||||
|
@account.followers_count = 0
|
||||||
|
@account.following_count = 0
|
||||||
|
@account.moved_to_account = nil
|
||||||
@account.avatar.destroy
|
@account.avatar.destroy
|
||||||
@account.header.destroy
|
@account.header.destroy
|
||||||
@account.save!
|
@account.save!
|
||||||
end
|
end
|
||||||
|
|
||||||
def unsubscribe_push_subscribers!
|
|
||||||
destroy_all(@account.subscriptions)
|
|
||||||
end
|
|
||||||
|
|
||||||
def destroy_all(association)
|
def destroy_all(association)
|
||||||
association.in_batches.destroy_all
|
association.in_batches.destroy_all
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def distribute_delete_actor!
|
||||||
|
ActivityPub::DeliveryWorker.push_bulk(delivery_inboxes) do |inbox_url|
|
||||||
|
[delete_actor_json, @account.id, inbox_url]
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def delete_actor_json
|
def delete_actor_json
|
||||||
return @delete_actor_json if defined?(@delete_actor_json)
|
return @delete_actor_json if defined?(@delete_actor_json)
|
||||||
|
|
||||||
|
@ -77,4 +118,12 @@ class SuspendAccountService < BaseService
|
||||||
def delivery_inboxes
|
def delivery_inboxes
|
||||||
Account.inboxes + Relay.enabled.pluck(:inbox_url)
|
Account.inboxes + Relay.enabled.pluck(:inbox_url)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def associations_for_destruction
|
||||||
|
if @options[:destroy]
|
||||||
|
ASSOCIATIONS_ON_SUSPEND + ASSOCIATIONS_ON_DESTROY
|
||||||
|
else
|
||||||
|
ASSOCIATIONS_ON_SUSPEND
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -6,6 +6,6 @@ class Admin::SuspensionWorker
|
||||||
sidekiq_options queue: 'pull'
|
sidekiq_options queue: 'pull'
|
||||||
|
|
||||||
def perform(account_id, remove_user = false)
|
def perform(account_id, remove_user = false)
|
||||||
SuspendAccountService.new.call(Account.find(account_id), remove_user: remove_user)
|
SuspendAccountService.new.call(Account.find(account_id), including_user: remove_user)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -3,6 +3,8 @@ default: &default
|
||||||
pool: <%= ENV["DB_POOL"] || ENV['MAX_THREADS'] || 5 %>
|
pool: <%= ENV["DB_POOL"] || ENV['MAX_THREADS'] || 5 %>
|
||||||
timeout: 5000
|
timeout: 5000
|
||||||
encoding: unicode
|
encoding: unicode
|
||||||
|
variables:
|
||||||
|
statement_timeout: 60000
|
||||||
|
|
||||||
development:
|
development:
|
||||||
<<: *default
|
<<: *default
|
||||||
|
|
|
@ -22,11 +22,7 @@ module Mastodon
|
||||||
dry_run = options[:dry_run] ? ' (DRY RUN)' : ''
|
dry_run = options[:dry_run] ? ' (DRY RUN)' : ''
|
||||||
|
|
||||||
Account.where(domain: domain).find_each do |account|
|
Account.where(domain: domain).find_each do |account|
|
||||||
unless options[:dry_run]
|
SuspendAccountService.new.call(account, destroy: true) unless options[:dry_run]
|
||||||
SuspendAccountService.new.call(account)
|
|
||||||
account.destroy
|
|
||||||
end
|
|
||||||
|
|
||||||
removed += 1
|
removed += 1
|
||||||
say('.', :green, false)
|
say('.', :green, false)
|
||||||
end
|
end
|
||||||
|
|
|
@ -115,14 +115,18 @@ describe StatusesController do
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'assigns @descendant_threads for threads with :next_status key if they are hitting the depth limit' do
|
it 'assigns @descendant_threads for threads with :next_status key if they are hitting the depth limit' do
|
||||||
stub_const 'StatusesController::DESCENDANTS_DEPTH_LIMIT', 1
|
stub_const 'StatusesController::DESCENDANTS_DEPTH_LIMIT', 2
|
||||||
status = Fabricate(:status)
|
status = Fabricate(:status)
|
||||||
child = Fabricate(:status, in_reply_to_id: status.id)
|
child0 = Fabricate(:status, in_reply_to_id: status.id)
|
||||||
|
child1 = Fabricate(:status, in_reply_to_id: child0.id)
|
||||||
|
child2 = Fabricate(:status, in_reply_to_id: child0.id)
|
||||||
|
|
||||||
get :show, params: { account_username: status.account.username, id: status.id }
|
get :show, params: { account_username: status.account.username, id: status.id }
|
||||||
|
|
||||||
expect(assigns(:descendant_threads)[0][:statuses].pluck(:id)).not_to include child.id
|
expect(assigns(:descendant_threads)[0][:statuses].pluck(:id)).not_to include child1.id
|
||||||
expect(assigns(:descendant_threads)[0][:next_status].id).to eq child.id
|
expect(assigns(:descendant_threads)[1][:statuses].pluck(:id)).not_to include child2.id
|
||||||
|
expect(assigns(:descendant_threads)[0][:next_status].id).to eq child1.id
|
||||||
|
expect(assigns(:descendant_threads)[1][:next_status].id).to eq child2.id
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'returns a success' do
|
it 'returns a success' do
|
||||||
|
|
|
@ -1,5 +1,16 @@
|
||||||
require 'rails_helper'
|
require 'rails_helper'
|
||||||
|
|
||||||
RSpec.describe Identity, type: :model do
|
RSpec.describe Identity, type: :model do
|
||||||
pending "add some examples to (or delete) #{__FILE__}"
|
describe '.find_for_oauth' do
|
||||||
|
let(:auth) { Fabricate(:identity, user: Fabricate(:user)) }
|
||||||
|
|
||||||
|
it 'calls .find_or_create_by' do
|
||||||
|
expect(described_class).to receive(:find_or_create_by).with(uid: auth.uid, provider: auth.provider)
|
||||||
|
described_class.find_for_oauth(auth)
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'returns an instance of Identity' do
|
||||||
|
expect(described_class.find_for_oauth(auth)).to be_instance_of Identity
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,10 +1,6 @@
|
||||||
require 'rails_helper'
|
require 'rails_helper'
|
||||||
|
|
||||||
RSpec.describe Notification, type: :model do
|
RSpec.describe Notification, type: :model do
|
||||||
describe '#from_account' do
|
|
||||||
pending
|
|
||||||
end
|
|
||||||
|
|
||||||
describe '#target_status' do
|
describe '#target_status' do
|
||||||
let(:notification) { Fabricate(:notification, activity: activity) }
|
let(:notification) { Fabricate(:notification, activity: activity) }
|
||||||
let(:status) { Fabricate(:status) }
|
let(:status) { Fabricate(:status) }
|
||||||
|
|
Loading…
Reference in New Issue