From e5879e3d4d26f6e98e80208b6df5577971989972 Mon Sep 17 00:00:00 2001 From: shpuld Date: Sun, 7 Jul 2019 22:23:04 +0300 Subject: [PATCH 01/34] check for user before checking users props --- src/components/status/status.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/components/status/status.js b/src/components/status/status.js index 199351cb..4b3499cd 100644 --- a/src/components/status/status.js +++ b/src/components/status/status.js @@ -173,12 +173,13 @@ const Status = { if (this.status.type === 'retweet') { return false } - var checkFollowing = this.$store.state.config.replyVisibility === 'following' + const checkFollowing = this.$store.state.config.replyVisibility === 'following' for (var i = 0; i < this.status.attentions.length; ++i) { if (this.status.user.id === this.status.attentions[i].id) { continue } - if (checkFollowing && this.$store.getters.findUser(this.status.attentions[i].id).following) { + const taggedUser = this.$store.getters.findUser(this.status.attentions[i].id) + if (checkFollowing && taggedUser && taggedUser.following) { return false } if (this.status.attentions[i].id === this.$store.state.users.currentUser.id) { From 17498ef906b79dd68276faa2a5624b90f3f0bc2b Mon Sep 17 00:00:00 2001 From: taehoon Date: Mon, 24 Jun 2019 04:21:09 -0400 Subject: [PATCH 02/34] update favs and repeats stats using favoritedByUsers and rebloggedByUsers data --- src/modules/statuses.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/modules/statuses.js b/src/modules/statuses.js index cf65c9f4..514f3081 100644 --- a/src/modules/statuses.js +++ b/src/modules/statuses.js @@ -492,10 +492,15 @@ export const mutations = { queueFlush (state, { timeline, id }) { state.timelines[timeline].flushMarker = id }, - addFavsAndRepeats (state, { id, favoritedByUsers, rebloggedByUsers }) { + addFavsAndRepeats (state, { id, favoritedByUsers, rebloggedByUsers, currentUser }) { const newStatus = state.allStatusesObject[id] newStatus.favoritedBy = favoritedByUsers.filter(_ => _) newStatus.rebloggedBy = rebloggedByUsers.filter(_ => _) + // favorites and repeats stats can be incorrect based on polling condition, let's update them using the most recent data + newStatus.fave_num = newStatus.favoritedBy.length + newStatus.repeat_num = newStatus.rebloggedBy.length + newStatus.favorited = !!newStatus.favoritedBy.find(({ id }) => currentUser.id === id) + newStatus.repeated = !!newStatus.rebloggedBy.find(({ id }) => currentUser.id === id) }, updateStatusWithPoll (state, { id, poll }) { const status = state.allStatusesObject[id] @@ -582,7 +587,7 @@ const statuses = { rootState.api.backendInteractor.fetchFavoritedByUsers(id), rootState.api.backendInteractor.fetchRebloggedByUsers(id) ]).then(([favoritedByUsers, rebloggedByUsers]) => - commit('addFavsAndRepeats', { id, favoritedByUsers, rebloggedByUsers }) + commit('addFavsAndRepeats', { id, favoritedByUsers, rebloggedByUsers, currentUser: rootState.users.currentUser }) ) } }, From e9b6e0e2b74ac4f9c8558c3329c70eee1c869abc Mon Sep 17 00:00:00 2001 From: taehoon Date: Mon, 24 Jun 2019 05:19:43 -0400 Subject: [PATCH 03/34] refetch favs and repeats when stats are changed --- src/components/status/status.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/components/status/status.js b/src/components/status/status.js index 4b3499cd..6f83dbe0 100644 --- a/src/components/status/status.js +++ b/src/components/status/status.js @@ -402,6 +402,9 @@ const Status = { setMedia () { const attachments = this.attachmentSize === 'hide' ? this.status.attachments : this.galleryAttachments return () => this.$store.dispatch('setMedia', attachments) + }, + refetchFavsAndRepeats () { + this.$store.dispatch('fetchFavsAndRepeats', this.status.id) } }, watch: { @@ -419,6 +422,16 @@ const Status = { window.scrollBy(0, rect.bottom - window.innerHeight + 50) } } + }, + 'status.repeat_num': function (num) { + if (this.isFocused && this.statusFromGlobalRepository.rebloggedBy && this.statusFromGlobalRepository.rebloggedBy.length !== num) { + this.refetchFavsAndRepeats() + } + }, + 'status.fave_num': function (num) { + if (this.isFocused && this.statusFromGlobalRepository.favoritedBy && this.statusFromGlobalRepository.favoritedBy.length !== num) { + this.refetchFavsAndRepeats() + } } }, filters: { From ab4d7d9616319778b7ed5d79ca1f389c9e439113 Mon Sep 17 00:00:00 2001 From: taehoon Date: Thu, 27 Jun 2019 08:14:54 -0400 Subject: [PATCH 04/34] refetch favs and repeats separately --- src/components/status/status.js | 7 ++----- src/modules/statuses.js | 29 +++++++++++++++++++++-------- 2 files changed, 23 insertions(+), 13 deletions(-) diff --git a/src/components/status/status.js b/src/components/status/status.js index 6f83dbe0..284c657c 100644 --- a/src/components/status/status.js +++ b/src/components/status/status.js @@ -402,9 +402,6 @@ const Status = { setMedia () { const attachments = this.attachmentSize === 'hide' ? this.status.attachments : this.galleryAttachments return () => this.$store.dispatch('setMedia', attachments) - }, - refetchFavsAndRepeats () { - this.$store.dispatch('fetchFavsAndRepeats', this.status.id) } }, watch: { @@ -425,12 +422,12 @@ const Status = { }, 'status.repeat_num': function (num) { if (this.isFocused && this.statusFromGlobalRepository.rebloggedBy && this.statusFromGlobalRepository.rebloggedBy.length !== num) { - this.refetchFavsAndRepeats() + this.$store.dispatch('fetchRepeats', this.status.id) } }, 'status.fave_num': function (num) { if (this.isFocused && this.statusFromGlobalRepository.favoritedBy && this.statusFromGlobalRepository.favoritedBy.length !== num) { - this.refetchFavsAndRepeats() + this.$store.dispatch('fetchFavs', this.status.id) } } }, diff --git a/src/modules/statuses.js b/src/modules/statuses.js index 514f3081..9d8d768c 100644 --- a/src/modules/statuses.js +++ b/src/modules/statuses.js @@ -492,15 +492,19 @@ export const mutations = { queueFlush (state, { timeline, id }) { state.timelines[timeline].flushMarker = id }, - addFavsAndRepeats (state, { id, favoritedByUsers, rebloggedByUsers, currentUser }) { + addRepeats (state, { id, rebloggedByUsers, currentUser }) { + const newStatus = state.allStatusesObject[id] + newStatus.rebloggedBy = rebloggedByUsers.filter(_ => _) + // repeats stats can be incorrect based on polling condition, let's update them using the most recent data + newStatus.repeat_num = newStatus.rebloggedBy.length + newStatus.repeated = !!newStatus.rebloggedBy.find(({ id }) => currentUser.id === id) + }, + addFavs (state, { id, favoritedByUsers, currentUser }) { const newStatus = state.allStatusesObject[id] newStatus.favoritedBy = favoritedByUsers.filter(_ => _) - newStatus.rebloggedBy = rebloggedByUsers.filter(_ => _) - // favorites and repeats stats can be incorrect based on polling condition, let's update them using the most recent data + // favorites stats can be incorrect based on polling condition, let's update them using the most recent data newStatus.fave_num = newStatus.favoritedBy.length - newStatus.repeat_num = newStatus.rebloggedBy.length newStatus.favorited = !!newStatus.favoritedBy.find(({ id }) => currentUser.id === id) - newStatus.repeated = !!newStatus.rebloggedBy.find(({ id }) => currentUser.id === id) }, updateStatusWithPoll (state, { id, poll }) { const status = state.allStatusesObject[id] @@ -586,9 +590,18 @@ const statuses = { Promise.all([ rootState.api.backendInteractor.fetchFavoritedByUsers(id), rootState.api.backendInteractor.fetchRebloggedByUsers(id) - ]).then(([favoritedByUsers, rebloggedByUsers]) => - commit('addFavsAndRepeats', { id, favoritedByUsers, rebloggedByUsers, currentUser: rootState.users.currentUser }) - ) + ]).then(([favoritedByUsers, rebloggedByUsers]) => { + commit('addFavs', { id, favoritedByUsers, currentUser: rootState.users.currentUser }) + commit('addRepeats', { id, rebloggedByUsers, currentUser: rootState.users.currentUser }) + }) + }, + fetchFavs ({ rootState, commit }, id) { + rootState.api.backendInteractor.fetchFavoritedByUsers(id) + .then(favoritedByUsers => commit('addFavs', { id, favoritedByUsers, currentUser: rootState.users.currentUser })) + }, + fetchRepeats ({ rootState, commit }, id) { + rootState.api.backendInteractor.fetchRebloggedByUsers(id) + .then(rebloggedByUsers => commit('addRepeats', { id, rebloggedByUsers, currentUser: rootState.users.currentUser })) } }, mutations From 0131effb013025edae843ed7c92ef8fdf43a3623 Mon Sep 17 00:00:00 2001 From: taehoon Date: Thu, 27 Jun 2019 08:19:35 -0400 Subject: [PATCH 05/34] add comments --- src/components/status/status.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/components/status/status.js b/src/components/status/status.js index 284c657c..7911d40d 100644 --- a/src/components/status/status.js +++ b/src/components/status/status.js @@ -421,11 +421,13 @@ const Status = { } }, 'status.repeat_num': function (num) { + // refetch repeats when repeat_num is changed in any way if (this.isFocused && this.statusFromGlobalRepository.rebloggedBy && this.statusFromGlobalRepository.rebloggedBy.length !== num) { this.$store.dispatch('fetchRepeats', this.status.id) } }, 'status.fave_num': function (num) { + // refetch favs when fave_num is changed in any way if (this.isFocused && this.statusFromGlobalRepository.favoritedBy && this.statusFromGlobalRepository.favoritedBy.length !== num) { this.$store.dispatch('fetchFavs', this.status.id) } From 532b76eb64119848d424d6d0d644a72d817fba59 Mon Sep 17 00:00:00 2001 From: Tae Hoon Date: Wed, 10 Jul 2019 16:58:49 +0000 Subject: [PATCH 06/34] Refactor user search api, better api error response handling --- src/components/user_search/user_search.js | 8 ++--- src/components/user_settings/user_settings.js | 8 ++--- src/modules/users.js | 10 +----- src/services/api/api.service.js | 23 ++++++++++-- .../backend_interactor_service.js | 5 ++- src/services/new_api/user_search.js | 20 ----------- src/services/new_api/utils.js | 36 ------------------- 7 files changed, 31 insertions(+), 79 deletions(-) delete mode 100644 src/services/new_api/user_search.js delete mode 100644 src/services/new_api/utils.js diff --git a/src/components/user_search/user_search.js b/src/components/user_search/user_search.js index 62dafdf1..5c29d8f2 100644 --- a/src/components/user_search/user_search.js +++ b/src/components/user_search/user_search.js @@ -35,15 +35,13 @@ const userSearch = { }, search (query) { if (!query) { - this.users = [] return } this.loading = true + this.userIds = [] this.$store.dispatch('searchUsers', query) - .then((res) => { - this.loading = false - this.userIds = map(res, 'id') - }) + .then((res) => { this.userIds = map(res, 'id') }) + .finally(() => { this.loading = false }) } } } diff --git a/src/components/user_settings/user_settings.js b/src/components/user_settings/user_settings.js index 19f4604f..0c3b2aef 100644 --- a/src/components/user_settings/user_settings.js +++ b/src/components/user_settings/user_settings.js @@ -17,7 +17,6 @@ import Autosuggest from '../autosuggest/autosuggest.vue' import Importer from '../importer/importer.vue' import Exporter from '../exporter/exporter.vue' import withSubscription from '../../hocs/with_subscription/with_subscription' -import userSearchApi from '../../services/new_api/user_search.js' import Mfa from './mfa.vue' const BlockList = withSubscription({ @@ -322,11 +321,8 @@ const UserSettings = { }) }, queryUserIds (query) { - return userSearchApi.search({ query, store: this.$store }) - .then((users) => { - this.$store.dispatch('addNewUsers', users) - return map(users, 'id') - }) + return this.$store.dispatch('searchUsers', query) + .then((users) => map(users, 'id')) }, blockUsers (ids) { return this.$store.dispatch('blockUsers', ids) diff --git a/src/modules/users.js b/src/modules/users.js index 6c7a96f6..453a6899 100644 --- a/src/modules/users.js +++ b/src/modules/users.js @@ -1,5 +1,4 @@ import backendInteractorService from '../services/backend_interactor_service/backend_interactor_service.js' -import userSearchApi from '../services/new_api/user_search.js' import oauthApi from '../services/new_api/oauth.js' import { compact, map, each, merge, last, concat, uniq } from 'lodash' import { set } from 'vue' @@ -356,14 +355,7 @@ const users = { }) }, searchUsers (store, query) { - // TODO: Move userSearch api into api.service - return userSearchApi.search({ - query, - store: { - state: store.rootState, - getters: store.rootGetters - } - }) + return store.rootState.api.backendInteractor.searchUsers(query) .then((users) => { store.commit('addNewUsers', users) return users diff --git a/src/services/api/api.service.js b/src/services/api/api.service.js index 22db671e..304fc869 100644 --- a/src/services/api/api.service.js +++ b/src/services/api/api.service.js @@ -65,6 +65,7 @@ const MASTODON_PROFILE_UPDATE_URL = '/api/v1/accounts/update_credentials' const MASTODON_REPORT_USER_URL = '/api/v1/reports' const MASTODON_PIN_OWN_STATUS = id => `/api/v1/statuses/${id}/pin` const MASTODON_UNPIN_OWN_STATUS = id => `/api/v1/statuses/${id}/unpin` +const MASTODON_USER_SEARCH_URL = '/api/v1/accounts/search' const oldfetch = window.fetch @@ -76,7 +77,7 @@ let fetch = (url, options) => { return oldfetch(fullUrl, options) } -const promisedRequest = ({ method, url, payload, credentials, headers = {} }) => { +const promisedRequest = ({ method, url, params, payload, credentials, headers = {} }) => { const options = { method, headers: { @@ -85,6 +86,11 @@ const promisedRequest = ({ method, url, payload, credentials, headers = {} }) => ...headers } } + if (params) { + url += '?' + Object.entries(params) + .map(([key, value]) => encodeURIComponent(key) + '=' + encodeURIComponent(value)) + .join('&') + } if (payload) { options.body = JSON.stringify(payload) } @@ -837,6 +843,18 @@ const reportUser = ({ credentials, userId, statusIds, comment, forward }) => { }) } +const searchUsers = ({ credentials, query }) => { + return promisedRequest({ + url: MASTODON_USER_SEARCH_URL, + params: { + q: query, + resolve: true + }, + credentials + }) + .then((data) => data.map(parseUser)) +} + const apiService = { verifyCredentials, fetchTimeline, @@ -899,7 +917,8 @@ const apiService = { fetchFavoritedByUsers, fetchRebloggedByUsers, reportUser, - updateNotificationSettings + updateNotificationSettings, + searchUsers } 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 3550aafd..5162d38f 100644 --- a/src/services/backend_interactor_service/backend_interactor_service.js +++ b/src/services/backend_interactor_service/backend_interactor_service.js @@ -147,6 +147,8 @@ const backendInteractorService = credentials => { const retweet = (id) => apiService.retweet({ id, credentials }) const unretweet = (id) => apiService.unretweet({ id, credentials }) + const searchUsers = (query) => apiService.searchUsers({ query, credentials }) + const backendInteractorServiceInstance = { fetchStatus, fetchConversation, @@ -205,7 +207,8 @@ const backendInteractorService = credentials => { unfavorite, retweet, unretweet, - updateNotificationSettings + updateNotificationSettings, + searchUsers } return backendInteractorServiceInstance diff --git a/src/services/new_api/user_search.js b/src/services/new_api/user_search.js deleted file mode 100644 index 5936fef9..00000000 --- a/src/services/new_api/user_search.js +++ /dev/null @@ -1,20 +0,0 @@ -import utils from './utils.js' -import { parseUser } from '../entity_normalizer/entity_normalizer.service.js' - -const search = ({ query, store }) => { - return utils.request({ - store, - url: '/api/v1/accounts/search', - params: { - q: query, - resolve: true - } - }) - .then((data) => data.json()) - .then((data) => data.map(parseUser)) -} -const UserSearch = { - search -} - -export default UserSearch diff --git a/src/services/new_api/utils.js b/src/services/new_api/utils.js deleted file mode 100644 index 57111026..00000000 --- a/src/services/new_api/utils.js +++ /dev/null @@ -1,36 +0,0 @@ -const queryParams = (params) => { - return Object.keys(params) - .map(k => encodeURIComponent(k) + '=' + encodeURIComponent(params[k])) - .join('&') -} - -const headers = (store) => { - const accessToken = store.getters.getToken() - if (accessToken) { - return { 'Authorization': `Bearer ${accessToken}` } - } else { - return {} - } -} - -const request = ({ method = 'GET', url, params, store }) => { - const instance = store.state.instance.server - let fullUrl = `${instance}${url}` - - if (method === 'GET' && params) { - fullUrl = fullUrl + `?${queryParams(params)}` - } - - return window.fetch(fullUrl, { - method, - headers: headers(store), - credentials: 'same-origin' - }) -} - -const utils = { - queryParams, - request -} - -export default utils From 34d95454b35712e4c1119f02693f2e2e9cda8cc8 Mon Sep 17 00:00:00 2001 From: taehoon Date: Tue, 25 Jun 2019 12:34:30 -0400 Subject: [PATCH 07/34] add csp header to dev server --- build/dev-server.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/build/dev-server.js b/build/dev-server.js index 48574214..59dd2c4d 100644 --- a/build/dev-server.js +++ b/build/dev-server.js @@ -24,6 +24,9 @@ var devMiddleware = require('webpack-dev-middleware')(compiler, { stats: { colors: true, chunks: false + }, + headers: { + 'content-security-policy': "base-uri 'self'; frame-ancestors 'none'; img-src 'self' data: https:; media-src 'self' https:; style-src 'self' 'unsafe-inline'; font-src 'self'; manifest-src 'self'; script-src 'self' 'unsafe-eval';" } }) From f2c95f9d0bcb9fd6640d8c5d38ce6fff111b70df Mon Sep 17 00:00:00 2001 From: jared Date: Mon, 15 Apr 2019 11:42:56 -0400 Subject: [PATCH 08/34] #482 - add new endpoints to subscribe to the user --- src/services/api/api.service.js | 12 ++++++++++++ .../backend_interactor_service.js | 4 ++++ 2 files changed, 16 insertions(+) diff --git a/src/services/api/api.service.js b/src/services/api/api.service.js index 304fc869..e417cf29 100644 --- a/src/services/api/api.service.js +++ b/src/services/api/api.service.js @@ -55,6 +55,8 @@ const MASTODON_BLOCK_USER_URL = id => `/api/v1/accounts/${id}/block` const MASTODON_UNBLOCK_USER_URL = id => `/api/v1/accounts/${id}/unblock` const MASTODON_MUTE_USER_URL = id => `/api/v1/accounts/${id}/mute` const MASTODON_UNMUTE_USER_URL = id => `/api/v1/accounts/${id}/unmute` +const MASTODON_SUBSCRIBE_USER = id => `/api/v1/pleroma/accounts/${id}/subscribe` +const MASTODON_UNSUBSCRIBE_USER = id => `/api/v1/pleroma/accounts/${id}/unsubscribe` const MASTODON_POST_STATUS_URL = '/api/v1/statuses' const MASTODON_MEDIA_UPLOAD_URL = '/api/v1/media' const MASTODON_VOTE_URL = id => `/api/v1/polls/${id}/votes` @@ -752,6 +754,14 @@ const unmuteUser = ({ id, credentials }) => { return promisedRequest({ url: MASTODON_UNMUTE_USER_URL(id), credentials, method: 'POST' }) } +const subscribeUser = ({ id, credentials }) => { + return promisedRequest({ url: MASTODON_SUBSCRIBE_USER(id), credentials, method: 'POST' }) +} + +const unsubscribeUser = ({ id, credentials }) => { + return promisedRequest({ url: MASTODON_UNSUBSCRIBE_USER(id), credentials, method: 'POST' }) +} + const fetchBlocks = ({ credentials }) => { return promisedRequest({ url: MASTODON_USER_BLOCKS_URL, credentials }) .then((users) => users.map(parseUser)) @@ -882,6 +892,8 @@ const apiService = { fetchMutes, muteUser, unmuteUser, + subscribeUser, + unsubscribeUser, fetchBlocks, fetchOAuthTokens, revokeOAuthToken, diff --git a/src/services/backend_interactor_service/backend_interactor_service.js b/src/services/backend_interactor_service/backend_interactor_service.js index 5162d38f..4e1675c2 100644 --- a/src/services/backend_interactor_service/backend_interactor_service.js +++ b/src/services/backend_interactor_service/backend_interactor_service.js @@ -108,6 +108,8 @@ const backendInteractorService = credentials => { const fetchMutes = () => apiService.fetchMutes({ credentials }) const muteUser = (id) => apiService.muteUser({ credentials, id }) const unmuteUser = (id) => apiService.unmuteUser({ credentials, id }) + const subscribeUser = (id) => apiService.subscribeUser({ credentials, id }) + const unsubscribeUser = (id) => apiService.unsubscribeUser({ credentials, id }) const fetchBlocks = () => apiService.fetchBlocks({ credentials }) const fetchFollowRequests = () => apiService.fetchFollowRequests({ credentials }) const fetchOAuthTokens = () => apiService.fetchOAuthTokens({ credentials }) @@ -167,6 +169,8 @@ const backendInteractorService = credentials => { fetchMutes, muteUser, unmuteUser, + subscribeUser, + unsubscribeUser, fetchBlocks, fetchOAuthTokens, revokeOAuthToken, From d5e8315e83327c7b8dda71eca5dd1c9d7d0a23dc Mon Sep 17 00:00:00 2001 From: jared Date: Tue, 16 Apr 2019 10:13:26 -0400 Subject: [PATCH 09/34] #482 - add subscribe button --- .../subscribe_button/subscribe_button.js | 26 ++ .../subscribe_button/subscribe_button.vue | 22 ++ src/components/user_card/user_card.js | 4 +- src/components/user_card/user_card.vue | 369 ++++++------------ src/modules/users.js | 1 + 5 files changed, 174 insertions(+), 248 deletions(-) create mode 100644 src/components/subscribe_button/subscribe_button.js create mode 100644 src/components/subscribe_button/subscribe_button.vue diff --git a/src/components/subscribe_button/subscribe_button.js b/src/components/subscribe_button/subscribe_button.js new file mode 100644 index 00000000..e3a2842c --- /dev/null +++ b/src/components/subscribe_button/subscribe_button.js @@ -0,0 +1,26 @@ +export default { + props: [ 'user' ], + data () { + return { + inProgress: false + } + }, + methods: { + subscribe () { + this.inProgress = true + this.$store.state.api.backendInteractor.subscribeUser(this.user.id) + .then((updated) => { + console.log(updated) + this.inProgress = false + }) + }, + unsubscribe () { + this.inProgress = true + this.$store.state.api.backendInteractor.unsubscribeUser(this.user.id) + .then((updated) => { + console.log(updated) + this.inProgress = false + }) + } + } +} diff --git a/src/components/subscribe_button/subscribe_button.vue b/src/components/subscribe_button/subscribe_button.vue new file mode 100644 index 00000000..f7dd8c61 --- /dev/null +++ b/src/components/subscribe_button/subscribe_button.vue @@ -0,0 +1,22 @@ + + + diff --git a/src/components/user_card/user_card.js b/src/components/user_card/user_card.js index 92cd0e54..bab1a654 100644 --- a/src/components/user_card/user_card.js +++ b/src/components/user_card/user_card.js @@ -1,5 +1,6 @@ import UserAvatar from '../user_avatar/user_avatar.vue' import RemoteFollow from '../remote_follow/remote_follow.vue' +import SubscribeButton from '../subscribe_button/subscribe_button.vue' import ModerationTools from '../moderation_tools/moderation_tools.vue' import { hex2rgb } from '../../services/color_convert/color_convert.js' import { requestFollow, requestUnfollow } from '../../services/follow_manipulate/follow_manipulate' @@ -104,7 +105,8 @@ export default { components: { UserAvatar, RemoteFollow, - ModerationTools + ModerationTools, + SubscribeButton }, methods: { followUser () { diff --git a/src/components/user_card/user_card.vue b/src/components/user_card/user_card.vue index 5a5a4881..18ec6e94 100644 --- a/src/components/user_card/user_card.vue +++ b/src/components/user_card/user_card.vue @@ -1,260 +1,135 @@ diff --git a/src/modules/users.js b/src/modules/users.js index 453a6899..f9b609b4 100644 --- a/src/modules/users.js +++ b/src/modules/users.js @@ -135,6 +135,7 @@ export const mutations = { user.following = relationship.following user.muted = relationship.muting user.statusnet_blocking = relationship.blocking + user.subscribing = relationship.subscribing } }) }, From 4cf402ff21c26fa9b82d2ea956ceb7ce8533146a Mon Sep 17 00:00:00 2001 From: taehoon Date: Thu, 25 Apr 2019 04:19:22 -0400 Subject: [PATCH 10/34] migrate SubscribeButton to the existing common component --- .../subscribe_button/subscribe_button.js | 26 ------------------- .../subscribe_button/subscribe_button.vue | 22 ---------------- src/components/user_card/user_card.js | 10 +++++-- src/components/user_card/user_card.vue | 9 ++++++- 4 files changed, 16 insertions(+), 51 deletions(-) delete mode 100644 src/components/subscribe_button/subscribe_button.js delete mode 100644 src/components/subscribe_button/subscribe_button.vue diff --git a/src/components/subscribe_button/subscribe_button.js b/src/components/subscribe_button/subscribe_button.js deleted file mode 100644 index e3a2842c..00000000 --- a/src/components/subscribe_button/subscribe_button.js +++ /dev/null @@ -1,26 +0,0 @@ -export default { - props: [ 'user' ], - data () { - return { - inProgress: false - } - }, - methods: { - subscribe () { - this.inProgress = true - this.$store.state.api.backendInteractor.subscribeUser(this.user.id) - .then((updated) => { - console.log(updated) - this.inProgress = false - }) - }, - unsubscribe () { - this.inProgress = true - this.$store.state.api.backendInteractor.unsubscribeUser(this.user.id) - .then((updated) => { - console.log(updated) - this.inProgress = false - }) - } - } -} diff --git a/src/components/subscribe_button/subscribe_button.vue b/src/components/subscribe_button/subscribe_button.vue deleted file mode 100644 index f7dd8c61..00000000 --- a/src/components/subscribe_button/subscribe_button.vue +++ /dev/null @@ -1,22 +0,0 @@ - - - diff --git a/src/components/user_card/user_card.js b/src/components/user_card/user_card.js index bab1a654..d7fe71d0 100644 --- a/src/components/user_card/user_card.js +++ b/src/components/user_card/user_card.js @@ -1,6 +1,6 @@ import UserAvatar from '../user_avatar/user_avatar.vue' import RemoteFollow from '../remote_follow/remote_follow.vue' -import SubscribeButton from '../subscribe_button/subscribe_button.vue' +import ProgressButton from '../progress_button/progress_button.vue' import ModerationTools from '../moderation_tools/moderation_tools.vue' import { hex2rgb } from '../../services/color_convert/color_convert.js' import { requestFollow, requestUnfollow } from '../../services/follow_manipulate/follow_manipulate' @@ -106,7 +106,7 @@ export default { UserAvatar, RemoteFollow, ModerationTools, - SubscribeButton + ProgressButton }, methods: { followUser () { @@ -137,6 +137,12 @@ export default { unmuteUser () { this.$store.dispatch('unmuteUser', this.user.id) }, + subscribeUser () { + return this.$store.state.api.backendInteractor.subscribeUser(this.user.id) + }, + unsubscribeUser () { + return this.$store.state.api.backendInteractor.unsubscribeUser(this.user.id) + }, setProfileView (v) { if (this.switcher) { const store = this.$store diff --git a/src/components/user_card/user_card.vue b/src/components/user_card/user_card.vue index 18ec6e94..e1d3f48f 100644 --- a/src/components/user_card/user_card.vue +++ b/src/components/user_card/user_card.vue @@ -72,7 +72,14 @@ - +
+ + Subscribe + + + Subscribing! + +