mirror of
https://github.com/darkwire/darkwire.io.git
synced 2025-07-19 19:14:53 +00:00
Fixing colors, allowing only unique usernames per chat session
This commit is contained in:
parent
6ce7c10584
commit
d0d47c098a
@ -34,7 +34,11 @@ export default class Chat {
|
||||
}
|
||||
|
||||
if (options && options.error) {
|
||||
$el = $('<li class="log-error">').addClass('log').html(message);
|
||||
$el = $('<li class="log-error">').addClass('log').html('ERROR: ' + message);
|
||||
} else if (options && options.warning) {
|
||||
$el = $('<li class="log-warning">').addClass('log').html('WARNING: ' + message);
|
||||
} else if (options && options.notice) {
|
||||
$el = $('<li class="log-info">').addClass('log').html('NOTICE: ' + message);
|
||||
} else if (options && options.info) {
|
||||
$el = $('<li class="log-info">').addClass('log').html(message);
|
||||
} else {
|
||||
@ -68,9 +72,10 @@ export default class Chat {
|
||||
const COLORS = [
|
||||
'#e21400', '#ffe400', '#ff8f00',
|
||||
'#58dc00', '#dd9cff', '#4ae8c4',
|
||||
'#3b88eb', '#f47777', '#d300e7',
|
||||
'#99FF33', '#99CC33', '#999933',
|
||||
'#996633', '#993333', '#990033',
|
||||
'#3b88eb', '#f47777', '#EEACB7',
|
||||
'#D3FF3E', '#99CC33', '#999933',
|
||||
'#996633', '#B8D5B8', '#7FFF38',
|
||||
'#FADBBC', '#FAE2B7', '#EBE8AF',
|
||||
];
|
||||
// Compute hash code
|
||||
let hash = 7;
|
||||
@ -173,7 +178,7 @@ export default class Chat {
|
||||
return this.log('Username must start with a letter.', {error: true});
|
||||
}
|
||||
|
||||
this.darkwire.updateUsername(window.username, newUsername).then((socketData) => {
|
||||
this.darkwire.updateUsername(newUsername).then((socketData) => {
|
||||
let modifiedSocketData = {
|
||||
username: window.username,
|
||||
newUsername: socketData.username
|
||||
@ -181,6 +186,8 @@ export default class Chat {
|
||||
|
||||
this.socket.emit('update user', modifiedSocketData);
|
||||
window.username = username = socketData.username;
|
||||
}).catch((err) => {
|
||||
return this.log(err, {error: true});
|
||||
});
|
||||
}
|
||||
}, {
|
||||
@ -194,7 +201,7 @@ export default class Chat {
|
||||
return '/' + command;
|
||||
});
|
||||
|
||||
this.log('Valid commands: ' + validCommands.sort().join(', '), {info: true});
|
||||
this.log('Valid commands: ' + validCommands.sort().join(', '), {notice: true});
|
||||
}
|
||||
}, {
|
||||
command: 'me',
|
||||
|
@ -53,16 +53,12 @@ export default class Darkwire {
|
||||
return _.findWhere(this._users, {id: id});
|
||||
}
|
||||
|
||||
getUserByName(username) {
|
||||
return _.findWhere(this._users, {username: username});
|
||||
}
|
||||
|
||||
updateUser(data) {
|
||||
return new Promise((resolve, reject) => {
|
||||
let user = this.getUserById(data.id);
|
||||
|
||||
if (!user) {
|
||||
return reject();
|
||||
return reject('User cannot be found');
|
||||
}
|
||||
|
||||
let oldUsername = user.username;
|
||||
@ -105,20 +101,31 @@ export default class Darkwire {
|
||||
return importKeysPromises;
|
||||
}
|
||||
|
||||
checkSessionUsernames(username) {
|
||||
let matches = _.find(this._users, (users) => {
|
||||
return username.toLowerCase() === users.username.toLowerCase();
|
||||
});
|
||||
|
||||
if (matches && matches.username) {
|
||||
return matches;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
removeUser(data) {
|
||||
this._users = _.without(this._users, _.findWhere(this._users, {id: data.id}));
|
||||
return this._users;
|
||||
}
|
||||
|
||||
updateUsername(username, newUsername) {
|
||||
updateUsername(username) {
|
||||
let user = null;
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
if (newUsername) {
|
||||
user = this.getUserByName(username);
|
||||
if (username) {
|
||||
user = this.getUserById(this._myUserId);
|
||||
}
|
||||
|
||||
if (username) {
|
||||
if (!user) {
|
||||
Promise.all([
|
||||
this._cryptoUtil.createPrimaryKeys()
|
||||
@ -139,12 +146,18 @@ export default class Darkwire {
|
||||
});
|
||||
});
|
||||
} else {
|
||||
resolve({
|
||||
username: newUsername,
|
||||
let userExists = this.checkSessionUsernames(username);
|
||||
if (userExists) {
|
||||
if (userExists.id !== this._myUserId) {
|
||||
return reject(username + ' is being used by someone else in this chat session.');
|
||||
}
|
||||
}
|
||||
|
||||
return resolve({
|
||||
username: username,
|
||||
publicKey: user.publicKey
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -48,7 +48,7 @@ $(function() {
|
||||
fs(window.TEMPORARY,
|
||||
100,
|
||||
() => {
|
||||
chat.log('WARNING: Your browser is not in incognito mode!', {error: true});
|
||||
chat.log('Your browser is not in incognito mode!', {warning: true});
|
||||
});
|
||||
}
|
||||
chat.log(moment().format('MMMM Do YYYY, h:mm:ss a'), {info: true});
|
||||
|
@ -313,14 +313,20 @@ html.no-touchevents .chat #input-icons {
|
||||
line-height: 10px;
|
||||
}
|
||||
|
||||
.log-info {
|
||||
color: #FFF;
|
||||
.log-error, .log-info, .log-warning {
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
.log-error {
|
||||
color: yellow;
|
||||
font-weight: bold;
|
||||
color: #D8D638;
|
||||
}
|
||||
|
||||
.log-info {
|
||||
color: #FFF;
|
||||
}
|
||||
|
||||
.log-warning {
|
||||
color: #E0873E;
|
||||
}
|
||||
|
||||
.action {
|
||||
|
Loading…
x
Reference in New Issue
Block a user