apply filter when sending message
This commit is contained in:
@@ -198,7 +198,7 @@ export default class ChatModel {
|
|||||||
body: string,
|
body: string,
|
||||||
inlineReplyId?: string,
|
inlineReplyId?: string,
|
||||||
fileContent?: FileContent<string>,
|
fileContent?: FileContent<string>,
|
||||||
): Promise<boolean> => {
|
): Promise<string|false> => {
|
||||||
const nameAndChannel = this.getNameAndChannel();
|
const nameAndChannel = this.getNameAndChannel();
|
||||||
if (nameAndChannel == false) return false;
|
if (nameAndChannel == false) return false;
|
||||||
const [senderName, combinedChannel] = nameAndChannel;
|
const [senderName, combinedChannel] = nameAndChannel;
|
||||||
@@ -214,7 +214,7 @@ export default class ChatModel {
|
|||||||
|
|
||||||
this.addMessage(chatMessage);
|
this.addMessage(chatMessage);
|
||||||
this.connectionModel.sendMessageOrStore(chatMessage);
|
this.connectionModel.sendMessageOrStore(chatMessage);
|
||||||
return true;
|
return chatMessage.id;
|
||||||
};
|
};
|
||||||
|
|
||||||
readonly decryptMessage = async (
|
readonly decryptMessage = async (
|
||||||
|
|||||||
@@ -171,7 +171,6 @@ export default class CalendarPageViewModel extends TaskContainingPageViewModel {
|
|||||||
|
|
||||||
updateMonthGrid = (): void => {
|
updateMonthGrid = (): void => {
|
||||||
const today = formatISO(this.coreViewModel.todayDate.value)
|
const today = formatISO(this.coreViewModel.todayDate.value)
|
||||||
console.log(today, this.coreViewModel.todayDate.value);
|
|
||||||
if (
|
if (
|
||||||
this.currentTodayDate == today
|
this.currentTodayDate == today
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -35,111 +35,118 @@ export default class MessagePageViewModel extends Context {
|
|||||||
cannotSendMessage: React.State<boolean>;
|
cannotSendMessage: React.State<boolean>;
|
||||||
|
|
||||||
// methods
|
// methods
|
||||||
sendMessage = (): void => {
|
sendMessage = async (): Promise<void> => {
|
||||||
if (this.cannotSendMessage.value == true) return;
|
if (this.cannotSendMessage.value == true) return;
|
||||||
|
|
||||||
this.sendMessageFromBody(this.composingMessage.value);
|
const idPromise = this.sendMessageFromBody(this.composingMessage.value);
|
||||||
this.composingMessage.value = "";
|
this.composingMessage.value = "";
|
||||||
|
|
||||||
|
const id = await idPromise;
|
||||||
|
if (id && this.reactionFilter.value != undefined) {
|
||||||
|
this.sendReaction(id, this.reactionFilter.value, false);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
sendMessageFromBody = (body: string): void => {
|
sendMessageFromBody = (body: string): Promise<string|false>=> {
|
||||||
let replyId: string | undefined = undefined;
|
let replyId: string | undefined = undefined;
|
||||||
if (this.replyingMessage.value) {
|
if (this.replyingMessage.value) {
|
||||||
replyId = this.replyingMessage.value.chatMessage.id;
|
replyId = this.replyingMessage.value.chatMessage.id;
|
||||||
}
|
}
|
||||||
this.chatViewModel.chatModel.sendMessage(body, replyId);
|
const id = this.chatViewModel.chatModel.sendMessage(body, replyId);
|
||||||
|
|
||||||
if (this.replyViewSelectedMessage.value != undefined) return;
|
if (this.replyViewSelectedMessage.value == undefined)
|
||||||
this.replyingMessage.value = undefined;
|
this.replyingMessage.value = undefined;
|
||||||
|
|
||||||
|
return id;
|
||||||
};
|
};
|
||||||
|
|
||||||
decryptMessage = async (
|
decryptMessage = async (
|
||||||
messageViewModel: ChatMessageViewModel,
|
messageViewModel: ChatMessageViewModel,
|
||||||
): Promise<void> => {
|
): Promise<void> => {
|
||||||
const chatMessage: ChatMessage = messageViewModel.chatMessage;
|
const chatMessage: ChatMessage = messageViewModel.chatMessage;
|
||||||
await this.chatViewModel.chatModel.decryptMessage(chatMessage);
|
await this.chatViewModel.chatModel.decryptMessage(chatMessage);
|
||||||
this.chatViewModel.chatModel.addMessage(chatMessage);
|
this.chatViewModel.chatModel.addMessage(chatMessage);
|
||||||
messageViewModel.loadData();
|
messageViewModel.loadData();
|
||||||
};
|
};
|
||||||
|
|
||||||
sendReaction = (
|
sendReaction = (
|
||||||
messageId: string,
|
messageId: string,
|
||||||
content: ReactionSymbols,
|
content: ReactionSymbols,
|
||||||
isDeleting: boolean,
|
isDeleting: boolean,
|
||||||
): void => {
|
): void => {
|
||||||
this.chatViewModel.chatModel.sendReaction(
|
this.chatViewModel.chatModel.sendReaction(
|
||||||
messageId,
|
messageId,
|
||||||
content,
|
content,
|
||||||
isDeleting,
|
isDeleting,
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
setReply = (
|
setReply = (
|
||||||
chatMessageViewModel: ChatMessageViewModel | undefined,
|
chatMessageViewModel: ChatMessageViewModel | undefined,
|
||||||
setFocus: boolean = true,
|
setFocus: boolean = true,
|
||||||
): void => {
|
): void => {
|
||||||
this.replyingMessage.value = chatMessageViewModel;
|
this.replyingMessage.value = chatMessageViewModel;
|
||||||
if (setFocus == false || chatMessageViewModel == undefined) return;
|
if (setFocus == false || chatMessageViewModel == undefined) return;
|
||||||
this.setFocus();
|
this.setFocus();
|
||||||
};
|
};
|
||||||
|
|
||||||
resetReply = (setFocus: boolean = true): void => {
|
resetReply = (setFocus: boolean = true): void => {
|
||||||
this.replyingMessage.value = undefined;
|
this.replyingMessage.value = undefined;
|
||||||
if (setFocus == false) return;
|
if (setFocus == false) return;
|
||||||
this.setFocus();
|
this.setFocus();
|
||||||
};
|
};
|
||||||
|
|
||||||
// view
|
// view
|
||||||
showChatMessage = (chatMessage: ChatMessage): void => {
|
showChatMessage = (chatMessage: ChatMessage): void => {
|
||||||
const chatMessageViewModel = new ChatMessageViewModel(
|
const chatMessageViewModel = new ChatMessageViewModel(
|
||||||
this.coreViewModel,
|
this.coreViewModel,
|
||||||
this,
|
this,
|
||||||
chatMessage,
|
chatMessage,
|
||||||
chatMessage.sender ==
|
chatMessage.sender ==
|
||||||
this.chatViewModel.settingsViewModel.username.value,
|
this.chatViewModel.settingsViewModel.username.value,
|
||||||
);
|
);
|
||||||
|
|
||||||
const existingChatMessageViewModel: ChatMessageViewModel | undefined =
|
const existingChatMessageViewModel: ChatMessageViewModel | undefined =
|
||||||
this.chatMessageViewModels.value.get(chatMessage.id);
|
this.chatMessageViewModels.value.get(chatMessage.id);
|
||||||
if (existingChatMessageViewModel != undefined) {
|
if (existingChatMessageViewModel != undefined) {
|
||||||
existingChatMessageViewModel.body.value = chatMessage.body;
|
existingChatMessageViewModel.body.value = chatMessage.body;
|
||||||
existingChatMessageViewModel.status.value = chatMessage.status;
|
existingChatMessageViewModel.status.value = chatMessage.status;
|
||||||
} else {
|
} else {
|
||||||
this.chatMessageViewModels.set(
|
this.chatMessageViewModels.set(
|
||||||
chatMessage.id,
|
chatMessage.id,
|
||||||
chatMessageViewModel,
|
chatMessageViewModel,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
handleReaction = (reaction: ChatMessageReaction): void => {
|
handleReaction = (reaction: ChatMessageReaction): void => {
|
||||||
const messageViewModel: ChatMessageViewModel | undefined =
|
const messageViewModel: ChatMessageViewModel | undefined =
|
||||||
this.chatMessageViewModels.value.get(reaction.messageId);
|
this.chatMessageViewModels.value.get(reaction.messageId);
|
||||||
if (messageViewModel == undefined) return;
|
if (messageViewModel == undefined) return;
|
||||||
messageViewModel.handleReaction(reaction);
|
messageViewModel.handleReaction(reaction);
|
||||||
};
|
};
|
||||||
|
|
||||||
showFilterModal = (): void => {
|
showFilterModal = (): void => {
|
||||||
this.isFilterModalOpen.value = true;
|
this.isFilterModalOpen.value = true;
|
||||||
};
|
};
|
||||||
|
|
||||||
hideFilterModal = (): void => {
|
hideFilterModal = (): void => {
|
||||||
this.isFilterModalOpen.value = false;
|
this.isFilterModalOpen.value = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
revokeReactionFilter = (persist: boolean = true): void => {
|
revokeReactionFilter = (persist: boolean = true): void => {
|
||||||
this.reactionFilter.value = undefined;
|
this.reactionFilter.value = undefined;
|
||||||
if (persist) this.chatViewModel.chatModel.storeFilter("");
|
if (persist) this.chatViewModel.chatModel.storeFilter("");
|
||||||
};
|
};
|
||||||
|
|
||||||
setReactionFilter = (content: ReactionSymbols): void => {
|
setReactionFilter = (content: ReactionSymbols): void => {
|
||||||
this.reactionFilter.value = content;
|
this.reactionFilter.value = content;
|
||||||
this.chatViewModel.chatModel.storeFilter(content);
|
this.chatViewModel.chatModel.storeFilter(content);
|
||||||
};
|
};
|
||||||
|
|
||||||
resetFilter = (): void => {
|
resetFilter = (): void => {
|
||||||
this.revokeReactionFilter();
|
this.revokeReactionFilter();
|
||||||
this.searchViewModel.search("");
|
this.searchViewModel.search("");
|
||||||
};
|
};
|
||||||
|
|
||||||
setReplyView = (message: ChatMessageViewModel): void => {
|
setReplyView = (message: ChatMessageViewModel): void => {
|
||||||
@@ -155,18 +162,18 @@ export default class MessagePageViewModel extends Context {
|
|||||||
}
|
}
|
||||||
|
|
||||||
setFocus = (): void => {
|
setFocus = (): void => {
|
||||||
this.focusSetter.callSubscriptions();
|
this.focusSetter.callSubscriptions();
|
||||||
};
|
};
|
||||||
|
|
||||||
// load
|
// load
|
||||||
loadData = (): void => {
|
loadData = (): void => {
|
||||||
this.chatMessageViewModels.clear();
|
this.chatMessageViewModels.clear();
|
||||||
for (const chatMessage of this.chatViewModel.chatModel.messages) {
|
for (const chatMessage of this.chatViewModel.chatModel.messages) {
|
||||||
this.showChatMessage(chatMessage);
|
this.showChatMessage(chatMessage);
|
||||||
}
|
}
|
||||||
for (const reaction of this.chatViewModel.chatModel.reactions) {
|
for (const reaction of this.chatViewModel.chatModel.reactions) {
|
||||||
this.handleReaction(reaction);
|
this.handleReaction(reaction);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
restoreFilter = (): void => {
|
restoreFilter = (): void => {
|
||||||
@@ -176,49 +183,49 @@ export default class MessagePageViewModel extends Context {
|
|||||||
|
|
||||||
// init
|
// init
|
||||||
constructor(
|
constructor(
|
||||||
public readonly coreViewModel: CoreViewModel,
|
public readonly coreViewModel: CoreViewModel,
|
||||||
public readonly chatViewModel: ChatViewModel,
|
public readonly chatViewModel: ChatViewModel,
|
||||||
) {
|
) {
|
||||||
super("message-page");
|
super("message-page");
|
||||||
this.restoreFilter();
|
this.restoreFilter();
|
||||||
|
|
||||||
// states
|
// states
|
||||||
this.cannotSendMessage = React.createProxyState(
|
this.cannotSendMessage = React.createProxyState(
|
||||||
[
|
[
|
||||||
this.chatViewModel.settingsViewModel.username,
|
this.chatViewModel.settingsViewModel.username,
|
||||||
this.composingMessage,
|
this.composingMessage,
|
||||||
],
|
],
|
||||||
() =>
|
() =>
|
||||||
this.chatViewModel.settingsViewModel.username.value == "" ||
|
this.chatViewModel.settingsViewModel.username.value == "" ||
|
||||||
this.composingMessage.value == "",
|
this.composingMessage.value == "",
|
||||||
);
|
);
|
||||||
|
|
||||||
this.searchViewModel = new SearchViewModel(
|
this.searchViewModel = new SearchViewModel(
|
||||||
this.chatMessageViewModels,
|
this.chatMessageViewModels,
|
||||||
this.filteredMessageViewModels,
|
this.filteredMessageViewModels,
|
||||||
(chatMessageViewModel) => [chatMessageViewModel.body.value],
|
(chatMessageViewModel) => [chatMessageViewModel.body.value],
|
||||||
new React.ListState(),
|
new React.ListState(),
|
||||||
);
|
);
|
||||||
|
|
||||||
this.isFilterActive = React.createProxyState(
|
this.isFilterActive = React.createProxyState(
|
||||||
[this.searchViewModel.appliedQuery, this.reactionFilter],
|
[this.searchViewModel.appliedQuery, this.reactionFilter],
|
||||||
() =>
|
() =>
|
||||||
this.searchViewModel.appliedQuery.value != "" ||
|
this.searchViewModel.appliedQuery.value != "" ||
|
||||||
this.reactionFilter.value != undefined,
|
this.reactionFilter.value != undefined,
|
||||||
);
|
);
|
||||||
|
|
||||||
// keystrokes
|
// keystrokes
|
||||||
this.registerKeyStroke(CommonKeys.Filter, this.showFilterModal);
|
this.registerKeyStroke(CommonKeys.Filter, this.showFilterModal);
|
||||||
this.registerKeyStroke(CommonKeys.CloseOrCancel, () => {
|
this.registerKeyStroke(CommonKeys.CloseOrCancel, () => {
|
||||||
if (this.isFilterModalOpen.value == true) {
|
if (this.isFilterModalOpen.value == true) {
|
||||||
this.hideFilterModal();
|
this.hideFilterModal();
|
||||||
} else {
|
} else {
|
||||||
this.replyingMessage.value = undefined;
|
this.replyingMessage.value = undefined;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
this.registerKeyStroke(CommonKeys.Reset, this.resetFilter);
|
this.registerKeyStroke(CommonKeys.Reset, this.resetFilter);
|
||||||
this.registerKeyStroke(CommonKeys.Create, this.setFocus);
|
this.registerKeyStroke(CommonKeys.Create, this.setFocus);
|
||||||
|
|
||||||
this.chatViewModel.registerContext(ChatPageTypes.Messages, this);
|
this.chatViewModel.registerContext(ChatPageTypes.Messages, this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user