mirror of
https://github.com/mattermost/mattermost.git
synced 2025-02-25 18:55:24 -06:00
fix bugs for pr #150 MM-895
This commit is contained in:
@@ -12,8 +12,6 @@ var Constants = require('../utils/constants.jsx');
|
|||||||
|
|
||||||
module.exports = React.createClass({
|
module.exports = React.createClass({
|
||||||
componentDidMount: function() {
|
componentDidMount: function() {
|
||||||
// Initalize stores
|
|
||||||
BrowserStore.initalize();
|
|
||||||
|
|
||||||
/* Start initial aysnc loads */
|
/* Start initial aysnc loads */
|
||||||
AsyncClient.getMe();
|
AsyncClient.getMe();
|
||||||
|
|||||||
@@ -1,44 +1,52 @@
|
|||||||
// Copyright (c) 2015 Spinpunch, Inc. All Rights Reserved.
|
// Copyright (c) 2015 Spinpunch, Inc. All Rights Reserved.
|
||||||
// See License.txt for license information.
|
// See License.txt for license information.
|
||||||
|
|
||||||
var UserStore = require('../stores/user_store.jsx');
|
var UserStore = require('../stores/user_store.jsx');
|
||||||
|
|
||||||
// Also change model/utils.go ETAG_ROOT_VERSION
|
// Also change model/utils.go ETAG_ROOT_VERSION
|
||||||
var BROWSER_STORE_VERSION = '.1';
|
var BROWSER_STORE_VERSION = '.1';
|
||||||
|
|
||||||
module.exports.initalize = function() {
|
var _initialized = false;
|
||||||
|
|
||||||
|
function _initialize() {
|
||||||
var currentVersion = localStorage.getItem("local_storage_version");
|
var currentVersion = localStorage.getItem("local_storage_version");
|
||||||
if (currentVersion !== BROWSER_STORE_VERSION) {
|
if (currentVersion !== BROWSER_STORE_VERSION) {
|
||||||
localStorage.clear();
|
localStorage.clear();
|
||||||
sessionStorage.clear();
|
sessionStorage.clear();
|
||||||
localStorage.setItem("local_storage_version", BROWSER_STORE_VERSION);
|
localStorage.setItem("local_storage_version", BROWSER_STORE_VERSION);
|
||||||
}
|
}
|
||||||
|
_initialized = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports.setItem = function(name, value) {
|
module.exports.setItem = function(name, value) {
|
||||||
|
if (!_initialized) _initialize();
|
||||||
var user_id = UserStore.getCurrentId();
|
var user_id = UserStore.getCurrentId();
|
||||||
localStorage.setItem(user_id + "_" + name, value);
|
localStorage.setItem(user_id + "_" + name, value);
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports.getItem = function(name) {
|
module.exports.getItem = function(name) {
|
||||||
|
if (!_initialized) _initialize();
|
||||||
var user_id = UserStore.getCurrentId();
|
var user_id = UserStore.getCurrentId();
|
||||||
return localStorage.getItem(user_id + "_" + name);
|
return localStorage.getItem(user_id + "_" + name);
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports.removeItem = function(name) {
|
module.exports.removeItem = function(name) {
|
||||||
|
if (!_initialized) _initialize();
|
||||||
var user_id = UserStore.getCurrentId();
|
var user_id = UserStore.getCurrentId();
|
||||||
localStorage.removeItem(user_id + "_" + name);
|
localStorage.removeItem(user_id + "_" + name);
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports.setGlobalItem = function(name, value) {
|
module.exports.setGlobalItem = function(name, value) {
|
||||||
|
if (!_initialized) _initialize();
|
||||||
localStorage.setItem(name, value);
|
localStorage.setItem(name, value);
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports.getGlobalItem = function(name) {
|
module.exports.getGlobalItem = function(name) {
|
||||||
|
if (!_initialized) _initialize();
|
||||||
return localStorage.getItem(name);
|
return localStorage.getItem(name);
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports.removeGlobalItem = function(name) {
|
module.exports.removeGlobalItem = function(name) {
|
||||||
|
if (!_initialized) _initialize();
|
||||||
localStorage.removeItem(name);
|
localStorage.removeItem(name);
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -53,7 +61,7 @@ module.exports.actionOnItemsWithPrefix = function (prefix, action) {
|
|||||||
var user_id = UserStore.getCurrentId();
|
var user_id = UserStore.getCurrentId();
|
||||||
var id_len = user_id.length;
|
var id_len = user_id.length;
|
||||||
var prefix_len = prefix.length;
|
var prefix_len = prefix.length;
|
||||||
for (key in localStorage) {
|
for (var key in localStorage) {
|
||||||
if (key.substring(id_len, id_len + prefix_len) === prefix) {
|
if (key.substring(id_len, id_len + prefix_len) === prefix) {
|
||||||
var userkey = key.substring(id_len);
|
var userkey = key.substring(id_len);
|
||||||
action(userkey, BrowserStore.getItem(key));
|
action(userkey, BrowserStore.getItem(key));
|
||||||
@@ -70,8 +78,8 @@ module.exports.isLocalStorageSupported = function() {
|
|||||||
localStorage.removeItem("testLocal", '1');
|
localStorage.removeItem("testLocal", '1');
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
catch (e) {
|
catch (e) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
|||||||
@@ -55,7 +55,7 @@ module.exports.getChannels = function(force, updateLastViewed, checkVersion) {
|
|||||||
if (checkVersion) {
|
if (checkVersion) {
|
||||||
var serverVersion = xhr.getResponseHeader("X-Version-ID");
|
var serverVersion = xhr.getResponseHeader("X-Version-ID");
|
||||||
|
|
||||||
if (UserStore.getLastVersion() == undefined) {
|
if (!UserStore.getLastVersion()) {
|
||||||
UserStore.setLastVersion(serverVersion);
|
UserStore.setLastVersion(serverVersion);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user