Skip to content
Snippets Groups Projects
Commit d083201a authored by Deucе's avatar Deucе :ok_hand_tone4:
Browse files

More Seen flag overhaul.

This should now actually work properly.
Also, add a debug_exceptions flag to rethrow exceptions so I can
get line numbers.
parent 1b6d5846
No related branches found
No related tags found
No related merge requests found
...@@ -13,6 +13,7 @@ load("822header.js"); ...@@ -13,6 +13,7 @@ load("822header.js");
load("mime.js"); load("mime.js");
var sepchar="|"; var sepchar="|";
var debug_exceptions = false;
var debug=false; var debug=false;
var debugRX=false; var debugRX=false;
...@@ -218,6 +219,41 @@ function next_epoch(last_epoch) ...@@ -218,6 +219,41 @@ function next_epoch(last_epoch)
return last_epoch + 1; return last_epoch + 1;
} }
function init_seen(code)
{
if(saved_config[code] == undefined)
saved_config[code] = {subscribed:false};
if(saved_config[code].Seen == undefined)
saved_config[code].Seen = {};
}
function get_seen_flag(code, idx)
{
if (saved_config[code] == undefined)
return 0;
if (saved_config[code].Seen == undefined)
return 0;
if (saved_config[code].Seen[idx.number] == undefined)
return 0;
return saved_config[code].Seen[idx.number];
}
/*
* This only sets the "internal" Seen. Caller is responsible for
* updating the message base.
*/
function set_seen_flag_g(code, idx, val)
{
if (!readonly) {
init_seen(code);
saved_config[code].Seen[idx.number] = val;
if (val)
idx.attr |= MSG_READ;
else
idx.attr &= ~MSG_READ;
}
}
/*************************************************************/ /*************************************************************/
/* Fetch response generation... this is the tricky bit. :-) */ /* Fetch response generation... this is the tricky bit. :-) */
/*************************************************************/ /*************************************************************/
...@@ -301,6 +337,10 @@ function send_fetch_response(msgnum, fmat, uid) ...@@ -301,6 +337,10 @@ function send_fetch_response(msgnum, fmat, uid)
function set_seen_flag() { function set_seen_flag() {
if(readonly) if(readonly)
return; return;
if (get_seen_flag(index.code, idx) == 0) {
seen_changed = true;
set_seen_flag_g(index.code, idx, 1);
}
if(base.subnum==-1) { if(base.subnum==-1) {
get_header(); get_header();
if(!(hdr.attr & MSG_READ)) { if(!(hdr.attr & MSG_READ)) {
...@@ -312,19 +352,6 @@ function send_fetch_response(msgnum, fmat, uid) ...@@ -312,19 +352,6 @@ function send_fetch_response(msgnum, fmat, uid)
seen_changed=true; seen_changed=true;
} }
} }
else {
if(saved_config[index.code] == undefined)
saved_config[index.code] = {subscribed:false};
if(saved_config[index.code].Seen == undefined)
saved_config[index.code].Seen = {};
if(saved_config[index.code].Seen[msgnum] != 1) {
seen_changed=true;
saved_config[index.code].Seen[msgnum]=1;
applied_epoch = next_epoch(saved_config.__config_epoch__);
index.idx[msgnum].attr |= MSG_READ;
}
idx.attr |= MSG_READ;
}
} }
// Moves flags to the end... // Moves flags to the end...
...@@ -799,6 +826,8 @@ function parse_command(line) ...@@ -799,6 +826,8 @@ function parse_command(line)
return(execute_line(parse_line())); return(execute_line(parse_line()));
} catch(error) { } catch(error) {
log(LOG_WARNING, "Exception during command parsing: " + error); log(LOG_WARNING, "Exception during command parsing: " + error);
if (debug_exceptions)
throw error;
} }
} }
...@@ -1360,7 +1389,7 @@ function read_index(base) ...@@ -1360,7 +1389,7 @@ function read_index(base)
else { else {
// Fake \Seen // Fake \Seen
idx.attr &= ~MSG_READ; idx.attr &= ~MSG_READ;
if(saved_config[index.code].Seen != undefined && saved_config[index.code].Seen[idx.number] == 1) { if(get_seen_flag(index.code, idx) == 1) {
idx.attr |= MSG_READ; idx.attr |= MSG_READ;
newseen[idx.number]=1; newseen[idx.number]=1;
} }
...@@ -1385,7 +1414,7 @@ function apply_seen(index) ...@@ -1385,7 +1414,7 @@ function apply_seen(index)
return; return;
for(i in index.idx) { for(i in index.idx) {
// Fake \Seen // Fake \Seen
if(saved_config[index.code].Seen != undefined && saved_config[index.code].Seen[index.idx[i].number] == 1) if(get_seen_flag(index.code, index.idx[i]) == 1)
index.idx[i].attr |= MSG_READ; index.idx[i].attr |= MSG_READ;
else else
index.idx[i].attr &= ~MSG_READ; index.idx[i].attr &= ~MSG_READ;
...@@ -1861,7 +1890,6 @@ function do_store(seq, uid, item, data) ...@@ -1861,7 +1890,6 @@ function do_store(seq, uid, item, data)
var flags; var flags;
var chflags; var chflags;
var hdr; var hdr;
var mod_seen=false;
var idx; var idx;
var changed=false; var changed=false;
...@@ -1889,9 +1917,11 @@ function do_store(seq, uid, item, data) ...@@ -1889,9 +1917,11 @@ function do_store(seq, uid, item, data)
chflags={attr:idx.attr^(idx.attr&~flags.attr), netattr:hdr.netattr^(hdr.netattr&~flags.netattr)}; chflags={attr:idx.attr^(idx.attr&~flags.attr), netattr:hdr.netattr^(hdr.netattr&~flags.netattr)};
break break
} }
if (((hdr.attr ^ chflags.attr) | MSG_READ) == MSG_READ)
set_seen_flag_g(index.code, idx, 1);
else
set_seen_flag_g(index.code, idx, 0);
if(chflags.attr & MSG_READ)
mod_seen=true;
chflags=check_msgflags(chflags.attr, chflags.netattr, base.subnum==-1, hdr.to_net_type==NET_NONE?hdr.to==user.number:false, hdr.from_net_type==NET_NONE?hdr.from==user.number:false,base.is_operator); chflags=check_msgflags(chflags.attr, chflags.netattr, base.subnum==-1, hdr.to_net_type==NET_NONE?hdr.to==user.number:false, hdr.from_net_type==NET_NONE?hdr.from==user.number:false,base.is_operator);
if(chflags.attr || chflags.netattr) { if(chflags.attr || chflags.netattr) {
hdr.attr ^= chflags.attr; hdr.attr ^= chflags.attr;
...@@ -1914,30 +1944,6 @@ function do_store(seq, uid, item, data) ...@@ -1914,30 +1944,6 @@ function do_store(seq, uid, item, data)
throw error; throw error;
} }
unlock_cfg(); unlock_cfg();
if(mod_seen && base.cfg != undefined) {
lock_cfg();
try {
read_cfg(base.cfg.code, false);
if(saved_config[base.cfg.code] == undefined) {
saved_config[base.cfg.code] = {subscribed:false};
}
if(saved_config[base.cfg.code].Seen == undefined) {
saved_config[base.cfg.code].Seen = {};
saved_config[base.cfg.code].Seen[header.number]=0;
}
saved_config[base.cfg.code].Seen[seq[i]] ^= 1;
if (saved_config[base.cfg.code].Seen[seq[i]])
index.idx[seq[i]].attr |= MSG_READ;
else
index.idx[seq[i]].attr &= ~MSG_READ;
save_cfg(false);
}
catch (error) {
unlock_cfg();
throw error;
}
unlock_cfg();
}
if(changed) if(changed)
index=read_index(base); index=read_index(base);
} }
...@@ -2518,6 +2524,8 @@ function new_search(args, uid) ...@@ -2518,6 +2524,8 @@ function new_search(args, uid)
} }
} catch(error) { } catch(error) {
log(LOG_WARNING, "Exception during search: " + error); log(LOG_WARNING, "Exception during search: " + error);
if (debug_exceptions)
throw error;
} }
untagged("SEARCH "+result.join(" ")); untagged("SEARCH "+result.join(" "));
} }
...@@ -2778,6 +2786,8 @@ function do_search(args, uid) ...@@ -2778,6 +2786,8 @@ function do_search(args, uid)
untagged("SEARCH "+result.join(" ")); untagged("SEARCH "+result.join(" "));
} catch(error) { } catch(error) {
log(LOG_WARNING, "Exception during search: " + error); log(LOG_WARNING, "Exception during search: " + error);
if (debug_exceptions)
throw error;
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment