remove upgrader

This commit is contained in:
marlon-erler
2026-09-27 01:58:06 +02:00
parent 6bde9e0627
commit 5ac0a54458
5 changed files with 14 additions and 304 deletions
+7 -7
View File
@@ -182,7 +182,7 @@ export default class ChatModel {
readonly getSendingData = (): [string, string, string] => {
const senderName: string = this.settingsModel.username || "?";
const id: string = this.settingsModel.userid;
const id: string = this.settingsModel.userid;
const allChannels: string[] = [this.id];
for (const secondaryChannel of this.info.secondaryChannels) {
@@ -203,7 +203,7 @@ export default class ChatModel {
const chatMessage: ChatMessage = await ChatModel.createChatMessage(
combinedChannel,
senderId,
senderId,
senderName,
this.info.encryptionKey,
body,
@@ -240,7 +240,7 @@ export default class ChatModel {
const reaction = ChatModel.createMessageReaction(
messageId,
senderId,
senderId,
content,
isDeleting,
);
@@ -396,7 +396,7 @@ export default class ChatModel {
static createChatMessage = async (
channel: string,
sender: string,
senderId: string,
senderId: string,
encryptionKey: string,
body: string,
inlineReplyId?: string,
@@ -409,7 +409,7 @@ export default class ChatModel {
channel,
sender,
senderId,
senderId,
body,
dateSent: createTimestamp(),
inlineReplyId,
@@ -438,7 +438,7 @@ export default class ChatModel {
static createMessageReaction = (
messageId: string,
senderId: string,
senderId: string,
content: ReactionSymbols,
isDeleting: boolean,
): ChatMessageReaction => {
@@ -449,7 +449,7 @@ export default class ChatModel {
fileId: ChatModel.createMessageReactionId(messageId, senderId),
messageId,
senderId,
senderId,
content,
isDeleting,
};
+6 -6
View File
@@ -1,5 +1,5 @@
import {UUID} from "../../react";
import StorageModel, { StorageModelSubPaths, filePaths } from "./storageModel";
import { UUID } from "../../react";
export default class SettingsModel {
readonly storageModel: StorageModel;
@@ -27,7 +27,7 @@ export default class SettingsModel {
this.userid = newValue;
this.storeSetting("userid", newValue);
};
readonly setName = (newValue: string): void => {
this.username = newValue;
this.storeSetting("username", newValue);
@@ -58,12 +58,12 @@ export default class SettingsModel {
);
return this.storageModel.read(path);
};
readonly loadId = (): void => {
const content: string | null = this.readSetting("userid");
const id = content ?? UUID();
const id = content ?? UUID();
if (content) this.userid = content;
else this.setId(id);
else this.setId(id);
};
readonly loadUsername = (): void => {
@@ -90,7 +90,7 @@ export default class SettingsModel {
constructor(storageModel: StorageModel) {
this.storageModel = storageModel;
this.loadId();
this.loadId();
this.loadUsername();
this.loadFirstDayofWeek();
this.loadLanguage();
+1 -1
View File
@@ -306,7 +306,7 @@ export const filePaths = {
settingsModel: {
username: ["user-name"],
userid: ["user-id"],
userid: ["user-id"],
firstDayOfWeek: ["first-day-of-week"],
language: ["language"],
theme: ["theme"],
-286
View File
@@ -1,286 +0,0 @@
// this file is responsible for migrating data from v1 to v2.
import { v4 } from "uuid";
import CoreViewModel from "../ViewModel/Global/coreViewModel";
import {
getLocalStorageItemAndClear,
parseArray,
parseOrFallback,
} from "../Model/Utility/utility";
import { checkMatchesObjectStructure } from "../Model/Utility/typeSafety";
import FileModel from "../Model/Files/fileModel";
import {
BoardInfoFileContent,
TaskFileContent,
} from "../Model/Files/boardsAndTasksModel";
import ChatModel, {
ChatMessage,
ChatMessageStatuses,
} from "../Model/Chat/chatModel";
export default class v1Upgrader {
// general
migrateSettings = (): void => {
const name: string | null = getLocalStorageItemAndClear("sender-name");
if (name != null) {
const parsedName: string = parseOrFallback(name);
this.coreViewModel.settingsModel.setName(parsedName);
}
const firstDayOfWeek: string | null =
getLocalStorageItemAndClear("first-day-of-week");
if (firstDayOfWeek != null) {
const parsedFirstDayOfWeek: string =
parseOrFallback(firstDayOfWeek);
this.coreViewModel.settingsModel.setFirstDayOfWeek(
parsedFirstDayOfWeek,
);
}
};
migrateConnections = (): void => {
const previousAddressString: string | null =
getLocalStorageItemAndClear("previous-addresses");
if (previousAddressString == null) return;
const previousAddresses: any[] = parseArray(previousAddressString);
for (const address of previousAddresses) {
if (typeof address != "string") continue;
this.coreViewModel.connectionModel.storeAddress(address);
}
};
// chats
migrateChats = (): void => {
const chatIdString: string | null =
getLocalStorageItemAndClear("chat-ids");
if (chatIdString == null) return;
const chatIds: any[] = parseArray(chatIdString);
for (const chatId of chatIds) {
if (typeof chatId != "string") continue;
this.migrateChatById(chatId);
}
};
migrateChatById = (id: string): void => {
// get primary channel
const primaryChannel: string | null = getLocalStorageItemAndClear(
storageKeys.primaryChannel(id),
);
if (primaryChannel == null) return;
const parsedPriamryChannel: string = parseOrFallback(primaryChannel);
// create chat
const chatModel: ChatModel =
this.coreViewModel.chatListModel.createChat(parsedPriamryChannel);
// secondary channels
const secondaryChannelString: string | null =
getLocalStorageItemAndClear(storageKeys.secondaryChannels(id));
if (secondaryChannelString != null) {
const potentialSecondaryChannels: any[] = parseArray(
secondaryChannelString,
);
const confirmedSecondaryChannels: string[] = [];
for (const secondaryChannel of potentialSecondaryChannels) {
if (typeof secondaryChannel != "string") continue;
confirmedSecondaryChannels.push(secondaryChannel);
}
chatModel.setSecondaryChannels(confirmedSecondaryChannels);
}
// encryption key
const encryptionKey: string | null = getLocalStorageItemAndClear(
storageKeys.encyptionKey(id),
);
if (encryptionKey != null) {
const parsedEncryptionKey: string = parseOrFallback(encryptionKey);
chatModel.setEncryptionKey(parsedEncryptionKey);
}
// messages
const messagesString: string =
getLocalStorageItemAndClear(storageKeys.messages(id)) ?? "";
const messageOutboxString: string =
getLocalStorageItemAndClear(storageKeys.outbox(id)) ?? "";
const potentialMessages: any[] = parseArray(messagesString);
const potentialMessagesInOutbox: any[] =
parseArray(messageOutboxString);
const addMessages = (
potentialMessages: any[],
status: ChatMessageStatuses,
) => {
for (const potentialMessage of potentialMessages) {
const isV1ChatMessage: boolean = checkMatchesObjectStructure(
potentialMessage,
V1ChatMessageReference,
);
if (isV1ChatMessage == false) continue;
const v1ChatMessage: typeof V1ChatMessageReference =
potentialMessage;
const convertedChatMessage: ChatMessage = {
dataVersion: "v2",
id: v4(),
channel: v1ChatMessage.channel,
sender: v1ChatMessage.sender,
body: v1ChatMessage.body,
dateSent: v1ChatMessage.isoDate,
status,
stringifiedFile: "",
};
chatModel.addMessage(convertedChatMessage);
if (status == ChatMessageStatuses.Outbox) {
this.coreViewModel.connectionModel.sendMessageOrStore(
convertedChatMessage,
);
}
}
};
addMessages(potentialMessages, ChatMessageStatuses.Received);
addMessages(potentialMessagesInOutbox, ChatMessageStatuses.Outbox);
// objects
const objectsString: string =
getLocalStorageItemAndClear(storageKeys.objects(id)) ?? "";
const objectOutboxString: string =
getLocalStorageItemAndClear(storageKeys.itemOutbox(id)) ?? "";
const potentialObjects: any[] = parseArray(objectsString);
const potentialObjectsInOutbox: any[] = parseArray(objectOutboxString);
const addObjects = (potentialObjects: any[]): void => {
const board: BoardInfoFileContent =
chatModel.fileModel.boardsAndTasksModel.createBoard(
this.coreViewModel.translations.updater.migrated,
);
chatModel.fileModel.boardsAndTasksModel.updateBoard(board);
for (const potentialObjectEntry of potentialObjects) {
const potentialObject = potentialObjectEntry[1];
const isV1MessageObject: boolean =
checkIsV1MessageObject(potentialObject);
if (isV1MessageObject == false) continue;
const objectId: string = potentialObject.id;
const objectName: string = potentialObject.title;
const contentVersions: any[] = Object.values(
potentialObject.contentVersions,
);
for (const potentialVersion of contentVersions) {
const isV1MessageObjectContent: boolean =
checkIsV1MessageObjectContent(potentialVersion);
if (isV1MessageObjectContent == false) continue;
const convertedTaskFileContent: TaskFileContent = {
dataVersion: "v2",
fileId: objectId,
fileContentId: FileModel.generateFileContentId(
potentialVersion.isoDateVersionCreated,
),
creationDate: potentialVersion.isoDateVersionCreated,
type: "task",
name: objectName ?? "",
boardId: board.fileId ?? "",
description: potentialVersion.noteContent ?? "",
category: potentialVersion.categoryName ?? "",
status: potentialVersion.status ?? "",
priority: potentialVersion.priority ?? "",
date: potentialVersion.date ?? "",
time: potentialVersion.time ?? "",
};
console.log(convertedTaskFileContent);
chatModel.fileModel.handleFileContent(
convertedTaskFileContent,
);
}
}
};
addObjects([...potentialObjects, ...potentialObjectsInOutbox]);
};
// init
constructor(public coreViewModel: CoreViewModel) {
this.migrateSettings();
this.migrateConnections();
this.migrateChats();
}
}
const storageKeys = {
viewType(id: string): string {
return id + "view-type";
},
hasUnread(id: string): string {
return id + "has-unread-messages";
},
primaryChannel(id: string): string {
return id + "primary-channel";
},
secondaryChannels(id: string): string {
return id + "secondary-channels";
},
encyptionKey(id: string): string {
return id + "encryption-key";
},
messages(id: string): string {
return id + "messages";
},
objects(id: string): string {
return id + "items";
},
outbox(id: string): string {
return id + "outbox";
},
itemOutbox(id: string): string {
return id + "item-outbox";
},
composingMessage(id: string): string {
return id + "composing-message";
},
};
const V1ChatMessageReference = {
channel: "",
sender: "",
body: "",
isoDate: "",
};
function checkIsV1MessageObject(object: any): boolean {
if (object.id == undefined) return false;
if (object.title == undefined) return false;
if (object.contentVersions == undefined) return false;
return true;
}
function checkIsV1MessageObjectContent(object: any): boolean {
if (object.id == undefined) return false;
if (object.isoDateVersionCreated == undefined) return false;
return true;
}
-4
View File
@@ -15,7 +15,6 @@ import { StorageModal } from "./View/Modals/storageModal";
import { SettingsModal } from "./View/Modals/settingsModal";
import { DataTransferModalWrapper } from "./View/Modals/dataTransferModal";
import { ConnectionModal } from "./View/Modals/connectionModal";
import v1Upgrader from "./Upgrader/v1";
import StorageModel from "./Model/Global/storageModel";
import SettingsModel from "./Model/Global/settingsModel";
import FileTransferModel from "./Model/Global/fileTransferModel";
@@ -42,9 +41,6 @@ const coreViewModel = new CoreViewModel(
fileTransferModel,
);
// upgrade
new v1Upgrader(coreViewModel);
const storageViewModel = new StorageViewModel(coreViewModel);
const settingsViewModel = new SettingsViewModel(coreViewModel);
const connectionViewModel = new ConnectionViewModel(coreViewModel);