2016-10-30 15:53:58 +00:00
|
|
|
import statusPoster from '../../services/status_poster/status_poster.service.js'
|
2016-11-06 18:30:35 +00:00
|
|
|
import MediaUpload from '../media_upload/media_upload.vue'
|
2019-03-03 13:15:41 +00:00
|
|
|
import ScopeSelector from '../scope_selector/scope_selector.vue'
|
2019-03-26 02:38:15 +00:00
|
|
|
import EmojiInput from '../emoji-input/emoji-input.vue'
|
2016-11-25 17:21:25 +00:00
|
|
|
import fileTypeService from '../../services/file_type/file_type.service.js'
|
2019-02-14 19:15:59 +00:00
|
|
|
import Completion from '../../services/completion/completion.js'
|
|
|
|
import { take, filter, reject, map, uniqBy } from 'lodash'
|
2019-06-06 21:17:49 +00:00
|
|
|
import suggestor from '../emoji-input/suggestor.js'
|
2016-11-03 16:17:32 +00:00
|
|
|
|
|
|
|
const buildMentionsString = ({user, attentions}, currentUser) => {
|
|
|
|
let allAttentions = [...attentions]
|
|
|
|
|
|
|
|
allAttentions.unshift(user)
|
|
|
|
|
|
|
|
allAttentions = uniqBy(allAttentions, 'id')
|
|
|
|
allAttentions = reject(allAttentions, {id: currentUser.id})
|
|
|
|
|
|
|
|
let mentions = map(allAttentions, (attention) => {
|
|
|
|
return `@${attention.screen_name}`
|
|
|
|
})
|
|
|
|
|
2019-01-31 00:50:19 +00:00
|
|
|
return mentions.length > 0 ? mentions.join(' ') + ' ' : ''
|
2016-11-03 16:17:32 +00:00
|
|
|
}
|
2016-10-30 15:53:58 +00:00
|
|
|
|
|
|
|
const PostStatusForm = {
|
2016-11-03 15:59:27 +00:00
|
|
|
props: [
|
2016-11-03 16:17:32 +00:00
|
|
|
'replyTo',
|
|
|
|
'repliedUser',
|
2018-06-12 17:28:48 +00:00
|
|
|
'attentions',
|
2018-09-25 12:16:26 +00:00
|
|
|
'copyMessageScope',
|
2018-08-26 00:50:11 +00:00
|
|
|
'subject'
|
2016-11-03 15:59:27 +00:00
|
|
|
],
|
2016-11-06 18:30:35 +00:00
|
|
|
components: {
|
2019-03-03 13:15:41 +00:00
|
|
|
MediaUpload,
|
2019-03-30 10:31:50 +00:00
|
|
|
ScopeSelector,
|
2019-03-26 02:38:15 +00:00
|
|
|
EmojiInput
|
2016-11-06 18:30:35 +00:00
|
|
|
},
|
2018-04-15 16:05:16 +00:00
|
|
|
mounted () {
|
2019-02-14 19:15:59 +00:00
|
|
|
this.resize(this.$refs.textarea)
|
|
|
|
const textLength = this.$refs.textarea.value.length
|
|
|
|
this.$refs.textarea.setSelectionRange(textLength, textLength)
|
|
|
|
|
2018-08-05 19:17:11 +00:00
|
|
|
if (this.replyTo) {
|
|
|
|
this.$refs.textarea.focus()
|
|
|
|
}
|
2018-04-15 16:05:16 +00:00
|
|
|
},
|
2016-11-03 15:59:27 +00:00
|
|
|
data () {
|
2018-04-29 14:44:08 +00:00
|
|
|
const preset = this.$route.query.message
|
|
|
|
let statusText = preset || ''
|
2016-11-03 16:17:32 +00:00
|
|
|
|
2018-12-18 20:31:10 +00:00
|
|
|
const scopeCopy = typeof this.$store.state.config.scopeCopy === 'undefined'
|
|
|
|
? this.$store.state.instance.scopeCopy
|
|
|
|
: this.$store.state.config.scopeCopy
|
|
|
|
|
2016-11-03 16:17:32 +00:00
|
|
|
if (this.replyTo) {
|
|
|
|
const currentUser = this.$store.state.users.currentUser
|
|
|
|
statusText = buildMentionsString({ user: this.repliedUser, attentions: this.attentions }, currentUser)
|
|
|
|
}
|
|
|
|
|
2018-12-18 20:31:10 +00:00
|
|
|
const scope = (this.copyMessageScope && scopeCopy || this.copyMessageScope === 'direct')
|
2018-09-25 12:16:26 +00:00
|
|
|
? this.copyMessageScope
|
|
|
|
: this.$store.state.users.currentUser.default_scope
|
|
|
|
|
2019-02-21 16:16:11 +00:00
|
|
|
const contentType = typeof this.$store.state.config.postContentType === 'undefined'
|
|
|
|
? this.$store.state.instance.postContentType
|
|
|
|
: this.$store.state.config.postContentType
|
|
|
|
|
2016-10-30 15:53:58 +00:00
|
|
|
return {
|
2017-02-21 13:13:19 +00:00
|
|
|
dropFiles: [],
|
2016-11-26 11:38:33 +00:00
|
|
|
submitDisabled: false,
|
2017-08-20 10:16:41 +00:00
|
|
|
error: null,
|
2017-08-21 12:35:14 +00:00
|
|
|
posting: false,
|
2019-02-14 19:15:59 +00:00
|
|
|
highlighted: 0,
|
2016-11-03 16:17:32 +00:00
|
|
|
newStatus: {
|
2018-11-07 16:20:33 +00:00
|
|
|
spoilerText: this.subject || '',
|
2016-11-06 18:30:35 +00:00
|
|
|
status: statusText,
|
2018-08-25 21:18:43 +00:00
|
|
|
nsfw: false,
|
2018-06-08 13:25:48 +00:00
|
|
|
files: [],
|
2019-02-21 16:16:11 +00:00
|
|
|
visibility: scope,
|
|
|
|
contentType
|
2019-02-14 19:15:59 +00:00
|
|
|
},
|
|
|
|
caret: 0
|
2016-10-30 15:53:58 +00:00
|
|
|
}
|
|
|
|
},
|
2016-11-30 12:39:17 +00:00
|
|
|
computed: {
|
2019-02-14 19:15:59 +00:00
|
|
|
users () {
|
|
|
|
return this.$store.state.users.users
|
|
|
|
},
|
2019-03-03 13:15:41 +00:00
|
|
|
userDefaultScope () {
|
|
|
|
return this.$store.state.users.currentUser.default_scope
|
|
|
|
},
|
|
|
|
showAllScopes () {
|
|
|
|
const minimalScopesMode = typeof this.$store.state.config.minimalScopesMode === 'undefined'
|
|
|
|
? this.$store.state.instance.minimalScopesMode
|
|
|
|
: this.$store.state.config.minimalScopesMode
|
|
|
|
return !minimalScopesMode
|
|
|
|
},
|
2019-06-06 21:17:49 +00:00
|
|
|
emojiUserSuggestor () {
|
|
|
|
return suggestor({
|
|
|
|
emoji: [
|
|
|
|
...this.$store.state.instance.emoji,
|
|
|
|
...this.$store.state.instance.customEmoji
|
|
|
|
],
|
|
|
|
users: this.$store.state.users.users
|
|
|
|
})
|
|
|
|
},
|
|
|
|
emojiSuggestor () {
|
2019-06-09 17:40:46 +00:00
|
|
|
return suggestor({ emoji: [
|
2019-06-06 21:17:49 +00:00
|
|
|
...this.$store.state.instance.emoji,
|
|
|
|
...this.$store.state.instance.customEmoji
|
|
|
|
]})
|
|
|
|
},
|
2019-02-14 19:15:59 +00:00
|
|
|
emoji () {
|
|
|
|
return this.$store.state.instance.emoji || []
|
|
|
|
},
|
|
|
|
customEmoji () {
|
|
|
|
return this.$store.state.instance.customEmoji || []
|
|
|
|
},
|
2018-02-09 14:51:04 +00:00
|
|
|
statusLength () {
|
|
|
|
return this.newStatus.status.length
|
|
|
|
},
|
2018-11-07 16:20:33 +00:00
|
|
|
spoilerTextLength () {
|
|
|
|
return this.newStatus.spoilerText.length
|
|
|
|
},
|
2018-02-09 14:51:04 +00:00
|
|
|
statusLengthLimit () {
|
2018-09-09 19:31:34 +00:00
|
|
|
return this.$store.state.instance.textlimit
|
2018-02-09 14:51:04 +00:00
|
|
|
},
|
|
|
|
hasStatusLengthLimit () {
|
|
|
|
return this.statusLengthLimit > 0
|
|
|
|
},
|
|
|
|
charactersLeft () {
|
2018-11-07 16:20:33 +00:00
|
|
|
return this.statusLengthLimit - (this.statusLength + this.spoilerTextLength)
|
2018-02-11 14:07:29 +00:00
|
|
|
},
|
|
|
|
isOverLengthLimit () {
|
2018-11-07 16:20:33 +00:00
|
|
|
return this.hasStatusLengthLimit && (this.charactersLeft < 0)
|
2018-06-08 13:25:48 +00:00
|
|
|
},
|
2019-03-30 10:41:42 +00:00
|
|
|
minimalScopesMode () {
|
|
|
|
return this.$store.state.instance.minimalScopesMode
|
2018-08-31 14:00:41 +00:00
|
|
|
},
|
2018-12-03 03:47:35 +00:00
|
|
|
alwaysShowSubject () {
|
|
|
|
if (typeof this.$store.state.config.alwaysShowSubjectInput !== 'undefined') {
|
|
|
|
return this.$store.state.config.alwaysShowSubjectInput
|
|
|
|
} else if (typeof this.$store.state.instance.alwaysShowSubjectInput !== 'undefined') {
|
|
|
|
return this.$store.state.instance.alwaysShowSubjectInput
|
|
|
|
} else {
|
2019-03-03 13:15:41 +00:00
|
|
|
return true
|
2018-12-03 03:47:35 +00:00
|
|
|
}
|
|
|
|
},
|
2018-08-31 14:00:41 +00:00
|
|
|
formattingOptionsEnabled () {
|
2018-09-09 18:21:23 +00:00
|
|
|
return this.$store.state.instance.formattingOptionsEnabled
|
2019-03-07 04:13:04 +00:00
|
|
|
},
|
|
|
|
postFormats () {
|
|
|
|
return this.$store.state.instance.postFormats || []
|
2019-04-02 14:26:14 +00:00
|
|
|
},
|
2019-04-02 15:19:45 +00:00
|
|
|
safeDMEnabled () {
|
|
|
|
return this.$store.state.instance.safeDM
|
2019-05-07 16:13:45 +00:00
|
|
|
},
|
|
|
|
hideScopeNotice () {
|
|
|
|
return this.$store.state.config.hideScopeNotice
|
2016-11-30 12:39:17 +00:00
|
|
|
}
|
|
|
|
},
|
2016-10-30 15:53:58 +00:00
|
|
|
methods: {
|
2016-11-03 15:59:27 +00:00
|
|
|
postStatus (newStatus) {
|
2017-08-22 08:43:03 +00:00
|
|
|
if (this.posting) { return }
|
2018-01-31 17:48:09 +00:00
|
|
|
if (this.submitDisabled) { return }
|
2017-08-24 13:16:06 +00:00
|
|
|
|
|
|
|
if (this.newStatus.status === '') {
|
|
|
|
if (this.newStatus.files.length > 0) {
|
|
|
|
this.newStatus.status = '\u200b' // hack
|
|
|
|
} else {
|
|
|
|
this.error = 'Cannot post an empty status with no files'
|
2017-08-24 13:25:26 +00:00
|
|
|
return
|
2017-08-24 13:16:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-21 12:35:14 +00:00
|
|
|
this.posting = true
|
2016-10-30 15:53:58 +00:00
|
|
|
statusPoster.postStatus({
|
|
|
|
status: newStatus.status,
|
2018-06-07 21:31:43 +00:00
|
|
|
spoilerText: newStatus.spoilerText || null,
|
2018-06-07 09:03:50 +00:00
|
|
|
visibility: newStatus.visibility,
|
2018-08-25 21:18:43 +00:00
|
|
|
sensitive: newStatus.nsfw,
|
2016-11-06 18:30:35 +00:00
|
|
|
media: newStatus.files,
|
2016-11-03 15:59:27 +00:00
|
|
|
store: this.$store,
|
2018-08-31 00:42:42 +00:00
|
|
|
inReplyToStatusId: this.replyTo,
|
|
|
|
contentType: newStatus.contentType
|
2017-08-20 10:16:41 +00:00
|
|
|
}).then((data) => {
|
|
|
|
if (!data.error) {
|
|
|
|
this.newStatus = {
|
|
|
|
status: '',
|
2018-11-08 18:34:59 +00:00
|
|
|
spoilerText: '',
|
2018-06-08 13:25:48 +00:00
|
|
|
files: [],
|
2018-08-31 00:42:42 +00:00
|
|
|
visibility: newStatus.visibility,
|
|
|
|
contentType: newStatus.contentType
|
2017-08-20 10:16:41 +00:00
|
|
|
}
|
2019-02-04 15:45:26 +00:00
|
|
|
this.$refs.mediaUpload.clearFile()
|
2017-08-20 10:16:41 +00:00
|
|
|
this.$emit('posted')
|
|
|
|
let el = this.$el.querySelector('textarea')
|
2018-12-25 01:24:49 +00:00
|
|
|
el.style.height = 'auto'
|
2018-12-18 22:11:57 +00:00
|
|
|
el.style.height = undefined
|
2017-08-20 10:16:41 +00:00
|
|
|
this.error = null
|
|
|
|
} else {
|
|
|
|
this.error = data.error
|
|
|
|
}
|
2017-08-21 12:35:14 +00:00
|
|
|
this.posting = false
|
2016-10-30 15:53:58 +00:00
|
|
|
})
|
2016-11-06 18:30:35 +00:00
|
|
|
},
|
|
|
|
addMediaFile (fileInfo) {
|
|
|
|
this.newStatus.files.push(fileInfo)
|
2016-11-24 22:07:21 +00:00
|
|
|
this.enableSubmit()
|
|
|
|
},
|
2016-11-26 02:00:06 +00:00
|
|
|
removeMediaFile (fileInfo) {
|
|
|
|
let index = this.newStatus.files.indexOf(fileInfo)
|
|
|
|
this.newStatus.files.splice(index, 1)
|
|
|
|
},
|
2018-12-08 21:36:54 +00:00
|
|
|
uploadFailed (errString, templateArgs) {
|
2018-12-08 21:39:58 +00:00
|
|
|
templateArgs = templateArgs || {}
|
2018-12-12 13:38:01 +00:00
|
|
|
this.error = this.$t('upload.error.base') + ' ' + this.$t('upload.error.' + errString, templateArgs)
|
2018-12-08 15:23:21 +00:00
|
|
|
this.enableSubmit()
|
|
|
|
},
|
2016-11-24 22:07:21 +00:00
|
|
|
disableSubmit () {
|
|
|
|
this.submitDisabled = true
|
|
|
|
},
|
|
|
|
enableSubmit () {
|
|
|
|
this.submitDisabled = false
|
2016-11-25 17:21:25 +00:00
|
|
|
},
|
|
|
|
type (fileInfo) {
|
|
|
|
return fileTypeService.fileType(fileInfo.mimetype)
|
2017-02-21 13:13:19 +00:00
|
|
|
},
|
2017-11-28 20:31:40 +00:00
|
|
|
paste (e) {
|
|
|
|
if (e.clipboardData.files.length > 0) {
|
2019-03-24 03:45:24 +00:00
|
|
|
// prevent pasting of file as text
|
|
|
|
e.preventDefault()
|
2017-11-28 20:31:40 +00:00
|
|
|
// Strangely, files property gets emptied after event propagation
|
|
|
|
// Trying to wrap it in array doesn't work. Plus I doubt it's possible
|
|
|
|
// to hold more than one file in clipboard.
|
|
|
|
this.dropFiles = [e.clipboardData.files[0]]
|
|
|
|
}
|
|
|
|
},
|
2017-02-21 13:13:19 +00:00
|
|
|
fileDrop (e) {
|
2017-02-21 20:48:48 +00:00
|
|
|
if (e.dataTransfer.files.length > 0) {
|
2017-02-21 13:13:19 +00:00
|
|
|
e.preventDefault() // allow dropping text like before
|
|
|
|
this.dropFiles = e.dataTransfer.files
|
|
|
|
}
|
2017-02-22 12:53:05 +00:00
|
|
|
},
|
|
|
|
fileDrag (e) {
|
2017-02-22 21:33:28 +00:00
|
|
|
e.dataTransfer.dropEffect = 'copy'
|
2017-05-31 11:02:54 +00:00
|
|
|
},
|
2019-02-14 19:15:59 +00:00
|
|
|
resize (e) {
|
|
|
|
const target = e.target || e
|
|
|
|
if (!(target instanceof window.Element)) { return }
|
|
|
|
const vertPadding = Number(window.getComputedStyle(target)['padding-top'].substr(0, 1)) +
|
|
|
|
Number(window.getComputedStyle(target)['padding-bottom'].substr(0, 1))
|
|
|
|
// Auto is needed to make textbox shrink when removing lines
|
|
|
|
target.style.height = 'auto'
|
|
|
|
target.style.height = `${target.scrollHeight - vertPadding}px`
|
|
|
|
if (target.value === '') {
|
|
|
|
target.style.height = null
|
|
|
|
}
|
|
|
|
},
|
2017-08-24 13:16:06 +00:00
|
|
|
clearError () {
|
|
|
|
this.error = null
|
2018-06-07 09:03:50 +00:00
|
|
|
},
|
|
|
|
changeVis (visibility) {
|
|
|
|
this.newStatus.visibility = visibility
|
2019-05-07 16:13:45 +00:00
|
|
|
},
|
|
|
|
dismissScopeNotice () {
|
|
|
|
this.$store.dispatch('setOption', { name: 'hideScopeNotice', value: true })
|
2016-10-30 15:53:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default PostStatusForm
|