fix: move isRenote check to note.vue

This commit is contained in:
Freeplay 2023-05-28 20:20:53 -04:00
parent 27307a8de2
commit 0741df711a
2 changed files with 56 additions and 60 deletions

View file

@ -17,10 +17,10 @@
:note="note" :note="note"
:detailedView="true" :detailedView="true"
/> />
<MkLoading v-else-if="appearNote.reply" mini /> <MkLoading v-else-if="note.reply" mini />
<MkNoteSub <MkNoteSub
v-if="appearNote.reply" v-if="note.reply"
:note="appearNote.reply" :note="note.reply"
class="reply-to" class="reply-to"
:detailedView="true" :detailedView="true"
/> />
@ -29,21 +29,21 @@
ref="noteEl" ref="noteEl"
@contextmenu.stop="onContextmenu" @contextmenu.stop="onContextmenu"
tabindex="-1" tabindex="-1"
:note="appearNote" :note="note"
detailedView detailedView
></MkNote> ></MkNote>
<MkTab v-model="tab" :style="'underline'" @update:modelValue="loadTab"> <MkTab v-model="tab" :style="'underline'" @update:modelValue="loadTab">
<option value="replies"> <option value="replies">
<!-- <i class="ph-arrow-u-up-left ph-bold ph-lg"></i> --> <!-- <i class="ph-arrow-u-up-left ph-bold ph-lg"></i> -->
<span v-if="appearNote.repliesCount > 0" class="count">{{ <span v-if="note.repliesCount > 0" class="count">{{
appearNote.repliesCount note.repliesCount
}}</span> }}</span>
{{ i18n.ts._notification._types.reply }} {{ i18n.ts._notification._types.reply }}
</option> </option>
<option value="renotes" v-if="appearNote.renoteCount > 0"> <option value="renotes" v-if="note.renoteCount > 0">
<!-- <i class="ph-repeat ph-bold ph-lg"></i> --> <!-- <i class="ph-repeat ph-bold ph-lg"></i> -->
<span class="count">{{ appearNote.renoteCount }}</span> <span class="count">{{ note.renoteCount }}</span>
{{ i18n.ts._notification._types.renote }} {{ i18n.ts._notification._types.renote }}
</option> </option>
<option value="reactions" v-if="reactionsCount > 0"> <option value="reactions" v-if="reactionsCount > 0">
@ -71,10 +71,10 @@
class="reply" class="reply"
:conversation="replies" :conversation="replies"
:detailedView="true" :detailedView="true"
:parentId="appearNote.id" :parentId="note.id"
/> />
<MkLoading <MkLoading
v-else-if="tab === 'replies' && appearNote.repliesCount > 0" v-else-if="tab === 'replies' && note.repliesCount > 0"
/> />
<MkNoteSub <MkNoteSub
@ -85,7 +85,7 @@
class="reply" class="reply"
:conversation="replies" :conversation="replies"
:detailedView="true" :detailedView="true"
:parentId="appearNote.id" :parentId="note.id"
/> />
<MkLoading v-else-if="tab === 'quotes' && directQuotes.length > 0" /> <MkLoading v-else-if="tab === 'quotes' && directQuotes.length > 0" />
@ -104,7 +104,7 @@
/> />
<!-- </MkPagination> --> <!-- </MkPagination> -->
<MkLoading <MkLoading
v-else-if="tab === 'renotes' && appearNote.renoteCount > 0" v-else-if="tab === 'renotes' && note.renoteCount > 0"
/> />
<div v-if="tab === 'clips' && clips.length > 0" class="_content clips"> <div v-if="tab === 'clips' && clips.length > 0" class="_content clips">
@ -132,7 +132,7 @@
<MkReactedUsers <MkReactedUsers
v-if="tab === 'reactions' && reactionsCount > 0" v-if="tab === 'reactions' && reactionsCount > 0"
:note-id="appearNote.id" :note-id="note.id"
></MkReactedUsers> ></MkReactedUsers>
</div> </div>
<div v-else class="_panel muted" @click="muted.muted = false"> <div v-else class="_panel muted" @click="muted.muted = false">
@ -217,23 +217,11 @@ if (noteViewInterruptors.length > 0) {
}); });
} }
const isRenote =
note.renote != null &&
note.text == null &&
note.fileIds.length === 0 &&
note.poll == null;
const el = ref<HTMLElement>(); const el = ref<HTMLElement>();
const noteEl = $ref(); const noteEl = $ref();
const menuButton = ref<HTMLElement>(); const menuButton = ref<HTMLElement>();
const starButton = ref<InstanceType<typeof XStarButton>>();
const renoteButton = ref<InstanceType<typeof XRenoteButton>>(); const renoteButton = ref<InstanceType<typeof XRenoteButton>>();
const renoteTime = ref<HTMLElement>();
const reactButton = ref<HTMLElement>(); const reactButton = ref<HTMLElement>();
let appearNote = $computed(() =>
isRenote ? (note.renote as misskey.entities.Note) : note
);
const isMyRenote = $i && $i.id === note.userId;
const showContent = ref(false); const showContent = ref(false);
const isDeleted = ref(false); const isDeleted = ref(false);
const muted = ref(getWordSoftMute(note, $i, defaultStore.state.mutedWords)); const muted = ref(getWordSoftMute(note, $i, defaultStore.state.mutedWords));
@ -263,14 +251,14 @@ const keymap = {
useNoteCapture({ useNoteCapture({
rootEl: el, rootEl: el,
note: $$(appearNote), note: $$(note),
isDeletedRef: isDeleted, isDeletedRef: isDeleted,
}); });
function reply(viaKeyboard = false): void { function reply(viaKeyboard = false): void {
pleaseLogin(); pleaseLogin();
os.post({ os.post({
reply: appearNote, reply: note,
animation: !viaKeyboard, animation: !viaKeyboard,
}).then(() => { }).then(() => {
focus(); focus();
@ -284,7 +272,7 @@ function react(viaKeyboard = false): void {
reactButton.value, reactButton.value,
(reaction) => { (reaction) => {
os.api("notes/reactions/create", { os.api("notes/reactions/create", {
noteId: appearNote.id, noteId: note.id,
reaction: reaction, reaction: reaction,
}); });
}, },
@ -355,27 +343,27 @@ function blur() {
directReplies = null; directReplies = null;
os.api("notes/children", { os.api("notes/children", {
noteId: appearNote.id, noteId: note.id,
limit: 30, limit: 30,
depth: 12, depth: 12,
}).then((res) => { }).then((res) => {
res = res.reduce((acc, note) => { res = res.reduce((acc, resNote) => {
if (note.userId == appearNote.userId) { if (resNote.userId == note.userId) {
return [...acc, note]; return [...acc, resNote];
} }
return [note, ...acc]; return [resNote, ...acc];
}, []); }, []);
replies.value = res; replies.value = res;
directReplies = res directReplies = res
.filter((note) => note.replyId === appearNote.id) .filter((resNote) => resNote.replyId === note.id)
.reverse(); .reverse();
directQuotes = res.filter((note) => note.renoteId === appearNote.id); directQuotes = res.filter((resNote) => resNote.renoteId === note.id);
}); });
conversation = null; conversation = null;
if (appearNote.replyId) { if (note.replyId) {
os.api("notes/conversation", { os.api("notes/conversation", {
noteId: appearNote.replyId, noteId: note.replyId,
limit: 30, limit: 30,
}).then((res) => { }).then((res) => {
conversation = res.reverse(); conversation = res.reverse();
@ -385,14 +373,14 @@ if (appearNote.replyId) {
clips = null; clips = null;
os.api("notes/clips", { os.api("notes/clips", {
noteId: appearNote.id, noteId: note.id,
}).then((res) => { }).then((res) => {
clips = res; clips = res;
}); });
// const pagination = { // const pagination = {
// endpoint: "notes/renotes", // endpoint: "notes/renotes",
// noteId: appearNote.id, // noteId: note.id,
// limit: 10, // limit: 10,
// }; // };
@ -402,7 +390,7 @@ renotes = null;
function loadTab() { function loadTab() {
if (tab === "renotes" && !renotes) { if (tab === "renotes" && !renotes) {
os.api("notes/renotes", { os.api("notes/renotes", {
noteId: appearNote.id, noteId: note.id,
limit: 100, limit: 100,
}).then((res) => { }).then((res) => {
renotes = res; renotes = res;
@ -414,7 +402,7 @@ async function onNoteUpdated(noteData: NoteUpdatedEvent): Promise<void> {
const { type, id, body } = noteData; const { type, id, body } = noteData;
let found = -1; let found = -1;
if (id === appearNote.id) { if (id === note.id) {
found = 0; found = 0;
} else { } else {
for (let i = 0; i < replies.value.length; i++) { for (let i = 0; i < replies.value.length; i++) {

View file

@ -13,7 +13,7 @@
:name="$store.state.animation ? 'fade' : ''" :name="$store.state.animation ? 'fade' : ''"
mode="out-in" mode="out-in"
> >
<div v-if="note" class="note"> <div v-if="appearNote" class="note">
<div v-if="showNext" class="_gap"> <div v-if="showNext" class="_gap">
<XNotes <XNotes
class="_content" class="_content"
@ -33,12 +33,12 @@
</MkButton> </MkButton>
<div class="note _gap"> <div class="note _gap">
<MkRemoteCaution <MkRemoteCaution
v-if="note.user.host != null" v-if="appearNote.user.host != null"
:href="note.url ?? note.uri" :href="appearNote.url ?? appearNote.uri"
/> />
<XNoteDetailed <XNoteDetailed
:key="note.id" :key="appearNote.id"
v-model:note="note" v-model:note="appearNote"
class="note" class="note"
/> />
</div> </div>
@ -71,7 +71,6 @@
<script lang="ts" setup> <script lang="ts" setup>
import { computed, defineComponent, watch } from "vue"; import { computed, defineComponent, watch } from "vue";
import * as misskey from "calckey-js"; import * as misskey from "calckey-js";
import XNote from "@/components/MkNote.vue";
import XNoteDetailed from "@/components/MkNoteDetailed.vue"; import XNoteDetailed from "@/components/MkNoteDetailed.vue";
import XNotes from "@/components/MkNotes.vue"; import XNotes from "@/components/MkNotes.vue";
import MkRemoteCaution from "@/components/MkRemoteCaution.vue"; import MkRemoteCaution from "@/components/MkRemoteCaution.vue";
@ -90,15 +89,17 @@ let hasNext = $ref(false);
let showPrev = $ref(false); let showPrev = $ref(false);
let showNext = $ref(false); let showNext = $ref(false);
let error = $ref(); let error = $ref();
let isRenote = $ref(false);
let appearNote = $ref<null | misskey.entities.Note>();
const prevPagination = { const prevPagination = {
endpoint: "users/notes" as const, endpoint: "users/notes" as const,
limit: 10, limit: 10,
params: computed(() => params: computed(() =>
note appearNote
? { ? {
userId: note.userId, userId: appearNote.userId,
untilId: note.id, untilId: appearNote.id,
} }
: null : null
), ),
@ -109,10 +110,10 @@ const nextPagination = {
endpoint: "users/notes" as const, endpoint: "users/notes" as const,
limit: 10, limit: 10,
params: computed(() => params: computed(() =>
note appearNote
? { ? {
userId: note.userId, userId: appearNote.userId,
sinceId: note.id, sinceId: appearNote.id,
} }
: null : null
), ),
@ -129,6 +130,13 @@ function fetchNote() {
}) })
.then((res) => { .then((res) => {
note = res; note = res;
isRenote =
note.renote != null &&
note.text == null &&
note.fileIds.length === 0 &&
note.poll == null;
appearNote = isRenote ? (note.renote as misskey.entities.Note) : note;
Promise.all([ Promise.all([
os.api("users/notes", { os.api("users/notes", {
userId: note.userId, userId: note.userId,
@ -160,19 +168,19 @@ const headerTabs = $computed(() => []);
definePageMetadata( definePageMetadata(
computed(() => computed(() =>
note appearNote
? { ? {
title: i18n.t("noteOf", { title: i18n.t("noteOf", {
user: note.user.name || note.user.username, user: appearNote.user.name || appearNote.user.username,
}), }),
subtitle: new Date(note.createdAt).toLocaleString(), subtitle: new Date(appearNote.createdAt).toLocaleString(),
avatar: note.user, avatar: appearNote.user,
path: `/notes/${note.id}`, path: `/notes/${appearNote.id}`,
share: { share: {
title: i18n.t("noteOf", { title: i18n.t("noteOf", {
user: note.user.name || note.user.username, user: appearNote.user.name || appearNote.user.username,
}), }),
text: note.text, text: appearNote.text,
}, },
} }
: null : null