Skip to content

Commit eef79f1

Browse files
committed
Add Voice protocol support in utils: viz.utils.voiceText, viz.utils.voicePublication
1 parent 33ef41f commit eef79f1

File tree

2 files changed

+146
-0
lines changed

2 files changed

+146
-0
lines changed

doc/README.md

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1164,6 +1164,53 @@ console.log(isValidUsername);
11641164
// => 'Account name should be longer.'
11651165
```
11661166

1167+
### Post Voice Text
1168+
```
1169+
//wif,account,text,reply,share,beneficiaries,loop,callback
1170+
viz.utils.voiceText('5K...','on1x','Just a test from viz-js-lib',false,false,false,false,function(result){console.log(result)});
1171+
```
1172+
1173+
### Post Voice Publication
1174+
```
1175+
//wif,account,text,reply,share,beneficiaries,loop,callback
1176+
let wif='5K...';
1177+
let account='on1x';
1178+
let markdown=`Well, Voice protocol markdown have **bold**, __italic__, ~~stroke~~ and \`code\`
1179+
1180+
## Headers 2
1181+
1182+
### And 3
1183+
1184+
Also we got:
1185+
1186+
> Quotes and
1187+
1188+
>> Second style for citation
1189+
1190+
Support lists:
1191+
1192+
* Unordered
1193+
* as ordinary
1194+
* items
1195+
1196+
And ordered, ofc:
1197+
1198+
*n Yes
1199+
*n it is!
1200+
1201+
After all, simple images:
1202+
![Alt text for image](https://viz.world/ubi-circle-300.jpg)
1203+
1204+
Paragraph
1205+
with
1206+
multiline
1207+
1208+
...and #en #example tags support :)`;
1209+
1210+
//wif,account,title,markdown,description,image,reply,share,beneficiaries,loop,callback
1211+
viz.utils.voicePublication(wif,account,'Test publication from viz-js-lib',markdown,false,false,false,false,false,false,function(result){console.log(result)});
1212+
```
1213+
11671214
# deprecated api methods
11681215
## Content
11691216

src/utils.js

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,3 +43,102 @@ export function validateAccountName(value) {
4343
}
4444
return null;
4545
}
46+
47+
export function voiceText(wif,account,text,reply,share,beneficiaries,loop,callback){
48+
reply=typeof reply === 'undefined'?false:reply;
49+
share=typeof share === 'undefined'?false:share;
50+
beneficiaries=typeof beneficiaries === 'undefined'?false:beneficiaries;
51+
loop=typeof loop === 'undefined'?false:loop;
52+
callback=typeof callback === 'undefined'?function(){}:callback;
53+
54+
let use_previous=function(wif,account,text,reply,share,beneficiaries,previous,callback){
55+
let object={
56+
'p':previous,
57+
//'t':'t',//text as default type
58+
'd':{
59+
't':text,
60+
}
61+
};
62+
if(reply){
63+
object['d']['r']=reply;
64+
}
65+
else{//share conflict with reply
66+
if(share){
67+
object['d']['s']=share;
68+
}
69+
}
70+
if(beneficiaries){//json example: [{"account":"committee","weight":1000}]
71+
object['d']['b']=beneficiaries;
72+
}
73+
viz.broadcast.custom(wif,[],[account],'V',JSON.stringify(object),function(err,result){
74+
callback(!err);
75+
});
76+
}
77+
if(false!==loop){
78+
use_previous(wif,account,text,reply,share,beneficiaries,loop,callback);
79+
}
80+
else{
81+
viz.api.getAccount(account,'V',function(err,result){
82+
if(!err){
83+
use_previous(wif,account,text,reply,share,beneficiaries,result.custom_sequence_block_num,callback);
84+
}
85+
else{
86+
callback(false);
87+
}
88+
});
89+
}
90+
}
91+
92+
export function voicePublication(wif,account,title,markdown,description,image,reply,share,beneficiaries,loop,callback){
93+
description=typeof description === 'undefined'?false:description;
94+
image=typeof image === 'undefined'?false:image;
95+
reply=typeof reply === 'undefined'?false:reply;
96+
share=typeof share === 'undefined'?false:share;
97+
beneficiaries=typeof beneficiaries === 'undefined'?false:beneficiaries;
98+
loop=typeof loop === 'undefined'?false:loop;
99+
callback=typeof callback === 'undefined'?function(){}:callback;
100+
101+
let use_previous=function(wif,account,title,markdown,description,image,reply,share,beneficiaries,previous,callback){
102+
let object={
103+
'p':previous,
104+
't':'p',//text as default type
105+
'd':{
106+
't':title,
107+
'm':markdown,
108+
}
109+
};
110+
if(description){
111+
object['d']['d']=description;
112+
}
113+
if(image){
114+
object['d']['i']=image;
115+
}
116+
if(reply){
117+
object['d']['r']=reply;
118+
}
119+
else{//share conflict with reply
120+
if(share){
121+
object['d']['s']=share;
122+
}
123+
}
124+
if(beneficiaries){//json example: [{"account":"committee","weight":1000}]
125+
object['d']['b']=beneficiaries;
126+
}
127+
viz.broadcast.custom(wif,[],[account],'V',JSON.stringify(object),function(err,result){
128+
callback(!err);
129+
});
130+
}
131+
if(false!==loop){
132+
use_previous(wif,account,title,markdown,description,image,reply,share,beneficiaries,loop,callback);
133+
}
134+
else{
135+
viz.api.getAccount(account,'V',function(err,result){
136+
if(!err){
137+
use_previous(wif,account,title,markdown,description,image,reply,share,beneficiaries,result.custom_sequence_block_num,callback);
138+
}
139+
else{
140+
callback(false);
141+
}
142+
});
143+
}
144+
}

0 commit comments

Comments
 (0)