Skip to content

Commit

Permalink
Merge pull request steemit#3011 from steemit/eonwarped-eonwarped_filt…
Browse files Browse the repository at this point in the history
…erresteem

Community - Filter Resteemed Posts from Individual User Profile Feed
  • Loading branch information
roadscape authored Oct 2, 2018
2 parents 2e517ac + a6fdd0e commit fd1160f
Show file tree
Hide file tree
Showing 7 changed files with 428 additions and 53 deletions.
10 changes: 7 additions & 3 deletions src/app/components/cards/PostsList.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class PostsList extends React.Component {
category: PropTypes.string,
loadMore: PropTypes.func,
showSpam: PropTypes.bool,
showResteem: PropTypes.bool,
fetchState: PropTypes.func.isRequired,
pathname: PropTypes.string,
nsfwPref: PropTypes.string.isRequired,
Expand Down Expand Up @@ -113,9 +114,9 @@ class PostsList extends React.Component {
topPosition(el) + el.offsetHeight - scrollTop - window.innerHeight <
10
) {
const { loadMore, posts, category } = this.props;
const { loadMore, posts, category, showResteem } = this.props;
if (loadMore && posts && posts.size)
loadMore(posts.last(), category);
loadMore(posts.last(), category, showResteem);
}
// Detect if we're in mobile mode (renders larger preview imgs)
const mq = window.matchMedia('screen and (max-width: 39.9375em)');
Expand Down Expand Up @@ -146,6 +147,7 @@ class PostsList extends React.Component {
render() {
const {
posts,
showResteem,
showSpam,
loading,
category,
Expand All @@ -164,8 +166,10 @@ class PostsList extends React.Component {
}
const ignore =
ignore_result && ignore_result.has(cont.get('author'));
const hideResteem =
!showResteem && account && cont.get('author') != account;
const hide = cont.getIn(['stats', 'hide']);
if (!(ignore || hide) || showSpam)
if (!hideResteem && (!(ignore || hide) || showSpam))
// rephide
postsInfo.push({ item, ignore });
});
Expand Down
49 changes: 36 additions & 13 deletions src/app/components/pages/UserProfile.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { Link } from 'react-router';
import { connect } from 'react-redux';
import { browserHistory } from 'react-router';
import classnames from 'classnames';
import * as globalActions from 'app/redux/GlobalReducer';
import * as transactionActions from 'app/redux/TransactionReducer';
import * as userActions from 'app/redux/UserReducer';
import { actions as fetchDataSagaActions } from 'app/redux/FetchDataSaga';
Expand All @@ -23,6 +24,7 @@ import { repLog10 } from 'app/utils/ParsersAndFormatters.js';
import Tooltip from 'app/components/elements/Tooltip';
import DateJoinWrapper from 'app/components/elements/DateJoinWrapper';
import tt from 'counterpart';
import { List } from 'immutable';
import WalletSubMenu from 'app/components/elements/WalletSubMenu';
import Userpic from 'app/components/elements/Userpic';
import Callout from 'app/components/elements/Callout';
Expand All @@ -36,14 +38,14 @@ import DropdownMenu from 'app/components/elements/DropdownMenu';
export default class UserProfile extends React.Component {
constructor() {
super();
this.state = {};
this.state = { showResteem: true };
this.onPrint = () => {
window.print();
};
this.loadMore = this.loadMore.bind(this);
}

shouldComponentUpdate(np) {
shouldComponentUpdate(np, ns) {
const { follow } = this.props;
const { follow_count } = this.props;

Expand Down Expand Up @@ -85,7 +87,8 @@ export default class UserProfile extends React.Component {
np.location.pathname !== this.props.location.pathname ||
np.routeParams.accountname !== this.props.routeParams.accountname ||
np.follow_count !== this.props.follow_count ||
np.blogmode !== this.props.blogmode
np.blogmode !== this.props.blogmode ||
ns.showResteem !== this.state.showResteem
);
}

Expand All @@ -94,8 +97,9 @@ export default class UserProfile extends React.Component {
this.props.clearPowerdownDefaults();
}

loadMore(last_post, category) {
loadMore(last_post, category, showResteem) {
const { accountname } = this.props.routeParams;

if (!last_post) return;

let order;
Expand All @@ -122,20 +126,33 @@ export default class UserProfile extends React.Component {
order,
category
)
)
) {
return;
}

const postFilter = showResteem
? null
: value => value.author === accountname;
const [author, permlink] = last_post.split('/');
this.props.requestData({
author,
permlink,
order,
category,
accountname,
postFilter,
});
}

toggleShowResteem = e => {
e.preventDefault();
const newShowResteem = !this.state.showResteem;
this.setState({ showResteem: newShowResteem });
};

render() {
const {
state: { showResteem },
props: { current_user, wifShown, global_status, follow },
onPrint,
} = this;
Expand Down Expand Up @@ -326,14 +343,20 @@ export default class UserProfile extends React.Component {
tab_content = <Callout>{emptyText}</Callout>;
} else {
tab_content = (
<PostsList
account={account.name}
posts={posts}
loading={fetching}
category="blog"
loadMore={this.loadMore}
showSpam
/>
<div>
<a href="#" onClick={this.toggleShowResteem}>
{showResteem ? 'Hide resteems' : 'Show all'}
</a>
<PostsList
account={account.name}
posts={posts}
loading={fetching}
category="blog"
loadMore={this.loadMore}
showResteem={showResteem}
showSpam
/>
</div>
);
}
} else {
Expand Down
58 changes: 46 additions & 12 deletions src/app/redux/FetchDataSaga.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ function* getAccounts(usernames) {
}

export function* fetchData(action) {
const { order, author, permlink, accountname } = action.payload;
const { order, author, permlink, accountname, postFilter } = action.payload;
let { category } = action.payload;
if (!category) category = '';
category = category.toLowerCase();
Expand Down Expand Up @@ -293,17 +293,51 @@ export function* fetchData(action) {
}
yield put(appActions.fetchDataBegin());
try {
const data = yield call([api, api[call_name]], ...args);
yield put(
globalActions.receiveData({
data,
order,
category,
author,
permlink,
accountname,
})
);
const firstPermlink = permlink;
var fetched = 0;
var endOfData = false;
var fetchLimitReached = false;
var fetchDone = false;
var batch = 0;
while (!fetchDone) {
var data = yield call([api, api[call_name]], ...args);

endOfData = data.length < constants.FETCH_DATA_BATCH_SIZE;

batch++;
fetchLimitReached = batch >= constants.MAX_BATCHES;

// next arg. Note 'by_replies' does not use same structure.
const lastValue = data.length > 0 ? data[data.length - 1] : null;
if (lastValue && order !== 'by_replies') {
args[0].start_author = lastValue.author;
args[0].start_permlink = lastValue.permlink;
}

// Still return all data but only count ones matching the filter.
// Rely on UI to actually hide the posts.
fetched += postFilter
? data.filter(postFilter).length
: data.length;

fetchDone =
endOfData ||
fetchLimitReached ||
fetched >= constants.FETCH_DATA_BATCH_SIZE;

yield put(
globalActions.receiveData({
data,
order,
category,
author,
firstPermlink,
accountname,
fetching: !fetchDone,
endOfData,
})
);
}
} catch (error) {
console.error('~~ Saga fetchData error ~~>', call_name, args, error);
yield put(appActions.steemApiError(error.message));
Expand Down
Loading

0 comments on commit fd1160f

Please sign in to comment.