mirror of
https://github.com/paricafe/misskey.git
synced 2024-11-30 23:26:44 -06:00
noteCapture update counts
This commit is contained in:
parent
f38364b82b
commit
ee463be450
3 changed files with 41 additions and 3 deletions
|
@ -417,6 +417,9 @@ if (props.mock) {
|
||||||
note: appearNote,
|
note: appearNote,
|
||||||
pureNote: note,
|
pureNote: note,
|
||||||
isDeletedRef: isDeleted,
|
isDeletedRef: isDeleted,
|
||||||
|
onReplyCallback: () => {
|
||||||
|
appearNote.value.repliesCount += 1;
|
||||||
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -193,7 +193,7 @@ SPDX-License-Identifier: AGPL-3.0-only
|
||||||
<!-- <div v-if="!repliesLoaded" style="padding: 16px">
|
<!-- <div v-if="!repliesLoaded" style="padding: 16px">
|
||||||
<MkButton style="margin: 0 auto;" primary rounded @click="loadReplies">{{ i18n.ts.loadReplies }}</MkButton>
|
<MkButton style="margin: 0 auto;" primary rounded @click="loadReplies">{{ i18n.ts.loadReplies }}</MkButton>
|
||||||
</div> -->
|
</div> -->
|
||||||
<MkNoteSub v-for="note in replies" :key="note.id" :note="note" :class="$style.reply" :detail="true"/>
|
<MkNoteSub v-for="note in replies" :key="note.id" :note="note" :class="$style.reply" :detail="true" :onDeleteCallback="removeReply" :isReply="true"/>
|
||||||
</div>
|
</div>
|
||||||
<div v-else-if="tab === 'renotes'" :class="$style.tab_renotes">
|
<div v-else-if="tab === 'renotes'" :class="$style.tab_renotes">
|
||||||
<MkPagination :pagination="renotesPagination" :disableAutoLoad="true">
|
<MkPagination :pagination="renotesPagination" :disableAutoLoad="true">
|
||||||
|
@ -400,11 +400,25 @@ const reactionsPagination = computed<Paging>(() => ({
|
||||||
},
|
},
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
async function addReplyTo(replyNote: Misskey.entities.Note) {
|
||||||
|
replies.value.unshift(replyNote);
|
||||||
|
appearNote.value.repliesCount += 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
async function removeReply(id: Misskey.entities.Note['id']) {
|
||||||
|
const replyIdx = replies.value.findIndex(note => note.id === id);
|
||||||
|
if (replyIdx >= 0) {
|
||||||
|
replies.value.splice(replyIdx, 1);
|
||||||
|
appearNote.value.repliesCount -= 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
useNoteCapture({
|
useNoteCapture({
|
||||||
rootEl: rootEl,
|
rootEl: rootEl,
|
||||||
note: appearNote,
|
note: appearNote,
|
||||||
pureNote: note,
|
pureNote: note,
|
||||||
isDeletedRef: isDeleted,
|
isDeletedRef: isDeleted,
|
||||||
|
onReplyCallback: addReplyTo,
|
||||||
});
|
});
|
||||||
|
|
||||||
useTooltip(renoteButton, async (showing) => {
|
useTooltip(renoteButton, async (showing) => {
|
||||||
|
|
|
@ -5,25 +5,44 @@
|
||||||
|
|
||||||
import { onUnmounted, Ref, ShallowRef } from 'vue';
|
import { onUnmounted, Ref, ShallowRef } from 'vue';
|
||||||
import * as Misskey from 'misskey-js';
|
import * as Misskey from 'misskey-js';
|
||||||
|
import { misskeyApi } from './misskey-api.js';
|
||||||
import { useStream } from '@/stream.js';
|
import { useStream } from '@/stream.js';
|
||||||
import { $i } from '@/account.js';
|
import { $i } from '@/account.js';
|
||||||
|
import * as os from '@/os.js';
|
||||||
|
|
||||||
export function useNoteCapture(props: {
|
export function useNoteCapture(props: {
|
||||||
rootEl: ShallowRef<HTMLElement | undefined>;
|
rootEl: ShallowRef<HTMLElement | undefined>;
|
||||||
note: Ref<Misskey.entities.Note>;
|
note: Ref<Misskey.entities.Note>;
|
||||||
pureNote: Ref<Misskey.entities.Note>;
|
pureNote?: Ref<Misskey.entities.Note>;
|
||||||
isDeletedRef: Ref<boolean>;
|
isDeletedRef: Ref<boolean>;
|
||||||
|
onReplyCallback?: (replyNote: Misskey.entities.Note) => void | Promise<void>;
|
||||||
|
onDeleteCallback?: (id: Misskey.entities.Note['id']) => void | Promise<void>;
|
||||||
}) {
|
}) {
|
||||||
const note = props.note;
|
const note = props.note;
|
||||||
const pureNote = props.pureNote;
|
const pureNote = props.pureNote;
|
||||||
const connection = $i ? useStream() : null;
|
const connection = $i ? useStream() : null;
|
||||||
|
|
||||||
function onStreamNoteUpdated(noteData): void {
|
async function onStreamNoteUpdated(noteData): Promise<void> {
|
||||||
const { type, id, body } = noteData;
|
const { type, id, body } = noteData;
|
||||||
|
|
||||||
if ((id !== note.value.id) && (id !== pureNote.value.id)) return;
|
if ((id !== note.value.id) && (id !== pureNote.value.id)) return;
|
||||||
|
|
||||||
switch (type) {
|
switch (type) {
|
||||||
|
case 'replied': {
|
||||||
|
if (!props.onReplyCallback) break;
|
||||||
|
|
||||||
|
// notes/show may throw if the current user can't see the note
|
||||||
|
try {
|
||||||
|
const replyNote = await misskeyApi('notes/show', {
|
||||||
|
noteId: body.id,
|
||||||
|
});
|
||||||
|
|
||||||
|
await props.onReplyCallback(replyNote);
|
||||||
|
} catch { /* empty */ }
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
case 'reacted': {
|
case 'reacted': {
|
||||||
const reaction = body.reaction;
|
const reaction = body.reaction;
|
||||||
|
|
||||||
|
@ -96,6 +115,8 @@ export function useNoteCapture(props: {
|
||||||
|
|
||||||
case 'deleted': {
|
case 'deleted': {
|
||||||
props.isDeletedRef.value = true;
|
props.isDeletedRef.value = true;
|
||||||
|
|
||||||
|
if (props.onDeleteCallback) await props.onDeleteCallback(id);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue