mirror of https://github.com/vector-im/riot-web
Bring breadcrumbs into new Riot config standard
parent
b44e14a722
commit
8dec435e50
|
@ -19,7 +19,9 @@ import MatrixClientPeg from '../../MatrixClientPeg';
|
|||
import MatrixClientBackedSettingsHandler from "./MatrixClientBackedSettingsHandler";
|
||||
import {SettingLevel} from "../SettingsStore";
|
||||
|
||||
const BREADCRUMBS_EVENT_TYPE = "im.vector.riot.breadcrumb_rooms";
|
||||
const BREADCRUMBS_LEGACY_EVENT_TYPE = "im.vector.riot.breadcrumb_rooms";
|
||||
const BREADCRUMBS_EVENT_TYPE = "im.vector.setting.breadcrumbs";
|
||||
const BREADCRUMBS_EVENT_TYPES = [BREADCRUMBS_LEGACY_EVENT_TYPE, BREADCRUMBS_EVENT_TYPE];
|
||||
|
||||
/**
|
||||
* Gets and sets settings at the "account" level for the current user.
|
||||
|
@ -57,9 +59,8 @@ export default class AccountSettingsHandler extends MatrixClientBackedSettingsHa
|
|||
const val = event.getContent()[settingName];
|
||||
this._watchers.notifyUpdate(settingName, null, SettingLevel.ACCOUNT, val);
|
||||
}
|
||||
} else if (event.getType() === BREADCRUMBS_EVENT_TYPE) {
|
||||
const val = event.getContent()['rooms'] || [];
|
||||
this._watchers.notifyUpdate("breadcrumb_rooms", null, SettingLevel.ACCOUNT, val);
|
||||
} else if (BREADCRUMBS_EVENT_TYPES.includes(event.getType())) {
|
||||
this._notifyBreadcrumbsUpdate(event);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -75,8 +76,15 @@ export default class AccountSettingsHandler extends MatrixClientBackedSettingsHa
|
|||
|
||||
// Special case for breadcrumbs
|
||||
if (settingName === "breadcrumb_rooms") {
|
||||
const content = this._getSettings(BREADCRUMBS_EVENT_TYPE) || {};
|
||||
return content['rooms'] || [];
|
||||
let content = this._getSettings(BREADCRUMBS_EVENT_TYPE);
|
||||
if (!content || !content['recent_rooms']) {
|
||||
content = this._getSettings(BREADCRUMBS_LEGACY_EVENT_TYPE);
|
||||
|
||||
// This is a bit of a hack, but it makes things slightly easier
|
||||
if (content) content['recent_rooms'] = content['rooms'];
|
||||
}
|
||||
|
||||
return content && content['recent_rooms'] ? content['recent_rooms'] : [];
|
||||
}
|
||||
|
||||
const settings = this._getSettings() || {};
|
||||
|
@ -102,8 +110,13 @@ export default class AccountSettingsHandler extends MatrixClientBackedSettingsHa
|
|||
|
||||
// Special case for breadcrumbs
|
||||
if (settingName === "breadcrumb_rooms") {
|
||||
const content = this._getSettings(BREADCRUMBS_EVENT_TYPE) || {};
|
||||
content['rooms'] = newValue;
|
||||
// We read the value first just to make sure we preserve whatever random keys might be present.
|
||||
let content = this._getSettings(BREADCRUMBS_EVENT_TYPE);
|
||||
if (!content || !content['recent_rooms']) {
|
||||
content = this._getSettings(BREADCRUMBS_LEGACY_EVENT_TYPE);
|
||||
}
|
||||
|
||||
content['recent_rooms'] = newValue;
|
||||
return MatrixClientPeg.get().setAccountData(BREADCRUMBS_EVENT_TYPE, content);
|
||||
}
|
||||
|
||||
|
@ -129,4 +142,19 @@ export default class AccountSettingsHandler extends MatrixClientBackedSettingsHa
|
|||
if (!event || !event.getContent()) return null;
|
||||
return event.getContent();
|
||||
}
|
||||
|
||||
_notifyBreadcrumbsUpdate(event) {
|
||||
let val = [];
|
||||
if (event.getType() === BREADCRUMBS_LEGACY_EVENT_TYPE) {
|
||||
// This seems fishy - try and get the event for the new rooms
|
||||
const newType = this._getSettings(BREADCRUMBS_EVENT_TYPE);
|
||||
if (newType) val = newType['recent_rooms'];
|
||||
else val = event.getContent()['rooms'];
|
||||
} else if (event.getType() === BREADCRUMBS_EVENT_TYPE) {
|
||||
val = event.getContent()['recent_rooms'];
|
||||
} else {
|
||||
return; // for sanity, not because we expect to be here.
|
||||
}
|
||||
this._watchers.notifyUpdate("breadcrumb_rooms", null, SettingLevel.ACCOUNT, val || []);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue