This repository has been archived on 2023-03-18. You can view files and clone it, but cannot push or open issues or pull requests.
osr-discourse-src/plugins/chat/assets/javascripts/discourse/components/chat-upload.js
Martin Brennan c3ace5ea8b
FEATURE: Inline audio player for chat uploads (#20175)
Similar to https://github.com/discourse/discourse-chat/pull/1283,
this adds the <audio> inline player for uploaded audio files in
chat channels.
2023-02-06 16:00:03 +10:00

57 lines
1.3 KiB
JavaScript

import Component from "@glimmer/component";
import { inject as service } from "@ember/service";
import { isAudio, isImage, isVideo } from "discourse/lib/uploads";
import { action } from "@ember/object";
import { tracked } from "@glimmer/tracking";
import { htmlSafe } from "@ember/template";
export default class extends Component {
@service siteSettings;
@tracked loaded = false;
IMAGE_TYPE = "image";
VIDEO_TYPE = "video";
AUDIO_TYPE = "audio";
ATTACHMENT_TYPE = "attachment";
get type() {
if (isImage(this.args.upload.original_filename)) {
return this.IMAGE_TYPE;
}
if (isVideo(this.args.upload.original_filename)) {
return this.VIDEO_TYPE;
}
if (isAudio(this.args.upload.original_filename)) {
return this.AUDIO_TYPE;
}
return this.ATTACHMENT_TYPE;
}
get size() {
const width = this.args.upload.width;
const height = this.args.upload.height;
const ratio = Math.min(
this.siteSettings.max_image_width / width,
this.siteSettings.max_image_height / height
);
return { width: width * ratio, height: height * ratio };
}
get imageStyle() {
if (this.args.upload.dominant_color && !this.loaded) {
return htmlSafe(`background-color: #${this.args.upload.dominant_color};`);
}
}
@action
imageLoaded() {
this.loaded = true;
}
}