Skip to content

Commit

Permalink
refactor: make static methods non-static (#398)
Browse files Browse the repository at this point in the history
Co-authored-by: Farhad Jay <[email protected]>
  • Loading branch information
vyneer and 11k authored Jan 8, 2024
1 parent ee18ae8 commit a33f31c
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 24 deletions.
44 changes: 22 additions & 22 deletions assets/chat/js/chat.js
Original file line number Diff line number Diff line change
Expand Up @@ -526,7 +526,7 @@ class Chat {
}

async loadEmotes() {
Chat.loadCss(
this.loadCss(
`${this.config.cdn.base}/emotes/emotes.css?_=${this.config.cacheKey}`,
);
return fetch(
Expand All @@ -540,7 +540,7 @@ class Chat {
}

async loadFlairs() {
Chat.loadCss(
this.loadCss(
`${this.config.cdn.base}/flairs/flairs.css?_=${this.config.cacheKey}`,
);
return fetch(
Expand Down Expand Up @@ -699,7 +699,7 @@ class Chat {
} else {
if (
Object.hasOwn(data, 'features') &&
!Chat.isArraysEqual(data.features, user.features)
!this.isArraysEqual(data.features, user.features)
) {
user.features = data.features;
}
Expand Down Expand Up @@ -751,7 +751,7 @@ class Chat {
// check if this is the current users message
message.isown = message.user?.username === this.user.username;
// get mentions from message
message.mentioned = Chat.extractNicks(message.message).filter((a) =>
message.mentioned = this.extractNicks(message.message).filter((a) =>
this.users.has(a.toLowerCase()),
);
// set tagged state
Expand Down Expand Up @@ -789,7 +789,7 @@ class Chat {
this.ishidden &&
!message.ignored
) {
Chat.showNotification(
this.showNotification(
`${message.user.displayName} said ...`,
message.message,
message.timestamp.valueOf(),
Expand Down Expand Up @@ -1015,7 +1015,7 @@ class Chat {

onCONNECTING(url) {
MessageBuilder.status(
`Connecting to ${Chat.extractHostname(url)} ...`,
`Connecting to ${this.extractHostname(url)} ...`,
).into(this);
}

Expand Down Expand Up @@ -1074,12 +1074,12 @@ class Chat {
}

onMSG(data) {
const textonly = Chat.removeSlashCmdFromText(data.data);
const textonly = this.removeSlashCmdFromText(data.data);
const usr = this.users.get(data.nick.toLowerCase());
const win = this.mainwindow;
const isCombo =
this.emoteService.canUserUseEmote(usr, textonly) &&
Chat.removeSlashCmdFromText(win.lastmessage?.message) === textonly;
this.removeSlashCmdFromText(win.lastmessage?.message) === textonly;

if (isCombo && win.lastmessage?.type === MessageTypes.EMOTE) {
win.lastmessage.incEmoteCount();
Expand Down Expand Up @@ -1328,7 +1328,7 @@ class Chat {
messageid,
).into(this);
if (this.settings.get('notificationwhisper') && this.ishidden)
Chat.showNotification(
this.showNotification(
`${data.nick} whispered ...`,
data.data,
data.timestamp,
Expand Down Expand Up @@ -1366,7 +1366,7 @@ class Chat {
const matches = raw.match(regexslashcmd);
const iscommand = matches && matches.length > 1;
const ismecmd = iscommand && matches[1].toLowerCase() === 'me';
const textonly = Chat.removeSlashCmdFromText(raw);
const textonly = this.removeSlashCmdFromText(raw);

// COMMAND
if (iscommand && !ismecmd) {
Expand Down Expand Up @@ -1656,7 +1656,7 @@ class Chat {
} else if (!nickregex.test(parts[0])) {
MessageBuilder.info(`Invalid nick - /mute <nick> [<time>].`).into(this);
} else {
const duration = parts[1] ? Chat.parseTimeInterval(parts[1]) : null;
const duration = parts[1] ? this.parseTimeInterval(parts[1]) : null;
if (duration && duration > 0) {
this.source.send('MUTE', { data: parts[0], duration });
} else {
Expand All @@ -1680,7 +1680,7 @@ class Chat {
reason: parts.slice(2, parts.length).join(' '),
};
if (/^perm/i.test(parts[1])) payload.ispermanent = true;
else payload.duration = Chat.parseTimeInterval(parts[1]);
else payload.duration = this.parseTimeInterval(parts[1]);

payload.banip = command === 'IPBAN';

Expand Down Expand Up @@ -1891,7 +1891,7 @@ class Chat {
this.mainwindow
.getlines(`.msg-user[data-username="${n}"]`)
.forEach((line) => {
const classesToRemove = Chat.removeClasses(
const classesToRemove = this.removeClasses(
'msg-tagged',
line.classList.value,
);
Expand Down Expand Up @@ -2368,28 +2368,28 @@ class Chat {
return '/bigscreen';
}

static removeSlashCmdFromText(msg) {
removeSlashCmdFromText(msg) {
return msg?.replace(regexslashcmd, '').trim();
}

static extractNicks(text) {
extractNicks(text) {
const uniqueNicks = new Set(text.match(nickmessageregex));
return [...uniqueNicks];
}

static removeClasses(search, classList) {
removeClasses(search, classList) {
return (
classList.match(new RegExp(`\\b${search}(?:[A-z-]+)?\\b`, 'g')) || []
);
}

static isArraysEqual(a, b) {
isArraysEqual(a, b) {
return !a || !b
? a.length !== b.length || a.sort().toString() !== b.sort().toString()
: false;
}

static showNotification(title, message, timestamp, timeout = false) {
showNotification(title, message, timestamp, timeout = false) {
if (Notification.permission === 'granted') {
const n = new Notification(title, {
body: message,
Expand All @@ -2401,7 +2401,7 @@ class Chat {
}
}

static parseTimeInterval(str) {
parseTimeInterval(str) {
const { number, unit } = str.match(regextime)?.groups ?? {};
return (
moment
Expand All @@ -2410,7 +2410,7 @@ class Chat {
);
}

static loadCss(url) {
loadCss(url) {
const link = document.createElement('link');
link.href = url;
link.type = 'text/css';
Expand All @@ -2420,7 +2420,7 @@ class Chat {
return link;
}

static reqParam(name) {
reqParam(name) {
const sanitizedName = name.replace(/[[\]]/g, '\\$&');
const url = window.location || window.location.href || null;
const regex = new RegExp(`[?&]${sanitizedName}(=([^&#]*)|&|#|$)`);
Expand All @@ -2429,7 +2429,7 @@ class Chat {
return decodeURIComponent(results[2].replace(/\+/g, ' '));
}

static extractHostname(url) {
extractHostname(url) {
let hostname =
url.indexOf('://') > -1 ? url.split('/')[2] : url.split('/')[0];
hostname = hostname.split(':')[0];
Expand Down
4 changes: 2 additions & 2 deletions assets/demo.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ const chat = new Chat({

const html = $('body,html');

switch ((Chat.reqParam('t') || 'embed').toUpperCase()) {
switch ((chat.reqParam('t') || 'embed').toUpperCase()) {
case 'STREAM':
html.css('background', 'transparent');
chat
.withGui(streamHtml)
.then(() => {
chat.settings.set('fontscale', Chat.reqParam('f') || 1);
chat.settings.set('fontscale', chat.reqParam('f') || 1);
chat.applySettings(false);
})
.then(() => chat.loadEmotesAndFlairs())
Expand Down

0 comments on commit a33f31c

Please sign in to comment.