A platform for community discussion. Free, open, simple.
DEV: Remove obsolete chat code and tests (#39451)
Jarek Radoszc63f9cca90d0
diff --git a/plugins/chat/assets/javascripts/discourse/components/chat-channel.gjs b/plugins/chat/assets/javascripts/discourse/components/chat-channel.gjsindex cfa73fc955d..ef1a3ef88ea 100644--- a/plugins/chat/assets/javascripts/discourse/components/chat-channel.gjs+++ b/plugins/chat/assets/javascripts/discourse/components/chat-channel.gjs@@ -47,7 +47,6 @@ import ChatUploadDropZone from "./chat-upload-drop-zone";export default class ChatChannel extends Component {@service capabilities;- @service chat;@service chatApi;@service chatChannelsManager;@service chatDraftsManager;@@ -604,7 +603,6 @@ export default class ChatChannel extends Component {stagedMessage.cooked = "";stagedMessage.error = error.jqXHR.responseJSON.errors[0];} else {- this.chat.markNetworkAsUnreliable();stagedMessage.error = "network_error";}}@@ -630,9 +628,6 @@ export default class ChatChannel extends Component {.catch((error) => {this._onSendError(data.staged_id, error);})- .then(() => {- this.chat.markNetworkAsReliable();- }).finally(() => {this.pane.sending = false;});diff --git a/plugins/chat/assets/javascripts/discourse/components/chat-thread.gjs b/plugins/chat/assets/javascripts/discourse/components/chat-thread.gjsindex 923d0737c7e..eb3e14f96e0 100644--- a/plugins/chat/assets/javascripts/discourse/components/chat-thread.gjs+++ b/plugins/chat/assets/javascripts/discourse/components/chat-thread.gjs@@ -44,7 +44,6 @@ import ChatUploadDropZone from "./chat-upload-drop-zone";export default class ChatThread extends Component {@service capabilities;- @service chat;@service chatApi;@service chatDraftsManager;@service chatThreadComposer;@@ -534,7 +533,6 @@ export default class ChatThread extends Component {if (error.jqXHR?.responseJSON?.errors?.length) {stagedMessage.error = error.jqXHR.responseJSON.errors[0];} else {- this.chat.markNetworkAsUnreliable();stagedMessage.error = "network_error";}}diff --git a/plugins/chat/assets/javascripts/discourse/services/chat-api.js b/plugins/chat/assets/javascripts/discourse/services/chat-api.jsindex 618b3631264..af01b23f4b8 100644--- a/plugins/chat/assets/javascripts/discourse/services/chat-api.js+++ b/plugins/chat/assets/javascripts/discourse/services/chat-api.js@@ -11,7 +11,6 @@ import Collection from "../lib/collection";* @implements {@ember/service}*/export default class ChatApi extends Service {- @service chat;@service chatChannelsManager;channel(channelId) {@@ -442,17 +441,9 @@ export default class ChatApi extends Service {data,},ignoreUnsent: false,- })- .then(() => {- this.chat.markNetworkAsReliable();- })- .catch((error) => {- // we ignore a draft which can't be saved because it's too big- // and only deal with network error for now- if (!error.jqXHR?.responseJSON?.errors?.length) {- this.chat.markNetworkAsUnreliable();- }- });+ }).catch(() => {+ // we ignore a draft which can't be saved because it's too big+ });}/**diff --git a/plugins/chat/assets/javascripts/discourse/services/chat.js b/plugins/chat/assets/javascripts/discourse/services/chat.jsindex 214addfc1cf..157aa663182 100644--- a/plugins/chat/assets/javascripts/discourse/services/chat.js+++ b/plugins/chat/assets/javascripts/discourse/services/chat.js@@ -1,6 +1,6 @@import { tracked } from "@glimmer/tracking";import { action, computed } from "@ember/object";-import { cancel, next } from "@ember/runloop";+import { next } from "@ember/runloop";import Service, { service } from "@ember/service";import { ajax } from "discourse/lib/ajax";import { popupAjaxError } from "discourse/lib/ajax-error";@@ -8,7 +8,6 @@ import { uniqueItemsFromArray } from "discourse/lib/array-tools";import { bind } from "discourse/lib/decorators";import deprecated from "discourse/lib/deprecated";import EmbedMode from "discourse/lib/embed-mode";-import discourseLater from "discourse/lib/later";import {onPresenceChange,removeOnPresenceChange,@@ -171,26 +170,6 @@ export default class Chat extends Service {}}- markNetworkAsUnreliable() {- cancel(this._networkCheckHandler);-- this.set("isNetworkUnreliable", true);-- this._networkCheckHandler = discourseLater(() => {- if (this.isDestroyed || this.isDestroying) {- return;- }-- this.markNetworkAsReliable();- }, 30000);- }-- markNetworkAsReliable() {- cancel(this._networkCheckHandler);-- this.set("isNetworkUnreliable", false);- }-async loadChannels() {// We want to be able to call this method multiple times, but only// actually load the channels once. This is because we might calldiff --git a/plugins/chat/assets/stylesheets/common/chat-composer.scss b/plugins/chat/assets/stylesheets/common/chat-composer.scssindex 7a0eedb548d..87dc26040a8 100644--- a/plugins/chat/assets/stylesheets/common/chat-composer.scss+++ b/plugins/chat/assets/stylesheets/common/chat-composer.scss@@ -116,11 +116,6 @@white-space: nowrap;}}-- &__unreliable-network {- color: var(--danger);- padding: 0 0.5em;- }}.chat-composer-message-details {diff --git a/plugins/chat/config/locales/client.en.yml b/plugins/chat/config/locales/client.en.ymlindex df05857647d..7a6a8eb6599 100644--- a/plugins/chat/config/locales/client.en.yml+++ b/plugins/chat/config/locales/client.en.yml@@ -301,7 +301,6 @@ en:retry_staged_message:title: "Network error"action: "Send again?"- unreliable_network: "Network is unreliable, sending messages and saving draft might not work"bookmark_message: "Bookmark"bookmark_message_edit: "Edit Bookmark"restore: "Restore deleted message"diff --git a/plugins/chat/test/javascripts/acceptance/chat-composer-test.js b/plugins/chat/test/javascripts/acceptance/chat-composer-test.jsdeleted file mode 100644index 49298770934..00000000000--- a/plugins/chat/test/javascripts/acceptance/chat-composer-test.js+++ /dev/null@@ -1,144 +0,0 @@-import {- click,- fillIn,- settled,- triggerEvent,- visit,-} from "@ember/test-helpers";-import { skip } from "qunit";-import {- acceptance,- publishToMessageBus,-} from "discourse/tests/helpers/qunit-helpers";-import {- baseChatPretenders,- chatChannelPretender,-} from "../helpers/chat-pretenders";--const GROUP_NAME = "group1";--acceptance("Composer", function (needs) {- needs.user({ has_chat_enabled: true });- needs.settings({- chat_enabled: true,- enable_rich_text_paste: true,- enable_emoji: true,- });- needs.pretender((server, helper) => {- baseChatPretenders(server, helper);- chatChannelPretender(server, helper);- server.get("/chat/:id/messages.json", () =>- helper.response({ chat_messages: [], meta: {} })- );- server.get("/emojis.json", () =>- helper.response({ favorites: [{ name: "grinning" }] })- );- server.post("/chat/drafts", () => {- return helper.response([]);- });-- server.get("/chat/api/mentions/groups.json", () => {- return helper.response({- unreachable: [GROUP_NAME],- over_members_limit: [],- invalid: [],- });- });- });-- needs.hooks.beforeEach(function () {- Object.defineProperty(this, "chatService", {- get: () => this.container.lookup("service:chat"),- });- });-- skip("when pasting html in composer", async function (assert) {- await visit("/chat/c/another-category/11");-- await triggerEvent(".chat-composer__input", "paste", {- bubbles: true,- clipboardData: {- types: ["text/html"],- getData: (type) => {- if (type === "text/html") {- return "<a href>Foo</a>";- }- },- },- });-- assert.dom(".chat-composer__input").hasValue("Foo");- });-});--let sendAttempt = 0;-acceptance("Composer - unreliable network", function (needs) {- needs.user({ id: 1, has_chat_enabled: true });- needs.settings({- chat_enabled: true,- enable_emoji: true,- });- needs.pretender((server, helper) => {- chatChannelPretender(server, helper);- server.get("/chat/:id/messages.json", () =>- helper.response({ chat_messages: [], meta: {} })- );- server.post("/chat/drafts", () => helper.response(500, {}));- server.post("/chat/:id.json", () => {- sendAttempt += 1;- return sendAttempt === 1- ? helper.response(500, {})- : helper.response({ success: true });- });- });-- needs.hooks.beforeEach(function () {- Object.defineProperty(this, "chatService", {- get: () => this.container.lookup("service:chat"),- });- });-- needs.hooks.afterEach(function () {- sendAttempt = 0;- });-- skip("Sending a message with unreliable network", async function (assert) {- await visit("/chat/c/-/11");- await fillIn(".chat-composer__input", "network-error-message");- await click(".chat-composer-button.-send");-- assert- .dom(".chat-message-container[data-id='1'] .retry-staged-message-btn")- .exists("it adds a retry button");-- await fillIn(".chat-composer__input", "network-error-message");- await click(".chat-composer-button.-send");- await publishToMessageBus(`/chat/11`, {- type: "sent",- staged_id: 1,- chat_message: {- cooked: "network-error-message",- id: 175,- user: { id: 1 },- },- });-- assert- .dom(".chat-message-container[data-id='1'] .retry-staged-message-btn")- .doesNotExist("it removes the staged message");- assert- .dom(".chat-message-container[data-id='175']")- .exists("it sends the message");- assert.dom(".chat-composer__input").hasNoValue("clears the input");- });-- skip("Draft with unreliable network", async function (assert) {- await visit("/chat/c/-/11");- this.chatService.set("isNetworkUnreliable", true);- await settled();-- assert- .dom(".chat-composer__unreliable-network")- .exists("it displays a network error icon");- });-});diff --git a/plugins/chat/test/javascripts/acceptance/chat-live-pane-collapse-test.js b/plugins/chat/test/javascripts/acceptance/chat-live-pane-collapse-test.jsdeleted file mode 100644index af2fcba1314..00000000000--- a/plugins/chat/test/javascripts/acceptance/chat-live-pane-collapse-test.js+++ /dev/null@@ -1,154 +0,0 @@-import { click, visit } from "@ember/test-helpers";-import { skip } from "qunit";-import { acceptance } from "discourse/tests/helpers/qunit-helpers";--acceptance("Chat live pane collapse", function (needs) {- needs.user({- username: "eviltrout",- id: 1,- can_chat: true,- has_chat_enabled: true,- });-- needs.settings({- chat_enabled: true,- enable_emoji: true,- });-- needs.pretender((server, helper) => {- server.get("/chat/:chatChannelId/messages.json", () =>- helper.response({- meta: {- can_chat: true,- user_silenced: false,- },- chat_messages: [- {- id: 1,- message: "https://www.youtube.com/watch?v=aOWkVdU4NH0",- cooked:- '<div class="youtube-onebox lazy-video-container" data-video-id="aOWkVdU4NH0" data-video-title="Picnic with my cat (shaved ice & lemonade)" data-provider-name="youtube"> <a href="https://www.youtube.com/watch?v=aOWkVdU4NH0" target="_blank" rel="nofollow ugc noopener"> <img class="youtube-thumbnail" src="https://img.youtube.com/vi/aOWkVdU4NH0/maxresdefault.jpg" title="Picnic with my cat (shaved ice & lemonade)"> </a> </div>',- excerpt:- '<a href="https://www.youtube.com/watch?v=aOWkVdU4NH0">[Picnic with my cat (shaved ice & lemonade…</a>',- created_at: "2021-07-20T08:14:16.950Z",- flag_count: 0,- user: {- avatar_template:- "/letter_avatar_proxy/v4/letter/t/a9a28c/{size}.png",- id: 1,- name: "Tomtom",- username: "tomtom",- },- },- {- id: 2,- message: "",- cooked: "",- excerpt: "",- uploads: [- {- id: 4,- url: "/images/avatar.png",- original_filename: "tomtom.jpeg",- filesize: 93815,- width: 480,- height: 640,- thumbnail_width: 375,- thumbnail_height: 500,- extension: "jpeg",- retain_hours: null,- human_filesize: "91.6 KB",- },- ],- user: {- avatar_template:- "/letter_avatar_proxy/v4/letter/t/a9a28c/{size}.png",- id: 1,- name: "Tomtom",- username: "tomtom",- },- },- ],- })- );-- server.get("/chat/chat_channels.json", () =>- helper.response({- public_channels: [],- direct_message_channels: [],- message_bus_last_ids: {- channel_metadata: 0,- channel_edits: 0,- channel_status: 0,- new_channel: 0,- user_tracking_state: 0,- },- })- );-- server.get("/chat/chat_channels/:chatChannelId", () =>- helper.response({ id: 1, title: "something" })- );-- server.post("/uploads/lookup-urls", () =>- helper.response([- 200,- { "Content-Type": "application/json" },- [- {- url: "/images/avatar.png",- },- ],- ])- );- });-- skip("can collapse and expand videos in chat", async function (assert) {- const videoContainer =- ".chat-message-container[data-id='1'] .lazy-video-container";- const expandImage =- ".chat-message-container[data-id='1'] .chat-message-collapser-closed";- const collapseImage =- ".chat-message-container[data-id='1'] .chat-message-collapser-opened";-- await visit("/chat/c/cat/1");-- assert.dom(videoContainer).isVisible();- assert.dom(collapseImage).isVisible("the open arrow is shown");- assert.dom(expandImage).isNotVIsible("the close arrow is hidden");-- await click(collapseImage);-- assert.dom(videoContainer).isNotVisible();- assert.dom(expandImage).isVisible("the close arrow is shown");- assert.dom(collapseImage).isNotVIsible("the open arrow is hidden");-- await click(expandImage);-- assert.dom(videoContainer).isVisible();- assert.dom(collapseImage).isVisible("the open arrow is shown again");- assert.dom(expandImage).isNotVIsible("the close arrow is hidden again");- });-- skip("lightbox shows up before and after expand and collapse", async function (assert) {- const image = ".chat-message-container[data-id='2'] .chat-img-upload";- const expandImage =- ".chat-message-container[data-id='2'] .chat-message-collapser-closed";- const collapseImage =- ".chat-message-container[data-id='2'] .chat-message-collapser-opened";-- await visit("/chat/c/cat/1");-- await click(image);-- assert.dom(".pswp--open").exists("can see lightbox");- await click(".pswp__bg");-- await click(collapseImage);- await click(expandImage);-- await click(image);- assert.dom(".pswp--open").exists("can see lightbox after collapse expand");- await click(".pswp__bg");- });-});diff --git a/plugins/chat/test/javascripts/acceptance/chat-live-pane-test.js b/plugins/chat/test/javascripts/acceptance/chat-live-pane-test.jsdeleted file mode 100644index b6807c3edcf..00000000000--- a/plugins/chat/test/javascripts/acceptance/chat-live-pane-test.js+++ /dev/null@@ -1,62 +0,0 @@-import { click, visit } from "@ember/test-helpers";-import { skip } from "qunit";-import { acceptance } from "discourse/tests/helpers/qunit-helpers";--acceptance("Chat live pane - handling 429 errors", function (needs) {- needs.user({- username: "eviltrout",- id: 1,- has_chat_enabled: true,- });- needs.settings({- chat_enabled: true,- navigation_menu: "legacy",- enable_emoji: true,- });-- needs.pretender((server, helper) => {- server.get("/chat/:chatChannelId/messages.json", () => {- return helper.response(429);- });-- server.get("/chat/chat_channels.json", () =>- helper.response({- public_channels: [- {- id: 1,- title: "something",- current_user_membership: { following: true },- message_bus_last_ids: { new_mentions: 0, new_messages: 0 },- },- ],- direct_message_channels: [],- message_bus_last_ids: {- channel_metadata: 0,- channel_edits: 0,- channel_status: 0,- new_channel: 0,- user_tracking_state: 0,- },- })- );-- server.get("/chat/chat_channels/:chatChannelId", () =>- helper.response({ id: 1, title: "something" })- );-- server.post("/chat/drafts", () => {- return helper.response([]);- });-- server.post("/chat/:chatChannelId.json", () => {- return helper.response({ success: "OK" });- });- });-- skip("Handles 429 errors by displaying an alert", async function (assert) {- await visit("/chat/c/cat/1");-- assert.dom(".dialog-content").exists("displays the 429 error");- await click(".dialog-footer .btn-primary");- });-});diff --git a/plugins/chat/test/javascripts/acceptance/chat-message-retry-test.js b/plugins/chat/test/javascripts/acceptance/chat-message-retry-test.jsnew file mode 100644index 00000000000..a505c350be6--- /dev/null+++ b/plugins/chat/test/javascripts/acceptance/chat-message-retry-test.js@@ -0,0 +1,66 @@+import { click, fillIn, visit } from "@ember/test-helpers";+import { test } from "qunit";+import pretender, { response } from "discourse/tests/helpers/create-pretender";+import { acceptance } from "discourse/tests/helpers/qunit-helpers";++const CHANNEL_ID = 11;++acceptance("Retry message on send failure", function (needs) {+ needs.user({ has_chat_enabled: true });+ needs.settings({ chat_enabled: true });++ let sendAttempt;++ needs.hooks.beforeEach(function () {+ sendAttempt = 0;++ pretender.get("/chat/api/me/channels", () =>+ response({+ direct_message_channels: [],+ public_channels: [+ {+ id: CHANNEL_ID,+ title: "My channel",+ chatable_type: "Category",+ meta: { message_bus_last_ids: {} },+ current_user_membership: { following: true },+ chatable: { color: "ff0000" },+ },+ ],+ meta: { message_bus_last_ids: {} },+ tracking: {},+ })+ );++ pretender.get(`/chat/api/channels/${CHANNEL_ID}/messages`, () =>+ response({ messages: [], meta: {} })+ );++ pretender.post(`/chat/api/channels/${CHANNEL_ID}/drafts`, () =>+ response({})+ );++ pretender.post(`/chat/${CHANNEL_ID}`, () => {+ sendAttempt += 1;+ return sendAttempt === 1+ ? response(500, {})+ : response({ success: "OK" });+ });+ });++ test("shows a retry button when sending fails and resends on click", async function (assert) {+ await visit(`/chat/c/-/${CHANNEL_ID}`);+ await fillIn(".chat-composer__input", "hello there");+ await click(".chat-composer .-send");++ assert+ .dom(".chat-message-error__retry-btn")+ .exists("shows the retry button after a network error");++ await click(".chat-message-error__retry-btn");++ assert+ .dom(".chat-message-error__retry-btn")+ .doesNotExist("clears the retry button after a successful resend");+ });+});diff --git a/plugins/chat/test/javascripts/components/chat-message-collapser-test.gjs b/plugins/chat/test/javascripts/components/chat-message-collapser-test.gjsindex 56ae750f570..715a63eb828 100644--- a/plugins/chat/test/javascripts/components/chat-message-collapser-test.gjs+++ b/plugins/chat/test/javascripts/components/chat-message-collapser-test.gjs@@ -1,5 +1,5 @@import { click, render, settled, waitFor } from "@ember/test-helpers";-import { module, skip, test } from "qunit";+import { module, test } from "qunit";import { setupRenderingTest } from "discourse/tests/helpers/component-test";import { queryAll } from "discourse/tests/helpers/qunit-helpers";import ChatMessageCollapser from "discourse/plugins/chat/discourse/components/chat-message-collapser";@@ -429,27 +429,6 @@ module(module("Component | chat message collapser images", function (hooks) {setupRenderingTest(hooks);- skip("escapes link", async function (assert) {- this.set(- "cooked",- imageCooked- .replace("shows alt", evilString)- .replace("/images/d-logo-sketch-small.png", evilString)- );- await render(- <template><ChatMessageCollapser @cooked={{this.cooked}} /></template>- );-- const links = [- ...document.querySelectorAll(".chat-message-collapser-link-small"),- ];-- assert.dom(links[0]).includesHtml(evilStringEscaped);- assert- .dom(links[1])- .includesHtml("<script>someeviltitle</script>");- });-test("shows alt or links (if no alt) for linked image", async function (assert) {this.set("cooked", imageCooked);diff --git a/plugins/chat/test/javascripts/unit/services/chat-test.js b/plugins/chat/test/javascripts/unit/services/chat-test.jsindex 6299bc8bbf2..3f001505aac 100644--- a/plugins/chat/test/javascripts/unit/services/chat-test.js+++ b/plugins/chat/test/javascripts/unit/services/chat-test.js@@ -26,7 +26,7 @@ acceptance("Unit | Service | chat", function (needs) {.get(() => 10);});- test("getDocumentTitleCount returns urget count when title_count_mode is 'notifications'", function (assert) {+ test("getDocumentTitleCount returns urgent count when title_count_mode is 'notifications'", function (assert) {this.currentUser.user_option.title_count_mode = "notifications";const count = this.chat.getDocumentTitleCount();diff --git a/plugins/discourse-chat-integration/app/controllers/discourse_chat_integration/chat_controller.rb b/plugins/discourse-chat-integration/app/controllers/discourse_chat_integration/chat_controller.rbindex 91dda2fa0f5..29e1113dac7 100644--- a/plugins/discourse-chat-integration/app/controllers/discourse_chat_integration/chat_controller.rb+++ b/plugins/discourse-chat-integration/app/controllers/discourse_chat_integration/chat_controller.rb@@ -77,7 +77,6 @@ class DiscourseChatIntegration::ChatController < ApplicationControllerrender json: { errors: [err.message] }, status: :unprocessable_entityrescue DiscourseChatIntegration::ProviderError => errif err.info[:error_key].present?- Rails.logger.error("Chat integration setup failed error_key=#{err.info[:error_key]}")render json: { error_key: err.info[:error_key] }, status: :unprocessable_entityelserender json: { errors: [err.message.presence || "error"] }, status: :unprocessable_entity