2016-10-31 00:53:58 +09:00
|
|
|
import statusPoster from '../../services/status_poster/status_poster.service.js'
|
2016-11-07 03:30:35 +09:00
|
|
|
import MediaUpload from '../media_upload/media_upload.vue'
|
2016-11-26 02:21:25 +09:00
|
|
|
import fileTypeService from '../../services/file_type/file_type.service.js'
|
2016-11-07 03:30:35 +09:00
|
|
|
|
2016-11-07 23:04:27 +09:00
|
|
|
import { reject, map, uniqBy } from 'lodash'
|
2016-11-04 01:17:32 +09: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}`
|
|
|
|
})
|
|
|
|
|
|
|
|
return mentions.join(' ') + ' '
|
|
|
|
}
|
2016-10-31 00:53:58 +09:00
|
|
|
|
|
|
|
const PostStatusForm = {
|
2016-11-04 00:59:27 +09:00
|
|
|
props: [
|
2016-11-04 01:17:32 +09:00
|
|
|
'replyTo',
|
|
|
|
'repliedUser',
|
2016-11-26 20:38:33 +09:00
|
|
|
'attentions'
|
2016-11-04 00:59:27 +09:00
|
|
|
],
|
2016-11-07 03:30:35 +09:00
|
|
|
components: {
|
|
|
|
MediaUpload
|
|
|
|
},
|
2016-11-04 00:59:27 +09:00
|
|
|
data () {
|
2016-11-04 01:17:32 +09:00
|
|
|
let statusText = ''
|
|
|
|
|
|
|
|
if (this.replyTo) {
|
|
|
|
const currentUser = this.$store.state.users.currentUser
|
|
|
|
statusText = buildMentionsString({ user: this.repliedUser, attentions: this.attentions }, currentUser)
|
|
|
|
}
|
|
|
|
|
2016-10-31 00:53:58 +09:00
|
|
|
return {
|
2016-11-26 20:38:33 +09:00
|
|
|
submitDisabled: false,
|
2016-11-04 01:17:32 +09:00
|
|
|
newStatus: {
|
2016-11-07 03:30:35 +09:00
|
|
|
status: statusText,
|
|
|
|
files: []
|
2016-11-04 01:17:32 +09:00
|
|
|
}
|
2016-10-31 00:53:58 +09:00
|
|
|
}
|
|
|
|
},
|
|
|
|
methods: {
|
2016-11-04 00:59:27 +09:00
|
|
|
postStatus (newStatus) {
|
2016-10-31 00:53:58 +09:00
|
|
|
statusPoster.postStatus({
|
|
|
|
status: newStatus.status,
|
2016-11-07 03:30:35 +09:00
|
|
|
media: newStatus.files,
|
2016-11-04 00:59:27 +09:00
|
|
|
store: this.$store,
|
|
|
|
inReplyToStatusId: this.replyTo
|
2016-10-31 00:53:58 +09:00
|
|
|
})
|
2016-11-07 03:30:35 +09:00
|
|
|
this.newStatus = {
|
|
|
|
status: '',
|
|
|
|
files: []
|
|
|
|
}
|
2016-11-04 01:35:49 +09:00
|
|
|
this.$emit('posted')
|
2016-11-07 03:30:35 +09:00
|
|
|
},
|
|
|
|
addMediaFile (fileInfo) {
|
|
|
|
this.newStatus.files.push(fileInfo)
|
2016-11-25 07:07:21 +09:00
|
|
|
this.enableSubmit()
|
|
|
|
},
|
2016-11-26 11:00:06 +09:00
|
|
|
removeMediaFile (fileInfo) {
|
|
|
|
let index = this.newStatus.files.indexOf(fileInfo)
|
|
|
|
this.newStatus.files.splice(index, 1)
|
|
|
|
},
|
2016-11-25 07:07:21 +09:00
|
|
|
disableSubmit () {
|
|
|
|
this.submitDisabled = true
|
|
|
|
},
|
|
|
|
enableSubmit () {
|
|
|
|
this.submitDisabled = false
|
2016-11-26 02:21:25 +09:00
|
|
|
},
|
|
|
|
type (fileInfo) {
|
|
|
|
return fileTypeService.fileType(fileInfo.mimetype)
|
2016-10-31 00:53:58 +09:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default PostStatusForm
|