move chat color into chat info file

This commit is contained in:
marlon-erler
2026-09-26 14:34:25 +02:00
parent 084a402f43
commit bae7d21f04
+15 -20
View File
@@ -35,12 +35,17 @@ export default class ChatModel {
// data // data
readonly id: string; readonly id: string;
info: ChatInfoFileContent; /* load function called in constructor */ info: ChatInfoFileContent; /* load function called in constructor */
color: Colors = Colors.Standard;
get secondaryChannels(): string[] { get secondaryChannels(): string[] {
return this.info.secondaryChannels.sort(localeCompare); return this.info.secondaryChannels.sort(localeCompare);
} }
get color(): Colors {
const color = this.info.color as Colors;
if ([...Object.values(Colors)].includes(color)) return color;
return Colors.Standard;
}
// handler managers // handler managers
chatMessageHandlerManager: HandlerManager<ChatMessage> = chatMessageHandlerManager: HandlerManager<ChatMessage> =
new HandlerManager(); new HandlerManager();
@@ -149,8 +154,8 @@ export default class ChatModel {
}; };
readonly setColor = (color: Colors): void => { readonly setColor = (color: Colors): void => {
this.color = color; this.info.color = color;
this.storeColor(); this.storeInfo();
}; };
// messaging // messaging
@@ -255,10 +260,6 @@ export default class ChatModel {
this.storageModel.writeStringifiable(this.getInfoPath(), this.info); this.storageModel.writeStringifiable(this.getInfoPath(), this.info);
}; };
readonly storeColor = (): void => {
this.storageModel.write(this.getColorPath(), this.color);
};
readonly storeFilter = (filter: string): void => { readonly storeFilter = (filter: string): void => {
this.storageModel.write(this.getPreviousFilterPath(), filter); this.storageModel.write(this.getPreviousFilterPath(), filter);
} }
@@ -285,17 +286,7 @@ export default class ChatModel {
if (info != null) { if (info != null) {
this.info = info; this.info = info;
} else { } else {
this.info = ChatModel.generateChatInfo("0", "0"); this.info = ChatModel.generateChatInfo("0", "0", Colors.Standard );
}
};
readonly loadColor = (): void => {
const path: string[] = this.getColorPath();
const color: string | null = this.storageModel.read(path);
if (!color) {
this.color = Colors.Standard;
} else {
this.color = color as any;
} }
}; };
@@ -359,7 +350,6 @@ export default class ChatModel {
this.chatListModel = chatListModel; this.chatListModel = chatListModel;
this.loadInfo(); this.loadInfo();
this.loadColor();
this.subscribe(); this.subscribe();
this.fileModel = new FileModel( this.fileModel = new FileModel(
@@ -374,7 +364,7 @@ export default class ChatModel {
return channelString.split("/"); return channelString.split("/");
} }
static generateChatInfo = (name: string, id: string): ChatInfoFileContent => { static generateChatInfo = (name: string, id: string, color: Colors): ChatInfoFileContent => {
const file = FileModel.createFileContent(id, "chat-info"); const file = FileModel.createFileContent(id, "chat-info");
return { return {
@@ -383,6 +373,7 @@ export default class ChatModel {
name, name,
secondaryChannels: [], secondaryChannels: [],
encryptionKey: "", encryptionKey: "",
color,
hasUnreadMessages: false, hasUnreadMessages: false,
}; };
}; };
@@ -471,6 +462,8 @@ export interface ChatInfoFileContent extends FileContent<"chat-info"> {
secondaryChannels: string[]; secondaryChannels: string[];
encryptionKey: string; encryptionKey: string;
color: string;
hasUnreadMessages: boolean; hasUnreadMessages: boolean;
} }
@@ -517,6 +510,8 @@ export const ChatInfoReference: ChatInfoFileContent = {
secondaryChannels: [""], secondaryChannels: [""],
encryptionKey: "", encryptionKey: "",
color: "",
hasUnreadMessages: true, hasUnreadMessages: true,
}; };