Merge pull request #836 from t3chguy/fix_UserSettingsStore

Fix user settings store
This commit is contained in:
David Baker 2017-04-26 10:11:32 +01:00 committed by GitHub
commit 78b452818c
3 changed files with 31 additions and 31 deletions

View file

@ -15,9 +15,9 @@ limitations under the License.
*/ */
'use strict'; 'use strict';
var q = require("q"); import q from 'q';
var MatrixClientPeg = require("./MatrixClientPeg"); import MatrixClientPeg from './MatrixClientPeg';
var Notifier = require("./Notifier"); import Notifier from './Notifier';
/* /*
* TODO: Make things use this. This is all WIP - see UserSettings.js for usage. * TODO: Make things use this. This is all WIP - see UserSettings.js for usage.
@ -33,7 +33,7 @@ module.exports = {
], ],
loadProfileInfo: function() { loadProfileInfo: function() {
var cli = MatrixClientPeg.get(); const cli = MatrixClientPeg.get();
return cli.getProfileInfo(cli.credentials.userId); return cli.getProfileInfo(cli.credentials.userId);
}, },
@ -44,7 +44,7 @@ module.exports = {
loadThreePids: function() { loadThreePids: function() {
if (MatrixClientPeg.get().isGuest()) { if (MatrixClientPeg.get().isGuest()) {
return q({ return q({
threepids: [] threepids: [],
}); // guests can't poke 3pid endpoint }); // guests can't poke 3pid endpoint
} }
return MatrixClientPeg.get().getThreePids(); return MatrixClientPeg.get().getThreePids();
@ -73,19 +73,19 @@ module.exports = {
Notifier.setAudioEnabled(enable); Notifier.setAudioEnabled(enable);
}, },
changePassword: function(old_password, new_password) { changePassword: function(oldPassword, newPassword) {
var cli = MatrixClientPeg.get(); const cli = MatrixClientPeg.get();
var authDict = { const authDict = {
type: 'm.login.password', type: 'm.login.password',
user: cli.credentials.userId, user: cli.credentials.userId,
password: old_password password: oldPassword,
}; };
return cli.setPassword(authDict, new_password); return cli.setPassword(authDict, newPassword);
}, },
/** /*
* Returns the email pusher (pusher of type 'email') for a given * Returns the email pusher (pusher of type 'email') for a given
* email address. Email pushers all have the same app ID, so since * email address. Email pushers all have the same app ID, so since
* pushers are unique over (app ID, pushkey), there will be at most * pushers are unique over (app ID, pushkey), there will be at most
@ -95,8 +95,8 @@ module.exports = {
if (pushers === undefined) { if (pushers === undefined) {
return undefined; return undefined;
} }
for (var i = 0; i < pushers.length; ++i) { for (let i = 0; i < pushers.length; ++i) {
if (pushers[i].kind == 'email' && pushers[i].pushkey == address) { if (pushers[i].kind === 'email' && pushers[i].pushkey === address) {
return pushers[i]; return pushers[i];
} }
} }
@ -110,7 +110,7 @@ module.exports = {
addEmailPusher: function(address, data) { addEmailPusher: function(address, data) {
return MatrixClientPeg.get().setPusher({ return MatrixClientPeg.get().setPusher({
kind: 'email', kind: 'email',
app_id: "m.email", app_id: 'm.email',
pushkey: address, pushkey: address,
app_display_name: 'Email Notifications', app_display_name: 'Email Notifications',
device_display_name: address, device_display_name: address,
@ -121,46 +121,46 @@ module.exports = {
}, },
getUrlPreviewsDisabled: function() { getUrlPreviewsDisabled: function() {
var event = MatrixClientPeg.get().getAccountData("org.matrix.preview_urls"); const event = MatrixClientPeg.get().getAccountData('org.matrix.preview_urls');
return (event && event.getContent().disable); return (event && event.getContent().disable);
}, },
setUrlPreviewsDisabled: function(disabled) { setUrlPreviewsDisabled: function(disabled) {
// FIXME: handle errors // FIXME: handle errors
return MatrixClientPeg.get().setAccountData("org.matrix.preview_urls", { return MatrixClientPeg.get().setAccountData('org.matrix.preview_urls', {
disable: disabled disable: disabled,
}); });
}, },
getSyncedSettings: function() { getSyncedSettings: function() {
var event = MatrixClientPeg.get().getAccountData("im.vector.web.settings"); const event = MatrixClientPeg.get().getAccountData('im.vector.web.settings');
return event ? event.getContent() : {}; return event ? event.getContent() : {};
}, },
getSyncedSetting: function(type, defaultValue = null) { getSyncedSetting: function(type, defaultValue = null) {
var settings = this.getSyncedSettings(); const settings = this.getSyncedSettings();
return settings.hasOwnProperty(type) ? settings[type] : null; return settings.hasOwnProperty(type) ? settings[type] : defaultValue;
}, },
setSyncedSetting: function(type, value) { setSyncedSetting: function(type, value) {
var settings = this.getSyncedSettings(); const settings = this.getSyncedSettings();
settings[type] = value; settings[type] = value;
// FIXME: handle errors // FIXME: handle errors
return MatrixClientPeg.get().setAccountData("im.vector.web.settings", settings); return MatrixClientPeg.get().setAccountData('im.vector.web.settings', settings);
}, },
getLocalSettings: function() { getLocalSettings: function() {
var localSettingsString = localStorage.getItem('mx_local_settings') || '{}'; const localSettingsString = localStorage.getItem('mx_local_settings') || '{}';
return JSON.parse(localSettingsString); return JSON.parse(localSettingsString);
}, },
getLocalSetting: function(type, defaultValue = null) { getLocalSetting: function(type, defaultValue = null) {
var settings = this.getLocalSettings(); const settings = this.getLocalSettings();
return settings.hasOwnProperty(type) ? settings[type] : null; return settings.hasOwnProperty(type) ? settings[type] : defaultValue;
}, },
setLocalSetting: function(type, value) { setLocalSetting: function(type, value) {
var settings = this.getLocalSettings(); const settings = this.getLocalSettings();
settings[type] = value; settings[type] = value;
// FIXME: handle errors // FIXME: handle errors
localStorage.setItem('mx_local_settings', JSON.stringify(settings)); localStorage.setItem('mx_local_settings', JSON.stringify(settings));
@ -171,8 +171,8 @@ module.exports = {
if (MatrixClientPeg.get().isGuest()) return false; if (MatrixClientPeg.get().isGuest()) return false;
if (localStorage.getItem(`mx_labs_feature_${feature}`) === null) { if (localStorage.getItem(`mx_labs_feature_${feature}`) === null) {
for (var i = 0; i < this.LABS_FEATURES.length; i++) { for (let i = 0; i < this.LABS_FEATURES.length; i++) {
var f = this.LABS_FEATURES[i]; const f = this.LABS_FEATURES[i];
if (f.id === feature) { if (f.id === feature) {
return f.default; return f.default;
} }
@ -183,5 +183,5 @@ module.exports = {
setFeatureEnabled: function(feature: string, enabled: boolean) { setFeatureEnabled: function(feature: string, enabled: boolean) {
localStorage.setItem(`mx_labs_feature_${feature}`, enabled); localStorage.setItem(`mx_labs_feature_${feature}`, enabled);
} },
}; };

View file

@ -50,7 +50,7 @@ export default class MessageComposer extends React.Component {
inputState: { inputState: {
style: [], style: [],
blockType: null, blockType: null,
isRichtextEnabled: UserSettingsStore.getSyncedSetting('MessageComposerInput.isRichTextEnabled', true), isRichtextEnabled: UserSettingsStore.getSyncedSetting('MessageComposerInput.isRichTextEnabled', false),
wordCount: 0, wordCount: 0,
}, },
showFormatting: UserSettingsStore.getSyncedSetting('MessageComposer.showFormatting', false), showFormatting: UserSettingsStore.getSyncedSetting('MessageComposer.showFormatting', false),

View file

@ -94,7 +94,7 @@ export default class MessageComposerInput extends React.Component {
this.setDisplayedCompletion = this.setDisplayedCompletion.bind(this); this.setDisplayedCompletion = this.setDisplayedCompletion.bind(this);
this.onMarkdownToggleClicked = this.onMarkdownToggleClicked.bind(this); this.onMarkdownToggleClicked = this.onMarkdownToggleClicked.bind(this);
const isRichtextEnabled = UserSettingsStore.getSyncedSetting('MessageComposerInput.isRichTextEnabled', true); const isRichtextEnabled = UserSettingsStore.getSyncedSetting('MessageComposerInput.isRichTextEnabled', false);
this.state = { this.state = {
// whether we're in rich text or markdown mode // whether we're in rich text or markdown mode