FIX: Chat video thumbnails in Safari (#33199)

When uploading videos in chat using Safari the thumbnail isn't being
displayed
so we need to trick the browser to by adding the timestamp property so
that it
will fetch the metedata the html5 video tag needs to render the
thumbnail.
This commit is contained in:
Blake Erickson
2025-06-13 13:04:35 -06:00
committed by GitHub
parent bc4844cb93
commit 2268f06b04
2 changed files with 61 additions and 1 deletions
@@ -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"
);
});
});
});