Add liking feature
This commit is contained in:
parent
9d4675770b
commit
0f91bf7018
@ -234,6 +234,16 @@ class API:
|
|||||||
resp = Response('Goodbye')
|
resp = Response('Goodbye')
|
||||||
elif action == 'ping':
|
elif action == 'ping':
|
||||||
resp = Response('pong')
|
resp = Response('pong')
|
||||||
|
elif action == 'site':
|
||||||
|
block = data
|
||||||
|
siteData = self._core.getData(data)
|
||||||
|
response = 'not found'
|
||||||
|
if siteData != '' and siteData != False:
|
||||||
|
self.mimeType = 'text/html'
|
||||||
|
response = siteData.split(b'-', 2)[-1]
|
||||||
|
resp = Response(response)
|
||||||
|
elif action == 'info':
|
||||||
|
resp = Response(json.dumps({'pubkey' : self._core._crypto.pubKey, 'host' : self._core.hsAddress}))
|
||||||
elif action == "insertBlock":
|
elif action == "insertBlock":
|
||||||
response = {'success' : False, 'reason' : 'An unknown error occurred'}
|
response = {'success' : False, 'reason' : 'An unknown error occurred'}
|
||||||
|
|
||||||
@ -431,7 +441,7 @@ class API:
|
|||||||
else:
|
else:
|
||||||
logger.warn(newNode.decode() + ' failed to meet POW: ' + powHash)
|
logger.warn(newNode.decode() + ' failed to meet POW: ' + powHash)
|
||||||
resp = Response(resp)
|
resp = Response(resp)
|
||||||
return resp
|
return resp
|
||||||
|
|
||||||
@app.route('/public/')
|
@app.route('/public/')
|
||||||
def public_handler():
|
def public_handler():
|
||||||
|
@ -22,7 +22,7 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="onionr-post-controls pt-2">
|
<div class="onionr-post-controls pt-2">
|
||||||
<a href="#!" onclick="toggleLike('$post-hash')" class="glyphicon glyphicon-heart mr-2"><$= LANG.POST_LIKE $></a>
|
<a href="#!" onclick="toggleLike('$post-hash')" class="glyphicon glyphicon-heart mr-2">$liked</a>
|
||||||
<a href="#!" onclick="reply('$post-hash')" class="glyphicon glyphicon-comment mr-2"><$= LANG.POST_REPLY $></a>
|
<a href="#!" onclick="reply('$post-hash')" class="glyphicon glyphicon-comment mr-2"><$= LANG.POST_REPLY $></a>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
19
onionr/static-data/www/ui/dist/js/main.js
vendored
19
onionr/static-data/www/ui/dist/js/main.js
vendored
@ -25,11 +25,22 @@ function getParameter(name) {
|
|||||||
/* usermap localStorage stuff */
|
/* usermap localStorage stuff */
|
||||||
|
|
||||||
var usermap = JSON.parse(get('usermap', '{}'));
|
var usermap = JSON.parse(get('usermap', '{}'));
|
||||||
|
var postmap = JSON.parse(get('postmap', '{}'))
|
||||||
|
|
||||||
function getUserMap() {
|
function getUserMap() {
|
||||||
return usermap;
|
return usermap;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getPostMap(hash) {
|
||||||
|
if(hash !== undefined) {
|
||||||
|
if(hash in postmap)
|
||||||
|
return postmap[hash];
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return postmap;
|
||||||
|
}
|
||||||
|
|
||||||
function deserializeUser(id) {
|
function deserializeUser(id) {
|
||||||
if(!(id in getUserMap()))
|
if(!(id in getUserMap()))
|
||||||
return null;
|
return null;
|
||||||
@ -287,7 +298,7 @@ class Post {
|
|||||||
</div>\
|
</div>\
|
||||||
\
|
\
|
||||||
<div class="onionr-post-controls pt-2">\
|
<div class="onionr-post-controls pt-2">\
|
||||||
<a href="#!" onclick="toggleLike(\'$post-hash\')" class="glyphicon glyphicon-heart mr-2">like</a>\
|
<a href="#!" onclick="toggleLike(\'$post-hash\')" class="glyphicon glyphicon-heart mr-2">$liked</a>\
|
||||||
<a href="#!" onclick="reply(\'$post-hash\')" class="glyphicon glyphicon-comment mr-2">reply</a>\
|
<a href="#!" onclick="reply(\'$post-hash\')" class="glyphicon glyphicon-comment mr-2">reply</a>\
|
||||||
</div>\
|
</div>\
|
||||||
</div>\
|
</div>\
|
||||||
@ -313,6 +324,12 @@ class Post {
|
|||||||
postTemplate = postTemplate.replaceAll('$date-relative', timeSince(this.getPostDate(), device) + (device === 'desktop' ? ' ago' : ''));
|
postTemplate = postTemplate.replaceAll('$date-relative', timeSince(this.getPostDate(), device) + (device === 'desktop' ? ' ago' : ''));
|
||||||
postTemplate = postTemplate.replaceAll('$date', this.getPostDate().toLocaleString());
|
postTemplate = postTemplate.replaceAll('$date', this.getPostDate().toLocaleString());
|
||||||
|
|
||||||
|
if(this.getHash() in getPostMap() && getPostMap()[this.getHash()]['liked']) {
|
||||||
|
postTemplate = postTemplate.replaceAll('$liked', 'unlike');
|
||||||
|
} else {
|
||||||
|
postTemplate = postTemplate.replaceAll('$liked', 'like');
|
||||||
|
}
|
||||||
|
|
||||||
return postTemplate;
|
return postTemplate;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
29
onionr/static-data/www/ui/dist/js/timeline.js
vendored
29
onionr/static-data/www/ui/dist/js/timeline.js
vendored
@ -32,6 +32,28 @@ Block.getBlocks({'type' : 'onionr-post', 'signed' : true, 'reverse' : true}, fun
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
function toggleLike(hash) {
|
||||||
|
var post = getPostMap(hash);
|
||||||
|
if(post === null || !getPostMap()[hash]['liked']) {
|
||||||
|
console.log('Liking ' + hash + '...');
|
||||||
|
|
||||||
|
if(post === null)
|
||||||
|
getPostMap()[hash] = {};
|
||||||
|
|
||||||
|
getPostMap()[hash]['liked'] = true;
|
||||||
|
|
||||||
|
set('postmap', JSON.stringify(getPostMap()));
|
||||||
|
|
||||||
|
var block = new Block();
|
||||||
|
|
||||||
|
block.setType('onionr-post-like');
|
||||||
|
block.setContent(JSON.stringify({'hash' : hash}));
|
||||||
|
block.save(true, function(hash) {});
|
||||||
|
} else {
|
||||||
|
console.log('Unliking ' + hash + '...');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function postCreatorChange() {
|
function postCreatorChange() {
|
||||||
var content = document.getElementById('onionr-post-creator-content').value;
|
var content = document.getElementById('onionr-post-creator-content').value;
|
||||||
var message = '';
|
var message = '';
|
||||||
@ -55,9 +77,9 @@ function postCreatorChange() {
|
|||||||
var button = document.getElementById("onionr-post-creator-create");
|
var button = document.getElementById("onionr-post-creator-create");
|
||||||
|
|
||||||
if(message === '')
|
if(message === '')
|
||||||
element.style.display = 'none';
|
element.style.visibility = 'hidden';
|
||||||
else {
|
else {
|
||||||
element.style.display = 'block';
|
element.style.visibility = 'visible';
|
||||||
|
|
||||||
element.innerHTML = message;
|
element.innerHTML = message;
|
||||||
|
|
||||||
@ -139,6 +161,7 @@ function makePost() {
|
|||||||
document.getElementById('onionr-timeline-posts').innerHTML = post.getHTML() + document.getElementById('onionr-timeline-posts').innerHTML;
|
document.getElementById('onionr-timeline-posts').innerHTML = post.getHTML() + document.getElementById('onionr-timeline-posts').innerHTML;
|
||||||
|
|
||||||
document.getElementById("onionr-post-creator-content").value = "";
|
document.getElementById("onionr-post-creator-content").value = "";
|
||||||
|
postCreatorChange();
|
||||||
} else {
|
} else {
|
||||||
console.log('Not making empty post.');
|
console.log('Not making empty post.');
|
||||||
}
|
}
|
||||||
@ -163,6 +186,8 @@ $('body').on('click', '[data-editable]', function() {
|
|||||||
input.one('blur', save).focus();
|
input.one('blur', save).focus();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
currentUser = getCurrentUser();
|
||||||
|
|
||||||
document.getElementById("onionr-post-creator-user-name").innerHTML = Sanitize.html(currentUser.getName());
|
document.getElementById("onionr-post-creator-user-name").innerHTML = Sanitize.html(currentUser.getName());
|
||||||
document.getElementById("onionr-post-creator-user-id").innerHTML = "you";
|
document.getElementById("onionr-post-creator-user-id").innerHTML = "you";
|
||||||
document.getElementById("onionr-post-creator-user-icon").src = "data:image/jpeg;base64," + Sanitize.html(currentUser.getIcon());
|
document.getElementById("onionr-post-creator-user-icon").src = "data:image/jpeg;base64," + Sanitize.html(currentUser.getIcon());
|
||||||
|
@ -13,6 +13,7 @@
|
|||||||
"MODAL_MESSAGE" : "Onionr has begun performing a CPU-intensive operation. If this operation does not complete in the next 10 seconds, try reloading the page.",
|
"MODAL_MESSAGE" : "Onionr has begun performing a CPU-intensive operation. If this operation does not complete in the next 10 seconds, try reloading the page.",
|
||||||
|
|
||||||
"POST_LIKE" : "like",
|
"POST_LIKE" : "like",
|
||||||
|
"POST_UNLIKE" : "unlike",
|
||||||
"POST_REPLY" : "reply",
|
"POST_REPLY" : "reply",
|
||||||
|
|
||||||
"POST_CREATOR_YOU" : "you",
|
"POST_CREATOR_YOU" : "you",
|
||||||
|
@ -25,11 +25,22 @@ function getParameter(name) {
|
|||||||
/* usermap localStorage stuff */
|
/* usermap localStorage stuff */
|
||||||
|
|
||||||
var usermap = JSON.parse(get('usermap', '{}'));
|
var usermap = JSON.parse(get('usermap', '{}'));
|
||||||
|
var postmap = JSON.parse(get('postmap', '{}'))
|
||||||
|
|
||||||
function getUserMap() {
|
function getUserMap() {
|
||||||
return usermap;
|
return usermap;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getPostMap(hash) {
|
||||||
|
if(hash !== undefined) {
|
||||||
|
if(hash in postmap)
|
||||||
|
return postmap[hash];
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return postmap;
|
||||||
|
}
|
||||||
|
|
||||||
function deserializeUser(id) {
|
function deserializeUser(id) {
|
||||||
if(!(id in getUserMap()))
|
if(!(id in getUserMap()))
|
||||||
return null;
|
return null;
|
||||||
@ -281,6 +292,12 @@ class Post {
|
|||||||
postTemplate = postTemplate.replaceAll('$date-relative', timeSince(this.getPostDate(), device) + (device === 'desktop' ? ' ago' : ''));
|
postTemplate = postTemplate.replaceAll('$date-relative', timeSince(this.getPostDate(), device) + (device === 'desktop' ? ' ago' : ''));
|
||||||
postTemplate = postTemplate.replaceAll('$date', this.getPostDate().toLocaleString());
|
postTemplate = postTemplate.replaceAll('$date', this.getPostDate().toLocaleString());
|
||||||
|
|
||||||
|
if(this.getHash() in getPostMap() && getPostMap()[this.getHash()]['liked']) {
|
||||||
|
postTemplate = postTemplate.replaceAll('$liked', '<$= LANG.POST_UNLIKE $>');
|
||||||
|
} else {
|
||||||
|
postTemplate = postTemplate.replaceAll('$liked', '<$= LANG.POST_LIKE $>');
|
||||||
|
}
|
||||||
|
|
||||||
return postTemplate;
|
return postTemplate;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -32,6 +32,28 @@ Block.getBlocks({'type' : 'onionr-post', 'signed' : true, 'reverse' : true}, fun
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
function toggleLike(hash) {
|
||||||
|
var post = getPostMap(hash);
|
||||||
|
if(post === null || !getPostMap()[hash]['liked']) {
|
||||||
|
console.log('Liking ' + hash + '...');
|
||||||
|
|
||||||
|
if(post === null)
|
||||||
|
getPostMap()[hash] = {};
|
||||||
|
|
||||||
|
getPostMap()[hash]['liked'] = true;
|
||||||
|
|
||||||
|
set('postmap', JSON.stringify(getPostMap()));
|
||||||
|
|
||||||
|
var block = new Block();
|
||||||
|
|
||||||
|
block.setType('onionr-post-like');
|
||||||
|
block.setContent(JSON.stringify({'hash' : hash}));
|
||||||
|
block.save(true, function(hash) {});
|
||||||
|
} else {
|
||||||
|
console.log('Unliking ' + hash + '...');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function postCreatorChange() {
|
function postCreatorChange() {
|
||||||
var content = document.getElementById('onionr-post-creator-content').value;
|
var content = document.getElementById('onionr-post-creator-content').value;
|
||||||
var message = '';
|
var message = '';
|
||||||
@ -55,9 +77,9 @@ function postCreatorChange() {
|
|||||||
var button = document.getElementById("onionr-post-creator-create");
|
var button = document.getElementById("onionr-post-creator-create");
|
||||||
|
|
||||||
if(message === '')
|
if(message === '')
|
||||||
element.style.display = 'none';
|
element.style.visibility = 'hidden';
|
||||||
else {
|
else {
|
||||||
element.style.display = 'block';
|
element.style.visibility = 'visible';
|
||||||
|
|
||||||
element.innerHTML = message;
|
element.innerHTML = message;
|
||||||
|
|
||||||
@ -139,6 +161,7 @@ function makePost() {
|
|||||||
document.getElementById('onionr-timeline-posts').innerHTML = post.getHTML() + document.getElementById('onionr-timeline-posts').innerHTML;
|
document.getElementById('onionr-timeline-posts').innerHTML = post.getHTML() + document.getElementById('onionr-timeline-posts').innerHTML;
|
||||||
|
|
||||||
document.getElementById("onionr-post-creator-content").value = "";
|
document.getElementById("onionr-post-creator-content").value = "";
|
||||||
|
postCreatorChange();
|
||||||
} else {
|
} else {
|
||||||
console.log('Not making empty post.');
|
console.log('Not making empty post.');
|
||||||
}
|
}
|
||||||
@ -163,6 +186,8 @@ $('body').on('click', '[data-editable]', function() {
|
|||||||
input.one('blur', save).focus();
|
input.one('blur', save).focus();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
currentUser = getCurrentUser();
|
||||||
|
|
||||||
document.getElementById("onionr-post-creator-user-name").innerHTML = Sanitize.html(currentUser.getName());
|
document.getElementById("onionr-post-creator-user-name").innerHTML = Sanitize.html(currentUser.getName());
|
||||||
document.getElementById("onionr-post-creator-user-id").innerHTML = "<$= LANG.POST_CREATOR_YOU $>";
|
document.getElementById("onionr-post-creator-user-id").innerHTML = "<$= LANG.POST_CREATOR_YOU $>";
|
||||||
document.getElementById("onionr-post-creator-user-icon").src = "data:image/jpeg;base64," + Sanitize.html(currentUser.getIcon());
|
document.getElementById("onionr-post-creator-user-icon").src = "data:image/jpeg;base64," + Sanitize.html(currentUser.getIcon());
|
||||||
|
Loading…
Reference in New Issue
Block a user