Skip to content

Commit

Permalink
enhance(frontend): Bluesky 게시물 임베디드 미리보기 지원 (misskey-dev/misskey#14933)
Browse files Browse the repository at this point in the history
  • Loading branch information
noridev committed Nov 26, 2024
1 parent d2ebd88 commit f026e8a
Show file tree
Hide file tree
Showing 28 changed files with 106 additions and 46 deletions.
1 change: 1 addition & 0 deletions CHANGELOG_CHERRYPICK.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ Misskey의 전체 변경 사항을 확인하려면, [CHANGELOG.md#2024xx](CHANGE
- Enhance: 외부 사이트 이동 경고 표시 개선 (kokonect-link/cherrypick#533)
- 신뢰할 수 있는 도메인 목록을 편집할 수 있음
- 경고를 표시하지 않도록 설정할 수 있음
- Enhance: Bluesky 게시물 임베디드 미리보기 지원 (misskey-dev/misskey#14933)
- Fix: 아바타 장식에서 가이드라인이 표시되지 않음
- Fix: 설정 페이지에서 글자수가 긴 일부 항목의 디자인이 잘못 표시될 수 있음
- Fix: 서브 노트의 동작 버튼이 정상적으로 작동하지 않을 수 있음 (kokonect-link/cherrypick#536)
Expand Down
2 changes: 1 addition & 1 deletion locales/ar-SA.yml
Original file line number Diff line number Diff line change
Expand Up @@ -568,7 +568,7 @@ poll: "استطلاع رأي"
useCw: "إخفاء المحتوى"
enablePlayer: "افتح مشغل الفيديو"
disablePlayer: "أغلق مشغل الفيديو"
expandTweet: "وسّع التغريدة"
expandPost: "وسّع التغريدة"
themeEditor: "مصمم القوالب"
description: "الوصف"
describeFile: "أضف تعليقًا توضيحيًا"
Expand Down
2 changes: 1 addition & 1 deletion locales/bn-BD.yml
Original file line number Diff line number Diff line change
Expand Up @@ -561,7 +561,7 @@ poll: "জরিপ"
useCw: "কন্টেন্ট লুকান"
enablePlayer: "ভিডিও প্লেয়ার খুলুন"
disablePlayer: "ভিডিও প্লেয়ার বন্ধ করুন"
expandTweet: "টুইট বিস্তারিত করুন"
expandPost: "টুইট বিস্তারিত করুন"
themeEditor: "থিম সম্পাদক"
description: "বর্ণনা"
describeFile: "ক্যাপশন যোগ করুন"
Expand Down
2 changes: 1 addition & 1 deletion locales/ca-ES.yml
Original file line number Diff line number Diff line change
Expand Up @@ -641,7 +641,7 @@ poll: "Enquesta"
useCw: "Amaga el contingut"
enablePlayer: "Obre el reproductor de vídeo"
disablePlayer: "Tanca el reproductor de vídeo"
expandTweet: "Expandir post"
expandPost: "Expandir post"
themeEditor: "Editor de temes"
description: "Descripció"
describeFile: "Afegir subtitulació"
Expand Down
2 changes: 1 addition & 1 deletion locales/cs-CZ.yml
Original file line number Diff line number Diff line change
Expand Up @@ -581,7 +581,7 @@ poll: "Anketa"
useCw: "Schovat obsah"
enablePlayer: "Otevřít video přehrávač"
disablePlayer: "Zavřít video přehrávač"
expandTweet: "Rozbalit tweet"
expandPost: "Rozbalit tweet"
themeEditor: "Editor témat"
description: "Popis"
describeFile: "Přidat popisek"
Expand Down
2 changes: 1 addition & 1 deletion locales/de-DE.yml
Original file line number Diff line number Diff line change
Expand Up @@ -644,7 +644,7 @@ poll: "Umfrage"
useCw: "Inhaltswarnung verwenden"
enablePlayer: "Video-Player öffnen"
disablePlayer: "Video-Player schließen"
expandTweet: "Tweet ausklappen"
expandPost: "Tweet ausklappen"
themeEditor: "Farbschema-Editor"
description: "Beschreibung"
describeFile: "Beschreibung hinzufügen"
Expand Down
2 changes: 1 addition & 1 deletion locales/en-US.yml
Original file line number Diff line number Diff line change
Expand Up @@ -776,7 +776,7 @@ poll: "Poll"
useCw: "Hide content"
enablePlayer: "Open video player"
disablePlayer: "Close video player"
expandTweet: "Expand post"
expandPost: "Expand post"
themeEditor: "Theme editor"
description: "Description"
describeFile: "Add caption"
Expand Down
2 changes: 1 addition & 1 deletion locales/es-ES.yml
Original file line number Diff line number Diff line change
Expand Up @@ -636,7 +636,7 @@ poll: "Encuesta"
useCw: "Esconder contenidos"
enablePlayer: "Abrir reproductor"
disablePlayer: "Cerrar reproductor"
expandTweet: "Expandir tweet"
expandPost: "Expandir tweet"
themeEditor: "Editor de temas"
description: "Descripción"
describeFile: "Añade una descripción"
Expand Down
2 changes: 1 addition & 1 deletion locales/fr-FR.yml
Original file line number Diff line number Diff line change
Expand Up @@ -638,7 +638,7 @@ poll: "Sondage"
useCw: "Masquer le contenu"
enablePlayer: "Ouvrir dans le lecteur vidéo"
disablePlayer: "Fermer le lecteur vidéo"
expandTweet: "Étendre le tweet"
expandPost: "Étendre le tweet"
themeEditor: "Éditeur de thèmes"
description: "Description"
describeFile: "Ajouter une description d'image"
Expand Down
2 changes: 1 addition & 1 deletion locales/id-ID.yml
Original file line number Diff line number Diff line change
Expand Up @@ -639,7 +639,7 @@ poll: "Angket"
useCw: "Sembunyikan konten"
enablePlayer: "Buka pemutar video"
disablePlayer: "Tutup pemutar video"
expandTweet: "Perluas utas"
expandPost: "Perluas utas"
themeEditor: "Penyunting tema"
description: "Deskripsi"
describeFile: "Tambahkan keterangan"
Expand Down
2 changes: 1 addition & 1 deletion locales/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3136,7 +3136,7 @@ export interface Locale extends ILocale {
/**
* ポストを展開する
*/
"expandTweet": string;
"expandPost": string;
/**
* テーマエディター
*/
Expand Down
2 changes: 1 addition & 1 deletion locales/it-IT.yml
Original file line number Diff line number Diff line change
Expand Up @@ -652,7 +652,7 @@ poll: "Sondaggio"
useCw: "Contenuto esplicito"
enablePlayer: "Visualizza"
disablePlayer: "Chiudi"
expandTweet: "Espandi tweet"
expandPost: "Espandi tweet"
themeEditor: "Editor di temi"
description: "Descrizione"
describeFile: "Aggiungi una descrizione d'immagine"
Expand Down
2 changes: 1 addition & 1 deletion locales/ja-JP.yml
Original file line number Diff line number Diff line change
Expand Up @@ -776,7 +776,7 @@ poll: "アンケート"
useCw: "内容を隠す"
enablePlayer: "プレイヤーを開く"
disablePlayer: "プレイヤーを閉じる"
expandTweet: "ポストを展開する"
expandPost: "ポストを展開する"
themeEditor: "テーマエディター"
description: "説明"
describeFile: "キャプションを付ける"
Expand Down
2 changes: 1 addition & 1 deletion locales/ja-KS.yml
Original file line number Diff line number Diff line change
Expand Up @@ -652,7 +652,7 @@ poll: "アンケート"
useCw: "内容を隠す"
enablePlayer: "プレイヤー開く"
disablePlayer: "プレイヤー閉じる"
expandTweet: "ポスト展開しとく"
expandPost: "ポスト展開しとく"
themeEditor: "テーマエディター"
description: "説明"
describeFile: "キャプションを付ける"
Expand Down
2 changes: 1 addition & 1 deletion locales/ko-KR.yml
Original file line number Diff line number Diff line change
Expand Up @@ -776,7 +776,7 @@ poll: "투표"
useCw: "내용 가리기"
enablePlayer: "플레이어 열기"
disablePlayer: "플레이어 닫기"
expandTweet: "게시물 확장하기"
expandPost: "게시물 확장하기"
themeEditor: "테마 에디터"
description: "설명"
describeFile: "캡션 추가"
Expand Down
2 changes: 1 addition & 1 deletion locales/pl-PL.yml
Original file line number Diff line number Diff line change
Expand Up @@ -627,7 +627,7 @@ poll: "Ankieta"
useCw: "Ukryj zawartość"
enablePlayer: "Otwórz odtwarzacz wideo"
disablePlayer: "Zamknij odtwarzacz wideo"
expandTweet: "Rozwiń tweet"
expandPost: "Rozwiń tweet"
themeEditor: "Edytor motywu"
description: "Opis"
describeFile: "Dodaj podpis"
Expand Down
2 changes: 1 addition & 1 deletion locales/pt-PT.yml
Original file line number Diff line number Diff line change
Expand Up @@ -627,7 +627,7 @@ poll: "Enquetes"
useCw: "Ocultar conteúdo"
enablePlayer: "Abrir o reprodutor de mídia"
disablePlayer: "Fechar o reprodutor de mídia"
expandTweet: "Expandir tweet"
expandPost: "Expandir tweet"
themeEditor: "Editor de temas"
description: "Descrição"
describeFile: "Adicionar legenda"
Expand Down
2 changes: 1 addition & 1 deletion locales/ro-RO.yml
Original file line number Diff line number Diff line change
Expand Up @@ -551,7 +551,7 @@ poll: "Sondaj"
useCw: "Ascunde conținutul"
enablePlayer: "Deschide player-ul video"
disablePlayer: "Închide player-ul video"
expandTweet: "Expandează tweet"
expandPost: "Expandează tweet"
themeEditor: "Editor de teme"
description: "Descriere"
describeFile: "Adaugă titrări"
Expand Down
2 changes: 1 addition & 1 deletion locales/ru-RU.yml
Original file line number Diff line number Diff line change
Expand Up @@ -640,7 +640,7 @@ poll: "Опрос"
useCw: "Скрывать содержимое под предупреждением"
enablePlayer: "Включить проигрыватель"
disablePlayer: "Выключить проигрыватель"
expandTweet: "Развернуть заметку"
expandPost: "Развернуть заметку"
themeEditor: "Редактор темы оформления"
description: "Описание"
describeFile: "Добавить подпись"
Expand Down
2 changes: 1 addition & 1 deletion locales/sk-SK.yml
Original file line number Diff line number Diff line change
Expand Up @@ -567,7 +567,7 @@ poll: "Hlasovanie"
useCw: "Skryť obsah"
enablePlayer: "Otvoriť video prehrávač"
disablePlayer: "Zavrieť video prehrávač"
expandTweet: "Rozšíriť tweet"
expandPost: "Rozšíriť tweet"
themeEditor: "Editor tém"
description: "Popis"
describeFile: "Pridať nadpis"
Expand Down
2 changes: 1 addition & 1 deletion locales/th-TH.yml
Original file line number Diff line number Diff line change
Expand Up @@ -652,7 +652,7 @@ poll: "โพล"
useCw: "ซ่อนเนื้อหา"
enablePlayer: "เปิดเครื่องเล่นวิดีโอ"
disablePlayer: "ปิดเครื่องเล่นวิดีโอ"
expandTweet: "ขยายทวีต"
expandPost: "ขยายทวีต"
themeEditor: "ตัวแก้ไขธีม"
description: "คำอธิบาย"
describeFile: "เพิ่มแคปชั่น"
Expand Down
2 changes: 1 addition & 1 deletion locales/uk-UA.yml
Original file line number Diff line number Diff line change
Expand Up @@ -566,7 +566,7 @@ poll: "Опитування"
useCw: "Приховати вміст"
enablePlayer: "Відкрити відеоплеєр"
disablePlayer: "Закрити відеоплеєр"
expandTweet: "Розгорнути твіт"
expandPost: "Розгорнути твіт"
themeEditor: "Редактор тем"
description: "Опис"
describeFile: "Додати підпис"
Expand Down
2 changes: 1 addition & 1 deletion locales/uz-UZ.yml
Original file line number Diff line number Diff line change
Expand Up @@ -567,7 +567,7 @@ poll: "So'ro'vnoma"
useCw: "Kontentni yashirish"
enablePlayer: "Video pleyerni ochish"
disablePlayer: "Video pleyerni yopish"
expandTweet: "Xabarni kengaytirish"
expandPost: "Xabarni kengaytirish"
themeEditor: "Rang sxemasi muharriri"
description: "tavsif"
describeFile: "sarlavha qo'shing"
Expand Down
2 changes: 1 addition & 1 deletion locales/vi-VN.yml
Original file line number Diff line number Diff line change
Expand Up @@ -614,7 +614,7 @@ poll: "Bình chọn"
useCw: "Ẩn nội dung"
enablePlayer: "Mở trình phát video"
disablePlayer: "Đóng trình phát video"
expandTweet: "Mở rộng tweet"
expandPost: "Mở rộng tweet"
themeEditor: "Công cụ thiết kế theme"
description: "Mô tả"
describeFile: "Thêm mô tả"
Expand Down
2 changes: 1 addition & 1 deletion locales/zh-CN.yml
Original file line number Diff line number Diff line change
Expand Up @@ -653,7 +653,7 @@ poll: "投票"
useCw: "隐藏内容"
enablePlayer: "打开播放器"
disablePlayer: "关闭播放器"
expandTweet: "展开帖子"
expandPost: "展开帖子"
themeEditor: "主题编辑器"
description: "描述"
describeFile: "添加描述"
Expand Down
2 changes: 1 addition & 1 deletion locales/zh-TW.yml
Original file line number Diff line number Diff line change
Expand Up @@ -653,7 +653,7 @@ poll: "票選活動"
useCw: "隱藏內容"
enablePlayer: "開啟播放器"
disablePlayer: "關閉播放器"
expandTweet: "展開推文"
expandPost: "展開推文"
themeEditor: "佈景主題編輯器"
description: "描述"
describeFile: "新增標題"
Expand Down
99 changes: 79 additions & 20 deletions packages/frontend/src/components/MkUrlPreview.vue
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,32 @@ SPDX-License-Identifier: AGPL-3.0-only
</MkButton>
</div>
</template>
<template v-else-if="tweetId && tweetExpanded">
<div ref="twitter">
<template v-else-if="tweetId && postExpanded">
<iframe
allow="fullscreen;web-share"
sandbox="allow-popups allow-popups-to-escape-sandbox allow-scripts allow-same-origin"
scrolling="no"
:style="{ position: 'relative', width: '100%', height: `${postHeight}px`, border: 0 }"
:src="`https://platform.twitter.com/embed/index.html?embedId=${embedId}&amp;hideCard=false&amp;hideThread=false&amp;lang=en&amp;theme=${defaultStore.state.darkMode ? 'dark' : 'light'}&amp;id=${tweetId}`"
></iframe>
<div :class="$style.action">
<MkButton :small="true" inline @click.stop="postExpanded = false">
<i class="ti ti-x"></i> {{ i18n.ts.close }}
</MkButton>
</div>
</template>
<template v-else-if="bskyDid && bskyPostRecordKey && postExpanded">
<div>
<iframe
ref="tweet"
allow="fullscreen;web-share"
sandbox="allow-popups allow-popups-to-escape-sandbox allow-scripts allow-same-origin"
scrolling="no"
:style="{ position: 'relative', width: '100%', height: `${tweetHeight}px`, border: 0 }"
:src="`https://platform.twitter.com/embed/index.html?embedId=${embedId}&amp;hideCard=false&amp;hideThread=false&amp;lang=en&amp;theme=${defaultStore.state.darkMode ? 'dark' : 'light'}&amp;id=${tweetId}`"
:style="{ position: 'relative', width: '100%', height: `${postHeight}px`, border: 0 }"
:src="`https://embed.bsky.app/embed/${bskyDid}/app.bsky.feed.post/${bskyPostRecordKey}?id=${embedId}`"
></iframe>
</div>
<div :class="$style.action">
<MkButton :small="true" inline @click.stop="tweetExpanded = false">
<MkButton :small="true" inline @click.stop="postExpanded = false">
<i class="ti ti-x"></i> {{ i18n.ts.close }}
</MkButton>
</div>
Expand Down Expand Up @@ -66,8 +79,13 @@ SPDX-License-Identifier: AGPL-3.0-only
</component>
<template v-if="showActions">
<div v-if="tweetId" :class="$style.action">
<MkButton :small="true" inline @click.stop="tweetExpanded = true">
<i class="ti ti-brand-x"></i> {{ i18n.ts.expandTweet }}
<MkButton :small="true" inline @click.stop="postExpanded = true">
<i class="ti ti-brand-x"></i> {{ i18n.ts.expandPost }}
</MkButton>
</div>
<div v-if="bskyPostRecordKey" :class="$style.action">
<MkButton :small="true" inline @click.stop="openBskyEmbed">
<i class="ti ti-brand-bluesky"></i> {{ i18n.ts.expandPost }}
</MkButton>
</div>
<div v-if="!playerEnabled && player.url" :class="$style.action">
Expand Down Expand Up @@ -127,10 +145,17 @@ const player = ref({
height: null,
} as SummalyResult['player']);
const playerEnabled = ref(false);
const tweetId = ref<string | null>(null);
const tweetExpanded = ref(props.detail);
const embedId = `embed${Math.random().toString().replace(/\D/, '')}`;
const tweetHeight = ref(150);

const postExpanded = ref(props.detail);
const postHeight = ref(150);

const tweetId = ref<string | null>(null);

const bskyHandleOrDid = ref<string | null>(null);
const bskyDid = ref<string | null>(null);
const bskyPostRecordKey = ref<string | null>(null);

const unknownUrl = ref(false);

onDeactivated(() => {
Expand All @@ -145,6 +170,17 @@ if (requestUrl.hostname === 'twitter.com' || requestUrl.hostname === 'mobile.twi
if (m) tweetId.value = m[1];
}

if (requestUrl.hostname === 'bsky.app') {
const bskyPostPageUrl = requestUrl.pathname.slice(1).split('/');
if (bskyPostPageUrl[0] === 'profile' && bskyPostPageUrl[1] && bskyPostPageUrl[2] === 'post' && bskyPostPageUrl[3]) {
bskyHandleOrDid.value = bskyPostPageUrl[1];
bskyPostRecordKey.value = bskyPostPageUrl[3];
if (postExpanded.value) {
openBskyEmbed();
}
}
}

if (requestUrl.hostname === 'music.youtube.com' && requestUrl.pathname.match('^/(?:watch|channel)')) {
requestUrl.hostname = 'www.youtube.com';
}
Expand Down Expand Up @@ -181,13 +217,21 @@ window.fetch(`/url?url=${encodeURIComponent(requestUrl.href)}&lang=${versatileLa
sensitive.value = info.sensitive ?? false;
});

function adjustTweetHeight(message: MessageEvent) {
if (message.origin !== 'https://platform.twitter.com') return;
const embed = message.data?.['twttr.embed'];
if (embed?.method !== 'twttr.private.resize') return;
if (embed?.id !== embedId) return;
const height = embed?.params[0]?.height;
if (height) tweetHeight.value = height;
async function openBskyEmbed() {
if (bskyHandleOrDid.value == null || bskyPostRecordKey.value == null) return;
if (bskyDid.value == null) {
if (bskyHandleOrDid.value.startsWith('did:')) {
bskyDid.value = bskyHandleOrDid.value;
} else {
// handleで来ている場合はdidに変換
const bskyApiRes = await window.fetch(`https://public.api.bsky.app/xrpc/com.atproto.identity.resolveHandle?handle=${bskyHandleOrDid.value}`);
if (bskyApiRes.ok) {
const bskyApiData = await bskyApiRes.json() as { did: string };
bskyDid.value = bskyApiData.did;
}
}
}
postExpanded.value = true;
}

function openPlayer(): void {
Expand All @@ -200,10 +244,25 @@ function openPlayer(): void {
});
}

window.addEventListener('message', adjustTweetHeight);
function adjustSocialsEmbedHeight(message: MessageEvent) {
if (message.origin === 'https://platform.twitter.com') {
const embed = message.data?.['twttr.embed'];
if (embed?.method === 'twttr.private.resize' && embed?.id === embedId) {
const height = embed?.params[0]?.height;
if (height) postHeight.value = height;
}
} else if (message.origin === 'https://embed.bsky.app') {
if (message.data?.id === embedId) {
const height = message.data?.height;
if (height) postHeight.value = height;
}
}
}

window.addEventListener('message', adjustSocialsEmbedHeight);

onUnmounted(() => {
window.removeEventListener('message', adjustTweetHeight);
window.removeEventListener('message', adjustSocialsEmbedHeight);
});
</script>

Expand Down
2 changes: 1 addition & 1 deletion packages/frontend/src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
style-src 'self' 'unsafe-inline';
img-src 'self' data: blob: www.google.com xn--931a.moe localhost:3000 localhost:5173 127.0.0.1:5173 127.0.0.1:3000;
media-src 'self' localhost:3000 localhost:5173 127.0.0.1:5173 127.0.0.1:3000;
connect-src 'self' localhost:3000 localhost:5173 127.0.0.1:5173 127.0.0.1:3000 https://newassets.hcaptcha.com;
connect-src 'self' localhost:3000 localhost:5173 127.0.0.1:5173 127.0.0.1:3000 https://newassets.hcaptcha.com https://public.api.bsky.app;
frame-src *;"
/>
<meta property="og:site_name" content="[DEV BUILD] CherryPick" />
Expand Down

0 comments on commit f026e8a

Please sign in to comment.