Revert "prevent errors with corrupt files"
This reverts commit 3f48f26327.
This commit is contained in:
Vendored
+2
-12
@@ -444,7 +444,6 @@
|
|||||||
handleStringifiedFile = (stringifiedFile) => {
|
handleStringifiedFile = (stringifiedFile) => {
|
||||||
const file = parseValidObject(stringifiedFile);
|
const file = parseValidObject(stringifiedFile);
|
||||||
if (file == null) return;
|
if (file == null) return;
|
||||||
this.storeFile(file);
|
|
||||||
};
|
};
|
||||||
// methods
|
// methods
|
||||||
addFile = (file) => {
|
addFile = (file) => {
|
||||||
@@ -462,8 +461,6 @@
|
|||||||
file,
|
file,
|
||||||
fileContentName
|
fileContentName
|
||||||
);
|
);
|
||||||
const existingFileContent = this.storageModel.read(fileContentPath);
|
|
||||||
if (existingFileContent != null) return;
|
|
||||||
const stringifiedContent = stringify(fileContent);
|
const stringifiedContent = stringify(fileContent);
|
||||||
this.storageModel.write(fileContentPath, stringifiedContent);
|
this.storageModel.write(fileContentPath, stringifiedContent);
|
||||||
};
|
};
|
||||||
@@ -503,13 +500,6 @@
|
|||||||
const filePath = _FileModel.getFilePath(file.id);
|
const filePath = _FileModel.getFilePath(file.id);
|
||||||
return [...filePath, fileContentName];
|
return [...filePath, fileContentName];
|
||||||
};
|
};
|
||||||
static createFile = () => {
|
|
||||||
return {
|
|
||||||
dataVersion: DATA_VERSION,
|
|
||||||
id: v4_default(),
|
|
||||||
contentVersions: []
|
|
||||||
};
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// src/Model/Utility/crypto.ts
|
// src/Model/Utility/crypto.ts
|
||||||
@@ -767,7 +757,7 @@
|
|||||||
// utility
|
// utility
|
||||||
static generateChatInfo = (primaryChannel) => {
|
static generateChatInfo = (primaryChannel) => {
|
||||||
return {
|
return {
|
||||||
dataVersion: DATA_VERSION,
|
dataVersion: "v2",
|
||||||
primaryChannel,
|
primaryChannel,
|
||||||
secondaryChannels: [],
|
secondaryChannels: [],
|
||||||
encryptionKey: "",
|
encryptionKey: "",
|
||||||
@@ -776,7 +766,7 @@
|
|||||||
};
|
};
|
||||||
static createChatMessage = async (channel, sender, encryptionKey, body, file) => {
|
static createChatMessage = async (channel, sender, encryptionKey, body, file) => {
|
||||||
const chatMessage = {
|
const chatMessage = {
|
||||||
dataVersion: DATA_VERSION,
|
dataVersion: "v2",
|
||||||
id: v4_default(),
|
id: v4_default(),
|
||||||
channel,
|
channel,
|
||||||
sender,
|
sender,
|
||||||
|
|||||||
@@ -66,7 +66,6 @@ export default class ChatListModel {
|
|||||||
|
|
||||||
let allChannels: string[] = [];
|
let allChannels: string[] = [];
|
||||||
for (const chatModel of this.chatModels) {
|
for (const chatModel of this.chatModels) {
|
||||||
if (chatModel.info.primaryChannel == undefined) continue;
|
|
||||||
allChannels.push(chatModel.info.primaryChannel);
|
allChannels.push(chatModel.info.primaryChannel);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+21
-31
@@ -1,10 +1,6 @@
|
|||||||
// this file is responsible for managing chats.
|
// this file is responsible for managing chats.
|
||||||
|
|
||||||
import {
|
import { DATA_VERSION, ValidObject, checkIsValidObject } from "./Utility/typeSafety";
|
||||||
DATA_VERSION,
|
|
||||||
ValidObject,
|
|
||||||
checkIsValidObject,
|
|
||||||
} from "./Utility/typeSafety";
|
|
||||||
import FileModel, { File } from "./fileModel";
|
import FileModel, { File } from "./fileModel";
|
||||||
import StorageModel, { storageKeys } from "./storageModel";
|
import StorageModel, { storageKeys } from "./storageModel";
|
||||||
import {
|
import {
|
||||||
@@ -39,7 +35,7 @@ export default class ChatModel {
|
|||||||
// sorting
|
// sorting
|
||||||
get index(): number {
|
get index(): number {
|
||||||
return this.chatListModel.getIndexOfPrimaryChannel(
|
return this.chatListModel.getIndexOfPrimaryChannel(
|
||||||
this.info.primaryChannel ?? ""
|
this.info.primaryChannel
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -94,7 +90,6 @@ export default class ChatModel {
|
|||||||
|
|
||||||
addMessage = async (chatMessage: ChatMessage): Promise<void> => {
|
addMessage = async (chatMessage: ChatMessage): Promise<void> => {
|
||||||
await this.decryptMessage(chatMessage);
|
await this.decryptMessage(chatMessage);
|
||||||
if (chatMessage.id == undefined) return;
|
|
||||||
|
|
||||||
// message
|
// message
|
||||||
if (chatMessage.body != "") {
|
if (chatMessage.body != "") {
|
||||||
@@ -104,7 +99,7 @@ export default class ChatModel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// file
|
// file
|
||||||
this.fileModel.handleStringifiedFile(chatMessage.stringifiedFile ?? "");
|
this.fileModel.handleStringifiedFile(chatMessage.stringifiedFile);
|
||||||
};
|
};
|
||||||
|
|
||||||
// delete
|
// delete
|
||||||
@@ -151,7 +146,7 @@ export default class ChatModel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const sorted = messages.sort((a, b) =>
|
const sorted = messages.sort((a, b) =>
|
||||||
(a.dateSent ?? "").localeCompare(b.dateSent ?? "")
|
a.dateSent.localeCompare(b.dateSent)
|
||||||
);
|
);
|
||||||
return sorted;
|
return sorted;
|
||||||
}
|
}
|
||||||
@@ -162,7 +157,7 @@ export default class ChatModel {
|
|||||||
if (senderName == "") return false;
|
if (senderName == "") return false;
|
||||||
|
|
||||||
const allChannels = [this.info.primaryChannel];
|
const allChannels = [this.info.primaryChannel];
|
||||||
for (const secondaryChannel of this.info.secondaryChannels ?? []) {
|
for (const secondaryChannel of this.info.secondaryChannels) {
|
||||||
allChannels.push(secondaryChannel);
|
allChannels.push(secondaryChannel);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -171,7 +166,7 @@ export default class ChatModel {
|
|||||||
const chatMessage: ChatMessage = await ChatModel.createChatMessage(
|
const chatMessage: ChatMessage = await ChatModel.createChatMessage(
|
||||||
combinedChannel,
|
combinedChannel,
|
||||||
senderName,
|
senderName,
|
||||||
this.info.encryptionKey ?? "",
|
this.info.encryptionKey,
|
||||||
body,
|
body,
|
||||||
file
|
file
|
||||||
);
|
);
|
||||||
@@ -196,12 +191,12 @@ export default class ChatModel {
|
|||||||
|
|
||||||
decryptMessage = async (chatMessage: ChatMessage): Promise<void> => {
|
decryptMessage = async (chatMessage: ChatMessage): Promise<void> => {
|
||||||
const decryptedBody: string = await decryptString(
|
const decryptedBody: string = await decryptString(
|
||||||
chatMessage.body ?? "",
|
chatMessage.body,
|
||||||
this.info.encryptionKey ?? ""
|
this.info.encryptionKey
|
||||||
);
|
);
|
||||||
const decryptedFile: string = await decryptString(
|
const decryptedFile: string = await decryptString(
|
||||||
chatMessage.stringifiedFile ?? "",
|
chatMessage.stringifiedFile ?? "",
|
||||||
this.info.encryptionKey ?? ""
|
this.info.encryptionKey
|
||||||
);
|
);
|
||||||
chatMessage.body = decryptedBody;
|
chatMessage.body = decryptedBody;
|
||||||
chatMessage.stringifiedFile = decryptedFile;
|
chatMessage.stringifiedFile = decryptedFile;
|
||||||
@@ -212,8 +207,6 @@ export default class ChatModel {
|
|||||||
};
|
};
|
||||||
|
|
||||||
subscribe = (): void => {
|
subscribe = (): void => {
|
||||||
if (this.info.primaryChannel == undefined || this.info.primaryChannel == "")
|
|
||||||
return;
|
|
||||||
this.connectionModel.addChannel(this.info.primaryChannel);
|
this.connectionModel.addChannel(this.info.primaryChannel);
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -278,12 +271,9 @@ export default class ChatModel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (encryptionKey != "") {
|
if (encryptionKey != "") {
|
||||||
chatMessage.body = await encryptString(
|
chatMessage.body = await encryptString(chatMessage.body, encryptionKey);
|
||||||
chatMessage.body ?? "",
|
|
||||||
encryptionKey
|
|
||||||
);
|
|
||||||
chatMessage.stringifiedFile = await encryptString(
|
chatMessage.stringifiedFile = await encryptString(
|
||||||
chatMessage.stringifiedFile ?? "",
|
chatMessage.stringifiedFile,
|
||||||
encryptionKey
|
encryptionKey
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -294,11 +284,11 @@ export default class ChatModel {
|
|||||||
|
|
||||||
// types
|
// types
|
||||||
export interface ChatInfo extends ValidObject {
|
export interface ChatInfo extends ValidObject {
|
||||||
primaryChannel?: string;
|
primaryChannel: string;
|
||||||
secondaryChannels?: string[];
|
secondaryChannels: string[];
|
||||||
encryptionKey?: string;
|
encryptionKey: string;
|
||||||
|
|
||||||
hasUnreadMessages?: boolean;
|
hasUnreadMessages: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export enum ChatMessageStatus {
|
export enum ChatMessageStatus {
|
||||||
@@ -308,14 +298,14 @@ export enum ChatMessageStatus {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export interface ChatMessage extends ValidObject {
|
export interface ChatMessage extends ValidObject {
|
||||||
id?: string;
|
id: string;
|
||||||
|
|
||||||
channel?: string;
|
channel: string;
|
||||||
sender?: string;
|
sender: string;
|
||||||
body?: string;
|
body: string;
|
||||||
dateSent?: string;
|
dateSent: string;
|
||||||
|
|
||||||
status?: ChatMessageStatus;
|
status?: ChatMessageStatus;
|
||||||
|
|
||||||
stringifiedFile?: string;
|
stringifiedFile: string;
|
||||||
}
|
}
|
||||||
|
|||||||
+11
-14
@@ -26,7 +26,6 @@ export default class FileModel {
|
|||||||
|
|
||||||
// storage
|
// storage
|
||||||
storeFile = (file: File): void => {
|
storeFile = (file: File): void => {
|
||||||
if (file.contentVersions == undefined) return;
|
|
||||||
for (const fileContent of file.contentVersions) {
|
for (const fileContent of file.contentVersions) {
|
||||||
this.storeFileContent(file, fileContent);
|
this.storeFileContent(file, fileContent);
|
||||||
}
|
}
|
||||||
@@ -40,8 +39,7 @@ export default class FileModel {
|
|||||||
);
|
);
|
||||||
|
|
||||||
// check if fileContent already exists
|
// check if fileContent already exists
|
||||||
const existingFileContent: string | null =
|
const existingFileContent: string | null = this.storageModel.read(fileContentPath);
|
||||||
this.storageModel.read(fileContentPath);
|
|
||||||
if (existingFileContent != null) return;
|
if (existingFileContent != null) return;
|
||||||
|
|
||||||
const stringifiedContent: string = stringify(fileContent);
|
const stringifiedContent: string = stringify(fileContent);
|
||||||
@@ -53,7 +51,6 @@ export default class FileModel {
|
|||||||
};
|
};
|
||||||
|
|
||||||
listFileContents = (file: File): string[] => {
|
listFileContents = (file: File): string[] => {
|
||||||
if (file.id == undefined) return [];
|
|
||||||
const filePath: string[] = FileModel.getFilePath(file.id);
|
const filePath: string[] = FileModel.getFilePath(file.id);
|
||||||
return this.storageModel.list(filePath);
|
return this.storageModel.list(filePath);
|
||||||
};
|
};
|
||||||
@@ -91,14 +88,14 @@ export default class FileModel {
|
|||||||
};
|
};
|
||||||
|
|
||||||
static getFileContentName = (fileContent: FileContent): string => {
|
static getFileContentName = (fileContent: FileContent): string => {
|
||||||
return fileContent.creationDate ?? "" + fileContent.id ?? "";
|
return fileContent.creationDate + fileContent.id;
|
||||||
};
|
};
|
||||||
|
|
||||||
static getFileContentPath = (
|
static getFileContentPath = (
|
||||||
file: File,
|
file: File,
|
||||||
fileContentName: string
|
fileContentName: string
|
||||||
): string[] => {
|
): string[] => {
|
||||||
const filePath: string[] = FileModel.getFilePath(file.id ?? "");
|
const filePath: string[] = FileModel.getFilePath(file.id);
|
||||||
return [...filePath, fileContentName];
|
return [...filePath, fileContentName];
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -107,20 +104,20 @@ export default class FileModel {
|
|||||||
dataVersion: DATA_VERSION,
|
dataVersion: DATA_VERSION,
|
||||||
|
|
||||||
id: v4(),
|
id: v4(),
|
||||||
contentVersions: [],
|
contentVersions: []
|
||||||
};
|
}
|
||||||
};
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// types
|
// types
|
||||||
export interface File extends ValidObject {
|
export interface File extends ValidObject {
|
||||||
id?: string;
|
id: string;
|
||||||
contentVersions?: FileContent[];
|
contentVersions: FileContent[];
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface FileContent extends ValidObject {
|
export interface FileContent extends ValidObject {
|
||||||
id?: string;
|
id: string;
|
||||||
creationDate?: string;
|
creationDate: string;
|
||||||
|
|
||||||
type?: string;
|
type: string;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user