Skip to content
Snippets Groups Projects
Commit 71fb48d2 authored by deuce's avatar deuce
Browse files

move redundant code into a sub-function.

parent cc76ea16
No related branches found
No related tags found
No related merge requests found
......@@ -372,6 +372,7 @@ function getMessageThreads(sub, max) {
var header_num={};
var all_headers=[];
var m;
var new_thread;
msgBase.open();
if(!msgBase.is_open)
......@@ -386,6 +387,16 @@ function getMessageThreads(sub, max) {
for(m=max; m <= msgBase.last_msg; m++)
all_headers.push(msgBase.get_msg_header(m));
}
function add_to_thread(header, thread)
{
header.ec_thread = thread;
thread.newest=header.when_written_time;
threads.dates[thread.dateIndex] = header.when_written_time;
thread.messages.push(header);
threadedMessages.push(header.number);
}
for(m in all_headers) {
header = all_headers[m];
if(
......@@ -406,14 +417,9 @@ function getMessageThreads(sub, max) {
header_num[header.number]=header;
md5subject = md5_calc(header.subject.toUpperCase().replace(/\s*RE:\s*/g, ''), hex=true);
if(header.thread_id === 0 && threadedMessages.indexOf(header.thread_back) >= 0) {
if(threads.thread.hasOwnProperty(header.thread_back)) {
// This is a reply to the first message in a thread
header.ec_thread = threads.thread[header.thread_back];
threads.thread[header.thread_back].newest = header.when_written_time;
threads.dates[threads.thread[header.thread_back].dateIndex] = header.when_written_time;
threads.thread[header.thread_back].messages.push(header);
threadedMessages.push(header.number);
} else {
if(threads.thread.hasOwnProperty(header.thread_back))
add_to_thread(header, threads.thread[header.thread_back]);
else {
tbHeader = header_num[header.thread_back];
if(tbHeader == null) {
tbHeader = msgBase.get_msg_header(header.thread_back);
......@@ -421,39 +427,22 @@ function getMessageThreads(sub, max) {
header_num[tbHeader.number]=tbHeader;
}
if(tbHeader !== null) {
if(tbHeader.ec_thread !== undefined) {
tbHeader.ec_thread.newest = header.when_written_time;
threads.dates[tbHeader.ec_thread.dateIndex] = header.when_written_time;
tbHeader.ec_thread.messages.push(header);
threadedMessages.push(header.number);
header.ec_thread=tbHeader.ec_thread;
}
if(tbHeader.ec_thread !== undefined)
add_to_thread(header, tbHeader.ec_thread);
}
}
}
} else if(header.thread_id !== header.number && threads.thread.hasOwnProperty(header.thread_id)) {
header.ec_thread = threads.thread[header.thread_id];
threads.thread[header.thread_id].newest = header.when_written_time;
threads.dates[threads.thread[header.thread_id].dateIndex] = header.when_written_time;
threads.thread[header.thread_id].messages.push(header);
threadedMessages.push(header.number);
add_to_thread(header, threads.thread[header.thread_id]);
} else if(subjects.hasOwnProperty(md5subject)) {
header.ec_thread = threads.thread[subjects[md5subject]];
threads.thread[subjects[md5subject]].newest = header.when_written_time;
threads.dates[threads.thread[subjects[md5subject]].dateIndex] = header.when_written_time;
threads.thread[subjects[md5subject]].messages.push(header);
threadedMessages.push(header.number);
add_to_thread(header, threads.thread[subjects[md5subject]]);
} else {
new_thread = (header.thread_id === 0)?header.number:header.thread_id;
subjects[md5subject] = new_thread;
threads.dates.push(header.when_written_time);
threads.thread[((header.thread_id === 0)?header.number:header.thread_id)] = {
newest : header.when_written_time,
threads.thread[new_thread] = {
dateIndex : threads.dates.length - 1,
messages : [
header
]
}
header.ec_thread = threads.thread[((header.thread_id === 0)?header.number:header.thread_id)];
subjects[md5subject] = ((header.thread_id === 0)?header.number:header.thread_id);
threadedMessages.push(header.number);
add_to_thread(header, threads.thread[new_thread]);
}
}
msgBase.close();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment