discourse/plugins/chat/test/javascripts/components/chat-channel-test.js

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

228 lines
6.7 KiB
JavaScript
Raw Normal View History

FEATURE: Add user status to inline mentions in chat (#20564) This PR adds status to mentions in chat and makes those mentions receive live updates. There are known unfinished part in this implementation: when posting a message, status on mentions on that message appears immediately, but only if a user used autocomplete when typing the message. If user copy and paste a message with mentions into chat composer, those mentions won't have user status on them. PRs with fixes for both problems are following soon. Preparations for this PR that were made previously include: - DEV: correct a relationship – a chat message may have several mentions 0dcfd7ddeccd438fed97c15827214a3ddd944838 - DEV: extract the logic for extracting and expanding mentions from ChatNotifier 75b81b6854087842b53b4c9559ef5836d9516269 - DEV: Always create chat mention records fa543cda06594b5bebe0ab35e48e613540f9d3dc - DEV: better split create_notification! and send_notifications logic e292c45924bb0b0a79497e5f494afcb8af2e1efc - DEV: more tests for mentions when updating chat messages e7292e1682bb910635af26879c31a17b8843b738 - DEV: extract updating status on mentions into a lib function e49d338c21885189970e51a60ac79ab8c1fc397e - DEV: Create and update chat message mentions earlier 35a414bb38b2ab990ff920f8c3adf2f877249f12 - DEV: Create a chat_mention record when self mentioning 2703f2311aefd87a7774316b50f5339626ea5b48 - DEV: When deleting a chat message, do not delete mention records f4fde4e49b03d5e8f01d02e2354c553c82f3402d
2023-05-24 20:55:20 +08:00
import { setupRenderingTest } from "discourse/tests/helpers/component-test";
import hbs from "htmlbars-inline-precompile";
import fabricators from "discourse/plugins/chat/discourse/lib/fabricators";
import { render, triggerEvent, waitFor } from "@ember/test-helpers";
FEATURE: Add user status to inline mentions in chat (#20564) This PR adds status to mentions in chat and makes those mentions receive live updates. There are known unfinished part in this implementation: when posting a message, status on mentions on that message appears immediately, but only if a user used autocomplete when typing the message. If user copy and paste a message with mentions into chat composer, those mentions won't have user status on them. PRs with fixes for both problems are following soon. Preparations for this PR that were made previously include: - DEV: correct a relationship – a chat message may have several mentions 0dcfd7ddeccd438fed97c15827214a3ddd944838 - DEV: extract the logic for extracting and expanding mentions from ChatNotifier 75b81b6854087842b53b4c9559ef5836d9516269 - DEV: Always create chat mention records fa543cda06594b5bebe0ab35e48e613540f9d3dc - DEV: better split create_notification! and send_notifications logic e292c45924bb0b0a79497e5f494afcb8af2e1efc - DEV: more tests for mentions when updating chat messages e7292e1682bb910635af26879c31a17b8843b738 - DEV: extract updating status on mentions into a lib function e49d338c21885189970e51a60ac79ab8c1fc397e - DEV: Create and update chat message mentions earlier 35a414bb38b2ab990ff920f8c3adf2f877249f12 - DEV: Create a chat_mention record when self mentioning 2703f2311aefd87a7774316b50f5339626ea5b48 - DEV: When deleting a chat message, do not delete mention records f4fde4e49b03d5e8f01d02e2354c553c82f3402d
2023-05-24 20:55:20 +08:00
import { module, test } from "qunit";
import pretender, { response } from "discourse/tests/helpers/create-pretender";
FEATURE: Add user status to inline mentions in chat (#20564) This PR adds status to mentions in chat and makes those mentions receive live updates. There are known unfinished part in this implementation: when posting a message, status on mentions on that message appears immediately, but only if a user used autocomplete when typing the message. If user copy and paste a message with mentions into chat composer, those mentions won't have user status on them. PRs with fixes for both problems are following soon. Preparations for this PR that were made previously include: - DEV: correct a relationship – a chat message may have several mentions 0dcfd7ddeccd438fed97c15827214a3ddd944838 - DEV: extract the logic for extracting and expanding mentions from ChatNotifier 75b81b6854087842b53b4c9559ef5836d9516269 - DEV: Always create chat mention records fa543cda06594b5bebe0ab35e48e613540f9d3dc - DEV: better split create_notification! and send_notifications logic e292c45924bb0b0a79497e5f494afcb8af2e1efc - DEV: more tests for mentions when updating chat messages e7292e1682bb910635af26879c31a17b8843b738 - DEV: extract updating status on mentions into a lib function e49d338c21885189970e51a60ac79ab8c1fc397e - DEV: Create and update chat message mentions earlier 35a414bb38b2ab990ff920f8c3adf2f877249f12 - DEV: Create a chat_mention record when self mentioning 2703f2311aefd87a7774316b50f5339626ea5b48 - DEV: When deleting a chat message, do not delete mention records f4fde4e49b03d5e8f01d02e2354c553c82f3402d
2023-05-24 20:55:20 +08:00
import { publishToMessageBus } from "discourse/tests/helpers/qunit-helpers";
module(
"Discourse Chat | Component | chat-channel | status on mentions",
function (hooks) {
setupRenderingTest(hooks);
const channelId = 1;
const actingUser = {
id: 1,
username: "acting_user",
};
const mentionedUser = {
id: 1000,
username: "user1",
status: {
description: "surfing",
emoji: "surfing_man",
},
};
const mentionedUser2 = {
id: 2000,
username: "user2",
status: {
description: "vacation",
emoji: "desert_island",
},
};
const message = {
id: 1891,
message: `Hey @${mentionedUser.username}`,
cooked: `<p>Hey <a class="mention" href="/u/${mentionedUser.username}">@${mentionedUser.username}</a></p>`,
mentioned_users: [mentionedUser],
created_at: "2020-08-04T15:00:00.000Z",
FEATURE: Add user status to inline mentions in chat (#20564) This PR adds status to mentions in chat and makes those mentions receive live updates. There are known unfinished part in this implementation: when posting a message, status on mentions on that message appears immediately, but only if a user used autocomplete when typing the message. If user copy and paste a message with mentions into chat composer, those mentions won't have user status on them. PRs with fixes for both problems are following soon. Preparations for this PR that were made previously include: - DEV: correct a relationship – a chat message may have several mentions 0dcfd7ddeccd438fed97c15827214a3ddd944838 - DEV: extract the logic for extracting and expanding mentions from ChatNotifier 75b81b6854087842b53b4c9559ef5836d9516269 - DEV: Always create chat mention records fa543cda06594b5bebe0ab35e48e613540f9d3dc - DEV: better split create_notification! and send_notifications logic e292c45924bb0b0a79497e5f494afcb8af2e1efc - DEV: more tests for mentions when updating chat messages e7292e1682bb910635af26879c31a17b8843b738 - DEV: extract updating status on mentions into a lib function e49d338c21885189970e51a60ac79ab8c1fc397e - DEV: Create and update chat message mentions earlier 35a414bb38b2ab990ff920f8c3adf2f877249f12 - DEV: Create a chat_mention record when self mentioning 2703f2311aefd87a7774316b50f5339626ea5b48 - DEV: When deleting a chat message, do not delete mention records f4fde4e49b03d5e8f01d02e2354c553c82f3402d
2023-05-24 20:55:20 +08:00
user: {
id: 1,
username: "jesse",
},
};
hooks.beforeEach(function () {
pretender.get(`/chat/api/channels/1/messages`, () =>
response({
messages: [message],
FEATURE: Add user status to inline mentions in chat (#20564) This PR adds status to mentions in chat and makes those mentions receive live updates. There are known unfinished part in this implementation: when posting a message, status on mentions on that message appears immediately, but only if a user used autocomplete when typing the message. If user copy and paste a message with mentions into chat composer, those mentions won't have user status on them. PRs with fixes for both problems are following soon. Preparations for this PR that were made previously include: - DEV: correct a relationship – a chat message may have several mentions 0dcfd7ddeccd438fed97c15827214a3ddd944838 - DEV: extract the logic for extracting and expanding mentions from ChatNotifier 75b81b6854087842b53b4c9559ef5836d9516269 - DEV: Always create chat mention records fa543cda06594b5bebe0ab35e48e613540f9d3dc - DEV: better split create_notification! and send_notifications logic e292c45924bb0b0a79497e5f494afcb8af2e1efc - DEV: more tests for mentions when updating chat messages e7292e1682bb910635af26879c31a17b8843b738 - DEV: extract updating status on mentions into a lib function e49d338c21885189970e51a60ac79ab8c1fc397e - DEV: Create and update chat message mentions earlier 35a414bb38b2ab990ff920f8c3adf2f877249f12 - DEV: Create a chat_mention record when self mentioning 2703f2311aefd87a7774316b50f5339626ea5b48 - DEV: When deleting a chat message, do not delete mention records f4fde4e49b03d5e8f01d02e2354c553c82f3402d
2023-05-24 20:55:20 +08:00
meta: { can_delete_self: true },
})
);
this.channel = fabricators.channel({
id: channelId,
currentUserMembership: { following: true },
meta: { can_join_chat_channel: false },
});
this.appEvents = this.container.lookup("service:appEvents");
});
test("it shows status on mentions", async function (assert) {
await render(hbs`<ChatChannel @channel={{this.channel}} />`);
FEATURE: Add user status to inline mentions in chat (#20564) This PR adds status to mentions in chat and makes those mentions receive live updates. There are known unfinished part in this implementation: when posting a message, status on mentions on that message appears immediately, but only if a user used autocomplete when typing the message. If user copy and paste a message with mentions into chat composer, those mentions won't have user status on them. PRs with fixes for both problems are following soon. Preparations for this PR that were made previously include: - DEV: correct a relationship – a chat message may have several mentions 0dcfd7ddeccd438fed97c15827214a3ddd944838 - DEV: extract the logic for extracting and expanding mentions from ChatNotifier 75b81b6854087842b53b4c9559ef5836d9516269 - DEV: Always create chat mention records fa543cda06594b5bebe0ab35e48e613540f9d3dc - DEV: better split create_notification! and send_notifications logic e292c45924bb0b0a79497e5f494afcb8af2e1efc - DEV: more tests for mentions when updating chat messages e7292e1682bb910635af26879c31a17b8843b738 - DEV: extract updating status on mentions into a lib function e49d338c21885189970e51a60ac79ab8c1fc397e - DEV: Create and update chat message mentions earlier 35a414bb38b2ab990ff920f8c3adf2f877249f12 - DEV: Create a chat_mention record when self mentioning 2703f2311aefd87a7774316b50f5339626ea5b48 - DEV: When deleting a chat message, do not delete mention records f4fde4e49b03d5e8f01d02e2354c553c82f3402d
2023-05-24 20:55:20 +08:00
assertStatusIsRendered(
assert,
statusSelector(mentionedUser.username),
mentionedUser.status
);
await assertStatusTooltipIsRendered(
assert,
statusSelector(mentionedUser.username),
mentionedUser.status
);
FEATURE: Add user status to inline mentions in chat (#20564) This PR adds status to mentions in chat and makes those mentions receive live updates. There are known unfinished part in this implementation: when posting a message, status on mentions on that message appears immediately, but only if a user used autocomplete when typing the message. If user copy and paste a message with mentions into chat composer, those mentions won't have user status on them. PRs with fixes for both problems are following soon. Preparations for this PR that were made previously include: - DEV: correct a relationship – a chat message may have several mentions 0dcfd7ddeccd438fed97c15827214a3ddd944838 - DEV: extract the logic for extracting and expanding mentions from ChatNotifier 75b81b6854087842b53b4c9559ef5836d9516269 - DEV: Always create chat mention records fa543cda06594b5bebe0ab35e48e613540f9d3dc - DEV: better split create_notification! and send_notifications logic e292c45924bb0b0a79497e5f494afcb8af2e1efc - DEV: more tests for mentions when updating chat messages e7292e1682bb910635af26879c31a17b8843b738 - DEV: extract updating status on mentions into a lib function e49d338c21885189970e51a60ac79ab8c1fc397e - DEV: Create and update chat message mentions earlier 35a414bb38b2ab990ff920f8c3adf2f877249f12 - DEV: Create a chat_mention record when self mentioning 2703f2311aefd87a7774316b50f5339626ea5b48 - DEV: When deleting a chat message, do not delete mention records f4fde4e49b03d5e8f01d02e2354c553c82f3402d
2023-05-24 20:55:20 +08:00
});
test("it updates status on mentions", async function (assert) {
await render(hbs`<ChatChannel @channel={{this.channel}} />`);
FEATURE: Add user status to inline mentions in chat (#20564) This PR adds status to mentions in chat and makes those mentions receive live updates. There are known unfinished part in this implementation: when posting a message, status on mentions on that message appears immediately, but only if a user used autocomplete when typing the message. If user copy and paste a message with mentions into chat composer, those mentions won't have user status on them. PRs with fixes for both problems are following soon. Preparations for this PR that were made previously include: - DEV: correct a relationship – a chat message may have several mentions 0dcfd7ddeccd438fed97c15827214a3ddd944838 - DEV: extract the logic for extracting and expanding mentions from ChatNotifier 75b81b6854087842b53b4c9559ef5836d9516269 - DEV: Always create chat mention records fa543cda06594b5bebe0ab35e48e613540f9d3dc - DEV: better split create_notification! and send_notifications logic e292c45924bb0b0a79497e5f494afcb8af2e1efc - DEV: more tests for mentions when updating chat messages e7292e1682bb910635af26879c31a17b8843b738 - DEV: extract updating status on mentions into a lib function e49d338c21885189970e51a60ac79ab8c1fc397e - DEV: Create and update chat message mentions earlier 35a414bb38b2ab990ff920f8c3adf2f877249f12 - DEV: Create a chat_mention record when self mentioning 2703f2311aefd87a7774316b50f5339626ea5b48 - DEV: When deleting a chat message, do not delete mention records f4fde4e49b03d5e8f01d02e2354c553c82f3402d
2023-05-24 20:55:20 +08:00
const newStatus = {
description: "off to dentist",
emoji: "tooth",
};
this.appEvents.trigger("user-status:changed", {
[mentionedUser.id]: newStatus,
});
const selector = statusSelector(mentionedUser.username);
await waitFor(selector);
assertStatusIsRendered(
assert,
statusSelector(mentionedUser.username),
newStatus
);
await assertStatusTooltipIsRendered(
assert,
statusSelector(mentionedUser.username),
newStatus
);
FEATURE: Add user status to inline mentions in chat (#20564) This PR adds status to mentions in chat and makes those mentions receive live updates. There are known unfinished part in this implementation: when posting a message, status on mentions on that message appears immediately, but only if a user used autocomplete when typing the message. If user copy and paste a message with mentions into chat composer, those mentions won't have user status on them. PRs with fixes for both problems are following soon. Preparations for this PR that were made previously include: - DEV: correct a relationship – a chat message may have several mentions 0dcfd7ddeccd438fed97c15827214a3ddd944838 - DEV: extract the logic for extracting and expanding mentions from ChatNotifier 75b81b6854087842b53b4c9559ef5836d9516269 - DEV: Always create chat mention records fa543cda06594b5bebe0ab35e48e613540f9d3dc - DEV: better split create_notification! and send_notifications logic e292c45924bb0b0a79497e5f494afcb8af2e1efc - DEV: more tests for mentions when updating chat messages e7292e1682bb910635af26879c31a17b8843b738 - DEV: extract updating status on mentions into a lib function e49d338c21885189970e51a60ac79ab8c1fc397e - DEV: Create and update chat message mentions earlier 35a414bb38b2ab990ff920f8c3adf2f877249f12 - DEV: Create a chat_mention record when self mentioning 2703f2311aefd87a7774316b50f5339626ea5b48 - DEV: When deleting a chat message, do not delete mention records f4fde4e49b03d5e8f01d02e2354c553c82f3402d
2023-05-24 20:55:20 +08:00
});
test("it deletes status on mentions", async function (assert) {
await render(hbs`<ChatChannel @channel={{this.channel}} />`);
FEATURE: Add user status to inline mentions in chat (#20564) This PR adds status to mentions in chat and makes those mentions receive live updates. There are known unfinished part in this implementation: when posting a message, status on mentions on that message appears immediately, but only if a user used autocomplete when typing the message. If user copy and paste a message with mentions into chat composer, those mentions won't have user status on them. PRs with fixes for both problems are following soon. Preparations for this PR that were made previously include: - DEV: correct a relationship – a chat message may have several mentions 0dcfd7ddeccd438fed97c15827214a3ddd944838 - DEV: extract the logic for extracting and expanding mentions from ChatNotifier 75b81b6854087842b53b4c9559ef5836d9516269 - DEV: Always create chat mention records fa543cda06594b5bebe0ab35e48e613540f9d3dc - DEV: better split create_notification! and send_notifications logic e292c45924bb0b0a79497e5f494afcb8af2e1efc - DEV: more tests for mentions when updating chat messages e7292e1682bb910635af26879c31a17b8843b738 - DEV: extract updating status on mentions into a lib function e49d338c21885189970e51a60ac79ab8c1fc397e - DEV: Create and update chat message mentions earlier 35a414bb38b2ab990ff920f8c3adf2f877249f12 - DEV: Create a chat_mention record when self mentioning 2703f2311aefd87a7774316b50f5339626ea5b48 - DEV: When deleting a chat message, do not delete mention records f4fde4e49b03d5e8f01d02e2354c553c82f3402d
2023-05-24 20:55:20 +08:00
this.appEvents.trigger("user-status:changed", {
[mentionedUser.id]: null,
});
const selector = statusSelector(mentionedUser.username);
await waitFor(selector, { count: 0 });
assert.dom(selector).doesNotExist("status is deleted");
});
test("it shows status on mentions on messages that came from Message Bus", async function (assert) {
await render(hbs`<ChatChannel @channel={{this.channel}} />`);
FEATURE: Add user status to inline mentions in chat (#20564) This PR adds status to mentions in chat and makes those mentions receive live updates. There are known unfinished part in this implementation: when posting a message, status on mentions on that message appears immediately, but only if a user used autocomplete when typing the message. If user copy and paste a message with mentions into chat composer, those mentions won't have user status on them. PRs with fixes for both problems are following soon. Preparations for this PR that were made previously include: - DEV: correct a relationship – a chat message may have several mentions 0dcfd7ddeccd438fed97c15827214a3ddd944838 - DEV: extract the logic for extracting and expanding mentions from ChatNotifier 75b81b6854087842b53b4c9559ef5836d9516269 - DEV: Always create chat mention records fa543cda06594b5bebe0ab35e48e613540f9d3dc - DEV: better split create_notification! and send_notifications logic e292c45924bb0b0a79497e5f494afcb8af2e1efc - DEV: more tests for mentions when updating chat messages e7292e1682bb910635af26879c31a17b8843b738 - DEV: extract updating status on mentions into a lib function e49d338c21885189970e51a60ac79ab8c1fc397e - DEV: Create and update chat message mentions earlier 35a414bb38b2ab990ff920f8c3adf2f877249f12 - DEV: Create a chat_mention record when self mentioning 2703f2311aefd87a7774316b50f5339626ea5b48 - DEV: When deleting a chat message, do not delete mention records f4fde4e49b03d5e8f01d02e2354c553c82f3402d
2023-05-24 20:55:20 +08:00
await receiveChatMessageViaMessageBus();
assertStatusIsRendered(
assert,
statusSelector(mentionedUser2.username),
mentionedUser2.status
);
await assertStatusTooltipIsRendered(
assert,
statusSelector(mentionedUser2.username),
mentionedUser2.status
);
FEATURE: Add user status to inline mentions in chat (#20564) This PR adds status to mentions in chat and makes those mentions receive live updates. There are known unfinished part in this implementation: when posting a message, status on mentions on that message appears immediately, but only if a user used autocomplete when typing the message. If user copy and paste a message with mentions into chat composer, those mentions won't have user status on them. PRs with fixes for both problems are following soon. Preparations for this PR that were made previously include: - DEV: correct a relationship – a chat message may have several mentions 0dcfd7ddeccd438fed97c15827214a3ddd944838 - DEV: extract the logic for extracting and expanding mentions from ChatNotifier 75b81b6854087842b53b4c9559ef5836d9516269 - DEV: Always create chat mention records fa543cda06594b5bebe0ab35e48e613540f9d3dc - DEV: better split create_notification! and send_notifications logic e292c45924bb0b0a79497e5f494afcb8af2e1efc - DEV: more tests for mentions when updating chat messages e7292e1682bb910635af26879c31a17b8843b738 - DEV: extract updating status on mentions into a lib function e49d338c21885189970e51a60ac79ab8c1fc397e - DEV: Create and update chat message mentions earlier 35a414bb38b2ab990ff920f8c3adf2f877249f12 - DEV: Create a chat_mention record when self mentioning 2703f2311aefd87a7774316b50f5339626ea5b48 - DEV: When deleting a chat message, do not delete mention records f4fde4e49b03d5e8f01d02e2354c553c82f3402d
2023-05-24 20:55:20 +08:00
});
test("it updates status on mentions on messages that came from Message Bus", async function (assert) {
await render(hbs`<ChatChannel @channel={{this.channel}} />`);
FEATURE: Add user status to inline mentions in chat (#20564) This PR adds status to mentions in chat and makes those mentions receive live updates. There are known unfinished part in this implementation: when posting a message, status on mentions on that message appears immediately, but only if a user used autocomplete when typing the message. If user copy and paste a message with mentions into chat composer, those mentions won't have user status on them. PRs with fixes for both problems are following soon. Preparations for this PR that were made previously include: - DEV: correct a relationship – a chat message may have several mentions 0dcfd7ddeccd438fed97c15827214a3ddd944838 - DEV: extract the logic for extracting and expanding mentions from ChatNotifier 75b81b6854087842b53b4c9559ef5836d9516269 - DEV: Always create chat mention records fa543cda06594b5bebe0ab35e48e613540f9d3dc - DEV: better split create_notification! and send_notifications logic e292c45924bb0b0a79497e5f494afcb8af2e1efc - DEV: more tests for mentions when updating chat messages e7292e1682bb910635af26879c31a17b8843b738 - DEV: extract updating status on mentions into a lib function e49d338c21885189970e51a60ac79ab8c1fc397e - DEV: Create and update chat message mentions earlier 35a414bb38b2ab990ff920f8c3adf2f877249f12 - DEV: Create a chat_mention record when self mentioning 2703f2311aefd87a7774316b50f5339626ea5b48 - DEV: When deleting a chat message, do not delete mention records f4fde4e49b03d5e8f01d02e2354c553c82f3402d
2023-05-24 20:55:20 +08:00
await receiveChatMessageViaMessageBus();
const newStatus = {
description: "off to meeting",
emoji: "calendar",
};
this.appEvents.trigger("user-status:changed", {
[mentionedUser2.id]: newStatus,
});
const selector = statusSelector(mentionedUser2.username);
await waitFor(selector);
assertStatusIsRendered(
assert,
statusSelector(mentionedUser2.username),
newStatus
);
await assertStatusTooltipIsRendered(
assert,
statusSelector(mentionedUser2.username),
newStatus
);
FEATURE: Add user status to inline mentions in chat (#20564) This PR adds status to mentions in chat and makes those mentions receive live updates. There are known unfinished part in this implementation: when posting a message, status on mentions on that message appears immediately, but only if a user used autocomplete when typing the message. If user copy and paste a message with mentions into chat composer, those mentions won't have user status on them. PRs with fixes for both problems are following soon. Preparations for this PR that were made previously include: - DEV: correct a relationship – a chat message may have several mentions 0dcfd7ddeccd438fed97c15827214a3ddd944838 - DEV: extract the logic for extracting and expanding mentions from ChatNotifier 75b81b6854087842b53b4c9559ef5836d9516269 - DEV: Always create chat mention records fa543cda06594b5bebe0ab35e48e613540f9d3dc - DEV: better split create_notification! and send_notifications logic e292c45924bb0b0a79497e5f494afcb8af2e1efc - DEV: more tests for mentions when updating chat messages e7292e1682bb910635af26879c31a17b8843b738 - DEV: extract updating status on mentions into a lib function e49d338c21885189970e51a60ac79ab8c1fc397e - DEV: Create and update chat message mentions earlier 35a414bb38b2ab990ff920f8c3adf2f877249f12 - DEV: Create a chat_mention record when self mentioning 2703f2311aefd87a7774316b50f5339626ea5b48 - DEV: When deleting a chat message, do not delete mention records f4fde4e49b03d5e8f01d02e2354c553c82f3402d
2023-05-24 20:55:20 +08:00
});
test("it deletes status on mentions on messages that came from Message Bus", async function (assert) {
await render(hbs`<ChatChannel @channel={{this.channel}} />`);
FEATURE: Add user status to inline mentions in chat (#20564) This PR adds status to mentions in chat and makes those mentions receive live updates. There are known unfinished part in this implementation: when posting a message, status on mentions on that message appears immediately, but only if a user used autocomplete when typing the message. If user copy and paste a message with mentions into chat composer, those mentions won't have user status on them. PRs with fixes for both problems are following soon. Preparations for this PR that were made previously include: - DEV: correct a relationship – a chat message may have several mentions 0dcfd7ddeccd438fed97c15827214a3ddd944838 - DEV: extract the logic for extracting and expanding mentions from ChatNotifier 75b81b6854087842b53b4c9559ef5836d9516269 - DEV: Always create chat mention records fa543cda06594b5bebe0ab35e48e613540f9d3dc - DEV: better split create_notification! and send_notifications logic e292c45924bb0b0a79497e5f494afcb8af2e1efc - DEV: more tests for mentions when updating chat messages e7292e1682bb910635af26879c31a17b8843b738 - DEV: extract updating status on mentions into a lib function e49d338c21885189970e51a60ac79ab8c1fc397e - DEV: Create and update chat message mentions earlier 35a414bb38b2ab990ff920f8c3adf2f877249f12 - DEV: Create a chat_mention record when self mentioning 2703f2311aefd87a7774316b50f5339626ea5b48 - DEV: When deleting a chat message, do not delete mention records f4fde4e49b03d5e8f01d02e2354c553c82f3402d
2023-05-24 20:55:20 +08:00
await receiveChatMessageViaMessageBus();
this.appEvents.trigger("user-status:changed", {
[mentionedUser2.id]: null,
});
const selector = statusSelector(mentionedUser2.username);
await waitFor(selector, { count: 0 });
assert.dom(selector).doesNotExist("status is deleted");
});
function assertStatusIsRendered(assert, selector, status) {
assert
.dom(selector)
.exists("status is rendered")
.hasAttribute(
"src",
new RegExp(`${status.emoji}.png`),
"status emoji is updated"
);
}
async function assertStatusTooltipIsRendered(assert, selector, status) {
await triggerEvent(selector, "mouseenter");
assert.equal(
document
.querySelector(".user-status-tooltip-description")
.textContent.trim(),
status.description,
"status description is correct"
);
assert.ok(
document.querySelector(
`.user-status-message-tooltip img[alt='${status.emoji}']`
),
"status emoji is correct"
);
await triggerEvent(selector, "mouseleave");
}
FEATURE: Add user status to inline mentions in chat (#20564) This PR adds status to mentions in chat and makes those mentions receive live updates. There are known unfinished part in this implementation: when posting a message, status on mentions on that message appears immediately, but only if a user used autocomplete when typing the message. If user copy and paste a message with mentions into chat composer, those mentions won't have user status on them. PRs with fixes for both problems are following soon. Preparations for this PR that were made previously include: - DEV: correct a relationship – a chat message may have several mentions 0dcfd7ddeccd438fed97c15827214a3ddd944838 - DEV: extract the logic for extracting and expanding mentions from ChatNotifier 75b81b6854087842b53b4c9559ef5836d9516269 - DEV: Always create chat mention records fa543cda06594b5bebe0ab35e48e613540f9d3dc - DEV: better split create_notification! and send_notifications logic e292c45924bb0b0a79497e5f494afcb8af2e1efc - DEV: more tests for mentions when updating chat messages e7292e1682bb910635af26879c31a17b8843b738 - DEV: extract updating status on mentions into a lib function e49d338c21885189970e51a60ac79ab8c1fc397e - DEV: Create and update chat message mentions earlier 35a414bb38b2ab990ff920f8c3adf2f877249f12 - DEV: Create a chat_mention record when self mentioning 2703f2311aefd87a7774316b50f5339626ea5b48 - DEV: When deleting a chat message, do not delete mention records f4fde4e49b03d5e8f01d02e2354c553c82f3402d
2023-05-24 20:55:20 +08:00
async function receiveChatMessageViaMessageBus() {
await publishToMessageBus(`/chat/${channelId}`, {
chat_message: {
id: 2138,
message: `Hey @${mentionedUser2.username}`,
cooked: `<p>Hey <a class="mention" href="/u/${mentionedUser2.username}">@${mentionedUser2.username}</a></p>`,
created_at: "2023-05-18T16:07:59.588Z",
excerpt: `Hey @${mentionedUser2.username}`,
available_flags: [],
chat_channel_id: 7,
mentioned_users: [mentionedUser2],
user: actingUser,
chat_webhook_event: null,
uploads: [],
},
type: "sent",
});
}
function statusSelector(username) {
return `.mention[href='/u/${username}'] .user-status-message img`;
FEATURE: Add user status to inline mentions in chat (#20564) This PR adds status to mentions in chat and makes those mentions receive live updates. There are known unfinished part in this implementation: when posting a message, status on mentions on that message appears immediately, but only if a user used autocomplete when typing the message. If user copy and paste a message with mentions into chat composer, those mentions won't have user status on them. PRs with fixes for both problems are following soon. Preparations for this PR that were made previously include: - DEV: correct a relationship – a chat message may have several mentions 0dcfd7ddeccd438fed97c15827214a3ddd944838 - DEV: extract the logic for extracting and expanding mentions from ChatNotifier 75b81b6854087842b53b4c9559ef5836d9516269 - DEV: Always create chat mention records fa543cda06594b5bebe0ab35e48e613540f9d3dc - DEV: better split create_notification! and send_notifications logic e292c45924bb0b0a79497e5f494afcb8af2e1efc - DEV: more tests for mentions when updating chat messages e7292e1682bb910635af26879c31a17b8843b738 - DEV: extract updating status on mentions into a lib function e49d338c21885189970e51a60ac79ab8c1fc397e - DEV: Create and update chat message mentions earlier 35a414bb38b2ab990ff920f8c3adf2f877249f12 - DEV: Create a chat_mention record when self mentioning 2703f2311aefd87a7774316b50f5339626ea5b48 - DEV: When deleting a chat message, do not delete mention records f4fde4e49b03d5e8f01d02e2354c553c82f3402d
2023-05-24 20:55:20 +08:00
}
}
);