Onionr/onionr/static-data/www/ui/dist/js/timeline.js

73 lines
2.3 KiB
JavaScript
Raw Normal View History

2018-09-02 22:44:23 +00:00
function getUserInfo(id, callback) {
var user = deserializeUser(id);
if(user === null) {
Block.getBlocks({'type' : 'onionr-user-info', 'signed' : true, 'reverse' : true}, function(data) {
if(data.length !== 0) {
try {
user = new User();
var userInfo = JSON.parse(data[0].getContent());
if(userInfo['id'] === id) {
user.setName(userInfo['name']);
user.setIcon(userInfo['icon']);
user.setID(id);
serializeUser(user);
return callback(user);
}
} catch(e) {
console.log(e);
return callback(null);
}
} else {
return callback(null);
}
});
} else {
return callback(user);
}
}
2018-08-05 04:09:33 +00:00
/* just for testing rn */
Block.getBlocks({'type' : 'onionr-post', 'signed' : true, 'reverse' : true}, function(data) {
for(var i = 0; i < data.length; i++) {
try {
var block = data[i];
2018-09-02 22:44:23 +00:00
var finished = false;
getUserInfo(new String(block.getHeader('signer', 'unknown')), function(user) {
var post = new Post();
var blockContent = JSON.parse(block.getContent());
post.setContent(blockContent['content']);
post.setPostDate(block.getDate());
post.setUser(user);
2018-08-05 04:09:33 +00:00
2018-09-02 22:44:23 +00:00
document.getElementById('onionr-timeline-posts').innerHTML += post.getHTML();
2018-08-05 04:09:33 +00:00
2018-09-02 22:44:23 +00:00
finished = true;
});
2018-08-05 04:09:33 +00:00
2018-09-02 22:44:23 +00:00
while(!finished);
2018-08-05 04:09:33 +00:00
} catch(e) {
console.log(e);
}
}
});
2018-08-04 02:52:45 +00:00
2018-07-30 00:43:28 +00:00
function viewProfile(id, name) {
2018-09-02 22:44:23 +00:00
id = decodeURIComponent(id);
2018-08-05 04:16:42 +00:00
document.getElementById("onionr-profile-username").innerHTML = Sanitize.html(decodeURIComponent(name));
2018-09-02 22:44:23 +00:00
getUserInfo(id, function(data) {
if(data !== null) {
document.getElementById("onionr-profile-username").innerHTML = Sanitize.html(data.getName());
document.getElementById("onionr-profile-username").title = Sanitize.html(data.getID());
document.getElementById("onionr-profile-user-icon").src = "data:image/jpeg;base64," + Sanitize.html(data.getIcon());
}
});
2018-07-30 00:43:28 +00:00
}