less hackery, more direct usage of mastoapi

This commit is contained in:
Henry Jameson 2019-03-21 23:45:18 +02:00
parent d6c62fa50f
commit 67719e9a23
2 changed files with 20 additions and 23 deletions

View File

@ -1,4 +1,5 @@
import { reduce, filter } from 'lodash' import { reduce, filter } from 'lodash'
import { set } from 'vue'
import Status from '../status/status.vue' import Status from '../status/status.vue'
const sortById = (a, b) => { const sortById = (a, b) => {
@ -97,9 +98,13 @@ const conversation = {
if (this.status) { if (this.status) {
const conversationId = this.status.id const conversationId = this.status.id
this.$store.state.api.backendInteractor.fetchConversation({id: conversationId}) this.$store.state.api.backendInteractor.fetchConversation({id: conversationId})
.then((statuses) => { .then(({ancestors, descendants}) => {
this.$store.dispatch('addNewStatuses', { statuses }) this.$store.dispatch('addNewStatuses', { statuses: ancestors })
statuses.forEach(status => this.relevantIds.push(status.id)) this.$store.dispatch('addNewStatuses', { statuses: descendants })
set(this, 'relevantIds', [].concat(
ancestors.map(_ => _.id),
this.statusId,
descendants.map(_ => _.id)))
}) })
.then(() => this.setHighlight(this.statusId)) .then(() => this.setHighlight(this.statusId))
} else { } else {

View File

@ -313,27 +313,19 @@ const fetchFollowRequests = ({credentials}) => {
} }
const fetchConversation = ({id, credentials}) => { const fetchConversation = ({id, credentials}) => {
let url = MASTODON_STATUS_URL(id)
let urlContext = MASTODON_STATUS_CONTEXT_URL(id) let urlContext = MASTODON_STATUS_CONTEXT_URL(id)
return Promise.all([ return fetch(urlContext, { headers: authHeaders(credentials) })
fetch(url, { headers: authHeaders(credentials) })
.then((data) => { .then((data) => {
if (data.ok) { if (data.ok) {
return data return data
} }
throw new Error('Error fetching timeline', data) throw new Error('Error fetching timeline', data)
}) })
.then((data) => data.json()), .then((data) => data.json())
fetch(urlContext, { headers: authHeaders(credentials) }) .then(({ancestors, descendants}) => ({
.then((data) => { ancestors: ancestors.map(parseStatus),
if (data.ok) { descendants: descendants.map(parseStatus)
return data }))
}
throw new Error('Error fetching timeline', data)
})
.then((data) => data.json())])
.then(([status, context]) => [...context.ancestors, status, ...context.descendants])
.then((data) => data.map(parseStatus))
} }
const fetchStatus = ({id, credentials}) => { const fetchStatus = ({id, credentials}) => {