sync changes to chat info

This commit is contained in:
marlon-erler
2026-09-26 15:16:16 +02:00
parent bae7d21f04
commit 2835510992
5 changed files with 375 additions and 346 deletions
+15 -6
View File
@@ -47,10 +47,11 @@ export default class ChatModel {
} }
// handler managers // handler managers
chatMessageHandlerManager: HandlerManager<ChatMessage> = readonly chatMessageHandlerManager: HandlerManager<ChatMessage> =
new HandlerManager(); new HandlerManager();
readonly reactionHandlerManager: HandlerManager<ChatMessageReaction> = readonly reactionHandlerManager: HandlerManager<ChatMessageReaction> =
new HandlerManager(); new HandlerManager();
readonly changeHandlerManager: HandlerManager<null> = new HandlerManager();
// paths // paths
readonly getBasePath = (): string[] => { readonly getBasePath = (): string[] => {
@@ -140,6 +141,7 @@ export default class ChatModel {
readonly setName = (name: string): void => { readonly setName = (name: string): void => {
this.info.name = name; this.info.name = name;
this.storeInfo(); this.storeInfo();
this.syncInfo();
this.subscribe(); this.subscribe();
}; };
@@ -155,6 +157,7 @@ export default class ChatModel {
readonly setColor = (color: Colors): void => { readonly setColor = (color: Colors): void => {
this.info.color = color; this.info.color = color;
this.syncInfo();
this.storeInfo(); this.storeInfo();
}; };
@@ -260,6 +263,10 @@ export default class ChatModel {
this.storageModel.writeStringifiable(this.getInfoPath(), this.info); this.storageModel.writeStringifiable(this.getInfoPath(), this.info);
}; };
readonly syncInfo = (): void => {
this.sendMessage("", undefined, this.info);
}
readonly storeFilter = (filter: string): void => { readonly storeFilter = (filter: string): void => {
this.storageModel.write(this.getPreviousFilterPath(), filter); this.storageModel.write(this.getPreviousFilterPath(), filter);
} }
@@ -283,13 +290,15 @@ export default class ChatModel {
this.getInfoPath(), this.getInfoPath(),
ChatInfoReference, ChatInfoReference,
); );
if (info != null) { this.info = (info || ChatModel.generateChatInfo("0", "0", Colors.Standard));
this.info = info;
} else {
this.info = ChatModel.generateChatInfo("0", "0", Colors.Standard );
}
}; };
readonly handleInfo = (info: ChatInfoFileContent): void => {
this.info = info;
this.changeHandlerManager.trigger(null);
this.storeInfo();
}
get messages(): ChatMessage[] { get messages(): ChatMessage[] {
const messageIds: string[] = this.storageModel.list( const messageIds: string[] = this.storageModel.list(
this.getMessageDirPath(), this.getMessageDirPath(),
+8 -2
View File
@@ -8,13 +8,13 @@ import {
parseValidObject, parseValidObject,
stringify, stringify,
} from "../Utility/utility"; } from "../Utility/utility";
import { DATA_VERSION, ValidObject } from "../Utility/typeSafety"; import { checkIsValidObject, checkMatchesObjectStructure, DATA_VERSION, ValidObject } from "../Utility/typeSafety";
import StorageModel, { import StorageModel, {
StorageModelSubPaths, StorageModelSubPaths,
filePaths, filePaths,
} from "../Global/storageModel"; } from "../Global/storageModel";
import SettingsModel from "../Global/settingsModel"; import SettingsModel from "../Global/settingsModel";
import ChatModel from "../Chat/chatModel"; import ChatModel, {ChatInfoFileContent, ChatInfoReference} from "../Chat/chatModel";
export default class FileModel { export default class FileModel {
readonly storageModel: StorageModel; readonly storageModel: StorageModel;
@@ -67,6 +67,12 @@ export default class FileModel {
}; };
readonly handleFileContent = (fileContent: FileContent<string>): void => { readonly handleFileContent = (fileContent: FileContent<string>): void => {
if (fileContent.type == "chat-info") {
if (checkMatchesObjectStructure(fileContent, ChatInfoReference) == false) return;
console.log("CHANGING");
this.chatModel.handleInfo(fileContent as ChatInfoFileContent);
}
const didStore: boolean = this.storeFileContent(fileContent); const didStore: boolean = this.storeFileContent(fileContent);
if (didStore == false) return; if (didStore == false) return;
+17
View File
@@ -179,6 +179,23 @@ export function SettingsPage(
{ColorPicker(settingsPageViewModel.color)} {ColorPicker(settingsPageViewModel.color)}
<div class="flex-row justify-end width-input">
<button
class="width-50"
aria-label={
coreViewModel.translations.chatPage.settings
.setNameButtonAudioLabel
}
on:click={
settingsPageViewModel.applyColor
}
>
{coreViewModel.translations.general.setButton}
<span class="icon">check</span>
</button>
</div>
<hr></hr> <hr></hr>
<div class="width-input"> <div class="width-input">
+1
View File
@@ -189,6 +189,7 @@ export default class ChatViewModel extends ContextHost<ChatPageTypes> {
this.messagePageViewModel.handleReaction(reaction); this.messagePageViewModel.handleReaction(reaction);
}, },
); );
chatModel.changeHandlerManager.setHandler(this.chatModel.id, this.settingsPageViewModel.preloadData);
// load // load
this.loadPageSelection(); this.loadPageSelection();
+2 -6
View File
@@ -71,8 +71,8 @@ export default class SettingsPageViewModel extends Context {
this.encryptionKeyInput.callSubscriptions(); this.encryptionKeyInput.callSubscriptions();
}; };
applyColor = (newColor: Colors): void => { applyColor = (): void => {
this.chatViewModel.setColor(newColor); this.chatViewModel.setColor(this.color.value);
}; };
remove = (): void => { remove = (): void => {
@@ -122,10 +122,6 @@ export default class SettingsPageViewModel extends Context {
this.chatViewModel.chatModel.info.encryptionKey, this.chatViewModel.chatModel.info.encryptionKey,
); );
this.color.subscribe((newColor) => {
this.applyColor(newColor);
});
this.chatViewModel.registerContext(ChatPageTypes.Settings, this); this.chatViewModel.registerContext(ChatPageTypes.Settings, this);
} }
} }