Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: チャットでも動画や音声を再生できるようにする #35

Merged
merged 1 commit into from
Sep 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 26 additions & 1 deletion packages/frontend/src/components/MkMediaAudio.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,15 @@ SPDX-License-Identifier: AGPL-3.0-only
-->

<template>
<div :class="[$style.audioContainer, audio.isSensitive && $style.sensitive]" @contextmenu.stop>
<div
:class="[
$style.audioContainer,
audio.isSensitive && $style.sensitive,
hideTopRound ? $style.hideTopRound : null,
useBg ? $style.useBg : null,
]"
@contextmenu.stop
>
<button v-if="hide" :class="$style.hidden" @click="hide = false">
<div :class="$style.hiddenTextWrapper">
<b v-if="audio.isSensitive" style="display: block"
Expand Down Expand Up @@ -59,6 +67,8 @@ import { iAmModerator } from '@/account.js';

const props = defineProps<{
audio: Misskey.entities.DriveFile;
hideTopRound?: boolean;
useBg?: boolean;
}>();

const audioEl = shallowRef<HTMLAudioElement>();
Expand Down Expand Up @@ -253,6 +263,21 @@ onDeactivated(() => {
overflow: clip;
}

.hideTopRound {
border-top-left-radius: 0;
border-top-right-radius: 0;
}

.useBg {
color: var(--fgOnAccent) !important;
:hover {
color: var(--fgOnAccent) !important;
}
input[type='range'] {
color: var(--fgOnAccent) !important;
}
}

.sensitive {
position: relative;

Expand Down
85 changes: 47 additions & 38 deletions packages/frontend/src/components/MkMediaBanner.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,23 @@ SPDX-License-Identifier: AGPL-3.0-only
-->

<template>
<div :class="$style.root">
<MkMediaAudio v-if="media.type.startsWith('audio') && media.type !== 'audio/midi'" :audio="media"/>
<div v-else-if="media.isSensitive && hide" :class="$style.sensitive" @click="hide = false">
<span style="font-size: 1.6em;"><i class="ti ti-alert-triangle"></i></span>
<b>{{ i18n.ts.sensitive }}</b>
<span>{{ i18n.ts.clickToShow }}</span>
</div>
<a
v-else :class="$style.download"
:href="media.url"
:title="media.name"
:download="media.name"
>
<span style="font-size: 1.6em;"><i class="ti ti-download"></i></span>
<b>{{ media.name }}</b>
</a>
</div>
<div :class="[$style.root, hideTopRound ? $style.hideTopRound : null]">
<MkMediaAudio
v-if="media.type.startsWith('audio') && media.type !== 'audio/midi'"
:audio="media"
:hide-top-round="hideTopRound"
:use-bg="useBg"
/>
<div v-else-if="media.isSensitive && hide" :class="$style.sensitive" @click="hide = false">
<span style="font-size: 1.6em"><i class="ti ti-alert-triangle"></i></span>
<b>{{ i18n.ts.sensitive }}</b>
<span>{{ i18n.ts.clickToShow }}</span>
</div>
<a v-else :class="$style.download" :href="media.url" :title="media.name" :download="media.name">
<span style="font-size: 1.6em"><i class="ti ti-download"></i></span>
<b>{{ media.name }}</b>
</a>
</div>
</template>

<script lang="ts" setup>
Expand All @@ -29,49 +29,58 @@ import * as Misskey from 'misskey-js';
import { i18n } from '@/i18n.js';
import MkMediaAudio from '@/components/MkMediaAudio.vue';

const props = withDefaults(defineProps<{
media: Misskey.entities.DriveFile;
}>(), {
});
const props = withDefaults(
defineProps<{
media: Misskey.entities.DriveFile;
hideTopRound?: boolean;
useBg?: boolean;
}>(),
{},
);

const audioEl = shallowRef<HTMLAudioElement>();
const hide = ref(true);

watch(audioEl, () => {
if (audioEl.value) {
audioEl.value.volume = 0.3;
}
if (audioEl.value) {
audioEl.value.volume = 0.3;
}
});
</script>

<style lang="scss" module>
.root {
width: 100%;
border-radius: 4px;
margin-top: 4px;
overflow: clip;
width: 100%;
border-radius: 4px;
margin-top: 4px;
overflow: clip;
}

.hideTopRound {
border-top-left-radius: 0;
border-top-right-radius: 0;
}

.download,
.sensitive {
display: flex;
align-items: center;
font-size: 12px;
padding: 8px 12px;
white-space: nowrap;
display: flex;
align-items: center;
font-size: 12px;
padding: 8px 12px;
white-space: nowrap;
}

.download {
background: var(--noteAttachedFile);
background: var(--noteAttachedFile);
}

.sensitive {
background: #111;
color: #fff;
background: #111;
color: #fff;
}

.audio {
border-radius: 8px;
overflow: clip;
border-radius: 8px;
overflow: clip;
}
</style>
19 changes: 16 additions & 3 deletions packages/frontend/src/components/MkMediaList.vue
Original file line number Diff line number Diff line change
@@ -1,20 +1,26 @@
<template>
<div>
<XBanner v-for="media in mediaList.filter((media) => !previewable(media))" :key="media.id" :media="media" />
<XBanner
v-for="media in mediaList.filter((media) => !previewable(media))"
:key="media.id"
:media="media"
:hide-top-round="hideTopRound"
:use-bg="useBg"
/>
<div v-if="mediaList.filter((media) => previewable(media)).length > 0" :class="$style.container">
<div ref="gallery" :class="[$style.medias, count <= 4 ? $style['n' + count] : $style.nMany]">
<template v-for="media in mediaList.filter((media) => previewable(media))">
<XVideo
v-if="media.type.startsWith('video')"
:key="media.id"
:class="$style.media"
:class="[$style.media, hideTopRound ? $style.hideTopRound : null]"
:video="media"
:total="count"
/>
<XImage
v-else-if="media.type.startsWith('image')"
:key="media.id"
:class="$style.media"
:class="[$style.media, hideTopRound ? $style.hideTopRound : null]"
class="image"
:data-id="media.id"
:image="media"
Expand All @@ -41,6 +47,8 @@ import { FILE_TYPE_BROWSERSAFE } from '@/const';
const props = defineProps<{
mediaList: misskey.entities.DriveFile[];
raw?: boolean;
hideTopRound?: boolean;
useBg?: boolean;
}>();

const $style = useCssModule();
Expand Down Expand Up @@ -221,6 +229,11 @@ const previewable = (file: misskey.entities.DriveFile): boolean => {
border-radius: 8px;
}

.hideTopRound {
border-top-left-radius: 0;
border-top-right-radius: 0;
}

.pswp {
--pswp-root-z-index: var(--mk-pswp-root-z-index, 2000700) !important;
--pswp-bg: var(--modalBg) !important;
Expand Down
47 changes: 38 additions & 9 deletions packages/frontend/src/pages/messaging/messaging-room.message.vue
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,13 @@
class="content"
@pointerdown.passive="onPointerdown"
@pointerup.passive="onPointerup"
@pointermove.passive="resetTimer"
>
<Mfm v-if="message.text" ref="text" class="text" :text="message.text" :i="$i" />
<div v-if="message.file" class="file">
<a :href="message.file.url" rel="noopener" target="_blank" :title="message.file.name">
<img
v-if="message.file.type.split('/')[0] == 'image'"
:src="message.file.url"
:alt="message.file.name"
/>
<p v-else>{{ message.file.name }}</p>
</a>
<div class="richcontent">
<MkMediaList :media-list="[message.file]" :hide-top-round="!!message.text" :use-bg="!!message.text" />
</div>
</div>
</div>
<div v-else class="content">
Expand Down Expand Up @@ -70,7 +66,7 @@ import * as os from '@/os';
import { $i } from '@/account';
import { defaultStore } from '@/store';
import { getMessageMenu } from '@/scripts/get-message-menu';
// @ts-ignore
import MkMediaList from '@/components/MkMediaList.vue';

const props = defineProps<{
// @ts-ignore
Expand Down Expand Up @@ -545,4 +541,37 @@ async function onPointerup(ev: PointerEvent): Promise<void> {
}
}
}

.richcontent {
min-width: 128px;
}

@container (min-width: 250px) {
.richcontent {
min-width: 200px;
}
}
@container (min-width: 400px) {
.richcontent {
min-width: 250px;
}
}

@container (min-width: 500px) {
.richcontent {
min-width: 320px;
}
}

@container (min-width: 640px) {
.richcontent {
min-width: 480px;
}
}

@container (min-width: 840px) {
.richcontent {
min-width: 640px;
}
}
</style>
Loading