client: refactor to pleaseLoginOrRemote

This commit is contained in:
Johann150 2023-03-04 00:08:12 +01:00
parent 5a263ec2c3
commit 49ae56a9e9
Signed by untrusted user: Johann150
GPG key ID: 9EE6577A2A06F8F1
5 changed files with 33 additions and 10 deletions

View file

@ -126,7 +126,7 @@ import XRenoteButton from './renote-button.vue';
import MkUrlPreview from '@/components/url-preview.vue';
import MkInstanceTicker from '@/components/instance-ticker.vue';
import MkVisibility from '@/components/visibility.vue';
import { pleaseLogin } from '@/scripts/please-login';
import { pleaseLoginOrRemote, urlForNote } from '@/scripts/please-login';
import { checkWordMute } from '@/scripts/check-word-mute';
import { userPage } from '@/filters/user';
import { notePage } from '@/filters/note';
@ -195,7 +195,8 @@ useNoteCapture({
});
function reply(viaKeyboard = false): void {
pleaseLogin();
pleaseLoginOrRemote(urlForNote(appearNote));
os.post({
reply: appearNote,
animation: !viaKeyboard,
@ -205,7 +206,8 @@ function reply(viaKeyboard = false): void {
}
function react(): void {
pleaseLogin();
pleaseLoginOrRemote(urlForNote(appearNote));
blur();
reactionPicker.show(reactButton.value, reaction => {
os.api('notes/reactions/create', {

View file

@ -115,7 +115,7 @@ import XRenoteButton from './renote-button.vue';
import MkUrlPreview from '@/components/url-preview.vue';
import MkInstanceTicker from '@/components/instance-ticker.vue';
import MkVisibility from '@/components/visibility.vue';
import { pleaseLogin } from '@/scripts/please-login';
import { pleaseLoginOrRemote, urlForNote } from '@/scripts/please-login';
import { focusPrev, focusNext } from '@/scripts/focus';
import { checkWordMute } from '@/scripts/check-word-mute';
import { userPage } from '@/filters/user';
@ -188,7 +188,8 @@ useNoteCapture({
});
function reply(viaKeyboard = false): void {
pleaseLogin();
pleaseLoginOrRemote(urlForNote(appearNote));
os.post({
reply: appearNote,
animation: !viaKeyboard,
@ -198,7 +199,8 @@ function reply(viaKeyboard = false): void {
}
function react(): void {
pleaseLogin();
pleaseLoginOrRemote(urlForNote(appearNote));
blur();
reactionPicker.show(reactButton.value, reaction => {
os.api('notes/reactions/create', {

View file

@ -25,7 +25,7 @@
import { computed, ref } from 'vue';
import * as foundkey from 'foundkey-js';
import { sum } from '@/scripts/array';
import { pleaseLogin } from '@/scripts/please-login';
import { pleaseLoginOrRemote, urlForNote } from '@/scripts/please-login';
import * as os from '@/os';
import { i18n } from '@/i18n';
import { useInterval } from '@/scripts/use-interval';
@ -68,7 +68,7 @@ if (props.note.poll.expiresAt) {
}
const vote = async (id) => {
pleaseLogin();
pleaseLoginOrRemote(urlForNote(props.note));
if (props.readOnly || closed.value || isVoted.value) return;

View file

@ -17,7 +17,7 @@
import { computed, ref } from 'vue';
import { Note } from 'foundkey-js/built/entities';
import XDetails from '@/components/users-tooltip.vue';
import { pleaseLogin } from '@/scripts/please-login';
import { pleaseLoginOrRemote, urlForNote } from '@/scripts/please-login';
import * as os from '@/os';
import { $i } from '@/account';
import { useTooltip } from '@/scripts/use-tooltip';
@ -51,7 +51,8 @@ useTooltip(buttonRef, async (showing) => {
});
function renote(viaKeyboard = false): void {
pleaseLogin();
pleaseLoginOrRemote(urlForNote(props.note));
os.popupMenu([{
text: i18n.ts.renote,
icon: 'fas fa-retweet',

View file

@ -2,6 +2,8 @@ import { defineAsyncComponent } from 'vue';
import { $i } from '@/account';
import { i18n } from '@/i18n';
import { popup } from '@/os';
import { url } from '@/config';
import { entities } from 'foundkey-js';
export function pleaseLoginOrPage(path?: string) {
if ($i) return;
@ -19,3 +21,19 @@ export function pleaseLoginOrPage(path?: string) {
if (!path) throw new Error('signin required');
}
export function pleaseLoginOrRemote(url: string) {
if ($i) return;
popup(defineAsyncComponent(() => import('@/components/remote-interact.vue')), {
remoteUrl,
}, {}, 'closed');
throw new Error('signin required');
}
export function urlForNote(note: entities.Note): string {
return note.url
?? note.uri
?? `${url}/notes/${note.id}`;
}