@@ -40,11 +46,13 @@
-
+
+
+
diff --git a/onionr/static-data/www/ui/src/js/main.js b/onionr/static-data/www/ui/src/js/main.js
index ca2c5214..808809ba 100644
--- a/onionr/static-data/www/ui/src/js/main.js
+++ b/onionr/static-data/www/ui/src/js/main.js
@@ -115,10 +115,10 @@ function timeSince(date, size) {
}
/* replace all instances of string */
-String.prototype.replaceAll = function(search, replacement) {
+String.prototype.replaceAll = function(search, replacement, limit) {
// taken from https://stackoverflow.com/a/17606289/3678023
var target = this;
- return target.split(search).join(replacement);
+ return target.split(search, limit).join(replacement);
};
/* useful functions to sanitize data */
@@ -276,7 +276,8 @@ class Post {
postTemplate = postTemplate.replaceAll('$user-id', Sanitize.html(this.getUser().getID()));
postTemplate = postTemplate.replaceAll('$user-image', "data:image/jpeg;base64," + Sanitize.html(this.getUser().getIcon()));
- postTemplate = postTemplate.replaceAll('$content', Sanitize.html(this.getContent()));
+ postTemplate = postTemplate.replaceAll('$content', Sanitize.html(this.getContent()).replaceAll('\n', '
', 16)); // Maximum of 16 lines
+ postTemplate = postTemplate.replaceAll('$post-hash', this.getHash());
postTemplate = postTemplate.replaceAll('$date-relative', timeSince(this.getPostDate(), device) + (device === 'desktop' ? ' ago' : ''));
postTemplate = postTemplate.replaceAll('$date', this.getPostDate().toLocaleString());
@@ -310,6 +311,14 @@ class Post {
return this.date;
}
+ setHash(hash) {
+ this.hash = hash;
+ }
+
+ getHash() {
+ return this.hash;
+ }
+
save(callback) {
var args = {'type' : 'onionr-post', 'sign' : true, 'content' : JSON.stringify({'content' : this.getContent()})};
@@ -322,8 +331,11 @@ class Post {
if(callback !== undefined) {
// async
+ var thisObject = this;
+
http.addEventListener('load', function() {
- callback(Block.parseBlockArray(JSON.parse(http.responseText)['hash']));
+ thisObject.setHash(Block.parseBlockArray(JSON.parse(http.responseText)['hash']));
+ callback(thisObject.getHash());
}, false);
http.open('GET', url, true);
@@ -335,7 +347,9 @@ class Post {
http.open('GET', url, false);
http.send(null);
- return Block.parseBlockArray(JSON.parse(http.responseText)['hash']);
+ this.setHash(Block.parseBlockArray(JSON.parse(http.responseText)['hash']));
+
+ return this.getHash();
}
}
}
diff --git a/onionr/static-data/www/ui/src/js/timeline.js b/onionr/static-data/www/ui/src/js/timeline.js
index c411f41c..0aea4f28 100644
--- a/onionr/static-data/www/ui/src/js/timeline.js
+++ b/onionr/static-data/www/ui/src/js/timeline.js
@@ -10,11 +10,16 @@ Block.getBlocks({'type' : 'onionr-post', 'signed' : true, 'reverse' : true}, fun
var blockContent = JSON.parse(block.getContent());
- post.setContent(blockContent['content']);
- post.setPostDate(block.getDate());
- post.setUser(user);
+ // just ignore anything shorter than 280 characters
+ if(String(blockContent['content']).length <= 280) {
+ post.setContent(blockContent['content']);
+ post.setPostDate(block.getDate());
+ post.setUser(user);
- document.getElementById('onionr-timeline-posts').innerHTML += post.getHTML();
+ post.setHash(block.getHash());
+
+ document.getElementById('onionr-timeline-posts').innerHTML += post.getHTML();
+ }
finished = true;
});
@@ -27,6 +32,47 @@ Block.getBlocks({'type' : 'onionr-post', 'signed' : true, 'reverse' : true}, fun
}
});
+function postCreatorChange() {
+ var content = document.getElementById('onionr-post-creator-content').value;
+ var message = '';
+
+ var disable = true;
+
+ if(content.length !== 0) {
+ if(content.length - content.replaceAll('\n', '').length > 16) {
+ // 16 max newlines
+ message = '<$= LANG.POST_CREATOR_MESSAGE_MAXIMUM_NEWLINES $>';
+ } else if(content.length <= 280) {
+ // 280 max characters
+ message = '<$= LANG.POST_CREATOR_MESSAGE_REMAINING $>'.replaceAll('%s', (280 - content.length));
+ disable = false;
+ } else {
+ message = '<$= LANG.POST_CREATOR_MESSAGE_OVER $>'.replaceAll('%s', (content.length - 280));
+ }
+ }
+
+ var element = document.getElementById('onionr-post-creator-content-message');
+ var button = document.getElementById("onionr-post-creator-create");
+
+ if(message === '')
+ element.style.display = 'none';
+ else {
+ element.style.display = 'block';
+
+ element.innerHTML = message;
+
+ if(disable)
+ element.style.color = 'red';
+ else
+ element.style.color = 'gray';
+ }
+
+ if(disable)
+ button.disabled = true;
+ else
+ button.disabled = false;
+}
+
function viewProfile(id, name) {
id = decodeURIComponent(id);
document.getElementById("onionr-profile-username").innerHTML = Sanitize.html(decodeURIComponent(name));
@@ -129,3 +175,6 @@ viewCurrentProfile = function() {
document.getElementById("onionr-post-creator-user-id").onclick = viewCurrentProfile;
document.getElementById("onionr-post-creator-user-name").onclick = viewCurrentProfile;
+
+// on some browsers it saves the user input on reload. So, it should also recheck the input.
+postCreatorChange();