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) {
this.info = info;
} else {
this.info = generateChatInfo("0");
this.info = ChatModel.generateChatInfo("0");
}
};
@@ -162,7 +162,20 @@ export class ChatModel {
// messaging
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
@@ -193,23 +206,22 @@ export class ChatModel {
this.restoreInfo();
this.restoreColor();
}
}
// creation methods
export function generateChatInfo(primaryChannel: string): ChatInfo {
// utility
static generateChatInfo = (primaryChannel: string): ChatInfo => {
return {
primaryChannel,
secondaryChannels: [],
encryptionKey: "",
hasUnreadMessages: false,
};
}
};
export function createChatMessage(
static createChatMessage = (
channel: string,
sender: string,
body: string
): ChatMessage {
): ChatMessage => {
return {
dataVersion: "v2",
@@ -220,6 +232,7 @@ export function createChatMessage(
body,
dateSent: createTimestamp(),
};
};
}
// types
+6
View File
@@ -102,6 +102,12 @@ export default class ChatViewModel {
this.chatListViewModel.restoreChats();
}
// messaging
sendMessage = (): void => {
this.chatModel.sendMessage(this.composingMessage.value);
this.composingMessage.value = "";
}
// restore
restorePageSelection = (): void => {
const path: string[] = storageKeys.chatLastUsedPage(this.chatModel.id);