Files
CT/src/ViewModel/Chat/chatMessageViewModel.ts
T

66 lines
1.7 KiB
TypeScript
Raw Normal View History

2024-07-21 01:12:35 +02:00
import * as React from "bloatless-react";
2024-07-22 19:52:08 +02:00
import { ChatMessage, ChatMessageStatus } from "../../Model/Chat/chatModel";
2024-07-21 01:12:35 +02:00
2024-07-22 21:07:44 +02:00
import MessagePageViewModel from "../Pages/messagePageViewModel";
2024-07-21 13:13:41 +02:00
2024-07-21 01:12:35 +02:00
export default class ChatMessageViewModel {
2024-07-22 21:07:44 +02:00
messagePageViewModel: MessagePageViewModel;
2024-07-21 01:12:35 +02:00
// data
2024-07-21 13:13:41 +02:00
chatMessage: ChatMessage;
2024-07-21 01:12:35 +02:00
channel: string;
sender: string;
dateSent: string;
body: React.State<string> = new React.State("");
status: React.State<ChatMessageStatus | any> = new React.State<
ChatMessageStatus | undefined
>(undefined);
2024-07-21 01:53:25 +02:00
sentByUser: boolean;
2024-07-23 13:09:46 +02:00
// state
isPresentingInfoModal: React.State<boolean> = new React.State(false);
2024-07-21 01:12:35 +02:00
2024-07-21 13:13:41 +02:00
// methods
copyMessage = (): void => {
navigator.clipboard.writeText(this.body.value);
};
resendMessage = (): void => {
2024-07-22 21:07:44 +02:00
this.messagePageViewModel.sendMessageFromBody(this.body.value);
2024-07-21 13:13:41 +02:00
};
decryptMessage = (): void => {
2024-07-22 21:07:44 +02:00
this.messagePageViewModel.decryptMessage(this);
2024-07-21 13:13:41 +02:00
};
2024-07-23 13:09:46 +02:00
// view
showInfoModal = (): void => {
this.isPresentingInfoModal.value = true;
}
hideInfoModal = (): void => {
this.isPresentingInfoModal.value = false;
}
2024-07-21 13:13:41 +02:00
// load
loadData = (): void => {
this.channel = this.chatMessage.channel;
this.sender = this.chatMessage.sender;
this.dateSent = new Date(this.chatMessage.dateSent).toLocaleString();
this.body.value = this.chatMessage.body;
this.status.value = this.chatMessage.status;
2024-07-21 13:13:41 +02:00
};
// init
2024-07-21 01:53:25 +02:00
constructor(
2024-07-22 21:07:44 +02:00
messagePageViewModel: MessagePageViewModel,
2024-07-21 01:53:25 +02:00
chatMessage: ChatMessage,
sentByUser: boolean
) {
2024-07-22 21:07:44 +02:00
this.messagePageViewModel = messagePageViewModel;
2024-07-21 01:12:35 +02:00
2024-07-21 13:13:41 +02:00
this.chatMessage = chatMessage;
2024-07-21 01:53:25 +02:00
this.sentByUser = sentByUser;
2024-07-21 13:13:41 +02:00
this.loadData();
2024-07-21 01:12:35 +02:00
}
}