Skip to content
This repository was archived by the owner on Sep 11, 2024. It is now read-only.

Commit 989e994

Browse files
committed
Merge remote-tracking branch 'origin/develop' into develop
2 parents 3ffa3d8 + 3c02b70 commit 989e994

File tree

4 files changed

+44
-26
lines changed

4 files changed

+44
-26
lines changed

src/Lifecycle.js

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ function _handleRestoreFailure(e) {
237237
+ ' This is a once off; sorry for the inconvenience.',
238238
);
239239

240-
_clearLocalStorage();
240+
_clearStorage();
241241

242242
return q.reject(new Error(
243243
_t('Unable to restore previous session') + ': ' + msg,
@@ -258,7 +258,7 @@ function _handleRestoreFailure(e) {
258258
return def.promise.then((success) => {
259259
if (success) {
260260
// user clicked continue.
261-
_clearLocalStorage();
261+
_clearStorage();
262262
return false;
263263
}
264264

@@ -332,6 +332,10 @@ export function setLoggedIn(credentials) {
332332
}
333333

334334
// stop any running clients before we create a new one with these new credentials
335+
//
336+
// XXX: why do we have any running clients here? Maybe on sign-in after
337+
// initial use as a guest? but what about our persistent storage? we need to
338+
// be careful not to leak e2e data created as one user into another session.
335339
stopMatrixClient();
336340

337341
MatrixClientPeg.replaceUsingCreds(credentials);
@@ -402,13 +406,19 @@ export function startMatrixClient() {
402406
* a session has been logged out / ended.
403407
*/
404408
export function onLoggedOut() {
405-
_clearLocalStorage();
406-
stopMatrixClient();
409+
stopMatrixClient(true);
407410
dis.dispatch({action: 'on_logged_out'});
408411
}
409412

410-
function _clearLocalStorage() {
413+
function _clearStorage() {
411414
Analytics.logout();
415+
416+
const cli = MatrixClientPeg.get();
417+
if (cli) {
418+
// TODO: *really* ought to wait for the promise to complete
419+
cli.clearStores().done();
420+
}
421+
412422
if (!window.localStorage) {
413423
return;
414424
}
@@ -425,9 +435,13 @@ function _clearLocalStorage() {
425435
}
426436

427437
/**
428-
* Stop all the background processes related to the current client
438+
* Stop all the background processes related to the current client.
439+
*
440+
* Optionally clears persistent stores.
441+
*
442+
* @param {boolean} clearStores true to clear the persistent stores.
429443
*/
430-
export function stopMatrixClient() {
444+
export function stopMatrixClient(clearStores) {
431445
Notifier.stop();
432446
UserActivity.stop();
433447
Presence.stop();
@@ -436,7 +450,13 @@ export function stopMatrixClient() {
436450
if (cli) {
437451
cli.stopClient();
438452
cli.removeAllListeners();
439-
cli.store.deleteAllData();
440-
MatrixClientPeg.unset();
441453
}
454+
455+
if (clearStores) {
456+
// note that we have to do this *after* stopping the client, but
457+
// *before* clearing the MatrixClientPeg.
458+
_clearStorage();
459+
}
460+
461+
MatrixClientPeg.unset();
442462
}

src/components/structures/MatrixChat.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ module.exports = React.createClass({
292292
},
293293

294294
componentWillUnmount: function() {
295-
Lifecycle.stopMatrixClient();
295+
Lifecycle.stopMatrixClient(false);
296296
dis.unregister(this.dispatcherRef);
297297
UDEHandler.stopListening();
298298
window.removeEventListener("focus", this.onFocus);
@@ -364,7 +364,7 @@ module.exports = React.createClass({
364364
// is completed in another browser, we'll be 401ed for using
365365
// a guest access token for a non-guest account.
366366
// It will be restarted in onReturnToGuestClick
367-
Lifecycle.stopMatrixClient();
367+
Lifecycle.stopMatrixClient(false);
368368

369369
this.notifyNewScreen('register');
370370
break;

src/components/views/elements/LanguageDropdown.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,14 @@ export default class LanguageDropdown extends React.Component {
4040
}
4141

4242
componentWillMount() {
43-
languageHandler.getAllLanguagesFromJson().then((langs) => {
43+
languageHandler.getAllLanguageKeysFromJson().then((langKeys) => {
44+
const langs = [];
45+
langKeys.forEach((languageKey) => {
46+
langs.push({
47+
value: languageKey,
48+
label: _t(languageKey)
49+
});
50+
});
4451
langs.sort(function(a, b){
4552
if(a.label < b.label) return -1;
4653
if(a.label > b.label) return 1;

src/languageHandler.js

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ export function setLanguage(preferredLangs) {
133133
throw new Error("Unable to find an appropriate language");
134134
}
135135

136-
return getLanguage(i18nFolder + availLangs[langToUse].fileName);
136+
return getLanguage(i18nFolder + availLangs[langToUse]);
137137
}).then((langData) => {
138138
counterpart.registerTranslations(langToUse, langData);
139139
counterpart.setLocale(langToUse);
@@ -142,25 +142,16 @@ export function setLanguage(preferredLangs) {
142142

143143
// Set 'en' as fallback language:
144144
if (langToUse != "en") {
145-
return getLanguage(i18nFolder + availLangs['en'].fileName);
145+
return getLanguage(i18nFolder + availLangs['en']);
146146
}
147147
}).then((langData) => {
148148
if (langData) counterpart.registerTranslations('en', langData);
149149
});
150150
};
151151

152-
export function getAllLanguagesFromJson() {
153-
return getLangsJson().then((langsObject) => {
154-
var langs = [];
155-
for (var langKey in langsObject) {
156-
if (langsObject.hasOwnProperty(langKey)) {
157-
langs.push({
158-
'value': langKey,
159-
'label': langsObject[langKey].label
160-
});
161-
}
162-
}
163-
return langs;
152+
export function getAllLanguageKeysFromJson() {
153+
return getLangsJson().then((langs) => {
154+
return Object.keys(langs);
164155
});
165156
}
166157

0 commit comments

Comments
 (0)