2024-07-21 01:12:35 +02:00
|
|
|
import * as React from "bloatless-react";
|
|
|
|
|
|
2026-04-06 20:47:49 +00:00
|
|
|
import {
|
|
|
|
|
ChatMessage,
|
|
|
|
|
ChatMessageReaction,
|
|
|
|
|
ChatMessageReactionReference,
|
|
|
|
|
ChatMessageStatus,
|
|
|
|
|
ReactionSymbol,
|
|
|
|
|
} from "../../Model/Chat/chatModel";
|
2024-07-21 01:12:35 +02:00
|
|
|
|
2024-07-25 16:02:49 +02:00
|
|
|
import CoreViewModel from "../Global/coreViewModel";
|
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 {
|
2026-04-01 08:29:39 +00:00
|
|
|
messagePageViewModel: MessagePageViewModel;
|
2024-07-21 01:12:35 +02:00
|
|
|
|
2026-04-01 08:29:39 +00:00
|
|
|
// data
|
|
|
|
|
chatMessage: ChatMessage;
|
|
|
|
|
channel: string;
|
|
|
|
|
sender: string;
|
|
|
|
|
dateSent: string;
|
|
|
|
|
body: React.State<string> = new React.State("");
|
|
|
|
|
status: React.State<ChatMessageStatus | any> = new React.State<any>(
|
|
|
|
|
undefined,
|
|
|
|
|
);
|
|
|
|
|
sentByUser: boolean;
|
2024-07-26 03:14:55 +02:00
|
|
|
|
2026-04-06 20:47:49 +00:00
|
|
|
reactionsThumbsUp = new React.MapState<ChatMessageReaction>();
|
|
|
|
|
reactionsCheck = new React.MapState<ChatMessageReaction>();
|
|
|
|
|
reactionsAttention = new React.MapState<ChatMessageReaction>();
|
|
|
|
|
reactionsDoubleAttention = new React.MapState<ChatMessageReaction>();
|
|
|
|
|
reactionsQuestion = new React.MapState<ChatMessageReaction>();
|
|
|
|
|
|
2026-04-01 08:29:39 +00:00
|
|
|
// state
|
|
|
|
|
isPresentingInfoModal: React.State<boolean> = new React.State(false);
|
2024-07-21 01:12:35 +02:00
|
|
|
|
2026-04-01 08:29:39 +00:00
|
|
|
// methods
|
|
|
|
|
copyMessage = (): void => {
|
|
|
|
|
navigator.clipboard.writeText(this.body.value);
|
|
|
|
|
};
|
|
|
|
|
resendMessage = (): void => {
|
|
|
|
|
this.messagePageViewModel.sendMessageFromBody(this.body.value);
|
|
|
|
|
};
|
|
|
|
|
decryptMessage = (): void => {
|
|
|
|
|
this.messagePageViewModel.decryptMessage(this);
|
|
|
|
|
};
|
2024-07-21 13:13:41 +02:00
|
|
|
|
2026-04-01 08:29:39 +00:00
|
|
|
// view
|
|
|
|
|
showInfoModal = (): void => {
|
|
|
|
|
this.isPresentingInfoModal.value = true;
|
|
|
|
|
};
|
2024-07-23 13:09:46 +02:00
|
|
|
|
2026-04-01 08:29:39 +00:00
|
|
|
hideInfoModal = (): void => {
|
|
|
|
|
this.isPresentingInfoModal.value = false;
|
|
|
|
|
};
|
2024-07-23 13:09:46 +02:00
|
|
|
|
2026-04-06 20:47:49 +00:00
|
|
|
// reactions
|
|
|
|
|
addReaction = (reaction: ChatMessageReaction): void => {
|
|
|
|
|
switch (reaction.content) {
|
|
|
|
|
case "👍":
|
|
|
|
|
return this.reactionsThumbsUp.set(reaction.fileId, reaction);
|
|
|
|
|
case "✅":
|
|
|
|
|
return this.reactionsCheck.set(reaction.fileId, reaction);
|
|
|
|
|
case "❗️":
|
|
|
|
|
return this.reactionsAttention.set(reaction.fileId, reaction);
|
|
|
|
|
case "‼️":
|
|
|
|
|
return this.reactionsDoubleAttention.set(
|
|
|
|
|
reaction.fileId,
|
|
|
|
|
reaction,
|
|
|
|
|
);
|
|
|
|
|
case "❓":
|
|
|
|
|
return this.reactionsQuestion.set(reaction.fileId, reaction);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2026-04-01 08:29:39 +00: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
|
|
|
|
2026-04-01 08:29:39 +00:00
|
|
|
// init
|
|
|
|
|
constructor(
|
|
|
|
|
public coreViewModel: CoreViewModel,
|
|
|
|
|
messagePageViewModel: MessagePageViewModel,
|
|
|
|
|
chatMessage: ChatMessage,
|
|
|
|
|
sentByUser: boolean,
|
|
|
|
|
) {
|
|
|
|
|
this.messagePageViewModel = messagePageViewModel;
|
2024-07-21 01:12:35 +02:00
|
|
|
|
2026-04-01 08:29:39 +00:00
|
|
|
this.chatMessage = chatMessage;
|
|
|
|
|
this.sentByUser = sentByUser;
|
|
|
|
|
this.loadData();
|
|
|
|
|
}
|
2024-07-21 01:12:35 +02:00
|
|
|
}
|