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