From 8721fb57fc3ee169ba401ce498280b8d7257297d Mon Sep 17 00:00:00 2001 From: Maksim Pechnikov Date: Sat, 21 Sep 2019 16:24:47 +0300 Subject: [PATCH] added support hide\show reblogs from a specific user --- src/components/user_card/user_card.js | 15 +++++++++++++-- src/components/user_card/user_card.vue | 16 ++++++++++++++++ src/i18n/en.json | 2 ++ src/modules/users.js | 19 +++++++++++++++++++ src/services/api/api.service.js | 5 ++++- .../backend_interactor_service.js | 4 ++-- .../entity_normalizer.service.js | 1 + .../follow_manipulate/follow_manipulate.js | 2 +- 8 files changed, 58 insertions(+), 6 deletions(-) diff --git a/src/components/user_card/user_card.js b/src/components/user_card/user_card.js index e3bd769789..03f15d8e52 100644 --- a/src/components/user_card/user_card.js +++ b/src/components/user_card/user_card.js @@ -7,7 +7,9 @@ import { requestFollow, requestUnfollow } from '../../services/follow_manipulate import generateProfileLink from 'src/services/user_profile_link_generator/user_profile_link_generator' export default { - props: [ 'user', 'switcher', 'selected', 'hideBio', 'rounded', 'bordered', 'allowZoomingAvatar' ], + props: [ + 'user', 'switcher', 'selected', 'hideBio', 'rounded', 'bordered', 'allowZoomingAvatar' + ], data () { return { followRequestInProgress: false, @@ -108,6 +110,12 @@ export default { ProgressButton }, methods: { + showReblogs () { + this.$store.dispatch('showReblogs', this.user.id) + }, + hideReblogs () { + this.$store.dispatch('hideReblogs', this.user.id) + }, followUser () { const store = this.$store this.followRequestInProgress = true @@ -156,7 +164,10 @@ export default { } }, userProfileLink (user) { - return generateProfileLink(user.id, user.screen_name, this.$store.state.instance.restrictedNicknames) + return generateProfileLink( + user.id, user.screen_name, + this.$store.state.instance.restrictedNicknames + ) }, reportUser () { this.$store.dispatch('openUserReportingModal', this.user.id) diff --git a/src/components/user_card/user_card.vue b/src/components/user_card/user_card.vue index 0b83cf168d..029406e7d3 100644 --- a/src/components/user_card/user_card.vue +++ b/src/components/user_card/user_card.vue @@ -186,6 +186,22 @@ > + +
diff --git a/src/i18n/en.json b/src/i18n/en.json index ddde471ab8..c20f880ace 100644 --- a/src/i18n/en.json +++ b/src/i18n/en.json @@ -543,6 +543,8 @@ "unmute": "Unmute", "unmute_progress": "Unmuting...", "mute_progress": "Muting...", + "hide_boosts": "Hide boosts from {user}", + "show_boosts": "Show boosts from {user}", "admin_menu": { "moderation": "Moderation", "grant_admin": "Grant Admin", diff --git a/src/modules/users.js b/src/modules/users.js index 4d02f8d749..6d259dc2ac 100644 --- a/src/modules/users.js +++ b/src/modules/users.js @@ -60,6 +60,18 @@ const unmuteUser = (store, id) => { .then((relationship) => store.commit('updateUserRelationship', [relationship])) } +const hideReblogs = (store, userId) => { + return store.rootState.api.backendInteractor.followUser({ id: userId, reblogs: false }) + .then((relationship) => { + store.commit('updateUserRelationship', [relationship]) + }) +} + +const showReblogs = (store, userId) => { + return store.rootState.api.backendInteractor.followUser({ id: userId, reblogs: true }) + .then((relationship) => store.commit('updateUserRelationship', [relationship])) +} + export const mutations = { setMuted (state, { user: { id }, muted }) { const user = state.usersObject[id] @@ -135,6 +147,7 @@ export const mutations = { user.muted = relationship.muting user.statusnet_blocking = relationship.blocking user.subscribed = relationship.subscribing + user.showing_reblogs = relationship.showing_reblogs } }) }, @@ -272,6 +285,12 @@ const users = { unmuteUser (store, id) { return unmuteUser(store, id) }, + hideReblogs (store, id) { + return hideReblogs(store, id) + }, + showReblogs (store, id) { + return showReblogs(store, id) + }, muteUsers (store, ids = []) { return Promise.all(ids.map(id => muteUser(store, id))) }, diff --git a/src/services/api/api.service.js b/src/services/api/api.service.js index 887d7d7aab..80e94a5024 100644 --- a/src/services/api/api.service.js +++ b/src/services/api/api.service.js @@ -219,9 +219,12 @@ const authHeaders = (accessToken) => { } } -const followUser = ({ id, credentials }) => { +const followUser = ({ id, reblogs, credentials }) => { let url = MASTODON_FOLLOW_URL(id) + const form = new FormData() + if (reblogs !== undefined) { form.append('reblogs', reblogs) } return fetch(url, { + body: form, headers: authHeaders(credentials), method: 'POST' }).then((data) => data.json()) diff --git a/src/services/backend_interactor_service/backend_interactor_service.js b/src/services/backend_interactor_service/backend_interactor_service.js index 3c44a10cb7..cbf48ee418 100644 --- a/src/services/backend_interactor_service/backend_interactor_service.js +++ b/src/services/backend_interactor_service/backend_interactor_service.js @@ -31,8 +31,8 @@ const backendInteractorService = credentials => { return apiService.fetchUserRelationship({ id, credentials }) } - const followUser = (id) => { - return apiService.followUser({ credentials, id }) + const followUser = ({ id, reblogs }) => { + return apiService.followUser({ credentials, id, reblogs }) } const unfollowUser = (id) => { diff --git a/src/services/entity_normalizer/entity_normalizer.service.js b/src/services/entity_normalizer/entity_normalizer.service.js index 7438cd9069..906838fde1 100644 --- a/src/services/entity_normalizer/entity_normalizer.service.js +++ b/src/services/entity_normalizer/entity_normalizer.service.js @@ -69,6 +69,7 @@ export const parseUser = (data) => { output.following = relationship.following output.statusnet_blocking = relationship.blocking output.muted = relationship.muting + output.showing_reblogs = relationship.showing_reblogs output.subscribed = relationship.subscribing } diff --git a/src/services/follow_manipulate/follow_manipulate.js b/src/services/follow_manipulate/follow_manipulate.js index d82ce59348..598cb5f726 100644 --- a/src/services/follow_manipulate/follow_manipulate.js +++ b/src/services/follow_manipulate/follow_manipulate.js @@ -14,7 +14,7 @@ const fetchUser = (attempt, user, store) => new Promise((resolve, reject) => { }) export const requestFollow = (user, store) => new Promise((resolve, reject) => { - store.state.api.backendInteractor.followUser(user.id) + store.state.api.backendInteractor.followUser({ id: user.id }) .then((updated) => { store.commit('updateUserRelationship', [updated])