A platform for community discussion. Free, open, simple.
FIX: Chat video thumbnails in Safari (#33199)
Blake Erickson2268f06b04da
diff --git a/plugins/chat/assets/javascripts/discourse/components/chat-upload.gjs b/plugins/chat/assets/javascripts/discourse/components/chat-upload.gjsindex 1469fc600ac..0c6f76672ee 100644--- a/plugins/chat/assets/javascripts/discourse/components/chat-upload.gjs+++ b/plugins/chat/assets/javascripts/discourse/components/chat-upload.gjs@@ -9,6 +9,7 @@ import { isAudio, isImage, isVideo } from "discourse/lib/uploads";export default class ChatUpload extends Component {@service siteSettings;+ @service capabilities;@tracked loaded = false;@@ -54,6 +55,11 @@ export default class ChatUpload extends Component {}}+ get videoSourceUrl() {+ const baseUrl = this.args.upload.url;+ return this.capabilities.isSafari ? `${baseUrl}#t=0.001` : baseUrl;+ }+@actionimageLoaded() {this.loaded = true;@@ -76,7 +82,7 @@ export default class ChatUpload extends Component {/>{{else if (eq this.type this.VIDEO_TYPE)}}<video class="chat-video-upload" preload="metadata" height="150" controls>- <source src={{@upload.url}} />+ <source src={{this.videoSourceUrl}} /></video>{{else if (eq this.type this.AUDIO_TYPE)}}<audio class="chat-audio-upload" preload="metadata" controls>diff --git a/plugins/chat/test/javascripts/components/chat-upload-test.gjs b/plugins/chat/test/javascripts/components/chat-upload-test.gjsindex 2e41a8e049e..15aef53bcd3 100644--- a/plugins/chat/test/javascripts/components/chat-upload-test.gjs+++ b/plugins/chat/test/javascripts/components/chat-upload-test.gjs@@ -1,3 +1,5 @@+import { tracked } from "@glimmer/tracking";+import Service from "@ember/service";import { render, triggerEvent } from "@ember/test-helpers";import { module, test } from "qunit";import { setupRenderingTest } from "discourse/tests/helpers/component-test";@@ -144,4 +146,56 @@ module("Discourse Chat | Component | chat-upload", function (hooks) {.dom("a.chat-other-upload").hasAttribute("href", TXT_FIXTURE.url, "has the correct URL");});++ module("video source URL", function (nestedHooks) {+ let mockCapabilities;++ class MockCapabilitiesService extends Service {+ @tracked isSafari = false;+ }++ nestedHooks.beforeEach(function () {+ // Register and inject the mock service+ this.owner.register("service:capabilities", MockCapabilitiesService);+ mockCapabilities = this.owner.lookup("service:capabilities");+ });++ test("adds timestamp parameter for Safari", async function (assert) {+ const self = this;+ this.set("upload", {+ ...VIDEO_FIXTURE,+ url: "https://example.com/video.mp4",+ });+ mockCapabilities.isSafari = true;++ await render(<template><ChatUpload @upload={{self.upload}} /></template>);++ assert+ .dom("video.chat-video-upload source")+ .hasAttribute(+ "src",+ "https://example.com/video.mp4#t=0.001",+ "adds timestamp for Safari"+ );+ });++ test("does not add timestamp parameter for other browsers", async function (assert) {+ const self = this;+ this.set("upload", {+ ...VIDEO_FIXTURE,+ url: "https://example.com/video.mp4",+ });+ mockCapabilities.isSafari = false;++ await render(<template><ChatUpload @upload={{self.upload}} /></template>);++ assert+ .dom("video.chat-video-upload source")+ .hasAttribute(+ "src",+ "https://example.com/video.mp4",+ "does not add timestamp for other browsers"+ );+ });+ });});