clean up of posts and some template additions

v1.18.x
Baris Usakli 12 years ago
parent 38da65ee58
commit a87ebb64d8

@ -297,8 +297,8 @@ var socket,
}); });
} }
app.makeNumbersHumanReadable = function() { app.makeNumbersHumanReadable = function(selector) {
$('.human-readable-number').each(function() { $(selector).each(function() {
var num = parseInt($(this).html(), 10); var num = parseInt($(this).html(), 10);
$(this).html(utils.makeNumberHumanReadable(num)); $(this).html(utils.makeNumberHumanReadable(num));
}); });
@ -312,7 +312,7 @@ var socket,
$('span.timeago').timeago(); $('span.timeago').timeago();
$('.post-content img').addClass('img-responsive'); $('.post-content img').addClass('img-responsive');
app.makeNumbersHumanReadable(); app.makeNumbersHumanReadable('.human-readable-number');
app.createUserTooltips(); app.createUserTooltips();

@ -866,10 +866,6 @@ define(function() {
if(!data || (data.posts && !data.posts.length)) if(!data || (data.posts && !data.posts.length))
return; return;
if (data.posts[0].uid !== app.uid) {
data.posts[0].display_moderator_tools = 'none';
}
function removeAlreadyAddedPosts() { function removeAlreadyAddedPosts() {
data.posts = data.posts.filter(function(post) { data.posts = data.posts.filter(function(post) {
return $('#post-container li[data-pid="' + post.pid +'"]').length === 0; return $('#post-container li[data-pid="' + post.pid +'"]').length === 0;

@ -15,9 +15,11 @@
<div class="account-online-status"> <div class="account-online-status">
<span><i class="fa fa-circle-o"></i> <span>offline</span></span> <span><i class="fa fa-circle-o"></i> <span>offline</span></span>
</div> </div>
<div class="{show_banned}"> <!-- IF banned -->
<div>
<span class="label label-danger">banned</span> <span class="label label-danger">banned</span>
</div> </div>
<!-- ENDIF banned -->
<div id="user-actions"> <div id="user-actions">
<a id="follow-btn" href="#" class="btn btn-default">Follow</a> <a id="follow-btn" href="#" class="btn btn-default">Follow</a>
<a id="unfollow-btn" href="#" class="btn btn-default">Unfollow</a> <a id="unfollow-btn" href="#" class="btn btn-default">Unfollow</a>

@ -36,7 +36,9 @@
<div class="col-md-1 profile-image-block hidden-xs hidden-sm sub-post"> <div class="col-md-1 profile-image-block hidden-xs hidden-sm sub-post">
<a href="/user/{posts.userslug}"> <a href="/user/{posts.userslug}">
<img src="{posts.picture}" align="left" class="img-thumbnail" itemprop="image" /> <img src="{posts.picture}" align="left" class="img-thumbnail" itemprop="image" />
<span class="label label-danger {posts.show_banned}">[[topic:banned]]</span> <!-- IF posts.user_banned -->
<span class="label label-danger">[[topic:banned]]</span>
<!-- ENDIF posts.user_banned -->
</a> </a>
</div> </div>
@ -64,9 +66,17 @@
<div class="btn-group"> <div class="btn-group">
<button class="btn btn-sm btn-default follow main-post" type="button" title="Be notified of new replies in this topic"><i class="fa fa-eye"></i></button> <button class="btn btn-sm btn-default follow main-post" type="button" title="Be notified of new replies in this topic"><i class="fa fa-eye"></i></button>
<button class="favourite btn btn-sm btn-default {posts.fav_button_class}" type="button"> <button class="favourite btn btn-sm btn-default <!-- IF posts.favourited --> btn-warning <!-- ENDIF posts.favourited -->" type="button">
<span class="favourite-text">[[topic:favourite]]</span> <span class="favourite-text">[[topic:favourite]]</span>
<span class="post_rep_{posts.pid}">{posts.post_rep} </span><i class="fa {posts.fav_star_class}"></i> <span class="post_rep_{posts.pid}">{posts.reputation} </span>
<!-- IF posts.favourited -->
<i class="fa fa-star"></i>
<!-- ELSE -->
<i class="fa fa-star-o"></i>
<!-- ENDIF posts.favourited -->
</button> </button>
</div> </div>
<div class="btn-group"> <div class="btn-group">
@ -82,10 +92,12 @@
<button class="btn btn-sm btn-default google-share" type="button" title=""><i class="fa fa-google-plus"></i></button> <button class="btn btn-sm btn-default google-share" type="button" title=""><i class="fa fa-google-plus"></i></button>
</div> </div>
<!-- IF posts.display_moderator_tools -->
<div class="btn-group post-tools"> <div class="btn-group post-tools">
<button class="btn btn-sm btn-default edit {posts.display_moderator_tools}" type="button" title="[[topic:edit]]"><i class="fa fa-pencil"></i></button> <button class="btn btn-sm btn-default edit" type="button" title="[[topic:edit]]"><i class="fa fa-pencil"></i></button>
<button class="btn btn-sm btn-default delete {posts.display_moderator_tools}" type="button" title="[[topic:delete]]"><i class="fa fa-trash-o"></i></button> <button class="btn btn-sm btn-default delete" type="button" title="[[topic:delete]]"><i class="fa fa-trash-o"></i></button>
</div> </div>
<!-- ENDIF posts.display_moderator_tools -->
</div> </div>
<input id="post_{posts.pid}_link" value="" class="pull-right" style="display:none;"></input> <input id="post_{posts.pid}_link" value="" class="pull-right" style="display:none;"></input>
@ -102,8 +114,10 @@
</span> </span>
<span class="pull-right"> <span class="pull-right">
posted <span class="relativeTimeAgo timeago" title="{posts.relativeTime}"></span> posted <span class="relativeTimeAgo timeago" title="{posts.relativeTime}"></span>
<span class="{posts.edited-class}">| last edited by <strong><a href="/user/{posts.editorslug}">{posts.editorname}</a></strong></span> <!-- IF posts.editor -->
<span>| last edited by <strong><a href="/user/{posts.editorslug}">{posts.editorname}</a></strong></span>
<span class="timeago" title="{posts.relativeEditTime}"></span> <span class="timeago" title="{posts.relativeEditTime}"></span>
<!-- ENDIF posts.editor -->
</span> </span>
<div style="clear:both;"></div> <div style="clear:both;"></div>
</div> </div>

@ -29,7 +29,9 @@
Feed.updateTopic = function (tid, callback) { Feed.updateTopic = function (tid, callback) {
topics.getTopicWithPosts(tid, 0, 0, -1, function (err, topicData) { topics.getTopicWithPosts(tid, 0, 0, -1, function (err, topicData) {
if (err) return callback(new Error('topic-invalid')); if (err) {
return callback(new Error('topic-invalid'));
}
var feed = new rss({ var feed = new rss({
title: topicData.topic_name, title: topicData.topic_name,
@ -44,7 +46,9 @@
dateStamp; dateStamp;
// Add pubDate if topic contains posts // Add pubDate if topic contains posts
if (topicData.posts.length > 0) feed.pubDate = new Date(parseInt(topicData.posts[0].timestamp, 10)).toUTCString(); if (topicData.posts.length > 0) {
feed.pubDate = new Date(parseInt(topicData.posts[0].timestamp, 10)).toUTCString();
}
async.each(topic_posts, function(postData, next) { async.each(topic_posts, function(postData, next) {
if (postData.deleted === '0') { if (postData.deleted === '0') {
@ -65,7 +69,9 @@
winston.info('[rss] Re-generated RSS Feed for tid ' + tid + '.'); winston.info('[rss] Re-generated RSS Feed for tid ' + tid + '.');
} }
if (callback) callback(); if (callback) {
callback();
}
}); });
}); });

@ -54,18 +54,25 @@ var RDB = require('./redis'),
'reputation': 0, 'reputation': 0,
'editor': '', 'editor': '',
'edited': 0, 'edited': 0,
'deleted': 0, 'deleted': 0
'fav_button_class': '', //TODO : write upgrade script to remove these fields from the database -barisu
'fav_star_class': 'fa-star-o', //'fav_button_class': '',
'show_banned': 'hide', //'fav_star_class': 'fa-star-o',
'relativeTime': new Date(timestamp).toISOString(), //'show_banned': 'hide',
'post_rep': '0', //'relativeTime': new Date(timestamp).toISOString(),
'edited-class': 'none', //'post_rep': '0',
'relativeEditTime': '' //'edited-class': 'none',
//'relativeEditTime': ''
}; };
RDB.hmset('post:' + pid, postData); RDB.hmset('post:' + pid, postData);
postData.favourited = false;
postData.display_moderator_tools = true;
postData.relativeTime = new Date(timestamp).toISOString();
//TODO : remove this once template bug is fixed -barisu (https://github.com/designcreateplay/NodeBB/issues/574)
postData.fav_star_class = 'fa-star-o';
topics.addPostToTopic(tid, pid); topics.addPostToTopic(tid, pid);
topics.increasePostCount(tid); topics.increasePostCount(tid);
topics.updateTimestamp(tid, timestamp); topics.updateTimestamp(tid, timestamp);
@ -78,8 +85,8 @@ var RDB = require('./redis'),
var cid = topicData.cid; var cid = topicData.cid;
feed.updateTopic(tid); //feed.updateTopic(tid);
feed.updateRecent(); //feed.updateRecent();
RDB.zadd('categories:recent_posts:cid:' + cid, timestamp, pid); RDB.zadd('categories:recent_posts:cid:' + cid, timestamp, pid);
@ -178,7 +185,6 @@ var RDB = require('./redis'),
if(err) { if(err) {
return callback(err, null); return callback(err, null);
} }
callback(null, postData); callback(null, postData);
}); });
}); });
@ -217,7 +223,7 @@ var RDB = require('./redis'),
post.userslug = userData.userslug || ''; post.userslug = userData.userslug || '';
post.user_rep = userData.reputation || 0; post.user_rep = userData.reputation || 0;
post.user_postcount = userData.postcount || 0; post.user_postcount = userData.postcount || 0;
post.user_banned = userData.banned || '0'; post.user_banned = userData.banned === '1';
post.picture = userData.picture || require('gravatar').url('', {}, https = nconf.get('https')); post.picture = userData.picture || require('gravatar').url('', {}, https = nconf.get('https'));
post.signature = signature; post.signature = signature;
@ -367,8 +373,6 @@ var RDB = require('./redis'),
async.map(replies, function(postData, _callback) { async.map(replies, function(postData, _callback) {
if (postData) { if (postData) {
postData.post_rep = postData.reputation;
postData['edited-class'] = postData.editor !== '' ? '' : 'none';
try { try {
postData.relativeTime = new Date(parseInt(postData.timestamp,10)).toISOString(); postData.relativeTime = new Date(parseInt(postData.timestamp,10)).toISOString();
postData.relativeEditTime = postData.edited !== '0' ? (new Date(parseInt(postData.edited,10)).toISOString()) : ''; postData.relativeEditTime = postData.edited !== '0' ? (new Date(parseInt(postData.edited,10)).toISOString()) : '';

@ -535,18 +535,18 @@ var user = require('./../user.js'),
return callerUID == uid || (data.email && (data.showemail && data.showemail === "1")); return callerUID == uid || (data.email && (data.showemail && data.showemail === "1"));
} }
if (!canSeeEmail()) if (!canSeeEmail()) {
data.email = ""; data.email = "";
}
if (callerUID == uid && (!data.showemail || data.showemail === "0")) if (callerUID == uid && (!data.showemail || data.showemail === "0")) {
data.emailClass = ""; data.emailClass = "";
else } else {
data.emailClass = "hide"; data.emailClass = "hide";
}
data.websiteName = data.website.replace('http://', '').replace('https://', ''); data.websiteName = data.website.replace('http://', '').replace('https://', '');
data.banned = data.banned === '1';
data.show_banned = data.banned === '1' ? '' : 'hide';
data.uid = uid; data.uid = uid;
data.yourid = callerUID; data.yourid = callerUID;
data.theirid = uid; data.theirid = uid;

@ -196,11 +196,10 @@ var RDB = require('./redis'),
privileges = results[2]; privileges = results[2];
for (var i = 0; i < postData.length; ++i) { for (var i = 0; i < postData.length; ++i) {
postData[i].favourited = fav_data[postData[i].pid] === 1;
postData[i].fav_button_class = fav_data[postData[i].pid] ? 'btn-warning' : ''; postData[i].fav_button_class = fav_data[postData[i].pid] ? 'btn-warning' : '';
postData[i].fav_star_class = fav_data[postData[i].pid] ? 'fa-star' : 'fa-star-o'; postData[i].fav_star_class = fav_data[postData[i].pid] ? 'fa-star' : 'fa-star-o';
postData[i]['display_moderator_tools'] = ((current_user != 0) && (postData[i].uid == current_user || privileges.editable)) ? 'show' : 'none'; postData[i].display_moderator_tools = ((current_user != 0) && (postData[i].uid == current_user || privileges.editable));
postData[i].show_banned = postData[i].user_banned === '1' ? 'show' : 'hide';
} }
callback(postData); callback(postData);

Loading…
Cancel
Save