cleanup path management
This commit is contained in:
Vendored
+19
-24
@@ -584,14 +584,9 @@
|
||||
return _StorageModel.pathComponentsToString(...allComponents);
|
||||
};
|
||||
static getPath(locationName, filePath) {
|
||||
return [DATA_VERSION, storageLocations[locationName], ...filePath];
|
||||
return [DATA_VERSION, locationName, ...filePath];
|
||||
}
|
||||
};
|
||||
var storageLocations = {
|
||||
connectionModel: "connection",
|
||||
chat: "chat",
|
||||
settingsModel: "settings"
|
||||
};
|
||||
var filePaths = {
|
||||
connectionModel: {
|
||||
socketAddress: ["socket-address"],
|
||||
@@ -832,7 +827,7 @@
|
||||
// paths
|
||||
getBasePath = () => {
|
||||
return StorageModel.getPath(
|
||||
"chat",
|
||||
"chat" /* Chat */,
|
||||
filePaths.chat.files(this.chatModel.id)
|
||||
);
|
||||
};
|
||||
@@ -1030,16 +1025,16 @@
|
||||
}
|
||||
// paths
|
||||
getBasePath = () => {
|
||||
return StorageModel.getPath("chat", filePaths.chat.chatBase(this.id));
|
||||
return StorageModel.getPath("chat" /* Chat */, filePaths.chat.chatBase(this.id));
|
||||
};
|
||||
getInfoPath = () => {
|
||||
return StorageModel.getPath("chat", filePaths.chat.info(this.id));
|
||||
return StorageModel.getPath("chat" /* Chat */, filePaths.chat.info(this.id));
|
||||
};
|
||||
getColorPath = () => {
|
||||
return StorageModel.getPath("chat", filePaths.chat.color(this.id));
|
||||
return StorageModel.getPath("chat" /* Chat */, filePaths.chat.color(this.id));
|
||||
};
|
||||
getMessageDirPath = () => {
|
||||
return StorageModel.getPath("chat", filePaths.chat.messages(this.id));
|
||||
return StorageModel.getPath("chat" /* Chat */, filePaths.chat.messages(this.id));
|
||||
};
|
||||
getMessagePath = (id) => {
|
||||
return [...this.getMessageDirPath(), id];
|
||||
@@ -1292,7 +1287,7 @@
|
||||
};
|
||||
// load
|
||||
loadChats = () => {
|
||||
const chatDir = StorageModel.getPath("chat", filePaths.chat.base);
|
||||
const chatDir = StorageModel.getPath("chat" /* Chat */, filePaths.chat.base);
|
||||
const chatIds = this.storageModel.list(chatDir);
|
||||
for (const chatId of chatIds) {
|
||||
const chatModel = new ChatModel(
|
||||
@@ -2015,7 +2010,7 @@
|
||||
// load
|
||||
loadPageSelection = () => {
|
||||
const path = StorageModel.getPath(
|
||||
"chat",
|
||||
"chat" /* Chat */,
|
||||
filePaths.chat.lastUsedPage(this.chatModel.id)
|
||||
);
|
||||
const lastUsedPage = this.storageModel.read(path);
|
||||
@@ -3434,7 +3429,7 @@
|
||||
console.log("connection status:", this.isConnected, this.address);
|
||||
this.connectionChangeHandlerManager.trigger();
|
||||
if (this.isConnected == false) return;
|
||||
if (!this.address) return;
|
||||
if (this.address == void 0) return;
|
||||
this.connectMailbox();
|
||||
this.storeAddress(this.address);
|
||||
this.sendSubscriptionRequest();
|
||||
@@ -3447,7 +3442,7 @@
|
||||
disconnect = () => {
|
||||
this.udn.disconnect();
|
||||
const reconnectAddressPath = StorageModel.getPath(
|
||||
"connectionModel",
|
||||
"connection" /* ConnectionModel */,
|
||||
filePaths.connectionModel.reconnectAddress
|
||||
);
|
||||
this.storageModel.remove(reconnectAddressPath);
|
||||
@@ -3455,14 +3450,14 @@
|
||||
// mailbox
|
||||
getMailboxPath = (address) => {
|
||||
const mailboxDirPath = StorageModel.getPath(
|
||||
"connectionModel",
|
||||
"connection" /* ConnectionModel */,
|
||||
filePaths.connectionModel.mailboxes
|
||||
);
|
||||
const mailboxFilePath = [...mailboxDirPath, address];
|
||||
return mailboxFilePath;
|
||||
};
|
||||
requestNewMailbox = () => {
|
||||
console.log("requesting mailbox");
|
||||
console.log("requesting new mailbox");
|
||||
this.udn.requestMailbox();
|
||||
};
|
||||
connectMailbox = () => {
|
||||
@@ -3491,7 +3486,7 @@
|
||||
// outbox
|
||||
getOutboxPath = () => {
|
||||
return StorageModel.getPath(
|
||||
"connectionModel",
|
||||
"connection" /* ConnectionModel */,
|
||||
filePaths.connectionModel.outbox
|
||||
);
|
||||
};
|
||||
@@ -3543,7 +3538,7 @@
|
||||
// storage
|
||||
getPreviousAddressPath = () => {
|
||||
return StorageModel.getPath(
|
||||
"connectionModel",
|
||||
"connection" /* ConnectionModel */,
|
||||
filePaths.connectionModel.previousAddresses
|
||||
);
|
||||
};
|
||||
@@ -3553,7 +3548,7 @@
|
||||
};
|
||||
getReconnectAddressPath = () => {
|
||||
return StorageModel.getPath(
|
||||
"connectionModel",
|
||||
"connection" /* ConnectionModel */,
|
||||
filePaths.connectionModel.reconnectAddress
|
||||
);
|
||||
};
|
||||
@@ -3823,7 +3818,7 @@
|
||||
setName(newValue) {
|
||||
this.username = newValue;
|
||||
const path = StorageModel.getPath(
|
||||
"settingsModel",
|
||||
"settings" /* SettingsModel */,
|
||||
filePaths.settingsModel.username
|
||||
);
|
||||
this.storageModel.write(path, newValue);
|
||||
@@ -3831,7 +3826,7 @@
|
||||
setFirstDayOfWeek(newValue) {
|
||||
this.firstDayOfWeek = newValue;
|
||||
const path = StorageModel.getPath(
|
||||
"settingsModel",
|
||||
"settings" /* SettingsModel */,
|
||||
filePaths.settingsModel.firstDayOfWeek
|
||||
);
|
||||
this.storageModel.write(path, newValue);
|
||||
@@ -3839,7 +3834,7 @@
|
||||
// load
|
||||
loadUsernam() {
|
||||
const path = StorageModel.getPath(
|
||||
"settingsModel",
|
||||
"settings" /* SettingsModel */,
|
||||
filePaths.settingsModel.username
|
||||
);
|
||||
const content = this.storageModel.read(path);
|
||||
@@ -3847,7 +3842,7 @@
|
||||
}
|
||||
loadFirstDayofWeek() {
|
||||
const path = StorageModel.getPath(
|
||||
"settingsModel",
|
||||
"settings" /* SettingsModel */,
|
||||
filePaths.settingsModel.firstDayOfWeek
|
||||
);
|
||||
const content = this.storageModel.read(path);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import ChatModel, { ChatMessage } from "./chatModel";
|
||||
import StorageModel, { filePaths } from "../Global/storageModel";
|
||||
import StorageModel, { StorageModelSubPath, filePaths } from "../Global/storageModel";
|
||||
|
||||
import ConnectionModel from "../Global/connectionModel";
|
||||
import { Message } from "udn-frontend";
|
||||
@@ -77,7 +77,7 @@ export default class ChatListModel {
|
||||
|
||||
// load
|
||||
loadChats = (): void => {
|
||||
const chatDir = StorageModel.getPath("chat", filePaths.chat.base);
|
||||
const chatDir = StorageModel.getPath(StorageModelSubPath.Chat, filePaths.chat.base);
|
||||
const chatIds = this.storageModel.list(chatDir);
|
||||
for (const chatId of chatIds) {
|
||||
const chatModel = new ChatModel(
|
||||
|
||||
@@ -9,7 +9,7 @@ import {
|
||||
parseValidObject,
|
||||
stringify,
|
||||
} from "../Utility/utility";
|
||||
import StorageModel, { filePaths } from "../Global/storageModel";
|
||||
import StorageModel, { StorageModelSubPath, filePaths } from "../Global/storageModel";
|
||||
import { decryptString, encryptString } from "../Utility/crypto";
|
||||
|
||||
import ChatListModel from "./chatListModel";
|
||||
@@ -39,19 +39,19 @@ export default class ChatModel {
|
||||
|
||||
// paths
|
||||
getBasePath = (): string[] => {
|
||||
return StorageModel.getPath("chat", filePaths.chat.chatBase(this.id));
|
||||
return StorageModel.getPath(StorageModelSubPath.Chat, filePaths.chat.chatBase(this.id));
|
||||
};
|
||||
|
||||
getInfoPath = (): string[] => {
|
||||
return StorageModel.getPath("chat", filePaths.chat.info(this.id));
|
||||
return StorageModel.getPath(StorageModelSubPath.Chat, filePaths.chat.info(this.id));
|
||||
};
|
||||
|
||||
getColorPath = (): string[] => {
|
||||
return StorageModel.getPath("chat", filePaths.chat.color(this.id));
|
||||
return StorageModel.getPath(StorageModelSubPath.Chat, filePaths.chat.color(this.id));
|
||||
};
|
||||
|
||||
getMessageDirPath = (): string[] => {
|
||||
return StorageModel.getPath("chat", filePaths.chat.messages(this.id));
|
||||
return StorageModel.getPath(StorageModelSubPath.Chat, filePaths.chat.messages(this.id));
|
||||
};
|
||||
|
||||
getMessagePath = (id: string): string[] => {
|
||||
|
||||
@@ -8,7 +8,7 @@ import {
|
||||
parseValidObject,
|
||||
stringify,
|
||||
} from "../Utility/utility";
|
||||
import StorageModel, { filePaths } from "../Global/storageModel";
|
||||
import StorageModel, { StorageModelSubPath, filePaths } from "../Global/storageModel";
|
||||
|
||||
import BoardsAndTasksModel from "./boardsAndTasksModel";
|
||||
import ChatModel from "../Chat/chatModel";
|
||||
@@ -25,7 +25,7 @@ export default class FileModel {
|
||||
// paths
|
||||
getBasePath = (): string[] => {
|
||||
return StorageModel.getPath(
|
||||
"chat",
|
||||
StorageModelSubPath.Chat,
|
||||
filePaths.chat.files(this.chatModel.id)
|
||||
);
|
||||
};
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
import { ChatMessage, ChatMessageReference } from "../Chat/chatModel";
|
||||
import { Handler, HandlerManager, stringify } from "../Utility/utility";
|
||||
import StorageModel, { filePaths } from "./storageModel";
|
||||
import StorageModel, { StorageModelSubPath, filePaths } from "./storageModel";
|
||||
import UDNFrontend, { Message } from "udn-frontend";
|
||||
|
||||
export default class ConnectionModel {
|
||||
@@ -34,7 +34,7 @@ export default class ConnectionModel {
|
||||
this.connectionChangeHandlerManager.trigger();
|
||||
|
||||
if (this.isConnected == false) return;
|
||||
if (!this.address) return;
|
||||
if (this.address == undefined) return;
|
||||
|
||||
this.connectMailbox();
|
||||
this.storeAddress(this.address);
|
||||
@@ -52,7 +52,7 @@ export default class ConnectionModel {
|
||||
|
||||
// do not reconnect
|
||||
const reconnectAddressPath: string[] = StorageModel.getPath(
|
||||
"connectionModel",
|
||||
StorageModelSubPath.ConnectionModel,
|
||||
filePaths.connectionModel.reconnectAddress
|
||||
);
|
||||
this.storageModel.remove(reconnectAddressPath);
|
||||
@@ -61,7 +61,7 @@ export default class ConnectionModel {
|
||||
// mailbox
|
||||
getMailboxPath = (address: string): string[] => {
|
||||
const mailboxDirPath = StorageModel.getPath(
|
||||
"connectionModel",
|
||||
StorageModelSubPath.ConnectionModel,
|
||||
filePaths.connectionModel.mailboxes
|
||||
);
|
||||
const mailboxFilePath = [...mailboxDirPath, address];
|
||||
@@ -69,7 +69,7 @@ export default class ConnectionModel {
|
||||
};
|
||||
|
||||
requestNewMailbox = (): void => {
|
||||
console.log("requesting mailbox");
|
||||
console.log("requesting new mailbox");
|
||||
this.udn.requestMailbox();
|
||||
};
|
||||
|
||||
@@ -107,7 +107,7 @@ export default class ConnectionModel {
|
||||
// outbox
|
||||
getOutboxPath = (): string[] => {
|
||||
return StorageModel.getPath(
|
||||
"connectionModel",
|
||||
StorageModelSubPath.ConnectionModel,
|
||||
filePaths.connectionModel.outbox
|
||||
);
|
||||
};
|
||||
@@ -173,7 +173,7 @@ export default class ConnectionModel {
|
||||
// storage
|
||||
getPreviousAddressPath = (): string[] => {
|
||||
return StorageModel.getPath(
|
||||
"connectionModel",
|
||||
StorageModelSubPath.ConnectionModel,
|
||||
filePaths.connectionModel.previousAddresses
|
||||
);
|
||||
};
|
||||
@@ -185,7 +185,7 @@ export default class ConnectionModel {
|
||||
|
||||
getReconnectAddressPath = (): string[] => {
|
||||
return StorageModel.getPath(
|
||||
"connectionModel",
|
||||
StorageModelSubPath.ConnectionModel,
|
||||
filePaths.connectionModel.reconnectAddress
|
||||
);
|
||||
};
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
// this file is responsible for all settings.
|
||||
|
||||
import StorageModel, { filePaths } from "./storageModel";
|
||||
import StorageModel, { StorageModelSubPath, filePaths } from "./storageModel";
|
||||
|
||||
export default class SettingsModel {
|
||||
storageModel: StorageModel;
|
||||
@@ -13,7 +13,7 @@ export default class SettingsModel {
|
||||
setName(newValue: string): void {
|
||||
this.username = newValue;
|
||||
const path = StorageModel.getPath(
|
||||
"settingsModel",
|
||||
StorageModelSubPath.SettingsModel,
|
||||
filePaths.settingsModel.username
|
||||
);
|
||||
this.storageModel.write(path, newValue);
|
||||
@@ -22,7 +22,7 @@ export default class SettingsModel {
|
||||
setFirstDayOfWeek(newValue: string): void {
|
||||
this.firstDayOfWeek = newValue;
|
||||
const path = StorageModel.getPath(
|
||||
"settingsModel",
|
||||
StorageModelSubPath.SettingsModel,
|
||||
filePaths.settingsModel.firstDayOfWeek
|
||||
);
|
||||
this.storageModel.write(path, newValue);
|
||||
@@ -31,7 +31,7 @@ export default class SettingsModel {
|
||||
// load
|
||||
loadUsernam(): void {
|
||||
const path = StorageModel.getPath(
|
||||
"settingsModel",
|
||||
StorageModelSubPath.SettingsModel,
|
||||
filePaths.settingsModel.username
|
||||
);
|
||||
const content = this.storageModel.read(path);
|
||||
@@ -40,7 +40,7 @@ export default class SettingsModel {
|
||||
|
||||
loadFirstDayofWeek(): void {
|
||||
const path = StorageModel.getPath(
|
||||
"settingsModel",
|
||||
StorageModelSubPath.SettingsModel,
|
||||
filePaths.settingsModel.firstDayOfWeek
|
||||
);
|
||||
const content = this.storageModel.read(path);
|
||||
|
||||
@@ -1,9 +1,6 @@
|
||||
// this file is responsible for reading and writing persistent data.
|
||||
|
||||
import {
|
||||
DATA_VERSION,
|
||||
ValidObject,
|
||||
} from "../Utility/typeSafety";
|
||||
import { DATA_VERSION, ValidObject } from "../Utility/typeSafety";
|
||||
import { localeCompare, parseValidObject, stringify } from "../Utility/utility";
|
||||
|
||||
export const PATH_COMPONENT_SEPARATOR = "\\";
|
||||
@@ -84,7 +81,6 @@ export default class StorageModel {
|
||||
const content: string | null = this.read(sourcePathComponents);
|
||||
if (content == null) return false;
|
||||
|
||||
|
||||
this.write(destinationPathComponents, content);
|
||||
this.remove(sourcePathComponents);
|
||||
|
||||
@@ -212,10 +208,10 @@ export default class StorageModel {
|
||||
};
|
||||
|
||||
static getPath(
|
||||
locationName: keyof typeof storageLocations,
|
||||
locationName: StorageModelSubPath,
|
||||
filePath: string[]
|
||||
): string[] {
|
||||
return [DATA_VERSION, storageLocations[locationName], ...filePath];
|
||||
return [DATA_VERSION, locationName, ...filePath];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -223,13 +219,12 @@ export default class StorageModel {
|
||||
export type StorageEntry = { [key: string]: StorageEntry };
|
||||
|
||||
// locations
|
||||
const storageLocations = {
|
||||
connectionModel: "connection",
|
||||
export enum StorageModelSubPath {
|
||||
Chat = "chat",
|
||||
|
||||
chat: "chat",
|
||||
|
||||
settingsModel: "settings",
|
||||
};
|
||||
ConnectionModel = "connection",
|
||||
SettingsModel = "settings",
|
||||
}
|
||||
|
||||
export const filePaths = {
|
||||
connectionModel: {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import * as React from "bloatless-react";
|
||||
|
||||
import ChatModel, { ChatMessage } from "../../Model/Chat/chatModel";
|
||||
import StorageModel, { filePaths } from "../../Model/Global/storageModel";
|
||||
import StorageModel, { StorageModelSubPath, filePaths } from "../../Model/Global/storageModel";
|
||||
|
||||
import ChatListViewModel from "./chatListViewModel";
|
||||
import { Color } from "../../colors";
|
||||
@@ -62,7 +62,7 @@ export default class ChatViewModel {
|
||||
// load
|
||||
loadPageSelection = (): void => {
|
||||
const path: string[] = StorageModel.getPath(
|
||||
"chat",
|
||||
StorageModelSubPath.Chat,
|
||||
filePaths.chat.lastUsedPage(this.chatModel.id)
|
||||
);
|
||||
const lastUsedPage: string | null = this.storageModel.read(path);
|
||||
|
||||
@@ -51,7 +51,7 @@ export default class BoardViewModel {
|
||||
};
|
||||
|
||||
getLastUsedBoardPath = (): string[] => {
|
||||
return [...this.getBasePath(), BoardViewModelSubPaths.LastUsedView];
|
||||
return [...this.getBasePath(), BoardViewModelSubPath.LastUsedView];
|
||||
};
|
||||
|
||||
// settings
|
||||
@@ -264,7 +264,7 @@ export default class BoardViewModel {
|
||||
}
|
||||
}
|
||||
|
||||
export enum BoardViewModelSubPaths {
|
||||
export enum BoardViewModelSubPath {
|
||||
LastUsedView = "last-used-view",
|
||||
}
|
||||
|
||||
|
||||
@@ -29,7 +29,7 @@ export default class TaskPageViewModel {
|
||||
};
|
||||
|
||||
getLastUsedBoardPath = (): string[] => {
|
||||
return [...this.getBasePath(), TaskPageViewModelSubPaths.LastUsedBoard];
|
||||
return [...this.getBasePath(), TaskPageViewModelSubPath.LastUsedBoard];
|
||||
};
|
||||
|
||||
// state
|
||||
@@ -162,6 +162,6 @@ export default class TaskPageViewModel {
|
||||
}
|
||||
}
|
||||
|
||||
export enum TaskPageViewModelSubPaths {
|
||||
export enum TaskPageViewModelSubPath {
|
||||
LastUsedBoard = "last-used-board",
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user