Skip to content

Commit

Permalink
Add Voice protocol support in utils: viz.utils.voiceText, viz.utils.v…
Browse files Browse the repository at this point in the history
…oicePublication
  • Loading branch information
On1x committed Aug 9, 2021
1 parent 33ef41f commit eef79f1
Show file tree
Hide file tree
Showing 2 changed files with 146 additions and 0 deletions.
47 changes: 47 additions & 0 deletions doc/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1164,6 +1164,53 @@ console.log(isValidUsername);
// => 'Account name should be longer.'
```

### Post Voice Text
```
//wif,account,text,reply,share,beneficiaries,loop,callback
viz.utils.voiceText('5K...','on1x','Just a test from viz-js-lib',false,false,false,false,function(result){console.log(result)});
```

### Post Voice Publication
```
//wif,account,text,reply,share,beneficiaries,loop,callback
let wif='5K...';
let account='on1x';
let markdown=`Well, Voice protocol markdown have **bold**, __italic__, ~~stroke~~ and \`code\`
## Headers 2
### And 3
Also we got:
> Quotes and
>> Second style for citation
Support lists:
* Unordered
* as ordinary
* items
And ordered, ofc:
*n Yes
*n it is!
After all, simple images:
![Alt text for image](https://viz.world/ubi-circle-300.jpg)
Paragraph
with
multiline
...and #en #example tags support :)`;
//wif,account,title,markdown,description,image,reply,share,beneficiaries,loop,callback
viz.utils.voicePublication(wif,account,'Test publication from viz-js-lib',markdown,false,false,false,false,false,false,function(result){console.log(result)});
```

# deprecated api methods
## Content

Expand Down
99 changes: 99 additions & 0 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,102 @@ export function validateAccountName(value) {
}
return null;
}

export function voiceText(wif,account,text,reply,share,beneficiaries,loop,callback){
reply=typeof reply === 'undefined'?false:reply;
share=typeof share === 'undefined'?false:share;
beneficiaries=typeof beneficiaries === 'undefined'?false:beneficiaries;
loop=typeof loop === 'undefined'?false:loop;
callback=typeof callback === 'undefined'?function(){}:callback;

let use_previous=function(wif,account,text,reply,share,beneficiaries,previous,callback){
let object={
'p':previous,
//'t':'t',//text as default type
'd':{
't':text,
}
};
if(reply){
object['d']['r']=reply;
}
else{//share conflict with reply
if(share){
object['d']['s']=share;
}
}
if(beneficiaries){//json example: [{"account":"committee","weight":1000}]
object['d']['b']=beneficiaries;
}
viz.broadcast.custom(wif,[],[account],'V',JSON.stringify(object),function(err,result){
callback(!err);
});
}
if(false!==loop){
use_previous(wif,account,text,reply,share,beneficiaries,loop,callback);
}
else{
viz.api.getAccount(account,'V',function(err,result){
if(!err){
use_previous(wif,account,text,reply,share,beneficiaries,result.custom_sequence_block_num,callback);
}
else{
callback(false);
}
});
}
}

export function voicePublication(wif,account,title,markdown,description,image,reply,share,beneficiaries,loop,callback){
description=typeof description === 'undefined'?false:description;
image=typeof image === 'undefined'?false:image;
reply=typeof reply === 'undefined'?false:reply;
share=typeof share === 'undefined'?false:share;
beneficiaries=typeof beneficiaries === 'undefined'?false:beneficiaries;
loop=typeof loop === 'undefined'?false:loop;
callback=typeof callback === 'undefined'?function(){}:callback;

let use_previous=function(wif,account,title,markdown,description,image,reply,share,beneficiaries,previous,callback){
let object={
'p':previous,
't':'p',//text as default type
'd':{
't':title,
'm':markdown,
}
};
if(description){
object['d']['d']=description;
}
if(image){
object['d']['i']=image;
}
if(reply){
object['d']['r']=reply;
}
else{//share conflict with reply
if(share){
object['d']['s']=share;
}
}
if(beneficiaries){//json example: [{"account":"committee","weight":1000}]
object['d']['b']=beneficiaries;
}
viz.broadcast.custom(wif,[],[account],'V',JSON.stringify(object),function(err,result){
callback(!err);
});
}
if(false!==loop){
use_previous(wif,account,title,markdown,description,image,reply,share,beneficiaries,loop,callback);
}
else{
viz.api.getAccount(account,'V',function(err,result){
if(!err){
use_previous(wif,account,title,markdown,description,image,reply,share,beneficiaries,result.custom_sequence_block_num,callback);
}
else{
callback(false);
}
});
}
}

0 comments on commit eef79f1

Please sign in to comment.