how to determine if user has unread mail
Re: how to determine if user has unread mail
By: nolageek to All on Wed Aug 06 2014 11:44:50
no> I'd like to show a read mail prompt if the user has unread mail, but I
no> can't figure out how to do it... user.stats.mail_waiting is if they have
no> any mail, not just unread. Suggestions?
Hopefully there's a better way (but I don't remember there being one.) Something like this ought to do the trick:
load('sbbsdefs.js');
// Check for unread messages for a given user number
var checkUnread = function(un) {
var unread = false;
var mb = new MsgBase('mail');
mb.open();
for(var m = mb.first_msg; m <= mb.last_msg; m++) {
var i = mb.get_msg_index(m);
if(i === null || i.to != un || i.attr&MSG_READ)
continue;
unread = true;
break;
}
mb.close();
return unread;
}
// Tell them what's what:
if(checkUnread(user.number))
print("You gots mail, bitch.");
// Or probably more useful:
if(checkUnread(user.number))
bbs.read_mail();
---
echicken
electronic chicken bbs - bbs.electronicchicken.com - 416-273-7230
■ Synchronet ■ electronic chicken bbs - bbs.electronicchicken.com