Add support for owner, admin and halfop user modes

This commit is contained in:
Ken-Håvard Lieng 2017-05-10 03:47:34 +02:00
parent 750ffef4c2
commit 2b5a468079
2 changed files with 47 additions and 42 deletions

File diff suppressed because one or more lines are too long

View File

@ -8,16 +8,22 @@ const User = Record({
mode: '' mode: ''
}); });
function updateRenderName(user) { const modePrefixes = [
let name = user.nick; { mode: 'q', prefix: '~' }, // Owner
{ mode: 'a', prefix: '&' }, // Admin
{ mode: 'o', prefix: '@' }, // Op
{ mode: 'h', prefix: '%' }, // Halfop
{ mode: 'v', prefix: '+' } // Voice
];
if (user.mode.indexOf('o') !== -1) { function updateRenderName(user) {
name = `@${name}`; for (let i = 0; i < modePrefixes.length; i++) {
} else if (user.mode.indexOf('v') !== -1) { if (user.mode.indexOf(modePrefixes[i].mode) !== -1) {
name = `+${name}`; return user.set('renderName', `${modePrefixes[i].prefix}${user.nick}`);
}
} }
return user.set('renderName', name); return user.set('renderName', user.nick);
} }
function createUser(nick, mode) { function createUser(nick, mode) {
@ -31,35 +37,34 @@ function createUser(nick, mode) {
function loadUser(nick) { function loadUser(nick) {
let mode; let mode;
if (nick[0] === '@') { for (let i = 0; i < modePrefixes.length; i++) {
mode = 'o'; if (nick[0] === modePrefixes[i].prefix) {
} else if (nick[0] === '+') { mode = modePrefixes[i].mode;
mode = 'v'; }
} }
if (mode) { if (mode) {
return createUser(nick.slice(1), mode); return createUser(nick.slice(1), mode);
} }
return createUser(nick, mode); return createUser(nick);
} }
function compareUsers(a, b) { function compareUsers(a, b) {
a = a.renderName.toLowerCase(); a = a.renderName.toLowerCase();
b = b.renderName.toLowerCase(); b = b.renderName.toLowerCase();
if (a[0] === '@' && b[0] !== '@') { for (let i = 0; i < modePrefixes.length; i++) {
return -1; const prefix = modePrefixes[i].prefix;
}
if (b[0] === '@' && a[0] !== '@') { if (a[0] === prefix && b[0] !== prefix) {
return 1; return -1;
} }
if (a[0] === '+' && b[0] !== '+') { if (b[0] === prefix && a[0] !== prefix) {
return -1; return 1;
} }
if (b[0] === '+' && a[0] !== '+') {
return 1;
} }
if (a < b) { if (a < b) {
return -1; return -1;
} }