Fetching convos via MastoAPI. Had to change conversation component a bit for

better support, since MastoAPI doesn't have coversation ids
This commit is contained in:
Henry Jameson 2019-03-09 18:33:49 +02:00
parent 09736691ea
commit 49b0f0a04a
2 changed files with 35 additions and 23 deletions

View file

@ -25,7 +25,8 @@ const sortAndFilterConversation = (conversation) => {
const conversation = { const conversation = {
data () { data () {
return { return {
highlight: null highlight: null,
relevantIds: []
} }
}, },
props: [ props: [
@ -48,9 +49,11 @@ const conversation = {
return [] return []
} }
const conversationId = this.status.statusnet_conversation_id const statusesObject = this.$store.state.statuses.allStatusesObject
const statuses = this.$store.state.statuses.allStatuses const conversation = this.relevantIds.reduce((acc, id) => {
const conversation = filter(statuses, { statusnet_conversation_id: conversationId }) acc.push(statusesObject[id])
return acc
}, [])
return sortAndFilterConversation(conversation) return sortAndFilterConversation(conversation)
}, },
replies () { replies () {
@ -83,15 +86,13 @@ const conversation = {
methods: { methods: {
fetchConversation () { fetchConversation () {
if (this.status) { if (this.status) {
const conversationId = this.status.statusnet_conversation_id const conversationId = this.status.id
this.$store.state.api.backendInteractor.fetchConversation({id: conversationId}) this.$store.state.api.backendInteractor.fetchConversation({id: conversationId})
.then((statuses) => this.$store.dispatch('addNewStatuses', { statuses })) .then((statuses) => {
this.$store.dispatch('addNewStatuses', { statuses })
statuses.forEach(status => this.relevantIds.push(status.id))
})
.then(() => this.setHighlight(this.statusId)) .then(() => this.setHighlight(this.statusId))
} else {
const id = this.$route.params.id
this.$store.state.api.backendInteractor.fetchStatus({id})
.then((status) => this.$store.dispatch('addNewStatuses', { statuses: [status] }))
.then(() => this.fetchConversation())
} }
}, },
getReplies (id) { getReplies (id) {

View file

@ -11,9 +11,7 @@ const RETWEET_URL = '/api/statuses/retweet'
const UNRETWEET_URL = '/api/statuses/unretweet' const UNRETWEET_URL = '/api/statuses/unretweet'
const STATUS_UPDATE_URL = '/api/statuses/update.json' const STATUS_UPDATE_URL = '/api/statuses/update.json'
const STATUS_DELETE_URL = '/api/statuses/destroy' const STATUS_DELETE_URL = '/api/statuses/destroy'
const STATUS_URL = '/api/statuses/show'
const MEDIA_UPLOAD_URL = '/api/statusnet/media/upload' const MEDIA_UPLOAD_URL = '/api/statusnet/media/upload'
const CONVERSATION_URL = '/api/statusnet/conversation'
const MENTIONS_URL = '/api/statuses/mentions.json' const MENTIONS_URL = '/api/statuses/mentions.json'
const DM_TIMELINE_URL = '/api/statuses/dm_timeline.json' const DM_TIMELINE_URL = '/api/statuses/dm_timeline.json'
const FOLLOWERS_URL = '/api/statuses/followers.json' const FOLLOWERS_URL = '/api/statuses/followers.json'
@ -43,6 +41,8 @@ const DENY_USER_URL = '/api/pleroma/friendships/deny'
const SUGGESTIONS_URL = '/api/v1/suggestions' const SUGGESTIONS_URL = '/api/v1/suggestions'
const MASTODON_USER_FAVORITES_TIMELINE_URL = '/api/v1/favourites' const MASTODON_USER_FAVORITES_TIMELINE_URL = '/api/v1/favourites'
const MASTODON_STATUS_URL = id => `/api/v1/statuses/${id}`
const MASTODON_STATUS_CONTEXT_URL = id => `/api/v1/statuses/${id}/context`
import { each, map } from 'lodash' import { each, map } from 'lodash'
import { parseStatus, parseUser, parseNotification } from '../entity_normalizer/entity_normalizer.service.js' import { parseStatus, parseUser, parseNotification } from '../entity_normalizer/entity_normalizer.service.js'
@ -298,20 +298,31 @@ const fetchFollowRequests = ({credentials}) => {
} }
const fetchConversation = ({id, credentials}) => { const fetchConversation = ({id, credentials}) => {
let url = `${CONVERSATION_URL}/${id}.json?count=100` let url = MASTODON_STATUS_URL(id)
return fetch(url, { headers: authHeaders(credentials) }) let urlContext = MASTODON_STATUS_CONTEXT_URL(id)
.then((data) => { return Promise.all([
if (data.ok) { fetch(url, { headers: authHeaders(credentials) })
return data .then((data) => {
} if (data.ok) {
throw new Error('Error fetching timeline', data) return data
}) }
.then((data) => data.json()) throw new Error('Error fetching timeline', data)
})
.then((data) => data.json()),
fetch(urlContext, { headers: authHeaders(credentials) })
.then((data) => {
if (data.ok) {
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)) .then((data) => data.map(parseStatus))
} }
const fetchStatus = ({id, credentials}) => { const fetchStatus = ({id, credentials}) => {
let url = `${STATUS_URL}/${id}.json` let url = MASTODON_STATUS_URL(id)
return fetch(url, { headers: authHeaders(credentials) }) return fetch(url, { headers: authHeaders(credentials) })
.then((data) => { .then((data) => {
if (data.ok) { if (data.ok) {