From 2d339cd3b8b3ffc1509c954f68636d8ed4d37253 Mon Sep 17 00:00:00 2001 From: Brenden Bice Date: Mon, 1 Apr 2019 22:29:45 -0400 Subject: fetch favorited users --- src/services/api/api.service.js | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (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 2dd52cb5..45eec566 100644 --- a/src/services/api/api.service.js +++ b/src/services/api/api.service.js @@ -49,6 +49,7 @@ const MASTODON_MUTE_USER_URL = id => `/api/v1/accounts/${id}/mute` const MASTODON_UNMUTE_USER_URL = id => `/api/v1/accounts/${id}/unmute` const MASTODON_POST_STATUS_URL = '/api/v1/statuses' const MASTODON_MEDIA_UPLOAD_URL = '/api/v1/media' +const MASTODON_STATUS_FAVOURITEDBY_URL = id => `/api/v1/statuses/${id}/favourited_by` import { each, map } from 'lodash' import { parseStatus, parseUser, parseNotification, parseAttachment } from '../entity_normalizer/entity_normalizer.service.js' @@ -722,6 +723,32 @@ const markNotificationsAsSeen = ({id, credentials}) => { }).then((data) => data.json()) } +const fetchFavouritedByUsers = ({id}) => { + return fetch(MASTODON_STATUS_FAVOURITEDBY_URL(id), { + method: 'GET' + }) + .then(response => { + if (response.ok) { + return response.json() + } else { + throw new Error('Error fetching favorited by users') + } + }) +} + +const fetchRebloggedByUsers = ({id}) => { + return fetch(MASTODON_STATUS_REBLOGGEDBY_URL(id), { + method: 'GET' + }) + .then(response => { + if (response.ok) { + return response.json() + } else { + throw new Error('Error reblogged by users') + } + }) +} + const apiService = { verifyCredentials, fetchTimeline, -- cgit v1.2.3-70-g09d2 From 85457fc9173d64d39b1d942496cae1366a0d95ab Mon Sep 17 00:00:00 2001 From: Brenden Bice Date: Mon, 1 Apr 2019 22:30:06 -0400 Subject: fetch reblogged users --- src/components/conversation/conversation.js | 9 ++++++++ src/components/status/status.js | 2 ++ src/components/status/status.vue | 25 ++++++++++++++++++++++ src/modules/statuses.js | 7 ++++++ src/services/api/api.service.js | 5 ++++- .../backend_interactor_service.js | 3 +++ 6 files changed, 50 insertions(+), 1 deletion(-) (limited to 'src/services/api/api.service.js') diff --git a/src/components/conversation/conversation.js b/src/components/conversation/conversation.js index b3335f64..24d48dd8 100644 --- a/src/components/conversation/conversation.js +++ b/src/components/conversation/conversation.js @@ -122,6 +122,7 @@ const conversation = { .then(({ancestors, descendants}) => { const ancestorId = ancestors.length ? ancestors[0].id : this.status.id this.fetchFavouritedByUsers(ancestorId) + this.fetchRebloggedByUsers(ancestorId) this.$store.dispatch('addNewStatuses', { statuses: ancestors }) this.$store.dispatch('addNewStatuses', { statuses: descendants }) }) @@ -160,6 +161,14 @@ const conversation = { this.$store.dispatch('addFavoritedByUsers', { favoritedByUsers, id }) }) }, + fetchRebloggedByUsers (id) { + this.$store.state.api.backendInteractor.fetchRebloggedByUsers({id: this.status.id}).then((response) => { + const rebloggedByUsers = response.map(item => ({ + src: item.avatar_static, + name: item.display_name + })) + this.$store.dispatch('addRebloggedByUsers', { rebloggedByUsers, id }) + }) } } } diff --git a/src/components/status/status.js b/src/components/status/status.js index e470eaeb..eda96373 100644 --- a/src/components/status/status.js +++ b/src/components/status/status.js @@ -262,6 +262,8 @@ const Status = { favouritedByUsers () { return this.statusoid.favoritedBy ? this.statusoid.favoritedBy : [] }, + rebloggedByUsers () { + return this.statusoid.rebloggedBy ? this.statusoid.rebloggedBy : [] } }, components: { diff --git a/src/components/status/status.vue b/src/components/status/status.vue index 690e8318..6b8e0b3d 100644 --- a/src/components/status/status.vue +++ b/src/components/status/status.vue @@ -142,6 +142,16 @@ +
+
+

Boosted By {{rebloggedByUsers.length}}:

+ +
+
+

Favourited By {{favouritedByUsers.length}}:

+ +
+
@@ -612,6 +622,21 @@ a.unmute { } } +.boosted-users { + display: flex; + justify-content: space-between; + margin-top: 10px; + + .favourited-users, + .reblogged-users { + flex: 1; + + .title { + margin: 0 0 10px 0; + } + } +} + @media all and (max-width: 800px) { .status-el { .retweet-info { diff --git a/src/modules/statuses.js b/src/modules/statuses.js index 8d2eb424..c749e60f 100644 --- a/src/modules/statuses.js +++ b/src/modules/statuses.js @@ -466,6 +466,11 @@ export const mutations = { favoritedBy: favoritedByUsers } }, + addRebloggedByUsers (state, { rebloggedByUsers, id }) { + state.allStatusesObject[id] = { + ...state.allStatusesObject[id], + rebloggedBy: rebloggedByUsers + } } } @@ -535,6 +540,8 @@ const statuses = { addFavoritedByUsers ({ rootState, commit }, { favoritedByUsers, id }) { commit('addFavoritedByUsers', { favoritedByUsers, id }) }, + addRebloggedByUsers ({ rootState, commit }, { rebloggedByUsers, id }) { + commit('addRebloggedByUsers', { rebloggedByUsers, id }) } }, mutations diff --git a/src/services/api/api.service.js b/src/services/api/api.service.js index 45eec566..120398f0 100644 --- a/src/services/api/api.service.js +++ b/src/services/api/api.service.js @@ -50,6 +50,7 @@ const MASTODON_UNMUTE_USER_URL = id => `/api/v1/accounts/${id}/unmute` const MASTODON_POST_STATUS_URL = '/api/v1/statuses' const MASTODON_MEDIA_UPLOAD_URL = '/api/v1/media' const MASTODON_STATUS_FAVOURITEDBY_URL = id => `/api/v1/statuses/${id}/favourited_by` +const MASTODON_STATUS_REBLOGGEDBY_URL = id => `/api/v1/statuses/${id}/reblogged_by` import { each, map } from 'lodash' import { parseStatus, parseUser, parseNotification, parseAttachment } from '../entity_normalizer/entity_normalizer.service.js' @@ -797,7 +798,9 @@ const apiService = { approveUser, denyUser, suggestions, - markNotificationsAsSeen + markNotificationsAsSeen, + fetchFavouritedByUsers, + fetchRebloggedByUsers } export default apiService diff --git a/src/services/backend_interactor_service/backend_interactor_service.js b/src/services/backend_interactor_service/backend_interactor_service.js index 5faec9af..01663a64 100644 --- a/src/services/backend_interactor_service/backend_interactor_service.js +++ b/src/services/backend_interactor_service/backend_interactor_service.js @@ -113,6 +113,8 @@ const backendInteractorService = (credentials) => { const changePassword = ({password, newPassword, newPasswordConfirmation}) => apiService.changePassword({credentials, password, newPassword, newPasswordConfirmation}) const fetchFavouritedByUsers = ({id}) => apiService.fetchFavouritedByUsers({id}) + const fetchRebloggedByUsers = ({id}) => apiService.fetchRebloggedByUsers({id}) + const backendInteractorServiceInstance = { fetchStatus, fetchConversation, @@ -155,6 +157,7 @@ const backendInteractorService = (credentials) => { approveUser, denyUser, fetchFavouritedByUsers, + fetchRebloggedByUsers } return backendInteractorServiceInstance -- cgit v1.2.3-70-g09d2 From 0c3a922341a6f04f203396fb1c932411f6df0cd5 Mon Sep 17 00:00:00 2001 From: Brenden Bice Date: Tue, 2 Apr 2019 12:01:48 -0400 Subject: use promisedRequest for api call --- src/services/api/api.service.js | 22 ++-------------------- 1 file changed, 2 insertions(+), 20 deletions(-) (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 120398f0..1f9e9a88 100644 --- a/src/services/api/api.service.js +++ b/src/services/api/api.service.js @@ -725,29 +725,11 @@ const markNotificationsAsSeen = ({id, credentials}) => { } const fetchFavouritedByUsers = ({id}) => { - return fetch(MASTODON_STATUS_FAVOURITEDBY_URL(id), { - method: 'GET' - }) - .then(response => { - if (response.ok) { - return response.json() - } else { - throw new Error('Error fetching favorited by users') - } - }) + return promisedRequest(MASTODON_STATUS_FAVOURITEDBY_URL(id)).then((users) => users.map(parseUser)) } const fetchRebloggedByUsers = ({id}) => { - return fetch(MASTODON_STATUS_REBLOGGEDBY_URL(id), { - method: 'GET' - }) - .then(response => { - if (response.ok) { - return response.json() - } else { - throw new Error('Error reblogged by users') - } - }) + return promisedRequest(MASTODON_STATUS_REBLOGGEDBY_URL(id)).then((users) => users.map(parseUser)) } const apiService = { -- cgit v1.2.3-70-g09d2 From 8c9bcdc6c16f3a6dad5131b8163ee9d933b6b952 Mon Sep 17 00:00:00 2001 From: Brenden Bice Date: Tue, 2 Apr 2019 12:13:55 -0400 Subject: rename favourite to favorite --- src/components/conversation/conversation.js | 6 +++--- src/components/status/status.vue | 4 ++-- src/modules/statuses.js | 4 ++-- src/services/api/api.service.js | 8 ++++---- .../backend_interactor_service/backend_interactor_service.js | 4 ++-- 5 files changed, 13 insertions(+), 13 deletions(-) (limited to 'src/services/api/api.service.js') diff --git a/src/components/conversation/conversation.js b/src/components/conversation/conversation.js index 851d30e9..ba90746e 100644 --- a/src/components/conversation/conversation.js +++ b/src/components/conversation/conversation.js @@ -121,7 +121,7 @@ const conversation = { this.$store.state.api.backendInteractor.fetchConversation({id: this.status.id}) .then(({ancestors, descendants}) => { const ancestorId = ancestors.length ? ancestors[0].id : this.status.id - this.fetchFavouritedByUsers(ancestorId) + this.fetchFavoritedByUsers(ancestorId) this.fetchRebloggedByUsers(ancestorId) this.$store.dispatch('addNewStatuses', { statuses: ancestors }) this.$store.dispatch('addNewStatuses', { statuses: descendants }) @@ -152,8 +152,8 @@ const conversation = { this.setHighlight(null) } }, - fetchFavouritedByUsers (id) { - this.$store.dispatch('fetchFavouritedByUsers', { id }) + fetchFavoritedByUsers (id) { + this.$store.dispatch('fetchFavoritedByUsers', { id }) }, fetchRebloggedByUsers (id) { this.$store.dispatch('fetchRebloggedByUsers', { id }) diff --git a/src/components/status/status.vue b/src/components/status/status.vue index ce4b2554..a8042afe 100644 --- a/src/components/status/status.vue +++ b/src/components/status/status.vue @@ -133,7 +133,7 @@
-
+
@@ -616,7 +616,7 @@ a.unmute { } } -.favs-favourited-users { +.favs-favorited-users { margin-top: 10px; } diff --git a/src/modules/statuses.js b/src/modules/statuses.js index 2cfc3ff1..44213e75 100644 --- a/src/modules/statuses.js +++ b/src/modules/statuses.js @@ -537,8 +537,8 @@ const statuses = { credentials: rootState.users.currentUser.credentials }) }, - fetchFavouritedByUsers ({ rootState, commit }, { id }) { - rootState.api.backendInteractor.fetchFavouritedByUsers({id}).then((favoritedByUsers) => commit('addFavoritedByUsers', { favoritedByUsers, id })) + fetchFavoritedByUsers ({ rootState, commit }, { id }) { + rootState.api.backendInteractor.fetchFavoritedByUsers({id}).then((favoritedByUsers) => commit('addFavoritedByUsers', { favoritedByUsers, id })) }, fetchRebloggedByUsers ({ rootState, commit }, { id }) { rootState.api.backendInteractor.fetchRebloggedByUsers({id}).then((rebloggedByUsers) => commit('addRebloggedByUsers', { rebloggedByUsers, id })) diff --git a/src/services/api/api.service.js b/src/services/api/api.service.js index 1f9e9a88..90309edf 100644 --- a/src/services/api/api.service.js +++ b/src/services/api/api.service.js @@ -49,7 +49,7 @@ const MASTODON_MUTE_USER_URL = id => `/api/v1/accounts/${id}/mute` const MASTODON_UNMUTE_USER_URL = id => `/api/v1/accounts/${id}/unmute` const MASTODON_POST_STATUS_URL = '/api/v1/statuses' const MASTODON_MEDIA_UPLOAD_URL = '/api/v1/media' -const MASTODON_STATUS_FAVOURITEDBY_URL = id => `/api/v1/statuses/${id}/favourited_by` +const MASTODON_STATUS_FAVORITEDBY_URL = id => `/api/v1/statuses/${id}/favourited_by` const MASTODON_STATUS_REBLOGGEDBY_URL = id => `/api/v1/statuses/${id}/reblogged_by` import { each, map } from 'lodash' @@ -724,8 +724,8 @@ const markNotificationsAsSeen = ({id, credentials}) => { }).then((data) => data.json()) } -const fetchFavouritedByUsers = ({id}) => { - return promisedRequest(MASTODON_STATUS_FAVOURITEDBY_URL(id)).then((users) => users.map(parseUser)) +const fetchFavoritedByUsers = ({id}) => { + return promisedRequest(MASTODON_STATUS_FAVORITEDBY_URL(id)).then((users) => users.map(parseUser)) } const fetchRebloggedByUsers = ({id}) => { @@ -781,7 +781,7 @@ const apiService = { denyUser, suggestions, markNotificationsAsSeen, - fetchFavouritedByUsers, + fetchFavoritedByUsers, fetchRebloggedByUsers } diff --git a/src/services/backend_interactor_service/backend_interactor_service.js b/src/services/backend_interactor_service/backend_interactor_service.js index 01663a64..0768c806 100644 --- a/src/services/backend_interactor_service/backend_interactor_service.js +++ b/src/services/backend_interactor_service/backend_interactor_service.js @@ -112,7 +112,7 @@ const backendInteractorService = (credentials) => { const deleteAccount = ({password}) => apiService.deleteAccount({credentials, password}) const changePassword = ({password, newPassword, newPasswordConfirmation}) => apiService.changePassword({credentials, password, newPassword, newPasswordConfirmation}) - const fetchFavouritedByUsers = ({id}) => apiService.fetchFavouritedByUsers({id}) + const fetchFavoritedByUsers = ({id}) => apiService.fetchFavoritedByUsers({id}) const fetchRebloggedByUsers = ({id}) => apiService.fetchRebloggedByUsers({id}) const backendInteractorServiceInstance = { @@ -156,7 +156,7 @@ const backendInteractorService = (credentials) => { fetchFollowRequests, approveUser, denyUser, - fetchFavouritedByUsers, + fetchFavoritedByUsers, fetchRebloggedByUsers } -- cgit v1.2.3-70-g09d2 From 808e1ac11cbbe6779dcaa42d5b4cdec900339ccd Mon Sep 17 00:00:00 2001 From: taehoon Date: Wed, 13 Mar 2019 13:12:56 -0400 Subject: Switch to mastoapi for updating avatar # Conflicts: # src/services/api/api.service.js --- src/components/user_settings/user_settings.js | 26 +++++++++++--------- src/services/api/api.service.js | 28 +++++++--------------- .../backend_interactor_service.js | 2 +- 3 files changed, 24 insertions(+), 32 deletions(-) (limited to 'src/services/api/api.service.js') diff --git a/src/components/user_settings/user_settings.js b/src/components/user_settings/user_settings.js index e88ee612..1e2422bb 100644 --- a/src/components/user_settings/user_settings.js +++ b/src/components/user_settings/user_settings.js @@ -164,19 +164,23 @@ const UserSettings = { reader.readAsDataURL(file) }, submitAvatar (cropper, file) { - let img - if (cropper) { - img = cropper.getCroppedCanvas().toDataURL(file.type) - } else { - img = file - } + return new Promise((resolve, reject) => { + function updateAvatar (avatar) { + this.$store.state.api.backendInteractor.updateAvatar({ avatar }) + .then((user) => { + this.$store.commit('addNewUsers', [user]) + this.$store.commit('setCurrentUser', user) + resolve() + }) + .catch((err) => { + reject(new Error(this.$t('upload.error.base') + ' ' + err.message)) + }) + } - return this.$store.state.api.backendInteractor.updateAvatar({ params: { img } }).then((user) => { - if (!user.error) { - this.$store.commit('addNewUsers', [user]) - this.$store.commit('setCurrentUser', user) + if (cropper) { + cropper.getCroppedCanvas().toBlob(updateAvatar, file.type) } else { - throw new Error(this.$t('upload.error.base') + user.error) + updateAvatar(file) } }) }, diff --git a/src/services/api/api.service.js b/src/services/api/api.service.js index 6b255e9f..0540b2d2 100644 --- a/src/services/api/api.service.js +++ b/src/services/api/api.service.js @@ -3,7 +3,6 @@ const LOGIN_URL = '/api/account/verify_credentials.json' const ALL_FOLLOWING_URL = '/api/qvitter/allfollowing' const MENTIONS_URL = '/api/statuses/mentions.json' const REGISTRATION_URL = '/api/account/register.json' -const AVATAR_UPDATE_URL = '/api/qvitter/update_avatar.json' const BG_UPDATE_URL = '/api/qvitter/update_background_image.json' const BANNER_UPDATE_URL = '/api/account/update_profile_banner.json' const PROFILE_UPDATE_URL = '/api/account/update_profile.json' @@ -49,6 +48,7 @@ const MASTODON_MUTE_USER_URL = id => `/api/v1/accounts/${id}/mute` const MASTODON_UNMUTE_USER_URL = id => `/api/v1/accounts/${id}/unmute` const MASTODON_POST_STATUS_URL = '/api/v1/statuses' const MASTODON_MEDIA_UPLOAD_URL = '/api/v1/media' +const MASTODON_PROFILE_UPDATE_URL = '/api/v1/accounts/update_credentials' import { each, map, concat, last } from 'lodash' import { parseStatus, parseUser, parseNotification, parseAttachment } from '../entity_normalizer/entity_normalizer.service.js' @@ -78,28 +78,16 @@ const promisedRequest = (url, options) => { }) } -// Params -// cropH -// cropW -// cropX -// cropY -// img (base 64 encodend data url) -const updateAvatar = ({credentials, params}) => { - let url = AVATAR_UPDATE_URL - +const updateAvatar = ({credentials, avatar}) => { const form = new FormData() - - each(params, (value, key) => { - if (value) { - form.append(key, value) - } - }) - - return fetch(url, { + form.append('avatar', avatar) + return fetch(MASTODON_PROFILE_UPDATE_URL, { headers: authHeaders(credentials), - method: 'POST', + method: 'PATCH', body: form - }).then((data) => data.json()) + }) + .then((data) => data.json()) + .then((data) => parseUser(data)) } const updateBg = ({credentials, params}) => { diff --git a/src/services/backend_interactor_service/backend_interactor_service.js b/src/services/backend_interactor_service/backend_interactor_service.js index 75bba92b..762ee08b 100644 --- a/src/services/backend_interactor_service/backend_interactor_service.js +++ b/src/services/backend_interactor_service/backend_interactor_service.js @@ -101,7 +101,7 @@ const backendInteractorService = (credentials) => { const getCaptcha = () => apiService.getCaptcha() const register = (params) => apiService.register(params) - const updateAvatar = ({params}) => apiService.updateAvatar({credentials, params}) + const updateAvatar = ({avatar}) => apiService.updateAvatar({credentials, avatar}) const updateBg = ({params}) => apiService.updateBg({credentials, params}) const updateBanner = ({params}) => apiService.updateBanner({credentials, params}) const updateProfile = ({params}) => apiService.updateProfile({credentials, params}) -- cgit v1.2.3-70-g09d2 From 909d11825d83201bf9ff0ec9491e6361f511ca0f Mon Sep 17 00:00:00 2001 From: taehoon Date: Wed, 13 Mar 2019 13:56:28 -0400 Subject: Switch to mastoapi for updating banner --- src/components/user_settings/user_settings.js | 32 +++++++--------------- src/services/api/api.service.js | 27 +++++------------- .../backend_interactor_service.js | 2 +- 3 files changed, 18 insertions(+), 43 deletions(-) (limited to 'src/services/api/api.service.js') diff --git a/src/components/user_settings/user_settings.js b/src/components/user_settings/user_settings.js index 1e2422bb..bc824393 100644 --- a/src/components/user_settings/user_settings.js +++ b/src/components/user_settings/user_settings.js @@ -160,6 +160,7 @@ const UserSettings = { reader.onload = ({target}) => { const img = target.result this[slot + 'Preview'] = img + this[slot] = file } reader.readAsDataURL(file) }, @@ -190,30 +191,17 @@ const UserSettings = { submitBanner () { if (!this.bannerPreview) { return } - let banner = this.bannerPreview - // eslint-disable-next-line no-undef - let imginfo = new Image() - /* eslint-disable camelcase */ - let offset_top, offset_left, width, height - imginfo.src = banner - width = imginfo.width - height = imginfo.height - offset_top = 0 - offset_left = 0 this.bannerUploading = true - this.$store.state.api.backendInteractor.updateBanner({params: {banner, offset_top, offset_left, width, height}}).then((data) => { - if (!data.error) { - let clone = JSON.parse(JSON.stringify(this.$store.state.users.currentUser)) - clone.cover_photo = data.url - this.$store.commit('addNewUsers', [clone]) - this.$store.commit('setCurrentUser', clone) + this.$store.state.api.backendInteractor.updateBanner({banner: this.banner}) + .then((user) => { + this.$store.commit('addNewUsers', [user]) + this.$store.commit('setCurrentUser', user) this.bannerPreview = null - } else { - this.bannerUploadError = this.$t('upload.error.base') + data.error - } - this.bannerUploading = false - }) - /* eslint-enable camelcase */ + }) + .catch((err) => { + this.bannerUploadError = this.$t('upload.error.base') + ' ' + err.message + }) + .then(() => { this.bannerUploading = false }) }, submitBg () { if (!this.backgroundPreview) { return } diff --git a/src/services/api/api.service.js b/src/services/api/api.service.js index 0540b2d2..eaebb3f1 100644 --- a/src/services/api/api.service.js +++ b/src/services/api/api.service.js @@ -4,7 +4,6 @@ const ALL_FOLLOWING_URL = '/api/qvitter/allfollowing' const MENTIONS_URL = '/api/statuses/mentions.json' const REGISTRATION_URL = '/api/account/register.json' const BG_UPDATE_URL = '/api/qvitter/update_background_image.json' -const BANNER_UPDATE_URL = '/api/account/update_profile_banner.json' const PROFILE_UPDATE_URL = '/api/account/update_profile.json' const EXTERNAL_PROFILE_URL = '/api/externalprofile/show.json' const QVITTER_USER_NOTIFICATIONS_READ_URL = '/api/qvitter/statuses/notifications/read.json' @@ -108,28 +107,16 @@ const updateBg = ({credentials, params}) => { }).then((data) => data.json()) } -// Params -// height -// width -// offset_left -// offset_top -// banner (base 64 encodend data url) -const updateBanner = ({credentials, params}) => { - let url = BANNER_UPDATE_URL - +const updateBanner = ({credentials, banner}) => { const form = new FormData() - - each(params, (value, key) => { - if (value) { - form.append(key, value) - } - }) - - return fetch(url, { + form.append('header', banner) + return fetch(MASTODON_PROFILE_UPDATE_URL, { headers: authHeaders(credentials), - method: 'POST', + method: 'PATCH', body: form - }).then((data) => data.json()) + }) + .then((data) => data.json()) + .then((data) => parseUser(data)) } // Params diff --git a/src/services/backend_interactor_service/backend_interactor_service.js b/src/services/backend_interactor_service/backend_interactor_service.js index 762ee08b..d61ff452 100644 --- a/src/services/backend_interactor_service/backend_interactor_service.js +++ b/src/services/backend_interactor_service/backend_interactor_service.js @@ -103,7 +103,7 @@ const backendInteractorService = (credentials) => { const register = (params) => apiService.register(params) const updateAvatar = ({avatar}) => apiService.updateAvatar({credentials, avatar}) const updateBg = ({params}) => apiService.updateBg({credentials, params}) - const updateBanner = ({params}) => apiService.updateBanner({credentials, params}) + const updateBanner = ({banner}) => apiService.updateBanner({credentials, banner}) const updateProfile = ({params}) => apiService.updateProfile({credentials, params}) const externalProfile = (profileUrl) => apiService.externalProfile({profileUrl, credentials}) -- cgit v1.2.3-70-g09d2 From e14720419f743f630eec8a671833eb08923e3dee Mon Sep 17 00:00:00 2001 From: taehoon Date: Sat, 16 Mar 2019 08:40:46 -0400 Subject: Switch to mastoapi for updating user profile --- src/components/user_settings/user_settings.js | 14 ++++++-------- src/services/api/api.service.js | 13 ++++++------- 2 files changed, 12 insertions(+), 15 deletions(-) (limited to 'src/services/api/api.service.js') diff --git a/src/components/user_settings/user_settings.js b/src/components/user_settings/user_settings.js index bc824393..6b367e4f 100644 --- a/src/components/user_settings/user_settings.js +++ b/src/components/user_settings/user_settings.js @@ -110,11 +110,11 @@ const UserSettings = { }, methods: { updateProfile () { - const name = this.newName - const description = this.newBio + const note = this.newBio const locked = this.newLocked // Backend notation. /* eslint-disable camelcase */ + const display_name = this.newName const default_scope = this.newDefaultScope const no_rich_text = this.newNoRichText const hide_follows = this.hideFollows @@ -125,8 +125,8 @@ const UserSettings = { this.$store.state.api.backendInteractor .updateProfile({ params: { - name, - description, + display_name, + note, locked, // Backend notation. /* eslint-disable camelcase */ @@ -137,10 +137,8 @@ const UserSettings = { show_role /* eslint-enable camelcase */ }}).then((user) => { - if (!user.error) { - this.$store.commit('addNewUsers', [user]) - this.$store.commit('setCurrentUser', user) - } + this.$store.commit('addNewUsers', [user]) + this.$store.commit('setCurrentUser', user) }) }, changeVis (visibility) { diff --git a/src/services/api/api.service.js b/src/services/api/api.service.js index eaebb3f1..9338c495 100644 --- a/src/services/api/api.service.js +++ b/src/services/api/api.service.js @@ -4,7 +4,6 @@ const ALL_FOLLOWING_URL = '/api/qvitter/allfollowing' const MENTIONS_URL = '/api/statuses/mentions.json' const REGISTRATION_URL = '/api/account/register.json' const BG_UPDATE_URL = '/api/qvitter/update_background_image.json' -const PROFILE_UPDATE_URL = '/api/account/update_profile.json' const EXTERNAL_PROFILE_URL = '/api/externalprofile/show.json' const QVITTER_USER_NOTIFICATIONS_READ_URL = '/api/qvitter/statuses/notifications/read.json' const FOLLOW_IMPORT_URL = '/api/pleroma/follow_import' @@ -126,9 +125,7 @@ const updateBanner = ({credentials, banner}) => { // description const updateProfile = ({credentials, params}) => { // Always include these fields, because they might be empty or false - const fields = ['description', 'locked', 'no_rich_text', 'hide_follows', 'hide_followers', 'show_role'] - let url = PROFILE_UPDATE_URL - + const fields = ['note', 'locked', 'no_rich_text', 'hide_follows', 'hide_followers', 'show_role'] const form = new FormData() each(params, (value, key) => { @@ -136,11 +133,13 @@ const updateProfile = ({credentials, params}) => { form.append(key, value) } }) - return fetch(url, { + return fetch(MASTODON_PROFILE_UPDATE_URL, { headers: authHeaders(credentials), - method: 'POST', + method: 'PATCH', body: form - }).then((data) => data.json()) + }) + .then((data) => data.json()) + .then((data) => parseUser(data)) } // Params needed: -- cgit v1.2.3-70-g09d2 From 903bce40c3b013ed2f2347c254ea184293b45b22 Mon Sep 17 00:00:00 2001 From: taehoon Date: Fri, 29 Mar 2019 23:39:24 -0400 Subject: move formData generating logic to api.service --- src/components/importer/importer.js | 5 +---- src/services/api/api.service.js | 6 ++++-- .../backend_interactor_service/backend_interactor_service.js | 2 +- 3 files changed, 6 insertions(+), 7 deletions(-) (limited to 'src/services/api/api.service.js') diff --git a/src/components/importer/importer.js b/src/components/importer/importer.js index 8d6c8b3f..44d02c93 100644 --- a/src/components/importer/importer.js +++ b/src/components/importer/importer.js @@ -13,10 +13,7 @@ const Importer = { }, submit () { this.uploading = true - // eslint-disable-next-line no-undef - const formData = new FormData() - formData.append('list', this.file) - this.$store.state.api.backendInteractor.followImport({params: formData}) + this.$store.state.api.backendInteractor.followImport(this.file) .then((status) => { if (status) { this.success = true diff --git a/src/services/api/api.service.js b/src/services/api/api.service.js index 6b255e9f..3f6ffccc 100644 --- a/src/services/api/api.service.js +++ b/src/services/api/api.service.js @@ -634,9 +634,11 @@ const uploadMedia = ({formData, credentials}) => { .then((data) => parseAttachment(data)) } -const followImport = ({params, credentials}) => { +const followImport = ({file, credentials}) => { + const formData = new FormData() + formData.append('list', file) return fetch(FOLLOW_IMPORT_URL, { - body: params, + body: formData, method: 'POST', headers: authHeaders(credentials) }) diff --git a/src/services/backend_interactor_service/backend_interactor_service.js b/src/services/backend_interactor_service/backend_interactor_service.js index 75bba92b..2438c603 100644 --- a/src/services/backend_interactor_service/backend_interactor_service.js +++ b/src/services/backend_interactor_service/backend_interactor_service.js @@ -107,7 +107,7 @@ const backendInteractorService = (credentials) => { const updateProfile = ({params}) => apiService.updateProfile({credentials, params}) const externalProfile = (profileUrl) => apiService.externalProfile({profileUrl, credentials}) - const followImport = ({params}) => apiService.followImport({params, credentials}) + const followImport = (file) => apiService.followImport({file, credentials}) const deleteAccount = ({password}) => apiService.deleteAccount({credentials, password}) const changePassword = ({password, newPassword, newPasswordConfirmation}) => apiService.changePassword({credentials, password, newPassword, newPasswordConfirmation}) -- cgit v1.2.3-70-g09d2 From 6ea4154084b288f6f67ccf9c10829013c3cbe892 Mon Sep 17 00:00:00 2001 From: taehoon Date: Sat, 30 Mar 2019 07:22:30 -0400 Subject: change api function name --- src/components/user_settings/user_settings.js | 2 +- src/services/api/api.service.js | 4 ++-- src/services/backend_interactor_service/backend_interactor_service.js | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) (limited to 'src/services/api/api.service.js') diff --git a/src/components/user_settings/user_settings.js b/src/components/user_settings/user_settings.js index 32e92dc4..fa252e59 100644 --- a/src/components/user_settings/user_settings.js +++ b/src/components/user_settings/user_settings.js @@ -235,7 +235,7 @@ const UserSettings = { }) }, importFollows (file) { - return this.$store.state.api.backendInteractor.followImport(file) + return this.$store.state.api.backendInteractor.importFollows(file) .then((status) => { if (!status) { throw new Error('failed') diff --git a/src/services/api/api.service.js b/src/services/api/api.service.js index 3f6ffccc..dbcde41d 100644 --- a/src/services/api/api.service.js +++ b/src/services/api/api.service.js @@ -634,7 +634,7 @@ const uploadMedia = ({formData, credentials}) => { .then((data) => parseAttachment(data)) } -const followImport = ({file, credentials}) => { +const importFollows = ({file, credentials}) => { const formData = new FormData() formData.append('list', file) return fetch(FOLLOW_IMPORT_URL, { @@ -778,7 +778,7 @@ const apiService = { updateProfile, updateBanner, externalProfile, - followImport, + importFollows, deleteAccount, changePassword, fetchFollowRequests, diff --git a/src/services/backend_interactor_service/backend_interactor_service.js b/src/services/backend_interactor_service/backend_interactor_service.js index 2438c603..726c8ced 100644 --- a/src/services/backend_interactor_service/backend_interactor_service.js +++ b/src/services/backend_interactor_service/backend_interactor_service.js @@ -107,7 +107,7 @@ const backendInteractorService = (credentials) => { const updateProfile = ({params}) => apiService.updateProfile({credentials, params}) const externalProfile = (profileUrl) => apiService.externalProfile({profileUrl, credentials}) - const followImport = (file) => apiService.followImport({file, credentials}) + const importFollows = (file) => apiService.importFollows({file, credentials}) const deleteAccount = ({password}) => apiService.deleteAccount({credentials, password}) const changePassword = ({password, newPassword, newPasswordConfirmation}) => apiService.changePassword({credentials, password, newPassword, newPasswordConfirmation}) @@ -147,7 +147,7 @@ const backendInteractorService = (credentials) => { updateBanner, updateProfile, externalProfile, - followImport, + importFollows, deleteAccount, changePassword, fetchFollowRequests, -- cgit v1.2.3-70-g09d2 From 0ab2f9dfa58c1f4caf01f083175a171d19272cda Mon Sep 17 00:00:00 2001 From: taehoon Date: Sat, 30 Mar 2019 07:27:53 -0400 Subject: add “block import” feature MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/user_settings/user_settings.js | 8 ++++++++ src/components/user_settings/user_settings.vue | 5 +++++ src/i18n/en.json | 4 ++++ src/services/api/api.service.js | 13 +++++++++++++ .../backend_interactor_service.js | 2 ++ 5 files changed, 32 insertions(+) (limited to 'src/services/api/api.service.js') diff --git a/src/components/user_settings/user_settings.js b/src/components/user_settings/user_settings.js index fa252e59..c4214744 100644 --- a/src/components/user_settings/user_settings.js +++ b/src/components/user_settings/user_settings.js @@ -242,6 +242,14 @@ const UserSettings = { } }) }, + importBlocks (file) { + return this.$store.state.api.backendInteractor.importBlocks(file) + .then((status) => { + if (!status) { + throw new Error('failed') + } + }) + }, /* This function takes an Array of Users * and outputs a file with all the addresses for the user to download */ diff --git a/src/components/user_settings/user_settings.vue b/src/components/user_settings/user_settings.vue index fc40bdc0..520a3d8a 100644 --- a/src/components/user_settings/user_settings.vue +++ b/src/components/user_settings/user_settings.vue @@ -180,6 +180,11 @@

{{$t('settings.follow_export_processing')}}

+
+

{{$t('settings.block_import')}}

+

{{$t('settings.import_blocks_from_a_csv_file')}}

+ +
diff --git a/src/i18n/en.json b/src/i18n/en.json index 34d252b2..d4ec1134 100644 --- a/src/i18n/en.json +++ b/src/i18n/en.json @@ -131,6 +131,9 @@ "avatarRadius": "Avatars", "background": "Background", "bio": "Bio", + "block_import": "Block import", + "block_import_error": "Error importing blocks", + "blocks_imported": "Blocks imported! Processing them will take a while.", "blocks_tab": "Blocks", "btnRadius": "Buttons", "cBlue": "Blue (Reply, follow)", @@ -174,6 +177,7 @@ "hide_post_stats": "Hide post statistics (e.g. the number of favorites)", "hide_user_stats": "Hide user statistics (e.g. the number of followers)", "hide_filtered_statuses": "Hide filtered statuses", + "import_blocks_from_a_csv_file": "Import blocks from a csv file", "import_followers_from_a_csv_file": "Import follows from a csv file", "import_theme": "Load preset", "inputRadius": "Input fields", diff --git a/src/services/api/api.service.js b/src/services/api/api.service.js index dbcde41d..a6892959 100644 --- a/src/services/api/api.service.js +++ b/src/services/api/api.service.js @@ -9,6 +9,7 @@ const BANNER_UPDATE_URL = '/api/account/update_profile_banner.json' const PROFILE_UPDATE_URL = '/api/account/update_profile.json' const EXTERNAL_PROFILE_URL = '/api/externalprofile/show.json' const QVITTER_USER_NOTIFICATIONS_READ_URL = '/api/qvitter/statuses/notifications/read.json' +const BLOCKS_IMPORT_URL = '/api/pleroma/blocks_import' const FOLLOW_IMPORT_URL = '/api/pleroma/follow_import' const DELETE_ACCOUNT_URL = '/api/pleroma/delete_account' const CHANGE_PASSWORD_URL = '/api/pleroma/change_password' @@ -634,6 +635,17 @@ const uploadMedia = ({formData, credentials}) => { .then((data) => parseAttachment(data)) } +const importBlocks = ({file, credentials}) => { + const formData = new FormData() + formData.append('list', file) + return fetch(BLOCKS_IMPORT_URL, { + body: formData, + method: 'POST', + headers: authHeaders(credentials) + }) + .then((response) => response.ok) +} + const importFollows = ({file, credentials}) => { const formData = new FormData() formData.append('list', file) @@ -778,6 +790,7 @@ const apiService = { updateProfile, updateBanner, externalProfile, + importBlocks, importFollows, deleteAccount, changePassword, diff --git a/src/services/backend_interactor_service/backend_interactor_service.js b/src/services/backend_interactor_service/backend_interactor_service.js index 726c8ced..3256a921 100644 --- a/src/services/backend_interactor_service/backend_interactor_service.js +++ b/src/services/backend_interactor_service/backend_interactor_service.js @@ -107,6 +107,7 @@ const backendInteractorService = (credentials) => { const updateProfile = ({params}) => apiService.updateProfile({credentials, params}) const externalProfile = (profileUrl) => apiService.externalProfile({profileUrl, credentials}) + const importBlocks = (file) => apiService.importBlocks({file, credentials}) const importFollows = (file) => apiService.importFollows({file, credentials}) const deleteAccount = ({password}) => apiService.deleteAccount({credentials, password}) @@ -147,6 +148,7 @@ const backendInteractorService = (credentials) => { updateBanner, updateProfile, externalProfile, + importBlocks, importFollows, deleteAccount, changePassword, -- cgit v1.2.3-70-g09d2 From 904a64de8951356d0e1a798349661039d5821d32 Mon Sep 17 00:00:00 2001 From: taehoon Date: Sat, 27 Apr 2019 14:20:32 -0400 Subject: use json content type --- src/services/api/api.service.js | 25 +++++++------------------ 1 file changed, 7 insertions(+), 18 deletions(-) (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 9338c495..1cf47bb8 100644 --- a/src/services/api/api.service.js +++ b/src/services/api/api.service.js @@ -118,27 +118,16 @@ const updateBanner = ({credentials, banner}) => { .then((data) => parseUser(data)) } -// Params -// name -// url -// location -// description const updateProfile = ({credentials, params}) => { - // Always include these fields, because they might be empty or false - const fields = ['note', 'locked', 'no_rich_text', 'hide_follows', 'hide_followers', 'show_role'] - const form = new FormData() - - each(params, (value, key) => { - if (fields.includes(key) || value) { - form.append(key, value) - } - }) - return fetch(MASTODON_PROFILE_UPDATE_URL, { - headers: authHeaders(credentials), + return promisedRequest(MASTODON_PROFILE_UPDATE_URL, { + headers: { + 'Accept': 'application/json', + 'Content-Type': 'application/json', + ...authHeaders(credentials) + }, method: 'PATCH', - body: form + body: JSON.stringify(params) }) - .then((data) => data.json()) .then((data) => parseUser(data)) } -- cgit v1.2.3-70-g09d2 From cea6ea42f0f882864e01f79a8af08c8bc59272fb Mon Sep 17 00:00:00 2001 From: taehoon Date: Wed, 20 Mar 2019 11:45:19 -0400 Subject: add api service function --- .../user_reporting_modal/user_reporting_modal.js | 6 +++--- src/modules/reports.js | 5 +++-- src/services/api/api.service.js | 22 +++++++++++++++++++++- .../backend_interactor_service.js | 4 +++- 4 files changed, 30 insertions(+), 7 deletions(-) (limited to 'src/services/api/api.service.js') diff --git a/src/components/user_reporting_modal/user_reporting_modal.js b/src/components/user_reporting_modal/user_reporting_modal.js index fb9ea16d..87b6fde9 100644 --- a/src/components/user_reporting_modal/user_reporting_modal.js +++ b/src/components/user_reporting_modal/user_reporting_modal.js @@ -44,12 +44,12 @@ const UserReportingModal = { this.$store.dispatch('closeUserReportingModal') }, reportUser () { - const payload = { + const params = { comment: this.comment, forward: this.forward, - statusIdsToReport: this.statusIdsToReport + statusIds: this.statusIdsToReport } - this.$store.dispatch('reportUser', payload) + this.$store.dispatch('reportUser', params) }, isChecked (statusId) { return this.statusIdsToReport.indexOf(statusId) !== -1 diff --git a/src/modules/reports.js b/src/modules/reports.js index b712cfeb..0470b3be 100644 --- a/src/modules/reports.js +++ b/src/modules/reports.js @@ -24,8 +24,9 @@ const reports = { closeUserReportingModal ({ commit }) { commit('closeUserReportingModal') }, - reportUser ({ commit }, payload) { - console.log('payload', payload) + reportUser ({ state, rootState, commit }, params) { + rootState.api.backendInteractor.reportUser({ userId: state.userId, ...params }) + .then(result => console.log(result)) } } } diff --git a/src/services/api/api.service.js b/src/services/api/api.service.js index c5e2280d..9753049f 100644 --- a/src/services/api/api.service.js +++ b/src/services/api/api.service.js @@ -50,6 +50,7 @@ const MASTODON_MEDIA_UPLOAD_URL = '/api/v1/media' const MASTODON_STATUS_FAVORITEDBY_URL = id => `/api/v1/statuses/${id}/favourited_by` const MASTODON_STATUS_REBLOGGEDBY_URL = id => `/api/v1/statuses/${id}/reblogged_by` const MASTODON_PROFILE_UPDATE_URL = '/api/v1/accounts/update_credentials' +const MASTODON_REPORT_USER_URL = 'api/v1/reports' import { each, map, concat, last } from 'lodash' import { parseStatus, parseUser, parseNotification, parseAttachment } from '../entity_normalizer/entity_normalizer.service.js' @@ -722,6 +723,24 @@ const fetchRebloggedByUsers = ({id}) => { return promisedRequest(MASTODON_STATUS_REBLOGGEDBY_URL(id)).then((users) => users.map(parseUser)) } +const reportUser = ({credentials, userId, statusIds, comment, forward}) => { + const payload = { + 'account_id': userId, + 'status_ids': statusIds, + comment, + forward + } + return fetch(MASTODON_REPORT_USER_URL, { + body: JSON.stringify(payload), + headers: { + ...authHeaders(credentials), + 'Accept': 'application/json', + 'Content-Type': 'application/json' + }, + method: 'POST' + }).then((data) => data.json()) +} + const apiService = { verifyCredentials, fetchTimeline, @@ -773,7 +792,8 @@ const apiService = { suggestions, markNotificationsAsSeen, fetchFavoritedByUsers, - fetchRebloggedByUsers + fetchRebloggedByUsers, + reportUser } export default apiService diff --git a/src/services/backend_interactor_service/backend_interactor_service.js b/src/services/backend_interactor_service/backend_interactor_service.js index d2b581ca..58bb1248 100644 --- a/src/services/backend_interactor_service/backend_interactor_service.js +++ b/src/services/backend_interactor_service/backend_interactor_service.js @@ -115,6 +115,7 @@ const backendInteractorService = (credentials) => { const fetchFavoritedByUsers = (id) => apiService.fetchFavoritedByUsers({id}) const fetchRebloggedByUsers = (id) => apiService.fetchRebloggedByUsers({id}) + const reportUser = (params) => apiService.reportUser({credentials, ...params}) const backendInteractorServiceInstance = { fetchStatus, @@ -159,7 +160,8 @@ const backendInteractorService = (credentials) => { approveUser, denyUser, fetchFavoritedByUsers, - fetchRebloggedByUsers + fetchRebloggedByUsers, + reportUser } return backendInteractorServiceInstance -- cgit v1.2.3-70-g09d2 From 02d169b92c61015a5663b703a23e769848239b13 Mon Sep 17 00:00:00 2001 From: taehoon Date: Wed, 20 Mar 2019 11:54:16 -0400 Subject: add promisedRequest helper --- src/services/api/api.service.js | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) (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 9753049f..a19aff9f 100644 --- a/src/services/api/api.service.js +++ b/src/services/api/api.service.js @@ -724,21 +724,17 @@ const fetchRebloggedByUsers = ({id}) => { } const reportUser = ({credentials, userId, statusIds, comment, forward}) => { - const payload = { - 'account_id': userId, - 'status_ids': statusIds, - comment, - forward - } - return fetch(MASTODON_REPORT_USER_URL, { - body: JSON.stringify(payload), - headers: { - ...authHeaders(credentials), - 'Accept': 'application/json', - 'Content-Type': 'application/json' + return promisedRequest({ + uri: MASTODON_REPORT_USER_URL, + method: 'POST', + payload: { + 'account_id': userId, + 'status_ids': statusIds, + comment, + forward }, - method: 'POST' - }).then((data) => data.json()) + credentials + }) } const apiService = { -- cgit v1.2.3-70-g09d2 From 2e6eab51b8272e3136046544f195253ec6c5841c Mon Sep 17 00:00:00 2001 From: taehoon Date: Sun, 24 Mar 2019 21:35:34 -0400 Subject: Update promisedRequest helper to support json payload --- src/services/api/api.service.js | 37 ++++++++++++++++++++++++------------- 1 file changed, 24 insertions(+), 13 deletions(-) (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 a19aff9f..15c4b62a 100644 --- a/src/services/api/api.service.js +++ b/src/services/api/api.service.js @@ -67,7 +67,24 @@ let fetch = (url, options) => { return oldfetch(fullUrl, options) } -const promisedRequest = (url, options) => { +const promisedRequest = ({ method, url, payload, credentials, headers = {} }) => { + const options = { + method, + headers: { + 'Accept': 'application/json', + 'Content-Type': 'application/json', + ...headers + } + } + if (payload) { + options.body = JSON.stringify(payload) + } + if (credentials) { + options.headers = { + ...options.headers, + ...authHeaders(credentials) + } + } return fetch(url, options) .then((response) => { return new Promise((resolve, reject) => response.json() @@ -228,7 +245,7 @@ const denyUser = ({id, credentials}) => { const fetchUser = ({id, credentials}) => { let url = `${MASTODON_USER_URL}/${id}` - return promisedRequest(url, { headers: authHeaders(credentials) }) + return promisedRequest({ url, credentials }) .then((data) => parseUser(data)) } @@ -652,26 +669,20 @@ const changePassword = ({credentials, password, newPassword, newPasswordConfirma } const fetchMutes = ({credentials}) => { - return promisedRequest(MASTODON_USER_MUTES_URL, { headers: authHeaders(credentials) }) + return promisedRequest({ url: MASTODON_USER_MUTES_URL, credentials }) .then((users) => users.map(parseUser)) } const muteUser = ({id, credentials}) => { - return promisedRequest(MASTODON_MUTE_USER_URL(id), { - headers: authHeaders(credentials), - method: 'POST' - }) + return promisedRequest({ url: MASTODON_MUTE_USER_URL(id), credentials, method: 'POST' }) } const unmuteUser = ({id, credentials}) => { - return promisedRequest(MASTODON_UNMUTE_USER_URL(id), { - headers: authHeaders(credentials), - method: 'POST' - }) + return promisedRequest({ url: MASTODON_UNMUTE_USER_URL(id), credentials, method: 'POST' }) } const fetchBlocks = ({credentials}) => { - return promisedRequest(MASTODON_USER_BLOCKS_URL, { headers: authHeaders(credentials) }) + return promisedRequest({ url: MASTODON_USER_BLOCKS_URL, credentials }) .then((users) => users.map(parseUser)) } @@ -725,7 +736,7 @@ const fetchRebloggedByUsers = ({id}) => { const reportUser = ({credentials, userId, statusIds, comment, forward}) => { return promisedRequest({ - uri: MASTODON_REPORT_USER_URL, + url: MASTODON_REPORT_USER_URL, method: 'POST', payload: { 'account_id': userId, -- cgit v1.2.3-70-g09d2 From 19a04769858c6786826a546bd5c0d3876049bad2 Mon Sep 17 00:00:00 2001 From: taehoon Date: Wed, 24 Apr 2019 22:40:37 -0400 Subject: update api endpoint url --- src/services/api/api.service.js | 2 +- 1 file changed, 1 insertion(+), 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 15c4b62a..846fab3a 100644 --- a/src/services/api/api.service.js +++ b/src/services/api/api.service.js @@ -50,7 +50,7 @@ const MASTODON_MEDIA_UPLOAD_URL = '/api/v1/media' const MASTODON_STATUS_FAVORITEDBY_URL = id => `/api/v1/statuses/${id}/favourited_by` const MASTODON_STATUS_REBLOGGEDBY_URL = id => `/api/v1/statuses/${id}/reblogged_by` const MASTODON_PROFILE_UPDATE_URL = '/api/v1/accounts/update_credentials' -const MASTODON_REPORT_USER_URL = 'api/v1/reports' +const MASTODON_REPORT_USER_URL = '/api/v1/reports' import { each, map, concat, last } from 'lodash' import { parseStatus, parseUser, parseNotification, parseAttachment } from '../entity_normalizer/entity_normalizer.service.js' -- cgit v1.2.3-70-g09d2 From 9787d996722e44e6554d936e0995bf4c346207e2 Mon Sep 17 00:00:00 2001 From: taehoon Date: Tue, 30 Apr 2019 16:38:34 -0400 Subject: update api services --- src/services/api/api.service.js | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) (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 846fab3a..da44fc54 100644 --- a/src/services/api/api.service.js +++ b/src/services/api/api.service.js @@ -140,14 +140,11 @@ const updateBanner = ({credentials, banner}) => { } const updateProfile = ({credentials, params}) => { - return promisedRequest(MASTODON_PROFILE_UPDATE_URL, { - headers: { - 'Accept': 'application/json', - 'Content-Type': 'application/json', - ...authHeaders(credentials) - }, + return promisedRequest({ + url: MASTODON_PROFILE_UPDATE_URL, method: 'PATCH', - body: JSON.stringify(params) + payload: params, + credentials }) .then((data) => parseUser(data)) } @@ -727,11 +724,11 @@ const markNotificationsAsSeen = ({id, credentials}) => { } const fetchFavoritedByUsers = ({id}) => { - return promisedRequest(MASTODON_STATUS_FAVORITEDBY_URL(id)).then((users) => users.map(parseUser)) + return promisedRequest({ url: MASTODON_STATUS_FAVORITEDBY_URL(id) }).then((users) => users.map(parseUser)) } const fetchRebloggedByUsers = ({id}) => { - return promisedRequest(MASTODON_STATUS_REBLOGGEDBY_URL(id)).then((users) => users.map(parseUser)) + return promisedRequest({ url: MASTODON_STATUS_REBLOGGEDBY_URL(id) }).then((users) => users.map(parseUser)) } const reportUser = ({credentials, userId, statusIds, comment, forward}) => { -- cgit v1.2.3-70-g09d2 From 26131266a926c8511d92e3d10aa618af5e94c6e3 Mon Sep 17 00:00:00 2001 From: taehoon Date: Tue, 7 May 2019 23:27:22 -0400 Subject: refactor api service functions using new helper --- src/services/api/api.service.js | 48 ++++------------------------------------- 1 file changed, 4 insertions(+), 44 deletions(-) (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 da44fc54..b7a602b8 100644 --- a/src/services/api/api.service.js +++ b/src/services/api/api.service.js @@ -506,62 +506,22 @@ const verifyCredentials = (user) => { } const favorite = ({ id, credentials }) => { - return fetch(MASTODON_FAVORITE_URL(id), { - headers: authHeaders(credentials), - method: 'POST' - }) - .then(response => { - if (response.ok) { - return response.json() - } else { - throw new Error('Error favoriting post') - } - }) + return promisedRequest({ url: MASTODON_FAVORITE_URL(id), method: 'POST', credentials }) .then((data) => parseStatus(data)) } const unfavorite = ({ id, credentials }) => { - return fetch(MASTODON_UNFAVORITE_URL(id), { - headers: authHeaders(credentials), - method: 'POST' - }) - .then(response => { - if (response.ok) { - return response.json() - } else { - throw new Error('Error removing favorite') - } - }) + return promisedRequest({ url: MASTODON_UNFAVORITE_URL(id), method: 'POST', credentials }) .then((data) => parseStatus(data)) } const retweet = ({ id, credentials }) => { - return fetch(MASTODON_RETWEET_URL(id), { - headers: authHeaders(credentials), - method: 'POST' - }) - .then(response => { - if (response.ok) { - return response.json() - } else { - throw new Error('Error repeating post') - } - }) + return promisedRequest({ url: MASTODON_RETWEET_URL(id), method: 'POST', credentials }) .then((data) => parseStatus(data)) } const unretweet = ({ id, credentials }) => { - return fetch(MASTODON_UNRETWEET_URL(id), { - headers: authHeaders(credentials), - method: 'POST' - }) - .then(response => { - if (response.ok) { - return response.json() - } else { - throw new Error('Error removing repeat') - } - }) + return promisedRequest({ url: MASTODON_UNRETWEET_URL(id), method: 'POST', credentials }) .then((data) => parseStatus(data)) } -- cgit v1.2.3-70-g09d2