Skip to content
This repository has been archived by the owner on Jan 28, 2021. It is now read-only.

Commit

Permalink
Added read/unread indicators to the tabs.
Browse files Browse the repository at this point in the history
  • Loading branch information
echicken committed Jan 26, 2019
1 parent e023658 commit 789b63d
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 15 deletions.
29 changes: 18 additions & 11 deletions web/lib/forum.js
Expand Up @@ -268,27 +268,34 @@ function getMailHeaders(sent, ascending) {
}

function get_mail_headers(filter, ascending) {
if (filter == 'sent') {
if (user.security.restrictions&UFLAG_K) return []; // I don't remember what this is for.
}
const headers = [];
const ret = {
headers: [],
sent: { read: 0, unread: 0 },
spam: { read: 0, unread: 0 },
inbox: { read: 0, unread: 0 }
};
if (filter == 'sent' && user.security.restrictions&UFLAG_K) return ret; // I don't remember what this is for.
const msg_base = new MsgBase('mail');
if (!msg_base.open()) return headers;
if (!msg_base.open()) return ret;
for (var n = msg_base.first_msg; n <= msg_base.last_msg; n++) {
var h = msg_base.get_msg_header(n);
if (h === null || h.attr&MSG_DELETE) continue;
if (filter == 'sent') {
if (h.from_ext == user.number) headers.push(h);
if (h.from_ext == user.number) {
h.attr&MSG_READ ? ret.sent.read++ : (ret.sent.unread++);
if (filter == 'sent') ret.headers.push(h);
} else if (h.to_ext == user.number) {
if (h.subject.search(/^SPAM:/) > -1) {
if (filter == 'spam') headers.push(h);
} else if (filter != 'spam') {
headers.push(h);
h.attr&MSG_READ ? ret.spam.read++ : (ret.spam.unread++);
if (filter == 'spam') ret.headers.push(h);
} else {
h.attr&MSG_READ ? ret.inbox.read++ : (ret.inbox.unread++);
if (filter != 'spam') ret.headers.push(h);
}
}
}
msg_base.close();
return ascending ? headers.reverse() : headers;
if (ascending) ret.headers.reverse();
return ret;
}

function mimeDecode(header, body, code) {
Expand Down
22 changes: 18 additions & 4 deletions web/pages/.examples/000-mail.xjs
Expand Up @@ -2,12 +2,10 @@

<?xjs
if (user.number == 0 || user.alias == settings.guest) exit();

load('sbbsdefs.js');
load(settings.web_lib + 'forum.js');

const _mail_tab = http_request.query.tab ? http_request.query.tab[0] : 'inbox';

const _mail = get_mail_headers(_mail_tab, true);
function _active_tab(tab) {
return tab == _mail_tab ? 'active' : '';
}
Expand Down Expand Up @@ -38,6 +36,19 @@
</li>
<?xjs } ?>

<?xjs
function _read_unread(tab) {
write('(');
if (_mail[tab].unread) {
write('<strong>' + _mail[tab].unread + '</strong>');
} else {
write(_mail[tab].unread);
}
write('/' + _mail[tab].read);
write(')');
}
?>

<script type="text/javascript" src="./js/forum.js"></script>

<script type="text/javascript">
Expand Down Expand Up @@ -90,21 +101,24 @@
<li role="presentation" class="<?xjs write(_active_tab('inbox')); ?>">
<a href="./?page=<?xjs write(page); ?>&amp;tab=inbox">
<?xjs write(locale.strings.page_mail.label_tab_inbox); ?>
<?xjs _read_unread('inbox'); ?>
</a>
</li>
<li role="presentation" class="<?xjs write(_active_tab('spam')); ?>">
<a href="./?page=<?xjs write(page); ?>&amp;tab=spam">
Spam
<?xjs _read_unread('spam'); ?>
</a>
</li>
<li role="presentation" class="<?xjs write(_active_tab('sent')); ?>">
<a href="./?page=<?xjs write(page); ?>&amp;tab=sent">
<?xjs write(locale.strings.page_mail.label_tab_sent); ?>
<?xjs _read_unread('sent'); ?>
</a>
</li>
</ul>
<br>

<ul id="forum-list-container" class="list-group">
<?xjs get_mail_headers(_mail_tab).forEach(writeMessage); ?>
<?xjs _mail.headers.forEach(writeMessage); ?>
</ul>

0 comments on commit 789b63d

Please sign in to comment.