fix(settings): do not use non-set localStorage values (#4299)

If a value is not set in localStorage then null is
returned. null should not be converted to an empty
string (via _.escape) because that will then be
stored in localStorage as the user set preference
and will keep overriding any other values set
in localStorage for the displayname.
This commit is contained in:
virtuacoplenny 2019-06-04 17:42:48 -07:00 committed by GitHub
parent de60a70daf
commit eb644987ce
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 14 additions and 4 deletions

View File

@ -119,12 +119,22 @@ function _initSettings(featureState) {
let settings = featureState; let settings = featureState;
// Old Settings.js values // Old Settings.js values
// FIXME: Let's remove this after a predefined time (e.g. by July 2018) to // FIXME: jibri uses old settings.js local storage values to set its display
// avoid garbage in the source. // name and email. Provide another way for jibri to set these values, update
const displayName = _.escape(window.localStorage.getItem('displayname')); // jibri, and remove the old settings.js values.
const email = _.escape(window.localStorage.getItem('email')); const savedDisplayName = window.localStorage.getItem('displayname');
const savedEmail = window.localStorage.getItem('email');
let avatarID = _.escape(window.localStorage.getItem('avatarId')); let avatarID = _.escape(window.localStorage.getItem('avatarId'));
// The helper _.escape will convert null to an empty strings. The empty
// string will be saved in settings. On app re-load, because an empty string
// is a defined value, it will override any value found in local storage.
// The workaround is sidestepping _.escape when the value is not set in
// local storage.
const displayName
= savedDisplayName === null ? undefined : _.escape(savedDisplayName);
const email = savedEmail === null ? undefined : _.escape(savedEmail);
if (!avatarID) { if (!avatarID) {
// if there is no avatar id, we generate a unique one and use it forever // if there is no avatar id, we generate a unique one and use it forever
avatarID = randomHexString(32); avatarID = randomHexString(32);