From 4aecef468f53299abbb1d34b05fcd27c8c7c932a Mon Sep 17 00:00:00 2001 From: Julian Steinwachs Date: Tue, 12 Jan 2016 14:17:40 +0100 Subject: [PATCH] edit profile and avatar --- build/app-bundle.js | 78 +++++++++++++++++++++-------------------- build/twister-lib.js | 83 +++++++++++++++++++++++++++++++++----------- css/main.css | 16 +++++++++ index.html | 2 +- jsx/App.js | 26 +------------- jsx/common/Post.js | 50 +++++++++++++++++++------- 6 files changed, 158 insertions(+), 97 deletions(-) diff --git a/build/app-bundle.js b/build/app-bundle.js index 0fff54d..c5098ab 100644 --- a/build/app-bundle.js +++ b/build/app-bundle.js @@ -247,6 +247,7 @@ if (accounts.length==0) { host: appSettings.host, logfunc: function(log){console.log(log)}, outdatedLimit: appSettings.pollInterval, + signatureVerification: "none", walletType: "client", querySettingsByType: { @@ -263,31 +264,6 @@ if (accounts.length==0) { initializeApp(); - /*Twister.importClientSideAccount("pampalulu","L12kz6tabDN6VmPes1rfEpiznztPF6vgkHp8UZVBgZadxzebHhAp",function(){ - - var activeAccount = localStorage.getItem("twister-react-activeAccount"); - - var accounts = Twister.getAccounts(); - - if (!activeAccount) { - - activeAccount = accounts[0]; - localStorage.setItem("twister-react-activeAccount",activeAccount); - - } - - console.log("active account defaulted to "+activeAccount) - - console.log(Twister.getAccount(activeAccount)) - - Twister.getAccount(activeAccount).activateTorrents(function(){ - - initializeApp(); - - }); - - }); -*/ } else { var activeAccount = localStorage.getItem("twister-react-activeAccount"); @@ -566,7 +542,9 @@ module.exports = Post = React.createClass({displayName: "Post", avatar: "img/genericPerson.png", fullname: "", timeAgo: "", - retwistingUser: this.props.post.username + retwistingUsername: this.props.post.username, + retwistingUserFullname: "", + retwistingUserAvatar: "img/genericPerson.png", }; }, updateTimeAgo: function() { @@ -599,6 +577,12 @@ module.exports = Post = React.createClass({displayName: "Post", }); }); + post.getUser().doAvatar(function(avatar){ + thisComponent.setStateSafe({ + retwistingUserAvatar: avatar.getUrl() + }); + }); + post=post.getRetwistedPost(); } @@ -623,11 +607,16 @@ module.exports = Post = React.createClass({displayName: "Post", var post = Twister.getUser(this.props.post.username).getPost(this.props.post.id); var retwist = false; + var retwistWithComment = false; + var comment = ""; if (post.isRetwist()) { retwist = true; + if(post.isRetwistWithComment()){ + retwistWithComment=true; + comment = post.getContent(); + } post=post.getRetwistedPost(); - } if (post.isReply()) { @@ -667,24 +656,32 @@ module.exports = Post = React.createClass({displayName: "Post", return ( React.createElement(ListGroupItem, null, - React.createElement(Row, {className: "nomargin"}, - React.createElement(Col, {xs: 2, md: 2, className: "fullytight"}, + React.createElement(Row, {className: "nomargin post-main"}, + React.createElement(Col, {xs: 1, md: 1, className: "fullytight"}, React.createElement("a", {href: "#/profile/"+post.getUsername()}, React.createElement("img", {className: "img-responsive", src: this.state.avatar}) ) ), - React.createElement(Col, {xs: 9, md: 9}, - React.createElement("strong", null, this.state.fullname), + React.createElement(Col, {xs: 11, md: 11}, + React.createElement(Row, null, + React.createElement(Col, {xs: 11, md: 11}, + React.createElement("strong", null, this.state.fullname) + ), + React.createElement(Col, {xs: 1, md: 1, className: "fullytight"}, + React.createElement("small", null, this.state.timeAgo) + ) + ), React.createElement(PostContent, {content: post.getContent()}) - ), - React.createElement(Col, {xs: 1, md: 1, className: "fullytight text-align-right"}, this.state.timeAgo) + ) ), React.createElement(Row, {className: "nomargin"}, - React.createElement(Col, {xs: 6, md: 6, className: "fullytight"}, - retwist && React.createElement("small", null, React.createElement("em", null, "retwisted by ", this.state.retwistingUserFullname)) - + React.createElement(Col, {xs: 8, md: 8, className: "fullytight"}, + retwist && React.createElement("small", null, React.createElement("em", null, + "retwisted by ", React.createElement("img", {className: "micro-avatar", src: this.state.retwistingUserAvatar}), this.state.retwistingUserFullname, retwistWithComment && ":" + )) + ), - React.createElement(Col, {xs: 4, md: 4, className: "fullytight text-align-right"}, + React.createElement(Col, {xs: 2, md: 2, className: "fullytight text-align-right"}, conversationLink ), React.createElement(Col, {xs: 1, md: 1, className: "fullytight text-align-right"}, @@ -693,8 +690,13 @@ module.exports = Post = React.createClass({displayName: "Post", React.createElement(Col, {xs: 1, md: 1, className: "fullytight text-align-right"}, retwistLink ) + ), + retwistWithComment && React.createElement(Row, null, + React.createElement(Col, {xs: 12, md: 12}, + React.createElement("small", null, React.createElement(PostContent, {content: comment})) + ) ) - + ) ); } diff --git a/build/twister-lib.js b/build/twister-lib.js index 400f941..4886a25 100755 --- a/build/twister-lib.js +++ b/build/twister-lib.js @@ -30001,8 +30001,8 @@ TwisterAccount.prototype.reply = function (replyusername,replyid,msg,cbfunc) { this._signAndPublish(post,function(newpost){ var v = { - rt: newpost._data, - sig_rt: newpost._signature + sig_userpost: newpost._signature, + userpost: newpost._data } thisAccount._dhtput( @@ -30193,27 +30193,31 @@ TwisterAccount.prototype._dhtput = function(username,resource,sorm,value,seq,cbf thisAccount.RPC("getinfo",[],function(info){ var p = { - height: info.blocks-1, - v:value, - seq: seq, - target:{ - "n" : username, - "r" : resource, - "t" : sorm - }, - time: Math.round(Date.now()/1000), - v: value - }; + height: info.blocks-1, + target:{ + "n" : username, + "r" : resource, + "t" : sorm + }, + time: Math.round(Date.now()/1000), + v: value + }; - console.log("dhtputraw",p) + if(sorm=="s"){ + p.seq=seq; + } + + console.log("dhtputraw",username,resource,sorm,p) - thisAccount._privkey.sign(p,function(sig){ + thisAccount._privkey.sign(p,function(sig,pWithBuffers){ var dhtentry = { - p: p, + p: pWithBuffers, sig_user:thisAccount._name, sig_p: sig } + + //console.log("p",dhtentry) var message = bencode.encode(dhtentry); @@ -30275,10 +30279,14 @@ TwisterAccount.prototype._publishPostOnDht = function(v,cbfunc){ } ); + console.log(v) + if(v.userpost && v.userpost.msg){ var parsedContent = TwisterContentParser.parseContent(v.userpost.msg); - + + console.log("parsed content",parsedContent) + parsedContent.map(function(item){ if(item.type=="hashtag"){ @@ -30863,6 +30871,20 @@ TwisterPrivKey.prototype.sign = function (message_ori, cbfunc) { var message = JSON.parse(JSON.stringify(message_ori)); + if ("p" in message && (typeof message.p)=="object"){ + if ("v" in message.p && (typeof message.p.v)=="object"){ + if("sig_userpost" in message.p.v && !Buffer.isBuffer(message.p.v.sig_userpost)) { + message.p.v.sig_userpost = new Buffer(message.p.v.sig_userpost, 'hex'); + } + if ("userpost" in message.p.v) { + if ("sig_rt" in message.p.v.userpost && !Buffer.isBuffer(message.p.v.userpost.sig_rt)) { + message.p.v.userpost.sig_rt = new Buffer(message.p.v.userpost.sig_rt, 'hex'); + } + } + } + } + + if ("v" in message && (typeof message.v)=="object"){ if("sig_userpost" in message.v && !Buffer.isBuffer(message.v.sig_userpost)) { message.v.sig_userpost = new Buffer(message.v.sig_userpost, 'hex'); @@ -30876,6 +30898,9 @@ TwisterPrivKey.prototype.sign = function (message_ori, cbfunc) { if ("sig_rt" in message && !Buffer.isBuffer(message.sig_rt)) { message.sig_rt = new Buffer(message.sig_rt, 'hex'); + } + if("sig_userpost" in message && !Buffer.isBuffer(message.sig_userpost)) { + message.sig_userpost = new Buffer(message.sig_userpost, 'hex'); } var Twister = this._scope; @@ -30886,11 +30911,13 @@ TwisterPrivKey.prototype.sign = function (message_ori, cbfunc) { var startTime = Date.now(); - message = bencode.encode(message); + //console.log("signing",message); + + bmessage = bencode.encode(message); try { - var retVal = Bitcoin.message.sign(keyPair,message ,twister_network); - cbfunc(retVal) + var retVal = Bitcoin.message.sign(keyPair,bmessage ,twister_network); + cbfunc(retVal,message) } catch(e) { //console.log(e) thisResource._handleError({ @@ -33363,6 +33390,14 @@ TwisterPost.prototype.isRetwist = function () { return ("rt" in this._data); } +/** @function + * @name isRetwist + * @description returns true if the postis an rewtist. + */ +TwisterPost.prototype.isRetwistWithComment = function () { + return ("rt" in this._data && "msg" in this._data); +} + /** @function * @name getRetwistedId @@ -33903,6 +33938,10 @@ TwisterPubKey.prototype.getKey = function () { TwisterPubKey.prototype.verifySignature = function (message_ori, signature_ori, cbfunc) { + var verifySignatures = (this.getQuerySetting("signatureVerification")!="none"); + + if(verifySignatures){ + var thisResource = this; var signature = JSON.parse(JSON.stringify(signature_ori)); @@ -33967,7 +34006,9 @@ TwisterPubKey.prototype.verifySignature = function (message_ori, signature_ori, },timeout); - + }else{ + cbfunc(true); + } } }).call(this,require("buffer").Buffer) diff --git a/css/main.css b/css/main.css index 2f6357d..1ba36b8 100755 --- a/css/main.css +++ b/css/main.css @@ -7,6 +7,10 @@ body.modal-open { margin: 0; } +.container { + padding: 0; +} + .modal { overflow: auto; } @@ -45,6 +49,7 @@ body.modal-open { .img-responsive { width: 100%; + border-radius: 0.25em; } .item-enter { @@ -65,6 +70,10 @@ body.modal-open { opacity: 0.01; } +.post-main{ + margin-bottom: 5px; +} + .mention { color: red; } @@ -81,3 +90,10 @@ body.modal-open { color: coral; } +.micro-avatar { + height: 1em; + border-radius: 0.25em; + vertical-align: text-top; + margin-left: 0.25em; + margin-right: 0.125em; +} \ No newline at end of file diff --git a/index.html b/index.html index f414b52..fd3b4c0 100755 --- a/index.html +++ b/index.html @@ -11,7 +11,7 @@ - + diff --git a/jsx/App.js b/jsx/App.js index cf6668d..460ee18 100755 --- a/jsx/App.js +++ b/jsx/App.js @@ -246,6 +246,7 @@ if (accounts.length==0) { host: appSettings.host, logfunc: function(log){console.log(log)}, outdatedLimit: appSettings.pollInterval, + signatureVerification: "none", walletType: "client", querySettingsByType: { @@ -262,31 +263,6 @@ if (accounts.length==0) { initializeApp(); - /*Twister.importClientSideAccount("pampalulu","L12kz6tabDN6VmPes1rfEpiznztPF6vgkHp8UZVBgZadxzebHhAp",function(){ - - var activeAccount = localStorage.getItem("twister-react-activeAccount"); - - var accounts = Twister.getAccounts(); - - if (!activeAccount) { - - activeAccount = accounts[0]; - localStorage.setItem("twister-react-activeAccount",activeAccount); - - } - - console.log("active account defaulted to "+activeAccount) - - console.log(Twister.getAccount(activeAccount)) - - Twister.getAccount(activeAccount).activateTorrents(function(){ - - initializeApp(); - - }); - - }); -*/ } else { var activeAccount = localStorage.getItem("twister-react-activeAccount"); diff --git a/jsx/common/Post.js b/jsx/common/Post.js index 4864fa5..72a09bf 100755 --- a/jsx/common/Post.js +++ b/jsx/common/Post.js @@ -57,7 +57,9 @@ module.exports = Post = React.createClass({ avatar: "img/genericPerson.png", fullname: "", timeAgo: "", - retwistingUser: this.props.post.username + retwistingUsername: this.props.post.username, + retwistingUserFullname: "", + retwistingUserAvatar: "img/genericPerson.png", }; }, updateTimeAgo: function() { @@ -90,6 +92,12 @@ module.exports = Post = React.createClass({ }); }); + post.getUser().doAvatar(function(avatar){ + thisComponent.setStateSafe({ + retwistingUserAvatar: avatar.getUrl() + }); + }); + post=post.getRetwistedPost(); } @@ -114,11 +122,16 @@ module.exports = Post = React.createClass({ var post = Twister.getUser(this.props.post.username).getPost(this.props.post.id); var retwist = false; + var retwistWithComment = false; + var comment = ""; if (post.isRetwist()) { retwist = true; + if(post.isRetwistWithComment()){ + retwistWithComment=true; + comment = post.getContent(); + } post=post.getRetwistedPost(); - } if (post.isReply()) { @@ -158,24 +171,32 @@ module.exports = Post = React.createClass({ return ( - - + + - - {this.state.fullname} + + + + {this.state.fullname} + + + {this.state.timeAgo} + + - {this.state.timeAgo} - - {retwist && retwisted by {this.state.retwistingUserFullname} - } + + {retwist && + retwisted by {this.state.retwistingUserFullname}{retwistWithComment && ":"} + + } - + {conversationLink} @@ -185,7 +206,12 @@ module.exports = Post = React.createClass({ {retwistLink} - + {retwistWithComment && + + + + + } ); }