add methods to send message
This commit is contained in:
+21
-8
@@ -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
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user