From fe1d11316b0a3ed0844ff1208c9f08e626bff215 Mon Sep 17 00:00:00 2001 From: Simon Grim Date: Fri, 21 Aug 2015 14:36:05 +0500 Subject: [PATCH] add quote fetching for retwisted twists with comments --- js/twister_formatpost.js | 61 ++++++++++++++++++++++++---------------- 1 file changed, 37 insertions(+), 24 deletions(-) diff --git a/js/twister_formatpost.js b/js/twister_formatpost.js index 3aa20a9..c7f65c4 100644 --- a/js/twister_formatpost.js +++ b/js/twister_formatpost.js @@ -35,22 +35,6 @@ $(document).ready(function() { // format "userpost" to html element // kind = "original"/"ancestor"/"descendant" function postToElem(post, kind, promoted) { - - function setPostCommon(elem, username, time) { - var postInfoName = elem.find('.post-info-name') - .text(username).attr('href', $.MAL.userUrl(username)); - - getFullname(username, postInfoName); - //elem.find('.post-info-tag').text("@" + username); // FIXME - getAvatar(username, elem.find('.avatar')); - - elem.find('.post-info-time') - .attr('title', timeSincePost(time)) - .find('span:last') - .text(timeGmtToText(time)) - ; - } - /* "userpost" : { @@ -170,19 +154,22 @@ function postToElem(post, kind, promoted) { if (typeof retweeted_by !== 'undefined') { var postContext = elem.find('.post-context'); if (userpost.msg) { - postContext.append(_templatePostRtReference.clone(true)) - .find('.post-rt-reference') - .attr('data-screen-name', rt.n) - .attr('data-id', rt.k) - .attr('data-userpost', $.toJSON({userpost: rt, sig_userpost: userpost.sig_rt})) - .find('.post-text').html(htmlFormatMsg(rt.msg).html) - ; - setPostCommon(postContext, rt.n, rt.time); + setPostReference(postContext, rt, userpost.sig_rt); } else { postContext.append(_templatePostRtBy.clone(true)) .find('.post-retransmited-by') .attr('href', $.MAL.userUrl(retweeted_by)).text('@' + retweeted_by) ; + // let's check original post and grab some possible RT + dhtget(username, 'post' + k, 's', + function(args, post) { + if (post && post.userpost.msg && post.userpost.rt) { + var postContext = $('
'); + setPostReference(postContext, post.userpost.rt, post.userpost.sig_rt); + args.elem.find('.post-text').after(postContext); + } + }, {elem: elem} + ); } postContext.show(); } @@ -226,6 +213,32 @@ function postToElem(post, kind, promoted) { return elem; } +function setPostCommon(elem, username, time) { + var postInfoName = elem.find('.post-info-name') + .text(username).attr('href', $.MAL.userUrl(username)); + + getFullname(username, postInfoName); + //elem.find('.post-info-tag').text("@" + username); // FIXME + getAvatar(username, elem.find('.avatar')); + + elem.find('.post-info-time') + .attr('title', timeSincePost(time)) + .find('span:last') + .text(timeGmtToText(time)) + ; +} + +function setPostReference(elem, rt, sig_rt) { + elem.append(_templatePostRtReference.clone(true)) + .find('.post-rt-reference') + .attr('data-screen-name', rt.n) + .attr('data-id', rt.k) + .attr('data-userpost', $.toJSON({userpost: rt, sig_userpost: sig_rt})) + .find('.post-text').html(htmlFormatMsg(rt.msg).html) + ; + setPostCommon(elem, rt.n, rt.time); +} + function setPostInfoSent(n, k, item) { if( n === defaultScreenName && k >= 0 ) { getPostMaxAvailability(n,k,