Merge branch 'master' of github.com:designcreateplay/NodeBB

v1.18.x
Julian Lam 11 years ago
commit 58b6a2e9ea

@ -352,24 +352,6 @@ var socket,
});
};
var previousScrollTop = 0;
app.enableInfiniteLoading = function(callback) {
$(window).on('scroll', function() {
var top = $(window).height() * 0.1;
var bottom = ($(document).height() - $(window).height()) * 0.9;
var currentScrollTop = $(window).scrollTop();
if(currentScrollTop < top && currentScrollTop < previousScrollTop) {
callback(-1);
} else if (currentScrollTop > bottom && currentScrollTop > previousScrollTop) {
callback(1);
}
previousScrollTop = currentScrollTop;
});
};
var titleObj = {
active: false,
interval: undefined,

@ -1,51 +1,40 @@
define(['forum/account/header'], function(header) {
var Favourites = {},
loadingMore = false;
'use strict';
/* globals define, app, utils */
define(['forum/account/header', 'forum/infinitescroll'], function(header, infinitescroll) {
var Favourites = {};
Favourites.init = function() {
header.init();
$('.user-favourite-posts img').addClass('img-responsive');
app.enableInfiniteLoading(function() {
if(!loadingMore) {
loadMore();
}
});
infinitescroll.init(loadMore);
};
function loadMore() {
loadingMore = true;
socket.emit('posts.loadMoreFavourites', {
after: $('.user-favourite-posts').attr('data-nextstart')
}, function(err, data) {
if(err) {
return app.alertError(err.message);
}
function loadMore(direction) {
if (direction < 0) {
return;
}
infinitescroll.loadMore('posts.loadMoreFavourites', {
after: $('.user-favourite-posts').attr('data-nextstart')
}, function(data) {
if (data.posts && data.posts.length) {
onTopicsLoaded(data.posts);
onPostsLoaded(data.posts);
$('.user-favourite-posts').attr('data-nextstart', data.nextStart);
}
loadingMore = false;
});
}
function onTopicsLoaded(posts) {
ajaxify.loadTemplate('account/favourites', function(favouritesTemplate) {
var html = templates.parse(templates.getBlock(favouritesTemplate, 'posts'), {posts: posts});
translator.translate(html, function(translatedHTML) {
$('#category-no-topics').remove();
html = $(translatedHTML);
html.find('img').addClass('img-responsive');
$('.user-favourite-posts').append(html);
html.find('span.timeago').timeago();
app.createUserTooltips();
utils.makeNumbersHumanReadable(html.find('.human-readable-number'));
});
function onPostsLoaded(posts) {
infinitescroll.parseAndTranslate('account/favourites', 'posts', {posts: posts}, function(html) {
$('.user-favourite-posts').append(html);
html.find('img').addClass('img-responsive');
html.find('span.timeago').timeago();
app.createUserTooltips();
utils.makeNumbersHumanReadable(html.find('.human-readable-number'));
});
}

@ -1,55 +1,41 @@
'use strict';
/* globals define, app, socket, ajaxify, templates, translator, utils */
/* globals define, app, socket, utils */
define(['forum/account/header'], function(header) {
var AccountPosts = {},
loadingMore = false;
define(['forum/account/header', 'forum/infinitescroll'], function(header, infinitescroll) {
var AccountPosts = {};
AccountPosts.init = function() {
header.init();
$('.user-favourite-posts img').addClass('img-responsive');
app.enableInfiniteLoading(function() {
if(!loadingMore) {
loadMore();
}
});
infinitescroll.init(loadMore);
};
function loadMore() {
loadingMore = true;
socket.emit('posts.loadMoreUserPosts', {
function loadMore(direction) {
if (direction < 0) {
return;
}
infinitescroll.loadMore('posts.loadMoreUserPosts', {
uid: $('.account-username-box').attr('data-uid'),
after: $('.user-favourite-posts').attr('data-nextstart')
}, function(err, data) {
if(err) {
return app.alertError(err.message);
}
}, function(data) {
if (data.posts && data.posts.length) {
onPostsLoaded(data.posts);
$('.user-favourite-posts').attr('data-nextstart', data.nextStart);
}
loadingMore = false;
});
}
function onPostsLoaded(posts) {
ajaxify.loadTemplate('account/posts', function(accountposts) {
var html = templates.parse(templates.getBlock(accountposts, 'posts'), {posts: posts});
translator.translate(html, function(translatedHTML) {
html = $(translatedHTML);
html.find('img').addClass('img-responsive');
$('.user-favourite-posts').append(html);
html.find('span.timeago').timeago();
app.createUserTooltips();
utils.makeNumbersHumanReadable(html.find('.human-readable-number'));
});
infinitescroll.parseAndTranslate('account/posts', 'posts', {posts: posts}, function(html) {
$('.user-favourite-posts').append(html);
html.find('img').addClass('img-responsive');
html.find('span.timeago').timeago();
app.createUserTooltips();
utils.makeNumbersHumanReadable(html.find('.human-readable-number'));
});
}

@ -1,51 +1,39 @@
'use strict';
/* globals define, app, socket, ajaxify, templates, translator, utils */
/* globals define, app, socket, utils */
define(['forum/account/header'], function(header) {
var AccountTopics = {},
loadingMore = false;
define(['forum/account/header', 'forum/infinitescroll'], function(header, infinitescroll) {
var AccountTopics = {};
AccountTopics.init = function() {
header.init();
app.enableInfiniteLoading(function() {
if(!loadingMore) {
loadMore();
}
});
infinitescroll.init(loadMore);
};
function loadMore() {
loadingMore = true;
socket.emit('topics.loadMoreFromSet', {
function loadMore(direction) {
if (direction < 0) {
return;
}
infinitescroll.loadMore('topics.loadMoreFromSet', {
set: 'uid:' + $('.account-username-box').attr('data-uid') + ':topics',
after: $('.user-topics').attr('data-nextstart')
}, function(err, data) {
if(err) {
return app.alertError(err.message);
}
}, function(data) {
if (data.topics && data.topics.length) {
onTopicsLoaded(data.topics);
$('.user-topics').attr('data-nextstart', data.nextStart);
}
loadingMore = false;
});
}
function onTopicsLoaded(topics) {
ajaxify.loadTemplate('account/topics', function(accounttopics) {
var html = templates.parse(templates.getBlock(accounttopics, 'topics'), {topics: topics});
translator.translate(html, function(translatedHTML) {
html = $(translatedHTML);
$('#topics-container').append(html);
html.find('span.timeago').timeago();
app.createUserTooltips();
utils.makeNumbersHumanReadable(html.find('.human-readable-number'));
});
infinitescroll.parseAndTranslate('account/topics', 'topics', {topics: topics}, function(html) {
$('#topics-container').append(html);
html.find('span.timeago').timeago();
app.createUserTooltips();
utils.makeNumbersHumanReadable(html.find('.human-readable-number'));
});
}

@ -1,10 +1,8 @@
"use strict";
/* global define, config, templates, app, utils, ajaxify, socket, translator */
define(['composer', 'forum/pagination', 'share', 'navigator', 'forum/categoryTools'], function(composer, pagination, share, navigator, categoryTools) {
var Category = {},
loadingMoreTopics = false;
define(['composer', 'forum/pagination', 'forum/infinitescroll', 'share', 'navigator', 'forum/categoryTools'], function(composer, pagination, infinitescroll, share, navigator, categoryTools) {
var Category = {};
$(window).on('action:ajaxify.start', function(ev, data) {
if(data && data.url.indexOf('category') !== 0) {
@ -34,7 +32,7 @@ define(['composer', 'forum/pagination', 'share', 'navigator', 'forum/categoryToo
categoryTools.init(cid);
enableInfiniteLoading();
enableInfiniteLoadingOrPagination();
if (!config.usePagination) {
navigator.init('#topics-container > .category-item', ajaxify.variables.get('topic_count'));
@ -87,9 +85,8 @@ define(['composer', 'forum/pagination', 'share', 'navigator', 'forum/categoryToo
}
$('#topics-container').empty();
loadingMoreTopics = false;
Category.loadMoreTopics(ajaxify.variables.get('category_id'), index, function() {
loadTopicsAfter(index, function() {
Category.scrollToTopic(bookmark, clicked, 0);
});
});
@ -132,41 +129,11 @@ define(['composer', 'forum/pagination', 'share', 'navigator', 'forum/categoryToo
}
};
function enableInfiniteLoading() {
if(!config.usePagination) {
app.enableInfiniteLoading(function(direction) {
if(!loadingMoreTopics && $('#topics-container').children().length) {
var after = 0,
offset = 0,
el = null;
if(direction > 0) {
el = $('#topics-container .category-item[data-tid]').last();
after = parseInt(el.attr('data-index'), 10) + 1;
} else {
el = $('#topics-container .category-item[data-tid]').first();
after = parseInt(el.attr('data-index'), 10);
if(isNaN(after)){
after = 0;
}
after -= config.topicsPerPage;
if(after < 0) {
after = 0;
}
offset = el.offset().top - $('#header-menu').offset().top + $('#header-menu').height();
}
Category.loadMoreTopics(ajaxify.variables.get('category_id'), after, function() {
if(direction < 0 && el) {
Category.scrollToTopic(el.attr('data-tid'), null, 0, offset);
}
});
}
});
function enableInfiniteLoadingOrPagination() {
if (!config.usePagination) {
infinitescroll.init(Category.loadMoreTopics);
} else {
navigator.hide();
pagination.init(ajaxify.variables.get('currentPage'), ajaxify.variables.get('pageCount'));
}
}
@ -293,53 +260,50 @@ define(['composer', 'forum/pagination', 'share', 'navigator', 'forum/categoryToo
}
}
if (typeof callback === 'function') {
callback();
}
html.find('span.timeago').timeago();
app.createUserTooltips();
utils.makeNumbersHumanReadable(html.find('.human-readable-number'));
if (typeof callback === 'function') {
callback(topics);
}
});
});
};
Category.loadMoreTopics = function(cid, after, callback) {
if (loadingMoreTopics || !$('#topics-container').length) {
Category.loadMoreTopics = function(direction) {
if (!$('#topics-container').length || !$('#topics-container').children().length) {
return;
}
infinitescroll.calculateAfter(direction, '#topics-container .category-item[data-tid]', config.topicsPerPage, function(after, offset, el) {
loadTopicsAfter(after, function() {
if (direction < 0 && el) {
Category.scrollToTopic(el.attr('data-tid'), null, 0, offset);
}
});
});
};
function loadTopicsAfter(after, callback) {
if(!utils.isNumber(after) || (after === 0 && $('#topics-container li.category-item[data-index="0"]').length)) {
return;
}
$(window).trigger('action:categories.loading');
loadingMoreTopics = true;
socket.emit('categories.loadMore', {
cid: cid,
infinitescroll.loadMore('categories.loadMore', {
cid: ajaxify.variables.get('category_id'),
after: after
}, function (err, data) {
loadingMoreTopics = false;
}, function (data) {
if(err) {
return app.alertError(err.message);
}
if (data && data.topics.length) {
if (data.topics && data.topics.length) {
Category.onTopicsLoaded(data, callback);
$('#topics-container').attr('data-nextstart', data.nextStart);
} else {
if (typeof callback === 'function') {
callback(data.topics);
}
}
$(window).trigger('action:categories.loaded');
});
};
}
return Category;
});

@ -0,0 +1,79 @@
'use strict';
/* globals define, socket, ajaxify, translator, templates, app */
define(function() {
var scroll = {};
var callback;
var previousScrollTop = 0;
var loadingMore = false;
scroll.init = function(cb) {
callback = cb;
$(window).off('scroll', onScroll).on('scroll', onScroll);
};
function onScroll() {
var top = $(window).height() * 0.1;
var bottom = ($(document).height() - $(window).height()) * 0.9;
var currentScrollTop = $(window).scrollTop();
if(currentScrollTop < top && currentScrollTop < previousScrollTop) {
callback(-1);
} else if (currentScrollTop > bottom && currentScrollTop > previousScrollTop) {
callback(1);
}
previousScrollTop = currentScrollTop;
}
scroll.loadMore = function(method, data, callback) {
if (loadingMore) {
return;
}
loadingMore = true;
socket.emit(method, data, function(err, data) {
if (err) {
return app.alertError(err.message);
}
callback(data);
loadingMore = false;
});
};
scroll.parseAndTranslate = function(template, blockName, data, callback) {
ajaxify.loadTemplate(template, function(templateHtml) {
var html = templates.parse(templates.getBlock(templateHtml, blockName), data);
translator.translate(html, function(translatedHTML) {
callback($(translatedHTML));
});
});
};
scroll.calculateAfter = function(direction, selector, count, callback) {
var after = 0,
offset = 0,
el = direction > 0 ? $(selector).last() : $(selector).first();
if (direction > 0) {
after = parseInt(el.attr('data-index'), 10) + 1;
} else {
after = parseInt(el.attr('data-index'), 10);
if (isNaN(after)) {
after = 0;
}
after -= count;
if (after < 0) {
after = 0;
}
if (el && el.offset()) {
offset = el.offset().top - $('#header-menu').offset().top + $('#header-menu').height();
}
}
callback(after, offset, el);
};
return scroll;
});

@ -1,6 +1,9 @@
define(['forum/recent'], function(recent) {
'use strict';
/* globals define, app, socket*/
define(['forum/recent', 'forum/infinitescroll'], function(recent, infinitescroll) {
var Popular = {},
loadingMoreTopics = false,
active = '';
$(window).on('action:ajaxify.start', function(ev, data) {
@ -20,34 +23,23 @@ define(['forum/recent'], function(recent) {
active = recent.selectActivePill();
app.enableInfiniteLoading(function() {
if(!loadingMoreTopics) {
loadMoreTopics();
}
});
infinitescroll.init(loadMoreTopics);
function loadMoreTopics() {
if(!$('#topics-container').length) {
function loadMoreTopics(direction) {
if(direction < 0 || !$('#topics-container').length) {
return;
}
loadingMoreTopics = true;
socket.emit('topics.loadMoreFromSet', {
infinitescroll.loadMore('topics.loadMoreFromSet', {
set: 'topics:' + $('.nav-pills .active a').html().toLowerCase(),
after: $('#topics-container').attr('data-nextstart')
}, function(err, data) {
if(err) {
return app.alertError(err.message);
}
}, function(data) {
if (data.topics && data.topics.length) {
recent.onTopicsLoaded('popular', data.topics, false);
$('#topics-container').attr('data-nextstart', data.nextStart);
} else {
$('#load-more-btn').hide();
}
loadingMoreTopics = false;
});
}
};

@ -1,13 +1,12 @@
'use strict';
/* globals define, app, socket, ajaxify, templates, translator, utils */
/* globals define, app, socket, utils */
define(function() {
define(['forum/infinitescroll'], function(infinitescroll) {
var Recent = {};
var newTopicCount = 0,
newPostCount = 0,
loadingMoreTopics = false;
newPostCount = 0;
var active = '';
@ -36,11 +35,7 @@ define(function() {
});
app.enableInfiniteLoading(function() {
if(!loadingMoreTopics) {
Recent.loadMoreTopics();
}
});
infinitescroll.init(Recent.loadMoreTopics);
};
Recent.selectActivePill = function() {
@ -102,42 +97,30 @@ define(function() {
$('#category-no-topics').addClass('hide');
};
Recent.loadMoreTopics = function() {
if(!$('#topics-container').length) {
Recent.loadMoreTopics = function(direction) {
if(direction < 0 || !$('#topics-container').length) {
return;
}
loadingMoreTopics = true;
socket.emit('topics.loadMoreRecentTopics', {
infinitescroll.loadMore('topics.loadMoreRecentTopics', {
after: $('#topics-container').attr('data-nextstart'),
term: active
}, function(err, data) {
if(err) {
return app.alertError(err.message);
}
}, function(data) {
if (data.topics && data.topics.length) {
Recent.onTopicsLoaded('recent', data.topics, false);
$('#topics-container').attr('data-nextstart', data.nextStart);
}
loadingMoreTopics = false;
});
};
Recent.onTopicsLoaded = function(templateName, topics, showSelect) {
ajaxify.loadTemplate(templateName, function(template) {
var html = templates.parse(templates.getBlock(template, 'topics'), {topics: topics, showSelect: showSelect});
translator.translate(html, function(translatedHTML) {
$('#category-no-topics').remove();
html = $(translatedHTML);
$('#topics-container').append(html);
html.find('span.timeago').timeago();
app.createUserTooltips();
utils.makeNumbersHumanReadable(html.find('.human-readable-number'));
});
infinitescroll.parseAndTranslate(templateName, 'topics', {topics: topics, showSelect: showSelect}, function(html) {
$('#category-no-topics').remove();
$('#topics-container').append(html);
html.find('span.timeago').timeago();
app.createUserTooltips();
utils.makeNumbersHumanReadable(html.find('.human-readable-number'));
});
};

@ -3,9 +3,8 @@
/* globals define, app, templates, translator, socket, bootbox, config, ajaxify, RELATIVE_PATH, utils */
define(['forum/pagination', 'forum/topic/threadTools', 'forum/topic/postTools', 'forum/topic/events', 'navigator'], function(pagination, threadTools, postTools, events, navigator) {
define(['forum/pagination', 'forum/infinitescroll', 'forum/topic/threadTools', 'forum/topic/postTools', 'forum/topic/events', 'navigator'], function(pagination, infinitescroll, threadTools, postTools, events, navigator) {
var Topic = {},
infiniteLoaderActive = false,
scrollingToPost = false,
currentUrl = '';
@ -43,7 +42,7 @@ define(['forum/pagination', 'forum/topic/threadTools', 'forum/topic/postTools',
hidePostToolsForDeletedPosts();
enableInfiniteLoading();
enableInfiniteLoadingOrPagination();
addBlockquoteEllipses($('.topic .post-content > blockquote'));
@ -114,36 +113,9 @@ define(['forum/pagination', 'forum/topic/threadTools', 'forum/topic/postTools',
});
}
function enableInfiniteLoading() {
function enableInfiniteLoadingOrPagination() {
if(!config.usePagination) {
app.enableInfiniteLoading(function(direction) {
if (!infiniteLoaderActive && $('#post-container').children().length) {
var after = 0;
var el = null;
if(direction > 0) {
el = $('#post-container .post-row').last();
after = parseInt(el.attr('data-index'), 10) + 1;
} else {
el = $('#post-container .post-row').first();
after = parseInt(el.attr('data-index'), 10);
after -= config.postsPerPage;
if(after < 0) {
after = 0;
}
}
var offset = el.offset().top - $('#header-menu').offset().top + $('#header-menu').height();
loadMorePosts(ajaxify.variables.get('topic_id'), after, function() {
hidePostToolsForDeletedPosts();
if(direction < 0 && el) {
Topic.scrollToPost(el.attr('data-pid'), false, 0, offset);
}
});
}
});
infinitescroll.init(loadMorePosts);
} else {
navigator.hide();
@ -224,14 +196,14 @@ define(['forum/pagination', 'forum/topic/threadTools', 'forum/topic/postTools',
if(err) {
return;
}
var tid = $('#post-container').attr('data-tid');
$('#post-container').empty();
var after = index - config.postsPerPage + 1;
if(after < 0) {
after = 0;
}
loadMorePosts(tid, after, function() {
loadPostsAfter(after, function() {
scrollToPid(pid);
});
});
@ -242,8 +214,8 @@ define(['forum/pagination', 'forum/topic/threadTools', 'forum/topic/postTools',
tid = $('#post-container').attr('data-tid');
function animateScroll() {
$("html, body").animate({
scrollTop: (scrollTo.offset().top - $('#header-menu').height() - offset) + "px"
$('html, body').animate({
scrollTop: (scrollTo.offset().top - $('#header-menu').height() - offset) + 'px'
}, duration !== undefined ? duration : 400, function() {
scrollingToPost = false;
navigator.update();
@ -316,7 +288,7 @@ define(['forum/pagination', 'forum/topic/threadTools', 'forum/topic/postTools',
}
});
if(!after) {
if (!after) {
var firstPost = $('#post-container .post-row').first();
if(firstPid < parseInt(firstPost.attr('data-pid'), 10)) {
before = firstPost;
@ -334,35 +306,26 @@ define(['forum/pagination', 'forum/topic/threadTools', 'forum/topic/postTools',
data.title = ajaxify.variables.get('topic_name');
data.viewcount = ajaxify.variables.get('viewcount');
parseAndTranslatePosts(data, function(translatedHTML) {
var translated = $(translatedHTML);
infinitescroll.parseAndTranslate('topic', 'posts', data, function(html) {
if(after) {
translated.insertAfter(after);
html.insertAfter(after);
} else if(before) {
translated.insertBefore(before);
html.insertBefore(before);
} else {
$('#post-container').append(translated);
$('#post-container').append(html);
}
translated.hide().fadeIn('slow');
addBlockquoteEllipses(translated.find('.post-content > blockquote'));
html.hide().fadeIn('slow');
onNewPostsLoaded(translated, data.posts);
addBlockquoteEllipses(html.find('.post-content > blockquote'));
if(typeof callback === 'function') {
onNewPostsLoaded(html, data.posts);
if (typeof callback === 'function') {
callback();
}
});
}
function parseAndTranslatePosts(data, callback) {
ajaxify.loadTemplate('topic', function(topicTemplate) {
var html = templates.parse(templates.getBlock(topicTemplate, 'posts'), data);
translator.translate(html, callback);
});
}
function onNewPostsLoaded(html, posts) {
function getPostPrivileges(pid) {
socket.emit('posts.getPrivileges', pid, function(err, privileges) {
@ -377,8 +340,6 @@ define(['forum/pagination', 'forum/topic/threadTools', 'forum/topic/postTools',
getPostPrivileges(posts[x].pid);
}
infiniteLoaderActive = false;
app.populateOnlineUsers();
app.createUserTooltips();
utils.addCommasToNumbers(html.find('.formatted-number'));
@ -392,45 +353,47 @@ define(['forum/pagination', 'forum/topic/threadTools', 'forum/topic/postTools',
function toggleModTools(postHtml, privileges) {
postHtml.find('.edit, .delete').toggleClass('none', !privileges.meta.editable);
postHtml.find('.move').toggleClass('none', !privileges.meta.move);
postHtml.find('.reply, .quote').toggleClass('none', !$('.post_reply').length)
postHtml.find('.reply, .quote').toggleClass('none', !$('.post_reply').length);
var isSelfPost = parseInt(postHtml.attr('data-uid'), 10) === parseInt(app.uid, 10);
postHtml.find('.chat, .flag').toggleClass('none', isSelfPost);
}
function loadMorePosts(tid, after, callback) {
var indicatorEl = $('.loading-indicator');
if (infiniteLoaderActive || !$('#post-container').length) {
function loadMorePosts(direction) {
if (!$('#post-container').length) {
return;
}
infinitescroll.calculateAfter(direction, '#post-container .post-row', config.postsPerPage, function(after, offset, el) {
loadPostsAfter(after, function() {
if (direction < 0 && el) {
Topic.scrollToPost(el.attr('data-pid'), false, 0, offset);
}
});
});
}
function loadPostsAfter(after, callback) {
if (!utils.isNumber(after) || (after === 0 && $('#post-container li.post-row[data-index="0"]').length)) {
return;
}
infiniteLoaderActive = true;
indicatorEl.fadeIn();
var indicatorEl = $('.loading-indicator');
if (!indicatorEl.is(':animated')) {
indicatorEl.fadeIn();
}
socket.emit('topics.loadMore', {
tid: tid,
infinitescroll.loadMore('topics.loadMore', {
tid: ajaxify.variables.get('topic_id'),
after: after
}, function (err, data) {
indicatorEl.fadeOut(function() {
infiniteLoaderActive = false;
});
}, function (data) {
if(err) {
return app.alertError(err.message);
}
indicatorEl.fadeOut();
if (data && data.posts && data.posts.length) {
createNewPosts(data, callback);
hidePostToolsForDeletedPosts();
} else {
navigator.update();
if (typeof callback === 'function') {
callback(data.posts);
}
}
});
}

@ -2,7 +2,7 @@
/* globals define, app, socket */
define(['forum/recent', 'topicSelect'], function(recent, topicSelect) {
define(['forum/recent', 'topicSelect', 'forum/infinitescroll'], function(recent, topicSelect, infinitescroll) {
var Unread = {},
loadingMoreTopics = false;
@ -86,33 +86,22 @@ define(['forum/recent', 'topicSelect'], function(recent, topicSelect) {
loadMoreTopics();
});
app.enableInfiniteLoading(function() {
if(!loadingMoreTopics) {
loadMoreTopics();
}
});
infinitescroll.init(loadMoreTopics);
function loadMoreTopics() {
if(!$('#topics-container').length) {
function loadMoreTopics(direction) {
if(direction < 0 || !$('#topics-container').length) {
return;
}
loadingMoreTopics = true;
socket.emit('topics.loadMoreUnreadTopics', {
infinitescroll.loadMore('topics.loadMoreUnreadTopics', {
after: $('#topics-container').attr('data-nextstart')
}, function(err, data) {
if(err) {
return app.alertError(err.message);
}
}, function(data) {
if (data.topics && data.topics.length) {
recent.onTopicsLoaded('unread', data.topics, true);
$('#topics-container').attr('data-nextstart', data.nextStart);
} else {
$('#load-more-btn').hide();
}
loadingMoreTopics = false;
});
}
};

@ -67,10 +67,6 @@
};
translator.translate = function (data, language, callback) {
if (!data) {
return callback(data);
}
if (typeof language === 'function') {
callback = language;
if ('undefined' !== typeof window && config) {
@ -81,6 +77,10 @@
}
}
if (!data) {
return callback(data);
}
function insertLanguage(text, key, value, variables) {
if (value) {
for (var i = 1, ii = variables.length; i < ii; i++) {

@ -164,7 +164,7 @@ var db = require('./database'),
}
async.filter(pids, function(pid, next) {
privileges.posts.canRead(pid, callerUid, function(err, canRead) {
privileges.posts.can('read', pid, callerUid, function(err, canRead) {
next(!err && canRead);
});
}, function(pids) {
@ -216,7 +216,7 @@ var db = require('./database'),
}
async.filter(pids, function(pid, next) {
privileges.posts.canRead(pid, uid, function(err, canRead) {
privileges.posts.can('read', pid, uid, function(err, canRead) {
next(!err && canRead);
});
}, function(pids) {

@ -58,20 +58,6 @@ module.exports = function(privileges) {
], callback);
};
privileges.categories.canRead = function(cid, uid, callback) {
helpers.some([
function(next) {
helpers.allowedTo('read', uid, cid, next);
},
function(next) {
user.isModerator(uid, cid, next);
},
function(next) {
user.isAdministrator(uid, next);
}
], callback);
};
privileges.categories.canMoveAllTopics = function(currentCid, targetCid, uid, callback) {
async.parallel({
isAdministrator: function(next) {

@ -30,22 +30,8 @@ helpers.allowedTo = function(privilege, uid, cid, callback) {
return callback(null, false);
}
// Guests handling
if (parseInt(uid, 10) === 0) {
return async.parallel([
function(next) {
groups.exists('cid:' + cid + ':privileges:' + privilege, function(err, exists) {
next(err, !err ? !exists : false);
});
},
function(next) {
helpers.isMember(groups.isMember, 'cid:' + cid + ':privileges:groups:' + privilege, 'guests', function(err, isMember) {
next(err, privilege !== 'find' && privilege !== 'read' ? isMember === true : isMember !== false);
});
}
], function(err, results) {
callback(err, results[0] && (results[1] || results[1] === null));
});
return isGuestAllowedTo(privilege, cid, callback);
}
async.parallel({
@ -65,6 +51,23 @@ helpers.allowedTo = function(privilege, uid, cid, callback) {
});
};
function isGuestAllowedTo(privilege, cid, callback) {
async.parallel([
function(next) {
groups.exists('cid:' + cid + ':privileges:' + privilege, function(err, exists) {
next(err, !err ? !exists : false);
});
},
function(next) {
helpers.isMember(groups.isMember, 'cid:' + cid + ':privileges:groups:' + privilege, 'guests', function(err, isMember) {
next(err, privilege !== 'find' && privilege !== 'read' ? isMember === true : isMember !== false);
});
}
], function(err, results) {
callback(err, results[0] && (results[1] || results[1] === null));
});
}
helpers.isMember = function(method, group, uid, callback) {
groups.exists(group, function(err, exists) {
if (err) {
@ -77,7 +80,7 @@ helpers.isMember = function(method, group, uid, callback) {
method(uid, group, callback);
});
}
};
helpers.hasEnoughReputationFor = function(privilege, uid, callback) {
if (parseInt(meta.config['privileges:disabled'], 10)) {

@ -53,13 +53,13 @@ module.exports = function(privileges) {
});
};
privileges.posts.canRead = function(pid, uid, callback) {
privileges.posts.can = function(privilege, pid, uid, callback) {
posts.getCidByPid(pid, function(err, cid) {
if (err) {
return callback(err);
}
privileges.categories.canRead(cid, uid, callback);
privileges.categories.can(privilege, cid, uid, callback);
});
};

@ -65,50 +65,6 @@ module.exports = function(privileges) {
});
};
privileges.topics.canRead = function(tid, uid, callback) {
topics.getTopicField(tid, 'cid', function(err, cid) {
if (err) {
return callback(err);
}
privileges.categories.canRead(cid, uid, callback);
});
};
privileges.topics.canCreate = function(cid, uid, callback) {
helpers.some([
function(next) {
helpers.allowedTo('topics:create', uid, cid, next);
},
function(next) {
user.isModerator(uid, cid, next);
},
function(next) {
user.isAdministrator(uid, next);
}
], callback);
};
privileges.topics.canReply = function(tid, uid, callback) {
topics.getTopicField(tid, 'cid', function(err, cid) {
if (err) {
return callback(err);
}
helpers.some([
function(next) {
helpers.allowedTo('topics:reply', uid, cid, next);
},
function(next) {
user.isModerator(uid, cid, next);
},
function(next) {
user.isAdministrator(uid, next);
}
], callback);
});
};
privileges.topics.canEdit = function(tid, uid, callback) {
helpers.some([
function(next) {

@ -9,7 +9,7 @@ var async = require('async'),
SocketCategories = {};
SocketCategories.getRecentReplies = function(socket, cid, callback) {
privileges.categories.canRead(cid, socket.uid, function(err, canRead) {
privileges.categories.can('read', cid, socket.uid, function(err, canRead) {
if (err) {
return callback(err);
}

@ -129,7 +129,7 @@ function sendNotificationToPostOwner(data, uid, notification) {
SocketPosts.getRawPost = function(socket, pid, callback) {
async.waterfall([
function(next) {
privileges.posts.canRead(pid, socket.uid, next);
privileges.posts.can('read', pid, socket.uid, next);
},
function(canRead, next) {
if (!canRead) {

@ -130,7 +130,7 @@ var async = require('async'),
}
async.filter(tids, function(tid, next) {
privileges.topics.canRead(tid, uid, function(err, canRead) {
privileges.topics.can('read', tid, uid, function(err, canRead) {
next(!err && canRead);
});
}, function(tids) {

@ -99,7 +99,7 @@ module.exports = function(Topics) {
if (!categoryExists) {
return next(new Error('[[error:no-category]]'));
}
privileges.topics.canCreate(cid, uid, next);
privileges.categories.can('topics:create', cid, uid, next);
},
function(canCreate, next) {
if(!canCreate) {
@ -173,7 +173,7 @@ module.exports = function(Topics) {
return next(new Error('[[error:topic-locked]]'));
}
privileges.topics.canReply(tid, uid, next);
privileges.topics.can('topics:reply', tid, uid, next);
},
function(canReply, next) {
if (!canReply) {

@ -49,7 +49,7 @@ module.exports = function(Topics) {
});
async.filter(newtids, function(tid, next) {
privileges.topics.canRead(tid, uid, function(err, canRead) {
privileges.topics.can('read', tid, uid, function(err, canRead) {
next(!err && canRead);
});
}, function(newtids) {

Loading…
Cancel
Save