From 2ec7069b3c4ac30c3e0f6ca85615700ee31d9cf1 Mon Sep 17 00:00:00 2001 From: Roger Braun Date: Fri, 12 May 2017 18:54:12 +0200 Subject: Add user finder. --- src/services/api/api.service.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'src/services/api/api.service.js') diff --git a/src/services/api/api.service.js b/src/services/api/api.service.js index 4dfc0a02..1c5e281e 100644 --- a/src/services/api/api.service.js +++ b/src/services/api/api.service.js @@ -17,6 +17,7 @@ const FRIENDS_URL = '/api/statuses/friends.json' const FOLLOWING_URL = '/api/friendships/create.json' const UNFOLLOWING_URL = '/api/friendships/destroy.json' const QVITTER_USER_PREF_URL = '/api/qvitter/set_profile_pref.json' +const EXTERNAL_PROFILE_URL = '/api/externalprofile/show.json' // const USER_URL = '/api/users/show.json' const oldfetch = window.fetch @@ -35,6 +36,13 @@ const authHeaders = (user) => { } } +const externalProfile = (profileUrl) => { + let url = `${EXTERNAL_PROFILE_URL}?profileurl=${profileUrl}` + return fetch(url, { + method: 'GET' + }).then((data) => data.json()) +} + const followUser = ({id, credentials}) => { let url = `${FOLLOWING_URL}?user_id=${id}` return fetch(url, { @@ -198,7 +206,8 @@ const apiService = { uploadMedia, fetchAllFollowing, setUserMute, - fetchMutes + fetchMutes, + externalProfile } export default apiService -- cgit v1.2.3-70-g09d2 From 090148ef6051ec2399fe47281db9f73955297d97 Mon Sep 17 00:00:00 2001 From: Roger Braun Date: Mon, 12 Jun 2017 16:00:46 +0200 Subject: Start fetching user timelines. --- src/components/user_profile/user_profile.js | 14 ++++++++++---- src/components/user_profile/user_profile.vue | 2 +- src/modules/api.js | 11 ++++++++++- src/modules/statuses.js | 11 +++++++++++ src/services/api/api.service.js | 19 +++++++++++++++---- .../backend_interactor_service.js | 4 ++-- .../timeline_fetcher/timeline_fetcher.service.js | 10 ++++++---- 7 files changed, 55 insertions(+), 16 deletions(-) (limited to 'src/services/api/api.service.js') diff --git a/src/components/user_profile/user_profile.js b/src/components/user_profile/user_profile.js index 4d52bc95..4f35cf27 100644 --- a/src/components/user_profile/user_profile.js +++ b/src/components/user_profile/user_profile.js @@ -1,12 +1,18 @@ import UserCardContent from '../user_card_content/user_card_content.vue' -import { find } from 'lodash' const UserProfile = { + created () { + this.$store.dispatch('startFetching', ['user', this.userId]) + }, + destroyed () { + this.$store.dispatch('stopFetching', ['user', this.userId]) + }, computed: { + userId () { + return this.$route.params.id + }, user () { - const id = this.$route.params.id - const user = find(this.$store.state.users.users, {id}) - return user + return this.$store.state.users.usersObject[this.userId] } }, components: { diff --git a/src/components/user_profile/user_profile.vue b/src/components/user_profile/user_profile.vue index 11a61bfc..fe693c9d 100644 --- a/src/components/user_profile/user_profile.vue +++ b/src/components/user_profile/user_profile.vue @@ -1,5 +1,5 @@ diff --git a/src/modules/api.js b/src/modules/api.js index a32adfde..e61382eb 100644 --- a/src/modules/api.js +++ b/src/modules/api.js @@ -1,4 +1,5 @@ import backendInteractorService from '../services/backend_interactor_service/backend_interactor_service.js' +import {isArray} from 'lodash' const api = { state: { @@ -18,9 +19,17 @@ const api = { }, actions: { startFetching (store, timeline) { + let userId = false + + // This is for user timelines + if (isArray(timeline)) { + userId = timeline[1] + timeline = timeline[0] + } + // Don't start fetching if we already are. if (!store.state.fetchers[timeline]) { - const fetcher = store.state.backendInteractor.startFetching({timeline, store}) + const fetcher = store.state.backendInteractor.startFetching({timeline, store, userId}) store.commit('addFetcher', {timeline, fetcher}) } }, diff --git a/src/modules/statuses.js b/src/modules/statuses.js index 2546a2de..372567c5 100644 --- a/src/modules/statuses.js +++ b/src/modules/statuses.js @@ -32,6 +32,17 @@ export const defaultState = { minVisibleId: 0, loading: false }, + user: { + statuses: [], + statusesObject: {}, + faves: [], + visibleStatuses: [], + visibleStatusesObject: {}, + newStatusCount: 0, + maxId: 0, + minVisibleId: 0, + loading: false + }, publicAndExternal: { statuses: [], statusesObject: {}, diff --git a/src/services/api/api.service.js b/src/services/api/api.service.js index 1c5e281e..3715a211 100644 --- a/src/services/api/api.service.js +++ b/src/services/api/api.service.js @@ -18,6 +18,7 @@ const FOLLOWING_URL = '/api/friendships/create.json' const UNFOLLOWING_URL = '/api/friendships/destroy.json' const QVITTER_USER_PREF_URL = '/api/qvitter/set_profile_pref.json' const EXTERNAL_PROFILE_URL = '/api/externalprofile/show.json' +const QVITTER_USER_TIMELINE_URL = '/api/qvitter/statuses/user_timeline.json' // const USER_URL = '/api/users/show.json' const oldfetch = window.fetch @@ -98,24 +99,34 @@ const setUserMute = ({id, credentials, muted = true}) => { }) } -const fetchTimeline = ({timeline, credentials, since = false, until = false}) => { +const fetchTimeline = ({timeline, credentials, since = false, until = false, userId = false}) => { const timelineUrls = { public: PUBLIC_TIMELINE_URL, friends: FRIENDS_TIMELINE_URL, mentions: MENTIONS_URL, - 'publicAndExternal': PUBLIC_AND_EXTERNAL_TIMELINE_URL + 'publicAndExternal': PUBLIC_AND_EXTERNAL_TIMELINE_URL, + user: QVITTER_USER_TIMELINE_URL } let url = timelineUrls[timeline] + let params = [] + if (since) { - url += `?since_id=${since}` + params.push('since_id', since) } if (until) { - url += `?max_id=${until}` + params.push('max_id', until) + } + + if (userId) { + params.push(['user_id', userId]) } + const queryString = new URLSearchParams(params).toString() + url += `?${queryString}` + return fetch(url, { headers: authHeaders(credentials) }).then((data) => data.json()) } diff --git a/src/services/backend_interactor_service/backend_interactor_service.js b/src/services/backend_interactor_service/backend_interactor_service.js index 74248bc0..f2d01c70 100644 --- a/src/services/backend_interactor_service/backend_interactor_service.js +++ b/src/services/backend_interactor_service/backend_interactor_service.js @@ -26,8 +26,8 @@ const backendInteractorService = (credentials) => { return apiService.unfollowUser({credentials, id}) } - const startFetching = ({timeline, store}) => { - return timelineFetcherService.startFetching({timeline, store, credentials}) + const startFetching = ({timeline, store, userId = false}) => { + return timelineFetcherService.startFetching({timeline, store, credentials, userId}) } const setUserMute = ({id, muted = true}) => { diff --git a/src/services/timeline_fetcher/timeline_fetcher.service.js b/src/services/timeline_fetcher/timeline_fetcher.service.js index 24aef069..b28de9e7 100644 --- a/src/services/timeline_fetcher/timeline_fetcher.service.js +++ b/src/services/timeline_fetcher/timeline_fetcher.service.js @@ -14,7 +14,7 @@ const update = ({store, statuses, timeline, showImmediately}) => { }) } -const fetchAndUpdate = ({store, credentials, timeline = 'friends', older = false, showImmediately = false}) => { +const fetchAndUpdate = ({store, credentials, timeline = 'friends', older = false, showImmediately = false, userId = false}) => { const args = { timeline, credentials } const rootState = store.rootState || store.state const timelineData = rootState.statuses.timelines[camelCase(timeline)] @@ -25,14 +25,16 @@ const fetchAndUpdate = ({store, credentials, timeline = 'friends', older = false args['since'] = timelineData.maxId } + args['userId'] = userId + return apiService.fetchTimeline(args) .then((statuses) => update({store, statuses, timeline, showImmediately}), () => store.dispatch('setError', { value: true })) } -const startFetching = ({ timeline = 'friends', credentials, store }) => { - fetchAndUpdate({timeline, credentials, store, showImmediately: true}) - const boundFetchAndUpdate = () => fetchAndUpdate({ timeline, credentials, store }) +const startFetching = ({timeline = 'friends', credentials, store, userId = false}) => { + fetchAndUpdate({timeline, credentials, store, showImmediately: true, userId}) + const boundFetchAndUpdate = () => fetchAndUpdate({ timeline, credentials, store, userId }) return setInterval(boundFetchAndUpdate, 10000) } const timelineFetcher = { -- cgit v1.2.3-70-g09d2 From 2e7029b67027dae7ee3202553c0c9e288c882730 Mon Sep 17 00:00:00 2001 From: Roger Braun Date: Mon, 12 Jun 2017 16:20:02 +0200 Subject: Display user timeline --- src/components/user_profile/user_profile.js | 7 +++++-- src/components/user_profile/user_profile.vue | 7 +++++-- src/services/api/api.service.js | 4 ++-- 3 files changed, 12 insertions(+), 6 deletions(-) (limited to 'src/services/api/api.service.js') diff --git a/src/components/user_profile/user_profile.js b/src/components/user_profile/user_profile.js index 4f35cf27..5eef2735 100644 --- a/src/components/user_profile/user_profile.js +++ b/src/components/user_profile/user_profile.js @@ -1,13 +1,15 @@ import UserCardContent from '../user_card_content/user_card_content.vue' +import Timeline from '../timeline/timeline.vue' const UserProfile = { created () { this.$store.dispatch('startFetching', ['user', this.userId]) }, destroyed () { - this.$store.dispatch('stopFetching', ['user', this.userId]) + this.$store.dispatch('stopFetching', 'user') }, computed: { + timeline () { return this.$store.state.statuses.timelines.user }, userId () { return this.$route.params.id }, @@ -16,7 +18,8 @@ const UserProfile = { } }, components: { - UserCardContent + UserCardContent, + Timeline } } diff --git a/src/components/user_profile/user_profile.vue b/src/components/user_profile/user_profile.vue index fe693c9d..0765b01c 100644 --- a/src/components/user_profile/user_profile.vue +++ b/src/components/user_profile/user_profile.vue @@ -1,6 +1,9 @@ diff --git a/src/services/api/api.service.js b/src/services/api/api.service.js index 3715a211..026dae73 100644 --- a/src/services/api/api.service.js +++ b/src/services/api/api.service.js @@ -113,11 +113,11 @@ const fetchTimeline = ({timeline, credentials, since = false, until = false, use let params = [] if (since) { - params.push('since_id', since) + params.push(['since_id', since]) } if (until) { - params.push('max_id', until) + params.push(['max_id', until]) } if (userId) { -- cgit v1.2.3-70-g09d2 From 48a6d2e9875973928e2172d5ca76a2592cbb8a61 Mon Sep 17 00:00:00 2001 From: Roger Braun Date: Mon, 12 Jun 2017 17:35:04 +0200 Subject: Don't use too advanced features. --- src/services/api/api.service.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'src/services/api/api.service.js') diff --git a/src/services/api/api.service.js b/src/services/api/api.service.js index 026dae73..59e3a1c3 100644 --- a/src/services/api/api.service.js +++ b/src/services/api/api.service.js @@ -23,6 +23,8 @@ const QVITTER_USER_TIMELINE_URL = '/api/qvitter/statuses/user_timeline.json' const oldfetch = window.fetch +import { map } from 'lodash' + let fetch = (url, options) => { const baseUrl = '' const fullUrl = baseUrl + url @@ -124,7 +126,7 @@ const fetchTimeline = ({timeline, credentials, since = false, until = false, use params.push(['user_id', userId]) } - const queryString = new URLSearchParams(params).toString() + const queryString = map(params, (param) => `${param[0]}=${param[1]}`).join('&') url += `?${queryString}` return fetch(url, { headers: authHeaders(credentials) }).then((data) => data.json()) -- cgit v1.2.3-70-g09d2