get statuses in a conversation from the global repository instead of local state

This commit is contained in:
taehoon 2019-04-09 11:08:39 -04:00
parent 8c2efc5a5c
commit 724602bdc1

View file

@ -36,8 +36,7 @@ const conversation = {
data () { data () {
return { return {
highlight: null, highlight: null,
expanded: false, expanded: false
converationStatusIds: []
} }
}, },
props: [ props: [
@ -54,15 +53,6 @@ const conversation = {
status () { status () {
return this.statusoid return this.statusoid
}, },
idsToShow () {
if (this.converationStatusIds.length > 0) {
return this.converationStatusIds
} else if (this.statusId) {
return [this.statusId]
} else {
return []
}
},
statusId () { statusId () {
if (this.statusoid.retweeted_status) { if (this.statusoid.retweeted_status) {
return this.statusoid.retweeted_status.id return this.statusoid.retweeted_status.id
@ -70,6 +60,13 @@ const conversation = {
return this.statusoid.id return this.statusoid.id
} }
}, },
conversationId () {
if (this.statusoid.retweeted_status) {
return this.statusoid.retweeted_status.statusnet_conversation_id
} else {
return this.statusoid.statusnet_conversation_id
}
},
conversation () { conversation () {
if (!this.status) { if (!this.status) {
return [] return []
@ -79,11 +76,8 @@ const conversation = {
return [this.status] return [this.status]
} }
const statusesObject = this.$store.state.statuses.allStatusesObject const statuses = this.$store.state.statuses.allStatuses
const conversation = this.idsToShow.reduce((acc, id) => { const conversation = filter(statuses, { statusnet_conversation_id: this.conversationId })
acc.push(statusesObject[id])
return acc
}, [])
const statusIndex = findIndex(conversation, { id: this.statusId }) const statusIndex = findIndex(conversation, { id: this.statusId })
if (statusIndex !== -1) { if (statusIndex !== -1) {
@ -131,10 +125,6 @@ const conversation = {
.then(({ancestors, descendants}) => { .then(({ancestors, descendants}) => {
this.$store.dispatch('addNewStatuses', { statuses: ancestors }) this.$store.dispatch('addNewStatuses', { statuses: ancestors })
this.$store.dispatch('addNewStatuses', { statuses: descendants }) this.$store.dispatch('addNewStatuses', { statuses: descendants })
set(this, 'converationStatusIds', [].concat(
ancestors.map(_ => _.id).filter(_ => _ !== this.statusId),
this.statusId,
descendants.map(_ => _.id).filter(_ => _ !== this.statusId)))
}) })
.then(() => this.setHighlight(this.statusId)) .then(() => this.setHighlight(this.statusId))
} else { } else {