load first tab that has any content
parent
579ed14344
commit
4416a3766b
|
@ -33,12 +33,16 @@ function chooseThread() {
|
||||||
document.getElementById('threadname').textContent = this.thread.name;
|
document.getElementById('threadname').textContent = this.thread.name;
|
||||||
this.classList.add('active');
|
this.classList.add('active');
|
||||||
window.currentThread = this.thread;
|
window.currentThread = this.thread;
|
||||||
loadMessages();
|
if (this.tab)
|
||||||
if (this.thread.permissions.post)
|
|
||||||
document.getElementById('msginput').classList.remove('hidden');
|
|
||||||
else
|
|
||||||
document.getElementById('msginput').classList.add('hidden');
|
|
||||||
switchTab(document.getElementById(this.tab));
|
switchTab(document.getElementById(this.tab));
|
||||||
|
else // load first tab that has any content
|
||||||
|
loadMessages(true, messages => {
|
||||||
|
if (messages.length)
|
||||||
|
switchTab(document.getElementById(this.tab = 'messagetab'));
|
||||||
|
else
|
||||||
|
loadSpace(spans => switchTab(
|
||||||
|
document.getElementById(this.tab = spans.length ? 'spacetab' : 'messagetab')));
|
||||||
|
});
|
||||||
window.emit('get_thread', { thread: this.thread.id }, msg => {
|
window.emit('get_thread', { thread: this.thread.id }, msg => {
|
||||||
window.currentThread = msg.thread;
|
window.currentThread = msg.thread;
|
||||||
setVisibility();
|
setVisibility();
|
||||||
|
@ -58,7 +62,9 @@ function switchTab(tab) {
|
||||||
document
|
document
|
||||||
.getElementById(tab.id.slice(0, -3))
|
.getElementById(tab.id.slice(0, -3))
|
||||||
.classList.remove('hidden');
|
.classList.remove('hidden');
|
||||||
if (tab.id === 'spacetab')
|
if (tab.id === 'messagetab')
|
||||||
|
loadMessages(true);
|
||||||
|
else if (tab.id === 'spacetab')
|
||||||
loadSpace();
|
loadSpace();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -288,7 +294,6 @@ function makeThread(thread) {
|
||||||
}</div>`;
|
}</div>`;
|
||||||
node.id = 'thread' + thread.id;
|
node.id = 'thread' + thread.id;
|
||||||
node.thread = thread;
|
node.thread = thread;
|
||||||
node.tab = 'messagetab';
|
|
||||||
return node;
|
return node;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -31,7 +31,7 @@ window.socket.on('new_message', message => {
|
||||||
earliestMessage = message.id;
|
earliestMessage = message.id;
|
||||||
});
|
});
|
||||||
|
|
||||||
function loadMessages() {
|
function loadMessages(firstRender, callback) {
|
||||||
if (!msg) {
|
if (!msg) {
|
||||||
render(document.getElementById('message'), html`
|
render(document.getElementById('message'), html`
|
||||||
<button id='loadmore' class='hidden' onclick=${loadMessages}>
|
<button id='loadmore' class='hidden' onclick=${loadMessages}>
|
||||||
|
@ -49,6 +49,10 @@ function loadMessages() {
|
||||||
if (!this) { // called from chooseThread, initializing thread
|
if (!this) { // called from chooseThread, initializing thread
|
||||||
messages.innerHTML = '';
|
messages.innerHTML = '';
|
||||||
earliestMessage = null;
|
earliestMessage = null;
|
||||||
|
if (window.currentThread.permissions.post)
|
||||||
|
document.getElementById('msginput').classList.remove('hidden');
|
||||||
|
else
|
||||||
|
document.getElementById('msginput').classList.add('hidden');
|
||||||
}
|
}
|
||||||
window.emit(
|
window.emit(
|
||||||
'get_history',
|
'get_history',
|
||||||
|
@ -57,8 +61,13 @@ function loadMessages() {
|
||||||
thread: window.currentThread.id
|
thread: window.currentThread.id
|
||||||
},
|
},
|
||||||
msg => {
|
msg => {
|
||||||
if (!msg.success)
|
if (!msg.success) {
|
||||||
console.log('get_history failed: ' + msg.message);
|
console.log('get_history failed: ' + msg.message);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
callback && callback(msg.messages);
|
||||||
|
if (firstRender && messages.hasChildNodes())
|
||||||
|
return;
|
||||||
if (msg.messages.length > 0) {
|
if (msg.messages.length > 0) {
|
||||||
earliestMessage = msg.messages[msg.messages.length - 1].id;
|
earliestMessage = msg.messages[msg.messages.length - 1].id;
|
||||||
for (let message of msg.messages)
|
for (let message of msg.messages)
|
||||||
|
|
|
@ -122,7 +122,7 @@ window.socket.on('span', msg => {
|
||||||
add(msg);
|
add(msg);
|
||||||
});
|
});
|
||||||
|
|
||||||
export default function loadSpace() {
|
export default function loadSpace(callback) {
|
||||||
if (!space) {
|
if (!space) {
|
||||||
space = document.getElementById('space');
|
space = document.getElementById('space');
|
||||||
space.onmouseup = event => {
|
space.onmouseup = event => {
|
||||||
|
@ -149,8 +149,11 @@ export default function loadSpace() {
|
||||||
spaceId = window.window.currentThread.id;
|
spaceId = window.window.currentThread.id;
|
||||||
space.innerHTML = '';
|
space.innerHTML = '';
|
||||||
window.emit('get_space', { thread: window.window.currentThread.id }, msg => {
|
window.emit('get_space', { thread: window.window.currentThread.id }, msg => {
|
||||||
if (!msg.success)
|
if (!msg.success) {
|
||||||
console.log('get space failed: ' + msg.message);
|
console.log('get space failed: ' + msg.message);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
callback && callback(msg.spans);
|
||||||
for (const span of msg.spans)
|
for (const span of msg.spans)
|
||||||
add(span);
|
add(span);
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue