From 608d1e6776769b933e194f96b4892a888880f60f Mon Sep 17 00:00:00 2001 From: eal Date: Tue, 7 Nov 2017 22:38:28 +0200 Subject: [PATCH] Add blocks. --- .../user_card_content/user_card_content.vue | 22 +++++++++++++++++++ src/i18n/messages.js | 2 ++ src/services/api/api.service.js | 20 +++++++++++++++++ .../backend_interactor_service.js | 10 +++++++++ 4 files changed, 54 insertions(+) diff --git a/src/components/user_card_content/user_card_content.vue b/src/components/user_card_content/user_card_content.vue index 4895f36f..8aef7e8a 100644 --- a/src/components/user_card_content/user_card_content.vue +++ b/src/components/user_card_content/user_card_content.vue @@ -46,6 +46,18 @@ +
+ + + + + + +
@@ -113,6 +125,16 @@ store.state.api.backendInteractor.unfollowUser(this.user.id) .then((unfollowedUser) => store.commit('addNewUsers', [unfollowedUser])) }, + blockUser () { + const store = this.$store + store.state.api.backendInteractor.blockUser(this.user.id) + .then((blockedUser) => store.commit('addNewUsers', [blockedUser])) + }, + unblockUser () { + const store = this.$store + store.state.api.backendInteractor.unblockUser(this.user.id) + .then((unblockedUser) => store.commit('addNewUsers', [unblockedUser])) + }, toggleMute () { const store = this.$store store.commit('setMuted', {user: this.user, muted: !this.user.muted}) diff --git a/src/i18n/messages.js b/src/i18n/messages.js index 3cbde819..3102d946 100644 --- a/src/i18n/messages.js +++ b/src/i18n/messages.js @@ -125,6 +125,8 @@ const en = { follows_you: 'Follows you!', following: 'Following!', follow: 'Follow', + blocked: 'Blocked!', + block: 'Block', statuses: 'Statuses', mute: 'Mute', muted: 'Muted', diff --git a/src/services/api/api.service.js b/src/services/api/api.service.js index a1c6b657..5abaea7e 100644 --- a/src/services/api/api.service.js +++ b/src/services/api/api.service.js @@ -26,6 +26,8 @@ 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_TIMELINE_URL = '/api/qvitter/statuses/user_timeline.json' +const BLOCKING_URL = '/api/blocks/create.json' +const UNBLOCKING_URL = '/api/blocks/destroy.json' // const USER_URL = '/api/users/show.json' import { each, map } from 'lodash' @@ -184,6 +186,22 @@ const unfollowUser = ({id, credentials}) => { }).then((data) => data.json()) } +const blockUser = ({id, credentials}) => { + let url = `${BLOCKING_URL}?user_id=${id}` + return fetch(url, { + headers: authHeaders(credentials), + method: 'POST' + }).then((data) => data.json()) +} + +const unblockUser = ({id, credentials}) => { + let url = `${UNBLOCKING_URL}?user_id=${id}` + return fetch(url, { + headers: authHeaders(credentials), + method: 'POST' + }).then((data) => data.json()) +} + const fetchFriends = ({id, credentials}) => { let url = `${FRIENDS_URL}?user_id=${id}` return fetch(url, { headers: authHeaders(credentials) }) @@ -343,6 +361,8 @@ const apiService = { fetchFollowers, followUser, unfollowUser, + blockUser, + unblockUser, favorite, unfavorite, retweet, diff --git a/src/services/backend_interactor_service/backend_interactor_service.js b/src/services/backend_interactor_service/backend_interactor_service.js index a99ea38a..51a46e45 100644 --- a/src/services/backend_interactor_service/backend_interactor_service.js +++ b/src/services/backend_interactor_service/backend_interactor_service.js @@ -30,6 +30,14 @@ const backendInteractorService = (credentials) => { return apiService.unfollowUser({credentials, id}) } + const blockUser = (id) => { + return apiService.blockUser({credentials, id}) + } + + const unblockUser = (id) => { + return apiService.unblockUser({credentials, id}) + } + const startFetching = ({timeline, store, userId = false}) => { return timelineFetcherService.startFetching({timeline, store, credentials, userId}) } @@ -55,6 +63,8 @@ const backendInteractorService = (credentials) => { fetchFollowers, followUser, unfollowUser, + blockUser, + unblockUser, fetchAllFollowing, verifyCredentials: apiService.verifyCredentials, startFetching,