akkoma-fe/src/components/post_status_form/post_status_form.js

54 lines
1.2 KiB
JavaScript
Raw Normal View History

2016-10-30 15:53:58 +00:00
import statusPoster from '../../services/status_poster/status_poster.service.js'
2016-11-03 16:17:32 +00:00
import { reject, map, uniqBy } from 'lodash';
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-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',
'attentions'
2016-11-03 15:59:27 +00:00
],
data () {
2016-11-03 16:17:32 +00:00
let statusText = ''
if (this.replyTo) {
const currentUser = this.$store.state.users.currentUser
statusText = buildMentionsString({ user: this.repliedUser, attentions: this.attentions }, currentUser)
}
2016-10-30 15:53:58 +00:00
return {
2016-11-03 16:17:32 +00:00
newStatus: {
status: statusText
}
2016-10-30 15:53:58 +00:00
}
},
methods: {
2016-11-03 15:59:27 +00:00
postStatus (newStatus) {
2016-10-30 15:53:58 +00:00
statusPoster.postStatus({
status: newStatus.status,
2016-11-03 15:59:27 +00:00
store: this.$store,
inReplyToStatusId: this.replyTo
2016-10-30 15:53:58 +00:00
})
this.newStatus = { }
2016-11-03 16:35:49 +00:00
this.$emit('posted')
2016-10-30 15:53:58 +00:00
}
}
}
export default PostStatusForm