fix: Use arrow function to bind methods to class (#10215)

Co-authored-by: Sivin Varghese <64252451+iamsivin@users.noreply.github.com>
Co-authored-by: iamsivin <iamsivin@gmail.com>
This commit is contained in:
Shivam Mishra
2024-10-04 20:35:34 +05:30
committed by GitHub
parent 5b22af6af8
commit 55bf05d2d4

View File

@@ -39,13 +39,13 @@ class DashboardAudioNotificationHelper {
}; };
} }
setInstanceValues({ setInstanceValues = ({
currentUser, currentUser,
alwaysPlayAudioAlert, alwaysPlayAudioAlert,
alertIfUnreadConversationExist, alertIfUnreadConversationExist,
audioAlertType, audioAlertType,
audioAlertTone, audioAlertTone,
}) { }) => {
this.audioAlertType = audioAlertType; this.audioAlertType = audioAlertType;
this.playAlertOnlyWhenHidden = !alwaysPlayAudioAlert; this.playAlertOnlyWhenHidden = !alwaysPlayAudioAlert;
this.alertIfUnreadConversationExist = alertIfUnreadConversationExist; this.alertIfUnreadConversationExist = alertIfUnreadConversationExist;
@@ -58,9 +58,9 @@ class DashboardAudioNotificationHelper {
}); });
}); });
initFaviconSwitcher(); initFaviconSwitcher();
} };
executeRecurringNotification() { executeRecurringNotification = () => {
if (!window.WOOT_STORE) { if (!window.WOOT_STORE) {
this.clearSetTimeout(); this.clearSetTimeout();
return; return;
@@ -81,9 +81,9 @@ class DashboardAudioNotificationHelper {
showBadgeOnFavicon(); showBadgeOnFavicon();
} }
this.clearSetTimeout(); this.clearSetTimeout();
} };
clearSetTimeout() { clearSetTimeout = () => {
if (this.recurringNotificationTimer) { if (this.recurringNotificationTimer) {
clearTimeout(this.recurringNotificationTimer); clearTimeout(this.recurringNotificationTimer);
} }
@@ -91,9 +91,9 @@ class DashboardAudioNotificationHelper {
this.executeRecurringNotification, this.executeRecurringNotification,
NOTIFICATION_TIME NOTIFICATION_TIME
); );
} };
playAudioEvery30Seconds() { playAudioEvery30Seconds = () => {
// Audio alert is disabled dismiss the timer // Audio alert is disabled dismiss the timer
if (this.audioAlertType === 'none') { if (this.audioAlertType === 'none') {
return; return;
@@ -104,25 +104,25 @@ class DashboardAudioNotificationHelper {
} }
this.clearSetTimeout(); this.clearSetTimeout();
} };
isConversationAssignedToCurrentUser(message) { isConversationAssignedToCurrentUser = message => {
const conversationAssigneeId = message?.conversation?.assignee_id; const conversationAssigneeId = message?.conversation?.assignee_id;
return conversationAssigneeId === this.currentUserId; return conversationAssigneeId === this.currentUserId;
} };
// eslint-disable-next-line class-methods-use-this // eslint-disable-next-line class-methods-use-this
isMessageFromCurrentConversation(message) { isMessageFromCurrentConversation = message => {
return ( return (
window.WOOT_STORE.getters.getSelectedChat?.id === message.conversation_id window.WOOT_STORE.getters.getSelectedChat?.id === message.conversation_id
); );
} };
isMessageFromCurrentUser(message) { isMessageFromCurrentUser = message => {
return message?.sender_id === this.currentUserId; return message?.sender_id === this.currentUserId;
} };
isUserHasConversationPermission() { isUserHasConversationPermission = () => {
const currentAccountId = window.WOOT_STORE.getters.getCurrentAccountId; const currentAccountId = window.WOOT_STORE.getters.getCurrentAccountId;
// Get the user permissions for the current account // Get the user permissions for the current account
const userPermissions = getUserPermissions( const userPermissions = getUserPermissions(
@@ -134,16 +134,16 @@ class DashboardAudioNotificationHelper {
permission => userPermissions.includes(permission) permission => userPermissions.includes(permission)
); );
return hasRequiredPermission; return hasRequiredPermission;
} };
shouldNotifyOnMessage(message) { shouldNotifyOnMessage = message => {
if (this.audioAlertType === 'mine') { if (this.audioAlertType === 'mine') {
return this.isConversationAssignedToCurrentUser(message); return this.isConversationAssignedToCurrentUser(message);
} }
return this.audioAlertType === 'all'; return this.audioAlertType === 'all';
} };
onNewMessage(message) { onNewMessage = message => {
// If the user does not have the permission to view the conversation, then dismiss the alert // If the user does not have the permission to view the conversation, then dismiss the alert
if (!this.isUserHasConversationPermission()) { if (!this.isUserHasConversationPermission()) {
return; return;
@@ -176,7 +176,7 @@ class DashboardAudioNotificationHelper {
window.playAudioAlert(); window.playAudioAlert();
showBadgeOnFavicon(); showBadgeOnFavicon();
this.playAudioEvery30Seconds(); this.playAudioEvery30Seconds();
} };
} }
const notifHelper = new DashboardAudioNotificationHelper(); const notifHelper = new DashboardAudioNotificationHelper();