diff --git a/app/channel-settings-mail-messages/client/views/mailMessagesInstructions.js b/app/channel-settings-mail-messages/client/views/mailMessagesInstructions.js index a141dc7bc5af..71d0345a10f6 100644 --- a/app/channel-settings-mail-messages/client/views/mailMessagesInstructions.js +++ b/app/channel-settings-mail-messages/client/views/mailMessagesInstructions.js @@ -129,7 +129,7 @@ Template.mailMessagesInstructions.events({ to_emails: selectedEmails.get().map((email) => email.text).toString(), subject, messages: selectedMessages.get(), - language: localStorage.getItem('userLanguage'), + language: Meteor._localStorage.getItem('userLanguage'), }; Meteor.call('mailMessages', data, function(err, result) { diff --git a/app/e2e/client/accountEncryption.js b/app/e2e/client/accountEncryption.js index da1071b15c36..e05ac493fba8 100644 --- a/app/e2e/client/accountEncryption.js +++ b/app/e2e/client/accountEncryption.js @@ -1,4 +1,5 @@ import { Template } from 'meteor/templating'; +import { Meteor } from 'meteor/meteor'; import { ReactiveVar } from 'meteor/reactive-var'; import toastr from 'toastr'; import s from 'underscore.string'; @@ -12,7 +13,7 @@ Template.accountEncryption.helpers({ return settings.get('E2E_Enable'); }, allowKeyChange() { - return localStorage.getItem('public_key') && localStorage.getItem('private_key'); + return Meteor._localStorage.getItem('public_key') && Meteor._localStorage.getItem('private_key'); }, canConfirmNewKey() { const encryptionKey = Template.instance().encryptionKey.get(); diff --git a/app/e2e/client/rocketchat.e2e.js b/app/e2e/client/rocketchat.e2e.js index 536d1b5a495f..16d39f6c3ee6 100644 --- a/app/e2e/client/rocketchat.e2e.js +++ b/app/e2e/client/rocketchat.e2e.js @@ -104,8 +104,8 @@ class E2E { } this.started = true; - let public_key = localStorage.getItem('public_key'); - let private_key = localStorage.getItem('private_key'); + let public_key = Meteor._localStorage.getItem('public_key'); + let private_key = Meteor._localStorage.getItem('private_key'); await this.loadKeysFromDB(); @@ -143,12 +143,12 @@ class E2E { // TODO: Split in 2 methods to persist keys if (!this.db_public_key || !this.db_private_key) { await call('e2e.setUserPublicAndPivateKeys', { - public_key: localStorage.getItem('public_key'), - private_key: await this.encodePrivateKey(localStorage.getItem('private_key'), this.createRandomPassword()), + public_key: Meteor._localStorage.getItem('public_key'), + private_key: await this.encodePrivateKey(Meteor._localStorage.getItem('private_key'), this.createRandomPassword()), }); } - const randomPassword = localStorage.getItem('e2e.randomPassword'); + const randomPassword = Meteor._localStorage.getItem('e2e.randomPassword'); if (randomPassword) { const passwordRevealText = TAPi18n.__('E2E_password_reveal_text', { postProcess: 'sprintf', @@ -174,7 +174,7 @@ class E2E { if (!confirm) { return; } - localStorage.removeItem('e2e.randomPassword'); + Meteor._localStorage.removeItem('e2e.randomPassword'); this.closeAlert(); }); }, @@ -196,8 +196,8 @@ class E2E { alerts.close(); } - localStorage.removeItem('public_key'); - localStorage.removeItem('private_key'); + Meteor._localStorage.removeItem('public_key'); + Meteor._localStorage.removeItem('private_key'); this.instancesByRoomId = {}; this.privateKey = null; this.enabled.set(false); @@ -233,12 +233,12 @@ class E2E { async changePassword(newPassword) { await call('e2e.setUserPublicAndPivateKeys', { - public_key: localStorage.getItem('public_key'), - private_key: await this.encodePrivateKey(localStorage.getItem('private_key'), newPassword), + public_key: Meteor._localStorage.getItem('public_key'), + private_key: await this.encodePrivateKey(Meteor._localStorage.getItem('private_key'), newPassword), }); - if (localStorage.getItem('e2e.randomPassword')) { - localStorage.setItem('e2e.randomPassword', newPassword); + if (Meteor._localStorage.getItem('e2e.randomPassword')) { + Meteor._localStorage.setItem('e2e.randomPassword', newPassword); } } @@ -254,12 +254,12 @@ class E2E { } async loadKeys({ public_key, private_key }) { - localStorage.setItem('public_key', public_key); + Meteor._localStorage.setItem('public_key', public_key); try { this.privateKey = await importRSAKey(EJSON.parse(private_key), ['decrypt']); - localStorage.setItem('private_key', private_key); + Meteor._localStorage.setItem('private_key', private_key); } catch (error) { return console.error('E2E -> Error importing private key: ', error); } @@ -278,7 +278,7 @@ class E2E { try { const publicKey = await exportJWKKey(key.publicKey); - localStorage.setItem('public_key', JSON.stringify(publicKey)); + Meteor._localStorage.setItem('public_key', JSON.stringify(publicKey)); } catch (error) { return console.error('E2E -> Error exporting public key: ', error); } @@ -286,7 +286,7 @@ class E2E { try { const privateKey = await exportJWKKey(key.privateKey); - localStorage.setItem('private_key', JSON.stringify(privateKey)); + Meteor._localStorage.setItem('private_key', JSON.stringify(privateKey)); } catch (error) { return console.error('E2E -> Error exporting private key: ', error); } @@ -300,7 +300,7 @@ class E2E { createRandomPassword() { const randomPassword = `${ Random.id(3) }-${ Random.id(3) }-${ Random.id(3) }`.toLowerCase(); - localStorage.setItem('e2e.randomPassword', randomPassword); + Meteor._localStorage.setItem('e2e.randomPassword', randomPassword); return randomPassword; } diff --git a/app/emoji/client/lib/EmojiPicker.js b/app/emoji/client/lib/EmojiPicker.js index 22de1609825f..c46226adc6d0 100644 --- a/app/emoji/client/lib/EmojiPicker.js +++ b/app/emoji/client/lib/EmojiPicker.js @@ -1,5 +1,6 @@ import _ from 'underscore'; import { Blaze } from 'meteor/blaze'; +import { Meteor } from 'meteor/meteor'; import { Template } from 'meteor/templating'; import { ReactiveVar } from 'meteor/reactive-var'; import { Tracker } from 'meteor/tracker'; @@ -27,8 +28,8 @@ export const EmojiPicker = { } this.initiated = true; - this.recent = window.localStorage.getItem('emoji.recent') ? window.localStorage.getItem('emoji.recent').split(',') : []; - this.tone = window.localStorage.getItem('emoji.tone') || 0; + this.recent = Meteor._localStorage.getItem('emoji.recent') ? Meteor._localStorage.getItem('emoji.recent').split(',') : []; + this.tone = Meteor._localStorage.getItem('emoji.tone') || 0; Blaze.render(Template.emojiPicker, document.body); @@ -55,7 +56,7 @@ export const EmojiPicker = { }, setTone(tone) { this.tone = tone; - window.localStorage.setItem('emoji.tone', tone); + Meteor._localStorage.setItem('emoji.tone', tone); }, getTone() { return this.tone; @@ -130,7 +131,7 @@ export const EmojiPicker = { updatePositions = true; - window.localStorage.setItem('emoji.recent', this.recent); + Meteor._localStorage.setItem('emoji.recent', this.recent); emoji.packages.base.emojisByCategory.recent = this.recent; this.updateRecent('recent'); }, @@ -140,7 +141,7 @@ export const EmojiPicker = { return; } this.recent.splice(pos, 1); - window.localStorage.setItem('emoji.recent', this.recent); + Meteor._localStorage.setItem('emoji.recent', this.recent); }, updateRecent(category) { updateRecentEmoji(category); diff --git a/app/oauth2-server-config/client/oauth/oauth2-client.js b/app/oauth2-server-config/client/oauth/oauth2-client.js index c763233e57e7..7dc011b3e802 100644 --- a/app/oauth2-server-config/client/oauth/oauth2-client.js +++ b/app/oauth2-server-config/client/oauth/oauth2-client.js @@ -36,7 +36,7 @@ Template.authorize.onCreated(function() { Template.authorize.helpers({ getToken() { - return localStorage.getItem(Accounts.LOGIN_TOKEN_KEY); + return Meteor._localStorage.getItem(Accounts.LOGIN_TOKEN_KEY); }, getClient() { return ChatOAuthApps.findOne(); diff --git a/app/setup-wizard/client/final.js b/app/setup-wizard/client/final.js index 24dacde539be..69acd1334d11 100644 --- a/app/setup-wizard/client/final.js +++ b/app/setup-wizard/client/final.js @@ -7,7 +7,7 @@ import { Users } from '../../models'; import { hasRole } from '../../authorization'; Template.setupWizardFinal.onCreated(function() { - const isSetupWizardDone = localStorage.getItem('wizardFinal'); + const isSetupWizardDone = Meteor._localStorage.getItem('wizardFinal'); if (isSetupWizardDone === null) { FlowRouter.go('setup-wizard'); } @@ -44,8 +44,8 @@ Template.setupWizardFinal.onRendered(function() { Template.setupWizardFinal.events({ 'click .js-finish'() { settings.set('Show_Setup_Wizard', 'completed', function() { - localStorage.removeItem('wizard'); - localStorage.removeItem('wizardFinal'); + Meteor._localStorage.removeItem('wizard'); + Meteor._localStorage.removeItem('wizardFinal'); FlowRouter.go('home'); }); }, diff --git a/app/setup-wizard/client/setupWizard.js b/app/setup-wizard/client/setupWizard.js index 093c0925c577..ac98f6b23808 100644 --- a/app/setup-wizard/client/setupWizard.js +++ b/app/setup-wizard/client/setupWizard.js @@ -112,11 +112,11 @@ Template.setupWizard.onCreated(async function() { this.wizardSettings = new ReactiveVar([]); this.allowStandaloneServer = new ReactiveVar(false); - if (localStorage.getItem('wizardFinal')) { + if (Meteor._localStorage.getItem('wizardFinal')) { return FlowRouter.go('setup-wizard-final'); } - const jsonString = localStorage.getItem('wizard'); + const jsonString = Meteor._localStorage.getItem('wizard'); const state = (jsonString && JSON.parse(jsonString)) || statusDefault; this.state.set(state); @@ -132,7 +132,7 @@ Template.setupWizard.onCreated(async function() { this.autorun(() => { const state = this.state.all(); state['registration-pass'] = ''; - localStorage.setItem('wizard', JSON.stringify(state)); + Meteor._localStorage.setItem('wizard', JSON.stringify(state)); }); this.autorun(async (c) => { @@ -196,8 +196,8 @@ Template.setupWizard.events({ } case 4: { persistSettings(t.state.all(), () => { - localStorage.removeItem('wizard'); - localStorage.setItem('wizardFinal', true); + Meteor._localStorage.removeItem('wizard'); + Meteor._localStorage.setItem('wizardFinal', true); if (t.state.get('registerServer')) { Meteor.call('cloud:registerWorkspace', (error) => { diff --git a/app/ui-account/client/accountPreferences.js b/app/ui-account/client/accountPreferences.js index 6dc1b0220c09..0a877b25f6c5 100644 --- a/app/ui-account/client/accountPreferences.js +++ b/app/ui-account/client/accountPreferences.js @@ -138,11 +138,11 @@ Template.accountPreferences.onCreated(function() { }); this.clearForm = function() { - this.find('#language').value = localStorage.getItem('userLanguage'); + this.find('#language').value = Meteor._localStorage.getItem('userLanguage'); }; this.shouldUpdateLocalStorageSetting = function(setting, newValue) { - return localStorage.getItem(setting) !== newValue; + return Meteor._localStorage.getItem(setting) !== newValue; }; this.save = function() { @@ -190,7 +190,7 @@ Template.accountPreferences.onCreated(function() { const selectedLanguage = $('#language').val(); if (this.shouldUpdateLocalStorageSetting('userLanguage', selectedLanguage)) { - localStorage.setItem('userLanguage', selectedLanguage); + Meteor._localStorage.setItem('userLanguage', selectedLanguage); data.language = selectedLanguage; reload = true; } @@ -198,14 +198,14 @@ Template.accountPreferences.onCreated(function() { const enableAutoAway = JSON.parse($('#enableAutoAway').find('input:checked').val()); data.enableAutoAway = enableAutoAway; if (this.shouldUpdateLocalStorageSetting('enableAutoAway', enableAutoAway)) { - localStorage.setItem('enableAutoAway', enableAutoAway); + Meteor._localStorage.setItem('enableAutoAway', enableAutoAway); reload = true; } const idleTimeLimit = $('input[name=idleTimeLimit]').val() === '' ? settings.get('Accounts_Default_User_Preferences_idleTimeLimit') : parseInt($('input[name=idleTimeLimit]').val()); data.idleTimeLimit = idleTimeLimit; if (this.shouldUpdateLocalStorageSetting('idleTimeLimit', idleTimeLimit)) { - localStorage.setItem('idleTimeLimit', idleTimeLimit); + Meteor._localStorage.setItem('idleTimeLimit', idleTimeLimit); reload = true; } diff --git a/app/ui-login/client/login/footer.js b/app/ui-login/client/login/footer.js index 89eb5c4d4a38..84001103b262 100644 --- a/app/ui-login/client/login/footer.js +++ b/app/ui-login/client/login/footer.js @@ -1,4 +1,5 @@ import { ReactiveVar } from 'meteor/reactive-var'; +import { Meteor } from 'meteor/meteor'; import { Template } from 'meteor/templating'; import { TAPi18n } from 'meteor/rocketchat:tap-i18n'; @@ -22,7 +23,7 @@ Template.loginFooter.onCreated(function() { } }; - const currentLanguage = localStorage.getItem('userLanguage'); + const currentLanguage = Meteor._localStorage.getItem('userLanguage'); this.suggestAnotherLanguageFor(currentLanguage); }); diff --git a/app/ui-master/server/inject.js b/app/ui-master/server/inject.js index b0d528fdc630..8b0e6b4c45fb 100644 --- a/app/ui-master/server/inject.js +++ b/app/ui-master/server/inject.js @@ -170,13 +170,19 @@ settings.get('Accounts_ForgetUserSessionOnWindowClose', (key, value) => { if (value) { Inject.rawModHtml(key, (html) => { const script = ` - + `; - return html.replace(/<\/body>/, `${ script }\n`); + return html + script; }); } else { Inject.rawModHtml(key, (html) => html); diff --git a/app/ui-utils/client/config.js b/app/ui-utils/client/config.js index 195b1b7db8e0..996c37ebeabb 100644 --- a/app/ui-utils/client/config.js +++ b/app/ui-utils/client/config.js @@ -1,6 +1,8 @@ +import { Meteor } from 'meteor/meteor'; + const url = new URL(window.location); const keys = new Set(); export const getConfig = (key) => { keys.add(key); - return url.searchParams.get(key) || localStorage.getItem(`rc-config-${ key }`); + return url.searchParams.get(key) || Meteor._localStorage.getItem(`rc-config-${ key }`); }; diff --git a/app/ui-utils/client/lib/menu.js b/app/ui-utils/client/lib/menu.js index 068dc28e7be2..320faaa86d3c 100644 --- a/app/ui-utils/client/lib/menu.js +++ b/app/ui-utils/client/lib/menu.js @@ -1,4 +1,5 @@ import { Session } from 'meteor/session'; +import { Meteor } from 'meteor/meteor'; import _ from 'underscore'; import EventEmitter from 'wolfy87-eventemitter'; @@ -42,7 +43,7 @@ export const menu = new class extends EventEmitter { } get isRtl() { - return isRtl(localStorage.getItem('userLanguage')); + return isRtl(Meteor._localStorage.getItem('userLanguage')); } touchstart(e) { diff --git a/app/ui-utils/lib/Message.js b/app/ui-utils/lib/Message.js index 7d6a2026e11f..cd4cd79a1e01 100644 --- a/app/ui-utils/lib/Message.js +++ b/app/ui-utils/lib/Message.js @@ -1,4 +1,5 @@ import { TAPi18n } from 'meteor/rocketchat:tap-i18n'; +import { Meteor } from 'meteor/meteor'; import s from 'underscore.string'; import { MessageTypes } from './MessageTypes'; @@ -14,8 +15,8 @@ export const Message = { // Render message return; } if (messageType.message) { - if (!language && typeof localStorage !== 'undefined') { - language = localStorage.getItem('userLanguage'); + if (!language) { + language = Meteor._localStorage.getItem('userLanguage'); } const data = (typeof messageType.data === 'function' && messageType.data(msg)) || {}; return TAPi18n.__(messageType.message, data, language); diff --git a/app/ui/client/lib/chatMessages.js b/app/ui/client/lib/chatMessages.js index 55beeb34927e..ecc7f6b80fa4 100644 --- a/app/ui/client/lib/chatMessages.js +++ b/app/ui/client/lib/chatMessages.js @@ -32,12 +32,12 @@ import { emoji } from '../../../emoji/client'; const messageBoxState = { saveValue: _.debounce(({ rid, tmid }, value) => { const key = ['messagebox', rid, tmid].filter(Boolean).join('_'); - value ? localStorage.setItem(key, value) : localStorage.removeItem(key); + value ? Meteor._localStorage.setItem(key, value) : Meteor._localStorage.removeItem(key); }, 1000), restoreValue: ({ rid, tmid }) => { const key = ['messagebox', rid, tmid].filter(Boolean).join('_'); - return localStorage.getItem(key); + return Meteor._localStorage.getItem(key); }, restore: ({ rid, tmid }, input) => { @@ -57,9 +57,9 @@ const messageBoxState = { }, purgeAll: () => { - Object.keys(localStorage) + Object.keys(Meteor._localStorage) .filter((key) => key.indexOf('messagebox_') === 0) - .forEach((key) => localStorage.removeItem(key)); + .forEach((key) => Meteor._localStorage.removeItem(key)); }, }; diff --git a/app/utils/client/lib/RestApiClient.js b/app/utils/client/lib/RestApiClient.js index 43dcb68041fc..7d0a30f1bfe4 100644 --- a/app/utils/client/lib/RestApiClient.js +++ b/app/utils/client/lib/RestApiClient.js @@ -1,3 +1,4 @@ +import { Meteor } from 'meteor/meteor'; import { Accounts } from 'meteor/accounts-base'; export const APIClient = { @@ -49,8 +50,8 @@ export const APIClient = { url: `${ document.baseURI }api/${ endpoint }${ query }`, headers: { 'Content-Type': 'application/json', - 'X-User-Id': localStorage[Accounts.USER_ID_KEY], - 'X-Auth-Token': localStorage[Accounts.LOGIN_TOKEN_KEY], + 'X-User-Id': Meteor._localStorage.getItem(Accounts.USER_ID_KEY), + 'X-Auth-Token': Meteor._localStorage.getItem(Accounts.LOGIN_TOKEN_KEY), }, data: JSON.stringify(body), success: function _rlGetSuccess(result) { @@ -76,8 +77,8 @@ export const APIClient = { jQuery.ajax({ url: `${ document.baseURI }api/${ endpoint }${ query }`, headers: { - 'X-User-Id': localStorage[Accounts.USER_ID_KEY], - 'X-Auth-Token': localStorage[Accounts.LOGIN_TOKEN_KEY], + 'X-User-Id': Meteor._localStorage.getItem(Accounts.USER_ID_KEY), + 'X-Auth-Token': Meteor._localStorage.getItem(Accounts.LOGIN_TOKEN_KEY), }, data: formData, processData: false, diff --git a/app/utils/lib/tapi18n.js b/app/utils/lib/tapi18n.js index c4dcf13aec6b..f8e1d3da66d6 100644 --- a/app/utils/lib/tapi18n.js +++ b/app/utils/lib/tapi18n.js @@ -1,5 +1,6 @@ import _ from 'underscore'; import { TAPi18n } from 'meteor/rocketchat:tap-i18n'; +import { Meteor } from 'meteor/meteor'; export const t = function(key, ...replaces) { if (_.isObject(replaces[0])) { @@ -12,6 +13,6 @@ export const t = function(key, ...replaces) { }; export const isRtl = (lang) => { - const language = lang || localStorage.getItem('userLanguage') || 'en-US'; + const language = lang || Meteor._localStorage.getItem('userLanguage') || 'en-US'; return ['ar', 'dv', 'fa', 'he', 'ku', 'ps', 'sd', 'ug', 'ur', 'yi'].includes(language.split('-').shift().toLowerCase()); }; diff --git a/client/startup/i18n.js b/client/startup/i18n.js index 9352a62f718b..72b9f3ee99c3 100644 --- a/client/startup/i18n.js +++ b/client/startup/i18n.js @@ -12,7 +12,7 @@ const currentLanguage = new ReactiveVar(); Meteor.startup(() => { TAPi18n.conf.i18n_files_route = Meteor._relativeToSiteRootUrl('/tap-i18n'); - currentLanguage.set(localStorage.getItem('userLanguage')); + currentLanguage.set(Meteor._localStorage.getItem('userLanguage')); const availableLanguages = TAPi18n.getLanguages(); @@ -70,7 +70,7 @@ Meteor.startup(() => { const setLanguage = (language) => { const lang = filterLanguage(language); currentLanguage.set(lang); - localStorage.setItem('userLanguage', lang); + Meteor._localStorage.setItem('userLanguage', lang); }; window.setLanguage = setLanguage;