Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export function contentStats(content, precision) {
if (!content) return {};
if (!(content instanceof Map)) content = fromJS(content);
let net_rshares_adj = Long.ZERO;
let neg_rshares = Long.ZERO;
let total_votes = 0;
let up_votes = 0;
const minDigits = precision
? Math.max(0, precision - 2)
: Math.log10(SCOT_DENOM) - 2;
// TODO: breaks if content has no active_votes attribute.
content.get('active_votes').forEach(v => {
const sign = Math.sign(v.get('percent'));
if (sign === 0) return;
total_votes += 1;
if (sign > 0) up_votes += 1;
export function contentStats(content) {
if(!content) return {}
if(!(content instanceof Map)) content = fromJS(content);
let net_rshares_adj = Long.ZERO
let neg_rshares = Long.ZERO
let total_votes = 0;
let up_votes = 0;
content.get('active_votes').forEach((v) => {
const sign = Math.sign(v.get('percent'))
if(sign === 0) return;
total_votes += 1
if(sign > 0) up_votes += 1
const rshares = String(v.get('rshares'))
// For flag weight: count total neg rshares
if(sign < 0) {
neg_rshares = neg_rshares.add(rshares)
}
export function contentStats(content, precision) {
if (!content) return {};
if (!(content instanceof Map)) content = fromJS(content);
let net_rshares_adj = Long.ZERO;
let neg_rshares = Long.ZERO;
let total_votes = 0;
let up_votes = 0;
const minDigits = precision
? Math.max(0, precision - 2)
: Math.log10(SCOT_DENOM) - 2;
// TODO: breaks if content has no active_votes attribute.
content.get('active_votes').forEach(v => {
const sign = Math.sign(v.get('percent'));
if (sign === 0) return;
total_votes += 1;
if (sign > 0) up_votes += 1;
const rshares = String(v.get('rshares'));
export function contentStats(content) {
if(!content) return {}
if(!(content instanceof Map)) content = fromJS(content);
let net_rshares_adj = Long.ZERO
let neg_rshares = Long.ZERO
let total_votes = 0;
let up_votes = 0;
content.get('active_votes').forEach((v) => {
const sign = Math.sign(v.get('percent'))
if(sign === 0) return;
total_votes += 1
if(sign > 0) up_votes += 1
const rshares = String(v.get('rshares'))
// For flag weight: count total neg rshares
if(sign < 0) {
neg_rshares = neg_rshares.add(rshares)
}
const content_body = content.body;
const {category, title, body} = content;
if (process.env.BROWSER && title) document.title = title + ' — Steemit';
const replyParams = {author, permlink, parent_author, parent_permlink, category, title, body}
let net_rshares = Long.ZERO
post_content.get('active_votes', List()).forEach(v => {
// ? Remove negative votes unless full power -1000 (we had downvoting spam)
const percent = v.get('percent')
if(percent < 0 /*&& percent !== -1000*/) return
net_rshares = net_rshares.add(Long.fromString(String(v.get('rshares'))))
})
const showDeleteOption = username === author &&
post_content.get('replies', List()).size === 0 &&
net_rshares.compare(Long.ZERO) <= 0
this.share_params = {
url: 'https://steemit.com' + link,
title: title + ' — Steemit',
desc: p.desc
};
const share_menu = [
{link: '#', onClick: this.fbShare, value: 'Facebook', icon: 'facebook'},
{link: '#', onClick: this.twitterShare, value: 'Twitter', icon: 'twitter'},
{link: '#', onClick: this.linkedInShare, value: 'LinkedIn', icon: 'linkedin'},
];
const Editor = this.state.showReply ? PostFullReplyEditor : PostFullEditEditor
let renderedEditor = null;
if (showReply || showEdit) {
renderedEditor = <div></div>
// take negative rshares, divide by 2, truncate 10 digits (plus neg sign), count digits.
// creates a cheap log10, stake-based flag weight. 1 = approx $400 of downvoting stake; 2 = $4,000; etc
const flagWeight = Math.max(
String(neg_rshares.div(2)).length - minDigits - 1,
0
);
// post must have non-trivial negative rshares to be grayed out. (more than 10 digits)
const grayThreshold = -(Math.pow(10, minDigits) - 1);
const meetsGrayThreshold = net_rshares_adj.compare(grayThreshold) < 0;
// 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;
// Expecting this to come from SCOT data.
const hasPendingPayout =
(content.has('vote_rshares') &&
parsePayoutAmount(content.get('vote_rshares')) > 0) ||
parsePayoutAmount(content.get('pending_payout_value')) >= 0.02;
const authorRepLog10 = repLog10(content.get('author_reputation'));
const gray =
!hasPendingPayout && (authorRepLog10 < 1 || meetsGrayThreshold);
const hide = !hasPendingPayout && authorRepLog10 < 0; // rephide
// Combine tags+category to check nsfw status
const json = content.get('json_metadata');
let tags = [];
try {
if (!post_content) return null;
const p = extractContent(immutableAccessor, post_content);
const content = post_content.toJS();
const {author, permlink, parent_author, parent_permlink} = content
const jsonMetadata = this.state.showReply ? null : p.json_metadata
// let author_link = '/@' + content.author;
let link = `/@${content.author}/${content.permlink}`;
if (content.category) link = `/${content.category}${link}`;
const content_body = content.body;
const {category, title, body} = content;
if (process.env.BROWSER && title) document.title = title + ' — Steemit';
const replyParams = {author, permlink, parent_author, parent_permlink, category, title, body}
let net_rshares = Long.ZERO
post_content.get('active_votes', List()).forEach(v => {
// ? Remove negative votes unless full power -1000 (we had downvoting spam)
const percent = v.get('percent')
if(percent < 0 /*&& percent !== -1000*/) return
net_rshares = net_rshares.add(Long.fromString(String(v.get('rshares'))))
})
const showDeleteOption = username === author &&
post_content.get('replies', List()).size === 0 &&
net_rshares.compare(Long.ZERO) <= 0
this.share_params = {
url: 'https://steemit.com' + link,
title: title + ' — Steemit',
desc: p.desc
};
if(!(rshares.substring(0, 1) === '-' && rshares.length < 11)) {
net_rshares_adj = net_rshares_adj.add(rshares)
}
}
});
// take negative rshares, divide by 2, truncate 10 digits (plus neg sign), count digits.
// creates a cheap log10, stake-based flag weight. 1 = approx $400 of downvoting stake; 2 = $4,000; etc
const flagWeight = Math.max(String(neg_rshares.div(2)).length - 11, 0)
// post must have non-trivial negative rshares to be grayed out. (more than 10 digits)
const grayThreshold = -9999999999
const meetsGrayThreshold = net_rshares_adj.compare(grayThreshold) < 0
// 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 gray = !hasPendingPayout && (authorRepLog10 < 1 || (authorRepLog10 < 65 && meetsGrayThreshold))
const hide = !hasPendingPayout && (authorRepLog10 < 0) // rephide
// Combine tags+category to check nsfw status
const json = content.get('json_metadata')
let tags = []
try {
tags = (json && JSON.parse(json).tags) || [];
if(typeof tags == 'string') {
tags = [tags];
} if(!Array.isArray(tags)) {
tags = [];