From 7dd5d83c5498451935512e2c458a6855646d490a Mon Sep 17 00:00:00 2001 From: Michael L Date: Wed, 31 Jul 2024 15:45:44 +0500 Subject: [PATCH 1/4] Add developapps --- config/Bastyon.json | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/config/Bastyon.json b/config/Bastyon.json index 4e010c0603..986b6d52ce 100644 --- a/config/Bastyon.json +++ b/config/Bastyon.json @@ -3,7 +3,16 @@ "turl" : "test.pocketnet.app", "name" : "Bastyon", "fullname" : "Bastyon", - "developapps" : [], + "developapps" : [ + { + "id" : "barteron.pocketnet.app", + "version": "1.0.0", + "scope" : "test.barter.pocketnet.app", + "cantdelete" : true, + "name" : "Barteron", + "grantedPermissions" : ["account", "chat"] + } + ], "protocol" : "bastyon", "support" : "support@bastyon.com", "lname" : "Dvm Analytics LLC", From c944212fbebde28bca63ac414f4f80cbfdd60d1d Mon Sep 17 00:00:00 2001 From: Michael L Date: Wed, 31 Jul 2024 15:49:41 +0500 Subject: [PATCH 2/4] Update devapps sdk --- js/lib/apps/sdk.js | 60 ++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 53 insertions(+), 7 deletions(-) diff --git a/js/lib/apps/sdk.js b/js/lib/apps/sdk.js index 5f0114d1bb..ea4080c7dc 100644 --- a/js/lib/apps/sdk.js +++ b/js/lib/apps/sdk.js @@ -41,6 +41,12 @@ var BastyonSdk = function(){ var listeners = {} var currentState = (document.location.pathname + document.location.search).replace('/', ''); + const popstateEventHandler = function() { + onChangeState() + } + + window.addEventListener('popstate', popstateEventHandler); + const onChangeState = (state, title, url, isReplace) => { setTimeout(() => { @@ -49,12 +55,12 @@ var BastyonSdk = function(){ if(currentState == link) return currentState = link - + send({ event : 'changestate', data : { value : currentState, - replace : isReplace + replace : true } }) }) @@ -67,7 +73,9 @@ var BastyonSdk = function(){ window.history['_' + changeState] = window.history[changeState] window.history[changeState] = new Proxy(window.history[changeState], { + apply (target, thisArg, argList) { + console.log('changeState', changeState) const [state, title, url] = argList onChangeState(state, title, url, changeState === 'replaceState') @@ -114,10 +122,7 @@ var BastyonSdk = function(){ } var send = function(message){ - - window.parent.postMessage(message, "*") - - + window.parent.postMessage(message, "*") } var action = function(action, data){ @@ -257,6 +262,30 @@ var BastyonSdk = function(){ }) } + self.barteron = { + account : function(data){ + return action('barteron.account', data) + }, + + offer : function(data){ + return action('barteron.offer', data) + }, + + comment : function(data){ + return action('barteron.comment', data) + }, + + vote : function(data){ + return action('barteron.vote', data) + } + } + + self.images = { + upload : function(data){ + return action('images.upload', data) + } + } + self.chat = { getOrCreateRoom : function({users, parameters}){ return action('chat.getOrCreateRoom', {users, parameters}).then(room => { @@ -331,18 +360,27 @@ var BastyonSdk = function(){ }, } + self.getroute = function(data){ + return '/' + data.route + } + self.init = function(){ self.on('keyboard', ({height}) => { document.documentElement.style.setProperty('--keyboardheight', `${height}px`); }) + self.on('changestate', (data) => { + currentState = data.route + }) + return new Promise((resolve, reject) => { - self.get.appinfo().then(({margintop, theme, application, project}) => { + self.get.appinfo().then(({margintop, theme, application, project, production}) => { self.applicationInfo = application self.project = project + self.test = !production if (document.documentElement.hasAttribute('theme')){ document.documentElement.removeAttribute('theme'); @@ -359,6 +397,14 @@ var BastyonSdk = function(){ } + self.inbastyon = function(){ + try { + return window.self !== window.top; + } catch (e) { + return true; + } + } + listen() From 0e28c045d1a1f397ca1287df3453a7765ad264e1 Mon Sep 17 00:00:00 2001 From: Michael L Date: Wed, 31 Jul 2024 15:51:52 +0500 Subject: [PATCH 3/4] Update devapps kit --- js/kit.js | 196 +++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 194 insertions(+), 2 deletions(-) diff --git a/js/kit.js b/js/kit.js index 84ac8858c1..c7ab557f28 100644 --- a/js/kit.js +++ b/js/kit.js @@ -356,6 +356,22 @@ Comment = function(txid){ v : [] } + self.info = { + set : function(_v){ + + if(!_v){ + this.v = '' + } + else + + this.v = _v + + if (self.on.change) + self.on.change('info', this.v) + }, + v : '' + } + self.donate = { set : function(donate){ @@ -517,6 +533,7 @@ Comment = function(txid){ images : _.map(self.images.v, function(i){ return (i) }), + info : (self.info.v || '') })) @@ -540,7 +557,8 @@ Comment = function(txid){ r.msgparsed = { message : self.message.v, url : self.url.v, - images : self.images.v + images : self.images.v, + info : self.info.v } } else{ @@ -550,6 +568,7 @@ Comment = function(txid){ images : _.map(self.images.v, function(i){ return (i) }), + info : self.info.v }) } @@ -589,12 +608,15 @@ Comment = function(txid){ self.images.set(_.map(v.msgparsed.images, function(i){ return decodeURIComponent(i) })) + self.info.set(v.msgparsed.info) } if (v.msgparsed){ self.url.set(v.msgparsed.url) self.message.set(v.msgparsed.message) self.images.set(v.msgparsed.images) + self.info.set(v.msgparsed.info) + } if (v.donate){ @@ -2162,6 +2184,170 @@ Transaction = function(){ } +/* BARTERON */ + +brtAccount = function(){ + var self = this; + + self.address = ''; + self.tags = []; + self.geohash = ''; + self.static = false; + self.radius = 0; + + self.validation = function(){ + + } + + self.serialize = function(){ + return self.address + + JSON.stringify({ + a: self.tags, + g: self.geohash, + s: self.static, + r: self.radius + }); + } + + self.export = function(alias){ + if(alias){ + return { + address: self.address, + tags: self.tags, + geohash: self.geohash, + static: self.static, + radius: self.radius + }; + } + + return { + s1: self.address, + p: { + s4: JSON.stringify({ + a: self.tags, + g: self.geohash, + s: self.static, + r: self.radius + }) + } + }; + } + + self.import = function(d){ + self.address = d.address || app.user.address.value; + self.tags = d.tags; + self.geohash = d.geohash; + self.static = d.static; + self.radius = d.radius; + } + + self.type = 'brtaccount'; + + return self; +} + +brtOffer = function(){ + var self = this; + + self.hash = null; + self.address = ''; + self.language = ''; + self.caption = ''; + self.description = ''; + self.tag = ''; + self.tags = []; + self.condition = []; + self.images = []; + self.geohash = ''; + self.price = 0; + + self.validation = function(){ + if(!self.address) return 'address'; + if(!self.language) return 'language'; + if(!self.caption) return 'caption'; + if(!self.description) return 'description'; + if(!self.tag) return 'tag'; + if(!self.tags) return 'tags'; + if(!self.condition) return 'condition'; + if(!self.images) return 'images'; + if(!self.geohash) return 'geohash'; + if(!(self.price > -1)) return 'price'; + } + + self.serialize = function(){ + return self.address + + (self.hash ?? '') + + self.language + + self.caption + + self.description + + JSON.stringify({ + t: self.tag, + a: self.tags, + c: self.condition + }) + + JSON.stringify(self.images) + + self.geohash + + self.price; + } + + self.export = function(alias){ + if(alias){ + return { + address: self.address, + hash: self.hash || null, + language: self.language, + caption: self.caption, + description: self.description, + tag: self.tag, + tags: self.tags, + condition: self.condition, + images: self.images, + geohash: self.geohash, + price: self.price + }; + } + + return { + s1: self.address, + ...(self.hash && { s2: self.hash }), + p: { + s1: self.language, + s2: self.caption, + s3: self.description, + s4: JSON.stringify({ + t: self.tag, + a: self.tags, + c: self.condition, + }), + s5: JSON.stringify(self.images), + s6: self.geohash, + i1: self.price + } + }; + } + + self.import = function(d){ + self.address = d.address || app.user.address.value; + self.hash = d.hash || null; + self.language = d.language; + self.caption = d.caption; + self.description = d.description; + self.tag = d.tag; + self.tags = d.tags; + self.condition = d.condition, + self.images = d.images; + self.geohash = d.geohash; + self.price = d.price; + } + + self.type = 'brtoffer'; + + return self; +} + + +/* ---- */ + pUserInfo = function(){ @@ -2982,6 +3168,7 @@ pComment = function(){ self.url = '' self.message = '' self.images = []; + self.info = '' self.postid = ''; self.id = ''; @@ -3020,6 +3207,7 @@ pComment = function(){ self.url = v.msgparsed.url; self.message = v.msgparsed.message self.images = v.msgparsed.images + self.info = v.msgparsed.info || '' } self.postid = v.postid; @@ -3084,6 +3272,7 @@ pComment = function(){ message : self.message, url : self.url, images : self.images, + info : self.info }, scoreDown : self.scoreDown, scoreUp : self.scoreUp, @@ -3654,7 +3843,10 @@ kits = { accDel : DeleteAccount, transaction : Transaction, contentDelete : Remove, - accSet : Settings + accSet : Settings, + brtoffer : brtOffer, + brtaccount : brtAccount + }, ini : { From 72e4d7932f618da05d86bf7a5621bfb38db922bd Mon Sep 17 00:00:00 2001 From: Michael L Date: Wed, 31 Jul 2024 16:00:36 +0500 Subject: [PATCH 4/4] Update devapps methods --- js/lib/apps/index.js | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/js/lib/apps/index.js b/js/lib/apps/index.js index 4baf3bc20e..f39f24cc82 100644 --- a/js/lib/apps/index.js +++ b/js/lib/apps/index.js @@ -724,12 +724,24 @@ var BastyonApps = function(app){ permissions : ['account'], authorization : true, action : function({data, application}){ - var comment = new brtComment(); + var comment = new Comment(); comment.import(data); return makeAction(comment, application) } + }, + + vote : { + permissions : ['account'], + authorization : true, + action : function({data, application}){ + var vote = new UpvoteShare(); + + vote.import(data); + + return makeAction(vote, application) + } } }