Show user likes to others if hide_favorites===false

Signed-off-by: marcin mikołajczak <git@mkljczk.pl>
public-report
marcin mikołajczak 2021-09-09 20:05:54 +02:00
rodzic ccaf070cbe
commit 3672d9faa5
4 zmienionych plików z 219 dodań i 28 usunięć

Wyświetl plik

@ -10,6 +10,14 @@ export const FAVOURITED_STATUSES_EXPAND_REQUEST = 'FAVOURITED_STATUSES_EXPAND_RE
export const FAVOURITED_STATUSES_EXPAND_SUCCESS = 'FAVOURITED_STATUSES_EXPAND_SUCCESS';
export const FAVOURITED_STATUSES_EXPAND_FAIL = 'FAVOURITED_STATUSES_EXPAND_FAIL';
export const USER_FAVOURITED_STATUSES_FETCH_REQUEST = 'USER_FAVOURITED_STATUSES_FETCH_REQUEST';
export const USER_FAVOURITED_STATUSES_FETCH_SUCCESS = 'USER_FAVOURITED_STATUSES_FETCH_SUCCESS';
export const USER_FAVOURITED_STATUSES_FETCH_FAIL = 'USER_FAVOURITED_STATUSES_FETCH_FAIL';
export const USER_FAVOURITED_STATUSES_EXPAND_REQUEST = 'USER_FAVOURITED_STATUSES_EXPAND_REQUEST';
export const USER_FAVOURITED_STATUSES_EXPAND_SUCCESS = 'USER_FAVOURITED_STATUSES_EXPAND_SUCCESS';
export const USER_FAVOURITED_STATUSES_EXPAND_FAIL = 'USER_FAVOURITED_STATUSES_EXPAND_FAIL';
export function fetchFavouritedStatuses() {
return (dispatch, getState) => {
if (!isLoggedIn(getState)) return;
@ -96,3 +104,96 @@ export function expandFavouritedStatusesFail(error) {
error,
};
}
export function fetchUserFavouritedStatuses(accountId) {
return (dispatch, getState) => {
if (!isLoggedIn(getState)) return;
if (getState().getIn(['status_lists', `favourites:${accountId}`, 'isLoading'])) {
return;
}
dispatch(fetchUserFavouritedStatusesRequest(accountId));
api(getState).get(`/api/v1/pleroma/accounts/${accountId}/favourites`).then(response => {
const next = getLinks(response).refs.find(link => link.rel === 'next');
dispatch(importFetchedStatuses(response.data));
dispatch(fetchUserFavouritedStatusesSuccess(accountId, response.data, next ? next.uri : null));
}).catch(error => {
dispatch(fetchUserFavouritedStatusesFail(accountId, error));
});
};
}
export function fetchUserFavouritedStatusesRequest(accountId) {
return {
type: USER_FAVOURITED_STATUSES_FETCH_REQUEST,
accountId,
skipLoading: true,
};
}
export function fetchUserFavouritedStatusesSuccess(accountId, statuses, next) {
return {
type: USER_FAVOURITED_STATUSES_FETCH_SUCCESS,
accountId,
statuses,
next,
skipLoading: true,
};
}
export function fetchUserFavouritedStatusesFail(accountId, error) {
return {
type: USER_FAVOURITED_STATUSES_FETCH_FAIL,
accountId,
error,
skipLoading: true,
};
}
export function expandUserFavouritedStatuses(accountId) {
return (dispatch, getState) => {
if (!isLoggedIn(getState)) return;
const url = getState().getIn(['status_lists', `favourites:${accountId}`, 'next'], null);
if (url === null || getState().getIn(['status_lists', `favourites:${accountId}`, 'isLoading'])) {
return;
}
dispatch(expandUserFavouritedStatusesRequest(accountId));
api(getState).get(url).then(response => {
const next = getLinks(response).refs.find(link => link.rel === 'next');
dispatch(importFetchedStatuses(response.data));
dispatch(expandUserFavouritedStatusesSuccess(accountId, response.data, next ? next.uri : null));
}).catch(error => {
dispatch(expandUserFavouritedStatusesFail(accountId, error));
});
};
}
export function expandUserFavouritedStatusesRequest(accountId) {
return {
type: USER_FAVOURITED_STATUSES_EXPAND_REQUEST,
accountId,
};
}
export function expandUserFavouritedStatusesSuccess(accountId, statuses, next) {
return {
type: USER_FAVOURITED_STATUSES_EXPAND_SUCCESS,
accountId,
statuses,
next,
};
}
export function expandUserFavouritedStatusesFail(accountId, error) {
return {
type: USER_FAVOURITED_STATUSES_EXPAND_FAIL,
accountId,
error,
};
}

Wyświetl plik

@ -356,24 +356,20 @@ class Header extends ImmutablePureComponent {
<span><FormattedMessage id='account.followers' defaultMessage='Followers' /></span>
</NavLink>}
{
ownAccount &&
<div>
<NavLink
exact activeClassName='active' to={`/@${account.get('acct')}/favorites`}
>
{ /* : TODO : shortNumberFormat(account.get('favourite_count')) */ }
<span></span>
<span><FormattedMessage id='navigation_bar.favourites' defaultMessage='Likes' /></span>
</NavLink>
<NavLink
exact activeClassName='active' to={`/@${account.get('acct')}/pins`}
>
{ /* : TODO : shortNumberFormat(account.get('pinned_count')) */ }
<span></span>
<span><FormattedMessage id='navigation_bar.pins' defaultMessage='Pins' /></span>
</NavLink>
</div>
{(ownAccount || !account.getIn(['pleroma', 'hide_favorites'], true)) && <NavLink exact activeClassName='active' to={`/@${account.get('acct')}/favorites`}>
{ /* : TODO : shortNumberFormat(account.get('favourite_count')) */ }
<span></span>
<span><FormattedMessage id='navigation_bar.favourites' defaultMessage='Likes' /></span>
</NavLink>}
{ownAccount &&
<NavLink
exact activeClassName='active' to={`/@${account.get('acct')}/pins`}
>
{ /* : TODO : shortNumberFormat(account.get('pinned_count')) */ }
<span></span>
<span><FormattedMessage id='navigation_bar.pins' defaultMessage='Pins' /></span>
</NavLink>
}
</div>

Wyświetl plik

@ -2,23 +2,55 @@ import React from 'react';
import { connect } from 'react-redux';
import PropTypes from 'prop-types';
import ImmutablePropTypes from 'react-immutable-proptypes';
import { fetchFavouritedStatuses, expandFavouritedStatuses } from '../../actions/favourites';
import { fetchFavouritedStatuses, expandFavouritedStatuses, fetchUserFavouritedStatuses, expandUserFavouritedStatuses } from '../../actions/favourites';
import Column from '../ui/components/column';
import StatusList from '../../components/status_list';
import { injectIntl, FormattedMessage } from 'react-intl';
import ImmutablePureComponent from 'react-immutable-pure-component';
import { debounce } from 'lodash';
import MissingIndicator from 'soapbox/components/missing_indicator';
import { fetchAccount, fetchAccountByUsername } from '../../actions/accounts';
import LoadingIndicator from '../../components/loading_indicator';
const mapStateToProps = (state, { params }) => {
const username = params.username || '';
const me = state.get('me');
const meUsername = state.getIn(['accounts', me, 'username']);
const isMyAccount = (username.toLowerCase() === meUsername.toLowerCase());
if (isMyAccount) {
return {
isMyAccount,
statusIds: state.getIn(['status_lists', 'favourites', 'items']),
isLoading: state.getIn(['status_lists', 'favourites', 'isLoading'], true),
hasMore: !!state.getIn(['status_lists', 'favourites', 'next']),
};
}
const accounts = state.getIn(['accounts']);
const accountFetchError = (state.getIn(['accounts', -1, 'username'], '').toLowerCase() === username.toLowerCase());
let accountId = -1;
if (accountFetchError) {
accountId = null;
} else {
const account = accounts.find(acct => username.toLowerCase() === acct.getIn(['acct'], '').toLowerCase());
accountId = account ? account.getIn(['id'], null) : -1;
}
const isBlocked = state.getIn(['relationships', accountId, 'blocked_by'], false);
const unavailable = (me === accountId) ? false : isBlocked;
return {
isMyAccount: (username.toLowerCase() === meUsername.toLowerCase()),
statusIds: state.getIn(['status_lists', 'favourites', 'items']),
isLoading: state.getIn(['status_lists', 'favourites', 'isLoading'], true),
hasMore: !!state.getIn(['status_lists', 'favourites', 'next']),
isMyAccount,
accountId,
unavailable,
username,
isAccount: !!state.getIn(['accounts', accountId]),
statusIds: state.getIn(['status_lists', `favourites:${accountId}`, 'items'], []),
isLoading: state.getIn(['status_lists', `favourites:${accountId}`, 'isLoading'], true),
hasMore: !!state.getIn(['status_lists', `favourites:${accountId}`, 'next']),
};
};
@ -36,17 +68,43 @@ class Favourites extends ImmutablePureComponent {
};
componentDidMount() {
this.props.dispatch(fetchFavouritedStatuses());
const { accountId, isMyAccount, username } = this.props;
if (isMyAccount)
this.props.dispatch(fetchFavouritedStatuses());
else {
if (accountId && accountId !== -1) {
this.props.dispatch(fetchAccount(accountId));
this.props.dispatch(fetchUserFavouritedStatuses(accountId));
} else {
this.props.dispatch(fetchAccountByUsername(username));
}
}
}
componentDidUpdate(prevProps) {
const { accountId, isMyAccount } = this.props;
if (!isMyAccount && accountId && accountId !== -1 && (accountId !== prevProps.accountId && accountId)) {
this.props.dispatch(fetchAccount(accountId));
this.props.dispatch(fetchUserFavouritedStatuses(accountId));
}
}
handleLoadMore = debounce(() => {
this.props.dispatch(expandFavouritedStatuses());
const { accountId, isMyAccount } = this.props;
if (isMyAccount) {
this.props.dispatch(expandFavouritedStatuses());
} else {
this.props.dispatch(expandUserFavouritedStatuses(accountId));
}
}, 300, { leading: true })
render() {
const { statusIds, hasMore, isLoading, isMyAccount } = this.props;
const { statusIds, isLoading, hasMore, isMyAccount, isAccount, accountId, unavailable } = this.props;
if (!isMyAccount) {
if (!isMyAccount && !isAccount && accountId !== -1) {
return (
<Column>
<MissingIndicator />
@ -54,7 +112,27 @@ class Favourites extends ImmutablePureComponent {
);
}
const emptyMessage = <FormattedMessage id='empty_column.favourited_statuses' defaultMessage="You don't have any liked posts yet. When you like one, it will show up here." />;
if (accountId === -1) {
return (
<Column>
<LoadingIndicator />
</Column>
);
}
if (unavailable) {
return (
<Column>
<div className='empty-column-indicator'>
<FormattedMessage id='empty_column.account_unavailable' defaultMessage='Profile unavailable' />
</div>
</Column>
);
}
const emptyMessage = isMyAccount
? <FormattedMessage id='empty_column.favourited_statuses' defaultMessage="You don't have any liked posts yet. When you like one, it will show up here." />
: <FormattedMessage id='empty_column.account_favourited_statuses' defaultMessage="This user doesn't have any liked posts yet." />;
return (
<Column>

Wyświetl plik

@ -5,6 +5,12 @@ import {
FAVOURITED_STATUSES_EXPAND_REQUEST,
FAVOURITED_STATUSES_EXPAND_SUCCESS,
FAVOURITED_STATUSES_EXPAND_FAIL,
USER_FAVOURITED_STATUSES_FETCH_REQUEST,
USER_FAVOURITED_STATUSES_FETCH_SUCCESS,
USER_FAVOURITED_STATUSES_FETCH_FAIL,
USER_FAVOURITED_STATUSES_EXPAND_REQUEST,
USER_FAVOURITED_STATUSES_EXPAND_SUCCESS,
USER_FAVOURITED_STATUSES_EXPAND_FAIL,
} from '../actions/favourites';
import {
BOOKMARKED_STATUSES_FETCH_REQUEST,
@ -101,6 +107,16 @@ export default function statusLists(state = initialState, action) {
return normalizeList(state, 'favourites', action.statuses, action.next);
case FAVOURITED_STATUSES_EXPAND_SUCCESS:
return appendToList(state, 'favourites', action.statuses, action.next);
case USER_FAVOURITED_STATUSES_FETCH_REQUEST:
case USER_FAVOURITED_STATUSES_EXPAND_REQUEST:
return setLoading(state, `favourites:${action.accountId}`, true);
case USER_FAVOURITED_STATUSES_FETCH_FAIL:
case USER_FAVOURITED_STATUSES_EXPAND_FAIL:
return setLoading(state, `favourites:${action.accountId}`, false);
case USER_FAVOURITED_STATUSES_FETCH_SUCCESS:
return normalizeList(state, `favourites:${action.accountId}`, action.statuses, action.next);
case USER_FAVOURITED_STATUSES_EXPAND_SUCCESS:
return appendToList(state, `favourites:${action.accountId}`, action.statuses, action.next);
case BOOKMARKED_STATUSES_FETCH_REQUEST:
case BOOKMARKED_STATUSES_EXPAND_REQUEST:
return setLoading(state, 'bookmarks', true);