upd: add renote limit to other note components

This commit is contained in:
Mar0xy 2023-10-13 21:53:38 +02:00
parent cea2de6209
commit 363df5b256
No known key found for this signature in database
GPG key ID: 56569BBE47D2C828
2 changed files with 55 additions and 11 deletions

View file

@ -100,7 +100,8 @@ SPDX-License-Identifier: AGPL-3.0-only
ref="renoteButton" ref="renoteButton"
:class="$style.footerButton" :class="$style.footerButton"
class="_button" class="_button"
@mousedown="renote()" :style="renoted ? 'color: var(--accent) !important;' : ''"
@mousedown="renoted ? undoRenote() : renote()"
> >
<i class="ph-repeat ph-bold ph-lg"></i> <i class="ph-repeat ph-bold ph-lg"></i>
<p v-if="appearNote.renoteCount > 0" :class="$style.footerButtonCount">{{ appearNote.renoteCount }}</p> <p v-if="appearNote.renoteCount > 0" :class="$style.footerButtonCount">{{ appearNote.renoteCount }}</p>
@ -226,6 +227,7 @@ const urls = appearNote.text ? extractUrlFromMfm(mfm.parse(appearNote.text)).fil
const isLong = shouldCollapsed(appearNote); const isLong = shouldCollapsed(appearNote);
const collapsed = ref(appearNote.cw == null && isLong); const collapsed = ref(appearNote.cw == null && isLong);
const isDeleted = ref(false); const isDeleted = ref(false);
const renoted = ref(false);
const muted = ref($i ? checkWordMute(appearNote, $i, $i.mutedWords) : false); const muted = ref($i ? checkWordMute(appearNote, $i, $i.mutedWords) : false);
const translation = ref<any>(null); const translation = ref<any>(null);
const translating = ref(false); const translating = ref(false);
@ -268,6 +270,16 @@ useTooltip(renoteButton, async (showing) => {
}, {}, 'closed'); }, {}, 'closed');
}); });
if ($i) {
os.api("notes/renotes", {
noteId: appearNote.id,
userId: $i.id,
limit: 1,
}).then((res) => {
renoted.value = res.length > 0;
});
}
type Visibility = 'public' | 'home' | 'followers' | 'specified'; type Visibility = 'public' | 'home' | 'followers' | 'specified';
// defaultStore.state.visibilitystringstring // defaultStore.state.visibilitystringstring
@ -288,7 +300,7 @@ function renote(viaKeyboard = false) {
if (appearNote.channel) { if (appearNote.channel) {
items = items.concat([{ items = items.concat([{
text: i18n.ts.inChannelRenote, text: i18n.ts.inChannelRenote,
icon: 'ph-repeat ph-bold ph-lg', icon: 'ph-rocket-launch ph-bold ph-lg',
action: () => { action: () => {
const el = renoteButton.value as HTMLElement | null | undefined; const el = renoteButton.value as HTMLElement | null | undefined;
if (el) { if (el) {
@ -303,6 +315,7 @@ function renote(viaKeyboard = false) {
channelId: appearNote.channelId, channelId: appearNote.channelId,
}).then(() => { }).then(() => {
os.toast(i18n.ts.renoted); os.toast(i18n.ts.renoted);
renoted.value = true;
}); });
}, },
}, { }, {
@ -319,7 +332,7 @@ function renote(viaKeyboard = false) {
items = items.concat([{ items = items.concat([{
text: i18n.ts.renote, text: i18n.ts.renote,
icon: 'ph-repeat ph-bold ph-lg', icon: 'ph-rocket-launch ph-bold ph-lg',
action: () => { action: () => {
const el = renoteButton.value as HTMLElement | null | undefined; const el = renoteButton.value as HTMLElement | null | undefined;
if (el) { if (el) {
@ -344,6 +357,7 @@ function renote(viaKeyboard = false) {
renoteId: appearNote.id, renoteId: appearNote.id,
}).then(() => { }).then(() => {
os.toast(i18n.ts.renoted); os.toast(i18n.ts.renoted);
renoted.value = true;
}); });
}, },
}, { }, {
@ -427,6 +441,14 @@ function undoReact(note): void {
}); });
} }
function undoRenote() : void {
if (!renoted) return;
os.api("notes/unrenote", {
noteId: appearNote.id,
});
renoted.value = false;
}
function onContextmenu(ev: MouseEvent): void { function onContextmenu(ev: MouseEvent): void {
const isLink = (el: HTMLElement) => { const isLink = (el: HTMLElement) => {
if (el.tagName === 'A') return true; if (el.tagName === 'A') return true;

View file

@ -26,13 +26,14 @@ SPDX-License-Identifier: AGPL-3.0-only
<p v-if="note.repliesCount > 0" :class="$style.noteFooterButtonCount">{{ note.repliesCount }}</p> <p v-if="note.repliesCount > 0" :class="$style.noteFooterButtonCount">{{ note.repliesCount }}</p>
</button> </button>
<button <button
v-if="canRenote" v-if="canRenote"
ref="renoteButton" ref="renoteButton"
class="_button" class="_button"
:class="$style.noteFooterButton" :class="$style.noteFooterButton"
@mousedown="renote()" :style="renoted ? 'color: var(--accent) !important;' : ''"
@mousedown="renoted ? undoRenote() : renote()"
> >
<i class="ph-repeat ph-bold ph-lg"></i> <i class="ph-rocket-launch ph-bold ph-lg"></i>
<p v-if="note.renoteCount > 0" :class="$style.noteFooterButtonCount">{{ note.renoteCount }}</p> <p v-if="note.renoteCount > 0" :class="$style.noteFooterButtonCount">{{ note.renoteCount }}</p>
</button> </button>
<button v-else class="_button" :class="$style.noteFooterButton" disabled> <button v-else class="_button" :class="$style.noteFooterButton" disabled>
@ -112,6 +113,7 @@ const muted = ref($i ? checkWordMute(props.note, $i, $i.mutedWords) : false);
const translation = ref(null); const translation = ref(null);
const translating = ref(false); const translating = ref(false);
const isDeleted = ref(false); const isDeleted = ref(false);
const renoted = ref(false);
const reactButton = shallowRef<HTMLElement>(); const reactButton = shallowRef<HTMLElement>();
const renoteButton = shallowRef<HTMLElement>(); const renoteButton = shallowRef<HTMLElement>();
const menuButton = shallowRef<HTMLElement>(); const menuButton = shallowRef<HTMLElement>();
@ -132,6 +134,16 @@ useNoteCapture({
isDeletedRef: isDeleted, isDeletedRef: isDeleted,
}); });
if ($i) {
os.api("notes/renotes", {
noteId: appearNote.id,
userId: $i.id,
limit: 1,
}).then((res) => {
renoted.value = res.length > 0;
});
}
function focus() { function focus() {
el.value.focus(); el.value.focus();
} }
@ -203,6 +215,14 @@ function undoReact(note): void {
}); });
} }
function undoRenote() : void {
if (!renoted) return;
os.api("notes/unrenote", {
noteId: appearNote.id,
});
renoted.value = false;
}
let showContent = $ref(false); let showContent = $ref(false);
let replies: Misskey.entities.Note[] = $ref([]); let replies: Misskey.entities.Note[] = $ref([]);
@ -215,7 +235,7 @@ function renote(viaKeyboard = false) {
if (props.note.channel) { if (props.note.channel) {
items = items.concat([{ items = items.concat([{
text: i18n.ts.inChannelRenote, text: i18n.ts.inChannelRenote,
icon: 'ph-repeat ph-bold ph-lg', icon: 'ph-rocket-launch ph-bold ph-lg',
action: () => { action: () => {
const el = renoteButton.value as HTMLElement | null | undefined; const el = renoteButton.value as HTMLElement | null | undefined;
if (el) { if (el) {
@ -230,6 +250,7 @@ function renote(viaKeyboard = false) {
channelId: props.note.channelId, channelId: props.note.channelId,
}).then(() => { }).then(() => {
os.toast(i18n.ts.renoted); os.toast(i18n.ts.renoted);
renoted.value = true;
}); });
}, },
}, { }, {
@ -246,7 +267,7 @@ function renote(viaKeyboard = false) {
items = items.concat([{ items = items.concat([{
text: i18n.ts.renote, text: i18n.ts.renote,
icon: 'ph-repeat ph-bold ph-lg', icon: 'ph-rocket-launch ph-bold ph-lg',
action: () => { action: () => {
const el = renoteButton.value as HTMLElement | null | undefined; const el = renoteButton.value as HTMLElement | null | undefined;
if (el) { if (el) {
@ -260,6 +281,7 @@ function renote(viaKeyboard = false) {
renoteId: props.note.id, renoteId: props.note.id,
}).then(() => { }).then(() => {
os.toast(i18n.ts.renoted); os.toast(i18n.ts.renoted);
renoted.value = true;
}); });
}, },
}, { }, {