Merge remote-tracking branch 'origin/develop' into next

profile-avatar-switcher
Alex Gleason 2021-09-18 16:22:09 -05:00
commit 48216659d6
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 7211D1F99744FBB7
8 zmienionych plików z 119 dodań i 151 usunięć

Wyświetl plik

@ -5,6 +5,7 @@ import {
importErrorWhileFetchingAccountByUsername,
} from './importer';
import { isLoggedIn } from 'soapbox/utils/auth';
import { getFeatures } from 'soapbox/utils/features';
export const ACCOUNT_CREATE_REQUEST = 'ACCOUNT_CREATE_REQUEST';
export const ACCOUNT_CREATE_SUCCESS = 'ACCOUNT_CREATE_SUCCESS';
@ -54,6 +55,10 @@ export const ACCOUNT_UNPIN_REQUEST = 'ACCOUNT_UNPIN_REQUEST';
export const ACCOUNT_UNPIN_SUCCESS = 'ACCOUNT_UNPIN_SUCCESS';
export const ACCOUNT_UNPIN_FAIL = 'ACCOUNT_UNPIN_FAIL';
export const ACCOUNT_SEARCH_REQUEST = 'ACCOUNT_SEARCH_REQUEST';
export const ACCOUNT_SEARCH_SUCCESS = 'ACCOUNT_SEARCH_SUCCESS';
export const ACCOUNT_SEARCH_FAIL = 'ACCOUNT_SEARCH_FAIL';
export const FOLLOWERS_FETCH_REQUEST = 'FOLLOWERS_FETCH_REQUEST';
export const FOLLOWERS_FETCH_SUCCESS = 'FOLLOWERS_FETCH_SUCCESS';
export const FOLLOWERS_FETCH_FAIL = 'FOLLOWERS_FETCH_FAIL';
@ -129,13 +134,18 @@ export function fetchAccount(id) {
export function fetchAccountByUsername(username) {
return (dispatch, getState) => {
const account = getState().get('accounts').find(account => account.get('acct') === username);
const state = getState();
const account = state.get('accounts').find(account => account.get('acct') === username);
if (account) {
dispatch(fetchAccount(account.get('id')));
return;
}
const instance = state.get('instance');
const features = getFeatures(instance);
if (features.accountByUsername) {
api(getState).get(`/api/v1/accounts/${username}`).then(response => {
dispatch(fetchRelationships([response.data.id]));
dispatch(importFetchedAccount(response.data));
@ -144,6 +154,25 @@ export function fetchAccountByUsername(username) {
dispatch(fetchAccountFail(null, error));
dispatch(importErrorWhileFetchingAccountByUsername(username));
});
} else {
dispatch(accountSearch({
q: username,
limit: 5,
resolve: true,
})).then(accounts => {
const found = accounts.find(a => a.acct === username);
if (found) {
dispatch(fetchRelationships([found.id]));
dispatch(fetchAccountSuccess(found));
} else {
throw accounts;
}
}).catch(error => {
dispatch(fetchAccountFail(null, error));
dispatch(importErrorWhileFetchingAccountByUsername(username));
});
}
};
}
@ -917,3 +946,17 @@ export function unpinAccountFail(error) {
error,
};
}
export function accountSearch(params) {
return (dispatch, getState) => {
dispatch({ type: ACCOUNT_SEARCH_REQUEST, params });
return api(getState).get('/api/v1/accounts/search', { params }).then(({ data: accounts }) => {
dispatch(importFetchedAccounts(accounts));
dispatch({ type: ACCOUNT_SEARCH_SUCCESS, accounts });
return accounts;
}).catch(error => {
dispatch({ type: ACCOUNT_SEARCH_FAIL, skipAlert: true });
throw error;
});
};
}

Wyświetl plik

@ -211,14 +211,14 @@ class SidebarMenu extends ImmutablePureComponent {
<Icon id='bitcoin' />
<span className='sidebar-menu-item__title'>{intl.formatMessage(messages.donate_crypto)}</span>
</NavLink>}
<NavLink className='sidebar-menu-item' to='/lists' onClick={this.handleClose}>
{features.lists && <NavLink className='sidebar-menu-item' to='/lists' onClick={this.handleClose}>
<Icon id='list' />
<span className='sidebar-menu-item__title'>{intl.formatMessage(messages.lists)}</span>
</NavLink>
<NavLink className='sidebar-menu-item' to='/bookmarks' onClick={this.handleClose}>
</NavLink>}
{features.bookmarks && <NavLink className='sidebar-menu-item' to='/bookmarks' onClick={this.handleClose}>
<Icon id='bookmark' />
<span className='sidebar-menu-item__title'>{intl.formatMessage(messages.bookmarks)}</span>
</NavLink>
</NavLink>}
</div>
<div className='sidebar-menu__section'>

Wyświetl plik

@ -290,7 +290,7 @@ class StatusActionBar extends ImmutablePureComponent {
}
_makeMenu = (publicStatus) => {
const { status, intl, withDismiss, withGroupAdmin, me, isStaff, isAdmin } = this.props;
const { status, intl, withDismiss, withGroupAdmin, me, features, isStaff, isAdmin } = this.props;
const mutingConversation = status.get('muted');
const ownAccount = status.getIn(['account', 'id']) === me;
@ -303,7 +303,9 @@ class StatusActionBar extends ImmutablePureComponent {
// menu.push({ text: intl.formatMessage(messages.embed), action: this.handleEmbed });
}
if (features.bookmarks) {
menu.push({ text: intl.formatMessage(status.get('bookmarked') ? messages.unbookmark : messages.bookmark), action: this.handleBookmarkClick });
}
if (!me) {
return menu;

Wyświetl plik

@ -187,16 +187,21 @@ class Header extends ImmutablePureComponent {
menu.push({ text: intl.formatMessage(messages.showReblogs, { name: account.get('username') }), action: this.props.onReblogToggle });
}
if (features.accountSubscriptions) {
if (account.getIn(['relationship', 'subscribing'])) {
menu.push({ text: intl.formatMessage(messages.unsubscribe, { name: account.get('username') }), action: this.props.onSubscriptionToggle });
} else {
menu.push({ text: intl.formatMessage(messages.subscribe, { name: account.get('username') }), action: this.props.onSubscriptionToggle });
}
}
if (features.lists) {
menu.push({ text: intl.formatMessage(messages.add_or_remove_from_list), action: this.props.onAddToList });
}
// menu.push({ text: intl.formatMessage(account.getIn(['relationship', 'endorsed']) ? messages.unendorse : messages.endorse), action: this.props.onEndorseToggle });
menu.push(null);
} else if (features.unrestrictedLists) {
} else if (features.lists && features.unrestrictedLists) {
menu.push({ text: intl.formatMessage(messages.add_or_remove_from_list), action: this.props.onAddToList });
}

Wyświetl plik

@ -1,103 +0,0 @@
import React from 'react';
import { connect } from 'react-redux';
import { openModal } from '../../../actions/modal';
import PropTypes from 'prop-types';
import DropdownMenuContainer from '../../../containers/dropdown_menu_container';
import { isStaff } from 'soapbox/utils/accounts';
import { defineMessages, injectIntl } from 'react-intl';
import { logOut } from 'soapbox/actions/auth';
const messages = defineMessages({
profile: { id: 'account.profile', defaultMessage: 'Profile' },
messages: { id: 'navigation_bar.messages', defaultMessage: 'Messages' },
lists: { id: 'navigation_bar.lists', defaultMessage: 'Lists' },
bookmarks: { id: 'navigation_bar.bookmarks', defaultMessage: 'Bookmarks' },
preferences: { id: 'navigation_bar.preferences', defaultMessage: 'Preferences' },
follow_requests: { id: 'navigation_bar.follow_requests', defaultMessage: 'Follow requests' },
blocks: { id: 'navigation_bar.blocks', defaultMessage: 'Blocked users' },
domain_blocks: { id: 'navigation_bar.domain_blocks', defaultMessage: 'Hidden domains' },
mutes: { id: 'navigation_bar.mutes', defaultMessage: 'Muted users' },
filters: { id: 'navigation_bar.filters', defaultMessage: 'Muted words' },
admin_settings: { id: 'navigation_bar.admin_settings', defaultMessage: 'Admin settings' },
soapbox_config: { id: 'navigation_bar.soapbox_config', defaultMessage: 'Soapbox config' },
import_data: { id: 'navigation_bar.import_data', defaultMessage: 'Import data' },
security: { id: 'navigation_bar.security', defaultMessage: 'Security' },
logout: { id: 'navigation_bar.logout', defaultMessage: 'Logout' },
keyboard_shortcuts: { id: 'navigation_bar.keyboard_shortcuts', defaultMessage: 'Hotkeys' },
});
const mapStateToProps = state => {
const me = state.get('me');
return {
meUsername: state.getIn(['accounts', me, 'username']),
isStaff: isStaff(state.getIn(['accounts', me])),
};
};
const mapDispatchToProps = (dispatch, { intl }) => ({
onOpenHotkeys() {
dispatch(openModal('HOTKEYS'));
},
onClickLogOut(e) {
dispatch(logOut(intl));
e.preventDefault();
},
});
class ActionBar extends React.PureComponent {
static propTypes = {
intl: PropTypes.object.isRequired,
size: PropTypes.number,
onOpenHotkeys: PropTypes.func.isRequired,
onClickLogOut: PropTypes.func.isRequired,
meUsername: PropTypes.string,
isStaff: PropTypes.bool.isRequired,
};
static defaultProps = {
isStaff: false,
}
handleHotkeyClick = () => {
this.props.onOpenHotkeys();
}
render() {
const { intl, onClickLogOut, meUsername, isStaff } = this.props;
const size = this.props.size || 16;
const menu = [];
menu.push({ text: intl.formatMessage(messages.profile), to: `/@${meUsername}` });
menu.push({ text: intl.formatMessage(messages.lists), to: '/lists' });
menu.push({ text: intl.formatMessage(messages.bookmarks), to: '/bookmarks' });
menu.push(null);
menu.push({ text: intl.formatMessage(messages.follow_requests), to: '/follow_requests' });
menu.push({ text: intl.formatMessage(messages.mutes), to: '/mutes' });
menu.push({ text: intl.formatMessage(messages.blocks), to: '/blocks' });
menu.push({ text: intl.formatMessage(messages.domain_blocks), to: '/domain_blocks' });
menu.push({ text: intl.formatMessage(messages.filters), to: '/filters' });
menu.push(null);
menu.push({ text: intl.formatMessage(messages.keyboard_shortcuts), action: this.handleHotkeyClick });
if (isStaff) {
menu.push({ text: intl.formatMessage(messages.admin_settings), href: '/pleroma/admin', newTab: true });
menu.push({ text: intl.formatMessage(messages.soapbox_config), to: '/soapbox/config' });
}
menu.push({ text: intl.formatMessage(messages.preferences), to: '/settings/preferences' });
menu.push({ text: intl.formatMessage(messages.import_data), to: '/settings/import' });
menu.push({ text: intl.formatMessage(messages.security), to: '/auth/edit' });
menu.push({ text: intl.formatMessage(messages.logout), to: '/auth/sign_out', action: onClickLogOut });
return (
<div className='compose__action-bar' style={{ 'marginTop':'-6px' }}>
<div className='compose__action-bar-dropdown'>
<DropdownMenuContainer items={menu} icon='chevron-down' size={size} direction='right' />
</div>
</div>
);
}
}
export default injectIntl(connect(mapStateToProps, mapDispatchToProps)(ActionBar));

Wyświetl plik

@ -315,7 +315,9 @@ class ActionBar extends React.PureComponent {
// menu.push({ text: intl.formatMessage(messages.embed), action: this.handleEmbed });
}
if (features.bookmarks) {
menu.push({ text: intl.formatMessage(status.get('bookmarked') ? messages.unbookmark : messages.bookmark), action: this.handleBookmarkClick });
}
menu.push(null);

Wyświetl plik

@ -62,15 +62,19 @@ class FeaturesPanel extends React.PureComponent {
{intl.formatMessage(messages.follow_requests)}
</NavLink>}
{features.bookmarks && (
<NavLink className='promo-panel-item' to='/bookmarks'>
<Icon id='bookmark' className='promo-panel-item__icon' fixedWidth />
{intl.formatMessage(messages.bookmarks)}
</NavLink>
)}
{features.lists && (
<NavLink className='promo-panel-item' to='/lists'>
<Icon id='list' className='promo-panel-item__icon' fixedWidth />
{intl.formatMessage(messages.lists)}
</NavLink>
)}
{features.securityAPI ? (
<NavLink className='promo-panel-item' to='/auth/edit'>

Wyświetl plik

@ -3,32 +3,47 @@ import gte from 'semver/functions/gte';
import { List as ImmutableList, Map as ImmutableMap } from 'immutable';
import { createSelector } from 'reselect';
const any = arr => arr.some(Boolean);
// For uglification
const MASTODON = 'Mastodon';
const PLEROMA = 'Pleroma';
export const getFeatures = createSelector([
instance => parseVersion(instance.get('version')),
instance => instance.getIn(['pleroma', 'metadata', 'features'], ImmutableList()),
instance => instance.getIn(['pleroma', 'metadata', 'federation'], ImmutableMap()),
], (v, features, federation) => {
return {
suggestions: v.software === 'Mastodon' && gte(v.compatVersion, '2.4.3'),
suggestionsV2: v.software === 'Mastodon' && gte(v.compatVersion, '3.4.0'),
trends: v.software === 'Mastodon' && gte(v.compatVersion, '3.0.0'),
emojiReacts: v.software === 'Pleroma' && gte(v.version, '2.0.0'),
emojiReactsRGI: v.software === 'Pleroma' && gte(v.version, '2.2.49'),
attachmentLimit: v.software === 'Pleroma' ? Infinity : 4,
focalPoint: v.software === 'Mastodon' && gte(v.compatVersion, '2.3.0'),
importMutes: v.software === 'Pleroma' && gte(v.version, '2.2.0'),
bookmarks: any([
v.software === MASTODON && gte(v.compatVersion, '3.1.0'),
v.software === PLEROMA && gte(v.version, '0.9.9'),
]),
lists: any([
v.software === MASTODON && gte(v.compatVersion, '2.1.0'),
v.software === PLEROMA && gte(v.version, '0.9.9'),
]),
suggestions: v.software === MASTODON && gte(v.compatVersion, '2.4.3'),
suggestionsV2: v.software === MASTODON && gte(v.compatVersion, '3.4.0'),
trends: v.software === MASTODON && gte(v.compatVersion, '3.0.0'),
emojiReacts: v.software === PLEROMA && gte(v.version, '2.0.0'),
emojiReactsRGI: v.software === PLEROMA && gte(v.version, '2.2.49'),
attachmentLimit: v.software === PLEROMA ? Infinity : 4,
focalPoint: v.software === MASTODON && gte(v.compatVersion, '2.3.0'),
importMutes: v.software === PLEROMA && gte(v.version, '2.2.0'),
emailList: features.includes('email_list'),
chats: v.software === 'Pleroma' && gte(v.version, '2.1.0'),
scopes: v.software === 'Pleroma' ? 'read write follow push admin' : 'read write follow push',
chats: v.software === PLEROMA && gte(v.version, '2.1.0'),
scopes: v.software === PLEROMA ? 'read write follow push admin' : 'read write follow push',
federating: federation.get('enabled', true), // Assume true unless explicitly false
richText: v.software === 'Pleroma',
securityAPI: v.software === 'Pleroma',
settingsStore: v.software === 'Pleroma',
accountAliasesAPI: v.software === 'Pleroma',
resetPasswordAPI: v.software === 'Pleroma',
richText: v.software === PLEROMA,
securityAPI: v.software === PLEROMA,
settingsStore: v.software === PLEROMA,
accountAliasesAPI: v.software === PLEROMA,
resetPasswordAPI: v.software === PLEROMA,
exposableReactions: features.includes('exposable_reactions'),
accountSubscriptions: v.software === 'Pleroma' && gte(v.version, '1.0.0'),
unrestrictedLists: v.software === 'Pleroma',
accountSubscriptions: v.software === PLEROMA && gte(v.version, '1.0.0'),
unrestrictedLists: v.software === PLEROMA,
accountByUsername: v.software === PLEROMA,
};
});
@ -36,7 +51,7 @@ export const parseVersion = version => {
const regex = /^([\w\.]*)(?: \(compatible; ([\w]*) (.*)\))?$/;
const match = regex.exec(version);
return {
software: match[2] || 'Mastodon',
software: match[2] || MASTODON,
version: match[3] || match[1],
compatVersion: match[1],
};