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

note preview #78

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from
Open
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
45 changes: 44 additions & 1 deletion packages/frontend/src/components/MkUrlPreview.vue
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,16 @@ SPDX-License-Identifier: AGPL-3.0-only
</MkButton>
</div>
</template>
<template v-else-if="noteId && tweetExpanded">
<div :class="$style.quote">
<MkNoteSimple :note="noteRecord[noteId]" :class="$style.quoteNote"/>
</div>
<div :class="$style.action">
<MkButton :small="true" inline @click="tweetExpanded = false">
<i class="ti ti-x"></i> {{ i18n.ts.close }}
</MkButton>
</div>
</template>
<div v-else>
<component :is="self ? 'MkA' : 'a'" :class="[$style.link, { [$style.compact]: compact }]" :[attr]="self ? url.substring(local.length) : url" rel="nofollow noopener" :target="target" :title="url">
<div v-if="thumbnail && !sensitive" :class="$style.thumbnail" :style="defaultStore.state.dataSaver.urlPreview ? '' : `background-image: url('${thumbnail}')`">
Expand Down Expand Up @@ -70,6 +80,11 @@ SPDX-License-Identifier: AGPL-3.0-only
<i class="ti ti-brand-x"></i> {{ i18n.ts.expandTweet }}
</MkButton>
</div>
<div v-if="noteId" :class="$style.action">
<MkButton :small="true" inline @click="onExpandNote()">
<i class="ti ti-eye"></i> {{ i18n.ts.expandNote }}
</MkButton>
</div>
<div v-if="!playerEnabled && player.url" :class="$style.action">
<MkButton :small="true" inline @click="playerEnabled = true">
<i class="ti ti-player-play"></i> {{ i18n.ts.enablePlayer }}
Expand All @@ -84,12 +99,15 @@ SPDX-License-Identifier: AGPL-3.0-only

<script lang="ts" setup>
import { defineAsyncComponent, onDeactivated, onUnmounted, ref } from 'vue';
import * as Misskey from 'misskey-js';
import type { summaly } from '@misskey-dev/summaly';
import { url as local } from '@@/js/config.js';
import { i18n } from '@/i18n.js';
import * as os from '@/os.js';
import { deviceKind } from '@/scripts/device-kind.js';
import { misskeyApi } from '@/scripts/misskey-api.js';
import MkButton from '@/components/MkButton.vue';
import MkNoteSimple from '@/components/MkNoteSimple.vue';
import { versatileLang } from '@@/js/intl-const.js';
import { transformPlayerUrl } from '@/scripts/player-url-transform.js';
import { defaultStore } from '@/store.js';
Expand Down Expand Up @@ -127,7 +145,9 @@ const player = ref({
} as SummalyResult['player']);
const playerEnabled = ref(false);
const tweetId = ref<string | null>(null);
const tweetExpanded = ref(props.detail);
const noteId = ref<string | null>(null);
const noteRecord = ref<Record<string, Misskey.entities.Note>>({});
const tweetExpanded = ref(props.detail); // noteと兼用
const embedId = `embed${Math.random().toString().replace(/\D/, '')}`;
const tweetHeight = ref(150);
const unknownUrl = ref(false);
Expand All @@ -144,6 +164,18 @@ if (requestUrl.hostname === 'twitter.com' || requestUrl.hostname === 'mobile.twi
if (m) tweetId.value = m[1];
}

if (self && requestUrl.pathname.startsWith('/notes/')) {
const m = requestUrl.pathname.match(/^\/notes\/(\w+)$/);
if (m) noteId.value = m[1];
}

async function onExpandNote() {
noteRecord.value[noteId.value] = await misskeyApi('notes/show', {
noteId: noteId.value,
});
tweetExpanded.value = true;
}

if (requestUrl.hostname === 'music.youtube.com' && requestUrl.pathname.match('^/(?:watch|channel)')) {
requestUrl.hostname = 'www.youtube.com';
}
Expand Down Expand Up @@ -330,6 +362,17 @@ onUnmounted(() => {
margin-top: 6px;
}

.quote {
padding: 8px 0;
}

.quoteNote {
padding: 16px;
border: dashed 1px var(--MI_THEME-renote);
border-radius: 8px;
overflow: clip;
}

@container (max-width: 400px) {
.link {
font-size: 12px;
Expand Down
Loading