2024-07-20 04:17:10 +02:00
|
|
|
import * as React from "bloatless-react";
|
|
|
|
|
|
2024-07-20 14:16:26 +02:00
|
|
|
import ChatListViewModel from "./chatListViewModel";
|
2024-07-20 04:17:10 +02:00
|
|
|
import { ChatModel } from "../Model/chatModel";
|
|
|
|
|
import StorageModel from "../Model/storageModel";
|
|
|
|
|
|
|
|
|
|
export default class ChatViewModel {
|
2024-07-20 14:16:26 +02:00
|
|
|
chatModel: ChatModel;
|
|
|
|
|
chatListViewModel: ChatListViewModel;
|
2024-07-20 04:17:10 +02:00
|
|
|
|
2024-07-20 14:16:26 +02:00
|
|
|
// state
|
|
|
|
|
primaryChannel: React.State<string> = new React.State("");
|
|
|
|
|
primaryChannelInput: React.State<string> = new React.State("");
|
|
|
|
|
|
2024-07-20 16:28:00 +02:00
|
|
|
selectedPage: React.State<ChatPageType> = new React.State<ChatPageType>(
|
|
|
|
|
ChatPageType.Messages
|
|
|
|
|
);
|
|
|
|
|
|
2024-07-20 14:16:26 +02:00
|
|
|
// guards
|
|
|
|
|
cannotSetPrimaryChannel: React.State<boolean> = React.createProxyState(
|
|
|
|
|
[this.primaryChannel, this.primaryChannelInput],
|
|
|
|
|
() =>
|
|
|
|
|
this.primaryChannelInput.value == "" ||
|
|
|
|
|
this.primaryChannelInput.value == this.primaryChannel.value
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
// methods
|
|
|
|
|
open = () => {
|
|
|
|
|
this.chatListViewModel.openChat(this);
|
2024-07-20 16:28:00 +02:00
|
|
|
};
|
2024-07-20 14:16:26 +02:00
|
|
|
|
2024-07-20 15:49:58 +02:00
|
|
|
close = () => {
|
|
|
|
|
this.chatListViewModel.closeChat();
|
2024-07-20 16:28:00 +02:00
|
|
|
};
|
2024-07-20 15:49:58 +02:00
|
|
|
|
2024-07-20 14:16:26 +02:00
|
|
|
// init
|
|
|
|
|
constructor(chatListViewModel: ChatListViewModel, chatModel: ChatModel) {
|
|
|
|
|
this.chatModel = chatModel;
|
|
|
|
|
this.chatListViewModel = chatListViewModel;
|
|
|
|
|
|
|
|
|
|
this.primaryChannel.value = chatModel.info.primaryChannel;
|
|
|
|
|
this.primaryChannelInput.value = chatModel.info.primaryChannel;
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-07-20 16:28:00 +02:00
|
|
|
|
|
|
|
|
// types
|
|
|
|
|
export enum ChatPageType {
|
|
|
|
|
Settings,
|
|
|
|
|
Messages,
|
|
|
|
|
AllObjects,
|
|
|
|
|
Kanban,
|
|
|
|
|
Calendar,
|
|
|
|
|
Progress,
|
|
|
|
|
}
|