Up to date fork #1

Merged
MiTask merged 33 commits from snxraven/LinkUp-P2P-Chat:main into main 2024-06-14 04:32:25 -04:00
Showing only changes of commit 060308ec92 - Show all commits

14
app.js
View File

@ -14,7 +14,6 @@ const drive = new Hyperdrive(store);
await drive.ready();
let swarm;
let registeredUsers = JSON.parse(localStorage.getItem('registeredUsers')) || {};
let peerCount = 0;
let activeRooms = [];
const eventEmitter = new EventEmitter();
@ -26,7 +25,8 @@ let servePort;
let config = {
userName: '',
userAvatar: '',
rooms: []
rooms: [],
registeredUsers: {}
};
// Store messages for each room
@ -97,8 +97,8 @@ async function initialize() {
config.rooms.forEach(room => {
room.alias = room.alias || truncateHash(room.topic);
});
for (let user in registeredUsers) {
registeredUsers[user] = updatePortInUrl(registeredUsers[user]);
for (let user in config.registeredUsers) {
config.registeredUsers[user] = updatePortInUrl(config.registeredUsers[user]);
}
renderRoomList(); // Render the room list with aliases
@ -189,7 +189,7 @@ function registerUser(e) {
e.preventDefault();
const regUsername = document.querySelector('#reg-username').value;
if (registeredUsers[regUsername]) {
if (config.registeredUsers[regUsername]) {
alert('Username already taken. Please choose another.');
return;
}
@ -201,8 +201,8 @@ function registerUser(e) {
const buffer = new Uint8Array(event.target.result);
await drive.put(`/icons/${regUsername}.png`, buffer);
config.userAvatar = `http://localhost:${servePort}/icons/${regUsername}.png`; // Set the correct URL
registeredUsers[regUsername] = `http://localhost:${servePort}/icons/${regUsername}.png`; // Use placeholder URL
localStorage.setItem('registeredUsers', JSON.stringify(registeredUsers));
config.registeredUsers[regUsername] = `http://localhost:${servePort}/icons/${regUsername}.png`; // Use placeholder URL
writeConfigToFile("./config.json");
continueRegistration(regUsername);
};
reader.readAsArrayBuffer(avatarFile);