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/backend_interactor_service/backend_interactor_service.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'src/services/backend_interactor_service') diff --git a/src/services/backend_interactor_service/backend_interactor_service.js b/src/services/backend_interactor_service/backend_interactor_service.js index 75bba92b..5faec9af 100644 --- a/src/services/backend_interactor_service/backend_interactor_service.js +++ b/src/services/backend_interactor_service/backend_interactor_service.js @@ -112,6 +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 backendInteractorServiceInstance = { fetchStatus, fetchConversation, @@ -152,7 +153,8 @@ const backendInteractorService = (credentials) => { changePassword, fetchFollowRequests, approveUser, - denyUser + denyUser, + fetchFavouritedByUsers, } return backendInteractorServiceInstance -- 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/backend_interactor_service') 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 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/backend_interactor_service') 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 8ed4eb8a7ffe0e370cfc06017d2bce34b2c9d987 Mon Sep 17 00:00:00 2001 From: Brenden Bice Date: Tue, 9 Apr 2019 11:45:33 -0400 Subject: refactor showing favs and repeats logic --- src/components/conversation/conversation.js | 6 ++-- src/components/status/status.js | 7 +++- src/components/status/status.vue | 8 ++--- src/components/timeline/timeline.vue | 3 +- src/modules/statuses.js | 39 +++++----------------- .../backend_interactor_service.js | 4 +-- 6 files changed, 23 insertions(+), 44 deletions(-) (limited to 'src/services/backend_interactor_service') diff --git a/src/components/conversation/conversation.js b/src/components/conversation/conversation.js index 5cc7f4ee..ffeb7244 100644 --- a/src/components/conversation/conversation.js +++ b/src/components/conversation/conversation.js @@ -41,8 +41,7 @@ const conversation = { props: [ 'statusoid', 'collapsable', - 'isPage', - 'timelineName' + 'isPage' ], created () { if (this.isPage) { @@ -121,8 +120,6 @@ const conversation = { if (this.status) { this.$store.state.api.backendInteractor.fetchConversation({id: this.status.id}) .then(({ancestors, descendants}) => { - this.$store.dispatch('fetchFavoritedByUsers', { id: this.statusId, retweetedStatusId: this.status.id, timelineName: this.timelineName }) - this.$store.dispatch('fetchRebloggedByUsers', { id: this.statusId, retweetedStatusId: this.status.id, timelineName: this.timelineName }) this.$store.dispatch('addNewStatuses', { statuses: ancestors }) this.$store.dispatch('addNewStatuses', { statuses: descendants }) }) @@ -142,6 +139,7 @@ const conversation = { }, setHighlight (id) { this.highlight = id + this.$store.dispatch('fetchFavsAndRepeats', id) }, getHighlight () { return this.isExpanded ? this.highlight : null diff --git a/src/components/status/status.js b/src/components/status/status.js index 44caf3af..db234ec1 100644 --- a/src/components/status/status.js +++ b/src/components/status/status.js @@ -98,6 +98,10 @@ const Status = { return this.statusoid } }, + statusFromGlobalRepository () { + // NOTE: Consider to replace status with statusFromGlobalRepository + return this.$store.state.statuses.allStatusesObject[this.status.id] + }, loggedIn () { return !!this.$store.state.users.currentUser }, @@ -260,7 +264,8 @@ const Status = { return this.status.summary_html + '
' + this.status.statusnet_html }, combinedFavsAndRepeatsAvatars () { - const combinedAvatars = [].concat(this.statusoid.favoritedBy, this.statusoid.rebloggedBy).filter(_ => _) + // Use the status from the global status repository since favs and repeats are saved in it + const combinedAvatars = [].concat(this.statusFromGlobalRepository.favoritedBy, this.statusFromGlobalRepository.rebloggedBy).filter(_ => _) return uniqBy(combinedAvatars, 'id') } }, diff --git a/src/components/status/status.vue b/src/components/status/status.vue index 34bb64d0..b0882964 100644 --- a/src/components/status/status.vue +++ b/src/components/status/status.vue @@ -136,13 +136,13 @@
    -
  • +
  • {{ $t('settings.notification_visibility_repeats') }} -
    {{ statusoid.rebloggedBy.length }}
    +
    {{ statusFromGlobalRepository.rebloggedBy.length }}
  • -
  • +
  • {{ $t('user_card.favorites') }} -
    {{ statusoid.favoritedBy.length }}
    +
    {{ statusFromGlobalRepository.favoritedBy.length }}
  • diff --git a/src/components/timeline/timeline.vue b/src/components/timeline/timeline.vue index 147e8a1d..e6a8d458 100644 --- a/src/components/timeline/timeline.vue +++ b/src/components/timeline/timeline.vue @@ -16,13 +16,12 @@
-
diff --git a/src/modules/statuses.js b/src/modules/statuses.js index 023f132e..527cafc2 100644 --- a/src/modules/statuses.js +++ b/src/modules/statuses.js @@ -460,32 +460,11 @@ export const mutations = { queueFlush (state, { timeline, id }) { state.timelines[timeline].flushMarker = id }, - addFavoritedByUsers (state, { favoritedByUsers, id, timelineName }) { - if (timelineName) { - state.timelines[timelineName].visibleStatusesObject[id] = { - ...state.timelines[timelineName].visibleStatusesObject[id], - favoritedBy: favoritedByUsers - } - state.timelines[timelineName].visibleStatuses = state.timelines[timelineName].visibleStatuses.map(visibleStatus => visibleStatus.id === id ? { ...visibleStatus, favoritedBy: favoritedByUsers } : visibleStatus) - } else { - state.allStatusesObject[id] = { - ...state.allStatusesObject[id], - favoritedBy: favoritedByUsers - } - } - }, - addRebloggedByUsers (state, { rebloggedByUsers, id, timelineName }) { - if (timelineName) { - state.timelines[timelineName].visibleStatusesObject[id] = { - ...state.timelines[timelineName].visibleStatusesObject[id], - rebloggedBy: rebloggedByUsers - } - state.timelines[timelineName].visibleStatuses = state.timelines[timelineName].visibleStatuses.map(visibleStatus => visibleStatus.id === id ? { ...visibleStatus, rebloggedBy: rebloggedByUsers } : visibleStatus) - } else { - state.allStatusesObject[id] = { - ...state.allStatusesObject[id], - rebloggedBy: rebloggedByUsers - } + addFavsAndRepeats (state, { id, favoritedByUsers, rebloggedByUsers }) { + state.allStatusesObject[id] = { + ...state.allStatusesObject[id], + favoritedBy: favoritedByUsers, + rebloggedBy: rebloggedByUsers } } } @@ -553,11 +532,9 @@ const statuses = { credentials: rootState.users.currentUser.credentials }) }, - fetchFavoritedByUsers ({ rootState, commit }, { id, retweetedStatusId, timelineName }) { - rootState.api.backendInteractor.fetchFavoritedByUsers({id}).then((favoritedByUsers) => commit('addFavoritedByUsers', { favoritedByUsers, id: retweetedStatusId, timelineName })) - }, - fetchRebloggedByUsers ({ rootState, commit }, { id, retweetedStatusId, timelineName }) { - rootState.api.backendInteractor.fetchRebloggedByUsers({id}).then((rebloggedByUsers) => commit('addRebloggedByUsers', { rebloggedByUsers, id: retweetedStatusId, timelineName })) + fetchFavsAndRepeats ({ rootState, commit }, id) { + Promise.all([rootState.api.backendInteractor.fetchFavoritedByUsers(id), rootState.api.backendInteractor.fetchRebloggedByUsers(id)]) + .then(([favoritedByUsers, rebloggedByUsers]) => commit('addFavsAndRepeats', { id, favoritedByUsers, rebloggedByUsers })) } }, mutations diff --git a/src/services/backend_interactor_service/backend_interactor_service.js b/src/services/backend_interactor_service/backend_interactor_service.js index 0768c806..c6742d26 100644 --- a/src/services/backend_interactor_service/backend_interactor_service.js +++ b/src/services/backend_interactor_service/backend_interactor_service.js @@ -112,8 +112,8 @@ const backendInteractorService = (credentials) => { const deleteAccount = ({password}) => apiService.deleteAccount({credentials, password}) const changePassword = ({password, newPassword, newPasswordConfirmation}) => apiService.changePassword({credentials, password, newPassword, newPasswordConfirmation}) - const fetchFavoritedByUsers = ({id}) => apiService.fetchFavoritedByUsers({id}) - const fetchRebloggedByUsers = ({id}) => apiService.fetchRebloggedByUsers({id}) + const fetchFavoritedByUsers = (id) => apiService.fetchFavoritedByUsers({id}) + const fetchRebloggedByUsers = (id) => apiService.fetchRebloggedByUsers({id}) const backendInteractorServiceInstance = { fetchStatus, -- 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/backend_interactor_service') 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/backend_interactor_service') 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 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/backend_interactor_service') 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/backend_interactor_service') 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/backend_interactor_service') 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 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/backend_interactor_service') 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 7d60ab322ed996b067242c3f047f90814f9c8f7c Mon Sep 17 00:00:00 2001 From: taehoon Date: Tue, 7 May 2019 23:36:35 -0400 Subject: use backendInteractor --- src/modules/statuses.js | 11 ++++++----- .../backend_interactor_service/backend_interactor_service.js | 11 ++++++++++- 2 files changed, 16 insertions(+), 6 deletions(-) (limited to 'src/services/backend_interactor_service') diff --git a/src/modules/statuses.js b/src/modules/statuses.js index 527789f8..4c92d4e1 100644 --- a/src/modules/statuses.js +++ b/src/modules/statuses.js @@ -524,24 +524,25 @@ const statuses = { favorite ({ rootState, commit }, status) { // Optimistic favoriting... commit('setFavorited', { status, value: true }) - apiService.favorite({ id: status.id, credentials: rootState.users.currentUser.credentials }) + rootState.api.backendInteractor.favorite(status.id) .then(status => commit('setFavoritedConfirm', { status, user: rootState.users.currentUser })) }, unfavorite ({ rootState, commit }, status) { - // Optimistic favoriting... + // Optimistic unfavoriting... commit('setFavorited', { status, value: false }) - apiService.unfavorite({ id: status.id, credentials: rootState.users.currentUser.credentials }) + rootState.api.backendInteractor.unfavorite(status.id) .then(status => commit('setFavoritedConfirm', { status, user: rootState.users.currentUser })) }, retweet ({ rootState, commit }, status) { // Optimistic retweeting... commit('setRetweeted', { status, value: true }) - apiService.retweet({ id: status.id, credentials: rootState.users.currentUser.credentials }) + rootState.api.backendInteractor.retweet(status.id) .then(status => commit('setRetweetedConfirm', { status: status.retweeted_status, user: rootState.users.currentUser })) }, unretweet ({ rootState, commit }, status) { + // Optimistic unretweeting... commit('setRetweeted', { status, value: false }) - apiService.unretweet({ id: status.id, credentials: rootState.users.currentUser.credentials }) + rootState.api.backendInteractor.unretweet(status.id) .then(status => commit('setRetweetedConfirm', { status, user: rootState.users.currentUser })) }, queueFlush ({ rootState, commit }, { timeline, id }) { diff --git a/src/services/backend_interactor_service/backend_interactor_service.js b/src/services/backend_interactor_service/backend_interactor_service.js index 58bb1248..c2b93de4 100644 --- a/src/services/backend_interactor_service/backend_interactor_service.js +++ b/src/services/backend_interactor_service/backend_interactor_service.js @@ -117,6 +117,11 @@ const backendInteractorService = (credentials) => { const fetchRebloggedByUsers = (id) => apiService.fetchRebloggedByUsers({id}) const reportUser = (params) => apiService.reportUser({credentials, ...params}) + const favorite = (id) => apiService.favorite({id, credentials}) + const unfavorite = (id) => apiService.unfavorite({id, credentials}) + const retweet = (id) => apiService.retweet({id, credentials}) + const unretweet = (id) => apiService.unretweet({id, credentials}) + const backendInteractorServiceInstance = { fetchStatus, fetchConversation, @@ -161,7 +166,11 @@ const backendInteractorService = (credentials) => { denyUser, fetchFavoritedByUsers, fetchRebloggedByUsers, - reportUser + reportUser, + favorite, + unfavorite, + retweet, + unretweet } return backendInteractorServiceInstance -- cgit v1.2.3-70-g09d2