FIX: ensures chat-message is recomputed with model (#20312)

The message model is not yet using tracked properties and as a result we were not correctly recomputing on various cases.
This commit is contained in:
Joffrey JAFFEUX 2023-02-15 15:08:55 +01:00 committed by GitHub
parent 075af7ba84
commit 61934afbb1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 46 additions and 28 deletions

View File

@ -72,15 +72,15 @@ export default class ChatMessage extends Component {
} }
get deletedAndCollapsed() { get deletedAndCollapsed() {
return this.args.message?.deleted_at && this.collapsed; return this.args.message?.get("deleted_at") && this.collapsed;
} }
get hiddenAndCollapsed() { get hiddenAndCollapsed() {
return this.args.message?.hidden && this.collapsed; return this.args.message?.get("hidden") && this.collapsed;
} }
get collapsed() { get collapsed() {
return !this.args.message?.expanded; return !this.args.message?.get("expanded");
} }
@action @action
@ -169,7 +169,7 @@ export default class ChatMessage extends Component {
get showActions() { get showActions() {
return ( return (
this.args.canInteractWithChat && this.args.canInteractWithChat &&
!this.args.message?.staged && !this.args.message?.get("staged") &&
this.args.isHovered this.args.isHovered
); );
} }
@ -270,14 +270,15 @@ export default class ChatMessage extends Component {
get hasThread() { get hasThread() {
return ( return (
this.args.chatChannel.threading_enabled && this.args.message.thread_id this.args.chatChannel?.get("threading_enabled") &&
this.args.message?.get("thread_id")
); );
} }
get show() { get show() {
return ( return (
!this.args.message?.deleted_at || !this.args.message?.get("deleted_at") ||
this.currentUser.id === this.args.message?.user?.id || this.currentUser.id === this.args.message?.get("user.id") ||
this.currentUser.staff || this.currentUser.staff ||
this.args.details?.can_moderate this.args.details?.can_moderate
); );
@ -330,43 +331,44 @@ export default class ChatMessage extends Component {
get hideUserInfo() { get hideUserInfo() {
return ( return (
this.args.message?.hideUserInfo && !this.args.message?.chat_webhook_event this.args.message?.get("hideUserInfo") &&
!this.args.message?.get("chat_webhook_event")
); );
} }
get showEditButton() { get showEditButton() {
return ( return (
!this.args.message?.deleted_at && !this.args.message?.get("deleted_at") &&
this.currentUser?.id === this.args.message?.user?.id && this.currentUser?.id === this.args.message?.get("user.id") &&
this.args.chatChannel?.canModifyMessages?.(this.currentUser) this.args.chatChannel?.canModifyMessages?.(this.currentUser)
); );
} }
get canFlagMessage() { get canFlagMessage() {
return ( return (
this.currentUser?.id !== this.args.message?.user?.id && this.currentUser?.id !== this.args.message?.get("user.id") &&
this.args.message?.user_flag_status === undefined && this.args.message?.get("user_flag_status") === undefined &&
this.args.details?.can_flag && this.args.details?.can_flag &&
!this.args.message?.chat_webhook_event && !this.args.message?.get("chat_webhook_event") &&
!this.args.message.deleted_at !this.args.message?.get("deleted_at")
); );
} }
get canManageDeletion() { get canManageDeletion() {
return this.currentUser?.id === this.args.message.user?.id return this.currentUser?.id === this.args.message.get("user.id")
? this.args.details?.can_delete_self ? this.args.details?.can_delete_self
: this.args.details?.can_delete_others; : this.args.details?.can_delete_others;
} }
get canReply() { get canReply() {
return ( return (
!this.args.message?.deleted_at && !this.args.message?.get("deleted_at") &&
this.args.chatChannel?.canModifyMessages?.(this.currentUser) this.args.chatChannel?.canModifyMessages?.(this.currentUser)
); );
} }
get canReact() { get canReact() {
return ( return (
!this.args.message?.deleted_at && !this.args.message?.get("deleted_at") &&
this.args.chatChannel?.canModifyMessages?.(this.currentUser) this.args.chatChannel?.canModifyMessages?.(this.currentUser)
); );
} }
@ -374,7 +376,7 @@ export default class ChatMessage extends Component {
get showDeleteButton() { get showDeleteButton() {
return ( return (
this.canManageDeletion && this.canManageDeletion &&
!this.args.message?.deleted_at && !this.args.message?.get("deleted_at") &&
this.args.chatChannel?.canModifyMessages?.(this.currentUser) this.args.chatChannel?.canModifyMessages?.(this.currentUser)
); );
} }
@ -382,7 +384,7 @@ export default class ChatMessage extends Component {
get showRestoreButton() { get showRestoreButton() {
return ( return (
this.canManageDeletion && this.canManageDeletion &&
this.args.message?.deleted_at && this.args.message?.get("deleted_at") &&
this.args.chatChannel?.canModifyMessages?.(this.currentUser) this.args.chatChannel?.canModifyMessages?.(this.currentUser)
); );
} }

View File

@ -13,21 +13,37 @@ RSpec.describe "Chat channel", type: :system, js: true do
context "when sending a message" do context "when sending a message" do
before do before do
channel_1.add(current_user) channel_1.add(current_user)
50.times { Fabricate(:chat_message, chat_channel: channel_1) }
sign_in(current_user) sign_in(current_user)
end end
it "loads most recent messages" do context "with lots of messages" do
unloaded_message = Fabricate(:chat_message, chat_channel: channel_1) before { 50.times { Fabricate(:chat_message, chat_channel: channel_1) } }
visit("/chat/message/#{message_1.id}")
it "loads most recent messages" do
unloaded_message = Fabricate(:chat_message, chat_channel: channel_1)
visit("/chat/message/#{message_1.id}")
expect(channel).to have_no_loading_skeleton
expect(page).to have_no_css("[data-id='#{unloaded_message.id}']")
channel.send_message("test_message")
expect(channel).to have_no_loading_skeleton
expect(page).to have_css("[data-id='#{unloaded_message.id}']")
end
end
it "allows to edit this message once persisted" do
chat.visit_channel(channel_1)
expect(channel).to have_no_loading_skeleton expect(channel).to have_no_loading_skeleton
expect(page).to have_no_css("[data-id='#{unloaded_message.id}']") channel.send_message("aaaaaaaaaaaaaaaaaaaa")
expect(page).to have_no_css("[data-staged-id]")
last_message = find(".chat-message-container:last-child")
last_message.hover
channel.send_message("test_message") expect(page).to have_css(
".chat-message-actions-container[data-id='#{last_message["data-id"]}']",
expect(channel).to have_no_loading_skeleton )
expect(page).to have_css("[data-id='#{unloaded_message.id}']")
end end
end end