url params
parent
62816d255f
commit
043a68874b
|
@ -126,7 +126,7 @@ function instanceClicked(event) {
|
||||||
document.getElementById('instancename').textContent = instance.url;
|
document.getElementById('instancename').textContent = instance.url;
|
||||||
let userlist = document.getElementById('userlist');
|
let userlist = document.getElementById('userlist');
|
||||||
userlist.innerHTML = '';
|
userlist.innerHTML = '';
|
||||||
instance.emit('list_users', {}, msg =>
|
instance.emit?.('list_users', {}, msg =>
|
||||||
userlist.replaceChildren(...msg.users.map(user => {
|
userlist.replaceChildren(...msg.users.map(user => {
|
||||||
let p = document.createElement('p');
|
let p = document.createElement('p');
|
||||||
p.append(window.makeUser(user, instance.url));
|
p.append(window.makeUser(user, instance.url));
|
||||||
|
|
|
@ -17,6 +17,7 @@ function setVisibility() {
|
||||||
function chooseThread() {
|
function chooseThread() {
|
||||||
const edit = document.getElementById('edit');
|
const edit = document.getElementById('edit');
|
||||||
let thread = this.thread;
|
let thread = this.thread;
|
||||||
|
let url = new URL(location);
|
||||||
if (window.currentThread) {
|
if (window.currentThread) {
|
||||||
window.currentThread.div.classList.remove('active');
|
window.currentThread.div.classList.remove('active');
|
||||||
let editform = document.getElementById('editthread');
|
let editform = document.getElementById('editthread');
|
||||||
|
@ -24,6 +25,10 @@ function chooseThread() {
|
||||||
editform.remove();
|
editform.remove();
|
||||||
edit.textContent = 'edit';
|
edit.textContent = 'edit';
|
||||||
}
|
}
|
||||||
|
url.searchParams.delete('tab');
|
||||||
|
if (window.currentThread.id === thread.id)
|
||||||
|
url.searchParams.delete('thread');
|
||||||
|
window.history.pushState(null, '', url.toString());
|
||||||
if (window.currentThread.id === thread.id) {
|
if (window.currentThread.id === thread.id) {
|
||||||
document.getElementById('thread').classList.add('hidden');
|
document.getElementById('thread').classList.add('hidden');
|
||||||
window.currentThread = null;
|
window.currentThread = null;
|
||||||
|
@ -40,36 +45,25 @@ function chooseThread() {
|
||||||
this.classList.add('active');
|
this.classList.add('active');
|
||||||
window.currentThread = thread;
|
window.currentThread = thread;
|
||||||
window.currentInstance = thread.instance;
|
window.currentInstance = thread.instance;
|
||||||
if (this.tab) {
|
let tab = url.searchParams.get('tab');
|
||||||
|
if (['message', 'space', 'stream'].indexOf(tab) === -1)
|
||||||
|
tab = null;
|
||||||
|
if (tab || this.tab) {
|
||||||
|
if (tab)
|
||||||
|
this.tab = tab + 'tab';
|
||||||
switchTab(document.getElementById(this.tab));
|
switchTab(document.getElementById(this.tab));
|
||||||
if (this.tab === 'messagetab')
|
if (this.tab === 'messagetab')
|
||||||
loadMessages();
|
loadMessages();
|
||||||
else if (this.tab === 'spacetab')
|
else if (this.tab === 'spacetab')
|
||||||
loadSpace();
|
loadSpace();
|
||||||
}
|
}
|
||||||
else // load first tab that has any content
|
let div = this;
|
||||||
loadMessages(messages => {
|
|
||||||
if (messages.length)
|
|
||||||
switchTab(document.getElementById(this.tab = 'messagetab'));
|
|
||||||
else
|
|
||||||
loadSpace(spans => {
|
|
||||||
if (spans.length)
|
|
||||||
switchTab(document.getElementById(this.tab = 'spacetab'));
|
|
||||||
else if (window.currentThread.streams.length)
|
|
||||||
switchTab(document.getElementById(this.tab = 'streamtab'));
|
|
||||||
else
|
|
||||||
switchTab(document.getElementById(
|
|
||||||
this.tab = spans.length ? 'spacetab' :
|
|
||||||
window.currentThread.streams.length ? 'streamtab' : 'messagetab'));
|
|
||||||
});
|
|
||||||
});
|
|
||||||
window.currentInstance.emit('get_thread', { thread: thread.id }, async msg => {
|
window.currentInstance.emit('get_thread', { thread: thread.id }, async msg => {
|
||||||
if (!msg.success) {
|
if (!msg.success) {
|
||||||
console.log('get_thread failed:', msg.message);
|
console.log('get_thread failed:', msg.message);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Object.assign(thread, msg.thread);
|
Object.assign(thread, msg.thread);
|
||||||
loadStreams();
|
|
||||||
setVisibility();
|
setVisibility();
|
||||||
document.getElementById('memberlist').replaceChildren(
|
document.getElementById('memberlist').replaceChildren(
|
||||||
...await Promise.all(msg.thread.members.map(async member => {
|
...await Promise.all(msg.thread.members.map(async member => {
|
||||||
|
@ -79,6 +73,31 @@ function chooseThread() {
|
||||||
return p;
|
return p;
|
||||||
}))
|
}))
|
||||||
);
|
);
|
||||||
|
loadStreams();
|
||||||
|
if (!div.tab)
|
||||||
|
await new Promise(resolve => {
|
||||||
|
// load first tab that has any content
|
||||||
|
loadMessages(messages => {
|
||||||
|
if (messages.length) {
|
||||||
|
switchTab(document.getElementById(div.tab = 'messagetab'));
|
||||||
|
resolve();
|
||||||
|
} else
|
||||||
|
loadSpace(spans => {
|
||||||
|
if (spans.length)
|
||||||
|
switchTab(document.getElementById(div.tab = 'spacetab'));
|
||||||
|
else if (window.currentThread.streams.length)
|
||||||
|
switchTab(document.getElementById(div.tab = 'streamtab'));
|
||||||
|
else
|
||||||
|
switchTab(document.getElementById(
|
||||||
|
div.tab = spans.length ? 'spacetab' :
|
||||||
|
window.currentThread.streams.length ? 'streamtab' : 'messagetab'));
|
||||||
|
resolve();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
url.searchParams.set('thread', thread.id);
|
||||||
|
url.searchParams.set('tab', div.tab.substring(0, div.tab.length - 3));
|
||||||
|
window.history.pushState(null, '', url.toString());
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -282,6 +301,9 @@ function clickedTab(event) {
|
||||||
loadMessages();
|
loadMessages();
|
||||||
else if (this.id === 'spacetab')
|
else if (this.id === 'spacetab')
|
||||||
loadSpace();
|
loadSpace();
|
||||||
|
let url = new URL(location);
|
||||||
|
url.searchParams.set('tab', this.id.substring(0, this.id.length - 3));
|
||||||
|
window.history.pushState(null, '', url.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
async function loadThreads(instancediv, select) {
|
async function loadThreads(instancediv, select) {
|
||||||
|
@ -339,7 +361,11 @@ async function loadThreads(instancediv, select) {
|
||||||
|
|
||||||
instancediv.instance.emit('list_threads', {}, msg => {
|
instancediv.instance.emit('list_threads', {}, msg => {
|
||||||
threadlist.replaceChildren(...msg.threads.map(makeThread));
|
threadlist.replaceChildren(...msg.threads.map(makeThread));
|
||||||
if (select && msg.threads.length)
|
let thread = msg.threads.find(thread =>
|
||||||
|
thread.id == (new URLSearchParams(location.search)).get('thread'))?.div;
|
||||||
|
if (!window.currentThread && thread)
|
||||||
|
chooseThread.call(thread);
|
||||||
|
else if (select && msg.threads.length)
|
||||||
chooseThread.call(threadlist.firstChild);
|
chooseThread.call(threadlist.firstChild);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue