make relationships separate from users
This commit is contained in:
parent
d5457c323a
commit
6bb75a3a6d
25 changed files with 112 additions and 81 deletions
|
@ -496,7 +496,8 @@ const fetchTimeline = ({
|
|||
userId = false,
|
||||
tag = false,
|
||||
withMuted = false,
|
||||
withMove = false
|
||||
withMove = false,
|
||||
withRelationships = false
|
||||
}) => {
|
||||
const timelineUrls = {
|
||||
public: MASTODON_PUBLIC_TIMELINE,
|
||||
|
@ -542,6 +543,7 @@ const fetchTimeline = ({
|
|||
|
||||
params.push(['count', 20])
|
||||
params.push(['with_muted', withMuted])
|
||||
params.push(['with_relationships', withRelationships])
|
||||
|
||||
const queryString = map(params, (param) => `${param[0]}=${param[1]}`).join('&')
|
||||
url += `?${queryString}`
|
||||
|
|
|
@ -73,7 +73,7 @@ export const parseUser = (data) => {
|
|||
output.background_image = data.pleroma.background_image
|
||||
output.token = data.pleroma.chat_token
|
||||
|
||||
if (relationship) {
|
||||
if (relationship && !relationship) {
|
||||
output.follows_you = relationship.followed_by
|
||||
output.requested = relationship.requested
|
||||
output.following = relationship.following
|
||||
|
@ -82,6 +82,9 @@ export const parseUser = (data) => {
|
|||
output.showing_reblogs = relationship.showing_reblogs
|
||||
output.subscribed = relationship.subscribing
|
||||
}
|
||||
if (relationship) {
|
||||
output.relationship = relationship
|
||||
}
|
||||
|
||||
output.allow_following_move = data.pleroma.allow_following_move
|
||||
|
||||
|
@ -137,16 +140,10 @@ export const parseUser = (data) => {
|
|||
|
||||
output.statusnet_profile_url = data.statusnet_profile_url
|
||||
|
||||
output.statusnet_blocking = data.statusnet_blocking
|
||||
|
||||
output.is_local = data.is_local
|
||||
output.role = data.role
|
||||
output.show_role = data.show_role
|
||||
|
||||
output.follows_you = data.follows_you
|
||||
|
||||
output.muted = data.muted
|
||||
|
||||
if (data.rights) {
|
||||
output.rights = {
|
||||
moderator: data.rights.delete_others_notice,
|
||||
|
@ -160,10 +157,16 @@ export const parseUser = (data) => {
|
|||
output.hide_follows_count = data.hide_follows_count
|
||||
output.hide_followers_count = data.hide_followers_count
|
||||
output.background_image = data.background_image
|
||||
// on mastoapi this info is contained in a "relationship"
|
||||
output.following = data.following
|
||||
// Websocket token
|
||||
output.token = data.token
|
||||
|
||||
// Convert relationsip data to expected format
|
||||
output.relationship = {
|
||||
muting: data.muted,
|
||||
blocking: data.statusnet_blocking,
|
||||
followed_by: data.follows_you,
|
||||
following: data.following
|
||||
}
|
||||
}
|
||||
|
||||
output.created_at = new Date(data.created_at)
|
||||
|
@ -317,6 +320,9 @@ export const parseStatus = (data) => {
|
|||
? String(output.in_reply_to_user_id)
|
||||
: null
|
||||
|
||||
if (data.account.pleroma.relationship) {
|
||||
data.account.pleroma.relationship = undefined
|
||||
}
|
||||
output.user = parseUser(masto ? data.account : data.user)
|
||||
|
||||
output.attentions = ((masto ? data.mentions : data.attentions) || []).map(parseUser)
|
||||
|
@ -342,7 +348,6 @@ export const parseNotification = (data) => {
|
|||
}
|
||||
const masto = !data.hasOwnProperty('ntype')
|
||||
const output = {}
|
||||
|
||||
if (masto) {
|
||||
output.type = mastoDict[data.type] || data.type
|
||||
output.seen = data.pleroma.is_seen
|
||||
|
|
|
@ -1,15 +1,18 @@
|
|||
const fetchUser = (attempt, user, store) => new Promise((resolve, reject) => {
|
||||
const fetchRelationship = (attempt, user, store) => new Promise((resolve, reject) => {
|
||||
setTimeout(() => {
|
||||
store.state.api.backendInteractor.fetchUser({ id: user.id })
|
||||
.then((user) => store.commit('addNewUsers', [user]))
|
||||
.then(() => resolve([user.following, user.requested, user.locked, attempt]))
|
||||
store.state.api.backendInteractor.fetchUserRelationship({ id: user.id })
|
||||
.then((relationship) => {
|
||||
store.commit('updateUserRelationship', [relationship])
|
||||
return relationship
|
||||
})
|
||||
.then((relationship) => resolve([relationship.following, relationship.requested, user.locked, attempt]))
|
||||
.catch((e) => reject(e))
|
||||
}, 500)
|
||||
}).then(([following, sent, locked, attempt]) => {
|
||||
if (!following && !(locked && sent) && attempt <= 3) {
|
||||
// If we BE reports that we still not following that user - retry,
|
||||
// increment attempts by one
|
||||
fetchUser(++attempt, user, store)
|
||||
fetchRelationship(++attempt, user, store)
|
||||
}
|
||||
})
|
||||
|
||||
|
@ -31,7 +34,7 @@ export const requestFollow = (user, store) => new Promise((resolve, reject) => {
|
|||
// don't know that yet.
|
||||
// Recursive Promise, it will call itself up to 3 times.
|
||||
|
||||
return fetchUser(1, user, store)
|
||||
return fetchRelationship(1, user, store)
|
||||
.then(() => {
|
||||
resolve()
|
||||
})
|
||||
|
|
|
@ -48,7 +48,6 @@ const fetchNotifications = ({ store, args, older }) => {
|
|||
update({ store, notifications, older })
|
||||
return notifications
|
||||
}, () => store.dispatch('setNotificationsError', { value: true }))
|
||||
.catch(() => store.dispatch('setNotificationsError', { value: true }))
|
||||
}
|
||||
|
||||
const startFetching = ({ credentials, store }) => {
|
||||
|
|
|
@ -31,6 +31,7 @@ const fetchAndUpdate = ({
|
|||
const { getters } = store
|
||||
const timelineData = rootState.statuses.timelines[camelCase(timeline)]
|
||||
const hideMutedPosts = getters.mergedConfig.hideMutedPosts
|
||||
const replyVisibility = getters.mergedConfig.replyVisibility
|
||||
|
||||
if (older) {
|
||||
args['until'] = until || timelineData.minId
|
||||
|
@ -41,6 +42,7 @@ const fetchAndUpdate = ({
|
|||
args['userId'] = userId
|
||||
args['tag'] = tag
|
||||
args['withMuted'] = !hideMutedPosts
|
||||
args['withRelationships'] = replyVisibility === 'following'
|
||||
|
||||
const numStatusesBeforeFetch = timelineData.statuses.length
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue