2020-01-29 21:37:25 +02:00
|
|
|
<template>
|
|
|
|
<div class="gafaadew"
|
|
|
|
@dragover.stop="onDragover"
|
|
|
|
@dragenter="onDragenter"
|
|
|
|
@dragleave="onDragleave"
|
|
|
|
@drop.stop="onDrop"
|
|
|
|
>
|
|
|
|
<header>
|
|
|
|
<button class="cancel _button" @click="cancel"><fa :icon="faTimes"/></button>
|
|
|
|
<div>
|
2020-02-10 16:17:42 +02:00
|
|
|
<span class="text-count" :class="{ over: trimmedLength(text) > max }">{{ max - trimmedLength(text) }}</span>
|
2020-02-05 14:28:51 +02:00
|
|
|
<button class="_button visibility" @click="setVisibility" ref="visibilityButton">
|
|
|
|
<span v-if="visibility === 'public'"><fa :icon="faGlobe"/></span>
|
|
|
|
<span v-if="visibility === 'home'"><fa :icon="faHome"/></span>
|
|
|
|
<span v-if="visibility === 'followers'"><fa :icon="faUnlock"/></span>
|
|
|
|
<span v-if="visibility === 'specified'"><fa :icon="faEnvelope"/></span>
|
|
|
|
</button>
|
2020-02-08 10:49:54 +02:00
|
|
|
<button class="submit _buttonPrimary" :disabled="!canPost" @click="post">{{ submitText }}<fa :icon="reply ? faReply : renote ? faQuoteRight : faPaperPlane"/></button>
|
2020-01-29 21:37:25 +02:00
|
|
|
</div>
|
|
|
|
</header>
|
|
|
|
<div class="form">
|
|
|
|
<x-note-preview class="preview" v-if="reply" :note="reply"/>
|
|
|
|
<x-note-preview class="preview" v-if="renote" :note="renote"/>
|
2020-02-11 23:27:11 +02:00
|
|
|
<div class="with-quote" v-if="quoteId"><fa icon="quote-left"/> {{ $t('quoteAttached') }}<button @click="quoteId = null"><fa icon="times"/></button></div>
|
2020-01-29 21:37:25 +02:00
|
|
|
<div v-if="visibility === 'specified'" class="to-specified">
|
|
|
|
<span style="margin-right: 8px;">{{ $t('recipient') }}</span>
|
|
|
|
<div class="visibleUsers">
|
|
|
|
<span v-for="u in visibleUsers">
|
|
|
|
<mk-acct :user="u"/>
|
|
|
|
<button class="_button" @click="removeVisibleUser(u)"><fa :icon="faTimes"/></button>
|
|
|
|
</span>
|
|
|
|
<button @click="addVisibleUser" class="_buttonPrimary"><fa :icon="faPlus" fixed-width/></button>
|
|
|
|
</div>
|
|
|
|
</div>
|
2020-02-05 01:59:24 +02:00
|
|
|
<input v-show="useCw" ref="cw" class="cw" v-model="cw" :placeholder="$t('annotation')" v-autocomplete="{ model: 'cw' }">
|
|
|
|
<textarea v-model="text" class="text" :class="{ withCw: useCw }" ref="text" :disabled="posting" :placeholder="placeholder" v-autocomplete="{ model: 'text' }" @keydown="onKeydown" @paste="onPaste"></textarea>
|
2020-01-29 21:37:25 +02:00
|
|
|
<x-post-form-attaches class="attaches" :files="files"/>
|
|
|
|
<x-poll-editor v-if="poll" ref="poll" @destroyed="poll = false" @updated="onPollUpdate()"/>
|
|
|
|
<x-uploader ref="uploader" @uploaded="attachMedia" @change="onChangeUploadings"/>
|
|
|
|
<footer>
|
|
|
|
<button class="_button" @click="chooseFileFrom"><fa :icon="faPhotoVideo"/></button>
|
2020-02-05 02:21:51 +02:00
|
|
|
<button class="_button" @click="poll = !poll" :class="{ active: poll }"><fa :icon="faChartPie"/></button>
|
|
|
|
<button class="_button" @click="useCw = !useCw" :class="{ active: useCw }"><fa :icon="faEyeSlash"/></button>
|
2020-01-29 21:37:25 +02:00
|
|
|
<button class="_button" @click="insertMention"><fa :icon="faAt"/></button>
|
|
|
|
<button class="_button" @click="insertEmoji"><fa :icon="faLaughSquint"/></button>
|
2020-02-05 02:21:51 +02:00
|
|
|
<button class="_button" v-if="visibility !== 'specified'" @click="localOnly = !localOnly" :class="{ active: localOnly }"><fa :icon="faBiohazard"/></button>
|
2020-01-29 21:37:25 +02:00
|
|
|
</footer>
|
|
|
|
<input ref="file" class="file _button" type="file" multiple="multiple" @change="onChangeFile"/>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script lang="ts">
|
|
|
|
import Vue from 'vue';
|
2020-02-08 10:49:54 +02:00
|
|
|
import { faReply, faQuoteRight, faPaperPlane, faTimes, faUpload, faChartPie, faGlobe, faHome, faUnlock, faEnvelope, faPlus, faPhotoVideo, faCloud, faLink, faAt, faBiohazard } from '@fortawesome/free-solid-svg-icons';
|
2020-01-29 21:37:25 +02:00
|
|
|
import { faEyeSlash, faLaughSquint } from '@fortawesome/free-regular-svg-icons';
|
2019-05-27 09:38:14 +03:00
|
|
|
import insertTextAtCursor from 'insert-text-at-cursor';
|
|
|
|
import { length } from 'stringz';
|
|
|
|
import { toASCII } from 'punycode';
|
2020-01-29 21:37:25 +02:00
|
|
|
import i18n from '../i18n';
|
|
|
|
import MkVisibilityChooser from './visibility-chooser.vue';
|
|
|
|
import MkUserSelect from './user-select.vue';
|
|
|
|
import XNotePreview from './note-preview.vue';
|
|
|
|
import { parse } from '../../mfm/parse';
|
|
|
|
import { host, url } from '../config';
|
|
|
|
import { erase, unique } from '../../prelude/array';
|
|
|
|
import extractMentions from '../../misc/extract-mentions';
|
|
|
|
import getAcct from '../../misc/acct/render';
|
|
|
|
import { formatTimeString } from '../../misc/format-time-string';
|
|
|
|
import { selectDriveFile } from '../scripts/select-drive-file';
|
|
|
|
|
|
|
|
export default Vue.extend({
|
|
|
|
i18n,
|
2019-05-27 09:38:14 +03:00
|
|
|
|
|
|
|
components: {
|
2020-01-29 21:37:25 +02:00
|
|
|
XNotePreview,
|
|
|
|
XUploader: () => import('./uploader.vue').then(m => m.default),
|
|
|
|
XPostFormAttaches: () => import('./post-form-attaches.vue').then(m => m.default),
|
|
|
|
XPollEditor: () => import('./poll-editor.vue').then(m => m.default)
|
2019-05-27 09:38:14 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
props: {
|
|
|
|
reply: {
|
|
|
|
type: Object,
|
|
|
|
required: false
|
|
|
|
},
|
|
|
|
renote: {
|
|
|
|
type: Object,
|
|
|
|
required: false
|
|
|
|
},
|
|
|
|
mention: {
|
|
|
|
type: Object,
|
|
|
|
required: false
|
|
|
|
},
|
2020-01-29 21:37:25 +02:00
|
|
|
specified: {
|
|
|
|
type: Object,
|
|
|
|
required: false
|
|
|
|
},
|
2019-05-27 09:38:14 +03:00
|
|
|
initialText: {
|
|
|
|
type: String,
|
|
|
|
required: false
|
|
|
|
},
|
2019-07-27 23:33:12 +03:00
|
|
|
initialNote: {
|
|
|
|
type: Object,
|
|
|
|
required: false
|
|
|
|
},
|
2019-05-27 09:38:14 +03:00
|
|
|
instant: {
|
|
|
|
type: Boolean,
|
|
|
|
required: false,
|
|
|
|
default: false
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
posting: false,
|
|
|
|
text: '',
|
|
|
|
files: [],
|
|
|
|
uploadings: [],
|
|
|
|
poll: false,
|
|
|
|
pollChoices: [],
|
|
|
|
pollMultiple: false,
|
|
|
|
pollExpiration: [],
|
|
|
|
useCw: false,
|
|
|
|
cw: null,
|
2020-02-05 02:15:28 +02:00
|
|
|
localOnly: false,
|
2019-05-27 09:38:14 +03:00
|
|
|
visibility: 'public',
|
|
|
|
visibleUsers: [],
|
|
|
|
autocomplete: null,
|
|
|
|
draghover: false,
|
|
|
|
quoteId: null,
|
|
|
|
recentHashtags: JSON.parse(localStorage.getItem('hashtags') || '[]'),
|
2020-02-08 10:49:54 +02:00
|
|
|
faReply, faQuoteRight, faPaperPlane, faTimes, faUpload, faChartPie, faGlobe, faHome, faUnlock, faEnvelope, faEyeSlash, faLaughSquint, faPlus, faPhotoVideo, faCloud, faLink, faAt, faBiohazard
|
2019-05-27 09:38:14 +03:00
|
|
|
};
|
|
|
|
},
|
|
|
|
|
|
|
|
computed: {
|
|
|
|
draftId(): string {
|
|
|
|
return this.renote
|
|
|
|
? `renote:${this.renote.id}`
|
|
|
|
: this.reply
|
|
|
|
? `reply:${this.reply.id}`
|
|
|
|
: 'note';
|
|
|
|
},
|
|
|
|
|
|
|
|
placeholder(): string {
|
|
|
|
const xs = [
|
2020-01-29 21:37:25 +02:00
|
|
|
this.$t('_postForm._placeholders.a'),
|
|
|
|
this.$t('_postForm._placeholders.b'),
|
|
|
|
this.$t('_postForm._placeholders.c'),
|
|
|
|
this.$t('_postForm._placeholders.d'),
|
|
|
|
this.$t('_postForm._placeholders.e'),
|
|
|
|
this.$t('_postForm._placeholders.f')
|
2019-05-27 09:38:14 +03:00
|
|
|
];
|
|
|
|
const x = xs[Math.floor(Math.random() * xs.length)];
|
2020-02-09 12:59:28 +02:00
|
|
|
|
2019-05-27 09:38:14 +03:00
|
|
|
return this.renote
|
2020-01-29 21:37:25 +02:00
|
|
|
? this.$t('_postForm.quotePlaceholder')
|
2019-05-27 09:38:14 +03:00
|
|
|
: this.reply
|
2020-01-29 21:37:25 +02:00
|
|
|
? this.$t('_postForm.replyPlaceholder')
|
2019-05-27 09:38:14 +03:00
|
|
|
: x;
|
|
|
|
},
|
|
|
|
|
|
|
|
submitText(): string {
|
|
|
|
return this.renote
|
2020-02-08 10:49:54 +02:00
|
|
|
? this.$t('quote')
|
2019-05-27 09:38:14 +03:00
|
|
|
: this.reply
|
2020-01-29 21:37:25 +02:00
|
|
|
? this.$t('reply')
|
2020-02-08 10:49:54 +02:00
|
|
|
: this.$t('note');
|
2019-05-27 09:38:14 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
canPost(): boolean {
|
|
|
|
return !this.posting &&
|
|
|
|
(1 <= this.text.length || 1 <= this.files.length || this.poll || this.renote) &&
|
2020-02-10 16:17:42 +02:00
|
|
|
(length(this.text.trim()) <= this.max) &&
|
2019-05-27 09:38:14 +03:00
|
|
|
(!this.poll || this.pollChoices.length >= 2);
|
2020-02-10 16:17:42 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
max(): number {
|
|
|
|
return this.$store.state.instance.meta ? this.$store.state.instance.meta.maxNoteTextLength : 1000;
|
2019-05-27 09:38:14 +03:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2020-02-05 02:42:58 +02:00
|
|
|
watch: {
|
|
|
|
localOnly() {
|
2020-02-10 00:23:43 +02:00
|
|
|
this.$store.commit('deviceUser/setLocalOnly', this.localOnly);
|
2020-02-05 02:42:58 +02:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2019-05-27 09:38:14 +03:00
|
|
|
mounted() {
|
|
|
|
if (this.initialText) {
|
|
|
|
this.text = this.initialText;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.mention) {
|
|
|
|
this.text = this.mention.host ? `@${this.mention.username}@${toASCII(this.mention.host)}` : `@${this.mention.username}`;
|
|
|
|
this.text += ' ';
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.reply && this.reply.user.host != null) {
|
|
|
|
this.text = `@${this.reply.user.username}@${toASCII(this.reply.user.host)} `;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.reply && this.reply.text != null) {
|
|
|
|
const ast = parse(this.reply.text);
|
|
|
|
|
|
|
|
for (const x of extractMentions(ast)) {
|
|
|
|
const mention = x.host ? `@${x.username}@${toASCII(x.host)}` : `@${x.username}`;
|
|
|
|
|
|
|
|
// 自分は除外
|
|
|
|
if (this.$store.state.i.username == x.username && x.host == null) continue;
|
|
|
|
if (this.$store.state.i.username == x.username && x.host == host) continue;
|
|
|
|
|
|
|
|
// 重複は除外
|
|
|
|
if (this.text.indexOf(`${mention} `) != -1) continue;
|
|
|
|
|
|
|
|
this.text += `${mention} `;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// デフォルト公開範囲
|
2020-02-10 00:23:43 +02:00
|
|
|
this.applyVisibility(this.$store.state.settings.rememberNoteVisibility ? this.$store.state.deviceUser.visibility : this.$store.state.settings.defaultNoteVisibility);
|
2020-02-05 02:42:58 +02:00
|
|
|
|
2020-02-10 00:23:43 +02:00
|
|
|
this.localOnly = this.$store.state.settings.rememberNoteVisibility ? this.$store.state.deviceUser.localOnly : this.$store.state.settings.defaultNoteLocalOnly;
|
2019-05-27 09:38:14 +03:00
|
|
|
|
|
|
|
// 公開以外へのリプライ時は元の公開範囲を引き継ぐ
|
|
|
|
if (this.reply && ['home', 'followers', 'specified'].includes(this.reply.visibility)) {
|
|
|
|
this.visibility = this.reply.visibility;
|
2019-07-07 11:14:08 +03:00
|
|
|
if (this.reply.visibility === 'specified') {
|
|
|
|
this.$root.api('users/show', {
|
|
|
|
userIds: this.reply.visibleUserIds.filter(uid => uid !== this.$store.state.i.id && uid !== this.reply.userId)
|
|
|
|
}).then(users => {
|
|
|
|
this.visibleUsers.push(...users);
|
|
|
|
});
|
2019-05-27 09:38:14 +03:00
|
|
|
|
2019-08-25 10:12:01 +03:00
|
|
|
if (this.reply.userId !== this.$store.state.i.id) {
|
|
|
|
this.$root.api('users/show', { userId: this.reply.userId }).then(user => {
|
|
|
|
this.visibleUsers.push(user);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
2019-05-27 09:38:14 +03:00
|
|
|
}
|
|
|
|
|
2020-01-29 21:37:25 +02:00
|
|
|
if (this.specified) {
|
|
|
|
this.visibility = 'specified';
|
|
|
|
this.visibleUsers.push(this.specified);
|
|
|
|
}
|
|
|
|
|
2019-05-27 09:38:14 +03:00
|
|
|
// keep cw when reply
|
|
|
|
if (this.$store.state.settings.keepCw && this.reply && this.reply.cw) {
|
|
|
|
this.useCw = true;
|
|
|
|
this.cw = this.reply.cw;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.focus();
|
|
|
|
|
|
|
|
this.$nextTick(() => {
|
|
|
|
this.focus();
|
|
|
|
});
|
|
|
|
|
|
|
|
this.$nextTick(() => {
|
|
|
|
// 書きかけの投稿を復元
|
|
|
|
if (!this.instant && !this.mention) {
|
|
|
|
const draft = JSON.parse(localStorage.getItem('drafts') || '{}')[this.draftId];
|
|
|
|
if (draft) {
|
|
|
|
this.text = draft.data.text;
|
2020-02-05 01:59:24 +02:00
|
|
|
this.useCw = draft.data.useCw;
|
|
|
|
this.cw = draft.data.cw;
|
2020-02-05 02:50:03 +02:00
|
|
|
this.applyVisibility(draft.data.visibility);
|
|
|
|
this.localOnly = draft.data.localOnly;
|
2019-05-27 09:38:14 +03:00
|
|
|
this.files = (draft.data.files || []).filter(e => e);
|
|
|
|
if (draft.data.poll) {
|
|
|
|
this.poll = true;
|
|
|
|
this.$nextTick(() => {
|
|
|
|
(this.$refs.poll as any).set(draft.data.poll);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-08-25 10:12:01 +03:00
|
|
|
|
|
|
|
// 削除して編集
|
2019-07-27 23:33:12 +03:00
|
|
|
if (this.initialNote) {
|
|
|
|
const init = this.initialNote;
|
|
|
|
this.text = init.text ? init.text : '';
|
|
|
|
this.files = init.files;
|
|
|
|
this.cw = init.cw;
|
|
|
|
this.useCw = init.cw != null;
|
|
|
|
if (init.poll) {
|
|
|
|
this.poll = true;
|
|
|
|
this.$nextTick(() => {
|
|
|
|
(this.$refs.poll as any).set({
|
|
|
|
choices: init.poll.choices.map(c => c.text),
|
|
|
|
multiple: init.poll.multiple
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
this.visibility = init.visibility;
|
|
|
|
this.quoteId = init.renote ? init.renote.id : null;
|
|
|
|
}
|
2019-05-27 09:38:14 +03:00
|
|
|
|
|
|
|
this.$nextTick(() => this.watch());
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
methods: {
|
|
|
|
watch() {
|
|
|
|
this.$watch('text', () => this.saveDraft());
|
2020-02-05 01:59:24 +02:00
|
|
|
this.$watch('useCw', () => this.saveDraft());
|
|
|
|
this.$watch('cw', () => this.saveDraft());
|
2019-05-27 09:38:14 +03:00
|
|
|
this.$watch('poll', () => this.saveDraft());
|
|
|
|
this.$watch('files', () => this.saveDraft());
|
2020-02-05 02:50:03 +02:00
|
|
|
this.$watch('visibility', () => this.saveDraft());
|
|
|
|
this.$watch('localOnly', () => this.saveDraft());
|
2019-05-27 09:38:14 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
trimmedLength(text: string) {
|
|
|
|
return length(text.trim());
|
|
|
|
},
|
|
|
|
|
|
|
|
addTag(tag: string) {
|
|
|
|
insertTextAtCursor(this.$refs.text, ` #${tag} `);
|
|
|
|
},
|
|
|
|
|
|
|
|
focus() {
|
|
|
|
(this.$refs.text as any).focus();
|
|
|
|
},
|
|
|
|
|
2020-01-29 21:37:25 +02:00
|
|
|
chooseFileFrom(ev) {
|
|
|
|
this.$root.menu({
|
|
|
|
items: [{
|
|
|
|
type: 'label',
|
|
|
|
text: this.$t('attachFile'),
|
|
|
|
}, {
|
|
|
|
text: this.$t('upload'),
|
|
|
|
icon: faUpload,
|
|
|
|
action: () => { this.chooseFileFromPc() }
|
|
|
|
}, {
|
|
|
|
text: this.$t('fromDrive'),
|
|
|
|
icon: faCloud,
|
|
|
|
action: () => { this.chooseFileFromDrive() }
|
|
|
|
}, {
|
|
|
|
text: this.$t('fromUrl'),
|
|
|
|
icon: faLink,
|
|
|
|
action: () => { this.chooseFileFromUrl() }
|
|
|
|
}],
|
|
|
|
source: ev.currentTarget || ev.target
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
chooseFileFromPc() {
|
2019-05-27 09:38:14 +03:00
|
|
|
(this.$refs.file as any).click();
|
|
|
|
},
|
|
|
|
|
|
|
|
chooseFileFromDrive() {
|
2020-01-29 21:37:25 +02:00
|
|
|
selectDriveFile(this.$root, true).then(files => {
|
|
|
|
for (const file of files) {
|
|
|
|
this.attachMedia(file);
|
|
|
|
}
|
2019-05-27 09:38:14 +03:00
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
attachMedia(driveFile) {
|
|
|
|
this.files.push(driveFile);
|
|
|
|
},
|
|
|
|
|
|
|
|
detachMedia(id) {
|
|
|
|
this.files = this.files.filter(x => x.id != id);
|
2020-01-29 21:37:25 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
updateMedia(file) {
|
|
|
|
Vue.set(this.files, this.files.findIndex(x => x.id === file.id), file);
|
2019-05-27 09:38:14 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
onChangeFile() {
|
|
|
|
for (const x of Array.from((this.$refs.file as any).files)) this.upload(x);
|
|
|
|
},
|
|
|
|
|
2019-07-08 07:46:31 +03:00
|
|
|
upload(file: File, name?: string) {
|
|
|
|
(this.$refs.uploader as any).upload(file, this.$store.state.settings.uploadFolder, name);
|
2019-05-27 09:38:14 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
onChangeUploadings(uploads) {
|
|
|
|
this.$emit('change-uploadings', uploads);
|
|
|
|
},
|
|
|
|
|
|
|
|
onPollUpdate() {
|
|
|
|
const got = this.$refs.poll.get();
|
|
|
|
this.pollChoices = got.choices;
|
|
|
|
this.pollMultiple = got.multiple;
|
|
|
|
this.pollExpiration = [got.expiration, got.expiresAt || got.expiredAfter];
|
|
|
|
this.saveDraft();
|
|
|
|
},
|
|
|
|
|
|
|
|
setVisibility() {
|
|
|
|
const w = this.$root.new(MkVisibilityChooser, {
|
|
|
|
source: this.$refs.visibilityButton,
|
2020-01-29 21:37:25 +02:00
|
|
|
currentVisibility: this.visibility
|
2019-05-27 09:38:14 +03:00
|
|
|
});
|
|
|
|
w.$once('chosen', v => {
|
|
|
|
this.applyVisibility(v);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
applyVisibility(v: string) {
|
2020-02-08 13:02:15 +02:00
|
|
|
this.visibility = ['public', 'home', 'followers', 'specified'].includes(v) ? v : 'public'; // v11互換性のため
|
2019-05-27 09:38:14 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
addVisibleUser() {
|
2020-01-29 21:37:25 +02:00
|
|
|
const vm = this.$root.new(MkUserSelect, {});
|
|
|
|
vm.$once('selected', user => {
|
2019-05-27 09:38:14 +03:00
|
|
|
this.visibleUsers.push(user);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
removeVisibleUser(user) {
|
|
|
|
this.visibleUsers = erase(user, this.visibleUsers);
|
|
|
|
},
|
|
|
|
|
|
|
|
clear() {
|
|
|
|
this.text = '';
|
|
|
|
this.files = [];
|
|
|
|
this.poll = false;
|
2019-07-19 21:23:16 +03:00
|
|
|
this.quoteId = null;
|
2019-05-27 09:38:14 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
onKeydown(e) {
|
|
|
|
if ((e.which == 10 || e.which == 13) && (e.ctrlKey || e.metaKey) && this.canPost) this.post();
|
|
|
|
},
|
|
|
|
|
2019-07-08 07:46:31 +03:00
|
|
|
async onPaste(e: ClipboardEvent) {
|
|
|
|
for (const { item, i } of Array.from(e.clipboardData.items).map((item, i) => ({item, i}))) {
|
2019-05-27 09:38:14 +03:00
|
|
|
if (item.kind == 'file') {
|
2019-07-08 07:46:31 +03:00
|
|
|
const file = item.getAsFile();
|
|
|
|
const lio = file.name.lastIndexOf('.');
|
|
|
|
const ext = lio >= 0 ? file.name.slice(lio) : '';
|
|
|
|
const formatted = `${formatTimeString(new Date(file.lastModified), this.$store.state.settings.pastedFileName).replace(/{{number}}/g, `${i + 1}`)}${ext}`;
|
2020-01-29 21:37:25 +02:00
|
|
|
this.upload(file, formatted);
|
2019-05-27 09:38:14 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const paste = e.clipboardData.getData('text');
|
|
|
|
|
2019-07-19 21:23:16 +03:00
|
|
|
if (!this.renote && !this.quoteId && paste.startsWith(url + '/notes/')) {
|
2019-05-27 09:38:14 +03:00
|
|
|
e.preventDefault();
|
|
|
|
|
|
|
|
this.$root.dialog({
|
|
|
|
type: 'info',
|
2020-02-11 23:27:11 +02:00
|
|
|
text: this.$t('quoteQuestion'),
|
2019-05-27 09:38:14 +03:00
|
|
|
showCancelButton: true
|
|
|
|
}).then(({ canceled }) => {
|
|
|
|
if (canceled) {
|
|
|
|
insertTextAtCursor(this.$refs.text, paste);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.quoteId = paste.substr(url.length).match(/^\/notes\/(.+?)\/?$/)[1];
|
|
|
|
});
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
onDragover(e) {
|
2020-01-29 21:37:25 +02:00
|
|
|
if (!e.dataTransfer.items[0]) return;
|
2019-05-27 09:38:14 +03:00
|
|
|
const isFile = e.dataTransfer.items[0].kind == 'file';
|
|
|
|
const isDriveFile = e.dataTransfer.types[0] == 'mk_drive_file';
|
|
|
|
if (isFile || isDriveFile) {
|
|
|
|
e.preventDefault();
|
|
|
|
this.draghover = true;
|
|
|
|
e.dataTransfer.dropEffect = e.dataTransfer.effectAllowed == 'all' ? 'copy' : 'move';
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
onDragenter(e) {
|
|
|
|
this.draghover = true;
|
|
|
|
},
|
|
|
|
|
|
|
|
onDragleave(e) {
|
|
|
|
this.draghover = false;
|
|
|
|
},
|
|
|
|
|
|
|
|
onDrop(e): void {
|
|
|
|
this.draghover = false;
|
|
|
|
|
|
|
|
// ファイルだったら
|
|
|
|
if (e.dataTransfer.files.length > 0) {
|
|
|
|
e.preventDefault();
|
|
|
|
for (const x of Array.from(e.dataTransfer.files)) this.upload(x);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
//#region ドライブのファイル
|
|
|
|
const driveFile = e.dataTransfer.getData('mk_drive_file');
|
|
|
|
if (driveFile != null && driveFile != '') {
|
|
|
|
const file = JSON.parse(driveFile);
|
|
|
|
this.files.push(file);
|
|
|
|
e.preventDefault();
|
|
|
|
}
|
|
|
|
//#endregion
|
|
|
|
},
|
|
|
|
|
|
|
|
saveDraft() {
|
|
|
|
if (this.instant) return;
|
|
|
|
|
|
|
|
const data = JSON.parse(localStorage.getItem('drafts') || '{}');
|
|
|
|
|
|
|
|
data[this.draftId] = {
|
|
|
|
updatedAt: new Date(),
|
|
|
|
data: {
|
|
|
|
text: this.text,
|
2020-02-05 01:59:24 +02:00
|
|
|
useCw: this.useCw,
|
|
|
|
cw: this.cw,
|
2020-02-05 02:50:03 +02:00
|
|
|
visibility: this.visibility,
|
|
|
|
localOnly: this.localOnly,
|
2019-05-27 09:38:14 +03:00
|
|
|
files: this.files,
|
|
|
|
poll: this.poll && this.$refs.poll ? (this.$refs.poll as any).get() : undefined
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
localStorage.setItem('drafts', JSON.stringify(data));
|
|
|
|
},
|
|
|
|
|
|
|
|
deleteDraft() {
|
|
|
|
const data = JSON.parse(localStorage.getItem('drafts') || '{}');
|
|
|
|
|
|
|
|
delete data[this.draftId];
|
|
|
|
|
|
|
|
localStorage.setItem('drafts', JSON.stringify(data));
|
|
|
|
},
|
|
|
|
|
|
|
|
post() {
|
|
|
|
this.posting = true;
|
|
|
|
this.$root.api('notes/create', {
|
|
|
|
text: this.text == '' ? undefined : this.text,
|
|
|
|
fileIds: this.files.length > 0 ? this.files.map(f => f.id) : undefined,
|
|
|
|
replyId: this.reply ? this.reply.id : undefined,
|
|
|
|
renoteId: this.renote ? this.renote.id : this.quoteId ? this.quoteId : undefined,
|
|
|
|
poll: this.poll ? (this.$refs.poll as any).get() : undefined,
|
|
|
|
cw: this.useCw ? this.cw || '' : undefined,
|
2020-02-05 02:15:28 +02:00
|
|
|
localOnly: this.localOnly,
|
2019-05-27 09:38:14 +03:00
|
|
|
visibility: this.visibility,
|
|
|
|
visibleUserIds: this.visibility == 'specified' ? this.visibleUsers.map(u => u.id) : undefined,
|
2020-01-29 21:37:25 +02:00
|
|
|
viaMobile: this.$root.isMobile
|
2019-05-27 09:38:14 +03:00
|
|
|
}).then(data => {
|
|
|
|
this.clear();
|
|
|
|
this.deleteDraft();
|
|
|
|
this.$emit('posted');
|
|
|
|
}).catch(err => {
|
|
|
|
}).then(() => {
|
|
|
|
this.posting = false;
|
|
|
|
});
|
|
|
|
|
|
|
|
if (this.text && this.text != '') {
|
|
|
|
const hashtags = parse(this.text).filter(x => x.node.type === 'hashtag').map(x => x.node.props.hashtag);
|
|
|
|
const history = JSON.parse(localStorage.getItem('hashtags') || '[]') as string[];
|
|
|
|
localStorage.setItem('hashtags', JSON.stringify(unique(hashtags.concat(history))));
|
|
|
|
}
|
|
|
|
},
|
2020-01-29 21:37:25 +02:00
|
|
|
|
|
|
|
cancel() {
|
|
|
|
this.$emit('cancel');
|
|
|
|
},
|
|
|
|
|
|
|
|
insertMention() {
|
|
|
|
const vm = this.$root.new(MkUserSelect, {});
|
|
|
|
vm.$once('selected', user => {
|
|
|
|
insertTextAtCursor(this.$refs.text, getAcct(user) + ' ');
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2020-01-30 00:53:19 +02:00
|
|
|
async insertEmoji(ev) {
|
|
|
|
const vm = this.$root.new(await import('./emoji-picker.vue').then(m => m.default), {
|
2020-01-29 21:37:25 +02:00
|
|
|
source: ev.currentTarget || ev.target
|
|
|
|
}).$once('chosen', emoji => {
|
|
|
|
insertTextAtCursor(this.$refs.text, emoji);
|
|
|
|
vm.close();
|
|
|
|
});
|
|
|
|
}
|
2019-05-27 09:38:14 +03:00
|
|
|
}
|
|
|
|
});
|
2020-01-29 21:37:25 +02:00
|
|
|
</script>
|
|
|
|
|
|
|
|
<style lang="scss" scoped>
|
|
|
|
.gafaadew {
|
|
|
|
background: var(--panel);
|
|
|
|
border-radius: var(--radius);
|
|
|
|
box-shadow: 0 0 2px rgba(#000, 0.1);
|
|
|
|
|
|
|
|
> header {
|
|
|
|
z-index: 1000;
|
|
|
|
height: 66px;
|
|
|
|
|
|
|
|
@media (max-width: 500px) {
|
|
|
|
height: 50px;
|
|
|
|
}
|
|
|
|
|
|
|
|
> .cancel {
|
|
|
|
padding: 0;
|
|
|
|
font-size: 20px;
|
|
|
|
width: 64px;
|
|
|
|
line-height: 66px;
|
|
|
|
|
|
|
|
@media (max-width: 500px) {
|
|
|
|
width: 50px;
|
|
|
|
line-height: 50px;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
> div {
|
|
|
|
position: absolute;
|
|
|
|
top: 0;
|
|
|
|
right: 0;
|
|
|
|
|
|
|
|
> .text-count {
|
2020-02-11 19:55:35 +02:00
|
|
|
opacity: 0.7;
|
2020-01-29 21:37:25 +02:00
|
|
|
line-height: 66px;
|
|
|
|
|
|
|
|
@media (max-width: 500px) {
|
|
|
|
line-height: 50px;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-05 14:28:51 +02:00
|
|
|
> .visibility {
|
|
|
|
height: 34px;
|
|
|
|
width: 34px;
|
|
|
|
margin: 0 8px;
|
|
|
|
}
|
|
|
|
|
2020-01-29 21:37:25 +02:00
|
|
|
> .submit {
|
2020-02-05 14:28:51 +02:00
|
|
|
margin: 16px 16px 16px 0;
|
2020-02-08 10:49:54 +02:00
|
|
|
padding: 0 12px;
|
2020-01-29 21:37:25 +02:00
|
|
|
line-height: 34px;
|
2020-02-08 10:49:54 +02:00
|
|
|
font-weight: bold;
|
2020-01-29 21:37:25 +02:00
|
|
|
vertical-align: bottom;
|
|
|
|
border-radius: 4px;
|
|
|
|
|
|
|
|
@media (max-width: 500px) {
|
|
|
|
margin: 8px;
|
|
|
|
}
|
|
|
|
|
|
|
|
&:disabled {
|
|
|
|
opacity: 0.7;
|
|
|
|
}
|
2020-02-08 10:49:54 +02:00
|
|
|
|
|
|
|
> [data-icon] {
|
|
|
|
margin-left: 6px;
|
|
|
|
}
|
2020-01-29 21:37:25 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
> .form {
|
|
|
|
max-width: 500px;
|
|
|
|
margin: 0 auto;
|
|
|
|
|
|
|
|
> .preview {
|
|
|
|
padding: 16px;
|
|
|
|
}
|
|
|
|
|
|
|
|
> .with-quote {
|
|
|
|
margin: 0 0 8px 0;
|
|
|
|
color: var(--accent);
|
|
|
|
|
|
|
|
> button {
|
|
|
|
padding: 4px 8px;
|
|
|
|
color: var(--accentAlpha04);
|
|
|
|
|
|
|
|
&:hover {
|
|
|
|
color: var(--accentAlpha06);
|
|
|
|
}
|
|
|
|
|
|
|
|
&:active {
|
|
|
|
color: var(--accentDarken30);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
> .to-specified {
|
|
|
|
padding: 6px 24px;
|
|
|
|
margin-bottom: 8px;
|
|
|
|
overflow: auto;
|
|
|
|
white-space: nowrap;
|
|
|
|
|
|
|
|
@media (max-width: 500px) {
|
|
|
|
padding: 6px 16px;
|
|
|
|
}
|
|
|
|
|
|
|
|
> .visibleUsers {
|
|
|
|
display: inline;
|
|
|
|
top: -1px;
|
|
|
|
font-size: 14px;
|
|
|
|
|
|
|
|
> button {
|
|
|
|
padding: 4px;
|
|
|
|
border-radius: 8px;
|
|
|
|
}
|
|
|
|
|
|
|
|
> span {
|
|
|
|
margin-right: 14px;
|
|
|
|
padding: 8px 0 8px 8px;
|
|
|
|
border-radius: 8px;
|
|
|
|
background: var(--nwjktjjq);
|
|
|
|
|
|
|
|
> button {
|
|
|
|
padding: 4px 8px;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-05 01:59:24 +02:00
|
|
|
> .cw,
|
|
|
|
> .text {
|
2020-01-29 21:37:25 +02: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 12:59:28 +02:00
|
|
|
font-family: inherit;
|
2020-01-29 21:37:25 +02:00
|
|
|
|
|
|
|
@media (max-width: 500px) {
|
|
|
|
padding: 0 16px;
|
|
|
|
}
|
|
|
|
|
|
|
|
&:focus {
|
|
|
|
outline: none;
|
|
|
|
}
|
|
|
|
|
|
|
|
&:disabled {
|
|
|
|
opacity: 0.5;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-05 01:59:24 +02:00
|
|
|
> .cw {
|
|
|
|
z-index: 1;
|
|
|
|
padding-bottom: 8px;
|
|
|
|
border-bottom: solid 1px var(--divider);
|
|
|
|
}
|
|
|
|
|
|
|
|
> .text {
|
2020-01-29 21:37:25 +02:00
|
|
|
max-width: 100%;
|
|
|
|
min-width: 100%;
|
|
|
|
min-height: 90px;
|
|
|
|
|
|
|
|
@media (max-width: 500px) {
|
|
|
|
min-height: 80px;
|
|
|
|
}
|
2020-02-05 01:59:24 +02:00
|
|
|
|
|
|
|
&.withCw {
|
|
|
|
padding-top: 8px;
|
|
|
|
}
|
2020-01-29 21:37:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
> .mk-uploader {
|
|
|
|
margin: 8px 0 0 0;
|
|
|
|
padding: 8px;
|
|
|
|
}
|
|
|
|
|
|
|
|
> .file {
|
|
|
|
display: none;
|
|
|
|
}
|
|
|
|
|
|
|
|
> footer {
|
|
|
|
padding: 0 16px 16px 16px;
|
|
|
|
|
|
|
|
@media (max-width: 500px) {
|
|
|
|
padding: 0 8px 8px 8px;
|
|
|
|
}
|
|
|
|
|
2020-02-05 02:15:28 +02:00
|
|
|
> button {
|
2020-01-29 21:37:25 +02:00
|
|
|
display: inline-block;
|
|
|
|
padding: 0;
|
|
|
|
margin: 0;
|
|
|
|
font-size: 16px;
|
|
|
|
width: 48px;
|
|
|
|
height: 48px;
|
|
|
|
border-radius: 6px;
|
|
|
|
|
|
|
|
&:hover {
|
|
|
|
background: var(--geavgsxy);
|
|
|
|
}
|
2020-02-05 02:15:28 +02:00
|
|
|
|
|
|
|
&.active {
|
|
|
|
color: var(--accent);
|
|
|
|
}
|
2020-01-29 21:37:25 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</style>
|