mirror of
https://github.com/revoltchat/revite.git
synced 2024-11-22 07:00:58 -05:00
chore: remove legacy Redux migration
This commit is contained in:
parent
b7be9f8c03
commit
211ff2058a
4 changed files with 3 additions and 239 deletions
|
@ -6,8 +6,6 @@ import { Client } from "revolt.js";
|
|||
|
||||
import { reportError } from "../lib/ErrorBoundary";
|
||||
|
||||
import { legacyMigrateForwards, LegacyState } from "./legacy/redux";
|
||||
|
||||
import Persistent from "./interfaces/Persistent";
|
||||
import Syncable from "./interfaces/Syncable";
|
||||
import Auth from "./stores/Auth";
|
||||
|
@ -239,23 +237,6 @@ export default class State {
|
|||
* Load data stores from local storage.
|
||||
*/
|
||||
async hydrate() {
|
||||
// Migrate legacy Redux store.
|
||||
try {
|
||||
let legacy = await localforage.getItem("state");
|
||||
await localforage.removeItem("state");
|
||||
if (legacy) {
|
||||
if (typeof legacy === "string") {
|
||||
legacy = JSON.parse(legacy);
|
||||
}
|
||||
|
||||
legacyMigrateForwards(legacy as Partial<LegacyState>, this);
|
||||
await this.save();
|
||||
return;
|
||||
}
|
||||
} catch (err) {
|
||||
reportError(err as any, "redux_migration");
|
||||
}
|
||||
|
||||
// Load MobX store.
|
||||
const sync = (await localforage.getItem("sync")) as DataSync;
|
||||
const { revision } = sync ?? { revision: {} };
|
||||
|
|
|
@ -1,188 +0,0 @@
|
|||
import { runInAction } from "mobx";
|
||||
import { API } from "revolt.js";
|
||||
|
||||
import { Fonts, MonospaceFonts, Overrides } from "../../context/Theme";
|
||||
|
||||
import { Language } from "../../../external/lang/Languages";
|
||||
import State from "../State";
|
||||
import { Data as DataAuth } from "../stores/Auth";
|
||||
import { Data as DataLocaleOptions } from "../stores/LocaleOptions";
|
||||
import { Data as DataNotificationOptions } from "../stores/NotificationOptions";
|
||||
import { ISettings } from "../stores/Settings";
|
||||
import { Data as DataSync } from "../stores/Sync";
|
||||
|
||||
export type LegacyTheme = Overrides & {
|
||||
light?: boolean;
|
||||
font?: Fonts;
|
||||
css?: string;
|
||||
monospaceFont?: MonospaceFonts;
|
||||
};
|
||||
|
||||
export interface LegacyThemeOptions {
|
||||
base?: string;
|
||||
ligatures?: boolean;
|
||||
custom?: Partial<LegacyTheme>;
|
||||
}
|
||||
|
||||
export type LegacyEmojiPacks = "mutant" | "twemoji" | "noto" | "openmoji";
|
||||
export interface LegacyAppearanceOptions {
|
||||
emojiPack?: LegacyEmojiPacks;
|
||||
}
|
||||
|
||||
export type LegacyNotificationState = "all" | "mention" | "none" | "muted";
|
||||
|
||||
export type LegacyNotifications = {
|
||||
[key: string]: LegacyNotificationState;
|
||||
};
|
||||
|
||||
export interface LegacySyncData {
|
||||
locale?: Language;
|
||||
theme?: LegacyThemeOptions;
|
||||
appearance?: LegacyAppearanceOptions;
|
||||
notifications?: LegacyNotifications;
|
||||
}
|
||||
|
||||
export type LegacySyncKeys =
|
||||
| "theme"
|
||||
| "appearance"
|
||||
| "locale"
|
||||
| "notifications";
|
||||
|
||||
export interface LegacySyncOptions {
|
||||
disabled?: LegacySyncKeys[];
|
||||
revision?: {
|
||||
[key: string]: number;
|
||||
};
|
||||
}
|
||||
|
||||
export interface LegacyAuthState {
|
||||
accounts: {
|
||||
[key: string]: {
|
||||
session: Session;
|
||||
};
|
||||
};
|
||||
active?: string;
|
||||
}
|
||||
|
||||
export interface LegacySettings {
|
||||
theme?: LegacyThemeOptions;
|
||||
appearance?: LegacyAppearanceOptions;
|
||||
}
|
||||
|
||||
export function legacyMigrateAuth(auth: LegacyAuthState): DataAuth {
|
||||
return {
|
||||
current: auth.active,
|
||||
sessions: auth.accounts,
|
||||
};
|
||||
}
|
||||
|
||||
export function legacyMigrateLocale(lang: Language): DataLocaleOptions {
|
||||
return {
|
||||
lang,
|
||||
};
|
||||
}
|
||||
|
||||
export function legacyMigrateTheme(
|
||||
theme: LegacyThemeOptions,
|
||||
): Partial<ISettings> {
|
||||
const { light, font, css, monospaceFont, ...variables } =
|
||||
theme.custom ?? {};
|
||||
|
||||
return {
|
||||
"appearance:ligatures": theme.ligatures,
|
||||
"appearance:theme:base": theme.base === "light" ? "light" : "dark",
|
||||
"appearance:theme:light": light,
|
||||
"appearance:theme:font": font,
|
||||
"appearance:theme:monoFont": monospaceFont,
|
||||
"appearance:theme:css": css,
|
||||
"appearance:theme:overrides": variables,
|
||||
};
|
||||
}
|
||||
|
||||
export function legacyMigrateAppearance(
|
||||
appearance: LegacyAppearanceOptions,
|
||||
): Partial<ISettings> {
|
||||
return {
|
||||
"appearance:emoji": appearance.emojiPack,
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove trolling from an object
|
||||
* @param inp Object to remove trolling from
|
||||
* @returns Object without trolling
|
||||
*/
|
||||
function detroll(inp: object): ISettings {
|
||||
const obj: object = {};
|
||||
Object.keys(inp)
|
||||
.filter((x) => typeof (inp as any)[x] !== "undefined")
|
||||
.map((x) => ((obj as any)[x] = (inp as any)[x]));
|
||||
|
||||
return obj as unknown as ISettings;
|
||||
}
|
||||
|
||||
export function legacyMigrateNotification(
|
||||
channel: LegacyNotifications,
|
||||
): DataNotificationOptions {
|
||||
return {
|
||||
channel,
|
||||
};
|
||||
}
|
||||
|
||||
export function legacyMigrateSync(sync: LegacySyncOptions): DataSync {
|
||||
return {
|
||||
disabled: sync.disabled ?? [],
|
||||
revision: {
|
||||
...sync.revision,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
export type LegacyState = {
|
||||
locale: Language;
|
||||
auth: LegacyAuthState;
|
||||
settings: LegacySettings;
|
||||
sync: LegacySyncOptions;
|
||||
notifications: LegacyNotifications;
|
||||
};
|
||||
|
||||
export function legacyMigrateForwards(
|
||||
data: Partial<LegacyState>,
|
||||
target: State,
|
||||
) {
|
||||
runInAction(() => {
|
||||
if ("sync" in data) {
|
||||
target.sync.hydrate(legacyMigrateSync(data.sync!));
|
||||
}
|
||||
|
||||
if ("locale" in data) {
|
||||
target.locale.hydrate(legacyMigrateLocale(data.locale!));
|
||||
}
|
||||
|
||||
if ("auth" in data) {
|
||||
target.auth.hydrate(legacyMigrateAuth(data.auth!));
|
||||
}
|
||||
|
||||
if ("settings" in data) {
|
||||
if (data!.settings!.theme) {
|
||||
target.settings.hydrate(
|
||||
detroll(legacyMigrateTheme(data.settings!.theme!)),
|
||||
);
|
||||
}
|
||||
|
||||
if (data!.settings!.appearance) {
|
||||
target.settings.hydrate(
|
||||
detroll(
|
||||
legacyMigrateAppearance(data.settings!.appearance!),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if ("notifications" in data) {
|
||||
target.notifications.hydrate(
|
||||
legacyMigrateNotification(data.notifications!),
|
||||
);
|
||||
}
|
||||
});
|
||||
}
|
|
@ -1,16 +1,8 @@
|
|||
import { action, computed, makeAutoObservable, ObservableMap } from "mobx";
|
||||
import { Channel } from "revolt.js";
|
||||
import { Message } from "revolt.js";
|
||||
import { Server } from "revolt.js";
|
||||
import { Channel, Message, Server } from "revolt.js";
|
||||
|
||||
import { mapToRecord } from "../../lib/conversion";
|
||||
|
||||
import {
|
||||
legacyMigrateNotification,
|
||||
LegacyNotifications,
|
||||
} from "../legacy/redux";
|
||||
|
||||
import { MIGRATIONS } from "../State";
|
||||
import Persistent from "../interfaces/Persistent";
|
||||
import Store from "../interfaces/Store";
|
||||
import Syncable from "../interfaces/Syncable";
|
||||
|
@ -217,11 +209,7 @@ export default class NotificationOptions
|
|||
return false;
|
||||
}
|
||||
|
||||
@action apply(_key: "notifications", data: unknown, revision: number) {
|
||||
if (revision < MIGRATIONS.REDUX) {
|
||||
data = legacyMigrateNotification(data as LegacyNotifications);
|
||||
}
|
||||
|
||||
@action apply(_key: "notifications", data: unknown, _revision: number) {
|
||||
this.hydrate(data as Data);
|
||||
}
|
||||
|
||||
|
|
|
@ -2,18 +2,9 @@ import { action, computed, makeAutoObservable, ObservableMap } from "mobx";
|
|||
|
||||
import { mapToRecord } from "../../lib/conversion";
|
||||
|
||||
import {
|
||||
LegacyAppearanceOptions,
|
||||
legacyMigrateAppearance,
|
||||
legacyMigrateTheme,
|
||||
LegacyTheme,
|
||||
LegacyThemeOptions,
|
||||
} from "../legacy/redux";
|
||||
|
||||
import { Fonts, MonospaceFonts, Overrides } from "../../context/Theme";
|
||||
|
||||
import { EmojiPack } from "../../components/common/Emoji";
|
||||
|
||||
import { MIGRATIONS } from "../State";
|
||||
import Persistent from "../interfaces/Persistent";
|
||||
import Store from "../interfaces/Store";
|
||||
|
@ -129,16 +120,8 @@ export default class Settings
|
|||
@action apply(
|
||||
key: "appearance" | "theme",
|
||||
data: unknown,
|
||||
revision: number,
|
||||
_revision: number,
|
||||
) {
|
||||
if (revision < MIGRATIONS.REDUX) {
|
||||
if (key === "appearance") {
|
||||
data = legacyMigrateAppearance(data as LegacyAppearanceOptions);
|
||||
} else {
|
||||
data = legacyMigrateTheme(data as LegacyThemeOptions);
|
||||
}
|
||||
}
|
||||
|
||||
if (key === "appearance") {
|
||||
this.remove("appearance:emoji");
|
||||
this.remove("appearance:seasonal");
|
||||
|
|
Loading…
Reference in a new issue