2020-01-30 04:37:25 +09:00
|
|
|
<template>
|
2023-04-08 09:01:42 +09:00
|
|
|
<div
|
|
|
|
v-size="{ max: [310, 500] }"
|
|
|
|
class="gafaadew"
|
|
|
|
:class="{ modal, _popup: modal }"
|
|
|
|
@dragover.stop="onDragover"
|
|
|
|
@dragenter="onDragenter"
|
|
|
|
@dragleave="onDragleave"
|
|
|
|
@drop.stop="onDrop"
|
|
|
|
>
|
|
|
|
<header>
|
|
|
|
<button v-if="!fixed" class="cancel _button" @click="cancel">
|
|
|
|
<i class="ph-x ph-bold ph-lg"></i>
|
2020-02-05 21:28:51 +09:00
|
|
|
</button>
|
2023-04-08 09:01:42 +09:00
|
|
|
<button
|
|
|
|
v-click-anime
|
|
|
|
v-tooltip="i18n.ts.switchAccount"
|
|
|
|
class="account _button"
|
|
|
|
@click="openAccountMenu"
|
|
|
|
>
|
|
|
|
<MkAvatar :user="postAccount ?? $i" class="avatar" />
|
|
|
|
</button>
|
|
|
|
<div class="right">
|
|
|
|
<span
|
|
|
|
class="text-count"
|
|
|
|
:class="{ over: textLength > maxTextLength }"
|
|
|
|
>{{ maxTextLength - textLength }}</span
|
|
|
|
>
|
|
|
|
<span v-if="localOnly" class="local-only"
|
|
|
|
><i class="ph-hand-fist ph-bold ph-lg"></i
|
|
|
|
></span>
|
|
|
|
<button
|
|
|
|
ref="visibilityButton"
|
|
|
|
v-tooltip="i18n.ts.visibility"
|
|
|
|
class="_button visibility"
|
|
|
|
:disabled="channel != null"
|
|
|
|
@click="setVisibility"
|
|
|
|
>
|
|
|
|
<span v-if="visibility === 'public'"
|
|
|
|
><i class="ph-planet ph-bold ph-lg"></i
|
|
|
|
></span>
|
|
|
|
<span v-if="visibility === 'home'"
|
|
|
|
><i class="ph-house ph-bold ph-lg"></i
|
|
|
|
></span>
|
|
|
|
<span v-if="visibility === 'followers'"
|
|
|
|
><i class="ph-lock-simple-open ph-bold ph-lg"></i
|
|
|
|
></span>
|
|
|
|
<span v-if="visibility === 'specified'"
|
|
|
|
><i class="ph-envelope-simple-open ph-bold ph-lg"></i
|
|
|
|
></span>
|
|
|
|
</button>
|
|
|
|
<button
|
|
|
|
v-tooltip="i18n.ts.previewNoteText"
|
|
|
|
class="_button preview"
|
|
|
|
:class="{ active: showPreview }"
|
|
|
|
@click="showPreview = !showPreview"
|
|
|
|
>
|
2023-04-29 14:08:11 +09:00
|
|
|
<i class="ph-binoculars ph-bold ph-lg"></i>
|
2023-04-08 09:01:42 +09:00
|
|
|
</button>
|
|
|
|
<button
|
|
|
|
class="submit _buttonGradate"
|
|
|
|
:disabled="!canPost"
|
|
|
|
data-cy-open-post-form-submit
|
|
|
|
@click="post"
|
|
|
|
>
|
|
|
|
{{ submitText
|
|
|
|
}}<i
|
|
|
|
:class="
|
|
|
|
reply
|
|
|
|
? 'ph-arrow-u-up-left ph-bold ph-lg'
|
|
|
|
: renote
|
|
|
|
? 'ph-quotes ph-bold ph-lg'
|
|
|
|
: 'ph-paper-plane-tilt ph-bold ph-lg'
|
|
|
|
"
|
|
|
|
></i>
|
|
|
|
</button>
|
|
|
|
</div>
|
|
|
|
</header>
|
|
|
|
<div class="form" :class="{ fixed }">
|
|
|
|
<XNoteSimple v-if="reply" class="preview" :note="reply" />
|
|
|
|
<XNoteSimple v-if="renote" class="preview" :note="renote" />
|
|
|
|
<div v-if="quoteId" class="with-quote">
|
|
|
|
<i class="ph-quotes ph-bold ph-lg"></i>
|
|
|
|
{{ i18n.ts.quoteAttached
|
2023-05-09 06:26:59 +09:00
|
|
|
}}<button class="_button" @click="quoteId = null">
|
2023-04-08 09:01:42 +09:00
|
|
|
<i class="ph-x ph-bold ph-lg"></i>
|
|
|
|
</button>
|
2020-01-30 04:37:25 +09:00
|
|
|
</div>
|
2023-04-08 09:01:42 +09:00
|
|
|
<div v-if="visibility === 'specified'" class="to-specified">
|
|
|
|
<span style="margin-right: 8px">{{ i18n.ts.recipient }}</span>
|
|
|
|
<div class="visibleUsers">
|
|
|
|
<span v-for="u in visibleUsers" :key="u.id">
|
|
|
|
<MkAcct :user="u" />
|
|
|
|
<button class="_button" @click="removeVisibleUser(u)">
|
|
|
|
<i class="ph-x ph-bold ph-lg"></i>
|
|
|
|
</button>
|
|
|
|
</span>
|
|
|
|
<button class="_button" @click="addVisibleUser">
|
|
|
|
<i class="ph-plus ph-bold ph-md ph-fw ph-lg"></i>
|
|
|
|
</button>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<MkInfo
|
|
|
|
v-if="hasNotSpecifiedMentions"
|
|
|
|
warn
|
|
|
|
class="hasNotSpecifiedMentions"
|
|
|
|
>{{ i18n.ts.notSpecifiedMentionWarning }} -
|
|
|
|
<button class="_textButton" @click="addMissingMention()">
|
|
|
|
{{ i18n.ts.add }}
|
|
|
|
</button></MkInfo
|
|
|
|
>
|
|
|
|
<input
|
|
|
|
v-show="useCw"
|
|
|
|
ref="cwInputEl"
|
|
|
|
v-model="cw"
|
|
|
|
class="cw"
|
|
|
|
:placeholder="i18n.ts.annotation"
|
|
|
|
@keydown="onKeydown"
|
|
|
|
/>
|
|
|
|
<textarea
|
|
|
|
ref="textareaEl"
|
|
|
|
v-model="text"
|
|
|
|
class="text"
|
|
|
|
:class="{ withCw: useCw }"
|
|
|
|
:disabled="posting"
|
|
|
|
:placeholder="placeholder"
|
|
|
|
data-cy-post-form-text
|
|
|
|
@keydown="onKeydown"
|
|
|
|
@paste="onPaste"
|
|
|
|
@compositionupdate="onCompositionUpdate"
|
|
|
|
@compositionend="onCompositionEnd"
|
|
|
|
/>
|
|
|
|
<input
|
|
|
|
v-show="withHashtags"
|
|
|
|
ref="hashtagsInputEl"
|
|
|
|
v-model="hashtags"
|
|
|
|
class="hashtags"
|
|
|
|
:placeholder="i18n.ts.hashtags"
|
|
|
|
list="hashtags"
|
|
|
|
/>
|
|
|
|
<XPostFormAttaches
|
|
|
|
class="attaches"
|
|
|
|
:files="files"
|
|
|
|
@updated="updateFiles"
|
|
|
|
@detach="detachFile"
|
|
|
|
@changeSensitive="updateFileSensitive"
|
|
|
|
@changeName="updateFileName"
|
|
|
|
/>
|
|
|
|
<XPollEditor v-if="poll" v-model="poll" @destroyed="poll = null" />
|
|
|
|
<XNotePreview v-if="showPreview" class="preview" :text="text" />
|
|
|
|
<footer>
|
|
|
|
<button
|
|
|
|
v-tooltip="i18n.ts.attachFile"
|
|
|
|
class="_button"
|
|
|
|
@click="chooseFileFrom"
|
|
|
|
>
|
|
|
|
<i class="ph-upload ph-bold ph-lg"></i>
|
|
|
|
</button>
|
|
|
|
<button
|
|
|
|
v-tooltip="i18n.ts.poll"
|
|
|
|
class="_button"
|
|
|
|
:class="{ active: poll }"
|
|
|
|
@click="togglePoll"
|
|
|
|
>
|
|
|
|
<i class="ph-microphone-stage ph-bold ph-lg"></i>
|
|
|
|
</button>
|
|
|
|
<button
|
|
|
|
v-tooltip="i18n.ts.useCw"
|
|
|
|
class="_button"
|
|
|
|
:class="{ active: useCw }"
|
|
|
|
@click="useCw = !useCw"
|
|
|
|
>
|
|
|
|
<i class="ph-eye-slash ph-bold ph-lg"></i>
|
|
|
|
</button>
|
|
|
|
<button
|
|
|
|
v-tooltip="i18n.ts.mention"
|
|
|
|
class="_button"
|
|
|
|
@click="insertMention"
|
|
|
|
>
|
|
|
|
<i class="ph-at ph-bold ph-lg"></i>
|
|
|
|
</button>
|
|
|
|
<button
|
|
|
|
v-tooltip="i18n.ts.hashtags"
|
|
|
|
class="_button"
|
|
|
|
:class="{ active: withHashtags }"
|
|
|
|
@click="withHashtags = !withHashtags"
|
|
|
|
>
|
|
|
|
<i class="ph-hash ph-bold ph-lg"></i>
|
|
|
|
</button>
|
|
|
|
<button
|
|
|
|
v-tooltip="i18n.ts.emoji"
|
|
|
|
class="_button"
|
|
|
|
@click="insertEmoji"
|
|
|
|
>
|
|
|
|
<i class="ph-smiley ph-bold ph-lg"></i>
|
|
|
|
</button>
|
|
|
|
<button
|
|
|
|
v-if="postFormActions.length > 0"
|
|
|
|
v-tooltip="i18n.ts.plugin"
|
|
|
|
class="_button"
|
|
|
|
@click="showActions"
|
|
|
|
>
|
|
|
|
<i class="ph-plug ph-bold ph-lg"></i>
|
|
|
|
</button>
|
|
|
|
<button
|
|
|
|
v-tooltip="i18n.ts._mfm.cheatSheet"
|
|
|
|
class="_button right"
|
|
|
|
@click="openCheatSheet"
|
|
|
|
>
|
|
|
|
<i class="ph-question ph-bold ph-lg"></i>
|
|
|
|
</button>
|
|
|
|
</footer>
|
|
|
|
<datalist id="hashtags">
|
|
|
|
<option
|
|
|
|
v-for="hashtag in recentHashtags"
|
|
|
|
:key="hashtag"
|
|
|
|
:value="hashtag"
|
|
|
|
/>
|
|
|
|
</datalist>
|
2020-01-30 04:37:25 +09:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
2022-01-16 01:46:25 +09:00
|
|
|
<script lang="ts" setup>
|
2023-04-08 09:01:42 +09:00
|
|
|
import { inject, watch, nextTick, onMounted, defineAsyncComponent } from "vue";
|
|
|
|
import * as mfm from "mfm-js";
|
|
|
|
import * as misskey from "calckey-js";
|
|
|
|
import insertTextAtCursor from "insert-text-at-cursor";
|
|
|
|
import { length } from "stringz";
|
|
|
|
import { toASCII } from "punycode/";
|
|
|
|
import * as Acct from "calckey-js/built/acct";
|
|
|
|
import { throttle } from "throttle-debounce";
|
|
|
|
import XNoteSimple from "@/components/MkNoteSimple.vue";
|
|
|
|
import XNotePreview from "@/components/MkNotePreview.vue";
|
|
|
|
import XPostFormAttaches from "@/components/MkPostFormAttaches.vue";
|
|
|
|
import XPollEditor from "@/components/MkPollEditor.vue";
|
|
|
|
import { host, url } from "@/config";
|
|
|
|
import { erase, unique } from "@/scripts/array";
|
|
|
|
import { extractMentions } from "@/scripts/extract-mentions";
|
|
|
|
import { formatTimeString } from "@/scripts/format-time-string";
|
|
|
|
import { Autocomplete } from "@/scripts/autocomplete";
|
|
|
|
import * as os from "@/os";
|
|
|
|
import { stream } from "@/stream";
|
|
|
|
import { selectFiles } from "@/scripts/select-file";
|
|
|
|
import { defaultStore, notePostInterruptors, postFormActions } from "@/store";
|
|
|
|
import MkInfo from "@/components/MkInfo.vue";
|
|
|
|
import { i18n } from "@/i18n";
|
|
|
|
import { instance } from "@/instance";
|
|
|
|
import {
|
|
|
|
$i,
|
|
|
|
getAccounts,
|
|
|
|
openAccountMenu as openAccountMenu_,
|
|
|
|
} from "@/account";
|
|
|
|
import { uploadFile } from "@/scripts/upload";
|
|
|
|
import { deepClone } from "@/scripts/clone";
|
|
|
|
import XCheatSheet from "@/components/MkCheatSheetDialog.vue";
|
|
|
|
import { preprocess } from "@/scripts/preprocess";
|
|
|
|
|
|
|
|
const modal = inject("modal");
|
|
|
|
|
|
|
|
const props = withDefaults(
|
|
|
|
defineProps<{
|
|
|
|
reply?: misskey.entities.Note;
|
|
|
|
renote?: misskey.entities.Note;
|
|
|
|
channel?: any; // TODO
|
|
|
|
mention?: misskey.entities.User;
|
|
|
|
specified?: misskey.entities.User;
|
|
|
|
initialText?: string;
|
|
|
|
initialVisibility?: typeof misskey.noteVisibilities;
|
|
|
|
initialFiles?: misskey.entities.DriveFile[];
|
|
|
|
initialLocalOnly?: boolean;
|
|
|
|
initialVisibleUsers?: misskey.entities.User[];
|
|
|
|
initialNote?: misskey.entities.Note;
|
|
|
|
instant?: boolean;
|
|
|
|
fixed?: boolean;
|
|
|
|
autofocus?: boolean;
|
|
|
|
}>(),
|
|
|
|
{
|
|
|
|
initialVisibleUsers: () => [],
|
|
|
|
autofocus: true,
|
|
|
|
}
|
|
|
|
);
|
2020-01-30 04:37:25 +09:00
|
|
|
|
2022-01-16 01:46:25 +09:00
|
|
|
const emit = defineEmits<{
|
2023-04-08 09:01:42 +09:00
|
|
|
(ev: "posted"): void;
|
|
|
|
(ev: "cancel"): void;
|
|
|
|
(ev: "esc"): void;
|
2022-01-16 01:46:25 +09:00
|
|
|
}>();
|
|
|
|
|
|
|
|
const textareaEl = $ref<HTMLTextAreaElement | null>(null);
|
|
|
|
const cwInputEl = $ref<HTMLInputElement | null>(null);
|
|
|
|
const hashtagsInputEl = $ref<HTMLInputElement | null>(null);
|
|
|
|
const visibilityButton = $ref<HTMLElement | null>(null);
|
|
|
|
|
|
|
|
let posting = $ref(false);
|
2023-04-08 09:01:42 +09:00
|
|
|
let text = $ref(props.initialText ?? "");
|
2022-01-16 01:46:25 +09:00
|
|
|
let files = $ref(props.initialFiles ?? []);
|
|
|
|
let poll = $ref<{
|
|
|
|
choices: string[];
|
|
|
|
multiple: boolean;
|
2022-01-26 03:26:12 +09:00
|
|
|
expiresAt: string | null;
|
|
|
|
expiredAfter: string | null;
|
2022-01-16 01:46:25 +09:00
|
|
|
} | null>(null);
|
|
|
|
let useCw = $ref(false);
|
|
|
|
let showPreview = $ref(false);
|
|
|
|
let cw = $ref<string | null>(null);
|
2023-04-08 09:01:42 +09:00
|
|
|
let localOnly = $ref<boolean>(
|
|
|
|
props.initialLocalOnly ?? defaultStore.state.rememberNoteVisibility
|
|
|
|
? defaultStore.state.localOnly
|
|
|
|
: defaultStore.state.defaultNoteLocalOnly
|
|
|
|
);
|
|
|
|
let visibility = $ref(
|
|
|
|
props.initialVisibility ??
|
|
|
|
((defaultStore.state.rememberNoteVisibility
|
|
|
|
? defaultStore.state.visibility
|
|
|
|
: defaultStore.state
|
|
|
|
.defaultNoteVisibility) as (typeof misskey.noteVisibilities)[number])
|
|
|
|
);
|
2022-02-01 21:49:34 +09:00
|
|
|
let visibleUsers = $ref([]);
|
|
|
|
if (props.initialVisibleUsers) {
|
|
|
|
props.initialVisibleUsers.forEach(pushVisibleUser);
|
|
|
|
}
|
2022-01-16 01:46:25 +09:00
|
|
|
let autocomplete = $ref(null);
|
|
|
|
let draghover = $ref(false);
|
|
|
|
let quoteId = $ref(null);
|
|
|
|
let hasNotSpecifiedMentions = $ref(false);
|
2023-04-08 09:01:42 +09:00
|
|
|
let recentHashtags = $ref(JSON.parse(localStorage.getItem("hashtags") || "[]"));
|
|
|
|
let imeText = $ref("");
|
2022-01-16 01:46:25 +09:00
|
|
|
|
|
|
|
const typing = throttle(3000, () => {
|
|
|
|
if (props.channel) {
|
2023-04-08 09:01:42 +09:00
|
|
|
stream.send("typingOnChannel", { channel: props.channel.id });
|
2022-01-16 01:46:25 +09:00
|
|
|
}
|
|
|
|
});
|
2019-05-27 15:38:14 +09:00
|
|
|
|
2022-01-16 01:46:25 +09:00
|
|
|
const draftKey = $computed((): string => {
|
2023-04-08 09:01:42 +09:00
|
|
|
let key = props.channel ? `channel:${props.channel.id}` : "";
|
2019-05-27 15:38:14 +09:00
|
|
|
|
2022-01-16 01:46:25 +09:00
|
|
|
if (props.renote) {
|
|
|
|
key += `renote:${props.renote.id}`;
|
|
|
|
} else if (props.reply) {
|
|
|
|
key += `reply:${props.reply.id}`;
|
|
|
|
} else {
|
2023-04-08 09:01:42 +09:00
|
|
|
key += "note";
|
2022-01-16 01:46:25 +09:00
|
|
|
}
|
2021-01-15 23:20:47 +09:00
|
|
|
|
2022-01-16 01:46:25 +09:00
|
|
|
return key;
|
|
|
|
});
|
2020-02-10 23:17:42 +09:00
|
|
|
|
2022-01-16 01:46:25 +09:00
|
|
|
const placeholder = $computed((): string => {
|
|
|
|
if (props.renote) {
|
2022-01-28 11:39:49 +09:00
|
|
|
return i18n.ts._postForm.quotePlaceholder;
|
2022-01-16 01:46:25 +09:00
|
|
|
} else if (props.reply) {
|
2022-01-28 11:39:49 +09:00
|
|
|
return i18n.ts._postForm.replyPlaceholder;
|
2022-01-16 01:46:25 +09:00
|
|
|
} else if (props.channel) {
|
2022-01-28 11:39:49 +09:00
|
|
|
return i18n.ts._postForm.channelPlaceholder;
|
2022-01-16 01:46:25 +09:00
|
|
|
} else {
|
|
|
|
const xs = [
|
2022-01-28 11:39:49 +09:00
|
|
|
i18n.ts._postForm._placeholders.a,
|
|
|
|
i18n.ts._postForm._placeholders.b,
|
|
|
|
i18n.ts._postForm._placeholders.c,
|
|
|
|
i18n.ts._postForm._placeholders.d,
|
|
|
|
i18n.ts._postForm._placeholders.e,
|
2022-07-05 23:01:23 +09:00
|
|
|
i18n.ts._postForm._placeholders.f,
|
2022-01-16 01:46:25 +09:00
|
|
|
];
|
|
|
|
return xs[Math.floor(Math.random() * xs.length)];
|
|
|
|
}
|
|
|
|
});
|
2021-08-07 12:47:01 +09:00
|
|
|
|
2022-01-16 01:46:25 +09:00
|
|
|
const submitText = $computed((): string => {
|
|
|
|
return props.renote
|
2022-01-28 11:39:49 +09:00
|
|
|
? i18n.ts.quote
|
2022-01-16 01:46:25 +09:00
|
|
|
: props.reply
|
2023-04-08 09:01:42 +09:00
|
|
|
? i18n.ts.reply
|
|
|
|
: i18n.ts.note;
|
2022-01-16 01:46:25 +09:00
|
|
|
});
|
2019-05-27 15:38:14 +09:00
|
|
|
|
2022-01-16 01:46:25 +09:00
|
|
|
const textLength = $computed((): number => {
|
2023-03-30 12:11:57 +09:00
|
|
|
return length((preprocess(text) + imeText).trim());
|
2022-01-16 01:46:25 +09:00
|
|
|
});
|
2021-04-16 00:13:20 +09:00
|
|
|
|
2022-01-16 01:46:25 +09:00
|
|
|
const maxTextLength = $computed((): number => {
|
|
|
|
return instance ? instance.maxNoteTextLength : 1000;
|
|
|
|
});
|
2019-05-27 15:38:14 +09:00
|
|
|
|
2022-01-16 01:46:25 +09:00
|
|
|
const canPost = $computed((): boolean => {
|
2023-04-08 09:01:42 +09:00
|
|
|
return (
|
|
|
|
!posting &&
|
2022-01-16 01:46:25 +09:00
|
|
|
(1 <= textLength || 1 <= files.length || !!poll || !!props.renote) &&
|
2023-04-08 09:01:42 +09:00
|
|
|
textLength <= maxTextLength &&
|
|
|
|
(!poll || poll.choices.length >= 2)
|
|
|
|
);
|
2022-01-16 01:46:25 +09:00
|
|
|
});
|
2021-10-20 03:10:36 +09:00
|
|
|
|
2023-04-08 09:01:42 +09:00
|
|
|
const withHashtags = $computed(
|
|
|
|
defaultStore.makeGetterSetter("postFormWithHashtags")
|
|
|
|
);
|
|
|
|
const hashtags = $computed(defaultStore.makeGetterSetter("postFormHashtags"));
|
2021-10-20 03:10:36 +09:00
|
|
|
|
2022-01-16 01:46:25 +09:00
|
|
|
watch($$(text), () => {
|
|
|
|
checkMissingMention();
|
|
|
|
});
|
2021-10-20 03:10:36 +09:00
|
|
|
|
2023-04-08 09:01:42 +09:00
|
|
|
watch(
|
|
|
|
$$(visibleUsers),
|
|
|
|
() => {
|
|
|
|
checkMissingMention();
|
|
|
|
},
|
|
|
|
{
|
|
|
|
deep: true,
|
|
|
|
}
|
|
|
|
);
|
2021-11-18 23:32:43 +09:00
|
|
|
|
2022-01-16 01:46:25 +09:00
|
|
|
if (props.mention) {
|
2023-04-08 09:01:42 +09:00
|
|
|
text = props.mention.host
|
|
|
|
? `@${props.mention.username}@${toASCII(props.mention.host)}`
|
|
|
|
: `@${props.mention.username}`;
|
|
|
|
text += " ";
|
2022-01-16 01:46:25 +09:00
|
|
|
}
|
2019-05-27 15:38:14 +09:00
|
|
|
|
2023-04-08 09:01:42 +09:00
|
|
|
if (
|
|
|
|
props.reply &&
|
|
|
|
(props.reply.user.username !== $i.username ||
|
|
|
|
(props.reply.user.host != null && props.reply.user.host !== host))
|
|
|
|
) {
|
|
|
|
text = `@${props.reply.user.username}${
|
|
|
|
props.reply.user.host != null
|
|
|
|
? "@" + toASCII(props.reply.user.host)
|
|
|
|
: ""
|
|
|
|
} `;
|
2022-01-16 01:46:25 +09:00
|
|
|
}
|
2019-05-27 15:38:14 +09:00
|
|
|
|
2022-01-16 01:46:25 +09:00
|
|
|
if (props.reply && props.reply.text != null) {
|
|
|
|
const ast = mfm.parse(props.reply.text);
|
|
|
|
const otherHost = props.reply.user.host;
|
2019-05-27 15:38:14 +09:00
|
|
|
|
2022-01-16 01:46:25 +09:00
|
|
|
for (const x of extractMentions(ast)) {
|
2023-04-08 09:01:42 +09:00
|
|
|
const mention = x.host
|
|
|
|
? `@${x.username}@${toASCII(x.host)}`
|
|
|
|
: otherHost == null || otherHost === host
|
|
|
|
? `@${x.username}`
|
|
|
|
: `@${x.username}@${toASCII(otherHost)}`;
|
2019-05-27 15:38:14 +09:00
|
|
|
|
2022-01-16 01:46:25 +09:00
|
|
|
// 自分は除外
|
2023-04-08 09:01:42 +09:00
|
|
|
if ($i.username === x.username && (x.host == null || x.host === host))
|
|
|
|
continue;
|
2019-05-27 15:38:14 +09:00
|
|
|
|
2022-01-16 01:46:25 +09:00
|
|
|
// 重複は除外
|
2022-05-07 17:01:01 +09:00
|
|
|
if (text.includes(`${mention} `)) continue;
|
2019-05-27 15:38:14 +09:00
|
|
|
|
2022-01-16 01:46:25 +09:00
|
|
|
text += `${mention} `;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (props.channel) {
|
2023-04-08 09:01:42 +09:00
|
|
|
visibility = "public";
|
2022-01-16 01:46:25 +09:00
|
|
|
localOnly = true; // TODO: チャンネルが連合するようになった折には消す
|
|
|
|
}
|
|
|
|
|
|
|
|
// 公開以外へのリプライ時は元の公開範囲を引き継ぐ
|
2023-04-08 09:01:42 +09:00
|
|
|
if (
|
|
|
|
props.reply &&
|
|
|
|
["home", "followers", "specified"].includes(props.reply.visibility)
|
|
|
|
) {
|
2023-05-02 12:32:18 +09:00
|
|
|
if (props.reply.visibility === "home" && visibility === "followers") {
|
|
|
|
visibility = "followers";
|
|
|
|
} else if (
|
|
|
|
["home", "followers"].includes(props.reply.visibility) &&
|
|
|
|
visibility === "specified"
|
|
|
|
) {
|
|
|
|
visibility = "specified";
|
2023-05-02 00:42:27 +09:00
|
|
|
} else {
|
|
|
|
visibility = props.reply.visibility;
|
|
|
|
}
|
2023-05-02 12:32:18 +09:00
|
|
|
if (visibility === "specified") {
|
2023-05-02 00:42:27 +09:00
|
|
|
if (props.reply.visibleUserIds) {
|
2023-05-02 12:32:18 +09:00
|
|
|
os.api("users/show", {
|
|
|
|
userIds: props.reply.visibleUserIds.filter(
|
|
|
|
(uid) => uid !== $i.id && uid !== props.reply.userId
|
|
|
|
),
|
|
|
|
}).then((users) => {
|
2023-05-02 00:42:27 +09:00
|
|
|
users.forEach(pushVisibleUser);
|
|
|
|
});
|
|
|
|
}
|
2019-05-27 15:38:14 +09:00
|
|
|
|
2022-01-16 01:46:25 +09:00
|
|
|
if (props.reply.userId !== $i.id) {
|
2023-04-08 09:01:42 +09:00
|
|
|
os.api("users/show", { userId: props.reply.userId }).then(
|
|
|
|
(user) => {
|
|
|
|
pushVisibleUser(user);
|
|
|
|
}
|
|
|
|
);
|
2020-08-18 22:44:21 +09:00
|
|
|
}
|
2022-01-16 01:46:25 +09:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (props.specified) {
|
2023-04-08 09:01:42 +09:00
|
|
|
visibility = "specified";
|
2022-02-01 21:49:34 +09:00
|
|
|
pushVisibleUser(props.specified);
|
2022-01-16 01:46:25 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
// keep cw when reply
|
|
|
|
if (defaultStore.state.keepCw && props.reply && props.reply.cw) {
|
|
|
|
useCw = true;
|
|
|
|
cw = props.reply.cw;
|
|
|
|
}
|
|
|
|
|
|
|
|
function watchForDraft() {
|
|
|
|
watch($$(text), () => saveDraft());
|
|
|
|
watch($$(useCw), () => saveDraft());
|
|
|
|
watch($$(cw), () => saveDraft());
|
|
|
|
watch($$(poll), () => saveDraft());
|
|
|
|
watch($$(files), () => saveDraft(), { deep: true });
|
|
|
|
watch($$(visibility), () => saveDraft());
|
|
|
|
watch($$(localOnly), () => saveDraft());
|
|
|
|
}
|
|
|
|
|
|
|
|
function checkMissingMention() {
|
2023-04-08 09:01:42 +09:00
|
|
|
if (visibility === "specified") {
|
2022-01-16 01:46:25 +09:00
|
|
|
const ast = mfm.parse(text);
|
|
|
|
|
|
|
|
for (const x of extractMentions(ast)) {
|
2023-04-08 09:01:42 +09:00
|
|
|
if (
|
|
|
|
!visibleUsers.some(
|
|
|
|
(u) => u.username === x.username && u.host === x.host
|
|
|
|
)
|
|
|
|
) {
|
2022-01-16 01:46:25 +09:00
|
|
|
hasNotSpecifiedMentions = true;
|
|
|
|
return;
|
2019-08-25 16:12:01 +09:00
|
|
|
}
|
2019-05-27 15:38:14 +09:00
|
|
|
}
|
2022-01-16 01:46:25 +09:00
|
|
|
hasNotSpecifiedMentions = false;
|
|
|
|
}
|
|
|
|
}
|
2019-05-27 15:38:14 +09:00
|
|
|
|
2022-01-16 01:46:25 +09:00
|
|
|
function addMissingMention() {
|
|
|
|
const ast = mfm.parse(text);
|
2020-10-17 20:12:00 +09:00
|
|
|
|
2022-01-16 01:46:25 +09:00
|
|
|
for (const x of extractMentions(ast)) {
|
2023-04-08 09:01:42 +09:00
|
|
|
if (
|
|
|
|
!visibleUsers.some(
|
|
|
|
(u) => u.username === x.username && u.host === x.host
|
|
|
|
)
|
|
|
|
) {
|
|
|
|
os.api("users/show", { username: x.username, host: x.host }).then(
|
|
|
|
(user) => {
|
|
|
|
visibleUsers.push(user);
|
|
|
|
}
|
|
|
|
);
|
2020-10-17 20:12:00 +09:00
|
|
|
}
|
2022-01-16 01:46:25 +09:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function togglePoll() {
|
|
|
|
if (poll) {
|
|
|
|
poll = null;
|
|
|
|
} else {
|
|
|
|
poll = {
|
2023-04-08 09:01:42 +09:00
|
|
|
choices: ["", ""],
|
2022-01-16 01:46:25 +09:00
|
|
|
multiple: false,
|
|
|
|
expiresAt: null,
|
|
|
|
expiredAfter: null,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
2020-10-17 20:12:00 +09:00
|
|
|
|
2022-01-16 01:46:25 +09:00
|
|
|
function addTag(tag: string) {
|
|
|
|
insertTextAtCursor(textareaEl, ` #${tag} `);
|
|
|
|
}
|
2019-05-27 15:38:14 +09:00
|
|
|
|
2022-01-16 01:46:25 +09:00
|
|
|
function focus() {
|
2022-02-09 21:27:42 +09:00
|
|
|
if (textareaEl) {
|
|
|
|
textareaEl.focus();
|
2023-04-08 09:01:42 +09:00
|
|
|
textareaEl.setSelectionRange(
|
|
|
|
textareaEl.value.length,
|
|
|
|
textareaEl.value.length
|
|
|
|
);
|
2022-02-09 21:27:42 +09:00
|
|
|
}
|
2022-01-16 01:46:25 +09:00
|
|
|
}
|
2021-04-16 00:13:20 +09:00
|
|
|
|
2022-01-16 01:46:25 +09:00
|
|
|
function chooseFileFrom(ev) {
|
2023-04-08 09:01:42 +09:00
|
|
|
selectFiles(ev.currentTarget ?? ev.target, i18n.ts.attachFile).then(
|
|
|
|
(files_) => {
|
|
|
|
for (const file of files_) {
|
|
|
|
files.push(file);
|
|
|
|
}
|
2022-01-16 01:46:25 +09:00
|
|
|
}
|
2023-04-08 09:01:42 +09:00
|
|
|
);
|
2022-01-16 01:46:25 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
function detachFile(id) {
|
2023-04-08 09:01:42 +09:00
|
|
|
files = files.filter((x) => x.id !== id);
|
2022-01-16 01:46:25 +09:00
|
|
|
}
|
|
|
|
|
2022-01-20 23:15:08 +09:00
|
|
|
function updateFiles(_files) {
|
|
|
|
files = _files;
|
2022-01-16 01:46:25 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
function updateFileSensitive(file, sensitive) {
|
2023-04-08 09:01:42 +09:00
|
|
|
files[files.findIndex((x) => x.id === file.id)].isSensitive = sensitive;
|
2022-01-16 01:46:25 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
function updateFileName(file, name) {
|
2023-04-08 09:01:42 +09:00
|
|
|
files[files.findIndex((x) => x.id === file.id)].name = name;
|
2022-01-16 01:46:25 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
function upload(file: File, name?: string) {
|
2023-04-08 09:01:42 +09:00
|
|
|
uploadFile(file, defaultStore.state.uploadFolder, name).then((res) => {
|
2022-01-16 01:46:25 +09:00
|
|
|
files.push(res);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function setVisibility() {
|
|
|
|
if (props.channel) {
|
|
|
|
// TODO: information dialog
|
|
|
|
return;
|
|
|
|
}
|
2021-04-16 00:13:20 +09:00
|
|
|
|
2023-04-08 09:01:42 +09:00
|
|
|
os.popup(
|
|
|
|
defineAsyncComponent(
|
|
|
|
() => import("@/components/MkVisibilityPicker.vue")
|
|
|
|
),
|
|
|
|
{
|
|
|
|
currentVisibility: visibility,
|
|
|
|
currentLocalOnly: localOnly,
|
|
|
|
src: visibilityButton,
|
2021-04-16 00:13:20 +09:00
|
|
|
},
|
2023-04-08 09:01:42 +09:00
|
|
|
{
|
|
|
|
changeVisibility: (v) => {
|
|
|
|
visibility = v;
|
|
|
|
if (defaultStore.state.rememberNoteVisibility) {
|
|
|
|
defaultStore.set("visibility", visibility);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
changeLocalOnly: (v) => {
|
|
|
|
localOnly = v;
|
|
|
|
if (defaultStore.state.rememberNoteVisibility) {
|
|
|
|
defaultStore.set("localOnly", localOnly);
|
|
|
|
}
|
|
|
|
},
|
2022-07-05 23:01:23 +09:00
|
|
|
},
|
2023-04-08 09:01:42 +09:00
|
|
|
"closed"
|
|
|
|
);
|
2022-01-16 01:46:25 +09:00
|
|
|
}
|
|
|
|
|
2022-02-01 21:49:34 +09:00
|
|
|
function pushVisibleUser(user) {
|
2023-04-08 09:01:42 +09:00
|
|
|
if (
|
|
|
|
!visibleUsers.some(
|
|
|
|
(u) => u.username === user.username && u.host === user.host
|
|
|
|
)
|
|
|
|
) {
|
2022-02-01 21:49:34 +09:00
|
|
|
visibleUsers.push(user);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-01-16 01:46:25 +09:00
|
|
|
function addVisibleUser() {
|
2023-04-08 09:01:42 +09:00
|
|
|
os.selectUser().then((user) => {
|
2022-02-01 21:49:34 +09:00
|
|
|
pushVisibleUser(user);
|
2022-01-16 01:46:25 +09:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function removeVisibleUser(user) {
|
|
|
|
visibleUsers = erase(user, visibleUsers);
|
|
|
|
}
|
|
|
|
|
|
|
|
function clear() {
|
2023-04-08 09:01:42 +09:00
|
|
|
text = "";
|
2022-01-16 01:46:25 +09:00
|
|
|
files = [];
|
|
|
|
poll = null;
|
|
|
|
quoteId = null;
|
|
|
|
}
|
|
|
|
|
2022-05-07 17:01:01 +09:00
|
|
|
function onKeydown(ev: KeyboardEvent) {
|
2023-04-08 09:01:42 +09:00
|
|
|
if (
|
|
|
|
(ev.which === 10 || ev.which === 13) &&
|
|
|
|
(ev.ctrlKey || ev.metaKey) &&
|
|
|
|
canPost
|
|
|
|
)
|
|
|
|
post();
|
|
|
|
if (ev.which === 27) emit("esc");
|
2022-01-16 01:46:25 +09:00
|
|
|
typing();
|
|
|
|
}
|
|
|
|
|
2022-05-07 17:01:01 +09:00
|
|
|
function onCompositionUpdate(ev: CompositionEvent) {
|
|
|
|
imeText = ev.data;
|
2022-01-16 01:46:25 +09:00
|
|
|
typing();
|
|
|
|
}
|
|
|
|
|
2022-05-07 17:01:01 +09:00
|
|
|
function onCompositionEnd(ev: CompositionEvent) {
|
2023-04-08 09:01:42 +09:00
|
|
|
imeText = "";
|
2022-01-16 01:46:25 +09:00
|
|
|
}
|
|
|
|
|
2022-05-07 17:01:01 +09:00
|
|
|
async function onPaste(ev: ClipboardEvent) {
|
2023-04-08 09:01:42 +09:00
|
|
|
for (const { item, i } of Array.from(ev.clipboardData.items).map(
|
|
|
|
(item, i) => ({ item, i })
|
|
|
|
)) {
|
|
|
|
if (item.kind === "file") {
|
2022-01-16 01:46:25 +09:00
|
|
|
const file = item.getAsFile();
|
2023-04-08 09:01:42 +09:00
|
|
|
const lio = file.name.lastIndexOf(".");
|
|
|
|
const ext = lio >= 0 ? file.name.slice(lio) : "";
|
|
|
|
const formatted = `${formatTimeString(
|
|
|
|
new Date(file.lastModified),
|
|
|
|
defaultStore.state.pastedFileName
|
|
|
|
).replace(/{{number}}/g, `${i + 1}`)}${ext}`;
|
2022-01-16 01:46:25 +09:00
|
|
|
upload(file, formatted);
|
|
|
|
}
|
|
|
|
}
|
2020-12-05 12:50:09 +09:00
|
|
|
|
2023-04-08 09:01:42 +09:00
|
|
|
const paste = ev.clipboardData.getData("text");
|
2019-05-27 15:38:14 +09:00
|
|
|
|
2023-04-08 09:01:42 +09:00
|
|
|
if (!props.renote && !quoteId && paste.startsWith(url + "/notes/")) {
|
2022-05-07 17:01:01 +09:00
|
|
|
ev.preventDefault();
|
2019-05-27 15:38:14 +09:00
|
|
|
|
2022-11-16 15:38:05 +09:00
|
|
|
os.yesno({
|
2023-04-08 09:01:42 +09:00
|
|
|
type: "info",
|
2022-01-28 11:39:49 +09:00
|
|
|
text: i18n.ts.quoteQuestion,
|
2022-01-16 01:46:25 +09:00
|
|
|
}).then(({ canceled }) => {
|
|
|
|
if (canceled) {
|
|
|
|
insertTextAtCursor(textareaEl, paste);
|
2020-08-18 22:44:21 +09:00
|
|
|
return;
|
|
|
|
}
|
2020-10-17 20:12:00 +09:00
|
|
|
|
2022-01-16 01:46:25 +09:00
|
|
|
quoteId = paste.substr(url.length).match(/^\/notes\/(.+?)\/?$/)[1];
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-05-07 17:01:01 +09:00
|
|
|
function onDragover(ev) {
|
|
|
|
if (!ev.dataTransfer.items[0]) return;
|
2023-04-08 09:01:42 +09:00
|
|
|
const isFile = ev.dataTransfer.items[0].kind === "file";
|
2022-05-07 17:01:01 +09:00
|
|
|
const isDriveFile = ev.dataTransfer.types[0] === _DATA_TRANSFER_DRIVE_FILE_;
|
2022-01-16 01:46:25 +09:00
|
|
|
if (isFile || isDriveFile) {
|
2022-05-07 17:01:01 +09:00
|
|
|
ev.preventDefault();
|
2022-01-16 01:46:25 +09:00
|
|
|
draghover = true;
|
2022-07-25 21:16:11 +09:00
|
|
|
switch (ev.dataTransfer.effectAllowed) {
|
2023-04-08 09:01:42 +09:00
|
|
|
case "all":
|
|
|
|
case "uninitialized":
|
|
|
|
case "copy":
|
|
|
|
case "copyLink":
|
|
|
|
case "copyMove":
|
|
|
|
ev.dataTransfer.dropEffect = "copy";
|
2022-07-25 21:16:11 +09:00
|
|
|
break;
|
2023-04-08 09:01:42 +09:00
|
|
|
case "linkMove":
|
|
|
|
case "move":
|
|
|
|
ev.dataTransfer.dropEffect = "move";
|
2022-07-25 21:16:11 +09:00
|
|
|
break;
|
|
|
|
default:
|
2023-04-08 09:01:42 +09:00
|
|
|
ev.dataTransfer.dropEffect = "none";
|
2022-07-25 21:16:11 +09:00
|
|
|
break;
|
|
|
|
}
|
2022-01-16 01:46:25 +09:00
|
|
|
}
|
|
|
|
}
|
2021-01-15 23:20:47 +09:00
|
|
|
|
2022-05-07 17:01:01 +09:00
|
|
|
function onDragenter(ev) {
|
2022-01-16 01:46:25 +09:00
|
|
|
draghover = true;
|
|
|
|
}
|
2021-01-15 23:20:47 +09:00
|
|
|
|
2022-05-07 17:01:01 +09:00
|
|
|
function onDragleave(ev) {
|
2022-01-16 01:46:25 +09:00
|
|
|
draghover = false;
|
|
|
|
}
|
2019-05-27 15:38:14 +09:00
|
|
|
|
2022-05-07 17:01:01 +09:00
|
|
|
function onDrop(ev): void {
|
2022-01-16 01:46:25 +09:00
|
|
|
draghover = false;
|
2019-05-27 15:38:14 +09:00
|
|
|
|
2022-01-16 01:46:25 +09:00
|
|
|
// ファイルだったら
|
2022-05-07 17:01:01 +09:00
|
|
|
if (ev.dataTransfer.files.length > 0) {
|
|
|
|
ev.preventDefault();
|
|
|
|
for (const x of Array.from(ev.dataTransfer.files)) upload(x);
|
2022-01-16 01:46:25 +09:00
|
|
|
return;
|
|
|
|
}
|
2019-05-27 15:38:14 +09:00
|
|
|
|
2022-01-16 01:46:25 +09:00
|
|
|
//#region ドライブのファイル
|
2022-05-07 17:01:01 +09:00
|
|
|
const driveFile = ev.dataTransfer.getData(_DATA_TRANSFER_DRIVE_FILE_);
|
2023-04-08 09:01:42 +09:00
|
|
|
if (driveFile != null && driveFile !== "") {
|
2022-01-16 01:46:25 +09:00
|
|
|
const file = JSON.parse(driveFile);
|
|
|
|
files.push(file);
|
2022-05-07 17:01:01 +09:00
|
|
|
ev.preventDefault();
|
2022-01-16 01:46:25 +09:00
|
|
|
}
|
|
|
|
//#endregion
|
|
|
|
}
|
|
|
|
|
|
|
|
function saveDraft() {
|
2023-04-08 09:01:42 +09:00
|
|
|
const draftData = JSON.parse(localStorage.getItem("drafts") || "{}");
|
2022-01-16 01:46:25 +09:00
|
|
|
|
2022-05-07 17:01:01 +09:00
|
|
|
draftData[draftKey] = {
|
2022-01-16 01:46:25 +09:00
|
|
|
updatedAt: new Date(),
|
|
|
|
data: {
|
|
|
|
text: text,
|
|
|
|
useCw: useCw,
|
|
|
|
cw: cw,
|
|
|
|
visibility: visibility,
|
|
|
|
localOnly: localOnly,
|
|
|
|
files: files,
|
2022-07-05 23:01:23 +09:00
|
|
|
poll: poll,
|
|
|
|
},
|
2022-01-16 01:46:25 +09:00
|
|
|
};
|
|
|
|
|
2023-04-08 09:01:42 +09:00
|
|
|
localStorage.setItem("drafts", JSON.stringify(draftData));
|
2022-01-16 01:46:25 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
function deleteDraft() {
|
2023-04-08 09:01:42 +09:00
|
|
|
const draftData = JSON.parse(localStorage.getItem("drafts") || "{}");
|
2022-01-16 01:46:25 +09:00
|
|
|
|
2022-05-07 17:01:01 +09:00
|
|
|
delete draftData[draftKey];
|
2022-01-16 01:46:25 +09:00
|
|
|
|
2023-04-08 09:01:42 +09:00
|
|
|
localStorage.setItem("drafts", JSON.stringify(draftData));
|
2022-01-16 01:46:25 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
async function post() {
|
2023-03-30 12:11:57 +09:00
|
|
|
const processedText = preprocess(text);
|
|
|
|
|
2022-05-07 17:01:01 +09:00
|
|
|
let postData = {
|
2023-04-08 09:01:42 +09:00
|
|
|
text: processedText === "" ? undefined : processedText,
|
|
|
|
fileIds: files.length > 0 ? files.map((f) => f.id) : undefined,
|
2022-01-16 01:46:25 +09:00
|
|
|
replyId: props.reply ? props.reply.id : undefined,
|
2023-04-08 09:01:42 +09:00
|
|
|
renoteId: props.renote
|
|
|
|
? props.renote.id
|
|
|
|
: quoteId
|
|
|
|
? quoteId
|
|
|
|
: undefined,
|
2022-01-16 01:46:25 +09:00
|
|
|
channelId: props.channel ? props.channel.id : undefined,
|
|
|
|
poll: poll,
|
2023-04-08 09:01:42 +09:00
|
|
|
cw: useCw ? cw || "" : undefined,
|
2022-01-16 01:46:25 +09:00
|
|
|
localOnly: localOnly,
|
|
|
|
visibility: visibility,
|
2023-04-08 09:01:42 +09:00
|
|
|
visibleUserIds:
|
|
|
|
visibility === "specified"
|
|
|
|
? visibleUsers.map((u) => u.id)
|
|
|
|
: undefined,
|
2022-01-16 01:46:25 +09:00
|
|
|
};
|
|
|
|
|
2023-04-08 09:01:42 +09:00
|
|
|
if (withHashtags && hashtags && hashtags.trim() !== "") {
|
|
|
|
const hashtags_ = hashtags
|
|
|
|
.trim()
|
|
|
|
.split(" ")
|
|
|
|
.map((x) => (x.startsWith("#") ? x : "#" + x))
|
|
|
|
.join(" ");
|
|
|
|
postData.text = postData.text
|
|
|
|
? `${postData.text} ${hashtags_}`
|
|
|
|
: hashtags_;
|
2022-01-16 01:46:25 +09:00
|
|
|
}
|
2019-05-27 15:38:14 +09:00
|
|
|
|
2022-01-16 01:46:25 +09:00
|
|
|
// plugin
|
|
|
|
if (notePostInterruptors.length > 0) {
|
|
|
|
for (const interruptor of notePostInterruptors) {
|
2022-11-17 09:31:07 +09:00
|
|
|
postData = await interruptor.handler(deepClone(postData));
|
2022-01-16 01:46:25 +09:00
|
|
|
}
|
|
|
|
}
|
2019-05-27 15:38:14 +09:00
|
|
|
|
2022-01-21 20:17:31 +09:00
|
|
|
let token = undefined;
|
|
|
|
|
|
|
|
if (postAccount) {
|
|
|
|
const storedAccounts = await getAccounts();
|
2023-04-08 09:01:42 +09:00
|
|
|
token = storedAccounts.find((x) => x.id === postAccount.id)?.token;
|
2022-01-21 20:17:31 +09:00
|
|
|
}
|
|
|
|
|
2022-01-16 01:46:25 +09:00
|
|
|
posting = true;
|
2023-04-08 09:01:42 +09:00
|
|
|
os.api("notes/create", postData, token)
|
|
|
|
.then(() => {
|
|
|
|
clear();
|
|
|
|
nextTick(() => {
|
|
|
|
deleteDraft();
|
|
|
|
emit("posted");
|
|
|
|
if (postData.text && postData.text !== "") {
|
|
|
|
const hashtags_ = mfm
|
|
|
|
.parse(postData.text)
|
|
|
|
.filter((x) => x.type === "hashtag")
|
|
|
|
.map((x) => x.props.hashtag);
|
|
|
|
const history = JSON.parse(
|
|
|
|
localStorage.getItem("hashtags") || "[]"
|
|
|
|
) as string[];
|
|
|
|
localStorage.setItem(
|
|
|
|
"hashtags",
|
|
|
|
JSON.stringify(unique(hashtags_.concat(history)))
|
|
|
|
);
|
|
|
|
}
|
|
|
|
posting = false;
|
|
|
|
postAccount = null;
|
|
|
|
});
|
|
|
|
})
|
|
|
|
.catch((err) => {
|
2022-01-16 01:46:25 +09:00
|
|
|
posting = false;
|
2023-04-08 09:01:42 +09:00
|
|
|
os.alert({
|
|
|
|
type: "error",
|
|
|
|
text: err.message + "\n" + (err as any).id,
|
|
|
|
});
|
2022-01-16 01:46:25 +09:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function cancel() {
|
2023-04-08 09:01:42 +09:00
|
|
|
emit("cancel");
|
2022-01-16 01:46:25 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
function insertMention() {
|
2023-04-08 09:01:42 +09:00
|
|
|
os.selectUser().then((user) => {
|
|
|
|
insertTextAtCursor(textareaEl, "@" + Acct.toString(user) + " ");
|
2022-01-16 01:46:25 +09:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2022-01-21 20:17:31 +09:00
|
|
|
async function insertEmoji(ev: MouseEvent) {
|
2022-01-28 11:53:12 +09:00
|
|
|
os.openEmojiPicker(ev.currentTarget ?? ev.target, {}, textareaEl);
|
2022-01-16 01:46:25 +09:00
|
|
|
}
|
|
|
|
|
2023-01-29 11:56:48 +09:00
|
|
|
async function openCheatSheet(ev: MouseEvent) {
|
2023-04-08 09:01:42 +09:00
|
|
|
os.popup(XCheatSheet, {}, {}, "closed");
|
2023-01-29 11:56:48 +09:00
|
|
|
}
|
|
|
|
|
2022-01-16 01:46:25 +09:00
|
|
|
function showActions(ev) {
|
2023-04-08 09:01:42 +09:00
|
|
|
os.popupMenu(
|
|
|
|
postFormActions.map((action) => ({
|
|
|
|
text: action.title,
|
|
|
|
action: () => {
|
|
|
|
action.handler(
|
|
|
|
{
|
|
|
|
text: text,
|
|
|
|
},
|
|
|
|
(key, value) => {
|
|
|
|
if (key === "text") {
|
|
|
|
text = value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
|
|
|
},
|
|
|
|
})),
|
|
|
|
ev.currentTarget ?? ev.target
|
|
|
|
);
|
2022-01-16 01:46:25 +09:00
|
|
|
}
|
2019-05-27 15:38:14 +09:00
|
|
|
|
2022-01-21 20:17:31 +09:00
|
|
|
let postAccount = $ref<misskey.entities.UserDetailed | null>(null);
|
|
|
|
|
|
|
|
function openAccountMenu(ev: MouseEvent) {
|
2023-04-08 09:01:42 +09:00
|
|
|
openAccountMenu_(
|
|
|
|
{
|
|
|
|
withExtraOperation: false,
|
|
|
|
includeCurrentAccount: true,
|
|
|
|
active: postAccount != null ? postAccount.id : $i.id,
|
|
|
|
onChoose: (account) => {
|
|
|
|
if (account.id === $i.id) {
|
|
|
|
postAccount = null;
|
|
|
|
} else {
|
|
|
|
postAccount = account;
|
|
|
|
}
|
|
|
|
},
|
2022-01-21 20:17:31 +09:00
|
|
|
},
|
2023-04-08 09:01:42 +09:00
|
|
|
ev
|
|
|
|
);
|
2022-01-21 20:17:31 +09:00
|
|
|
}
|
|
|
|
|
2022-01-16 01:46:25 +09:00
|
|
|
onMounted(() => {
|
|
|
|
if (props.autofocus) {
|
|
|
|
focus();
|
2019-05-27 15:38:14 +09:00
|
|
|
|
2022-01-16 01:46:25 +09:00
|
|
|
nextTick(() => {
|
|
|
|
focus();
|
|
|
|
});
|
|
|
|
}
|
2019-05-27 15:38:14 +09:00
|
|
|
|
2022-01-16 01:46:25 +09:00
|
|
|
// TODO: detach when unmount
|
|
|
|
new Autocomplete(textareaEl, $$(text));
|
|
|
|
new Autocomplete(cwInputEl, $$(cw));
|
|
|
|
new Autocomplete(hashtagsInputEl, $$(hashtags));
|
|
|
|
|
|
|
|
nextTick(() => {
|
|
|
|
// 書きかけの投稿を復元
|
2022-01-27 17:38:02 +09:00
|
|
|
if (!props.instant && !props.mention && !props.specified) {
|
2023-04-08 09:01:42 +09:00
|
|
|
const draft = JSON.parse(localStorage.getItem("drafts") || "{}")[
|
|
|
|
draftKey
|
|
|
|
];
|
2022-01-16 01:46:25 +09:00
|
|
|
if (draft) {
|
|
|
|
text = draft.data.text;
|
|
|
|
useCw = draft.data.useCw;
|
|
|
|
cw = draft.data.cw;
|
|
|
|
visibility = draft.data.visibility;
|
|
|
|
localOnly = draft.data.localOnly;
|
2023-04-08 09:01:42 +09:00
|
|
|
files = (draft.data.files || []).filter(
|
|
|
|
(draftFile) => draftFile
|
|
|
|
);
|
2022-01-16 01:46:25 +09:00
|
|
|
if (draft.data.poll) {
|
|
|
|
poll = draft.data.poll;
|
2019-05-27 15:38:14 +09:00
|
|
|
}
|
2021-08-07 12:47:01 +09:00
|
|
|
}
|
2022-01-16 01:46:25 +09:00
|
|
|
}
|
2021-08-07 12:47:01 +09:00
|
|
|
|
2022-01-16 01:46:25 +09:00
|
|
|
// 削除して編集
|
|
|
|
if (props.initialNote) {
|
|
|
|
const init = props.initialNote;
|
2023-04-08 09:01:42 +09:00
|
|
|
text = init.text ? init.text : "";
|
2022-01-16 01:46:25 +09:00
|
|
|
files = init.files;
|
|
|
|
cw = init.cw;
|
|
|
|
useCw = init.cw != null;
|
|
|
|
if (init.poll) {
|
|
|
|
poll = {
|
2023-04-08 09:01:42 +09:00
|
|
|
choices: init.poll.choices.map((x) => x.text),
|
2022-01-16 01:46:25 +09:00
|
|
|
multiple: init.poll.multiple,
|
|
|
|
expiresAt: init.poll.expiresAt,
|
|
|
|
expiredAfter: init.poll.expiredAfter,
|
|
|
|
};
|
2020-07-29 23:37:50 +09:00
|
|
|
}
|
2022-01-16 01:46:25 +09:00
|
|
|
visibility = init.visibility;
|
|
|
|
localOnly = init.localOnly;
|
|
|
|
quoteId = init.renote ? init.renote.id : null;
|
2020-07-12 00:38:55 +09:00
|
|
|
}
|
2022-01-16 01:46:25 +09:00
|
|
|
|
|
|
|
nextTick(() => watchForDraft());
|
|
|
|
});
|
2019-05-27 15:38:14 +09:00
|
|
|
});
|
2020-01-30 04:37:25 +09:00
|
|
|
</script>
|
|
|
|
|
|
|
|
<style lang="scss" scoped>
|
2023-01-29 11:56:48 +09:00
|
|
|
.right {
|
2023-04-08 09:01:42 +09:00
|
|
|
float: right;
|
2023-01-29 11:56:48 +09:00
|
|
|
}
|
2020-01-30 04:37:25 +09:00
|
|
|
.gafaadew {
|
2020-10-17 20:12:00 +09:00
|
|
|
position: relative;
|
|
|
|
|
|
|
|
&.modal {
|
|
|
|
width: 100%;
|
|
|
|
max-width: 520px;
|
|
|
|
}
|
2020-01-30 04:37:25 +09:00
|
|
|
|
|
|
|
> header {
|
|
|
|
z-index: 1000;
|
|
|
|
height: 66px;
|
|
|
|
|
|
|
|
> .cancel {
|
|
|
|
padding: 0;
|
|
|
|
font-size: 20px;
|
|
|
|
width: 64px;
|
|
|
|
line-height: 66px;
|
|
|
|
}
|
|
|
|
|
2022-01-21 20:17:31 +09:00
|
|
|
> .account {
|
|
|
|
height: 100%;
|
|
|
|
aspect-ratio: 1/1;
|
|
|
|
display: inline-flex;
|
|
|
|
vertical-align: bottom;
|
|
|
|
|
|
|
|
> .avatar {
|
|
|
|
width: 28px;
|
|
|
|
height: 28px;
|
|
|
|
margin: auto;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-07-05 23:01:23 +09:00
|
|
|
> .right {
|
2020-01-30 04:37:25 +09:00
|
|
|
position: absolute;
|
|
|
|
top: 0;
|
|
|
|
right: 0;
|
|
|
|
|
|
|
|
> .text-count {
|
2020-02-12 02:55:35 +09:00
|
|
|
opacity: 0.7;
|
2020-01-30 04:37:25 +09:00
|
|
|
line-height: 66px;
|
|
|
|
}
|
|
|
|
|
2020-02-05 21:28:51 +09:00
|
|
|
> .visibility {
|
|
|
|
height: 34px;
|
|
|
|
width: 34px;
|
2021-10-16 01:19:49 +09:00
|
|
|
margin: 0 0 0 8px;
|
2020-05-16 21:50:16 +09:00
|
|
|
|
|
|
|
& + .localOnly {
|
|
|
|
margin-left: 0 !important;
|
|
|
|
}
|
|
|
|
}
|
2022-11-18 13:32:24 +09:00
|
|
|
|
2020-10-17 20:12:00 +09:00
|
|
|
> .local-only {
|
|
|
|
margin: 0 0 0 12px;
|
|
|
|
opacity: 0.7;
|
2020-02-05 21:28:51 +09:00
|
|
|
}
|
|
|
|
|
2021-10-16 01:19:49 +09:00
|
|
|
> .preview {
|
|
|
|
display: inline-block;
|
|
|
|
padding: 0;
|
|
|
|
margin: 0 8px 0 0;
|
|
|
|
font-size: 16px;
|
|
|
|
width: 34px;
|
|
|
|
height: 34px;
|
|
|
|
border-radius: 6px;
|
|
|
|
|
|
|
|
&:hover {
|
|
|
|
background: var(--X5);
|
|
|
|
}
|
|
|
|
|
|
|
|
&.active {
|
|
|
|
color: var(--accent);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-30 04:37:25 +09:00
|
|
|
> .submit {
|
2023-03-16 10:24:12 +09:00
|
|
|
display: inline-flex;
|
|
|
|
align-items: center;
|
2020-02-05 21:28:51 +09:00
|
|
|
margin: 16px 16px 16px 0;
|
2020-02-08 17:49:54 +09:00
|
|
|
padding: 0 12px;
|
2020-01-30 04:37:25 +09:00
|
|
|
line-height: 34px;
|
2020-02-08 17:49:54 +09:00
|
|
|
font-weight: bold;
|
2020-01-30 04:37:25 +09:00
|
|
|
vertical-align: bottom;
|
|
|
|
border-radius: 4px;
|
2021-10-16 15:00:55 +09:00
|
|
|
font-size: 0.9em;
|
2020-01-30 04:37:25 +09:00
|
|
|
|
|
|
|
&:disabled {
|
|
|
|
opacity: 0.7;
|
|
|
|
}
|
2020-02-08 17:49:54 +09:00
|
|
|
|
2021-04-20 23:22:59 +09:00
|
|
|
> i {
|
2020-02-08 17:49:54 +09:00
|
|
|
margin-left: 6px;
|
|
|
|
}
|
2020-01-30 04:37:25 +09:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
> .form {
|
|
|
|
> .preview {
|
|
|
|
padding: 16px;
|
|
|
|
}
|
|
|
|
|
|
|
|
> .with-quote {
|
2023-05-09 06:26:59 +09:00
|
|
|
display: flex;
|
|
|
|
align-items: center;
|
|
|
|
gap: .4em;
|
|
|
|
margin-inline: 24px;
|
|
|
|
margin-bottom: 12px;
|
2020-01-30 04:37:25 +09:00
|
|
|
color: var(--accent);
|
|
|
|
|
|
|
|
> button {
|
2023-05-09 06:26:59 +09:00
|
|
|
display: flex;
|
|
|
|
padding: 0;
|
2020-01-30 04:37:25 +09:00
|
|
|
color: var(--accentAlpha04);
|
|
|
|
|
|
|
|
&:hover {
|
|
|
|
color: var(--accentAlpha06);
|
|
|
|
}
|
|
|
|
|
|
|
|
&:active {
|
|
|
|
color: var(--accentDarken30);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
> .to-specified {
|
|
|
|
padding: 6px 24px;
|
|
|
|
margin-bottom: 8px;
|
|
|
|
overflow: auto;
|
2022-11-18 14:01:05 +09:00
|
|
|
line-height: 2rem;
|
2020-01-30 04:37:25 +09:00
|
|
|
|
|
|
|
> .visibleUsers {
|
|
|
|
display: inline;
|
|
|
|
top: -1px;
|
|
|
|
font-size: 14px;
|
|
|
|
|
|
|
|
> button {
|
2022-11-18 13:32:24 +09:00
|
|
|
padding: 2px;
|
2020-01-30 04:37:25 +09:00
|
|
|
border-radius: 8px;
|
2022-11-18 13:32:24 +09:00
|
|
|
|
|
|
|
> i {
|
|
|
|
transform: translateX(2px);
|
|
|
|
}
|
2020-01-30 04:37:25 +09:00
|
|
|
}
|
|
|
|
|
2022-11-18 13:32:24 +09:00
|
|
|
> span {
|
|
|
|
margin: 0.3rem;
|
|
|
|
padding: 4px 0 4px 4px;
|
|
|
|
border-radius: 999px;
|
|
|
|
background: var(--X3);
|
2020-01-30 04:37:25 +09:00
|
|
|
|
|
|
|
> button {
|
|
|
|
padding: 4px 8px;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-16 00:13:20 +09:00
|
|
|
> .hasNotSpecifiedMentions {
|
|
|
|
margin: 0 20px 16px 20px;
|
|
|
|
}
|
|
|
|
|
2020-02-05 08:59:24 +09:00
|
|
|
> .cw,
|
2021-08-07 12:47:01 +09:00
|
|
|
> .hashtags,
|
2020-02-05 08:59:24 +09:00
|
|
|
> .text {
|
2020-01-30 04:37:25 +09:00
|
|
|
display: block;
|
|
|
|
box-sizing: border-box;
|
|
|
|
padding: 0 24px;
|
|
|
|
margin: 0;
|
|
|
|
width: 100%;
|
|
|
|
font-size: 16px;
|
|
|
|
border: none;
|
|
|
|
border-radius: 0;
|
|
|
|
background: transparent;
|
|
|
|
color: var(--fg);
|
2020-02-09 19:59:28 +09:00
|
|
|
font-family: inherit;
|
2020-01-30 04:37:25 +09:00
|
|
|
|
2021-11-08 03:43:14 +09:00
|
|
|
&:focus {
|
2020-01-30 04:37:25 +09:00
|
|
|
outline: none;
|
|
|
|
}
|
|
|
|
|
|
|
|
&:disabled {
|
|
|
|
opacity: 0.5;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-05 08:59:24 +09:00
|
|
|
> .cw {
|
|
|
|
z-index: 1;
|
|
|
|
padding-bottom: 8px;
|
2021-04-10 12:40:50 +09:00
|
|
|
border-bottom: solid 0.5px var(--divider);
|
2020-02-05 08:59:24 +09:00
|
|
|
}
|
|
|
|
|
2021-08-07 12:47:01 +09:00
|
|
|
> .hashtags {
|
|
|
|
z-index: 1;
|
|
|
|
padding-top: 8px;
|
|
|
|
padding-bottom: 8px;
|
|
|
|
border-top: solid 0.5px var(--divider);
|
|
|
|
}
|
|
|
|
|
2020-02-05 08:59:24 +09:00
|
|
|
> .text {
|
2020-01-30 04:37:25 +09:00
|
|
|
max-width: 100%;
|
|
|
|
min-width: 100%;
|
|
|
|
min-height: 90px;
|
|
|
|
|
2020-02-05 08:59:24 +09:00
|
|
|
&.withCw {
|
|
|
|
padding-top: 8px;
|
|
|
|
}
|
2020-01-30 04:37:25 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
> footer {
|
|
|
|
padding: 0 16px 16px 16px;
|
|
|
|
|
2020-02-05 09:15:28 +09:00
|
|
|
> button {
|
2020-01-30 04:37:25 +09:00
|
|
|
display: inline-block;
|
|
|
|
padding: 0;
|
|
|
|
margin: 0;
|
|
|
|
font-size: 16px;
|
|
|
|
width: 48px;
|
|
|
|
height: 48px;
|
|
|
|
border-radius: 6px;
|
|
|
|
|
|
|
|
&:hover {
|
2020-07-05 03:49:58 +09:00
|
|
|
background: var(--X5);
|
2020-01-30 04:37:25 +09:00
|
|
|
}
|
2020-02-05 09:15:28 +09:00
|
|
|
|
|
|
|
&.active {
|
|
|
|
color: var(--accent);
|
|
|
|
}
|
2020-01-30 04:37:25 +09:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-10-17 20:12:00 +09:00
|
|
|
|
|
|
|
&.max-width_500px {
|
|
|
|
> header {
|
|
|
|
height: 50px;
|
|
|
|
|
|
|
|
> .cancel {
|
|
|
|
width: 50px;
|
|
|
|
line-height: 50px;
|
|
|
|
}
|
|
|
|
|
2022-07-05 23:01:23 +09:00
|
|
|
> .right {
|
2020-10-17 20:12:00 +09:00
|
|
|
> .text-count {
|
|
|
|
line-height: 50px;
|
|
|
|
}
|
|
|
|
|
|
|
|
> .submit {
|
|
|
|
margin: 8px;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
> .form {
|
|
|
|
> .to-specified {
|
|
|
|
padding: 6px 16px;
|
|
|
|
}
|
|
|
|
|
|
|
|
> .cw,
|
2021-08-07 12:47:01 +09:00
|
|
|
> .hashtags,
|
2020-10-17 20:12:00 +09:00
|
|
|
> .text {
|
|
|
|
padding: 0 16px;
|
|
|
|
}
|
|
|
|
|
|
|
|
> .text {
|
|
|
|
min-height: 80px;
|
|
|
|
}
|
|
|
|
|
|
|
|
> footer {
|
|
|
|
padding: 0 8px 8px 8px;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-10-14 18:51:15 +09:00
|
|
|
|
|
|
|
&.max-width_310px {
|
|
|
|
> .form {
|
|
|
|
> footer {
|
|
|
|
> button {
|
|
|
|
font-size: 14px;
|
|
|
|
width: 44px;
|
2023-04-08 09:01:42 +09:00
|
|
|
height: 44px;
|
2021-10-14 18:51:15 +09:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-01-30 04:37:25 +09:00
|
|
|
}
|
|
|
|
</style>
|