Post/Comment Delete Authority | Steemit Condenser Official

in Steem Alliance2 years ago

Hello Programmers,

I hope you all are well. I am very well sure that many new developers are working on Steem and they want to build some useful tools for Steem Blockchain. Our team is working on SteemPro Mobile App for the last 6 months, During this time frame we also launch SteemPro

condonsor1.png

To educate the new developers and also to the whole steemit users, We arrange this bi-weekly post in which we explore the code of official Steemit. You can get the GitHub repository here.

We will also modify the code to convert it into TypeScript and make the necessary changes to work with the SDS APIs provided by @steemchiller.

File Path

steemit/condenser/src/app/utils/StateFunctions.js

Function

allowDelete

Code

export function allowDelete(comment) {
    const rshares = String(comment.get('net_rshares'));
    const hasPayout = !(rshares[0] == '0' || rshares[0] == '-');
    const hasChildren = comment.get('children') !== 0;
    const archived = comment.get('is_paidout');
    return !(hasPayout || hasChildren) && !archived;
}

Working

This function helps to render the delete button to a post or a comment on Steemit. There are some conditions that need to be true to get the deleted authority.

We can not delete the post if:
If a comment or post has a child (reply).
If a comment or post has a pending reward.
If comment or post author is not same as the login author.

Typescript

export function allowDelete(comment: PostType | FeedType) {
  const rshares = comment.net_rshares;
  const hasPayout = !(rshares === 0);
  const hasUpvotes = !(
    comment.upvote_count === 0 && comment.downvote_count === 0
  );
  const hasChildren = comment.children !== 0;
  return !(hasPayout || hasChildren || hasUpvotes);
}

What's new

We add types in the code, In the future we will also discuss the PostType and the FeedType interfaces. These interfaces are derived from the SDS Feed and Post APIs.

We set a check for the upvote count and for the downvote count.

SteemPro Official

@steempro.com
https://www.steempro.com

▀▄▀▄▀▄ T̳̿͟͞h̳̿͟͞a̳̿͟͞n̳̿͟͞k̳̿͟͞s̳̿͟͞ ̳̿͟͞f̳̿͟͞o̳̿͟͞r̳̿͟͞ ̳̿͟͞R̳̿͟͞e̳̿͟͞a̳̿͟͞d̳̿͟͞i̳̿͟͞n̳̿͟͞g̳̿͟͞ ▄▀▄▀▄▀

Cc: @blacks
Cc: @rme
Cc: @hungry-griffin
Cc: @steemchiller
Cc: @steemcurator01


Best Regards @faisalamin

Sort:  
 2 years ago 

Thank you for the update

My pleasure

 2 years ago 

Thank you so much for the good works you and your team are doing. Indeed, I love using the SteemPro tools. It's easy to navigate through. Kudos to you all.

Thank you for having interest 😊.

Thank you so much for this new update. Indeed, this tool is is really very helpful. I am waiting for more excellent update.

Coin Marketplace

STEEM 0.21
TRX 0.20
JST 0.034
BTC 90827.60
ETH 3116.50
USDT 1.00
SBD 2.97