...
 
Commits (5)
......@@ -4,6 +4,7 @@ var last_subs;
var last_groups;
var last_threads;
var last_run = 0;
const is_real_user = is_user();
const frequency = (settings.refresh_interval || 60000) / 1000;
// Where 'a' is the previous data and 'b' is new
......@@ -46,7 +47,7 @@ function scan_subs(group) {
}
function scan_threads(sub, offset, page_size) {
const scan = getThreadStats(sub, offset, page_size);
const scan = getThreadStats(sub, offset, page_size, !is_real_user);
if (!last_threads) {
forum_emit('threads', scan);
} else {
......@@ -66,11 +67,10 @@ function scan_threads(sub, offset, page_size) {
}
function cycle() {
if (!is_user()) return;
if (time() - last_run <= frequency) return;
last_run = time();
if (Request.has_param('groups_unread')) scan_groups();
if (Request.has_param('subs_unread')) scan_subs(Request.get_param('subs_unread'));
if (is_real_user && Request.has_param('groups_unread')) scan_groups();
if (is_real_user && Request.has_param('subs_unread')) scan_subs(Request.get_param('subs_unread'));
if (Request.has_param('threads')) scan_threads(Request.get_param('threads'), Request.get_param('offset'), Request.get_param('page_size'));
}
......
......@@ -45,15 +45,13 @@ function listSubs(group) {
});
}
function listThreads(sub, offset, count, page_offset) {
function listThreads(sub, offset, count) {
offset = parseInt(offset);
if (isNaN(offset) || offset < 0) return false;
count = parseInt(count);
if (isNaN(count) || count < 1) return false;
if (page_offset) offset = offset * count;
var threads = getMessageThreads(sub, settings.max_messages);
if (offset >= threads.order.length) return false;
......@@ -72,10 +70,40 @@ function listThreads(sub, offset, count, page_offset) {
}
function getNewestMessageInSub(sub) {
const mb = new MsgBase(sub.code);
if (!mb.open()) return;
var h;
var ret;
for (var m = mb.last_msg; m >= mb.first_msg; m--) {
h = mb.get_msg_header(m);
if (h === null) continue;
ret = {
from: h.from,
subject: h.subject,
when_written_time: h.when_written_time,
};
break;
}
mb.close();
return ret;
}
function getNewestMessagePerSub(grp) {
grp = parseInt(grp, 10);
if (isNaN(grp) || grp < 0 || !msg_area.grp_list[grp]) return [];
return msg_area.grp_list[grp].sub_list.reduce(function (a, c) {
const s = getNewestMessageInSub(c);
if (s !== undefined) a[c.code] = s;
log(LOG_DEBUG, JSON.stringify(s));
return a;
}, {});
}
function getSubUnreadCount(sub) {
var ret = {
scanned : 0,
total : 0
scanned: 0,
total: 0
};
if (typeof msg_area.sub[sub] === 'undefined') return ret;
try {
......@@ -157,7 +185,7 @@ function getThreadVoteTotals(thread, mkeys) {
}
// { [thread_id]: { total, unread, votes: { up: { parent, total }, down: { parent, total }, total }, newest } }
function getThreadStats(sub, offset, page_size) {
function getThreadStats(sub, offset, page_size, guest) {
const threads = getMessageThreads(sub, settings.max_messages);
const ret = {};
if (!offset) offset = 0;
......@@ -169,7 +197,7 @@ function getThreadStats(sub, offset, page_size) {
var mkeys = Object.keys(thread.messages);
ret[threads.order[n]] = {
total: mkeys.length,
unread: getUnreadInThread(sub, thread, mkeys),
unread: guest ? 0 : getUnreadInThread(sub, thread, mkeys),
votes: getThreadVoteTotals(thread, mkeys),
newest: {
from: thread.messages[mkeys[mkeys.length - 1]].from,
......
......@@ -74,6 +74,7 @@ label_message_to = To
label_message_date = on
label_message_subject = Subject
label_thread_latest_reply = Latest reply from
label_sub_newest_message = Latest message
suffix_reply_count = reply
suffix_replies_count = replies
badge_poll = POLL
......
This diff is collapsed.
......@@ -175,6 +175,10 @@ if (Request.has_param('call') && (http_request.method === 'GET' || http_request.
}
break;
case 'get-newest-message-per-sub':
if (Request.has_param('group')) reply = getNewestMessagePerSub(Request.get_param('group'));
break;
default:
break;
......