From 66561200b5c0bb24ccb65487289729414b87ce2b Mon Sep 17 00:00:00 2001 From: Z Date: Fri, 25 Oct 2019 22:22:19 +0800 Subject: [PATCH] show comments on timeline, and show right count when unfavourite/unreblog --- .../mastodon/actions/interactions.js | 10 +++++-- app/javascript/mastodon/components/status.js | 26 +++++++------------ .../mastodon/containers/status_container.js | 5 ++++ 3 files changed, 22 insertions(+), 19 deletions(-) diff --git a/app/javascript/mastodon/actions/interactions.js b/app/javascript/mastodon/actions/interactions.js index 2dc4c574c..d184f32f2 100644 --- a/app/javascript/mastodon/actions/interactions.js +++ b/app/javascript/mastodon/actions/interactions.js @@ -52,8 +52,11 @@ export function unreblog(status) { return (dispatch, getState) => { dispatch(unreblogRequest(status)); + let old_reblogs_count = status.get('reblogs_count'); api(getState).post(`/api/v1/statuses/${status.get('id')}/unreblog`).then(response => { - dispatch(importFetchedStatus(response.data)); + let pred = response.data + pred.reblogs_count = old_reblogs_count - 1; // unreb is async + dispatch(importFetchedStatus(pred)); dispatch(unreblogSuccess(status)); }).catch(error => { dispatch(unreblogFail(status, error)); @@ -128,8 +131,11 @@ export function unfavourite(status) { return (dispatch, getState) => { dispatch(unfavouriteRequest(status)); + let old_favourites_count = status.get('favourites_count'); api(getState).post(`/api/v1/statuses/${status.get('id')}/unfavourite`).then(response => { - dispatch(importFetchedStatus(response.data)); + let pred = response.data + pred.favourites_count = old_favourites_count - 1; // unfav is async + dispatch(importFetchedStatus(pred)); dispatch(unfavouriteSuccess(status)); }).catch(error => { dispatch(unfavouriteFail(status, error)); diff --git a/app/javascript/mastodon/components/status.js b/app/javascript/mastodon/components/status.js index 9f8535c8c..d1bff4524 100644 --- a/app/javascript/mastodon/components/status.js +++ b/app/javascript/mastodon/components/status.js @@ -91,6 +91,7 @@ class Status extends ImmutablePureComponent { cachedMediaWidth: PropTypes.number, sonsIds: ImmutablePropTypes.list, + onPreview: PropTypes.func }; // Avoid checking props that are functions (and whose equality will always @@ -100,6 +101,7 @@ class Status extends ImmutablePureComponent { 'account', 'muted', 'hidden', + 'sonsIds' ]; state = { @@ -110,6 +112,10 @@ class Status extends ImmutablePureComponent { // Track height changes we know about to compensate scrolling componentDidMount () { this.didShowCard = !this.props.muted && !this.props.hidden && this.props.status && this.props.status.get('card'); + if(this.props.com_prev) { + const { status } = this.props; + this.props.onPreview(status.get('id')); + } } getSnapshotBeforeUpdate () { @@ -260,7 +266,7 @@ class Status extends ImmutablePureComponent { handleHotkeyToggleSensitive = () => { this.handleToggleMediaVisibility(); } - + _properStatus () { const { status } = this.props; @@ -275,22 +281,8 @@ class Status extends ImmutablePureComponent { this.node = c; } - renderChildren (list) { - /* - return list.map(id => ( - - )); - */ + renderChildren (list) { return list.map(id => ( {prepend} -
+
diff --git a/app/javascript/mastodon/containers/status_container.js b/app/javascript/mastodon/containers/status_container.js index a15ece512..889227002 100644 --- a/app/javascript/mastodon/containers/status_container.js +++ b/app/javascript/mastodon/containers/status_container.js @@ -20,6 +20,7 @@ import { deleteStatus, hideStatus, revealStatus, + fetchContext, } from '../actions/statuses'; import { initMuteModal } from '../actions/mutes'; import { initBlockModal } from '../actions/blocks'; @@ -163,6 +164,10 @@ const mapDispatchToProps = (dispatch, { intl }) => ({ } }, + onPreview (id) { + dispatch(fetchContext(id)); + }, + }); export default injectIntl(connect(makeMapStateToProps, mapDispatchToProps)(Status));