fix bugs with message hiding
This commit is contained in:
@@ -95,6 +95,10 @@ export default class ChatModel {
|
|||||||
return [...this.getReactionDirPath(), id];
|
return [...this.getReactionDirPath(), id];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
readonly getPreviousFilterPath = (): string[] => {
|
||||||
|
return [StorageModelSubPaths.Chat, ...filePaths.chat.previousFilter(this.id)];
|
||||||
|
}
|
||||||
|
|
||||||
// handlers
|
// handlers
|
||||||
readonly handleMessage = (body: string): void => {
|
readonly handleMessage = (body: string): void => {
|
||||||
const chatMessage: ChatMessage | null = parseValidObject(
|
const chatMessage: ChatMessage | null = parseValidObject(
|
||||||
@@ -265,6 +269,14 @@ export default class ChatModel {
|
|||||||
this.storageModel.write(this.getColorPath(), this.color);
|
this.storageModel.write(this.getColorPath(), this.color);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
readonly storeFilter = (filter: string): void => {
|
||||||
|
this.storageModel.write(this.getPreviousFilterPath(), filter);
|
||||||
|
}
|
||||||
|
|
||||||
|
readonly getFilter = (): string => {
|
||||||
|
return this.storageModel.read(this.getPreviousFilterPath());
|
||||||
|
}
|
||||||
|
|
||||||
readonly delete = () => {
|
readonly delete = () => {
|
||||||
// untrack
|
// untrack
|
||||||
this.chatListModel.untrackChat(this);
|
this.chatListModel.untrackChat(this);
|
||||||
@@ -541,4 +553,4 @@ export const ChatMessageReactionReference: ChatMessageReaction = {
|
|||||||
content: "",
|
content: "",
|
||||||
|
|
||||||
isDeleting: false,
|
isDeleting: false,
|
||||||
};
|
}
|
||||||
|
|||||||
@@ -200,6 +200,7 @@ export default class FileModel {
|
|||||||
export enum FileModelSubPath {
|
export enum FileModelSubPath {
|
||||||
Data = "data",
|
Data = "data",
|
||||||
Model = "model",
|
Model = "model",
|
||||||
|
Chat = "chat",
|
||||||
ModelView = "view",
|
ModelView = "view",
|
||||||
ModelTask = "tasks",
|
ModelTask = "tasks",
|
||||||
ModelCalendar = "calendar",
|
ModelCalendar = "calendar",
|
||||||
|
|||||||
@@ -254,6 +254,7 @@ export const filePaths = {
|
|||||||
...filePaths.chat.chatBase(id),
|
...filePaths.chat.chatBase(id),
|
||||||
"reactions",
|
"reactions",
|
||||||
],
|
],
|
||||||
|
previousFilter: (id: string) => [...filePaths.chat.chatBase(id), "previous-filter"],
|
||||||
lastUsedPage: (id: string) => [
|
lastUsedPage: (id: string) => [
|
||||||
...filePaths.chat.chatBase(id),
|
...filePaths.chat.chatBase(id),
|
||||||
"last-used-page",
|
"last-used-page",
|
||||||
|
|||||||
@@ -99,109 +99,107 @@ export default class ChatMessageViewModel {
|
|||||||
this.isPresentingInfoModal.value = false;
|
this.isPresentingInfoModal.value = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
toggleHiding = (): void => {
|
||||||
|
let hideForReactions: boolean = false;
|
||||||
|
let hideForReplyView: boolean = false;
|
||||||
|
|
||||||
|
// reactions
|
||||||
|
const reactionFilter = this.messagePageViewModel.reactionFilter.value;
|
||||||
|
if (reactionFilter == undefined) {
|
||||||
|
hideForReactions = false;
|
||||||
|
} else {
|
||||||
|
let count: number = 0;
|
||||||
|
switch (reactionFilter) {
|
||||||
|
case ReactionSymbols.ThumbsUp: {
|
||||||
|
count = this.reactionsThumbsUpCount.value;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case ReactionSymbols.Check: {
|
||||||
|
count = this.reactionsCheckCount.value;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case ReactionSymbols.Stop: {
|
||||||
|
count = this.reactionsStopCount.value;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case ReactionSymbols.Attention: {
|
||||||
|
count = this.reactionsAttentionCount.value;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case ReactionSymbols.DoubleAttention: {
|
||||||
|
count = this.reactionsDoubleAttentionCount.value;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case ReactionSymbols.Question: {
|
||||||
|
count = this.reactionsQuestionCount.value;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
hideForReactions = count == 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// reply
|
||||||
|
const selectedMessage = this.messagePageViewModel.replyViewSelectedMessage.value;
|
||||||
|
if (selectedMessage == undefined) hideForReplyView = false;
|
||||||
|
else if (selectedMessage.chatMessage.id == this.chatMessage.id) hideForReplyView = false;
|
||||||
|
else if (this.inlineReply != undefined && selectedMessage.chatMessage.id == this.inlineReply.chatMessage.id) hideForReplyView = false;
|
||||||
|
else hideForReplyView = true;
|
||||||
|
|
||||||
|
this.isHidden.value = hideForReactions || hideForReplyView;
|
||||||
|
}
|
||||||
|
|
||||||
// reactions
|
// reactions
|
||||||
handleReaction = (reaction: ChatMessageReaction): void => {
|
handleReaction = (reaction: ChatMessageReaction): void => {
|
||||||
if (reaction.isDeleting) {
|
if (reaction.isDeleting) {
|
||||||
this.allReactions.remove(reaction.sender);
|
this.allReactions.remove(reaction.sender);
|
||||||
} else {
|
} else {
|
||||||
this.allReactions.set(reaction.sender, reaction);
|
this.allReactions.set(reaction.sender, reaction);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (reaction.sender != this.coreViewModel.settingsModel.username)
|
if (reaction.sender != this.coreViewModel.settingsModel.username)
|
||||||
return;
|
return;
|
||||||
this.userReaction.value = reaction.isDeleting
|
this.userReaction.value = reaction.isDeleting
|
||||||
? undefined
|
? undefined
|
||||||
: reaction.content;
|
: reaction.content;
|
||||||
};
|
};
|
||||||
|
|
||||||
sendReaction = (content: ReactionSymbols, isDeleting: boolean): void => {
|
sendReaction = (content: ReactionSymbols, isDeleting: boolean): void => {
|
||||||
this.messagePageViewModel.sendReaction(
|
this.messagePageViewModel.sendReaction(
|
||||||
this.chatMessage.id,
|
this.chatMessage.id,
|
||||||
content,
|
content,
|
||||||
isDeleting,
|
isDeleting,
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
// load
|
// load
|
||||||
loadData = (): void => {
|
loadData = (): void => {
|
||||||
this.channel = this.chatMessage.channel;
|
this.channel = this.chatMessage.channel;
|
||||||
this.sender = this.chatMessage.sender;
|
this.sender = this.chatMessage.sender;
|
||||||
this.dateSent = new Date(this.chatMessage.dateSent).toLocaleString();
|
this.dateSent = new Date(this.chatMessage.dateSent).toLocaleString();
|
||||||
this.body.value = this.chatMessage.body;
|
this.body.value = this.chatMessage.body;
|
||||||
this.status.value = this.chatMessage.status;
|
this.status.value = this.chatMessage.status;
|
||||||
|
|
||||||
if (this.chatMessage.inlineReplyId) {
|
if (this.chatMessage.inlineReplyId) {
|
||||||
this.inlineReply =
|
this.inlineReply =
|
||||||
this.messagePageViewModel.chatMessageViewModels.value.get(
|
this.messagePageViewModel.chatMessageViewModels.value.get(
|
||||||
this.chatMessage.inlineReplyId,
|
this.chatMessage.inlineReplyId,
|
||||||
);
|
);
|
||||||
this.inlineReply.replies.set(this.chatMessage.id, this);
|
this.inlineReply.replies.set(this.chatMessage.id, this);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// init
|
// init
|
||||||
constructor(
|
constructor(
|
||||||
public readonly coreViewModel: CoreViewModel,
|
public readonly coreViewModel: CoreViewModel,
|
||||||
public readonly messagePageViewModel: MessagePageViewModel,
|
public readonly messagePageViewModel: MessagePageViewModel,
|
||||||
chatMessage: ChatMessage,
|
chatMessage: ChatMessage,
|
||||||
sentByUser: boolean,
|
sentByUser: boolean,
|
||||||
) {
|
) {
|
||||||
this.chatMessage = chatMessage;
|
this.chatMessage = chatMessage;
|
||||||
this.sentByUser = sentByUser;
|
this.sentByUser = sentByUser;
|
||||||
this.loadData();
|
this.loadData();
|
||||||
|
|
||||||
let hideForReactions: boolean = false;
|
React.bulkSubscribe([this.messagePageViewModel.reactionFilter, this.messagePageViewModel.replyViewSelectedMessage, this.allReactions], this.toggleHiding);
|
||||||
let hideForReplyView: boolean = false;
|
this.toggleHiding();
|
||||||
|
|
||||||
const updateHiding = () => {
|
|
||||||
this.isHidden.value = hideForReactions || hideForReplyView;
|
|
||||||
}
|
|
||||||
|
|
||||||
this.messagePageViewModel.reactionFilter.subscribe((content) => {
|
|
||||||
if (content == undefined) {
|
|
||||||
hideForReactions = false;
|
|
||||||
updateHiding();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
let count: number = 0;
|
|
||||||
switch (content) {
|
|
||||||
case ReactionSymbols.ThumbsUp: {
|
|
||||||
count = this.reactionsThumbsUpCount.value;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case ReactionSymbols.Check: {
|
|
||||||
count = this.reactionsCheckCount.value;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case ReactionSymbols.Stop: {
|
|
||||||
count = this.reactionsStopCount.value;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case ReactionSymbols.Attention: {
|
|
||||||
count = this.reactionsAttentionCount.value;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case ReactionSymbols.DoubleAttention: {
|
|
||||||
count = this.reactionsDoubleAttentionCount.value;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case ReactionSymbols.Question: {
|
|
||||||
count = this.reactionsQuestionCount.value;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
hideForReactions = count == 0;
|
|
||||||
updateHiding();
|
|
||||||
});
|
|
||||||
|
|
||||||
this.messagePageViewModel.replyViewSelectedMessage.subscribe(selectedMessage => {
|
|
||||||
if (selectedMessage == undefined) hideForReplyView = false;
|
|
||||||
else if (selectedMessage.chatMessage.id == this.chatMessage.id) hideForReplyView = false;
|
|
||||||
else if (this.inlineReply != undefined && selectedMessage.chatMessage.id == this.inlineReply.chatMessage.id) hideForReplyView = false;
|
|
||||||
else hideForReplyView = true;
|
|
||||||
updateHiding();
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -127,10 +127,12 @@ export default class MessagePageViewModel extends Context {
|
|||||||
|
|
||||||
revokeReactionFilter = (): void => {
|
revokeReactionFilter = (): void => {
|
||||||
this.reactionFilter.value = undefined;
|
this.reactionFilter.value = undefined;
|
||||||
|
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);
|
||||||
};
|
};
|
||||||
|
|
||||||
resetFilter = (): void => {
|
resetFilter = (): void => {
|
||||||
@@ -196,6 +198,9 @@ export default class MessagePageViewModel extends Context {
|
|||||||
this.reactionFilter.value != undefined,
|
this.reactionFilter.value != undefined,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const previousFilter = this.chatViewModel.chatModel.getFilter() as any;
|
||||||
|
if (Object.values(ReactionSymbols).includes(previousFilter)) this.setReactionFilter(previousFilter);
|
||||||
|
|
||||||
// keystrokes
|
// keystrokes
|
||||||
this.registerKeyStroke(CommonKeys.Filter, this.showFilterModal);
|
this.registerKeyStroke(CommonKeys.Filter, this.showFilterModal);
|
||||||
this.registerKeyStroke(CommonKeys.CloseOrCancel, () => {
|
this.registerKeyStroke(CommonKeys.CloseOrCancel, () => {
|
||||||
|
|||||||
Reference in New Issue
Block a user