in site/js/dev/ponymail_email_displays.js [333:433]
function toggleEmails_threaded(id, close, toverride, threadobj) {
current_thread_mids = {}
current_email_msgs = []
var thread = threadobj ? threadobj : document.getElementById('thread_' + id.toString().replace(/@<.+>/, ""))
if (thread) {
current_thread = id
if (localStorageAvailable) {
var epoch = latestEmailInThread + "!"
if (current_thread_json[id]) {
var xx = window.localStorage.getItem("viewed_" + current_thread_json[id].tid)
if (xx) {
var yy = parseInt(xx)
if (yy >= parseInt(latestEmailInThread)) {
epoch = yy
}
}
try {
window.localStorage.setItem("viewed_" + current_thread_json[id].tid, epoch)
} catch(e) {
}
}
}
thread.style.display = (thread.style.display == 'none') ? 'block' : 'none';
// Bail if we can't find the thread struct
if (!current_thread_json[id]) {
return;
}
var helper = document.getElementById('helper_' + id)
if (!helper) {
helper = document.createElement('div')
helper.setAttribute("id", "helper_" + id)
helper.style.padding = "10px"
thread.parentNode.insertBefore(helper, thread)
}
if (prefs.groupBy == 'thread' && !(toverride == true)) {
// View as flat
helper.innerHTML = '<label style="padding: 4px; font-size: 10pt; cursor: pointer; float: right;" class="label label-info" onclick="prefs.groupBy=\'date\'; toggleEmails_threaded(' + id + ', true); toggleEmails_threaded(' + id + ', false, true); sortByDate(' + id + ');" style="cursor: pointer; float: right;">Click to view as flat thread, sort by date</label> '
// Highlight new emails since last view
helper.innerHTML += '<label style="margin-right: 10px; padding: 4px; font-size: 10pt; cursor: pointer; float: right;" class="label label-success" onclick="highlightNewEmails('+id+');" style="cursor: pointer; float: right;">Highlight new messages</label> '
} else {
helper.innerHTML = '<label style="padding: 4px; font-size: 10pt; cursor: pointer; float: right;" class="label label-info" onclick="prefs.groupBy=\'thread\'; toggleEmails_threaded(' + id + ', true);toggleEmails_threaded(' + id + ');" style="cursor: pointer; float: right;">Click to view as nested thread</label> '
}
// time travel magic!
var ml = findEml(current_thread_json[id].tid)
if (!current_thread_json[id].magic && ml.irt && ml.irt.length > 0) {
helper.innerHTML += "<p id='magic_"+id+"'><i><b>Note:</b> You are viewing a search result/aggregation in threaded mode. Only results matching your keywords or dates are shown, which may distort the thread. For the best result, go to the specific list and view the full thread there, or view your search results in flat mode. Or we can <a href='javascript:void(0);' onclick='timeTravelList("+id+")'>do some magic for you</a>.</i></p>"
// Why was this here??
/*
var btn = document.createElement('a')
btn.setAttribute("href", "javascript:void(0);")
btn.setAttribute("class", "btn btn-success")
btn.setAttribute("onclick", "prefs.displayMode='flat'; buildPage();")
btn.style.marginRight = "10px"
btn.innerHTML = "View results in flat mode instead"
helper.appendChild(btn)
*/
} else if (!current_thread_json[id].magic) {
helper.innerHTML += "<p id='magic_"+id+"'></p>"
}
if (close == true) {
thread.style.display = 'none'
}
if (thread.style.display == 'none') {
helper.style.display = 'none'
prefs.groupBy = 'thread' // hack for now
thread.innerHTML = ""
if (document.getElementById('bubble_' + id)) {
document.getElementById('bubble_' + id).style.display = 'block'
}
return
} else {
helper.style.display = 'block'
if (document.getElementById('bubble_' + id)) {
document.getElementById('bubble_' + id).style.display = 'none'
}
}
if (!open_emails[id]) {
open_emails[id] = true
}
var eml = saved_emails[current_thread_json[id].tid]
if (!eml || !eml.from) {
GetAsync("/api/email.lua?id=" + current_thread_json[id].tid, {
blockid: id,
thread: current_thread_json[id],
object: threadobj,
}, loadEmails_threaded)
} else {
loadEmails_threaded(eml, {
blockid: id,
thread: current_thread_json[id],
object: threadobj
})
}
}
}