user normalizer works
This commit is contained in:
parent
5a3c9cfc9b
commit
e0fd6d12ed
|
@ -44,7 +44,7 @@ const SUGGESTIONS_URL = '/api/v1/suggestions'
|
||||||
const MASTODON_USER_FAVORITES_TIMELINE_URL = '/api/v1/favourites'
|
const MASTODON_USER_FAVORITES_TIMELINE_URL = '/api/v1/favourites'
|
||||||
|
|
||||||
import { each, map } from 'lodash'
|
import { each, map } from 'lodash'
|
||||||
import { parseStatus } from '../status_normalizer/status_normalizer.service.js'
|
import { parseStatus, parseUser } from '../status_normalizer/status_normalizer.service.js'
|
||||||
import 'whatwg-fetch'
|
import 'whatwg-fetch'
|
||||||
|
|
||||||
const oldfetch = window.fetch
|
const oldfetch = window.fetch
|
||||||
|
@ -243,24 +243,28 @@ const fetchUser = ({id, credentials}) => {
|
||||||
let url = `${USER_URL}?user_id=${id}`
|
let url = `${USER_URL}?user_id=${id}`
|
||||||
return fetch(url, { headers: authHeaders(credentials) })
|
return fetch(url, { headers: authHeaders(credentials) })
|
||||||
.then((data) => data.json())
|
.then((data) => data.json())
|
||||||
|
.then((data) => parseUser(data))
|
||||||
}
|
}
|
||||||
|
|
||||||
const fetchFriends = ({id, credentials}) => {
|
const fetchFriends = ({id, credentials}) => {
|
||||||
let url = `${FRIENDS_URL}?user_id=${id}`
|
let url = `${FRIENDS_URL}?user_id=${id}`
|
||||||
return fetch(url, { headers: authHeaders(credentials) })
|
return fetch(url, { headers: authHeaders(credentials) })
|
||||||
.then((data) => data.json())
|
.then((data) => data.json())
|
||||||
|
.then((data) => data.map(parseUser))
|
||||||
}
|
}
|
||||||
|
|
||||||
const fetchFollowers = ({id, credentials}) => {
|
const fetchFollowers = ({id, credentials}) => {
|
||||||
let url = `${FOLLOWERS_URL}?user_id=${id}`
|
let url = `${FOLLOWERS_URL}?user_id=${id}`
|
||||||
return fetch(url, { headers: authHeaders(credentials) })
|
return fetch(url, { headers: authHeaders(credentials) })
|
||||||
.then((data) => data.json())
|
.then((data) => data.json())
|
||||||
|
.then((data) => data.map(parseUser))
|
||||||
}
|
}
|
||||||
|
|
||||||
const fetchAllFollowing = ({username, credentials}) => {
|
const fetchAllFollowing = ({username, credentials}) => {
|
||||||
const url = `${ALL_FOLLOWING_URL}/${username}.json`
|
const url = `${ALL_FOLLOWING_URL}/${username}.json`
|
||||||
return fetch(url, { headers: authHeaders(credentials) })
|
return fetch(url, { headers: authHeaders(credentials) })
|
||||||
.then((data) => data.json())
|
.then((data) => data.json())
|
||||||
|
.then((data) => data.map(parseUser))
|
||||||
}
|
}
|
||||||
|
|
||||||
const fetchFollowRequests = ({credentials}) => {
|
const fetchFollowRequests = ({credentials}) => {
|
||||||
|
@ -280,7 +284,7 @@ const fetchStatus = ({id, credentials}) => {
|
||||||
let url = `${STATUS_URL}/${id}.json`
|
let url = `${STATUS_URL}/${id}.json`
|
||||||
return fetch(url, { headers: authHeaders(credentials) })
|
return fetch(url, { headers: authHeaders(credentials) })
|
||||||
.then((data) => data.json())
|
.then((data) => data.json())
|
||||||
.then((data) => parseStatus(data))
|
.then((data) => data.map(parseStatus))
|
||||||
}
|
}
|
||||||
|
|
||||||
const setUserMute = ({id, credentials, muted = true}) => {
|
const setUserMute = ({id, credentials, muted = true}) => {
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
export const qvitterStatusType = (status) => {
|
const qvitterStatusType = (status) => {
|
||||||
if (status.is_post_verb) {
|
if (status.is_post_verb) {
|
||||||
return 'status'
|
return 'status'
|
||||||
}
|
}
|
||||||
|
@ -27,11 +27,71 @@ const isMastoAPI = (status) => {
|
||||||
return status.hasOwnProperty('account')
|
return status.hasOwnProperty('account')
|
||||||
}
|
}
|
||||||
|
|
||||||
const parseUser = (data) => {
|
export const parseUser = (data) => {
|
||||||
return {
|
const output = {}
|
||||||
id: data.id,
|
const masto = data.hasOwnProperty('acct')
|
||||||
screen_name: data.screen_name || data.acct
|
// case for users in "mentions" property for statuses in MastoAPI
|
||||||
|
const mastoShort = masto && !data.hasOwnProperty('avatar')
|
||||||
|
|
||||||
|
output.id = data.id
|
||||||
|
|
||||||
|
if (masto) {
|
||||||
|
output.screen_name = data.acct
|
||||||
|
|
||||||
|
// There's nothing else to get
|
||||||
|
if (mastoShort) {
|
||||||
|
return output
|
||||||
|
}
|
||||||
|
|
||||||
|
output.name = null // missing
|
||||||
|
output.name_html = data.display_name
|
||||||
|
|
||||||
|
output.description = null // missing
|
||||||
|
output.description_html = data.note
|
||||||
|
|
||||||
|
// Utilize avatar_static for gif avatars?
|
||||||
|
output.profile_image_url = data.avatar
|
||||||
|
output.profile_image_url_original = data.avatar
|
||||||
|
|
||||||
|
// Same, utilize header_static?
|
||||||
|
output.cover_photo = data.header
|
||||||
|
|
||||||
|
output.friends_count = data.following_count
|
||||||
|
|
||||||
|
output.bot = data.bot
|
||||||
|
|
||||||
|
output.statusnet_profile_url = data.url
|
||||||
|
|
||||||
|
// Missing, trying to recover
|
||||||
|
output.is_local = !output.screen_name.includes('@')
|
||||||
|
} else {
|
||||||
|
output.screen_name = data.screen_name
|
||||||
|
|
||||||
|
output.name = data.name
|
||||||
|
output.name_html = data.name_html
|
||||||
|
|
||||||
|
output.description = data.description
|
||||||
|
output.description_html = data.description_html
|
||||||
|
|
||||||
|
output.profile_image_url = data.profile_image_url
|
||||||
|
output.profile_image_url_original = data.profile_image_url_original
|
||||||
|
|
||||||
|
output.cover_photo = data.cover_photo
|
||||||
|
|
||||||
|
output.friends_count = data.friends_count
|
||||||
|
|
||||||
|
output.bot = null // missing
|
||||||
|
|
||||||
|
output.statusnet_profile_url = data.statusnet_profile_url
|
||||||
|
output.is_local = data.is_local
|
||||||
}
|
}
|
||||||
|
|
||||||
|
output.created_at = new Date(data.created_at)
|
||||||
|
output.locked = data.locked
|
||||||
|
output.followers_count = data.followers_count
|
||||||
|
output.statuses_count = data.statuses_count
|
||||||
|
|
||||||
|
return output
|
||||||
}
|
}
|
||||||
|
|
||||||
const parseAttachment = (data) => {
|
const parseAttachment = (data) => {
|
||||||
|
|
Loading…
Reference in New Issue