remove more object stuff, prepare FileModel
This commit is contained in:
+1
-54
@@ -44,18 +44,10 @@ export class ChatModel {
|
|||||||
return storageKeys.chatMessages(this.id);
|
return storageKeys.chatMessages(this.id);
|
||||||
}
|
}
|
||||||
|
|
||||||
get objectDirPath(): string[] {
|
|
||||||
return storageKeys.chatObjects(this.id);
|
|
||||||
}
|
|
||||||
|
|
||||||
getMessagePath = (id: string): string[] => {
|
getMessagePath = (id: string): string[] => {
|
||||||
return [...this.messageDirPath, id];
|
return [...this.messageDirPath, id];
|
||||||
};
|
};
|
||||||
|
|
||||||
getObjectPath = (id: string): string[] => {
|
|
||||||
return [...this.objectDirPath, id];
|
|
||||||
};
|
|
||||||
|
|
||||||
// set
|
// set
|
||||||
setPrimaryChannel = (primaryChannel: string): void => {
|
setPrimaryChannel = (primaryChannel: string): void => {
|
||||||
this.info.primaryChannel = primaryChannel;
|
this.info.primaryChannel = primaryChannel;
|
||||||
@@ -95,11 +87,6 @@ export class ChatModel {
|
|||||||
this.chatMessageHandler(chatMessage);
|
this.chatMessageHandler(chatMessage);
|
||||||
};
|
};
|
||||||
|
|
||||||
addObject = (chatObject: ChatObject): void => {
|
|
||||||
const objectPath: string[] = this.getObjectPath(chatObject.id);
|
|
||||||
this.storageModel.storeStringifiable(objectPath, chatObject);
|
|
||||||
};
|
|
||||||
|
|
||||||
// delete
|
// delete
|
||||||
delete = () => {
|
delete = () => {
|
||||||
// untrack
|
// untrack
|
||||||
@@ -149,23 +136,6 @@ export class ChatModel {
|
|||||||
return sorted;
|
return sorted;
|
||||||
}
|
}
|
||||||
|
|
||||||
get objects(): ChatObject[] {
|
|
||||||
const objectIds: string[] = this.storageModel.list(this.objectDirPath);
|
|
||||||
if (!Array.isArray(objectIds)) return [];
|
|
||||||
|
|
||||||
const objects: ChatObject[] = [];
|
|
||||||
for (const objectId of objectIds) {
|
|
||||||
const objectPathComponents: string[] = this.getObjectPath(objectId);
|
|
||||||
const object: any =
|
|
||||||
this.storageModel.restoreStringifiable(objectPathComponents);
|
|
||||||
if (checkIsValidObject(object) == false) continue;
|
|
||||||
if (object.id != objectId) continue;
|
|
||||||
|
|
||||||
objects.push(object);
|
|
||||||
}
|
|
||||||
return objects;
|
|
||||||
}
|
|
||||||
|
|
||||||
// messaging
|
// messaging
|
||||||
sendMessage = async (body: string): Promise<boolean> => {
|
sendMessage = async (body: string): Promise<boolean> => {
|
||||||
const senderName = this.settingsModel.username;
|
const senderName = this.settingsModel.username;
|
||||||
@@ -309,28 +279,5 @@ export interface ChatMessage {
|
|||||||
|
|
||||||
status?: ChatMessageStatus;
|
status?: ChatMessageStatus;
|
||||||
|
|
||||||
stringifiedObject?: string;
|
stringifiedFile?: string;
|
||||||
}
|
|
||||||
|
|
||||||
export interface ChatObject {
|
|
||||||
dataVersion: "v2";
|
|
||||||
|
|
||||||
id: string;
|
|
||||||
title: string;
|
|
||||||
|
|
||||||
contentVersions: { [key: string]: ChatObjectContent };
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface ChatObjectContent {
|
|
||||||
dataVersion: "v2";
|
|
||||||
|
|
||||||
id: string;
|
|
||||||
creationDate: string;
|
|
||||||
|
|
||||||
noteText?: string;
|
|
||||||
priority?: number;
|
|
||||||
category?: string;
|
|
||||||
status?: string;
|
|
||||||
date?: string;
|
|
||||||
time?: string;
|
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
export interface File {
|
||||||
|
dataVersion: "v2";
|
||||||
|
|
||||||
|
id: string;
|
||||||
|
title: string;
|
||||||
|
|
||||||
|
contentVersions: { [id: string]: FileContent };
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface FileContent {
|
||||||
|
dataVersion: "v2";
|
||||||
|
|
||||||
|
id: string;
|
||||||
|
creationDate: string;
|
||||||
|
}
|
||||||
@@ -113,13 +113,13 @@ export default class StorageModel {
|
|||||||
};
|
};
|
||||||
|
|
||||||
static getFileName = (pathComponents: string[]): string => {
|
static getFileName = (pathComponents: string[]): string => {
|
||||||
return pathComponents[pathComponents.length - 1] || "\\"
|
return pathComponents[pathComponents.length - 1] || "\\";
|
||||||
}
|
};
|
||||||
|
|
||||||
static getFileNameFromString = (pathString: string): string => {
|
static getFileNameFromString = (pathString: string): string => {
|
||||||
const pathComponents: string[] = this.stringToPathComponents(pathString);
|
const pathComponents: string[] = this.stringToPathComponents(pathString);
|
||||||
return pathComponents[pathComponents.length - 1] || "\\"
|
return pathComponents[pathComponents.length - 1] || "\\";
|
||||||
}
|
};
|
||||||
|
|
||||||
static pathComponentsToString = (...pathComponents: string[]): string => {
|
static pathComponentsToString = (...pathComponents: string[]): string => {
|
||||||
return pathComponents.join(PATH_COMPONENT_SEPARATOR);
|
return pathComponents.join(PATH_COMPONENT_SEPARATOR);
|
||||||
@@ -156,11 +156,8 @@ export const storageKeys = {
|
|||||||
|
|
||||||
// history
|
// history
|
||||||
previousAddresses: [DATA_VERSION, "history", "previous-addresses"],
|
previousAddresses: [DATA_VERSION, "history", "previous-addresses"],
|
||||||
previousObjectCategories: [DATA_VERSION, "history", "object-categories"],
|
|
||||||
previousObjectStatuses: [DATA_VERSION, "history", "object-statuses"],
|
|
||||||
previousObjectFilters: [DATA_VERSION, "history", "object-filters"],
|
|
||||||
|
|
||||||
// chat etc
|
// chat
|
||||||
chats: [DATA_VERSION, "chat"],
|
chats: [DATA_VERSION, "chat"],
|
||||||
chatInfo: (id: string) => [DATA_VERSION, "chat", id, "info"],
|
chatInfo: (id: string) => [DATA_VERSION, "chat", id, "info"],
|
||||||
chatLastUsedPage: (id: string) => [
|
chatLastUsedPage: (id: string) => [
|
||||||
@@ -171,5 +168,4 @@ export const storageKeys = {
|
|||||||
],
|
],
|
||||||
chatColor: (id: string) => [DATA_VERSION, "chat", id, "color"],
|
chatColor: (id: string) => [DATA_VERSION, "chat", id, "color"],
|
||||||
chatMessages: (id: string) => [DATA_VERSION, "chat", id, "messages"],
|
chatMessages: (id: string) => [DATA_VERSION, "chat", id, "messages"],
|
||||||
chatObjects: (id: string) => [DATA_VERSION, "chat", id, "objects"],
|
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user