From 712851d02a0773accf29ddf5a7d3704718f4a8c1 Mon Sep 17 00:00:00 2001 From: Hoto Ras Date: Sun, 25 Aug 2024 18:25:46 +0900 Subject: [PATCH] =?UTF-8?q?fix=20(frontend):=20=EB=85=B8=ED=8A=B8=20?= =?UTF-8?q?=EC=97=85=EB=8D=B0=EC=9D=B4=ED=8A=B8=20=EC=8B=9C=20notes/update?= =?UTF-8?q?=20api=EB=A5=BC=20=ED=98=B8=EC=B6=9C=ED=95=98=EB=8F=84=EB=A1=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 기존; notes/create api만 호출하도록 되어 있었음 -> notes/update와 이를 핸들링하기 위한 부분을 추가해 랜딩 --- .../frontend/src/components/MkPostForm.vue | 79 +++++++++++++++++++ .../src/components/MkPostFormDialog.vue | 2 + 2 files changed, 81 insertions(+) diff --git a/packages/frontend/src/components/MkPostForm.vue b/packages/frontend/src/components/MkPostForm.vue index 51ec941c9798..f78aee86a5d8 100644 --- a/packages/frontend/src/components/MkPostForm.vue +++ b/packages/frontend/src/components/MkPostForm.vue @@ -152,6 +152,7 @@ const props = withDefaults(defineProps<{ autofocus?: boolean; freezeAfterPosted?: boolean; mock?: boolean; + editMode?: boolean; }>(), { initialVisibleUsers: () => [], autofocus: true, @@ -790,6 +791,13 @@ async function post(ev?: MouseEvent) { reactionAcceptance: reactionAcceptance.value, }; + if (props.initialNote && props.editMode) { + postData.updatedAt = new Date(); + postData.updatedAtHistory = props.initialNote.updatedAtHistory; + postData.updatedAtHistory.push(updatedAt); + postData.id = props.initialNote.id; + } + if (withHashtags.value && hashtags.value && hashtags.value.trim() !== '') { const hashtags_ = hashtags.value.trim().split(' ').map(x => x.startsWith('#') ? x : '#' + x).join(' '); if (!postData.text) { @@ -824,6 +832,77 @@ async function post(ev?: MouseEvent) { } posting.value = true; + + if (props.editMode) { + misskeyApi('notes/update', postData, token).then(() => { + if (props.freezeAfterPosted) { + posted.value = true; + } else { + clear(); + } + nextTick(() => { + deleteDraft(); + emit('posted'); + if (postData.text && postData.text !== '') { + const hashtags_ = mfm.parse(postData.text).map(x => x.type === 'hashtag' && x.props.hashtag).filter(x => x) as string[]; + const history = JSON.parse(miLocalStorage.getItem('hashtags') ?? '[]') as string[]; + miLocalStorage.setItem('hashtags', JSON.stringify(unique(hashtags_.concat(history)))); + } + posting.value = false; + postAccount.value = null; + + incNotesCount(); + if (notesCount === 1) { + claimAchievement('notes1'); + } + + const text = postData.text ?? ''; + const lowerCase = text.toLowerCase(); + if ((lowerCase.includes('love') || lowerCase.includes('❤')) && lowerCase.includes('misskey')) { + claimAchievement('iLoveMisskey'); + } + if ([ + 'https://youtu.be/Efrlqw8ytg4', + 'https://www.youtube.com/watch?v=Efrlqw8ytg4', + 'https://m.youtube.com/watch?v=Efrlqw8ytg4', + + 'https://youtu.be/XVCwzwxdHuA', + 'https://www.youtube.com/watch?v=XVCwzwxdHuA', + 'https://m.youtube.com/watch?v=XVCwzwxdHuA', + + 'https://open.spotify.com/track/3Cuj0mZrlLoXx9nydNi7RB', + 'https://open.spotify.com/track/7anfcaNPQWlWCwyCHmZqNy', + 'https://open.spotify.com/track/5Odr16TvEN4my22K9nbH7l', + 'https://open.spotify.com/album/5bOlxyl4igOrp2DwVQxBco', + ].some(url => text.includes(url))) { + claimAchievement('brainDiver'); + } + + if (props.renote && (props.renote.userId === $i.id) && text.length > 0) { + claimAchievement('selfQuote'); + } + + const date = new Date(); + const h = date.getHours(); + const m = date.getMinutes(); + const s = date.getSeconds(); + if (h >= 0 && h <= 3) { + claimAchievement('postedAtLateNight'); + } + if (m === 0 && s === 0) { + claimAchievement('postedAt0min0sec'); + } + }); + }).catch(err => { + posting.value = false; + os.alert({ + type: 'error', + text: err.message + '\n' + (err as any).id, + }); + }); + return; + } + misskeyApi('notes/create', postData, token).then(() => { if (props.freezeAfterPosted) { posted.value = true; diff --git a/packages/frontend/src/components/MkPostFormDialog.vue b/packages/frontend/src/components/MkPostFormDialog.vue index d6bca290504d..3d858330c6f6 100644 --- a/packages/frontend/src/components/MkPostFormDialog.vue +++ b/packages/frontend/src/components/MkPostFormDialog.vue @@ -31,8 +31,10 @@ const props = withDefaults(defineProps<{ instant?: boolean; fixed?: boolean; autofocus?: boolean; + editMode?: boolean; }>(), { initialLocalOnly: undefined, + editMode: false, }); const emit = defineEmits<{