Skip to content

Commit

Permalink
consolidate post stats, fix archive logic (steemit#1322)
Browse files Browse the repository at this point in the history
* eslint, cleanup, remove dead code steemit#1321

* consolidate netVoteSign and hasReplies into allowDelete. steemit#1321

* remove "pictures", replace with "!gray" steemit#1321

* fix long comparison bug steemit#1321

* allow replies indefinitely after hf17, close steemit#1321
  • Loading branch information
roadscape authored and Valentine Zavgorodnev committed Apr 11, 2017
1 parent c93fcd5 commit 579d374
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 66 deletions.
19 changes: 9 additions & 10 deletions app/components/cards/Comment.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ class CommentImpl extends React.Component {
console.error('Comment -- missing stats object')
comment.stats = {}
}
const {netVoteSign, hasReplies, authorRepLog10, pictures, gray} = comment.stats
const {allowDelete, authorRepLog10, gray} = comment.stats
const {author, json_metadata} = comment
const {username, depth, anchor_link,
showNegativeComments, ignore_list, noImage} = this.props
Expand Down Expand Up @@ -260,26 +260,25 @@ class CommentImpl extends React.Component {
// const get_asset_value = ( asset_str ) => { return parseFloat( asset_str.split(' ')[0] ); }
// const steem_supply = this.props.global.getIn(['props','current_supply']);

const showDeleteOption = username === author && !hasReplies && netVoteSign <= 0
const showDeleteOption = username === author && allowDelete
const showEditOption = username === author
const showReplyOption = comment.depth < 255
const archived = comment.cashout_time === '1969-12-31T23:59:59' // TODO: audit after HF17. #1259
const archived = comment.cashout_time === '1969-12-31T23:59:59' // TODO: audit after HF19. #1259
const readonly = archived || $STM_Config.read_only_mode

let body = null;
let controls = null;

if (!this.state.collapsed && !hide_body) {
body = (<MarkdownViewer formId={post + '-viewer'} text={comment.body}
noImage={noImage || !pictures} jsonMetadata={jsonMetadata} />);
noImage={noImage || gray} jsonMetadata={jsonMetadata} />);
controls = <div>
<Voting post={post} />
{!readonly &&
<span className="Comment__footer__controls">
{showReplyOption && <a onClick={onShowReply}>{translate('reply')}</a>}
{' '}{showEditOption && <a onClick={onShowEdit}>{translate('edit')}</a>}
{' '}{showDeleteOption && <a onClick={onDeletePost}>{translate('delete')}</a>}
</span>}
<span className="Comment__footer__controls">
{showReplyOption && <a onClick={onShowReply}>{translate('reply')}</a>}
{' '}{!readonly && showEditOption && <a onClick={onShowEdit}>{translate('edit')}</a>}
{' '}{!readonly && showDeleteOption && <a onClick={onDeletePost}>{translate('delete')}</a>}
</span>
</div>;
}

Expand Down
19 changes: 9 additions & 10 deletions app/components/cards/PostFull.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -277,12 +277,12 @@ class PostFull extends React.Component {
</div>)
}

const archived = post_content.get('cashout_time') === '1969-12-31T23:59:59' // TODO: audit after HF17. #1259
const archived = post_content.get('cashout_time') === '1969-12-31T23:59:59' // TODO: audit after HF19. #1259
const readonly = archived || $STM_Config.read_only_mode
const showPromote = username && post_content.get('last_payout') === '1970-01-01T00:00:00' && post_content.get('depth') == 0 // TODO: audit after HF17. #1259
const showPromote = username && !archived && post_content.get('depth') == 0
const showReplyOption = post_content.get('depth') < 255
const showEditOption = username === author
const showDeleteOption = username === author && post_content.get('children') === 0 && content.stats.netVoteSign <= 0
const showDeleteOption = username === author && content.stats.allowDelete

const authorRepLog10 = repLog10(content.author_reputation)
const isPreViewCount = Date.parse(post_content.get('created')) < 1480723200000 // check if post was created before view-count tracking began (2016-12-03)
Expand All @@ -298,7 +298,7 @@ class PostFull extends React.Component {
<TimeAuthorCategoryLarge content={content} authorRepLog10={authorRepLog10} />
</div>
<div className="PostFull__body entry-content">
<MarkdownViewer formId={formId + '-viewer'} text={content_body} jsonMetadata={jsonMetadata} large highQualityPost={high_quality_post} noImage={!content.stats.pictures} />
<MarkdownViewer formId={formId + '-viewer'} text={content_body} jsonMetadata={jsonMetadata} large highQualityPost={high_quality_post} noImage={content.stats.gray} />
</div>
</span>
}
Expand All @@ -312,12 +312,11 @@ class PostFull extends React.Component {
</div>
<div className="RightShare__Menu small-11 medium-5 large-5 columns text-right">
{!readonly && <Reblog author={author} permlink={permlink} />}
{!readonly &&
<span className="PostFull__reply">
{showReplyOption && <a onClick={onShowReply}>Reply</a>}
{' '}{showEditOption && !showEdit && <a onClick={onShowEdit}>Edit</a>}
{' '}{showDeleteOption && !showReply && <a onClick={onDeletePost}>Delete</a>}
</span>}
<span className="PostFull__reply">
{showReplyOption && <a onClick={onShowReply}>Reply</a>}
{' '}{!readonly && showEditOption && !showEdit && <a onClick={onShowEdit}>Edit</a>}
{' '}{!readonly && showDeleteOption && !showReply && <a onClick={onDeletePost}>Delete</a>}
</span>
<span className="PostFull__responses">
<Link to={link} title={pluralize('Responses', content.children, true)}>
<Icon name="chatboxes" className="space-right" />{content.children}
Expand Down
59 changes: 25 additions & 34 deletions app/components/cards/PostSummary.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import { Link } from 'react-router';
import { Link, browserHistory } from 'react-router';
import TimeAgoWrapper from 'app/components/elements/TimeAgoWrapper';
import Icon from 'app/components/elements/Icon';
import { connect } from 'react-redux';
Expand All @@ -8,11 +8,8 @@ import Reblog from 'app/components/elements/Reblog';
import Voting from 'app/components/elements/Voting';
import {immutableAccessor} from 'app/utils/Accessors';
import extractContent from 'app/utils/ExtractContent';
import { browserHistory } from 'react-router';
import VotesAndComments from 'app/components/elements/VotesAndComments';
import {authorNameAndRep} from 'app/utils/ComponentFormatters';
import {Map} from 'immutable';
import Reputation from 'app/components/elements/Reputation';
import Author from 'app/components/elements/Author';
import TagList from 'app/components/elements/TagList';
import UserNames from 'app/components/elements/UserNames';
Expand All @@ -38,7 +35,6 @@ class PostSummary extends React.Component {
pending_payout: React.PropTypes.string.isRequired,
total_payout: React.PropTypes.string.isRequired,
content: React.PropTypes.object.isRequired,
currentCategory: React.PropTypes.string,
thumbSize: React.PropTypes.string,
nsfwPref: React.PropTypes.string,
onClick: React.PropTypes.func
Expand All @@ -65,73 +61,68 @@ class PostSummary extends React.Component {
}

render() {
const {currentCategory, thumbSize, ignore, onClick} = this.props;
const {post, content, pending_payout, total_payout} = this.props;
const {thumbSize, ignore, onClick} = this.props;
const {post, content} = this.props;
const {account} = this.props;
if (!content) return null;

const archived = content.get('cashout_time') === '1969-12-31T23:59:59' // TODO: audit after HF17. #1259

let reblogged_by;
if(content.get('reblogged_by') && content.get('reblogged_by').size > 0) {
reblogged_by = content.get('reblogged_by').toJS()
} else if(content.get('first_reblogged_by')) {
// TODO: this case is backwards-compat for 0.16.1. remove after upgrading.
reblogged_by = [content.get('first_reblogged_by')]
}

if(reblogged_by) {
reblogged_by = <div className="PostSummary__reblogged_by">
<Icon name="reblog" /> Resteemed by <UserNames names={reblogged_by} />
</div>
reblogged_by = (<div className="PostSummary__reblogged_by">
<Icon name="reblog" /> Resteemed by <UserNames names={reblogged_by} />
</div>)
}

// 'account' is the current blog being viewed, if applicable.
if(account && account != content.get('author')) {
reblogged_by = <div className="PostSummary__reblogged_by">
<Icon name="reblog" /> Resteemed
</div>
reblogged_by = (<div className="PostSummary__reblogged_by">
<Icon name="reblog" /> Resteemed
</div>)
}

const {gray, pictures, authorRepLog10, flagWeight, isNsfw} = content.get('stats', Map()).toJS()
const {gray, authorRepLog10, flagWeight, isNsfw} = content.get('stats', Map()).toJS()
const p = extractContent(immutableAccessor, content);
let desc = p.desc
if(p.image_link)// image link is already shown in the preview
desc = desc.replace(p.image_link, '')
const desc = p.desc

const archived = content.get('cashout_time') === '1969-12-31T23:59:59' // TODO: audit after HF17. #1259
const full_power = content.get('percent_steem_dollars') === 0;

let title_link_url;
let title_text = p.title;
let comments_link;
let is_comment = false;
let full_power = content.get('percent_steem_dollars') === 0;

if( content.get( 'parent_author') !== "" ) {
title_text = "Re: " + content.get('root_title');
title_link_url = content.get( 'url' );
comments_link = title_link_url;
is_comment = true;
} else {
title_link_url = p.link;
comments_link = p.link + '#comments';
}

let content_body = <div className="PostSummary__body entry-content">
const content_body = (<div className="PostSummary__body entry-content">
<a href={title_link_url} onClick={e => navigate(e, onClick, post, title_link_url)}>{desc}</a>
</div>;
let content_title = <h3 className="entry-title">
</div>);
const content_title = (<h3 className="entry-title">
<a href={title_link_url} onClick={e => navigate(e, onClick, post, title_link_url)}>
{isNsfw && <span className="nsfw-flag">nsfw</span>}
{title_text}
{full_power && <span title="Powered Up 100%"><Icon name="steem" /></span>}
</a>
</h3>;
</h3>);

// author and category
let author_category = <span className="vcard">
const author_category = (<span className="vcard">
<a href={title_link_url} onClick={e => navigate(e, onClick, post, title_link_url)}><TimeAgoWrapper date={p.created} className="updated" /></a>
{} by <Author author={p.author} authorRepLog10={authorRepLog10} follow={false} mute={false} />
{} in <TagList post={p} single />
</span>
</span>);

const content_footer = <div className="PostSummary__footer">
const content_footer = (<div className="PostSummary__footer">
<Voting post={post} showList={false} />
<VotesAndComments post={post} commentsLink={comments_link} />
<span className="PostSummary__time_author_category">
Expand All @@ -140,7 +131,7 @@ class PostSummary extends React.Component {
{author_category}
</span>
</span>
</div>
</div>)

const {nsfwPref, username} = this.props
const {revealNsfw} = this.state
Expand Down Expand Up @@ -169,7 +160,7 @@ class PostSummary extends React.Component {
}

let thumb = null;
if(pictures && p.image_link) {
if(!gray && p.image_link) {
const prox = $STM_Config.img_proxy_prefix
const size = (thumbSize == 'mobile') ? '640x480' : '256x512';
const url = (prox ? prox + size + '/' : '') + p.image_link
Expand Down
1 change: 0 additions & 1 deletion app/components/cards/PostsList.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,6 @@ class PostsList extends React.Component {
<PostSummary
account={account}
post={item.item}
currentCategory={category}
thumbSize={thumbSize}
ignore={item.ignore}
onClick={this.onPostClick}
Expand Down
4 changes: 1 addition & 3 deletions app/redux/EmptyState.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,7 @@ export const emptyContent = {
authorRepLog10: 86,
gray: false,
hasPendingPayout: false,
hasReplies: false,
allowDelete: true,
hide: false,
netVoteSign: 0,
pictures: true,
},
}
13 changes: 5 additions & 8 deletions app/utils/StateFunctions.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,17 +98,14 @@ export function contentStats(content) {
const grayThreshold = -9999999999
const meetsGrayThreshold = net_rshares_adj.compare(grayThreshold) < 0

const net_rshares = Long.fromString(String(content.get('net_rshares')))
const netVoteSign = net_rshares.compare(Long.ZERO)
const pending_payout = content.get('pending_payout_value');
const hasPendingPayout = parsePayoutAmount(pending_payout) >= 0.02

// to be eligible for deletion, a comment must have non-positive rshares and no replies
const hasPositiveRshares = Long.fromString(String(content.get('net_rshares'))).gt(Long.ZERO)
const allowDelete = !hasPositiveRshares && content.get('children') === 0
const hasPendingPayout = parsePayoutAmount(content.get('pending_payout_value')) >= 0.02
const authorRepLog10 = repLog10(content.get('author_reputation'))
const hasReplies = content.get('replies').size !== 0

const gray = !hasPendingPayout && (authorRepLog10 < 1 || (authorRepLog10 < 65 && meetsGrayThreshold))
const hide = !hasPendingPayout && (authorRepLog10 < 0) // rephide
const pictures = !gray

// Combine tags+category to check nsfw status
const json = content.get('json_metadata')
Expand All @@ -126,5 +123,5 @@ export function contentStats(content) {
tags.push(content.get('category'))
const isNsfw = tags.filter(tag => tag && tag.match(/^nsfw$/i)).length > 0;

return {hide, gray, pictures, netVoteSign, authorRepLog10, hasReplies, isNsfw, flagWeight, total_votes, up_votes, hasPendingPayout}
return {hide, gray, authorRepLog10, allowDelete, isNsfw, flagWeight, total_votes, up_votes, hasPendingPayout}
}

0 comments on commit 579d374

Please sign in to comment.