Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactored code to remove Sonar Cloud Warning about function nesting. #8

Merged
merged 6 commits into from
Nov 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file modified .husky/commit-msg
100755 → 100644
Empty file.
Empty file modified .husky/pre-commit
100755 → 100644
Empty file.
Binary file added dump.rdb
Binary file not shown.
Empty file modified install/docker/entrypoint.sh
100755 → 100644
Empty file.
Empty file modified nodebb
100755 → 100644
Empty file.
54 changes: 37 additions & 17 deletions public/src/admin/admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,35 +12,55 @@ app.onDomReady();
(function () {
let logoutTimer = 0;
let logoutMessage;
function startLogoutTimer() {
if (app.config.adminReloginDuration <= 0) {
return;
}
if (logoutTimer) {
clearTimeout(logoutTimer);
}
// pre-translate language string gh#9046
if (!logoutMessage) {
require(['translator'], function (translator) {
translator.translate('[[login:logged-out-due-to-inactivity]]', function (translated) {

// Separate the translation logic into a function that returns a promise
function translateMessage(callback) {
require(['translator'], function (translator) {
translator.translate('[[login:logged-out-due-to-inactivity]]', callback);
});
}
// Separate function to generate the logout message
function getLogoutMessage() {
return new Promise((resolve) => {
if (logoutMessage) {
resolve(logoutMessage);
} else {
translateMessage((translated) => {
logoutMessage = translated;
resolve(logoutMessage);
});
});
}

logoutTimer = setTimeout(function () {
}
});
}
// Separate the bootbox logic into its own function
function showLogoutAlert() {
getLogoutMessage().then((message) => {
require(['bootbox'], function (bootbox) {
bootbox.alert({
closeButton: false,
message: logoutMessage,
message: message,
callback: function () {
window.location.reload();
},
});
});
}, 3600000);
});
}

// Logout timer start logic
function startLogoutTimer() {
if (app.config.adminReloginDuration <= 0) {
return;
}

if (logoutTimer) {
clearTimeout(logoutTimer);
}

logoutTimer = setTimeout(() => {
showLogoutAlert();
}, 3600000);
}
require(['hooks', 'admin/settings'], (hooks, Settings) => {
hooks.on('action:ajaxify.end', (data) => {
updatePageTitle(data.url);
Expand Down