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,8 +34,12 @@ export default class Chat {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (options && options.error) {
|
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.info) {
|
} 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);
|
$el = $('<li class="log-info">').addClass('log').html(message);
|
||||||
} else {
|
} else {
|
||||||
$el = $('<li>').addClass('log').html(message);
|
$el = $('<li>').addClass('log').html(message);
|
||||||
@ -68,9 +72,10 @@ export default class Chat {
|
|||||||
const COLORS = [
|
const COLORS = [
|
||||||
'#e21400', '#ffe400', '#ff8f00',
|
'#e21400', '#ffe400', '#ff8f00',
|
||||||
'#58dc00', '#dd9cff', '#4ae8c4',
|
'#58dc00', '#dd9cff', '#4ae8c4',
|
||||||
'#3b88eb', '#f47777', '#d300e7',
|
'#3b88eb', '#f47777', '#EEACB7',
|
||||||
'#99FF33', '#99CC33', '#999933',
|
'#D3FF3E', '#99CC33', '#999933',
|
||||||
'#996633', '#993333', '#990033',
|
'#996633', '#B8D5B8', '#7FFF38',
|
||||||
|
'#FADBBC', '#FAE2B7', '#EBE8AF',
|
||||||
];
|
];
|
||||||
// Compute hash code
|
// Compute hash code
|
||||||
let hash = 7;
|
let hash = 7;
|
||||||
@ -173,7 +178,7 @@ export default class Chat {
|
|||||||
return this.log('Username must start with a letter.', {error: true});
|
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 = {
|
let modifiedSocketData = {
|
||||||
username: window.username,
|
username: window.username,
|
||||||
newUsername: socketData.username
|
newUsername: socketData.username
|
||||||
@ -181,6 +186,8 @@ export default class Chat {
|
|||||||
|
|
||||||
this.socket.emit('update user', modifiedSocketData);
|
this.socket.emit('update user', modifiedSocketData);
|
||||||
window.username = username = socketData.username;
|
window.username = username = socketData.username;
|
||||||
|
}).catch((err) => {
|
||||||
|
return this.log(err, {error: true});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}, {
|
}, {
|
||||||
@ -194,7 +201,7 @@ export default class Chat {
|
|||||||
return '/' + command;
|
return '/' + command;
|
||||||
});
|
});
|
||||||
|
|
||||||
this.log('Valid commands: ' + validCommands.sort().join(', '), {info: true});
|
this.log('Valid commands: ' + validCommands.sort().join(', '), {notice: true});
|
||||||
}
|
}
|
||||||
}, {
|
}, {
|
||||||
command: 'me',
|
command: 'me',
|
||||||
|
@ -53,16 +53,12 @@ export default class Darkwire {
|
|||||||
return _.findWhere(this._users, {id: id});
|
return _.findWhere(this._users, {id: id});
|
||||||
}
|
}
|
||||||
|
|
||||||
getUserByName(username) {
|
|
||||||
return _.findWhere(this._users, {username: username});
|
|
||||||
}
|
|
||||||
|
|
||||||
updateUser(data) {
|
updateUser(data) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
let user = this.getUserById(data.id);
|
let user = this.getUserById(data.id);
|
||||||
|
|
||||||
if (!user) {
|
if (!user) {
|
||||||
return reject();
|
return reject('User cannot be found');
|
||||||
}
|
}
|
||||||
|
|
||||||
let oldUsername = user.username;
|
let oldUsername = user.username;
|
||||||
@ -105,45 +101,62 @@ export default class Darkwire {
|
|||||||
return importKeysPromises;
|
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) {
|
removeUser(data) {
|
||||||
this._users = _.without(this._users, _.findWhere(this._users, {id: data.id}));
|
this._users = _.without(this._users, _.findWhere(this._users, {id: data.id}));
|
||||||
return this._users;
|
return this._users;
|
||||||
}
|
}
|
||||||
|
|
||||||
updateUsername(username, newUsername) {
|
updateUsername(username) {
|
||||||
let user = null;
|
let user = null;
|
||||||
|
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
if (newUsername) {
|
if (username) {
|
||||||
user = this.getUserByName(username);
|
user = this.getUserById(this._myUserId);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (username) {
|
if (!user) {
|
||||||
if (!user) {
|
Promise.all([
|
||||||
Promise.all([
|
this._cryptoUtil.createPrimaryKeys()
|
||||||
this._cryptoUtil.createPrimaryKeys()
|
])
|
||||||
])
|
.then((data) => {
|
||||||
.then((data) => {
|
this._keys = {
|
||||||
this._keys = {
|
public: data[0].publicKey,
|
||||||
public: data[0].publicKey,
|
private: data[0].privateKey
|
||||||
private: data[0].privateKey
|
};
|
||||||
};
|
return Promise.all([
|
||||||
return Promise.all([
|
this._cryptoUtil.exportKey(data[0].publicKey, 'spki')
|
||||||
this._cryptoUtil.exportKey(data[0].publicKey, 'spki')
|
]);
|
||||||
]);
|
})
|
||||||
})
|
.then((exportedKeys) => {
|
||||||
.then((exportedKeys) => {
|
|
||||||
resolve({
|
|
||||||
username: username,
|
|
||||||
publicKey: exportedKeys[0]
|
|
||||||
});
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
resolve({
|
resolve({
|
||||||
username: newUsername,
|
username: username,
|
||||||
publicKey: user.publicKey
|
publicKey: exportedKeys[0]
|
||||||
});
|
});
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
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,
|
fs(window.TEMPORARY,
|
||||||
100,
|
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});
|
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;
|
line-height: 10px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.log-info {
|
.log-error, .log-info, .log-warning {
|
||||||
color: #FFF;
|
|
||||||
font-weight: bold;
|
font-weight: bold;
|
||||||
}
|
}
|
||||||
|
|
||||||
.log-error {
|
.log-error {
|
||||||
color: yellow;
|
color: #D8D638;
|
||||||
font-weight: bold;
|
}
|
||||||
|
|
||||||
|
.log-info {
|
||||||
|
color: #FFF;
|
||||||
|
}
|
||||||
|
|
||||||
|
.log-warning {
|
||||||
|
color: #E0873E;
|
||||||
}
|
}
|
||||||
|
|
||||||
.action {
|
.action {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user