add methods to send message

This commit is contained in:
marlon-erler
2024-07-20 20:53:48 +02:00
parent 819c8f4cac
commit 9f93856829
2 changed files with 42 additions and 23 deletions
+21 -8
View File
@@ -118,7 +118,7 @@ export class ChatModel {
if (info != null) { if (info != null) {
this.info = info; this.info = info;
} else { } else {
this.info = generateChatInfo("0"); this.info = ChatModel.generateChatInfo("0");
} }
}; };
@@ -162,7 +162,20 @@ export class ChatModel {
// messaging // messaging
sendMessage = (body: string): void => { sendMessage = (body: string): void => {
//TODO const allChannels = [this.info.primaryChannel];
for (const secondaryChannel of this.info.secondaryChannels) {
allChannels.push(secondaryChannel);
}
const combinedChannel = allChannels.join("/");
const chatMessage: ChatMessage = ChatModel.createChatMessage(
combinedChannel,
this.settingsModel.username,
body
);
this.connectionModel.sendMessageOrStore(chatMessage);
}; };
// memory // memory
@@ -193,23 +206,22 @@ export class ChatModel {
this.restoreInfo(); this.restoreInfo();
this.restoreColor(); this.restoreColor();
} }
}
// creation methods // utility
export function generateChatInfo(primaryChannel: string): ChatInfo { static generateChatInfo = (primaryChannel: string): ChatInfo => {
return { return {
primaryChannel, primaryChannel,
secondaryChannels: [], secondaryChannels: [],
encryptionKey: "", encryptionKey: "",
hasUnreadMessages: false, hasUnreadMessages: false,
}; };
} };
export function createChatMessage( static createChatMessage = (
channel: string, channel: string,
sender: string, sender: string,
body: string body: string
): ChatMessage { ): ChatMessage => {
return { return {
dataVersion: "v2", dataVersion: "v2",
@@ -220,6 +232,7 @@ export function createChatMessage(
body, body,
dateSent: createTimestamp(), dateSent: createTimestamp(),
}; };
};
} }
// types // types
+6
View File
@@ -102,6 +102,12 @@ export default class ChatViewModel {
this.chatListViewModel.restoreChats(); this.chatListViewModel.restoreChats();
} }
// messaging
sendMessage = (): void => {
this.chatModel.sendMessage(this.composingMessage.value);
this.composingMessage.value = "";
}
// restore // restore
restorePageSelection = (): void => { restorePageSelection = (): void => {
const path: string[] = storageKeys.chatLastUsedPage(this.chatModel.id); const path: string[] = storageKeys.chatLastUsedPage(this.chatModel.id);