Commit 548c9c13 authored by buttle's avatar buttle

ordered converstaion.

parent b5b69445
Pipeline #28 skipped
......@@ -52,21 +52,26 @@
margin-bottom: 0.7em;
}
.Conversation .gsb-quip:not(:first-child) {
.Conversation > .Quip ~ .Quip {
padding-left: 2em;
}
.Conversation .Quip:not(:first-child) .Profile img {
.Conversation > .Quip ~ .Quip > .Profile img {
width: 36px;
height: 36px;
}
.Conversation .gsb-quip:not(:first-child) .GetConversationLink{
.Conversation .GetConversationLink{
display:none;
}
.Conversation .ConversationStats {
padding-left: 0.5em;
border-bottom: thin solid lightgray;
margin-bottom: 0.5em;
}
.Conversation .ConversationStats span{
padding: 0 3px 0 3px;
background-color: #1EAEDB;
color: #fff;
}
.No_external_url {
background-color: orange !important;
}
......@@ -83,7 +83,7 @@ function loadConversation(element){
var $statsistics = $('<div class="gsb-converse_stats ConversationStats"></div>');
$statsistics.append('<div>Converstaion stats: Downloaded / Incorporated: <span><span class="gsb-total_downloaded">0</span> / <span class="gsb-total_incorporated">0</span></span></div>');
$converseBlock.append($statsistics);
$converseBlock.prepend($statsistics);
var URLdata = split_URL(element.href, 'conversation');
callAPI(URLdata['apiURL'], function(APIresult){
......@@ -140,9 +140,9 @@ function renderQuips(APIresult, URLdata){
function createQuip_ID(APIresult, URLdata){
// better to get the id from external_url but not all nodes generate it.
if (typeof APIresult.external_url !== 'undefined') {
return 'quip_'+split_URL(APIresult.external_url, 'notice')['identifier']
return 'quip_'+split_URL(APIresult.external_url, 'notice')['identifier']; //+APIresult.user.screen_name;
}
return 'quip_'+APIresult.id;
return 'quip_'+APIresult.id; //+APIresult.user.screen_name;
}
function buildQuip(data, URLdata){
......@@ -160,9 +160,10 @@ function buildQuip(data, URLdata){
$message=$('<div class="Message">'+data.statusnet_html+'</div>');
$options=$('<div class="QuipOptions gsb-quip_options"></div>');
$options.append('<span class="date">'+data.created_at+'</span>');
$quip.attr('timestamp', Date.parse(data.created_at));
$options.append('<span class="QuipSource">Source: '+URLdata.hostname+'</span>');
if (data.in_reply_to_user_id != null){
//if (data.statusnet_conversation_id != null){ // every notice has a statusnet_conversation_id ??
//if (data.statusnet_conversation_id != null){ // every notice has a statusnet_conversation_id :(
$options.append('<a class="gsb-request_convers GetConversationLink" href="'+URLdata.host+'/conversation/'+data.statusnet_conversation_id+'" id="'+data.statusnet_conversation_id+'">Conversation</a>');
}
$quip.append($profile);
......@@ -175,23 +176,26 @@ function buildQuip(data, URLdata){
//––––––––––––––––––––––––––––––––––––––––––––––––––
function constructConversation($converseBlock, APIresult, URLdata, queriedNodes){
if (APIresult.length === 'undefined') {
alert("APIresult.length === 'undefined'");
if (! $.isArray(APIresult)) {
console.log(URLdata.apiURL+' did not return an array');
return;
}
}
var $totalDownloaded = $converseBlock.find('.gsb-total_downloaded');
var $totalIncorporated = $converseBlock.find('.gsb-total_incorporated');
$totalDownloaded.html(parseInt($totalDownloaded.html())+APIresult.length);
var $stats = addNodeStatsToConversation($converseBlock, APIresult, URLdata);
// render the quips.
for(var s=0; s<APIresult.length; s++) {
var reply=APIresult[s];
var $incorporated = $stats.find('.gsb-converse_incorporated');
$quip = buildQuip(reply, URLdata);
if ($converseBlock.find($quip).length === 0){ // this is a new quip
if (typeof reply.external_url === 'undefined') {
$incorporated.addClass('No_external_url');
}
$incorporated.html(parseInt( $incorporated.html() ) +1);
$totalIncorporated.html(parseInt($totalIncorporated.html())+1);
}
......@@ -202,7 +206,7 @@ function constructConversation($converseBlock, APIresult, URLdata, queriedNodes)
var reply=APIresult[s];
if (typeof reply.external_url === 'undefined') {
console.log('external_url not defined on server??'+reply);
console.log('external_url not defined on server: '+reply);
continue;
}
var reply_URLdata = split_URL(reply.external_url, 'notice');
......@@ -212,11 +216,8 @@ function constructConversation($converseBlock, APIresult, URLdata, queriedNodes)
var API_ID = createAPI_ID(converse_URLdata);
if ($.inArray( API_ID, queriedNodes ) == -1){
queriedNodes.push(API_ID);
// get the list of quips from the thread
callAPI(converse_URLdata['apiURL'], function(result){
//$converseBlock.find('.gsb-converse_stats').append('<div class="API">'+converse_URLdata.apiURL+': '+result.length+' quips</div>');
queriedNodes.push(API_ID); // don't query this node for this conversation ID again.
callAPI(converse_URLdata['apiURL'], function(result){ // get the list of quips from the thread
constructConversation($converseBlock, result, converse_URLdata, queriedNodes);
});
}
......@@ -224,8 +225,17 @@ function constructConversation($converseBlock, APIresult, URLdata, queriedNodes)
}
}
function insertQuipIntoConversation($converseBlock, $quip){
//console.log($quip);
$quip.prependTo($converseBlock);
var inserted=false;
$($converseBlock).find('.gsb-quip').each( function(){
if($quip.attr('timestamp') < $(this).attr('timestamp')){
$quip.insertBefore($(this));
inserted=true;
return false;
}
});
if(! inserted){
$converseBlock.append($quip);
}
}
function addNodeStatsToConversation($converseBlock, APIresult, node_URLdata){
var id = 'gsb-nodeStats_'+createAPI_ID(node_URLdata);
......@@ -379,9 +389,13 @@ function callAPI(url, cb_func){
crossDomain: true,
dataType: 'jsonp',
beforeSend: function() { $('#loader').show(); },
complete: function() { $('#loader').hide(); },
complete: function(xhr, data) {
if (xhr.status === 404){
alert('404 fail');
}
$('#loader').hide(); },
success: function(APIresult){
console.log(APIresult);
//console.log(APIresult);
cb_func(APIresult);
},
error: function(APIresult){console.log(APIresult); alert('error'); }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment