format
This commit is contained in:
@@ -17,7 +17,10 @@ export default class ChatMessageViewModel {
|
||||
body: React.State<string> = new React.State("");
|
||||
inlineReply: ChatMessageViewModel | undefined = undefined;
|
||||
replies: React.MapState<ChatMessageViewModel> = new React.MapState();
|
||||
replyCount: React.State<number> = React.createProxyState([this.replies], ()=>this.replies.value.size);
|
||||
replyCount: React.State<number> = React.createProxyState(
|
||||
[this.replies],
|
||||
() => this.replies.value.size,
|
||||
);
|
||||
status: React.State<ChatMessageStatuses | any> = new React.State<any>(
|
||||
undefined,
|
||||
);
|
||||
@@ -100,106 +103,119 @@ export default class ChatMessageViewModel {
|
||||
};
|
||||
|
||||
toggleHiding = (): void => {
|
||||
let hideForReactions: boolean = false;
|
||||
let hideForReplyView: boolean = false;
|
||||
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;
|
||||
}
|
||||
// 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;
|
||||
// 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;
|
||||
}
|
||||
this.isHidden.value = hideForReactions || hideForReplyView;
|
||||
};
|
||||
|
||||
// reactions
|
||||
handleReaction = (reaction: ChatMessageReaction): void => {
|
||||
if (reaction.isDeleting) {
|
||||
this.allReactions.remove(reaction.sender);
|
||||
} else {
|
||||
this.allReactions.set(reaction.sender, reaction);
|
||||
}
|
||||
if (reaction.isDeleting) {
|
||||
this.allReactions.remove(reaction.sender);
|
||||
} else {
|
||||
this.allReactions.set(reaction.sender, reaction);
|
||||
}
|
||||
|
||||
if (reaction.sender != this.coreViewModel.settingsModel.username)
|
||||
return;
|
||||
this.userReaction.value = reaction.isDeleting
|
||||
? undefined
|
||||
: reaction.content;
|
||||
if (reaction.sender != this.coreViewModel.settingsModel.username)
|
||||
return;
|
||||
this.userReaction.value = reaction.isDeleting
|
||||
? undefined
|
||||
: reaction.content;
|
||||
};
|
||||
|
||||
sendReaction = (content: ReactionSymbols, isDeleting: boolean): void => {
|
||||
this.messagePageViewModel.sendReaction(
|
||||
this.chatMessage.id,
|
||||
content,
|
||||
isDeleting,
|
||||
);
|
||||
this.messagePageViewModel.sendReaction(
|
||||
this.chatMessage.id,
|
||||
content,
|
||||
isDeleting,
|
||||
);
|
||||
};
|
||||
|
||||
// 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;
|
||||
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;
|
||||
|
||||
if (this.chatMessage.inlineReplyId) {
|
||||
this.inlineReply =
|
||||
this.messagePageViewModel.chatMessageViewModels.value.get(
|
||||
this.chatMessage.inlineReplyId,
|
||||
);
|
||||
this.inlineReply?.replies.set(this.chatMessage.id, this);
|
||||
}
|
||||
if (this.chatMessage.inlineReplyId) {
|
||||
this.inlineReply =
|
||||
this.messagePageViewModel.chatMessageViewModels.value.get(
|
||||
this.chatMessage.inlineReplyId,
|
||||
);
|
||||
this.inlineReply?.replies.set(this.chatMessage.id, this);
|
||||
}
|
||||
};
|
||||
|
||||
// init
|
||||
constructor(
|
||||
public readonly coreViewModel: CoreViewModel,
|
||||
public readonly messagePageViewModel: MessagePageViewModel,
|
||||
chatMessage: ChatMessage,
|
||||
sentByUser: boolean,
|
||||
public readonly coreViewModel: CoreViewModel,
|
||||
public readonly messagePageViewModel: MessagePageViewModel,
|
||||
chatMessage: ChatMessage,
|
||||
sentByUser: boolean,
|
||||
) {
|
||||
this.chatMessage = chatMessage;
|
||||
this.sentByUser = sentByUser;
|
||||
this.loadData();
|
||||
this.chatMessage = chatMessage;
|
||||
this.sentByUser = sentByUser;
|
||||
this.loadData();
|
||||
|
||||
React.bulkSubscribe([this.messagePageViewModel.reactionFilter, this.messagePageViewModel.replyViewSelectedMessage, this.allReactions], this.toggleHiding);
|
||||
this.toggleHiding();
|
||||
React.bulkSubscribe(
|
||||
[
|
||||
this.messagePageViewModel.reactionFilter,
|
||||
this.messagePageViewModel.replyViewSelectedMessage,
|
||||
this.allReactions,
|
||||
],
|
||||
this.toggleHiding,
|
||||
);
|
||||
this.toggleHiding();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user