Skip to content

Commit

Permalink
using broadcastPostingJSON method for reblog to avoid dependency on h…
Browse files Browse the repository at this point in the history
…sClient.reblog for delete/undo reblog
  • Loading branch information
noumantahir committed May 16, 2024
1 parent 3048273 commit 467b467
Showing 1 changed file with 15 additions and 47 deletions.
62 changes: 15 additions & 47 deletions src/providers/hive/dhive.js
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,7 @@ export const getUser = async (user, loggedIn = true) => {
export const getUserReputation = async (author) => {
try {
const response = await client.call('condenser_api', 'get_account_reputations', [author, 1]);

if (response && response.length < 1) {
return 0;
}
Expand Down Expand Up @@ -1751,62 +1751,30 @@ const _postContent = async (

// Re-blog
// TODO: remove pinCode
export const reblog = (account, pinCode, author, permlink) =>
_reblog(account, pinCode, author, permlink).then((resp) => {
export const reblog = (account, pinCode, author, permlink, undo = false) =>
_reblog(account, pinCode, author, permlink, undo).then((resp) => {
return resp;
});

const _reblog = async (account, pinCode, author, permlink) => {
const pin = getDigitPinCode(pinCode);
const key = getAnyPrivateKey(account.local, pin);

if (account.local.authType === AUTH_TYPE.STEEM_CONNECT) {
const token = decryptKey(account.local.accessToken, pin);
const api = new hsClient({
accessToken: token,
});
const _reblog = async (account, pinCode, author, permlink, undo = false) => {

const follower = account.name;

return api.reblog(follower, author, permlink).then((resp) => resp.result);
}

if (key) {
const privateKey = PrivateKey.fromString(key);
const follower = account.name;

const json = {
id: 'follow',
json: jsonStringify([
'reblog',
{
account: follower,
author,
permlink,
},
]),
required_auths: [],
required_posting_auths: [follower],
};
const json = [
'reblog',
{
account: account.name,
author,
permlink,
delete: undo ? 'delete' : undefined
},
];

const opArray = [['custom_json', json]];

return new Promise((resolve, reject) => {
sendHiveOperations(opArray, privateKey)
.then((result) => {
resolve(result);
})
.catch((err) => {
reject(err);
});
});
}
return broadcastPostingJSON('follow', json, account, pinCode)

return Promise.reject(
new Error('Check private key permission! Required private posting key or above.'),
);
};


export const claimRewardBalance = (account, pinCode, rewardHive, rewardHbd, rewardVests) => {
const pin = getDigitPinCode(pinCode);
const key = getAnyPrivateKey(get(account, 'local'), pin);
Expand Down

0 comments on commit 467b467

Please sign in to comment.