Merge branch 'main' into glitch-soc/merge-upstream
Conflicts: - `README.md`: Upstream updated copyright year, we don't mention it so kept our version. - `app/controllers/admin/dashboard_controller.rb`: Not really a conflict, upstream change (removing the spam checker) too close to glitch-soc changes. Ported upstream changes. - `app/models/form/admin_settings.rb`: Same. - `app/services/remove_status_service.rb`: Same. - `app/views/admin/settings/edit.html.haml`: Same. - `config/settings.yml`: Same. - `config/environments/production.rb`: Not a real conflict, upstream added a default HTTP header, but we have extra headers in glitch-soc. Added the header.
This commit is contained in:
@@ -36,7 +36,6 @@ module Admin
|
||||
@profile_directory = Setting.profile_directory
|
||||
@timeline_preview = Setting.timeline_preview
|
||||
@keybase_integration = Setting.enable_keybase
|
||||
@spam_check_enabled = Setting.spam_check_enabled
|
||||
@trends_enabled = Setting.trends
|
||||
end
|
||||
|
||||
|
53
app/controllers/admin/follow_recommendations_controller.rb
Normal file
53
app/controllers/admin/follow_recommendations_controller.rb
Normal file
@@ -0,0 +1,53 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
module Admin
|
||||
class FollowRecommendationsController < BaseController
|
||||
before_action :set_language
|
||||
|
||||
def show
|
||||
authorize :follow_recommendation, :show?
|
||||
|
||||
@form = Form::AccountBatch.new
|
||||
@accounts = filtered_follow_recommendations
|
||||
end
|
||||
|
||||
def update
|
||||
@form = Form::AccountBatch.new(form_account_batch_params.merge(current_account: current_account, action: action_from_button))
|
||||
@form.save
|
||||
rescue ActionController::ParameterMissing
|
||||
# Do nothing
|
||||
ensure
|
||||
redirect_to admin_follow_recommendations_path(filter_params)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def set_language
|
||||
@language = follow_recommendation_filter.language
|
||||
end
|
||||
|
||||
def filtered_follow_recommendations
|
||||
follow_recommendation_filter.results
|
||||
end
|
||||
|
||||
def follow_recommendation_filter
|
||||
@follow_recommendation_filter ||= FollowRecommendationFilter.new(filter_params)
|
||||
end
|
||||
|
||||
def form_account_batch_params
|
||||
params.require(:form_account_batch).permit(:action, account_ids: [])
|
||||
end
|
||||
|
||||
def filter_params
|
||||
params.slice(*FollowRecommendationFilter::KEYS).permit(*FollowRecommendationFilter::KEYS)
|
||||
end
|
||||
|
||||
def action_from_button
|
||||
if params[:suppress]
|
||||
'suppress_follow_recommendation'
|
||||
elsif params[:unsuppress]
|
||||
'unsuppress_follow_recommendation'
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
@@ -3,13 +3,13 @@
|
||||
class Api::V1::Push::SubscriptionsController < Api::BaseController
|
||||
before_action -> { doorkeeper_authorize! :push }
|
||||
before_action :require_user!
|
||||
before_action :set_web_push_subscription
|
||||
before_action :check_web_push_subscription, only: [:show, :update]
|
||||
before_action :set_push_subscription
|
||||
before_action :check_push_subscription, only: [:show, :update]
|
||||
|
||||
def create
|
||||
@web_subscription&.destroy!
|
||||
@push_subscription&.destroy!
|
||||
|
||||
@web_subscription = ::Web::PushSubscription.create!(
|
||||
@push_subscription = Web::PushSubscription.create!(
|
||||
endpoint: subscription_params[:endpoint],
|
||||
key_p256dh: subscription_params[:keys][:p256dh],
|
||||
key_auth: subscription_params[:keys][:auth],
|
||||
@@ -18,31 +18,31 @@ class Api::V1::Push::SubscriptionsController < Api::BaseController
|
||||
access_token_id: doorkeeper_token.id
|
||||
)
|
||||
|
||||
render json: @web_subscription, serializer: REST::WebPushSubscriptionSerializer
|
||||
render json: @push_subscription, serializer: REST::WebPushSubscriptionSerializer
|
||||
end
|
||||
|
||||
def show
|
||||
render json: @web_subscription, serializer: REST::WebPushSubscriptionSerializer
|
||||
render json: @push_subscription, serializer: REST::WebPushSubscriptionSerializer
|
||||
end
|
||||
|
||||
def update
|
||||
@web_subscription.update!(data: data_params)
|
||||
render json: @web_subscription, serializer: REST::WebPushSubscriptionSerializer
|
||||
@push_subscription.update!(data: data_params)
|
||||
render json: @push_subscription, serializer: REST::WebPushSubscriptionSerializer
|
||||
end
|
||||
|
||||
def destroy
|
||||
@web_subscription&.destroy!
|
||||
@push_subscription&.destroy!
|
||||
render_empty
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def set_web_push_subscription
|
||||
@web_subscription = ::Web::PushSubscription.find_by(access_token_id: doorkeeper_token.id)
|
||||
def set_push_subscription
|
||||
@push_subscription = Web::PushSubscription.find_by(access_token_id: doorkeeper_token.id)
|
||||
end
|
||||
|
||||
def check_web_push_subscription
|
||||
not_found if @web_subscription.nil?
|
||||
def check_push_subscription
|
||||
not_found if @push_subscription.nil?
|
||||
end
|
||||
|
||||
def subscription_params
|
||||
@@ -52,6 +52,6 @@ class Api::V1::Push::SubscriptionsController < Api::BaseController
|
||||
def data_params
|
||||
return {} if params[:data].blank?
|
||||
|
||||
params.require(:data).permit(alerts: [:follow, :follow_request, :favourite, :reblog, :mention, :poll, :status])
|
||||
params.require(:data).permit(:policy, alerts: [:follow, :follow_request, :favourite, :reblog, :mention, :poll, :status])
|
||||
end
|
||||
end
|
||||
|
@@ -19,6 +19,6 @@ class Api::V1::SuggestionsController < Api::BaseController
|
||||
private
|
||||
|
||||
def set_accounts
|
||||
@accounts = PotentialFriendshipTracker.get(current_account.id, limit: limit_param(DEFAULT_ACCOUNTS_LIMIT))
|
||||
@accounts = PotentialFriendshipTracker.get(current_account, limit_param(DEFAULT_ACCOUNTS_LIMIT))
|
||||
end
|
||||
end
|
||||
|
19
app/controllers/api/v2/suggestions_controller.rb
Normal file
19
app/controllers/api/v2/suggestions_controller.rb
Normal file
@@ -0,0 +1,19 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class Api::V2::SuggestionsController < Api::BaseController
|
||||
include Authorization
|
||||
|
||||
before_action -> { doorkeeper_authorize! :read }
|
||||
before_action :require_user!
|
||||
before_action :set_suggestions
|
||||
|
||||
def index
|
||||
render json: @suggestions, each_serializer: REST::SuggestionSerializer
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def set_suggestions
|
||||
@suggestions = AccountSuggestions.get(current_account, limit_param(DEFAULT_ACCOUNTS_LIMIT))
|
||||
end
|
||||
end
|
@@ -2,6 +2,7 @@
|
||||
|
||||
class Api::Web::PushSubscriptionsController < Api::Web::BaseController
|
||||
before_action :require_user!
|
||||
before_action :set_push_subscription, only: :update
|
||||
|
||||
def create
|
||||
active_session = current_session
|
||||
@@ -15,9 +16,11 @@ class Api::Web::PushSubscriptionsController < Api::Web::BaseController
|
||||
alerts_enabled = active_session.detection.device.mobile? || active_session.detection.device.tablet?
|
||||
|
||||
data = {
|
||||
policy: 'all',
|
||||
|
||||
alerts: {
|
||||
follow: alerts_enabled,
|
||||
follow_request: false,
|
||||
follow_request: alerts_enabled,
|
||||
favourite: alerts_enabled,
|
||||
reblog: alerts_enabled,
|
||||
mention: alerts_enabled,
|
||||
@@ -28,7 +31,7 @@ class Api::Web::PushSubscriptionsController < Api::Web::BaseController
|
||||
|
||||
data.deep_merge!(data_params) if params[:data]
|
||||
|
||||
web_subscription = ::Web::PushSubscription.create!(
|
||||
push_subscription = ::Web::PushSubscription.create!(
|
||||
endpoint: subscription_params[:endpoint],
|
||||
key_p256dh: subscription_params[:keys][:p256dh],
|
||||
key_auth: subscription_params[:keys][:auth],
|
||||
@@ -37,27 +40,27 @@ class Api::Web::PushSubscriptionsController < Api::Web::BaseController
|
||||
access_token_id: active_session.access_token_id
|
||||
)
|
||||
|
||||
active_session.update!(web_push_subscription: web_subscription)
|
||||
active_session.update!(web_push_subscription: push_subscription)
|
||||
|
||||
render json: web_subscription, serializer: REST::WebPushSubscriptionSerializer
|
||||
render json: push_subscription, serializer: REST::WebPushSubscriptionSerializer
|
||||
end
|
||||
|
||||
def update
|
||||
params.require([:id])
|
||||
|
||||
web_subscription = ::Web::PushSubscription.find(params[:id])
|
||||
web_subscription.update!(data: data_params)
|
||||
|
||||
render json: web_subscription, serializer: REST::WebPushSubscriptionSerializer
|
||||
@push_subscription.update!(data: data_params)
|
||||
render json: @push_subscription, serializer: REST::WebPushSubscriptionSerializer
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def set_push_subscription
|
||||
@push_subscription = ::Web::PushSubscription.find(params[:id])
|
||||
end
|
||||
|
||||
def subscription_params
|
||||
@subscription_params ||= params.require(:subscription).permit(:endpoint, keys: [:auth, :p256dh])
|
||||
end
|
||||
|
||||
def data_params
|
||||
@data_params ||= params.require(:data).permit(alerts: [:follow, :follow_request, :favourite, :reblog, :mention, :poll, :status])
|
||||
@data_params ||= params.require(:data).permit(:policy, alerts: [:follow, :follow_request, :favourite, :reblog, :mention, :poll, :status])
|
||||
end
|
||||
end
|
||||
|
@@ -91,8 +91,6 @@ module ApplicationHelper
|
||||
fa_icon('unlock', title: I18n.t('statuses.visibilities.unlisted'))
|
||||
elsif status.private_visibility? || status.limited_visibility?
|
||||
fa_icon('lock', title: I18n.t('statuses.visibilities.private'))
|
||||
elsif status.direct_visibility?
|
||||
fa_icon('envelope', title: I18n.t('statuses.visibilities.direct'))
|
||||
end
|
||||
end
|
||||
|
||||
|
18
app/helpers/email_helper.rb
Normal file
18
app/helpers/email_helper.rb
Normal file
@@ -0,0 +1,18 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
module EmailHelper
|
||||
def self.included(base)
|
||||
base.extend(self)
|
||||
end
|
||||
|
||||
def email_to_canonical_email(str)
|
||||
username, domain = str.downcase.split('@', 2)
|
||||
username, = username.gsub('.', '').split('+', 2)
|
||||
|
||||
"#{username}@#{domain}"
|
||||
end
|
||||
|
||||
def email_to_canonical_email_hash(str)
|
||||
Digest::SHA2.new(256).hexdigest(email_to_canonical_email(str))
|
||||
end
|
||||
end
|
@@ -24,6 +24,7 @@ export function normalizeAccount(account) {
|
||||
|
||||
account.display_name_html = emojify(escapeTextContentForBrowser(displayName), emojiMap);
|
||||
account.note_emojified = emojify(account.note, emojiMap);
|
||||
account.note_plain = unescapeHTML(account.note);
|
||||
|
||||
if (account.fields) {
|
||||
account.fields = account.fields.map(pair => ({
|
||||
|
@@ -1,21 +1,8 @@
|
||||
import { changeSetting, saveSettings } from './settings';
|
||||
import { requestBrowserPermission } from './notifications';
|
||||
|
||||
export const INTRODUCTION_VERSION = 20181216044202;
|
||||
|
||||
export const closeOnboarding = () => dispatch => {
|
||||
dispatch(changeSetting(['introductionVersion'], INTRODUCTION_VERSION));
|
||||
dispatch(saveSettings());
|
||||
|
||||
dispatch(requestBrowserPermission((permission) => {
|
||||
if (permission === 'granted') {
|
||||
dispatch(changeSetting(['notifications', 'alerts', 'follow'], true));
|
||||
dispatch(changeSetting(['notifications', 'alerts', 'favourite'], true));
|
||||
dispatch(changeSetting(['notifications', 'alerts', 'reblog'], true));
|
||||
dispatch(changeSetting(['notifications', 'alerts', 'mention'], true));
|
||||
dispatch(changeSetting(['notifications', 'alerts', 'poll'], true));
|
||||
dispatch(changeSetting(['notifications', 'alerts', 'status'], true));
|
||||
dispatch(saveSettings());
|
||||
}
|
||||
}));
|
||||
};
|
||||
|
@@ -1,5 +1,6 @@
|
||||
import api from '../api';
|
||||
import { importFetchedAccounts } from './importer';
|
||||
import { fetchRelationships } from './accounts';
|
||||
|
||||
export const SUGGESTIONS_FETCH_REQUEST = 'SUGGESTIONS_FETCH_REQUEST';
|
||||
export const SUGGESTIONS_FETCH_SUCCESS = 'SUGGESTIONS_FETCH_SUCCESS';
|
||||
@@ -7,13 +8,17 @@ export const SUGGESTIONS_FETCH_FAIL = 'SUGGESTIONS_FETCH_FAIL';
|
||||
|
||||
export const SUGGESTIONS_DISMISS = 'SUGGESTIONS_DISMISS';
|
||||
|
||||
export function fetchSuggestions() {
|
||||
export function fetchSuggestions(withRelationships = false) {
|
||||
return (dispatch, getState) => {
|
||||
dispatch(fetchSuggestionsRequest());
|
||||
|
||||
api(getState).get('/api/v1/suggestions').then(response => {
|
||||
dispatch(importFetchedAccounts(response.data));
|
||||
api(getState).get('/api/v2/suggestions').then(response => {
|
||||
dispatch(importFetchedAccounts(response.data.map(x => x.account)));
|
||||
dispatch(fetchSuggestionsSuccess(response.data));
|
||||
|
||||
if (withRelationships) {
|
||||
dispatch(fetchRelationships(response.data.map(item => item.account.id)));
|
||||
}
|
||||
}).catch(error => dispatch(fetchSuggestionsFail(error)));
|
||||
};
|
||||
};
|
||||
@@ -25,10 +30,10 @@ export function fetchSuggestionsRequest() {
|
||||
};
|
||||
};
|
||||
|
||||
export function fetchSuggestionsSuccess(accounts) {
|
||||
export function fetchSuggestionsSuccess(suggestions) {
|
||||
return {
|
||||
type: SUGGESTIONS_FETCH_SUCCESS,
|
||||
accounts,
|
||||
suggestions,
|
||||
skipLoading: true,
|
||||
};
|
||||
};
|
||||
@@ -48,5 +53,12 @@ export const dismissSuggestion = accountId => (dispatch, getState) => {
|
||||
id: accountId,
|
||||
});
|
||||
|
||||
api(getState).delete(`/api/v1/suggestions/${accountId}`);
|
||||
api(getState).delete(`/api/v1/suggestions/${accountId}`).then(() => {
|
||||
dispatch(fetchSuggestionsRequest());
|
||||
|
||||
api(getState).get('/api/v2/suggestions').then(response => {
|
||||
dispatch(importFetchedAccounts(response.data.map(x => x.account)));
|
||||
dispatch(fetchSuggestionsSuccess(response.data));
|
||||
}).catch(error => dispatch(fetchSuggestionsFail(error)));
|
||||
}).catch(() => {});
|
||||
};
|
||||
|
@@ -78,8 +78,10 @@ class Account extends ImmutablePureComponent {
|
||||
|
||||
let buttons;
|
||||
|
||||
if (onActionClick && actionIcon) {
|
||||
buttons = <IconButton icon={actionIcon} title={actionTitle} onClick={this.handleAction} />;
|
||||
if (actionIcon) {
|
||||
if (onActionClick) {
|
||||
buttons = <IconButton icon={actionIcon} title={actionTitle} onClick={this.handleAction} />;
|
||||
}
|
||||
} else if (account.get('id') !== me && account.get('relationship', null) !== null) {
|
||||
const following = account.getIn(['relationship', 'following']);
|
||||
const requested = account.getIn(['relationship', 'requested']);
|
||||
|
9
app/javascript/mastodon/components/logo.js
Normal file
9
app/javascript/mastodon/components/logo.js
Normal file
@@ -0,0 +1,9 @@
|
||||
import React from 'react';
|
||||
|
||||
const Logo = () => (
|
||||
<svg viewBox='0 0 216.4144 232.00976' className='logo'>
|
||||
<use xlinkHref='#mastodon-svg-logo' />
|
||||
</svg>
|
||||
);
|
||||
|
||||
export default Logo;
|
@@ -1,12 +1,10 @@
|
||||
import React from 'react';
|
||||
import { Provider, connect } from 'react-redux';
|
||||
import { Provider } from 'react-redux';
|
||||
import PropTypes from 'prop-types';
|
||||
import configureStore from '../store/configureStore';
|
||||
import { INTRODUCTION_VERSION } from '../actions/onboarding';
|
||||
import { BrowserRouter, Route } from 'react-router-dom';
|
||||
import { ScrollContext } from 'react-router-scroll-4';
|
||||
import UI from '../features/ui';
|
||||
import Introduction from '../features/introduction';
|
||||
import { fetchCustomEmojis } from '../actions/custom_emojis';
|
||||
import { hydrateStore } from '../actions/store';
|
||||
import { connectUserStream } from '../actions/streaming';
|
||||
@@ -26,39 +24,6 @@ const hydrateAction = hydrateStore(initialState);
|
||||
store.dispatch(hydrateAction);
|
||||
store.dispatch(fetchCustomEmojis());
|
||||
|
||||
const mapStateToProps = state => ({
|
||||
showIntroduction: state.getIn(['settings', 'introductionVersion'], 0) < INTRODUCTION_VERSION,
|
||||
});
|
||||
|
||||
@connect(mapStateToProps)
|
||||
class MastodonMount extends React.PureComponent {
|
||||
|
||||
static propTypes = {
|
||||
showIntroduction: PropTypes.bool,
|
||||
};
|
||||
|
||||
shouldUpdateScroll (_, { location }) {
|
||||
return location.state !== previewMediaState && location.state !== previewVideoState;
|
||||
}
|
||||
|
||||
render () {
|
||||
const { showIntroduction } = this.props;
|
||||
|
||||
if (showIntroduction) {
|
||||
return <Introduction />;
|
||||
}
|
||||
|
||||
return (
|
||||
<BrowserRouter basename='/web'>
|
||||
<ScrollContext shouldUpdateScroll={this.shouldUpdateScroll}>
|
||||
<Route path='/' component={UI} />
|
||||
</ScrollContext>
|
||||
</BrowserRouter>
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export default class Mastodon extends React.PureComponent {
|
||||
|
||||
static propTypes = {
|
||||
@@ -76,6 +41,10 @@ export default class Mastodon extends React.PureComponent {
|
||||
}
|
||||
}
|
||||
|
||||
shouldUpdateScroll (_, { location }) {
|
||||
return location.state !== previewMediaState && location.state !== previewVideoState;
|
||||
}
|
||||
|
||||
render () {
|
||||
const { locale } = this.props;
|
||||
|
||||
@@ -83,7 +52,11 @@ export default class Mastodon extends React.PureComponent {
|
||||
<IntlProvider locale={locale} messages={messages}>
|
||||
<Provider store={store}>
|
||||
<ErrorBoundary>
|
||||
<MastodonMount />
|
||||
<BrowserRouter basename='/web'>
|
||||
<ScrollContext shouldUpdateScroll={this.shouldUpdateScroll}>
|
||||
<Route path='/' component={UI} />
|
||||
</ScrollContext>
|
||||
</BrowserRouter>
|
||||
</ErrorBoundary>
|
||||
</Provider>
|
||||
</IntlProvider>
|
||||
|
@@ -51,12 +51,12 @@ class SearchResults extends ImmutablePureComponent {
|
||||
<FormattedMessage id='suggestions.header' defaultMessage='You might be interested in…' />
|
||||
</div>
|
||||
|
||||
{suggestions && suggestions.map(accountId => (
|
||||
{suggestions && suggestions.map(suggestion => (
|
||||
<AccountContainer
|
||||
key={accountId}
|
||||
id={accountId}
|
||||
actionIcon='times'
|
||||
actionTitle={intl.formatMessage(messages.dismissSuggestion)}
|
||||
key={suggestion.get('account')}
|
||||
id={suggestion.get('account')}
|
||||
actionIcon={suggestion.get('source') === 'past_interaction' ? 'times' : null}
|
||||
actionTitle={suggestion.get('source') === 'past_interaction' ? intl.formatMessage(messages.dismissSuggestion) : null}
|
||||
onActionClick={dismissSuggestion}
|
||||
/>
|
||||
))}
|
||||
|
@@ -11,7 +11,7 @@ const emojiFilenames = (emojis) => {
|
||||
};
|
||||
|
||||
// Emoji requiring extra borders depending on theme
|
||||
const darkEmoji = emojiFilenames(['🎱', '🐜', '⚫', '🖤', '⬛', '◼️', '◾', '◼️', '✒️', '▪️', '💣', '🎳', '📷', '📸', '♣️', '🕶️', '✴️', '🔌', '💂♀️', '📽️', '🍳', '🦍', '💂', '🔪', '🕳️', '🕹️', '🕋', '🖊️', '🖋️', '💂♂️', '🎤', '🎓', '🎥', '🎼', '♠️', '🎩', '🦃', '📼', '📹', '🎮', '🐃', '🏴', '🐞', '🕺', '📱', '📲']);
|
||||
const darkEmoji = emojiFilenames(['🎱', '🐜', '⚫', '🖤', '⬛', '◼️', '◾', '◼️', '✒️', '▪️', '💣', '🎳', '📷', '📸', '♣️', '🕶️', '✴️', '🔌', '💂♀️', '📽️', '🍳', '🦍', '💂', '🔪', '🕳️', '🕹️', '🕋', '🖊️', '🖋️', '💂♂️', '🎤', '🎓', '🎥', '🎼', '♠️', '🎩', '🦃', '📼', '📹', '🎮', '🐃', '🏴', '🐞', '🕺', '📱', '📲', '🚲']);
|
||||
const lightEmoji = emojiFilenames(['👽', '⚾', '🐔', '☁️', '💨', '🕊️', '👀', '🍥', '👻', '🐐', '❕', '❔', '⛸️', '🌩️', '🔊', '🔇', '📃', '🌧️', '🐏', '🍚', '🍙', '🐓', '🐑', '💀', '☠️', '🌨️', '🔉', '🔈', '💬', '💭', '🏐', '🏳️', '⚪', '⬜', '◽', '◻️', '▫️']);
|
||||
|
||||
const emojiFilename = (filename) => {
|
||||
|
@@ -0,0 +1,85 @@
|
||||
import React from 'react';
|
||||
import PropTypes from 'prop-types';
|
||||
import ImmutablePropTypes from 'react-immutable-proptypes';
|
||||
import ImmutablePureComponent from 'react-immutable-pure-component';
|
||||
import { connect } from 'react-redux';
|
||||
import { makeGetAccount } from 'mastodon/selectors';
|
||||
import Avatar from 'mastodon/components/avatar';
|
||||
import DisplayName from 'mastodon/components/display_name';
|
||||
import Permalink from 'mastodon/components/permalink';
|
||||
import IconButton from 'mastodon/components/icon_button';
|
||||
import { injectIntl, defineMessages } from 'react-intl';
|
||||
import { followAccount, unfollowAccount } from 'mastodon/actions/accounts';
|
||||
|
||||
const messages = defineMessages({
|
||||
follow: { id: 'account.follow', defaultMessage: 'Follow' },
|
||||
unfollow: { id: 'account.unfollow', defaultMessage: 'Unfollow' },
|
||||
});
|
||||
|
||||
const makeMapStateToProps = () => {
|
||||
const getAccount = makeGetAccount();
|
||||
|
||||
const mapStateToProps = (state, props) => ({
|
||||
account: getAccount(state, props.id),
|
||||
});
|
||||
|
||||
return mapStateToProps;
|
||||
};
|
||||
|
||||
const getFirstSentence = str => {
|
||||
const arr = str.split(/(([\.\?!]+\s)|[.。?!\n•])/);
|
||||
|
||||
return arr[0];
|
||||
};
|
||||
|
||||
export default @connect(makeMapStateToProps)
|
||||
@injectIntl
|
||||
class Account extends ImmutablePureComponent {
|
||||
|
||||
static propTypes = {
|
||||
account: ImmutablePropTypes.map.isRequired,
|
||||
intl: PropTypes.object.isRequired,
|
||||
dispatch: PropTypes.func.isRequired,
|
||||
};
|
||||
|
||||
handleFollow = () => {
|
||||
const { account, dispatch } = this.props;
|
||||
|
||||
if (account.getIn(['relationship', 'following']) || account.getIn(['relationship', 'requested'])) {
|
||||
dispatch(unfollowAccount(account.get('id')));
|
||||
} else {
|
||||
dispatch(followAccount(account.get('id')));
|
||||
}
|
||||
}
|
||||
|
||||
render () {
|
||||
const { account, intl } = this.props;
|
||||
|
||||
let button;
|
||||
|
||||
if (account.getIn(['relationship', 'following'])) {
|
||||
button = <IconButton icon='check' title={intl.formatMessage(messages.unfollow)} active onClick={this.handleFollow} />;
|
||||
} else {
|
||||
button = <IconButton icon='plus' title={intl.formatMessage(messages.follow)} onClick={this.handleFollow} />;
|
||||
}
|
||||
|
||||
return (
|
||||
<div className='account follow-recommendations-account'>
|
||||
<div className='account__wrapper'>
|
||||
<Permalink className='account__display-name account__display-name--with-note' title={account.get('acct')} href={account.get('url')} to={`/accounts/${account.get('id')}`}>
|
||||
<div className='account__avatar-wrapper'><Avatar account={account} size={36} /></div>
|
||||
|
||||
<DisplayName account={account} />
|
||||
|
||||
<div className='account__note'>{getFirstSentence(account.get('note_plain'))}</div>
|
||||
</Permalink>
|
||||
|
||||
<div className='account__relationship'>
|
||||
{button}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,95 @@
|
||||
import React from 'react';
|
||||
import PropTypes from 'prop-types';
|
||||
import ImmutablePureComponent from 'react-immutable-pure-component';
|
||||
import ImmutablePropTypes from 'react-immutable-proptypes';
|
||||
import { connect } from 'react-redux';
|
||||
import { FormattedMessage } from 'react-intl';
|
||||
import { fetchSuggestions } from 'mastodon/actions/suggestions';
|
||||
import { changeSetting, saveSettings } from 'mastodon/actions/settings';
|
||||
import { requestBrowserPermission } from 'mastodon/actions/notifications';
|
||||
import Column from 'mastodon/features/ui/components/column';
|
||||
import Account from './components/account';
|
||||
import Logo from 'mastodon/components/logo';
|
||||
import imageGreeting from 'mastodon/../images/elephant_ui_greeting.svg';
|
||||
import Button from 'mastodon/components/button';
|
||||
|
||||
const mapStateToProps = state => ({
|
||||
suggestions: state.getIn(['suggestions', 'items']),
|
||||
isLoading: state.getIn(['suggestions', 'isLoading']),
|
||||
});
|
||||
|
||||
export default @connect(mapStateToProps)
|
||||
class FollowRecommendations extends ImmutablePureComponent {
|
||||
|
||||
static contextTypes = {
|
||||
router: PropTypes.object.isRequired,
|
||||
};
|
||||
|
||||
static propTypes = {
|
||||
dispatch: PropTypes.func.isRequired,
|
||||
suggestions: ImmutablePropTypes.list,
|
||||
isLoading: PropTypes.bool,
|
||||
};
|
||||
|
||||
componentDidMount () {
|
||||
const { dispatch, suggestions } = this.props;
|
||||
|
||||
// Don't re-fetch if we're e.g. navigating backwards to this page,
|
||||
// since we don't want followed accounts to disappear from the list
|
||||
|
||||
if (suggestions.size === 0) {
|
||||
dispatch(fetchSuggestions(true));
|
||||
}
|
||||
}
|
||||
|
||||
handleDone = () => {
|
||||
const { dispatch } = this.props;
|
||||
const { router } = this.context;
|
||||
|
||||
dispatch(requestBrowserPermission((permission) => {
|
||||
if (permission === 'granted') {
|
||||
dispatch(changeSetting(['notifications', 'alerts', 'follow'], true));
|
||||
dispatch(changeSetting(['notifications', 'alerts', 'favourite'], true));
|
||||
dispatch(changeSetting(['notifications', 'alerts', 'reblog'], true));
|
||||
dispatch(changeSetting(['notifications', 'alerts', 'mention'], true));
|
||||
dispatch(changeSetting(['notifications', 'alerts', 'poll'], true));
|
||||
dispatch(changeSetting(['notifications', 'alerts', 'status'], true));
|
||||
dispatch(saveSettings());
|
||||
}
|
||||
}));
|
||||
|
||||
router.history.push('/timelines/home');
|
||||
}
|
||||
|
||||
render () {
|
||||
const { suggestions, isLoading } = this.props;
|
||||
|
||||
return (
|
||||
<Column>
|
||||
<div className='scrollable'>
|
||||
<div className='column-title'>
|
||||
<Logo />
|
||||
<h3><FormattedMessage id='follow_recommendations.heading' defaultMessage="Follow people you'd like to see posts from! Here are some suggestions." /></h3>
|
||||
<p><FormattedMessage id='follow_recommendations.lead' defaultMessage="Posts from people you follow will show up in chronological order on your home feed. Don't be afraid to make mistakes, you can unfollow people just as easily any time!" /></p>
|
||||
</div>
|
||||
|
||||
{!isLoading && (
|
||||
<React.Fragment>
|
||||
<div>
|
||||
{suggestions.map(suggestion => (
|
||||
<Account key={suggestion.get('account')} id={suggestion.get('account')} />
|
||||
))}
|
||||
</div>
|
||||
|
||||
<div className='column-actions'>
|
||||
<img src={imageGreeting} alt='' className='column-actions__background' />
|
||||
<Button onClick={this.handleDone}><FormattedMessage id='follow_recommendations.done' defaultMessage='Done' /></Button>
|
||||
</div>
|
||||
</React.Fragment>
|
||||
)}
|
||||
</div>
|
||||
</Column>
|
||||
);
|
||||
}
|
||||
|
||||
}
|
@@ -51,10 +51,12 @@ import {
|
||||
Lists,
|
||||
Search,
|
||||
Directory,
|
||||
FollowRecommendations,
|
||||
} from './util/async-components';
|
||||
import { me } from '../../initial_state';
|
||||
import { previewState as previewMediaState } from './components/media_modal';
|
||||
import { previewState as previewVideoState } from './components/video_modal';
|
||||
import { closeOnboarding, INTRODUCTION_VERSION } from 'mastodon/actions/onboarding';
|
||||
|
||||
// Dummy import, to make sure that <Status /> ends up in the application bundle.
|
||||
// Without this it ends up in ~8 very commonly used bundles.
|
||||
@@ -71,6 +73,7 @@ const mapStateToProps = state => ({
|
||||
hasMediaAttachments: state.getIn(['compose', 'media_attachments']).size > 0,
|
||||
canUploadMore: !state.getIn(['compose', 'media_attachments']).some(x => ['audio', 'video'].includes(x.get('type'))) && state.getIn(['compose', 'media_attachments']).size < 4,
|
||||
dropdownMenuIsOpen: state.getIn(['dropdown_menu', 'openId']) !== null,
|
||||
firstLaunch: state.getIn(['settings', 'introductionVersion'], 0) < INTRODUCTION_VERSION,
|
||||
});
|
||||
|
||||
const keyMap = {
|
||||
@@ -167,6 +170,7 @@ class SwitchingColumnsArea extends React.PureComponent {
|
||||
<WrappedRoute path='/bookmarks' component={BookmarkedStatuses} content={children} />
|
||||
<WrappedRoute path='/pinned' component={PinnedStatuses} content={children} componentParams={{ shouldUpdateScroll: this.shouldUpdateScroll }} />
|
||||
|
||||
<WrappedRoute path='/start' component={FollowRecommendations} content={children} />
|
||||
<WrappedRoute path='/search' component={Search} content={children} />
|
||||
<WrappedRoute path='/directory' component={Directory} content={children} componentParams={{ shouldUpdateScroll: this.shouldUpdateScroll }} />
|
||||
|
||||
@@ -215,6 +219,7 @@ class UI extends React.PureComponent {
|
||||
intl: PropTypes.object.isRequired,
|
||||
dropdownMenuIsOpen: PropTypes.bool,
|
||||
layout: PropTypes.string.isRequired,
|
||||
firstLaunch: PropTypes.bool,
|
||||
};
|
||||
|
||||
state = {
|
||||
@@ -350,6 +355,12 @@ class UI extends React.PureComponent {
|
||||
navigator.serviceWorker.addEventListener('message', this.handleServiceWorkerPostMessage);
|
||||
}
|
||||
|
||||
// On first launch, redirect to the follow recommendations page
|
||||
if (this.props.firstLaunch) {
|
||||
this.context.router.history.replace('/start');
|
||||
this.props.dispatch(closeOnboarding());
|
||||
}
|
||||
|
||||
this.props.dispatch(fetchMarkers());
|
||||
this.props.dispatch(expandHomeTimeline());
|
||||
this.props.dispatch(expandNotifications());
|
||||
|
@@ -153,3 +153,7 @@ export function Audio () {
|
||||
export function Directory () {
|
||||
return import(/* webpackChunkName: "features/directory" */'../../directory');
|
||||
}
|
||||
|
||||
export function FollowRecommendations () {
|
||||
return import(/* webpackChunkName: "features/follow_recommendations" */'../../follow_recommendations');
|
||||
}
|
||||
|
@@ -19,18 +19,18 @@ export default function suggestionsReducer(state = initialState, action) {
|
||||
return state.set('isLoading', true);
|
||||
case SUGGESTIONS_FETCH_SUCCESS:
|
||||
return state.withMutations(map => {
|
||||
map.set('items', fromJS(action.accounts.map(x => x.id)));
|
||||
map.set('items', fromJS(action.suggestions.map(x => ({ ...x, account: x.account.id }))));
|
||||
map.set('isLoading', false);
|
||||
});
|
||||
case SUGGESTIONS_FETCH_FAIL:
|
||||
return state.set('isLoading', false);
|
||||
case SUGGESTIONS_DISMISS:
|
||||
return state.update('items', list => list.filterNot(id => id === action.id));
|
||||
return state.update('items', list => list.filterNot(x => x.account === action.id));
|
||||
case ACCOUNT_BLOCK_SUCCESS:
|
||||
case ACCOUNT_MUTE_SUCCESS:
|
||||
return state.update('items', list => list.filterNot(id => id === action.relationship.id));
|
||||
return state.update('items', list => list.filterNot(x => x.account === action.relationship.id));
|
||||
case DOMAIN_BLOCK_SUCCESS:
|
||||
return state.update('items', list => list.filterNot(id => action.accounts.includes(id)));
|
||||
return state.update('items', list => list.filterNot(x => action.accounts.includes(x.account)));
|
||||
default:
|
||||
return state;
|
||||
}
|
||||
|
@@ -1307,6 +1307,29 @@
|
||||
overflow: hidden;
|
||||
text-decoration: none;
|
||||
font-size: 14px;
|
||||
|
||||
&--with-note {
|
||||
strong {
|
||||
display: inline;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
&__note {
|
||||
white-space: nowrap;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
color: $ui-secondary-color;
|
||||
}
|
||||
}
|
||||
|
||||
.follow-recommendations-account {
|
||||
.icon-button {
|
||||
color: $ui-primary-color;
|
||||
|
||||
&.active {
|
||||
color: $valid-value-color;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2459,6 +2482,49 @@ a.account__display-name {
|
||||
border-color: darken($ui-base-color, 8%);
|
||||
}
|
||||
|
||||
.column-title {
|
||||
text-align: center;
|
||||
padding: 40px;
|
||||
|
||||
.logo {
|
||||
fill: $primary-text-color;
|
||||
width: 50px;
|
||||
margin: 0 auto;
|
||||
margin-bottom: 40px;
|
||||
}
|
||||
|
||||
h3 {
|
||||
font-size: 24px;
|
||||
line-height: 1.5;
|
||||
font-weight: 700;
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
|
||||
p {
|
||||
font-size: 16px;
|
||||
line-height: 24px;
|
||||
font-weight: 400;
|
||||
color: $darker-text-color;
|
||||
}
|
||||
}
|
||||
|
||||
.column-actions {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
padding: 40px;
|
||||
padding-top: 40px;
|
||||
padding-bottom: 200px;
|
||||
|
||||
&__background {
|
||||
position: absolute;
|
||||
left: 0;
|
||||
bottom: 0;
|
||||
height: 220px;
|
||||
width: auto;
|
||||
}
|
||||
}
|
||||
|
||||
.compose-panel {
|
||||
width: 285px;
|
||||
margin-top: 10px;
|
||||
|
25
app/lib/account_reach_finder.rb
Normal file
25
app/lib/account_reach_finder.rb
Normal file
@@ -0,0 +1,25 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class AccountReachFinder
|
||||
def initialize(account)
|
||||
@account = account
|
||||
end
|
||||
|
||||
def inboxes
|
||||
(followers_inboxes + reporters_inboxes + relay_inboxes).uniq
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def followers_inboxes
|
||||
@account.followers.inboxes
|
||||
end
|
||||
|
||||
def reporters_inboxes
|
||||
Account.where(id: @account.targeted_reports.select(:account_id)).inboxes
|
||||
end
|
||||
|
||||
def relay_inboxes
|
||||
Relay.enabled.pluck(:inbox_url)
|
||||
end
|
||||
end
|
@@ -88,7 +88,6 @@ class ActivityPub::Activity::Create < ActivityPub::Activity
|
||||
|
||||
resolve_thread(@status)
|
||||
fetch_replies(@status)
|
||||
check_for_spam
|
||||
distribute(@status)
|
||||
forward_for_reply
|
||||
end
|
||||
@@ -498,10 +497,6 @@ class ActivityPub::Activity::Create < ActivityPub::Activity
|
||||
Tombstone.exists?(uri: object_uri)
|
||||
end
|
||||
|
||||
def check_for_spam
|
||||
SpamCheck.perform(@status)
|
||||
end
|
||||
|
||||
def forward_for_reply
|
||||
return unless @status.distributable? && @json['signature'].present? && reply_to_local?
|
||||
|
||||
|
@@ -10,6 +10,8 @@ class ActivityPub::Activity::Flag < ActivityPub::Activity
|
||||
target_accounts.each do |target_account|
|
||||
target_statuses = target_statuses_by_account[target_account.id]
|
||||
|
||||
next if target_account.suspended?
|
||||
|
||||
ReportService.new.call(
|
||||
@account,
|
||||
target_account,
|
||||
|
@@ -7,7 +7,6 @@ class Admin::SystemCheck::SidekiqProcessCheck < Admin::SystemCheck::BaseCheck
|
||||
mailers
|
||||
pull
|
||||
scheduler
|
||||
ingress
|
||||
).freeze
|
||||
|
||||
def pass?
|
||||
|
@@ -4,6 +4,8 @@ module ApplicationExtension
|
||||
extend ActiveSupport::Concern
|
||||
|
||||
included do
|
||||
validates :website, url: true, if: :website?
|
||||
validates :name, length: { maximum: 60 }
|
||||
validates :website, url: true, length: { maximum: 2_000 }, if: :website?
|
||||
validates :redirect_uri, length: { maximum: 2_000 }
|
||||
end
|
||||
end
|
||||
|
@@ -118,7 +118,7 @@ class Formatter
|
||||
end
|
||||
|
||||
def format_field(account, str, **options)
|
||||
html = account.local? ? encode_and_link_urls(str, me: true) : reformat(str)
|
||||
html = account.local? ? encode_and_link_urls(str, me: true, with_domain: true) : reformat(str)
|
||||
html = encode_custom_emojis(html, account.emojis, options[:autoplay]) if options[:custom_emojify]
|
||||
html.html_safe # rubocop:disable Rails/OutputSafety
|
||||
end
|
||||
@@ -187,7 +187,7 @@ class Formatter
|
||||
elsif entity[:hashtag]
|
||||
link_to_hashtag(entity)
|
||||
elsif entity[:screen_name]
|
||||
link_to_mention(entity, accounts)
|
||||
link_to_mention(entity, accounts, options)
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -352,22 +352,37 @@ class Formatter
|
||||
encode(entity[:url])
|
||||
end
|
||||
|
||||
def link_to_mention(entity, linkable_accounts)
|
||||
def link_to_mention(entity, linkable_accounts, options = {})
|
||||
acct = entity[:screen_name]
|
||||
|
||||
return link_to_account(acct) unless linkable_accounts
|
||||
return link_to_account(acct, options) unless linkable_accounts
|
||||
|
||||
account = linkable_accounts.find { |item| TagManager.instance.same_acct?(item.acct, acct) }
|
||||
account ? mention_html(account) : "@#{encode(acct)}"
|
||||
same_username_hits = 0
|
||||
account = nil
|
||||
username, domain = acct.split('@')
|
||||
domain = nil if TagManager.instance.local_domain?(domain)
|
||||
|
||||
linkable_accounts.each do |item|
|
||||
same_username = item.username.casecmp(username).zero?
|
||||
same_domain = item.domain.nil? ? domain.nil? : item.domain.casecmp(domain)&.zero?
|
||||
|
||||
if same_username && !same_domain
|
||||
same_username_hits += 1
|
||||
elsif same_username && same_domain
|
||||
account = item
|
||||
end
|
||||
end
|
||||
|
||||
account ? mention_html(account, with_domain: same_username_hits.positive? || options[:with_domain]) : "@#{encode(acct)}"
|
||||
end
|
||||
|
||||
def link_to_account(acct)
|
||||
def link_to_account(acct, options = {})
|
||||
username, domain = acct.split('@')
|
||||
|
||||
domain = nil if TagManager.instance.local_domain?(domain)
|
||||
account = EntityCache.instance.mention(username, domain)
|
||||
|
||||
account ? mention_html(account) : "@#{encode(acct)}"
|
||||
account ? mention_html(account, with_domain: options[:with_domain]) : "@#{encode(acct)}"
|
||||
end
|
||||
|
||||
def link_to_hashtag(entity)
|
||||
@@ -388,7 +403,7 @@ class Formatter
|
||||
"<a href=\"#{encode(tag_url(tag))}\" class=\"mention hashtag\" rel=\"tag\">#<span>#{encode(tag)}</span></a>"
|
||||
end
|
||||
|
||||
def mention_html(account)
|
||||
"<span class=\"h-card\"><a href=\"#{encode(ActivityPub::TagManager.instance.url_for(account))}\" class=\"u-url mention\">@<span>#{encode(account.username)}</span></a></span>"
|
||||
def mention_html(account, with_domain: false)
|
||||
"<span class=\"h-card\"><a href=\"#{encode(ActivityPub::TagManager.instance.url_for(account))}\" class=\"u-url mention\">@<span>#{encode(with_domain ? account.pretty_acct : account.username)}</span></a></span>"
|
||||
end
|
||||
end
|
||||
|
@@ -28,10 +28,14 @@ class PotentialFriendshipTracker
|
||||
redis.zrem("interactions:#{account_id}", target_account_id)
|
||||
end
|
||||
|
||||
def get(account_id, limit: 20, offset: 0)
|
||||
account_ids = redis.zrevrange("interactions:#{account_id}", offset, limit)
|
||||
return [] if account_ids.empty?
|
||||
Account.searchable.where(id: account_ids)
|
||||
def get(account, limit)
|
||||
account_ids = redis.zrevrange("interactions:#{account.id}", 0, limit)
|
||||
|
||||
return [] if account_ids.empty? || limit < 1
|
||||
|
||||
accounts = Account.searchable.where(id: account_ids).index_by(&:id)
|
||||
|
||||
account_ids.map { |id| accounts[id.to_i] }.compact
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@@ -1,198 +0,0 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class SpamCheck
|
||||
include Redisable
|
||||
include ActionView::Helpers::TextHelper
|
||||
|
||||
# Threshold over which two Nilsimsa values are considered
|
||||
# to refer to the same text
|
||||
NILSIMSA_COMPARE_THRESHOLD = 95
|
||||
|
||||
# Nilsimsa doesn't work well on small inputs, so below
|
||||
# this size, we check only for exact matches with MD5
|
||||
NILSIMSA_MIN_SIZE = 10
|
||||
|
||||
# How long to keep the trail of digests between updates,
|
||||
# there is no reason to store it forever
|
||||
EXPIRE_SET_AFTER = 1.week.seconds
|
||||
|
||||
# How many digests to keep in an account's trail. If it's
|
||||
# too small, spam could rotate around different message templates
|
||||
MAX_TRAIL_SIZE = 10
|
||||
|
||||
# How many detected duplicates to allow through before
|
||||
# considering the message as spam
|
||||
THRESHOLD = 5
|
||||
|
||||
def initialize(status)
|
||||
@account = status.account
|
||||
@status = status
|
||||
end
|
||||
|
||||
def skip?
|
||||
disabled? || already_flagged? || trusted? || no_unsolicited_mentions? || solicited_reply?
|
||||
end
|
||||
|
||||
def spam?
|
||||
if insufficient_data?
|
||||
false
|
||||
elsif nilsimsa?
|
||||
digests_over_threshold?('nilsimsa') { |_, other_digest| nilsimsa_compare_value(digest, other_digest) >= NILSIMSA_COMPARE_THRESHOLD }
|
||||
else
|
||||
digests_over_threshold?('md5') { |_, other_digest| other_digest == digest }
|
||||
end
|
||||
end
|
||||
|
||||
def flag!
|
||||
auto_report_status!
|
||||
end
|
||||
|
||||
def remember!
|
||||
# The scores in sorted sets don't actually have enough bits to hold an exact
|
||||
# value of our snowflake IDs, so we use it only for its ordering property. To
|
||||
# get the correct status ID back, we have to save it in the string value
|
||||
|
||||
redis.zadd(redis_key, @status.id, digest_with_algorithm)
|
||||
redis.zremrangebyrank(redis_key, 0, -(MAX_TRAIL_SIZE + 1))
|
||||
redis.expire(redis_key, EXPIRE_SET_AFTER)
|
||||
end
|
||||
|
||||
def reset!
|
||||
redis.del(redis_key)
|
||||
end
|
||||
|
||||
def hashable_text
|
||||
return @hashable_text if defined?(@hashable_text)
|
||||
|
||||
@hashable_text = @status.text
|
||||
@hashable_text = remove_mentions(@hashable_text)
|
||||
@hashable_text = strip_tags(@hashable_text) unless @status.local?
|
||||
@hashable_text = normalize_unicode(@status.spoiler_text + ' ' + @hashable_text)
|
||||
@hashable_text = remove_whitespace(@hashable_text)
|
||||
end
|
||||
|
||||
def insufficient_data?
|
||||
hashable_text.blank?
|
||||
end
|
||||
|
||||
def digest
|
||||
@digest ||= begin
|
||||
if nilsimsa?
|
||||
Nilsimsa.new(hashable_text).hexdigest
|
||||
else
|
||||
Digest::MD5.hexdigest(hashable_text)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def digest_with_algorithm
|
||||
if nilsimsa?
|
||||
['nilsimsa', digest, @status.id].join(':')
|
||||
else
|
||||
['md5', digest, @status.id].join(':')
|
||||
end
|
||||
end
|
||||
|
||||
class << self
|
||||
def perform(status)
|
||||
spam_check = new(status)
|
||||
|
||||
return if spam_check.skip?
|
||||
|
||||
if spam_check.spam?
|
||||
spam_check.flag!
|
||||
else
|
||||
spam_check.remember!
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def disabled?
|
||||
!Setting.spam_check_enabled
|
||||
end
|
||||
|
||||
def remove_mentions(text)
|
||||
return text.gsub(Account::MENTION_RE, '') if @status.local?
|
||||
|
||||
Nokogiri::HTML.fragment(text).tap do |html|
|
||||
mentions = @status.mentions.map { |mention| ActivityPub::TagManager.instance.url_for(mention.account) }
|
||||
|
||||
html.traverse do |element|
|
||||
element.unlink if element.name == 'a' && mentions.include?(element['href'])
|
||||
end
|
||||
end.to_s
|
||||
end
|
||||
|
||||
def normalize_unicode(text)
|
||||
text.unicode_normalize(:nfkc).downcase
|
||||
end
|
||||
|
||||
def remove_whitespace(text)
|
||||
text.gsub(/\s+/, ' ').strip
|
||||
end
|
||||
|
||||
def auto_report_status!
|
||||
status_ids = Status.where(visibility: %i(public unlisted)).where(id: matching_status_ids).pluck(:id) + [@status.id] if @status.distributable?
|
||||
ReportService.new.call(Account.representative, @account, status_ids: status_ids, comment: I18n.t('spam_check.spam_detected'))
|
||||
end
|
||||
|
||||
def already_flagged?
|
||||
@account.silenced? || @account.targeted_reports.unresolved.where(account_id: -99).exists?
|
||||
end
|
||||
|
||||
def trusted?
|
||||
@account.trust_level > Account::TRUST_LEVELS[:untrusted] || (@account.local? && @account.user_staff?)
|
||||
end
|
||||
|
||||
def no_unsolicited_mentions?
|
||||
@status.mentions.all? { |mention| mention.silent? || (!@account.local? && !mention.account.local?) || mention.account.following?(@account) }
|
||||
end
|
||||
|
||||
def solicited_reply?
|
||||
!@status.thread.nil? && @status.thread.mentions.where(account: @account).exists?
|
||||
end
|
||||
|
||||
def nilsimsa_compare_value(first, second)
|
||||
first = [first].pack('H*')
|
||||
second = [second].pack('H*')
|
||||
bits = 0
|
||||
|
||||
0.upto(31) do |i|
|
||||
bits += Nilsimsa::POPC[255 & (first[i].ord ^ second[i].ord)].ord
|
||||
end
|
||||
|
||||
128 - bits # -128 <= Nilsimsa Compare Value <= 128
|
||||
end
|
||||
|
||||
def nilsimsa?
|
||||
hashable_text.size > NILSIMSA_MIN_SIZE
|
||||
end
|
||||
|
||||
def other_digests
|
||||
redis.zrange(redis_key, 0, -1)
|
||||
end
|
||||
|
||||
def digests_over_threshold?(filter_algorithm)
|
||||
other_digests.select do |record|
|
||||
algorithm, other_digest, status_id = record.split(':')
|
||||
|
||||
next unless algorithm == filter_algorithm
|
||||
|
||||
yield algorithm, other_digest, status_id
|
||||
end.size >= THRESHOLD
|
||||
end
|
||||
|
||||
def matching_status_ids
|
||||
if nilsimsa?
|
||||
other_digests.filter_map { |record| record.split(':')[2] if record.start_with?('nilsimsa') && nilsimsa_compare_value(digest, record.split(':')[1]) >= NILSIMSA_COMPARE_THRESHOLD }
|
||||
else
|
||||
other_digests.filter_map { |record| record.split(':')[2] if record.start_with?('md5') && record.split(':')[1] == digest }
|
||||
end
|
||||
end
|
||||
|
||||
def redis_key
|
||||
@redis_key ||= "spam_check:#{@account.id}"
|
||||
end
|
||||
end
|
@@ -6,11 +6,22 @@ class StatusReachFinder
|
||||
end
|
||||
|
||||
def inboxes
|
||||
Account.where(id: reached_account_ids).inboxes
|
||||
(reached_account_inboxes + followers_inboxes + relay_inboxes).uniq
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def reached_account_inboxes
|
||||
# When the status is a reblog, there are no interactions with it
|
||||
# directly, we assume all interactions are with the original one
|
||||
|
||||
if @status.reblog?
|
||||
[]
|
||||
else
|
||||
Account.where(id: reached_account_ids).inboxes
|
||||
end
|
||||
end
|
||||
|
||||
def reached_account_ids
|
||||
[
|
||||
replied_to_account_id,
|
||||
@@ -49,4 +60,16 @@ class StatusReachFinder
|
||||
def replies_account_ids
|
||||
@status.replies.pluck(:account_id)
|
||||
end
|
||||
|
||||
def followers_inboxes
|
||||
@status.account.followers.inboxes
|
||||
end
|
||||
|
||||
def relay_inboxes
|
||||
if @status.public_visibility?
|
||||
Relay.enabled.pluck(:inbox_url)
|
||||
else
|
||||
[]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@@ -22,14 +22,6 @@ class TagManager
|
||||
uri.normalized_host
|
||||
end
|
||||
|
||||
def same_acct?(canonical, needle)
|
||||
return true if canonical.casecmp(needle).zero?
|
||||
|
||||
username, domain = needle.split('@')
|
||||
|
||||
local_domain?(domain) && canonical.casecmp(username).zero?
|
||||
end
|
||||
|
||||
def local_url?(url)
|
||||
uri = Addressable::URI.parse(url).normalize
|
||||
return false unless uri.host
|
||||
|
@@ -114,6 +114,7 @@ class Account < ApplicationRecord
|
||||
scope :matches_domain, ->(value) { where(arel_table[:domain].matches("%#{value}%")) }
|
||||
scope :searchable, -> { without_suspended.where(moved_to_account_id: nil) }
|
||||
scope :discoverable, -> { searchable.without_silenced.where(discoverable: true).left_outer_joins(:account_stat) }
|
||||
scope :followable_by, ->(account) { joins(arel_table.join(Follow.arel_table, Arel::Nodes::OuterJoin).on(arel_table[:id].eq(Follow.arel_table[:target_account_id]).and(Follow.arel_table[:account_id].eq(account.id))).join_sources).where(Follow.arel_table[:id].eq(nil)).joins(arel_table.join(FollowRequest.arel_table, Arel::Nodes::OuterJoin).on(arel_table[:id].eq(FollowRequest.arel_table[:target_account_id]).and(FollowRequest.arel_table[:account_id].eq(account.id))).join_sources).where(FollowRequest.arel_table[:id].eq(nil)) }
|
||||
scope :tagged_with, ->(tag) { joins(:accounts_tags).where(accounts_tags: { tag_id: tag }) }
|
||||
scope :by_recent_status, -> { order(Arel.sql('(case when account_stats.last_status_at is null then 1 else 0 end) asc, account_stats.last_status_at desc, accounts.id desc')) }
|
||||
scope :by_recent_sign_in, -> { order(Arel.sql('(case when users.current_sign_in_at is null then 1 else 0 end) asc, users.current_sign_in_at desc, accounts.id desc')) }
|
||||
@@ -238,6 +239,7 @@ class Account < ApplicationRecord
|
||||
transaction do
|
||||
create_deletion_request!
|
||||
update!(suspended_at: date, suspension_origin: origin)
|
||||
create_canonical_email_block!
|
||||
end
|
||||
end
|
||||
|
||||
@@ -245,6 +247,7 @@ class Account < ApplicationRecord
|
||||
transaction do
|
||||
deletion_request&.destroy!
|
||||
update!(suspended_at: nil, suspension_origin: nil)
|
||||
destroy_canonical_email_block!
|
||||
end
|
||||
end
|
||||
|
||||
@@ -365,7 +368,7 @@ class Account < ApplicationRecord
|
||||
end
|
||||
|
||||
def excluded_from_timeline_account_ids
|
||||
Rails.cache.fetch("exclude_account_ids_for:#{id}") { blocking.pluck(:target_account_id) + blocked_by.pluck(:account_id) + muting.pluck(:target_account_id) }
|
||||
Rails.cache.fetch("exclude_account_ids_for:#{id}") { block_relationships.pluck(:target_account_id) + blocked_by_relationships.pluck(:account_id) + mute_relationships.pluck(:target_account_id) }
|
||||
end
|
||||
|
||||
def excluded_from_timeline_domains
|
||||
@@ -570,4 +573,16 @@ class Account < ApplicationRecord
|
||||
def clean_feed_manager
|
||||
FeedManager.instance.clean_feeds!(:home, [id])
|
||||
end
|
||||
|
||||
def create_canonical_email_block!
|
||||
return unless local? && user_email.present?
|
||||
|
||||
CanonicalEmailBlock.create(reference_account: self, email: user_email)
|
||||
end
|
||||
|
||||
def destroy_canonical_email_block!
|
||||
return unless local?
|
||||
|
||||
CanonicalEmailBlock.where(reference_account: self).delete_all
|
||||
end
|
||||
end
|
||||
|
17
app/models/account_suggestions.rb
Normal file
17
app/models/account_suggestions.rb
Normal file
@@ -0,0 +1,17 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class AccountSuggestions
|
||||
class Suggestion < ActiveModelSerializers::Model
|
||||
attributes :account, :source
|
||||
end
|
||||
|
||||
def self.get(account, limit)
|
||||
suggestions = PotentialFriendshipTracker.get(account, limit).map { |target_account| Suggestion.new(account: target_account, source: :past_interaction) }
|
||||
suggestions.concat(FollowRecommendation.get(account, limit - suggestions.size, suggestions.map { |suggestion| suggestion.account.id }).map { |target_account| Suggestion.new(account: target_account, source: :global) }) if suggestions.size < limit
|
||||
suggestions
|
||||
end
|
||||
|
||||
def self.remove(account, target_account_id)
|
||||
PotentialFriendshipTracker.remove(account.id, target_account_id)
|
||||
end
|
||||
end
|
25
app/models/account_summary.rb
Normal file
25
app/models/account_summary.rb
Normal file
@@ -0,0 +1,25 @@
|
||||
# frozen_string_literal: true
|
||||
# == Schema Information
|
||||
#
|
||||
# Table name: account_summaries
|
||||
#
|
||||
# account_id :bigint(8) primary key
|
||||
# language :string
|
||||
# sensitive :boolean
|
||||
#
|
||||
|
||||
class AccountSummary < ApplicationRecord
|
||||
self.primary_key = :account_id
|
||||
|
||||
scope :safe, -> { where(sensitive: false) }
|
||||
scope :localized, ->(locale) { where(language: locale) }
|
||||
scope :filtered, -> { joins(arel_table.join(FollowRecommendationSuppression.arel_table, Arel::Nodes::OuterJoin).on(arel_table[:account_id].eq(FollowRecommendationSuppression.arel_table[:account_id])).join_sources).where(FollowRecommendationSuppression.arel_table[:id].eq(nil)) }
|
||||
|
||||
def self.refresh
|
||||
Scenic.database.refresh_materialized_view(table_name, concurrently: true, cascade: false)
|
||||
end
|
||||
|
||||
def readonly?
|
||||
true
|
||||
end
|
||||
end
|
27
app/models/canonical_email_block.rb
Normal file
27
app/models/canonical_email_block.rb
Normal file
@@ -0,0 +1,27 @@
|
||||
# frozen_string_literal: true
|
||||
# == Schema Information
|
||||
#
|
||||
# Table name: canonical_email_blocks
|
||||
#
|
||||
# id :bigint(8) not null, primary key
|
||||
# canonical_email_hash :string default(""), not null
|
||||
# reference_account_id :bigint(8) not null
|
||||
# created_at :datetime not null
|
||||
# updated_at :datetime not null
|
||||
#
|
||||
|
||||
class CanonicalEmailBlock < ApplicationRecord
|
||||
include EmailHelper
|
||||
|
||||
belongs_to :reference_account, class_name: 'Account'
|
||||
|
||||
validates :canonical_email_hash, presence: true
|
||||
|
||||
def email=(email)
|
||||
self.canonical_email_hash = email_to_canonical_email_hash(email)
|
||||
end
|
||||
|
||||
def self.block?(email)
|
||||
where(canonical_email_hash: email_to_canonical_email_hash(email)).exists?
|
||||
end
|
||||
end
|
@@ -63,5 +63,8 @@ module AccountAssociations
|
||||
|
||||
# Account deletion requests
|
||||
has_one :deletion_request, class_name: 'AccountDeletionRequest', inverse_of: :account, dependent: :destroy
|
||||
|
||||
# Follow recommendations
|
||||
has_one :follow_recommendation_suppression, inverse_of: :account, dependent: :destroy
|
||||
end
|
||||
end
|
||||
|
39
app/models/follow_recommendation.rb
Normal file
39
app/models/follow_recommendation.rb
Normal file
@@ -0,0 +1,39 @@
|
||||
# frozen_string_literal: true
|
||||
# == Schema Information
|
||||
#
|
||||
# Table name: follow_recommendations
|
||||
#
|
||||
# account_id :bigint(8) primary key
|
||||
# rank :decimal(, )
|
||||
# reason :text is an Array
|
||||
#
|
||||
|
||||
class FollowRecommendation < ApplicationRecord
|
||||
self.primary_key = :account_id
|
||||
|
||||
belongs_to :account_summary, foreign_key: :account_id
|
||||
belongs_to :account, foreign_key: :account_id
|
||||
|
||||
scope :safe, -> { joins(:account_summary).merge(AccountSummary.safe) }
|
||||
scope :localized, ->(locale) { joins(:account_summary).merge(AccountSummary.localized(locale)) }
|
||||
scope :filtered, -> { joins(:account_summary).merge(AccountSummary.filtered) }
|
||||
|
||||
def readonly?
|
||||
true
|
||||
end
|
||||
|
||||
def self.get(account, limit, exclude_account_ids = [])
|
||||
account_ids = Redis.current.zrevrange("follow_recommendations:#{account.user_locale}", 0, -1).map(&:to_i) - exclude_account_ids - [account.id]
|
||||
|
||||
return [] if account_ids.empty? || limit < 1
|
||||
|
||||
accounts = Account.followable_by(account)
|
||||
.not_excluded_by_account(account)
|
||||
.not_domain_blocked_by_account(account)
|
||||
.where(id: account_ids)
|
||||
.limit(limit)
|
||||
.index_by(&:id)
|
||||
|
||||
account_ids.map { |id| accounts[id] }.compact
|
||||
end
|
||||
end
|
26
app/models/follow_recommendation_filter.rb
Normal file
26
app/models/follow_recommendation_filter.rb
Normal file
@@ -0,0 +1,26 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class FollowRecommendationFilter
|
||||
KEYS = %i(
|
||||
language
|
||||
status
|
||||
).freeze
|
||||
|
||||
attr_reader :params, :language
|
||||
|
||||
def initialize(params)
|
||||
@language = params.delete('language') || I18n.locale
|
||||
@params = params
|
||||
end
|
||||
|
||||
def results
|
||||
if params['status'] == 'suppressed'
|
||||
Account.joins(:follow_recommendation_suppression).order(FollowRecommendationSuppression.arel_table[:id].desc).to_a
|
||||
else
|
||||
account_ids = Redis.current.zrevrange("follow_recommendations:#{@language}", 0, -1).map(&:to_i)
|
||||
accounts = Account.where(id: account_ids).index_by(&:id)
|
||||
|
||||
account_ids.map { |id| accounts[id] }.compact
|
||||
end
|
||||
end
|
||||
end
|
28
app/models/follow_recommendation_suppression.rb
Normal file
28
app/models/follow_recommendation_suppression.rb
Normal file
@@ -0,0 +1,28 @@
|
||||
# frozen_string_literal: true
|
||||
# == Schema Information
|
||||
#
|
||||
# Table name: follow_recommendation_suppressions
|
||||
#
|
||||
# id :bigint(8) not null, primary key
|
||||
# account_id :bigint(8) not null
|
||||
# created_at :datetime not null
|
||||
# updated_at :datetime not null
|
||||
#
|
||||
|
||||
class FollowRecommendationSuppression < ApplicationRecord
|
||||
include Redisable
|
||||
|
||||
belongs_to :account
|
||||
|
||||
after_commit :remove_follow_recommendations, on: :create
|
||||
|
||||
private
|
||||
|
||||
def remove_follow_recommendations
|
||||
redis.pipelined do
|
||||
I18n.available_locales.each do |locale|
|
||||
redis.zrem("follow_recommendations:#{locale}", account_id)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
@@ -21,6 +21,10 @@ class Form::AccountBatch
|
||||
approve!
|
||||
when 'reject'
|
||||
reject!
|
||||
when 'suppress_follow_recommendation'
|
||||
suppress_follow_recommendation!
|
||||
when 'unsuppress_follow_recommendation'
|
||||
unsuppress_follow_recommendation!
|
||||
end
|
||||
end
|
||||
|
||||
@@ -79,4 +83,18 @@ class Form::AccountBatch
|
||||
records.each { |account| authorize(account.user, :reject?) }
|
||||
.each { |account| DeleteAccountService.new.call(account, reserve_email: false, reserve_username: false) }
|
||||
end
|
||||
|
||||
def suppress_follow_recommendation!
|
||||
authorize(:follow_recommendation, :suppress?)
|
||||
|
||||
accounts.each do |account|
|
||||
FollowRecommendationSuppression.create(account: account)
|
||||
end
|
||||
end
|
||||
|
||||
def unsuppress_follow_recommendation!
|
||||
authorize(:follow_recommendation, :unsuppress?)
|
||||
|
||||
FollowRecommendationSuppression.where(account_id: account_ids).destroy_all
|
||||
end
|
||||
end
|
||||
|
@@ -35,7 +35,6 @@ class Form::AdminSettings
|
||||
mascot
|
||||
show_reblogs_in_public_timelines
|
||||
show_replies_in_public_timelines
|
||||
spam_check_enabled
|
||||
trends
|
||||
trendable_by_default
|
||||
show_domain_blocks
|
||||
@@ -59,7 +58,6 @@ class Form::AdminSettings
|
||||
enable_keybase
|
||||
show_reblogs_in_public_timelines
|
||||
show_replies_in_public_timelines
|
||||
spam_check_enabled
|
||||
trends
|
||||
trendable_by_default
|
||||
noindex
|
||||
|
@@ -24,81 +24,101 @@ class Web::PushSubscription < ApplicationRecord
|
||||
validates :key_p256dh, presence: true
|
||||
validates :key_auth, presence: true
|
||||
|
||||
def push(notification)
|
||||
I18n.with_locale(associated_user&.locale || I18n.default_locale) do
|
||||
push_payload(payload_for_notification(notification), 48.hours.seconds)
|
||||
end
|
||||
delegate :locale, to: :associated_user
|
||||
|
||||
def encrypt(payload)
|
||||
Webpush::Encryption.encrypt(payload, key_p256dh, key_auth)
|
||||
end
|
||||
|
||||
def audience
|
||||
@audience ||= Addressable::URI.parse(endpoint).normalized_site
|
||||
end
|
||||
|
||||
def crypto_key_header
|
||||
p256ecdsa = vapid_key.public_key_for_push_header
|
||||
|
||||
"p256ecdsa=#{p256ecdsa}"
|
||||
end
|
||||
|
||||
def authorization_header
|
||||
jwt = JWT.encode({ aud: audience, exp: 24.hours.from_now.to_i, sub: "mailto:#{contact_email}" }, vapid_key.curve, 'ES256', typ: 'JWT')
|
||||
|
||||
"WebPush #{jwt}"
|
||||
end
|
||||
|
||||
def pushable?(notification)
|
||||
data&.key?('alerts') && ActiveModel::Type::Boolean.new.cast(data['alerts'][notification.type.to_s])
|
||||
policy_allows_notification?(notification) && alert_enabled_for_notification_type?(notification)
|
||||
end
|
||||
|
||||
def associated_user
|
||||
return @associated_user if defined?(@associated_user)
|
||||
|
||||
@associated_user = if user_id.nil?
|
||||
session_activation.user
|
||||
else
|
||||
user
|
||||
end
|
||||
@associated_user = begin
|
||||
if user_id.nil?
|
||||
session_activation.user
|
||||
else
|
||||
user
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def associated_access_token
|
||||
return @associated_access_token if defined?(@associated_access_token)
|
||||
|
||||
@associated_access_token = if access_token_id.nil?
|
||||
find_or_create_access_token.token
|
||||
else
|
||||
access_token.token
|
||||
end
|
||||
@associated_access_token = begin
|
||||
if access_token_id.nil?
|
||||
find_or_create_access_token.token
|
||||
else
|
||||
access_token.token
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
class << self
|
||||
def unsubscribe_for(application_id, resource_owner)
|
||||
access_token_ids = Doorkeeper::AccessToken.where(application_id: application_id, resource_owner_id: resource_owner.id, revoked_at: nil)
|
||||
.pluck(:id)
|
||||
|
||||
access_token_ids = Doorkeeper::AccessToken.where(application_id: application_id, resource_owner_id: resource_owner.id, revoked_at: nil).pluck(:id)
|
||||
where(access_token_id: access_token_ids).delete_all
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def push_payload(message, ttl = 5.minutes.seconds)
|
||||
Webpush.payload_send(
|
||||
message: Oj.dump(message),
|
||||
endpoint: endpoint,
|
||||
p256dh: key_p256dh,
|
||||
auth: key_auth,
|
||||
ttl: ttl,
|
||||
ssl_timeout: 10,
|
||||
open_timeout: 10,
|
||||
read_timeout: 10,
|
||||
vapid: {
|
||||
subject: "mailto:#{::Setting.site_contact_email}",
|
||||
private_key: Rails.configuration.x.vapid_private_key,
|
||||
public_key: Rails.configuration.x.vapid_public_key,
|
||||
}
|
||||
)
|
||||
end
|
||||
|
||||
def payload_for_notification(notification)
|
||||
ActiveModelSerializers::SerializableResource.new(
|
||||
notification,
|
||||
serializer: Web::NotificationSerializer,
|
||||
scope: self,
|
||||
scope_name: :current_push_subscription
|
||||
).as_json
|
||||
end
|
||||
|
||||
def find_or_create_access_token
|
||||
Doorkeeper::AccessToken.find_or_create_for(
|
||||
application: Doorkeeper::Application.find_by(superapp: true),
|
||||
resource_owner: session_activation.user_id,
|
||||
resource_owner: user_id || session_activation.user_id,
|
||||
scopes: Doorkeeper::OAuth::Scopes.from_string('read write follow push'),
|
||||
expires_in: Doorkeeper.configuration.access_token_expires_in,
|
||||
use_refresh_token: Doorkeeper.configuration.refresh_token_enabled?
|
||||
)
|
||||
end
|
||||
|
||||
def vapid_key
|
||||
@vapid_key ||= Webpush::VapidKey.from_keys(Rails.configuration.x.vapid_public_key, Rails.configuration.x.vapid_private_key)
|
||||
end
|
||||
|
||||
def contact_email
|
||||
@contact_email ||= ::Setting.site_contact_email
|
||||
end
|
||||
|
||||
def alert_enabled_for_notification_type?(notification)
|
||||
truthy?(data&.dig('alerts', notification.type.to_s))
|
||||
end
|
||||
|
||||
def policy_allows_notification?(notification)
|
||||
case data&.dig('policy')
|
||||
when nil, 'all'
|
||||
true
|
||||
when 'none'
|
||||
false
|
||||
when 'followed'
|
||||
notification.account.following?(notification.from_account)
|
||||
when 'follower'
|
||||
notification.from_account.following?(notification.account)
|
||||
end
|
||||
end
|
||||
|
||||
def truthy?(val)
|
||||
ActiveModel::Type::Boolean.new.cast(val)
|
||||
end
|
||||
end
|
||||
|
15
app/policies/follow_recommendation_policy.rb
Normal file
15
app/policies/follow_recommendation_policy.rb
Normal file
@@ -0,0 +1,15 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class FollowRecommendationPolicy < ApplicationPolicy
|
||||
def show?
|
||||
staff?
|
||||
end
|
||||
|
||||
def suppress?
|
||||
staff?
|
||||
end
|
||||
|
||||
def unsuppress?
|
||||
staff?
|
||||
end
|
||||
end
|
7
app/serializers/rest/suggestion_serializer.rb
Normal file
7
app/serializers/rest/suggestion_serializer.rb
Normal file
@@ -0,0 +1,7 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class REST::SuggestionSerializer < ActiveModel::Serializer
|
||||
attributes :source
|
||||
|
||||
has_one :account, serializer: REST::AccountSerializer
|
||||
end
|
@@ -43,7 +43,6 @@ class ProcessMentionsService < BaseService
|
||||
end
|
||||
|
||||
status.save!
|
||||
check_for_spam(status)
|
||||
|
||||
mentions.each { |mention| create_notification(mention) }
|
||||
end
|
||||
@@ -72,8 +71,4 @@ class ProcessMentionsService < BaseService
|
||||
def resolve_account_service
|
||||
ResolveAccountService.new
|
||||
end
|
||||
|
||||
def check_for_spam(status)
|
||||
SpamCheck.perform(status)
|
||||
end
|
||||
end
|
||||
|
@@ -27,10 +27,7 @@ class RemoveStatusService < BaseService
|
||||
# original object being removed implicitly removes reblogs
|
||||
# of it. The Delete activity of the original is forwarded
|
||||
# separately.
|
||||
if @account.local? && !@options[:original_removed]
|
||||
remove_from_remote_followers
|
||||
remove_from_remote_reach
|
||||
end
|
||||
remove_from_remote_reach if @account.local? && !@options[:original_removed]
|
||||
|
||||
# Since reblogs don't mention anyone, don't get reblogged,
|
||||
# favourited and don't contain their own media attachments
|
||||
@@ -42,7 +39,6 @@ class RemoveStatusService < BaseService
|
||||
remove_from_public
|
||||
remove_from_media if @status.media_attachments.any?
|
||||
remove_from_direct if status.direct_visibility?
|
||||
remove_from_spam_check
|
||||
remove_media
|
||||
end
|
||||
|
||||
@@ -85,13 +81,10 @@ class RemoveStatusService < BaseService
|
||||
end
|
||||
|
||||
def remove_from_remote_reach
|
||||
return if @status.reblog?
|
||||
|
||||
# People who got mentioned in the status, or who
|
||||
# reblogged it from someone else might not follow
|
||||
# the author and wouldn't normally receive the
|
||||
# delete notification - so here, we explicitly
|
||||
# send it to them
|
||||
# Followers, relays, people who got mentioned in the status,
|
||||
# or who reblogged it from someone else might not follow
|
||||
# the author and wouldn't normally receive the delete
|
||||
# notification - so here, we explicitly send it to them
|
||||
|
||||
status_reach_finder = StatusReachFinder.new(@status)
|
||||
|
||||
@@ -100,24 +93,6 @@ class RemoveStatusService < BaseService
|
||||
end
|
||||
end
|
||||
|
||||
def remove_from_remote_followers
|
||||
ActivityPub::DeliveryWorker.push_bulk(@account.followers.inboxes) do |inbox_url|
|
||||
[signed_activity_json, @account.id, inbox_url]
|
||||
end
|
||||
|
||||
relay! if relayable?
|
||||
end
|
||||
|
||||
def relayable?
|
||||
@status.public_visibility?
|
||||
end
|
||||
|
||||
def relay!
|
||||
ActivityPub::DeliveryWorker.push_bulk(Relay.enabled.pluck(:inbox_url)) do |inbox_url|
|
||||
[signed_activity_json, @account.id, inbox_url]
|
||||
end
|
||||
end
|
||||
|
||||
def signed_activity_json
|
||||
@signed_activity_json ||= Oj.dump(serialize_payload(@status, @status.reblog? ? ActivityPub::UndoAnnounceSerializer : ActivityPub::DeleteSerializer, signer: @account))
|
||||
end
|
||||
@@ -171,10 +146,6 @@ class RemoveStatusService < BaseService
|
||||
@status.media_attachments.destroy_all
|
||||
end
|
||||
|
||||
def remove_from_spam_check
|
||||
redis.zremrangebyscore("spam_check:#{@status.account_id}", @status.id, @status.id)
|
||||
end
|
||||
|
||||
def lock_options
|
||||
{ redis: Redis.current, key: "distribute:#{@status.id}" }
|
||||
end
|
||||
|
@@ -10,6 +10,8 @@ class ReportService < BaseService
|
||||
@comment = options.delete(:comment) || ''
|
||||
@options = options
|
||||
|
||||
raise ActiveRecord::RecordNotFound if @target_account.suspended?
|
||||
|
||||
create_report!
|
||||
notify_staff!
|
||||
forward_to_origin! if !@target_account.local? && ActiveModel::Type::Boolean.new.cast(@options[:forward])
|
||||
|
@@ -42,7 +42,13 @@ class SuspendAccountService < BaseService
|
||||
end
|
||||
|
||||
def distribute_update_actor!
|
||||
ActivityPub::UpdateDistributionWorker.perform_async(@account.id) if @account.local?
|
||||
return unless @account.local?
|
||||
|
||||
account_reach_finder = AccountReachFinder.new(@account)
|
||||
|
||||
ActivityPub::DeliveryWorker.push_bulk(account_reach_finder.inboxes) do |inbox_url|
|
||||
[signed_activity_json, @account.id, inbox_url]
|
||||
end
|
||||
end
|
||||
|
||||
def unmerge_from_home_timelines!
|
||||
@@ -90,4 +96,8 @@ class SuspendAccountService < BaseService
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def signed_activity_json
|
||||
@signed_activity_json ||= Oj.dump(serialize_payload(@account, ActivityPub::UpdateSerializer, signer: @account))
|
||||
end
|
||||
end
|
||||
|
@@ -12,6 +12,7 @@ class UnsuspendAccountService < BaseService
|
||||
merge_into_home_timelines!
|
||||
merge_into_list_timelines!
|
||||
publish_media_attachments!
|
||||
distribute_update_actor!
|
||||
end
|
||||
|
||||
private
|
||||
@@ -36,6 +37,16 @@ class UnsuspendAccountService < BaseService
|
||||
# @account would now be nil.
|
||||
end
|
||||
|
||||
def distribute_update_actor!
|
||||
return unless @account.local?
|
||||
|
||||
account_reach_finder = AccountReachFinder.new(@account)
|
||||
|
||||
ActivityPub::DeliveryWorker.push_bulk(account_reach_finder.inboxes) do |inbox_url|
|
||||
[signed_activity_json, @account.id, inbox_url]
|
||||
end
|
||||
end
|
||||
|
||||
def merge_into_home_timelines!
|
||||
@account.followers_for_local_distribution.find_each do |follower|
|
||||
FeedManager.instance.merge_into_home(@account, follower)
|
||||
@@ -81,4 +92,8 @@ class UnsuspendAccountService < BaseService
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def signed_activity_json
|
||||
@signed_activity_json ||= Oj.dump(serialize_payload(@account, ActivityPub::UpdateSerializer, signer: @account))
|
||||
end
|
||||
end
|
||||
|
@@ -6,26 +6,25 @@ class BlacklistedEmailValidator < ActiveModel::Validator
|
||||
|
||||
@email = user.email
|
||||
|
||||
user.errors.add(:email, :blocked) if blocked_email?
|
||||
user.errors.add(:email, :blocked) if blocked_email_provider?
|
||||
user.errors.add(:email, :taken) if blocked_canonical_email?
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def blocked_email?
|
||||
on_blacklist? || not_on_whitelist?
|
||||
def blocked_email_provider?
|
||||
disallowed_through_email_domain_block? || disallowed_through_configuration? || not_allowed_through_configuration?
|
||||
end
|
||||
|
||||
def on_blacklist?
|
||||
return true if EmailDomainBlock.block?(@email)
|
||||
return false if Rails.configuration.x.email_domains_blacklist.blank?
|
||||
|
||||
domains = Rails.configuration.x.email_domains_blacklist.gsub('.', '\.')
|
||||
regexp = Regexp.new("@(.+\\.)?(#{domains})", true)
|
||||
|
||||
regexp.match?(@email)
|
||||
def blocked_canonical_email?
|
||||
CanonicalEmailBlock.block?(@email)
|
||||
end
|
||||
|
||||
def not_on_whitelist?
|
||||
def disallowed_through_email_domain_block?
|
||||
EmailDomainBlock.block?(@email)
|
||||
end
|
||||
|
||||
def not_allowed_through_configuration?
|
||||
return false if Rails.configuration.x.email_domains_whitelist.blank?
|
||||
|
||||
domains = Rails.configuration.x.email_domains_whitelist.gsub('.', '\.')
|
||||
@@ -33,4 +32,13 @@ class BlacklistedEmailValidator < ActiveModel::Validator
|
||||
|
||||
@email !~ regexp
|
||||
end
|
||||
|
||||
def disallowed_through_configuration?
|
||||
return false if Rails.configuration.x.email_domains_blacklist.blank?
|
||||
|
||||
domains = Rails.configuration.x.email_domains_blacklist.gsub('.', '\.')
|
||||
regexp = Regexp.new("@(.+\\.)?(#{domains})", true)
|
||||
|
||||
regexp.match?(@email)
|
||||
end
|
||||
end
|
||||
|
@@ -79,8 +79,6 @@
|
||||
= feature_hint(link_to(t('admin.dashboard.trends'), edit_admin_settings_path), @trends_enabled)
|
||||
%li
|
||||
= feature_hint(link_to(t('admin.dashboard.feature_relay'), admin_relays_path), @relay_enabled)
|
||||
%li
|
||||
= feature_hint(link_to(t('admin.dashboard.feature_spam_check'), edit_admin_settings_path), @spam_check_enabled)
|
||||
|
||||
.dashboard__widgets__versions
|
||||
%div
|
||||
|
20
app/views/admin/follow_recommendations/_account.html.haml
Normal file
20
app/views/admin/follow_recommendations/_account.html.haml
Normal file
@@ -0,0 +1,20 @@
|
||||
.batch-table__row
|
||||
%label.batch-table__row__select.batch-table__row__select--aligned.batch-checkbox
|
||||
= f.check_box :account_ids, { multiple: true, include_hidden: false }, account.id
|
||||
.batch-table__row__content.batch-table__row__content--unpadded
|
||||
%table.accounts-table
|
||||
%tbody
|
||||
%tr
|
||||
%td= account_link_to account
|
||||
%td.accounts-table__count.optional
|
||||
= number_to_human account.statuses_count, strip_insignificant_zeros: true
|
||||
%small= t('accounts.posts', count: account.statuses_count).downcase
|
||||
%td.accounts-table__count.optional
|
||||
= number_to_human account.followers_count, strip_insignificant_zeros: true
|
||||
%small= t('accounts.followers', count: account.followers_count).downcase
|
||||
%td.accounts-table__count
|
||||
- if account.last_status_at.present?
|
||||
%time.time-ago{ datetime: account.last_status_at.to_date.iso8601, title: l(account.last_status_at.to_date) }= l account.last_status_at
|
||||
- else
|
||||
\-
|
||||
%small= t('accounts.last_active')
|
41
app/views/admin/follow_recommendations/show.html.haml
Normal file
41
app/views/admin/follow_recommendations/show.html.haml
Normal file
@@ -0,0 +1,41 @@
|
||||
- content_for :page_title do
|
||||
= t('admin.follow_recommendations.title')
|
||||
|
||||
- content_for :header_tags do
|
||||
= javascript_pack_tag 'admin', async: true, crossorigin: 'anonymous'
|
||||
|
||||
%p= t('admin.follow_recommendations.description_html')
|
||||
|
||||
%hr.spacer/
|
||||
|
||||
= form_tag admin_follow_recommendations_path, method: 'GET', class: 'simple_form' do
|
||||
.filters
|
||||
.filter-subset.filter-subset--with-select
|
||||
%strong= t('admin.follow_recommendations.language')
|
||||
.input.select.optional
|
||||
= select_tag :language, options_for_select(I18n.available_locales.map { |key| [human_locale(key), key]}, @language)
|
||||
|
||||
.filter-subset
|
||||
%strong= t('admin.follow_recommendations.status')
|
||||
%ul
|
||||
%li= filter_link_to t('admin.accounts.moderation.active'), status: nil
|
||||
%li= filter_link_to t('admin.follow_recommendations.suppressed'), status: 'suppressed'
|
||||
|
||||
= form_for(@form, url: admin_follow_recommendations_path, method: :patch) do |f|
|
||||
- RelationshipFilter::KEYS.each do |key|
|
||||
= hidden_field_tag key, params[key] if params[key].present?
|
||||
|
||||
.batch-table
|
||||
.batch-table__toolbar
|
||||
%label.batch-table__toolbar__select.batch-checkbox-all
|
||||
= check_box_tag :batch_checkbox_all, nil, false
|
||||
.batch-table__toolbar__actions
|
||||
- if params[:status].blank? && can?(:suppress, :follow_recommendation)
|
||||
= f.button safe_join([fa_icon('times'), t('admin.follow_recommendations.suppress')]), name: :suppress, class: 'table-action-link', type: :submit, data: { confirm: t('admin.reports.are_you_sure') }
|
||||
- if params[:status] == 'suppressed' && can?(:unsuppress, :follow_recommendation)
|
||||
= f.button safe_join([fa_icon('plus'), t('admin.follow_recommendations.unsuppress')]), name: :unsuppress, class: 'table-action-link', type: :submit
|
||||
.batch-table__body
|
||||
- if @accounts.empty?
|
||||
= nothing_here 'nothing-here--under-tabs'
|
||||
- else
|
||||
= render partial: 'account', collection: @accounts, locals: { f: f }
|
@@ -1,8 +1,9 @@
|
||||
- content_for :page_title do
|
||||
= t('admin.rules.title')
|
||||
|
||||
.simple_form
|
||||
%p.hint= t('admin.rules.description')
|
||||
%p= t('admin.rules.description_html')
|
||||
|
||||
%hr.spacer/
|
||||
|
||||
- if can? :create, :rule
|
||||
= simple_form_for @rule, url: admin_rules_path do |f|
|
||||
|
@@ -101,9 +101,6 @@
|
||||
.fields-group
|
||||
= f.input :show_replies_in_public_timelines, as: :boolean, wrapper: :with_label, label: t('admin.settings.show_replies_in_public_timelines.title'), hint: t('admin.settings.show_replies_in_public_timelines.desc_html')
|
||||
|
||||
.fields-group
|
||||
= f.input :spam_check_enabled, as: :boolean, wrapper: :with_label, label: t('admin.settings.spam_check_enabled.title'), hint: t('admin.settings.spam_check_enabled.desc_html')
|
||||
|
||||
%hr.spacer/
|
||||
|
||||
.fields-group
|
||||
|
@@ -1,7 +1,7 @@
|
||||
<%= t 'devise.mailer.webauthn_credentia.added.title' %>
|
||||
<%= t 'devise.mailer.webauthn_credential.added.title' %>
|
||||
|
||||
===
|
||||
|
||||
<%= t 'devise.mailer.webauthn_credentia.added.explanation' %>
|
||||
<%= t 'devise.mailer.webauthn_credential.added.explanation' %>
|
||||
|
||||
=> <%= edit_user_registration_url %>
|
||||
|
61
app/workers/scheduler/follow_recommendations_scheduler.rb
Normal file
61
app/workers/scheduler/follow_recommendations_scheduler.rb
Normal file
@@ -0,0 +1,61 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class Scheduler::FollowRecommendationsScheduler
|
||||
include Sidekiq::Worker
|
||||
include Redisable
|
||||
|
||||
sidekiq_options retry: 0
|
||||
|
||||
# The maximum number of accounts that can be requested in one page from the
|
||||
# API is 80, and the suggestions API does not allow pagination. This number
|
||||
# leaves some room for accounts being filtered during live access
|
||||
SET_SIZE = 100
|
||||
|
||||
def perform
|
||||
# Maintaining a materialized view speeds-up subsequent queries significantly
|
||||
AccountSummary.refresh
|
||||
|
||||
fallback_recommendations = FollowRecommendation.safe.filtered.limit(SET_SIZE).index_by(&:account_id)
|
||||
|
||||
I18n.available_locales.each do |locale|
|
||||
recommendations = begin
|
||||
if AccountSummary.safe.filtered.localized(locale).exists? # We can skip the work if no accounts with that language exist
|
||||
FollowRecommendation.safe.filtered.localized(locale).limit(SET_SIZE).index_by(&:account_id)
|
||||
else
|
||||
{}
|
||||
end
|
||||
end
|
||||
|
||||
# Use language-agnostic results if there are not enough language-specific ones
|
||||
missing = SET_SIZE - recommendations.keys.size
|
||||
|
||||
if missing.positive?
|
||||
added = 0
|
||||
|
||||
# Avoid duplicate results
|
||||
fallback_recommendations.each_value do |recommendation|
|
||||
next if recommendations.key?(recommendation.account_id)
|
||||
|
||||
recommendations[recommendation.account_id] = recommendation
|
||||
added += 1
|
||||
|
||||
break if added >= missing
|
||||
end
|
||||
end
|
||||
|
||||
redis.pipelined do
|
||||
redis.del(key(locale))
|
||||
|
||||
recommendations.each_value do |recommendation|
|
||||
redis.zadd(key(locale), recommendation.rank, recommendation.account_id)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def key(locale)
|
||||
"follow_recommendations:#{locale}"
|
||||
end
|
||||
end
|
@@ -3,22 +3,67 @@
|
||||
class Web::PushNotificationWorker
|
||||
include Sidekiq::Worker
|
||||
|
||||
sidekiq_options backtrace: true, retry: 5
|
||||
sidekiq_options queue: 'push', retry: 5
|
||||
|
||||
TTL = 48.hours.to_s
|
||||
URGENCY = 'normal'
|
||||
|
||||
def perform(subscription_id, notification_id)
|
||||
subscription = ::Web::PushSubscription.find(subscription_id)
|
||||
notification = Notification.find(notification_id)
|
||||
@subscription = Web::PushSubscription.find(subscription_id)
|
||||
@notification = Notification.find(notification_id)
|
||||
|
||||
subscription.push(notification) unless notification.activity.nil?
|
||||
rescue Webpush::ResponseError => e
|
||||
code = e.response.code.to_i
|
||||
# Polymorphically associated activity could have been deleted
|
||||
# in the meantime, so we have to double-check before proceeding
|
||||
return unless @notification.activity.present? && @subscription.pushable?(@notification)
|
||||
|
||||
if (400..499).cover?(code) && ![408, 429].include?(code)
|
||||
subscription.destroy!
|
||||
else
|
||||
raise e
|
||||
payload = @subscription.encrypt(push_notification_json)
|
||||
|
||||
request_pool.with(@subscription.audience) do |http_client|
|
||||
request = Request.new(:post, @subscription.endpoint, body: payload.fetch(:ciphertext), http_client: http_client)
|
||||
|
||||
request.add_headers(
|
||||
'Content-Type' => 'application/octet-stream',
|
||||
'Ttl' => TTL,
|
||||
'Urgency' => URGENCY,
|
||||
'Content-Encoding' => 'aesgcm',
|
||||
'Encryption' => "salt=#{Webpush.encode64(payload.fetch(:salt)).delete('=')}",
|
||||
'Crypto-Key' => "dh=#{Webpush.encode64(payload.fetch(:server_public_key)).delete('=')};#{@subscription.crypto_key_header}",
|
||||
'Authorization' => @subscription.authorization_header
|
||||
)
|
||||
|
||||
request.perform do |response|
|
||||
# If the server responds with an error in the 4xx range
|
||||
# that isn't about rate-limiting or timeouts, we can
|
||||
# assume that the subscription is invalid or expired
|
||||
# and must be removed
|
||||
|
||||
if (400..499).cover?(response.code) && ![408, 429].include?(response.code)
|
||||
@subscription.destroy!
|
||||
elsif !(200...300).cover?(response.code)
|
||||
raise Mastodon::UnexpectedResponseError, response
|
||||
end
|
||||
end
|
||||
end
|
||||
rescue ActiveRecord::RecordNotFound
|
||||
true
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def push_notification_json
|
||||
json = I18n.with_locale(@subscription.locale || I18n.default_locale) do
|
||||
ActiveModelSerializers::SerializableResource.new(
|
||||
@notification,
|
||||
serializer: Web::NotificationSerializer,
|
||||
scope: @subscription,
|
||||
scope_name: :current_push_subscription
|
||||
).as_json
|
||||
end
|
||||
|
||||
Oj.dump(json)
|
||||
end
|
||||
|
||||
def request_pool
|
||||
RequestPool.current
|
||||
end
|
||||
end
|
||||
|
Reference in New Issue
Block a user