|
|
|
@ -24,16 +24,42 @@ webpassword = webpass |
|
|
|
|
newPostForm = document.getElementById('addMsg') |
|
|
|
|
firstLoad = true |
|
|
|
|
lastLoadedBoard = 'global' |
|
|
|
|
loadingMessage = document.getElementById('loadingBoard') |
|
|
|
|
|
|
|
|
|
let toggleLoadingMessage = function(){ |
|
|
|
|
switch (loadingMessage.style.display){ |
|
|
|
|
case "block": |
|
|
|
|
case "inline": |
|
|
|
|
case "inline-block": |
|
|
|
|
loadingMessage.style.display = "none" |
|
|
|
|
break; |
|
|
|
|
default: |
|
|
|
|
loadingMessage.style.display = "initial" |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
function appendMessages(msg){ |
|
|
|
|
fetch('/flow/version', { |
|
|
|
|
method: 'GET', |
|
|
|
|
headers: { |
|
|
|
|
"token": webpass |
|
|
|
|
}}) |
|
|
|
|
.then((resp) => resp.text()) // Transform the data into json
|
|
|
|
|
.then(function(data) { |
|
|
|
|
document.getElementById('circlesVersion').innerText = data |
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
function appendMessages(msg, blockHash, beforeHash){ |
|
|
|
|
var humanDate = new Date(0) |
|
|
|
|
if (msg.length == 0){ |
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
var msg = JSON.parse(msg) |
|
|
|
|
var dateEl = document.createElement('div') |
|
|
|
|
//var msg = JSON.parse(msg)
|
|
|
|
|
var el = document.createElement('div') |
|
|
|
|
var msgDate = msg['meta']['time'] |
|
|
|
|
var feed = document.getElementById("feed") |
|
|
|
|
var beforeEl = null |
|
|
|
|
|
|
|
|
|
if (msgDate === undefined){ |
|
|
|
|
msgDate = 'unknown' |
|
|
|
|
} |
|
|
|
@ -43,6 +69,13 @@ function appendMessages(msg){ |
|
|
|
|
} |
|
|
|
|
el.className = 'entry' |
|
|
|
|
el.innerText = msg['content'] |
|
|
|
|
if (beforeHash !== null){ |
|
|
|
|
for (x = 0; x < feed.children.length; x++){ |
|
|
|
|
if (feed.children[x].getAttribute('data-bl') === beforeHash){ |
|
|
|
|
beforeEl = feed.children[x] |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/* Template Test */ |
|
|
|
|
// Test to see if the browser supports the HTML template element by checking
|
|
|
|
@ -54,9 +87,10 @@ function appendMessages(msg){ |
|
|
|
|
var template = document.getElementById('cMsgTemplate') |
|
|
|
|
|
|
|
|
|
// Clone the new row and insert it into the table
|
|
|
|
|
var feed = document.getElementById("feed") |
|
|
|
|
var clone = document.importNode(template.content, true); |
|
|
|
|
var clone = document.importNode(template.content, true) |
|
|
|
|
var div = clone.querySelectorAll("div") |
|
|
|
|
|
|
|
|
|
div[0].setAttribute('data-bl', blockHash) |
|
|
|
|
div[2].textContent = msg['content'] |
|
|
|
|
if (typeof msg['meta']['signer'] != 'undefined'){ |
|
|
|
|
div[3].textContent = msg['meta']['signer'].substr(0, 5) |
|
|
|
@ -64,16 +98,23 @@ function appendMessages(msg){ |
|
|
|
|
} |
|
|
|
|
div[4].textContent = msgDate |
|
|
|
|
|
|
|
|
|
loadingMessage.style.display = "none" |
|
|
|
|
if (firstLoad){ |
|
|
|
|
feed.appendChild(clone) |
|
|
|
|
//feed.appendChild(clone)
|
|
|
|
|
feed.prepend(clone) |
|
|
|
|
firstLoad = false |
|
|
|
|
} |
|
|
|
|
else{ |
|
|
|
|
feed.prepend(clone) |
|
|
|
|
if (beforeEl === null){ |
|
|
|
|
feed.prepend(clone) |
|
|
|
|
} |
|
|
|
|
else{ |
|
|
|
|
//feed.insertAfter(clone, beforeEl)
|
|
|
|
|
beforeEl.insertAdjacentElement("beforebegin", clone) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} else { |
|
|
|
|
// Find another way to add the rows to the table because
|
|
|
|
|
// the HTML template element is not supported.
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -81,6 +122,7 @@ function getBlocks(){ |
|
|
|
|
var feed = document.getElementById("feed") |
|
|
|
|
var ch = document.getElementById('feedIDInput').value |
|
|
|
|
if (lastLoadedBoard !== ch){ |
|
|
|
|
toggleLoadingMessage() |
|
|
|
|
while (feed.firstChild) { |
|
|
|
|
feed.removeChild(feed.firstChild); |
|
|
|
|
} |
|
|
|
@ -92,23 +134,49 @@ function getBlocks(){ |
|
|
|
|
document.getElementById('none').remove(); |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
var feedText = httpGet('/flow/getpostsbyboard/' + ch) |
|
|
|
|
var blockList = feedText.split(',').reverse() |
|
|
|
|
var blockList = feedText.split(',') |
|
|
|
|
|
|
|
|
|
for (i = 0; i < blockList.length; i++){ |
|
|
|
|
while (blockList[i].length < 64) blockList[i] = "0" + blockList[i] |
|
|
|
|
while (blockList[i].length < 64) { blockList[i] = "0" + blockList[i] } |
|
|
|
|
if (! requested.includes(blockList[i])){ |
|
|
|
|
if (blockList[i].length == 0){ |
|
|
|
|
continue |
|
|
|
|
} |
|
|
|
|
bl = httpGet('/getblockdata/' + blockList[i]) |
|
|
|
|
appendMessages(bl) |
|
|
|
|
requested.push(blockList[i]) |
|
|
|
|
} |
|
|
|
|
loadMessage(blockList[i], blockList, i) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
firstLoad = false |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
function loadMessage(blockHash, blockList, count){ |
|
|
|
|
fetch('/getblockdata/' + blockHash, { |
|
|
|
|
method: 'GET', |
|
|
|
|
headers: { |
|
|
|
|
"token": webpass |
|
|
|
|
}}) |
|
|
|
|
.then((resp) => resp.json()) |
|
|
|
|
.then(function(data) { |
|
|
|
|
let before = blockList[count - 1] |
|
|
|
|
let delay = 2000 |
|
|
|
|
if (typeof before == "undefined"){ |
|
|
|
|
before = null |
|
|
|
|
} |
|
|
|
|
else{ |
|
|
|
|
let existing = document.getElementsByClassName('cMsgBox') |
|
|
|
|
for (x = 0; x < existing.length; x++){ |
|
|
|
|
if (existing[x].getAttribute('data-bl') === before){ |
|
|
|
|
delay = 0 |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
setTimeout(function(){appendMessages(data, blockHash, before)}, delay) |
|
|
|
|
//appendMessages(data, blockHash, before)
|
|
|
|
|
}) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
document.getElementById('refreshFeed').onclick = function(){ |
|
|
|
|
getBlocks() |
|
|
|
|
} |
|
|
|
@ -140,7 +208,7 @@ newPostForm.onsubmit = function(){ |
|
|
|
|
PNotify.success({ |
|
|
|
|
text: "Message queued for posting" |
|
|
|
|
}) |
|
|
|
|
setTimeout(function(){getBlocks()}, 3000) |
|
|
|
|
setTimeout(function(){getBlocks()}, 500) |
|
|
|
|
}) |
|
|
|
|
return false |
|
|
|
|
} |