Compare commits

...

1 Commits
main ... main

Author SHA1 Message Date
jerl e0b1685070 a few fixes 2025-10-29 21:58:12 -05:00
8 changed files with 52 additions and 50 deletions

View File

@ -98,7 +98,7 @@ window.makeUser = (user, url, context) => {
membername.textContent = user.displayname; membername.textContent = user.displayname;
memberusername.textContent = `${user.name}@${url}`; memberusername.textContent = `${user.name}@${url}`;
memberbio.textContent = user.bio; memberbio.textContent = user.bio;
}}>${user.displayname}</span>`; }}>${user.displayname || user.id}</span>`;
span.user = user; span.user = user;
return span; return span;
}; };
@ -207,7 +207,7 @@ document.body.append(html.node`
<button class='hidden' id='saveprofile' onclick=${saveProfile}>save</button> <button class='hidden' id='saveprofile' onclick=${saveProfile}>save</button>
</p> </p>
<label class='heading'>display name</label> <label class='heading'>display name</label>
<input id='newname' onkeyup=${profileEdit}> <input id='newname' onkeyup=${profileEdit} autocomplete='off' spellcheck='false'>
<p> <p>
<input id='profilepublic' type='checkbox' oninput=${saveProfile}> <input id='profilepublic' type='checkbox' oninput=${saveProfile}>
<label for='profilepublic'>show profile in instance user list</label> <label for='profilepublic'>show profile in instance user list</label>

View File

@ -114,7 +114,7 @@ your keys are stored in your browser's local storage only, so do this on a brows
</p> </p>
<form onsubmit=${submit} id='registerform'> <form onsubmit=${submit} id='registerform'>
<label for='username'>username: </label> <label for='username'>username: </label>
<input id='username' type='text' /> <input id='username' type='text' autocomplete='off' spellcheck='false'>
<br> <br>
<button id='submit' type='submit'>register</button> <button id='submit' type='submit'>register</button>
<button onclick=${submit}>authenticate</button> <button onclick=${submit}>authenticate</button>

View File

@ -44,11 +44,13 @@ function loadMessages(callback) {
now.getDate() === date.getDate() && date.getTime() > now.getTime() - 24 * 60 * 60000 now.getDate() === date.getDate() && date.getTime() > now.getTime() - 24 * 60 * 60000
? date.toLocaleTimeString() : date.toLocaleString() ? date.toLocaleTimeString() : date.toLocaleString()
}</span></div>`; }</span></div>`;
let author;
let content = html.node`<span class='content'>: ${message.content}</span>`; let content = html.node`<span class='content'>: ${message.content}</span>`;
content.prepend(user ? window.makeUser(user, user.id.split?.('@')[1] || instance.url) content.prepend(author = user ? window.makeUser(user, user.id.split?.('@')[1] || instance.url)
: html.node`<span>${message.user.id}</span>`); : html.node`<span>${message.user.id}</span>`);
div.prepend(content); div.prepend(content);
messages.append(div); messages.append(div);
return author;
} }
instance.emit('get_history', { instance.emit('get_history', {
@ -67,25 +69,25 @@ function loadMessages(callback) {
let user; let user;
if (message.user.name) if (message.user.name)
user = message.user; user = message.user;
else if (message.user.id.indexOf('@') === -1) else if (!message.user.id.includes('@'))
message.user.id = 'deleted user'; message.user.id = 'deleted user';
else { else {
user = users[message.user.id]; user = users[message.user.id];
if (user === undefined) if (!user)
try { user = users[message.user.id] = {
user = users[message.user.id] = await window.getUser(message.user.id); ...message.user,
} messages: []
catch (e) { };
console.log(`error getting user ${message.user.id}:`, e);
users[message.user.id] = false;
}
if (user) {
user.id = message.user.id;
user.permissions = message.user.permissions;
}
} }
addMessage(message, user); let author = addMessage(message, user);
if (user?.messages)
user.messages.push(author);
} }
for (let id in users)
window.getUser(id).then(user => {
for (let author of users[id].messages)
author.replaceWith(window.makeUser(user, id.split('@')[1]));
});
} }
if (msg.more) if (msg.more)
document.getElementById('loadmore').classList.remove('hidden'); document.getElementById('loadmore').classList.remove('hidden');

View File

@ -90,7 +90,7 @@ function loadStreams() {
name: this.value name: this.value
}); });
currentThread.streamname = this.value; currentThread.streamname = this.value;
}}> }} autocomplete='off'>
<p id='listeners'>${currentThread.listeners ? <p id='listeners'>${currentThread.listeners ?
currentThread.listeners + ' listeners' : ''} currentThread.listeners + ' listeners' : ''}
</p>`); </p>`);

View File

@ -219,7 +219,7 @@ function newThread(instance) {
<h4>create thread</h4> <h4>create thread</h4>
<label for='newthreadname' class='heading'>thread name</label> <label for='newthreadname' class='heading'>thread name</label>
<p id='newnameempty' class='hidden'>name cannot be empty</p> <p id='newnameempty' class='hidden'>name cannot be empty</p>
<input type='text' id='newthreadname' /> <input type='text' id='newthreadname' autocomplete='off'>
<p id='permissions'>thread permissions</p> <p id='permissions'>thread permissions</p>
<input type='radio' name='newpermissions' <input type='radio' name='newpermissions'
id='public' value='public' checked /> id='public' value='public' checked />
@ -236,7 +236,7 @@ function newThread(instance) {
event.preventDefault(); event.preventDefault();
addMember(); addMember();
} }
}} /> }} autocomplete='off'>
<button type='button' onclick=${addMember}>add</button> <button type='button' onclick=${addMember}>add</button>
<p id='newmembererror'></p> <p id='newmembererror'></p>
<div id='newmembers'> <div id='newmembers'>
@ -292,7 +292,7 @@ function editThread() {
}}> }}>
<h4>edit thread</h4> <h4>edit thread</h4>
<label for='editthreadname' class='heading'>thread name</label> <label for='editthreadname' class='heading'>thread name</label>
<input type='text' id='editthreadname' /> <input type='text' id='editthreadname' autocomplete='off'>
<p id='nameempty' class='hidden'>name cannot be empty</p> <p id='nameempty' class='hidden'>name cannot be empty</p>
<p id='permissions'>thread permissions</p> <p id='permissions'>thread permissions</p>
<input type='radio' name='permissions' <input type='radio' name='permissions'
@ -445,7 +445,7 @@ async function loadThreads(instancediv, select) {
<input id='addmembername' onblur=${addMember} onkeydown=${event => { <input id='addmembername' onblur=${addMember} onkeydown=${event => {
if (event.key === 'Enter') if (event.key === 'Enter')
addMember(); addMember();
}}> }} autocomplete='off'>
<p id='membererror'></p> <p id='membererror'></p>
</div> </div>
<div id='memberlist'> <div id='memberlist'>

View File

@ -76,6 +76,29 @@ global.celi = {
await new Promise(connecting); await new Promise(connecting);
} }
return instance; return instance;
},
emitcall: async function(thread) {
let msg = {
thread: thread.id,
call: thread.call
};
if ((await db.query(
`select * from permission
where thread = ? and type = 'everyone' and value = 'true' and permission = 'view'`,
thread.id)).rows.length) {
for (let id in celi.users)
for (let socket of celi.users[id].sockets)
socket.emit('call', msg);
} else {
for (let member of (
await db.query('select user from member where member.thread = ?', thread.id)
).rows) {
member = celi.users[member.user];
if (member)
for (let socket of member.sockets)
socket.emit('call', msg);
}
}
} }
}; };

View File

@ -78,7 +78,7 @@ async function join(msg, respond, socket) {
for (let id in call) for (let id in call)
if (id != msg.auth_user.id) if (id != msg.auth_user.id)
connection.addTrack(call[id].track); connection.addTrack(call[id].track);
await thread.emitcall(); await celi.emitcall(thread);
break; break;
case 'failed': case 'failed':
console.log('peer connection failed'); console.log('peer connection failed');
@ -91,7 +91,7 @@ async function join(msg, respond, socket) {
} }
delete call[msg.auth_user.id]; delete call[msg.auth_user.id];
delete thread.call[msg.auth_user.id]; delete thread.call[msg.auth_user.id];
await thread.emitcall(); await celi.emitcall(thread);
} }
} }
}; };
@ -159,7 +159,7 @@ async function leave(msg, respond) {
connection.close(); connection.close();
delete call[msg.auth_user.id]; delete call[msg.auth_user.id];
delete thread.call[msg.auth_user.id]; delete thread.call[msg.auth_user.id];
await thread.emitcall(); await celi.emitcall(thread);
respond({ success: true }); respond({ success: true });
} }

View File

@ -9,30 +9,7 @@ db.ready.then(async () => {
celi.threads[thread.id] = { celi.threads[thread.id] = {
...thread, ...thread,
streams: [], streams: [],
call: {}, // list of members in call call: {} // list of members in call
emitcall: async function() {
let msg = {
thread: this.id,
call: this.call
};
if ((await db.query(
`select * from permission
where thread = ? and type = 'everyone' and value = 'true' and permission = 'view'`,
this.id)).rows.length) {
for (let id in celi.users)
for (let socket of celi.users[id].sockets)
socket.emit('call', msg);
} else {
for (let member of (
await db.query('select user from member where member.thread = ?', this.id)
).rows) {
member = celi.users[member.user];
if (member)
for (let socket of member.sockets)
socket.emit('call', msg);
}
}
}
}; };
celi.calls[thread.id] = {}; celi.calls[thread.id] = {};
} }