feat(mobx): add sync back (do not look at the code)

This commit is contained in:
Paul
2021-12-24 02:05:18 +00:00
parent 0591d44a31
commit aaadd98cfa
18 changed files with 341 additions and 166 deletions

View File

@@ -6,8 +6,15 @@ import { Server } from "revolt.js/dist/maps/Servers";
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";
/**
* Possible notification states.
@@ -42,7 +49,9 @@ export interface Data {
/**
* Manages the user's notification preferences.
*/
export default class NotificationOptions implements Store, Persistent<Data> {
export default class NotificationOptions
implements Store, Persistent<Data>, Syncable
{
private server: ObservableMap<string, NotificationState>;
private channel: ObservableMap<string, NotificationState>;
@@ -208,4 +217,18 @@ export default class NotificationOptions implements Store, Persistent<Data> {
return false;
}
@action apply(_key: "notifications", data: unknown, revision: number) {
if (revision < MIGRATIONS.REDUX) {
data = legacyMigrateNotification(data as LegacyNotifications);
}
this.hydrate(data as Data);
}
@computed toSyncable() {
return {
notifications: this.toJSON(),
};
}
}