From ee49409049430dedf042ddbeb73898f605664cd2 Mon Sep 17 00:00:00 2001 From: Henry Jameson Date: Fri, 8 Mar 2019 00:35:30 +0200 Subject: Partially transitioned user data to MastoAPI. Added support for fetching relationship data. Upgraded code to be more resilient to nulls caused by missing data in either APIs --- src/modules/users.js | 32 ++++++++++++++++++++++++++------ 1 file changed, 26 insertions(+), 6 deletions(-) (limited to 'src/modules/users.js') diff --git a/src/modules/users.js b/src/modules/users.js index 4159964c..a81ed964 100644 --- a/src/modules/users.js +++ b/src/modules/users.js @@ -1,5 +1,5 @@ import backendInteractorService from '../services/backend_interactor_service/backend_interactor_service.js' -import { compact, map, each, merge, find } from 'lodash' +import { compact, map, each, merge, find, omitBy } from 'lodash' import { set } from 'vue' import { registerPushNotifications, unregisterPushNotifications } from '../services/push/push.js' import oauthApi from '../services/new_api/oauth' @@ -11,7 +11,7 @@ export const mergeOrAdd = (arr, obj, item) => { const oldItem = obj[item.id] if (oldItem) { // We already have this, so only merge the new info. - merge(oldItem, item) + merge(oldItem, omitBy(item, _ => _ === null)) return { item: oldItem, new: false } } else { // This is a new item, prepare it @@ -39,7 +39,7 @@ export const mutations = { }, setCurrentUser (state, user) { state.lastLoginName = user.screen_name - state.currentUser = merge(state.currentUser || {}, user) + state.currentUser = merge(state.currentUser || {}, omitBy(user, _ => _ === null)) }, clearCurrentUser (state) { state.currentUser = false @@ -91,6 +91,16 @@ export const mutations = { addNewUsers (state, users) { each(users, (user) => mergeOrAdd(state.users, state.usersObject, user)) }, + updateUserRelationship (state, relationships) { + relationships.forEach((relationship) => { + const user = state.usersObject[relationship.id] + + user.follows_you = relationship.followed_by + user.following = relationship.following + user.muted = relationship.muting + user.statusnet_blocking = relationship.blocking + }) + }, saveBlocks (state, blockIds) { state.currentUser.blockIds = blockIds }, @@ -98,11 +108,17 @@ export const mutations = { state.currentUser.muteIds = muteIds }, setUserForStatus (state, status) { - status.user = state.usersObject[status.user.id] + // Not setting it again since it's already reactive if it has getters + if (!Object.getOwnPropertyDescriptor(status.user, 'id').get) { + status.user = state.usersObject[status.user.id] + } }, setUserForNotification (state, notification) { - notification.action.user = state.usersObject[notification.action.user.id] - notification.from_profile = state.usersObject[notification.action.user.id] + // Not setting it again since it's already reactive if it has getters + if (!Object.getOwnPropertyDescriptor(notification.action.user, 'id').get) { + notification.action.user = state.usersObject[notification.action.user.id] + notification.from_profile = state.usersObject[notification.action.user.id] + } }, setColor (state, { user: { id }, highlighted }) { const user = state.usersObject[id] @@ -149,6 +165,10 @@ const users = { return store.rootState.api.backendInteractor.fetchUser({ id }) .then((user) => store.commit('addNewUsers', [user])) }, + fetchUserRelationship (store, id) { + return store.rootState.api.backendInteractor.fetchUserRelationship({ id }) + .then((relationships) => store.commit('updateUserRelationship', relationships)) + }, fetchBlocks (store) { return store.rootState.api.backendInteractor.fetchBlocks() .then((blocks) => { -- cgit v1.2.3-70-g09d2 From 4f3a220487c3c8b3596e5a8de7b65cc7c4f0c981 Mon Sep 17 00:00:00 2001 From: Henry Jameson Date: Fri, 8 Mar 2019 22:40:57 +0200 Subject: Since BE doesn't support fetching user by screen name over MastoAPI we'll gonna just fetching it over QvitterAPI real quick :DDDDDDDDD --- src/components/block_card/block_card.js | 2 +- src/components/mute_card/mute_card.js | 2 +- src/components/user_profile/user_profile.js | 63 +++++++++------------- src/components/user_profile/user_profile.vue | 4 +- src/modules/statuses.js | 1 + src/modules/users.js | 12 ++--- src/services/api/api.service.js | 23 ++++++-- .../backend_interactor_service.js | 5 ++ test/unit/specs/components/user_profile.spec.js | 3 +- test/unit/specs/modules/users.spec.js | 6 +-- 10 files changed, 65 insertions(+), 56 deletions(-) (limited to 'src/modules/users.js') diff --git a/src/components/block_card/block_card.js b/src/components/block_card/block_card.js index 11fa27b4..c459ff1b 100644 --- a/src/components/block_card/block_card.js +++ b/src/components/block_card/block_card.js @@ -9,7 +9,7 @@ const BlockCard = { }, computed: { user () { - return this.$store.getters.userById(this.userId) + return this.$store.getters.findUser(this.userId) }, blocked () { return this.user.statusnet_blocking diff --git a/src/components/mute_card/mute_card.js b/src/components/mute_card/mute_card.js index 5dd0a9e5..65c9cfb5 100644 --- a/src/components/mute_card/mute_card.js +++ b/src/components/mute_card/mute_card.js @@ -9,7 +9,7 @@ const MuteCard = { }, computed: { user () { - return this.$store.getters.userById(this.userId) + return this.$store.getters.findUser(this.userId) }, muted () { return this.user.muted diff --git a/src/components/user_profile/user_profile.js b/src/components/user_profile/user_profile.js index 345e7035..4f920ae2 100644 --- a/src/components/user_profile/user_profile.js +++ b/src/components/user_profile/user_profile.js @@ -9,7 +9,7 @@ import withList from '../../hocs/with_list/with_list' const FollowerList = compose( withLoadMore({ fetch: (props, $store) => $store.dispatch('addFollowers', props.userId), - select: (props, $store) => get($store.getters.userById(props.userId), 'followers', []), + select: (props, $store) => get($store.getters.findUser(props.userId), 'followers', []), destory: (props, $store) => $store.dispatch('clearFollowers', props.userId), childPropName: 'entries', additionalPropNames: ['userId'] @@ -20,7 +20,7 @@ const FollowerList = compose( const FriendList = compose( withLoadMore({ fetch: (props, $store) => $store.dispatch('addFriends', props.userId), - select: (props, $store) => get($store.getters.userById(props.userId), 'friends', []), + select: (props, $store) => get($store.getters.findUser(props.userId), 'friends', []), destory: (props, $store) => $store.dispatch('clearFriends', props.userId), childPropName: 'entries', additionalPropNames: ['userId'] @@ -31,19 +31,22 @@ const FriendList = compose( const UserProfile = { data () { return { - error: false + error: false, + fetchedUserId: null } }, created () { - this.$store.commit('clearTimeline', { timeline: 'user' }) - this.$store.commit('clearTimeline', { timeline: 'favorites' }) - this.$store.commit('clearTimeline', { timeline: 'media' }) - this.$store.dispatch('startFetching', { timeline: 'user', userId: this.fetchBy }) - this.$store.dispatch('startFetching', { timeline: 'media', userId: this.fetchBy }) - this.startFetchFavorites() if (!this.user.id) { - this.$store.dispatch('fetchUser', this.fetchBy) - .then(() => this.$store.dispatch('fetchUserRelationship', this.fetchBy)) + let fetchPromise + if (this.userId) { + fetchPromise = this.$store.dispatch('fetchUser', this.userId) + } else { + fetchPromise = this.$store.dispatch('fetchUserByScreenName', this.userName) + .then(userId => { + this.fetchedUserId = userId + }) + } + fetchPromise .catch((reason) => { const errorMessage = get(reason, 'error.error') if (errorMessage === 'No user with such user_id') { // Known error @@ -54,8 +57,7 @@ const UserProfile = { this.error = this.$t('user_profile.profile_loading_error') } }) - } else if (typeof this.user.following === 'undefined' || this.user.following === null) { - this.$store.dispatch('fetchUserRelationship', this.fetchBy) + .then(() => this.startUp()) } }, destroyed () { @@ -72,7 +74,7 @@ const UserProfile = { return this.$store.state.statuses.timelines.media }, userId () { - return this.$route.params.id || this.user.id + return this.$route.params.id || this.user.id || this.fetchedUserId }, userName () { return this.$route.params.name || this.user.screen_name @@ -82,10 +84,8 @@ const UserProfile = { this.userId === this.$store.state.users.currentUser.id }, userInStore () { - if (this.isExternal) { - return this.$store.getters.userById(this.userId) - } - return this.$store.getters.userByName(this.userName) + const routeParams = this.$route.params + return this.$store.getters.findUser(routeParams.name || routeParams.iid) }, user () { if (this.timeline.statuses[0]) { @@ -96,9 +96,6 @@ const UserProfile = { } return {} }, - fetchBy () { - return this.isExternal ? this.userId : this.userName - }, isExternal () { return this.$route.name === 'external-user-profile' }, @@ -112,13 +109,13 @@ const UserProfile = { methods: { startFetchFavorites () { if (this.isUs) { - this.$store.dispatch('startFetching', { timeline: 'favorites', userId: this.fetchBy }) + this.$store.dispatch('startFetching', { timeline: 'favorites', userId: this.userId }) } }, startUp () { - this.$store.dispatch('startFetching', { timeline: 'user', userId: this.fetchBy }) - this.$store.dispatch('startFetching', { timeline: 'media', userId: this.fetchBy }) - + this.$store.dispatch('fetchUserRelationship', this.userId) + this.$store.dispatch('startFetching', { timeline: 'user', userId: this.userId }) + this.$store.dispatch('startFetching', { timeline: 'media', userId: this.userId }) this.startFetchFavorites() }, cleanUp () { @@ -131,19 +128,11 @@ const UserProfile = { } }, watch: { - userName () { - if (this.isExternal) { - return - } - this.cleanUp() - this.startUp() - }, - userId () { - if (!this.isExternal) { - return + userId (newVal, oldVal) { + if (newVal) { + this.cleanUp() + this.startUp() } - this.cleanUp() - this.startUp() }, $route () { this.$refs.tabSwitcher.activateTab(0)() diff --git a/src/components/user_profile/user_profile.vue b/src/components/user_profile/user_profile.vue index 7d4a8b1f..d449eb85 100644 --- a/src/components/user_profile/user_profile.vue +++ b/src/components/user_profile/user_profile.vue @@ -11,7 +11,7 @@ :title="$t('user_profile.timeline_title')" :timeline="timeline" :timeline-name="'user'" - :user-id="fetchBy" + :user-id="userId" />
@@ -25,7 +25,7 @@ :embedded="true" :title="$t('user_card.media')" timeline-name="media" :timeline="media" - :user-id="fetchBy" + :user-id="userId" /> id => - state.users.find(user => user.id === id), - userByName: state => name => - state.users.find(user => user.screen_name && - (user.screen_name.toLowerCase() === name.toLowerCase()) - ) + findUser: state => query => state.usersObject[query] } export const defaultState = { @@ -165,6 +160,11 @@ const users = { return store.rootState.api.backendInteractor.fetchUser({ id }) .then((user) => store.commit('addNewUsers', [user])) }, + fetchUserByScreenName (store, screenName) { + return store.rootState.api.backendInteractor.figureOutUserId({ screenName }) + .then((qvitterUserData) => store.rootState.api.backendInteractor.fetchUser({ id: qvitterUserData.id })) + .then((user) => store.commit('addNewUsers', [user]) || user.id) + }, fetchUserRelationship (store, id) { return store.rootState.api.backendInteractor.fetchUserRelationship({ id }) .then((relationships) => store.commit('updateUserRelationship', relationships)) diff --git a/src/services/api/api.service.js b/src/services/api/api.service.js index 744c2f64..5a0aa2de 100644 --- a/src/services/api/api.service.js +++ b/src/services/api/api.service.js @@ -32,6 +32,7 @@ const QVITTER_USER_NOTIFICATIONS_URL = '/api/qvitter/statuses/notifications.json const QVITTER_USER_NOTIFICATIONS_READ_URL = '/api/qvitter/statuses/notifications/read.json' const BLOCKING_URL = '/api/blocks/create.json' const UNBLOCKING_URL = '/api/blocks/destroy.json' +const USER_URL = '/api/users/show.json' const FOLLOW_IMPORT_URL = '/api/pleroma/follow_import' const DELETE_ACCOUNT_URL = '/api/pleroma/delete_account' const CHANGE_PASSWORD_URL = '/api/pleroma/change_password' @@ -41,7 +42,7 @@ const DENY_USER_URL = '/api/pleroma/friendships/deny' const SUGGESTIONS_URL = '/api/v1/suggestions' const MASTODON_USER_FAVORITES_TIMELINE_URL = '/api/v1/favourites' -const MASTODON_USER_URL = '/api/v1/accounts/' +const MASTODON_USER_URL = '/api/v1/accounts' const MASTODON_USER_RELATIONSHIPS_URL = '/api/v1/accounts/relationships' const MASTODON_USER_TIMELINE_URL = id => `/api/v1/accounts/${id}/statuses` @@ -272,6 +273,22 @@ const fetchUserRelationship = ({id, credentials}) => { }) } +// TODO remove once MastoAPI supports screen_name in fetchUser one +const figureOutUserId = ({screenName, credentials}) => { + let url = `${USER_URL}/?user_id=${screenName}` + return fetch(url, { headers: authHeaders(credentials) }) + .then((response) => { + return new Promise((resolve, reject) => response.json() + .then((json) => { + if (!response.ok) { + return reject(new StatusCodeError(response.status, json, { url }, response)) + } + return resolve(json) + })) + }) + .then((data) => parseUser(data)) +} + const fetchFriends = ({id, page, credentials}) => { let url = `${FRIENDS_URL}?user_id=${id}` if (page) { @@ -382,9 +399,6 @@ const fetchTimeline = ({timeline, credentials, since = false, until = false, use if (until) { params.push(['max_id', until]) } - if (userId) { - params.push(['user_id', userId]) - } if (tag) { url += `/${tag}.json` } @@ -608,6 +622,7 @@ const apiService = { unblockUser, fetchUser, fetchUserRelationship, + figureOutUserId, 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 cbd0b733..48689167 100644 --- a/src/services/backend_interactor_service/backend_interactor_service.js +++ b/src/services/backend_interactor_service/backend_interactor_service.js @@ -26,6 +26,10 @@ const backendInteractorService = (credentials) => { return apiService.fetchAllFollowing({username, credentials}) } + const figureOutUserId = ({screenName}) => { + return apiService.figureOutUserId({screenName, credentials}) + } + const fetchUser = ({id}) => { return apiService.fetchUser({id, credentials}) } @@ -95,6 +99,7 @@ const backendInteractorService = (credentials) => { unfollowUser, blockUser, unblockUser, + figureOutUserId, fetchUser, fetchUserRelationship, fetchAllFollowing, diff --git a/test/unit/specs/components/user_profile.spec.js b/test/unit/specs/components/user_profile.spec.js index 41fd9cd0..1524c4eb 100644 --- a/test/unit/specs/components/user_profile.spec.js +++ b/test/unit/specs/components/user_profile.spec.js @@ -13,8 +13,7 @@ const mutations = { } const testGetters = { - userByName: state => getters.userByName(state.users), - userById: state => getters.userById(state.users) + findUser: state => getters.findUser(state.users) } const localUser = { diff --git a/test/unit/specs/modules/users.spec.js b/test/unit/specs/modules/users.spec.js index 4d49ee24..dae7e580 100644 --- a/test/unit/specs/modules/users.spec.js +++ b/test/unit/specs/modules/users.spec.js @@ -43,7 +43,7 @@ describe('The users module', () => { } const name = 'Guy' const expected = { screen_name: 'Guy', id: '1' } - expect(getters.userByName(state)(name)).to.eql(expected) + expect(getters.findUser(state)(name)).to.eql(expected) }) it('returns user with matching screen_name with different case', () => { @@ -54,7 +54,7 @@ describe('The users module', () => { } const name = 'Guy' const expected = { screen_name: 'guy', id: '1' } - expect(getters.userByName(state)(name)).to.eql(expected) + expect(getters.findUser(state)(name)).to.eql(expected) }) }) @@ -67,7 +67,7 @@ describe('The users module', () => { } const id = '1' const expected = { screen_name: 'Guy', id: '1' } - expect(getters.userById(state)(id)).to.eql(expected) + expect(getters.findUser(state)(id)).to.eql(expected) }) }) }) -- cgit v1.2.3-70-g09d2 From 690c1dcd7ac09f3e6cd4ba5778dce5bd360ee68e Mon Sep 17 00:00:00 2001 From: Henry Jameson Date: Sat, 9 Mar 2019 01:19:56 +0200 Subject: revert some stuff, turns out it's actually breaking. Fixed some local user things --- src/components/user_profile/user_profile.js | 53 +++++++++++++++++------------ src/modules/users.js | 12 ++----- 2 files changed, 34 insertions(+), 31 deletions(-) (limited to 'src/modules/users.js') diff --git a/src/components/user_profile/user_profile.js b/src/components/user_profile/user_profile.js index 4f920ae2..0f387f66 100644 --- a/src/components/user_profile/user_profile.js +++ b/src/components/user_profile/user_profile.js @@ -37,27 +37,7 @@ const UserProfile = { }, created () { if (!this.user.id) { - let fetchPromise - if (this.userId) { - fetchPromise = this.$store.dispatch('fetchUser', this.userId) - } else { - fetchPromise = this.$store.dispatch('fetchUserByScreenName', this.userName) - .then(userId => { - this.fetchedUserId = userId - }) - } - fetchPromise - .catch((reason) => { - const errorMessage = get(reason, 'error.error') - if (errorMessage === 'No user with such user_id') { // Known error - this.error = this.$t('user_profile.profile_does_not_exist') - } else if (errorMessage) { - this.error = errorMessage - } else { - this.error = this.$t('user_profile.profile_loading_error') - } - }) - .then(() => this.startUp()) + this.fetchUserId() } }, destroyed () { @@ -112,8 +92,30 @@ const UserProfile = { this.$store.dispatch('startFetching', { timeline: 'favorites', userId: this.userId }) } }, + fetchUserId () { + let fetchPromise + if (this.userId && !this.$route.params.name) { + fetchPromise = this.$store.dispatch('fetchUser', this.userId) + } else { + fetchPromise = this.$store.dispatch('fetchUserByScreenName', this.userName) + .then(userId => { + this.fetchedUserId = userId + }) + } + fetchPromise + .catch((reason) => { + const errorMessage = get(reason, 'error.error') + if (errorMessage === 'No user with such user_id') { // Known error + this.error = this.$t('user_profile.profile_does_not_exist') + } else if (errorMessage) { + this.error = errorMessage + } else { + this.error = this.$t('user_profile.profile_loading_error') + } + }) + .then(() => this.startUp()) + }, startUp () { - this.$store.dispatch('fetchUserRelationship', this.userId) this.$store.dispatch('startFetching', { timeline: 'user', userId: this.userId }) this.$store.dispatch('startFetching', { timeline: 'media', userId: this.userId }) this.startFetchFavorites() @@ -134,6 +136,13 @@ const UserProfile = { this.startUp() } }, + userName (newVal, oldVal) { + if (this.$route.params.name) { + this.fetchUserId() + this.cleanUp() + this.startUp() + } + }, $route () { this.$refs.tabSwitcher.activateTab(0)() } diff --git a/src/modules/users.js b/src/modules/users.js index 4e17ebf2..e4146c31 100644 --- a/src/modules/users.js +++ b/src/modules/users.js @@ -108,17 +108,11 @@ export const mutations = { state.currentUser.muteIds = muteIds }, setUserForStatus (state, status) { - // Not setting it again since it's already reactive if it has getters - if (!Object.getOwnPropertyDescriptor(status.user, 'id').get) { - status.user = state.usersObject[status.user.id] - } + status.user = state.usersObject[status.user.id] }, setUserForNotification (state, notification) { - // Not setting it again since it's already reactive if it has getters - if (!Object.getOwnPropertyDescriptor(notification.action.user, 'id').get) { - notification.action.user = state.usersObject[notification.action.user.id] - notification.from_profile = state.usersObject[notification.action.user.id] - } + notification.action.user = state.usersObject[notification.action.user.id] + notification.from_profile = state.usersObject[notification.action.user.id] }, setColor (state, { user: { id }, highlighted }) { const user = state.usersObject[id] -- cgit v1.2.3-70-g09d2 From e618c6ffb0b974156b89f3e54737e738e94b12b3 Mon Sep 17 00:00:00 2001 From: slice Date: Sun, 10 Mar 2019 11:23:27 -0700 Subject: Only connect to chat when authenticating in the first place To avoid duplication of the connection, the chat socket is destroyed upon logging out. --- src/boot/after_store.js | 4 +--- src/modules/api.js | 2 +- src/modules/chat.js | 10 +++++++++- src/modules/users.js | 4 ++++ 4 files changed, 15 insertions(+), 5 deletions(-) (limited to 'src/modules/users.js') diff --git a/src/boot/after_store.js b/src/boot/after_store.js index a8e2bf35..cd88c188 100644 --- a/src/boot/after_store.js +++ b/src/boot/after_store.js @@ -89,10 +89,8 @@ const afterStoreSetup = ({ store, i18n }) => { copyInstanceOption('noAttachmentLinks') copyInstanceOption('showFeaturesPanel') - if ((config.chatDisabled)) { + if (config.chatDisabled) { store.dispatch('disableChat') - } else { - store.dispatch('initializeSocket') } return store.dispatch('setTheme', config['theme']) diff --git a/src/modules/api.js b/src/modules/api.js index dc5278f8..31cb55c6 100644 --- a/src/modules/api.js +++ b/src/modules/api.js @@ -50,7 +50,7 @@ const api = { }, initializeSocket (store) { // Set up websocket connection - if (!store.state.chatDisabled && store.state.wsToken) { + if (!store.state.chatDisabled) { const token = store.state.wsToken const socket = new Socket('/socket', {params: {token}}) socket.connect() diff --git a/src/modules/chat.js b/src/modules/chat.js index 383ac75c..2804e577 100644 --- a/src/modules/chat.js +++ b/src/modules/chat.js @@ -1,12 +1,16 @@ const chat = { state: { messages: [], - channel: {state: ''} + channel: {state: ''}, + socket: null }, mutations: { setChannel (state, channel) { state.channel = channel }, + setSocket (state, socket) { + state.socket = socket + }, addMessage (state, message) { state.messages.push(message) state.messages = state.messages.slice(-19, 20) @@ -16,8 +20,12 @@ const chat = { } }, actions: { + disconnectFromChat (store) { + store.state.socket.disconnect() + }, initializeChat (store, socket) { const channel = socket.channel('chat:public') + store.commit('setSocket', socket) channel.on('new_msg', (msg) => { store.commit('addMessage', msg) }) diff --git a/src/modules/users.js b/src/modules/users.js index 4159964c..26884750 100644 --- a/src/modules/users.js +++ b/src/modules/users.js @@ -292,6 +292,7 @@ const users = { logout (store) { store.commit('clearCurrentUser') + store.dispatch('disconnectFromChat') store.commit('setToken', false) store.dispatch('stopFetching', 'friends') store.commit('setBackendInteractor', backendInteractorService()) @@ -321,6 +322,9 @@ const users = { if (user.token) { store.dispatch('setWsToken', user.token) + + // Initialize the chat socket. + store.dispatch('initializeSocket') } // Start getting fresh posts. -- cgit v1.2.3-70-g09d2 From 06d39b62a8358c911b18f5acc378047035840465 Mon Sep 17 00:00:00 2001 From: Henry Jameson Date: Mon, 11 Mar 2019 02:17:49 +0200 Subject: fixed tests, review fixes, now storing local users with downcase screen name for better compatibility --- src/components/user_profile/user_profile.js | 7 ++++--- src/modules/statuses.js | 2 +- src/modules/users.js | 4 ++-- test/unit/specs/components/user_profile.spec.js | 14 ++++++++++---- test/unit/specs/modules/users.spec.js | 4 ++-- 5 files changed, 19 insertions(+), 12 deletions(-) (limited to 'src/modules/users.js') diff --git a/src/components/user_profile/user_profile.js b/src/components/user_profile/user_profile.js index 2d186bc5..a8dfce2f 100644 --- a/src/components/user_profile/user_profile.js +++ b/src/components/user_profile/user_profile.js @@ -68,7 +68,7 @@ const UserProfile = { }, userInStore () { const routeParams = this.$route.params - return this.$store.getters.findUser(routeParams.name || routeParams.iid) + return this.$store.getters.findUser(routeParams.name || routeParams.id) }, user () { if (this.timeline.statuses[0]) { @@ -135,13 +135,14 @@ const UserProfile = { } }, watch: { - userId (newVal, oldVal) { + // userId can be undefined if we don't know it yet + userId (newVal) { if (newVal) { this.cleanUp() this.startUp() } }, - userName (newVal, oldVal) { + userName () { if (this.$route.params.name) { this.fetchUserId() this.cleanUp() diff --git a/src/modules/statuses.js b/src/modules/statuses.js index 2b0215f0..ea1b2de0 100644 --- a/src/modules/statuses.js +++ b/src/modules/statuses.js @@ -73,7 +73,7 @@ const mergeOrAdd = (arr, obj, item) => { if (oldItem) { // We already have this, so only merge the new info. // We ignore null values to avoid overwriting existing properties with missing data - // we also skip 'used' because that is handled by users module + // we also skip 'user' because that is handled by users module merge(oldItem, omitBy(item, (v, k) => v === null || k === 'user')) // Reactivity fix. oldItem.attachments.splice(oldItem.attachments.length) diff --git a/src/modules/users.js b/src/modules/users.js index e4146c31..5eabb1ec 100644 --- a/src/modules/users.js +++ b/src/modules/users.js @@ -18,7 +18,7 @@ export const mergeOrAdd = (arr, obj, item) => { arr.push(item) obj[item.id] = item if (item.screen_name && !item.screen_name.includes('@')) { - obj[item.screen_name] = item + obj[item.screen_name.toLowerCase()] = item } return { item, new: true } } @@ -132,7 +132,7 @@ export const mutations = { } export const getters = { - findUser: state => query => state.usersObject[query] + findUser: state => query => state.usersObject[typeof query === 'string' ? query.toLowerCase() : query] } export const defaultState = { diff --git a/test/unit/specs/components/user_profile.spec.js b/test/unit/specs/components/user_profile.spec.js index 23e5ce20..847481f3 100644 --- a/test/unit/specs/components/user_profile.spec.js +++ b/test/unit/specs/components/user_profile.spec.js @@ -12,6 +12,11 @@ const mutations = { setError: () => {} } +const actions = { + fetchUser: () => {}, + fetchUserByScreenName: () => {} +} + const testGetters = { findUser: state => getters.findUser(state.users) } @@ -30,6 +35,7 @@ const extUser = { const externalProfileStore = new Vuex.Store({ mutations, + actions, getters: testGetters, state: { api: { @@ -88,7 +94,7 @@ const externalProfileStore = new Vuex.Store({ currentUser: { credentials: '' }, - usersObject: [extUser], + usersObject: { 100: extUser }, users: [extUser] } } @@ -96,6 +102,7 @@ const externalProfileStore = new Vuex.Store({ const localProfileStore = new Vuex.Store({ mutations, + actions, getters: testGetters, state: { api: { @@ -154,14 +161,13 @@ const localProfileStore = new Vuex.Store({ currentUser: { credentials: '' }, - usersObject: [localUser], + usersObject: { 100: localUser, 'testuser': localUser }, users: [localUser] } } }) -// It's a little bit more complicated now -describe.skip('UserProfile', () => { +describe('UserProfile', () => { it('renders external profile', () => { const wrapper = mount(UserProfile, { localVue, diff --git a/test/unit/specs/modules/users.spec.js b/test/unit/specs/modules/users.spec.js index a7f18dce..c8bc0ae7 100644 --- a/test/unit/specs/modules/users.spec.js +++ b/test/unit/specs/modules/users.spec.js @@ -40,7 +40,7 @@ describe('The users module', () => { const state = { usersObject: { 1: user, - Guy: user + guy: user } } const name = 'Guy' @@ -53,7 +53,7 @@ describe('The users module', () => { const state = { usersObject: { 1: user, - Guy: user + guy: user } } const id = '1' -- cgit v1.2.3-70-g09d2 From a6a162177b8347917494ddd18de9d239b15bd7fa Mon Sep 17 00:00:00 2001 From: Henry Jameson Date: Mon, 11 Mar 2019 23:03:55 +0200 Subject: instead of filtering nulls, let's just not have them in the first place --- src/modules/users.js | 6 +++--- .../entity_normalizer/entity_normalizer.service.js | 15 +++++++-------- 2 files changed, 10 insertions(+), 11 deletions(-) (limited to 'src/modules/users.js') diff --git a/src/modules/users.js b/src/modules/users.js index 5eabb1ec..d04c7f0b 100644 --- a/src/modules/users.js +++ b/src/modules/users.js @@ -1,5 +1,5 @@ import backendInteractorService from '../services/backend_interactor_service/backend_interactor_service.js' -import { compact, map, each, merge, find, omitBy } from 'lodash' +import { compact, map, each, merge, find } from 'lodash' import { set } from 'vue' import { registerPushNotifications, unregisterPushNotifications } from '../services/push/push.js' import oauthApi from '../services/new_api/oauth' @@ -11,7 +11,7 @@ export const mergeOrAdd = (arr, obj, item) => { const oldItem = obj[item.id] if (oldItem) { // We already have this, so only merge the new info. - merge(oldItem, omitBy(item, _ => _ === null)) + merge(oldItem, item) return { item: oldItem, new: false } } else { // This is a new item, prepare it @@ -39,7 +39,7 @@ export const mutations = { }, setCurrentUser (state, user) { state.lastLoginName = user.screen_name - state.currentUser = merge(state.currentUser || {}, omitBy(user, _ => _ === null)) + state.currentUser = merge(state.currentUser || {}, user) }, clearCurrentUser (state) { state.currentUser = false diff --git a/src/services/entity_normalizer/entity_normalizer.service.js b/src/services/entity_normalizer/entity_normalizer.service.js index d20ce77f..7c840552 100644 --- a/src/services/entity_normalizer/entity_normalizer.service.js +++ b/src/services/entity_normalizer/entity_normalizer.service.js @@ -39,10 +39,10 @@ export const parseUser = (data) => { return output } - output.name = null // missing + // output.name = ??? missing output.name_html = data.display_name - output.description = null // missing + // output.description = ??? missing output.description_html = data.note // Utilize avatar_static for gif avatars? @@ -83,7 +83,7 @@ export const parseUser = (data) => { output.friends_count = data.friends_count - output.bot = null // missing + // output.bot = ??? missing output.statusnet_profile_url = data.statusnet_profile_url @@ -134,7 +134,7 @@ const parseAttachment = (data) => { output.meta = data.meta // not present in BE yet } else { output.mimetype = data.mimetype - output.meta = null // missing + // output.meta = ??? missing } output.url = data.url @@ -166,7 +166,7 @@ export const parseStatus = (data) => { output.in_reply_to_user_id = data.in_reply_to_account_id // Missing!! fix in UI? - output.in_reply_to_screen_name = null + // output.in_reply_to_screen_name = ??? // Not exactly the same but works output.statusnet_conversation_id = data.id @@ -179,8 +179,7 @@ export const parseStatus = (data) => { output.summary_html = data.spoiler_text output.external_url = data.url - // FIXME missing!! - output.is_local = false + // output.is_local = ??? missing } else { output.favorited = data.favorited output.fave_num = data.fave_num @@ -259,7 +258,7 @@ export const parseNotification = (data) => { if (masto) { output.type = mastoDict[data.type] || data.type - output.seen = null // missing + // output.seen = ??? missing output.status = parseStatus(data.status) output.action = output.status // not sure output.from_profile = parseUser(data.account) -- cgit v1.2.3-70-g09d2 From 27cbe3ca658e3f9a40650f119854cd7d31094085 Mon Sep 17 00:00:00 2001 From: Henry Jameson Date: Tue, 12 Mar 2019 22:10:22 +0200 Subject: レインせんぱいにサンキュー MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/user_profile/user_profile.js | 7 ++++--- src/modules/users.js | 10 ++++------ src/services/api/api.service.js | 18 ------------------ .../backend_interactor_service.js | 5 ----- 4 files changed, 8 insertions(+), 32 deletions(-) (limited to 'src/modules/users.js') diff --git a/src/components/user_profile/user_profile.js b/src/components/user_profile/user_profile.js index a8dfce2f..216ac392 100644 --- a/src/components/user_profile/user_profile.js +++ b/src/components/user_profile/user_profile.js @@ -100,9 +100,10 @@ const UserProfile = { if (this.userId && !this.$route.params.name) { fetchPromise = this.$store.dispatch('fetchUser', this.userId) } else { - fetchPromise = this.$store.dispatch('fetchUserByScreenName', this.userName) - .then(userId => { - this.fetchedUserId = userId + fetchPromise = this.$store.dispatch('fetchUser', this.userName) + .then(({ id }) => { + console.log(arguments) + this.fetchedUserId = id }) } return fetchPromise diff --git a/src/modules/users.js b/src/modules/users.js index d04c7f0b..27114684 100644 --- a/src/modules/users.js +++ b/src/modules/users.js @@ -152,12 +152,10 @@ const users = { actions: { fetchUser (store, id) { return store.rootState.api.backendInteractor.fetchUser({ id }) - .then((user) => store.commit('addNewUsers', [user])) - }, - fetchUserByScreenName (store, screenName) { - return store.rootState.api.backendInteractor.figureOutUserId({ screenName }) - .then((qvitterUserData) => store.rootState.api.backendInteractor.fetchUser({ id: qvitterUserData.id })) - .then((user) => store.commit('addNewUsers', [user]) || user.id) + .then((user) => { + store.commit('addNewUsers', [user]) + return user + }) }, fetchUserRelationship (store, id) { return store.rootState.api.backendInteractor.fetchUserRelationship({ id }) diff --git a/src/services/api/api.service.js b/src/services/api/api.service.js index 5a0aa2de..1c6703b7 100644 --- a/src/services/api/api.service.js +++ b/src/services/api/api.service.js @@ -32,7 +32,6 @@ const QVITTER_USER_NOTIFICATIONS_URL = '/api/qvitter/statuses/notifications.json const QVITTER_USER_NOTIFICATIONS_READ_URL = '/api/qvitter/statuses/notifications/read.json' const BLOCKING_URL = '/api/blocks/create.json' const UNBLOCKING_URL = '/api/blocks/destroy.json' -const USER_URL = '/api/users/show.json' const FOLLOW_IMPORT_URL = '/api/pleroma/follow_import' const DELETE_ACCOUNT_URL = '/api/pleroma/delete_account' const CHANGE_PASSWORD_URL = '/api/pleroma/change_password' @@ -273,22 +272,6 @@ const fetchUserRelationship = ({id, credentials}) => { }) } -// TODO remove once MastoAPI supports screen_name in fetchUser one -const figureOutUserId = ({screenName, credentials}) => { - let url = `${USER_URL}/?user_id=${screenName}` - return fetch(url, { headers: authHeaders(credentials) }) - .then((response) => { - return new Promise((resolve, reject) => response.json() - .then((json) => { - if (!response.ok) { - return reject(new StatusCodeError(response.status, json, { url }, response)) - } - return resolve(json) - })) - }) - .then((data) => parseUser(data)) -} - const fetchFriends = ({id, page, credentials}) => { let url = `${FRIENDS_URL}?user_id=${id}` if (page) { @@ -622,7 +605,6 @@ const apiService = { unblockUser, fetchUser, fetchUserRelationship, - figureOutUserId, 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 48689167..cbd0b733 100644 --- a/src/services/backend_interactor_service/backend_interactor_service.js +++ b/src/services/backend_interactor_service/backend_interactor_service.js @@ -26,10 +26,6 @@ const backendInteractorService = (credentials) => { return apiService.fetchAllFollowing({username, credentials}) } - const figureOutUserId = ({screenName}) => { - return apiService.figureOutUserId({screenName, credentials}) - } - const fetchUser = ({id}) => { return apiService.fetchUser({id, credentials}) } @@ -99,7 +95,6 @@ const backendInteractorService = (credentials) => { unfollowUser, blockUser, unblockUser, - figureOutUserId, fetchUser, fetchUserRelationship, fetchAllFollowing, -- cgit v1.2.3-70-g09d2 From 885a3a77df84c21026b7d13ff368c3bebcf70561 Mon Sep 17 00:00:00 2001 From: Henry Jameson Date: Thu, 14 Mar 2019 18:50:51 +0200 Subject: fix console error --- src/modules/users.js | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'src/modules/users.js') diff --git a/src/modules/users.js b/src/modules/users.js index 27114684..2d23955b 100644 --- a/src/modules/users.js +++ b/src/modules/users.js @@ -94,11 +94,12 @@ export const mutations = { updateUserRelationship (state, relationships) { relationships.forEach((relationship) => { const user = state.usersObject[relationship.id] - - user.follows_you = relationship.followed_by - user.following = relationship.following - user.muted = relationship.muting - user.statusnet_blocking = relationship.blocking + if (user) { + user.follows_you = relationship.followed_by + user.following = relationship.following + user.muted = relationship.muting + user.statusnet_blocking = relationship.blocking + } }) }, saveBlocks (state, blockIds) { -- cgit v1.2.3-70-g09d2 From 6420c93e983040807ea58277e5780038a656ef4d Mon Sep 17 00:00:00 2001 From: Henry Jameson Date: Thu, 14 Mar 2019 23:04:13 +0200 Subject: fix flake id users not fetching correctly --- src/components/user_profile/user_profile.js | 3 ++- src/modules/users.js | 9 ++++++++- 2 files changed, 10 insertions(+), 2 deletions(-) (limited to 'src/modules/users.js') diff --git a/src/components/user_profile/user_profile.js b/src/components/user_profile/user_profile.js index 1bf4a86d..82df4510 100644 --- a/src/components/user_profile/user_profile.js +++ b/src/components/user_profile/user_profile.js @@ -68,7 +68,8 @@ const UserProfile = { }, userInStore () { const routeParams = this.$route.params - return this.$store.getters.findUser(routeParams.name || routeParams.id) + // This needs fetchedUserId so that computed will be refreshed when user is fetched + return this.$store.getters.findUser(this.fetchedUserId || routeParams.name || routeParams.id) }, user () { if (this.timeline.statuses[0]) { diff --git a/src/modules/users.js b/src/modules/users.js index 2d23955b..fafe1a60 100644 --- a/src/modules/users.js +++ b/src/modules/users.js @@ -133,7 +133,14 @@ export const mutations = { } export const getters = { - findUser: state => query => state.usersObject[typeof query === 'string' ? query.toLowerCase() : query] + findUser: state => query => { + const result = state.usersObject[query] + // In case it's a screen_name, we can try searching case-insensitive + if (!result && typeof query === 'string') { + return state.usersObject[query.toLowerCase()] + } + return result + } } export const defaultState = { -- cgit v1.2.3-70-g09d2 From 3255950b0e9a16f2a477d606b91d90bed8a6cef7 Mon Sep 17 00:00:00 2001 From: taehoon Date: Sun, 24 Feb 2019 03:02:04 -0500 Subject: Add mute/unmute featrue and mutes management tab --- src/components/mute_card/mute_card.js | 2 +- src/components/user_card/user_card.js | 20 +++++----- src/components/user_card/user_card.vue | 4 +- src/components/user_settings/user_settings.vue | 6 +++ src/modules/users.js | 32 ++++++++++------ src/services/api/api.service.js | 44 ++++++++++++++++++++-- .../backend_interactor_service.js | 6 ++- src/utils/url.js | 9 +++++ 8 files changed, 93 insertions(+), 30 deletions(-) create mode 100644 src/utils/url.js (limited to 'src/modules/users.js') diff --git a/src/components/mute_card/mute_card.js b/src/components/mute_card/mute_card.js index 65c9cfb5..5ef17b60 100644 --- a/src/components/mute_card/mute_card.js +++ b/src/components/mute_card/mute_card.js @@ -12,7 +12,7 @@ const MuteCard = { return this.$store.getters.findUser(this.userId) }, muted () { - return this.user.muted + return this.user.mastodonMuted } }, components: { diff --git a/src/components/user_card/user_card.js b/src/components/user_card/user_card.js index b07da675..61b784fe 100644 --- a/src/components/user_card/user_card.js +++ b/src/components/user_card/user_card.js @@ -121,21 +121,19 @@ export default { }) }, blockUser () { - const store = this.$store - store.state.api.backendInteractor.blockUser(this.user.id) - .then((blockedUser) => { - store.commit('addNewUsers', [blockedUser]) - store.commit('removeStatus', { timeline: 'friends', userId: this.user.id }) - store.commit('removeStatus', { timeline: 'public', userId: this.user.id }) - store.commit('removeStatus', { timeline: 'publicAndExternal', userId: this.user.id }) - }) + this.$store.dispatch('blockUser', this.user.id) }, unblockUser () { - const store = this.$store - store.state.api.backendInteractor.unblockUser(this.user.id) - .then((unblockedUser) => store.commit('addNewUsers', [unblockedUser])) + this.$store.dispatch('unblockUser', this.user.id) + }, + muteUser () { // Mastodon Mute + this.$store.dispatch('muteUser', this.user.id) + }, + unmuteUser () { // Mastodon Unmute + this.$store.dispatch('unmuteUser', this.user.id) }, toggleMute () { + // TODO: Pleroma mute/unmute, Need to migrate to the Mastodon API const store = this.$store store.commit('setMuted', {user: this.user, muted: !this.user.muted}) store.state.api.backendInteractor.setUserMute(this.user) diff --git a/src/components/user_card/user_card.vue b/src/components/user_card/user_card.vue index f4114e6e..3259d1c5 100644 --- a/src/components/user_card/user_card.vue +++ b/src/components/user_card/user_card.vue @@ -74,12 +74,12 @@
- - diff --git a/src/components/user_settings/user_settings.vue b/src/components/user_settings/user_settings.vue index a1123638..c9e68808 100644 --- a/src/components/user_settings/user_settings.vue +++ b/src/components/user_settings/user_settings.vue @@ -192,6 +192,12 @@
+ +
+ + + +
diff --git a/src/modules/users.js b/src/modules/users.js index 1fe12fc8..9c89f34a 100644 --- a/src/modules/users.js +++ b/src/modules/users.js @@ -177,9 +177,14 @@ const users = { return blocks }) }, - blockUser (store, id) { - return store.rootState.api.backendInteractor.blockUser(id) - .then((user) => store.commit('addNewUsers', [user])) + blockUser (store, userId) { + return store.rootState.api.backendInteractor.blockUser(userId) + .then((blockedUser) => { + store.commit('addNewUsers', [blockedUser]) + store.commit('removeStatus', { timeline: 'friends', userId }) + store.commit('removeStatus', { timeline: 'public', userId }) + store.commit('removeStatus', { timeline: 'publicAndExternal', userId }) + }) }, unblockUser (store, id) { return store.rootState.api.backendInteractor.unblockUser(id) @@ -188,18 +193,26 @@ const users = { fetchMutes (store) { return store.rootState.api.backendInteractor.fetchMutes() .then((mutedUsers) => { - each(mutedUsers, (user) => { user.muted = true }) + each(mutedUsers, (user) => { user.mastodonMuted = true }) store.commit('addNewUsers', mutedUsers) store.commit('saveMutes', map(mutedUsers, 'id')) }) }, muteUser (store, id) { - return store.state.api.backendInteractor.setUserMute({ id, muted: true }) - .then((user) => store.commit('addNewUsers', [user])) + return store.rootState.api.backendInteractor.muteUser(id) + .then(() => { + const user = store.rootState.users.usersObject[id] + set(user, 'mastodonMuted', true) + store.commit('addNewUsers', [user]) + }) }, unmuteUser (store, id) { - return store.state.api.backendInteractor.setUserMute({ id, muted: false }) - .then((user) => store.commit('addNewUsers', [user])) + return store.rootState.api.backendInteractor.unmuteUser(id) + .then(() => { + const user = store.rootState.users.usersObject[id] + set(user, 'mastodonMuted', false) + store.commit('addNewUsers', [user]) + }) }, addFriends ({ rootState, commit }, fetchBy) { return new Promise((resolve, reject) => { @@ -350,9 +363,6 @@ const users = { // Start getting fresh posts. store.dispatch('startFetching', { timeline: 'friends' }) - // Get user mutes - store.dispatch('fetchMutes') - // Fetch our friends store.rootState.api.backendInteractor.fetchFriends({ id: user.id }) .then((friends) => commit('addNewUsers', friends)) diff --git a/src/services/api/api.service.js b/src/services/api/api.service.js index 176f1c18..92abf94b 100644 --- a/src/services/api/api.service.js +++ b/src/services/api/api.service.js @@ -1,3 +1,5 @@ +import { generateUrl } from '../../utils/url' + /* eslint-env browser */ const LOGIN_URL = '/api/account/verify_credentials.json' const FRIENDS_TIMELINE_URL = '/api/statuses/friends_timeline.json' @@ -19,6 +21,9 @@ const DM_TIMELINE_URL = '/api/statuses/dm_timeline.json' const FOLLOWERS_URL = '/api/statuses/followers.json' const FRIENDS_URL = '/api/statuses/friends.json' const BLOCKS_URL = '/api/statuses/blocks.json' +const MUTES_URL = '/api/v1/mutes.json' +const MUTING_URL = '/api/v1/accounts/:id/mute' +const UNMUTING_URL = '/api/v1/accounts/:id/unmute' const FOLLOWING_URL = '/api/friendships/create.json' const UNFOLLOWING_URL = '/api/friendships/destroy.json' const QVITTER_USER_PREF_URL = '/api/qvitter/set_profile_pref.json' @@ -538,14 +543,43 @@ const changePassword = ({credentials, password, newPassword, newPasswordConfirma } const fetchMutes = ({credentials}) => { - const url = '/api/qvitter/mutes.json' + return fetch(MUTES_URL, { + headers: authHeaders(credentials) + }).then((data) => { + if (data.ok) { + return data.json() + } + throw new Error('Error fetching mutes', data) + }) +} +const muteUser = ({id, credentials}) => { + const url = generateUrl(MUTING_URL, { id }) return fetch(url, { - headers: authHeaders(credentials) - }).then((data) => data.json()) + headers: authHeaders(credentials), + method: 'POST' + }).then((data) => { + if (data.ok) { + return data.json() + } + throw new Error('Error muting', data) + }) +} + +const unmuteUser = ({id, credentials}) => { + const url = generateUrl(UNMUTING_URL, { id }) + return fetch(url, { + headers: authHeaders(credentials), + method: 'POST' + }).then((data) => { + if (data.ok) { + return data.json() + } + throw new Error('Error unmuting', data) + }) } -const fetchBlocks = ({page, credentials}) => { +const fetchBlocks = ({credentials}) => { return fetch(BLOCKS_URL, { headers: authHeaders(credentials) }).then((data) => { @@ -620,6 +654,8 @@ const apiService = { fetchAllFollowing, setUserMute, fetchMutes, + muteUser, + unmuteUser, 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 cbd0b733..674fb4a4 100644 --- a/src/services/backend_interactor_service/backend_interactor_service.js +++ b/src/services/backend_interactor_service/backend_interactor_service.js @@ -67,7 +67,9 @@ const backendInteractorService = (credentials) => { } const fetchMutes = () => apiService.fetchMutes({credentials}) - const fetchBlocks = (params) => apiService.fetchBlocks({credentials, ...params}) + const muteUser = (id) => apiService.muteUser({credentials, id}) + const unmuteUser = (id) => apiService.unmuteUser({credentials, id}) + const fetchBlocks = () => apiService.fetchBlocks({credentials}) const fetchFollowRequests = () => apiService.fetchFollowRequests({credentials}) const fetchOAuthTokens = () => apiService.fetchOAuthTokens({credentials}) const revokeOAuthToken = (id) => apiService.revokeOAuthToken({id, credentials}) @@ -102,6 +104,8 @@ const backendInteractorService = (credentials) => { startFetching, setUserMute, fetchMutes, + muteUser, + unmuteUser, fetchBlocks, fetchOAuthTokens, revokeOAuthToken, diff --git a/src/utils/url.js b/src/utils/url.js new file mode 100644 index 00000000..79ea7394 --- /dev/null +++ b/src/utils/url.js @@ -0,0 +1,9 @@ +// Generate url based on template +// Example: /api/v1/accounts/:id/mute -> /api/v1/accounts/123/mute +export const generateUrl = (template, params = {}) => { + let url = template + Object.entries(params).forEach(([key, value]) => { + url = url.replace(':' + key, value) + }) + return url +} -- cgit v1.2.3-70-g09d2 From f04cbc887595e842ab8b9dad6545f6e409e52ea1 Mon Sep 17 00:00:00 2001 From: taehoon Date: Sun, 24 Feb 2019 03:20:11 -0500 Subject: Add mute/unmute mutations --- src/modules/users.js | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'src/modules/users.js') diff --git a/src/modules/users.js b/src/modules/users.js index 9c89f34a..f53245a2 100644 --- a/src/modules/users.js +++ b/src/modules/users.js @@ -108,6 +108,14 @@ export const mutations = { saveMutes (state, muteIds) { state.currentUser.muteIds = muteIds }, + muteUser (state, id) { + const user = state.usersObject[id] + set(user, 'mastodonMuted', true) + }, + unmuteUser (state, id) { + const user = state.usersObject[id] + set(user, 'mastodonMuted', false) + }, setUserForStatus (state, status) { status.user = state.usersObject[status.user.id] }, @@ -200,19 +208,11 @@ const users = { }, muteUser (store, id) { return store.rootState.api.backendInteractor.muteUser(id) - .then(() => { - const user = store.rootState.users.usersObject[id] - set(user, 'mastodonMuted', true) - store.commit('addNewUsers', [user]) - }) + .then(() => store.commit('muteUser', id)) }, unmuteUser (store, id) { return store.rootState.api.backendInteractor.unmuteUser(id) - .then(() => { - const user = store.rootState.users.usersObject[id] - set(user, 'mastodonMuted', false) - store.commit('addNewUsers', [user]) - }) + .then(() => store.commit('unmuteUser', id)) }, addFriends ({ rootState, commit }, fetchBy) { return new Promise((resolve, reject) => { -- cgit v1.2.3-70-g09d2 From 859ed4f34feffd4a975e6d865f82bc57224025f9 Mon Sep 17 00:00:00 2001 From: taehoon Date: Sun, 24 Feb 2019 03:21:21 -0500 Subject: Fetct full data of muted users after fetchMutes api call --- src/modules/users.js | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'src/modules/users.js') diff --git a/src/modules/users.js b/src/modules/users.js index f53245a2..af40be3d 100644 --- a/src/modules/users.js +++ b/src/modules/users.js @@ -200,6 +200,11 @@ const users = { }, fetchMutes (store) { return store.rootState.api.backendInteractor.fetchMutes() + .then((mutes) => { + // fetchMutes api doesn't return full user data, let's fetch full user data using separate api calls + const promises = mutes.map(({ id }) => store.rootState.api.backendInteractor.fetchUser({ id })) + return Promise.all(promises) + }) .then((mutedUsers) => { each(mutedUsers, (user) => { user.mastodonMuted = true }) store.commit('addNewUsers', mutedUsers) -- cgit v1.2.3-70-g09d2 From 302310a653083bc82226cf0743d52fc02c277a8a Mon Sep 17 00:00:00 2001 From: taehoon Date: Fri, 1 Mar 2019 11:37:34 -0500 Subject: Remove old muting logic --- src/components/mute_card/mute_card.js | 2 +- src/components/user_card/user_card.js | 10 ++-------- src/modules/users.js | 12 +++++++++--- src/services/api/api.service.js | 18 ------------------ .../backend_interactor_service.js | 5 ----- 5 files changed, 12 insertions(+), 35 deletions(-) (limited to 'src/modules/users.js') diff --git a/src/components/mute_card/mute_card.js b/src/components/mute_card/mute_card.js index 5ef17b60..65c9cfb5 100644 --- a/src/components/mute_card/mute_card.js +++ b/src/components/mute_card/mute_card.js @@ -12,7 +12,7 @@ const MuteCard = { return this.$store.getters.findUser(this.userId) }, muted () { - return this.user.mastodonMuted + return this.user.muted } }, components: { diff --git a/src/components/user_card/user_card.js b/src/components/user_card/user_card.js index 61b784fe..197c61d5 100644 --- a/src/components/user_card/user_card.js +++ b/src/components/user_card/user_card.js @@ -126,18 +126,12 @@ export default { unblockUser () { this.$store.dispatch('unblockUser', this.user.id) }, - muteUser () { // Mastodon Mute + muteUser () { this.$store.dispatch('muteUser', this.user.id) }, - unmuteUser () { // Mastodon Unmute + unmuteUser () { this.$store.dispatch('unmuteUser', this.user.id) }, - toggleMute () { - // TODO: Pleroma mute/unmute, Need to migrate to the Mastodon API - const store = this.$store - store.commit('setMuted', {user: this.user, muted: !this.user.muted}) - store.state.api.backendInteractor.setUserMute(this.user) - }, setProfileView (v) { if (this.switcher) { const store = this.$store diff --git a/src/modules/users.js b/src/modules/users.js index af40be3d..5e53aafb 100644 --- a/src/modules/users.js +++ b/src/modules/users.js @@ -110,11 +110,11 @@ export const mutations = { }, muteUser (state, id) { const user = state.usersObject[id] - set(user, 'mastodonMuted', true) + set(user, 'muted', true) }, unmuteUser (state, id) { const user = state.usersObject[id] - set(user, 'mastodonMuted', false) + set(user, 'muted', false) }, setUserForStatus (state, status) { status.user = state.usersObject[status.user.id] @@ -206,9 +206,10 @@ const users = { return Promise.all(promises) }) .then((mutedUsers) => { - each(mutedUsers, (user) => { user.mastodonMuted = true }) + each(mutedUsers, (user) => { user.muted = true }) store.commit('addNewUsers', mutedUsers) store.commit('saveMutes', map(mutedUsers, 'id')) + // TODO: Unset muted property of the rest users }) }, muteUser (store, id) { @@ -368,6 +369,11 @@ const users = { // Start getting fresh posts. store.dispatch('startFetching', { timeline: 'friends' }) + // Fetch mutes + // TODO: We should not show timeline until fetchMutes is resolved + // However, we can get rid of this logic totally if we can know user muted state from user object + store.dispatch('fetchMutes') + // Fetch our friends store.rootState.api.backendInteractor.fetchFriends({ id: user.id }) .then((friends) => commit('addNewUsers', friends)) diff --git a/src/services/api/api.service.js b/src/services/api/api.service.js index 92abf94b..7da2758a 100644 --- a/src/services/api/api.service.js +++ b/src/services/api/api.service.js @@ -26,7 +26,6 @@ const MUTING_URL = '/api/v1/accounts/:id/mute' const UNMUTING_URL = '/api/v1/accounts/:id/unmute' const FOLLOWING_URL = '/api/friendships/create.json' const UNFOLLOWING_URL = '/api/friendships/destroy.json' -const QVITTER_USER_PREF_URL = '/api/qvitter/set_profile_pref.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' @@ -343,22 +342,6 @@ const fetchStatus = ({id, credentials}) => { .then((data) => parseStatus(data)) } -const setUserMute = ({id, credentials, muted = true}) => { - const form = new FormData() - - const muteInteger = muted ? 1 : 0 - - form.append('namespace', 'qvitter') - form.append('data', muteInteger) - form.append('topic', `mute:${id}`) - - return fetch(QVITTER_USER_PREF_URL, { - method: 'POST', - headers: authHeaders(credentials), - body: form - }) -} - const fetchTimeline = ({timeline, credentials, since = false, until = false, userId = false, tag = false}) => { const timelineUrls = { public: PUBLIC_TIMELINE_URL, @@ -652,7 +635,6 @@ const apiService = { deleteStatus, uploadMedia, fetchAllFollowing, - setUserMute, fetchMutes, muteUser, unmuteUser, diff --git a/src/services/backend_interactor_service/backend_interactor_service.js b/src/services/backend_interactor_service/backend_interactor_service.js index 674fb4a4..0f0bcddc 100644 --- a/src/services/backend_interactor_service/backend_interactor_service.js +++ b/src/services/backend_interactor_service/backend_interactor_service.js @@ -62,10 +62,6 @@ const backendInteractorService = (credentials) => { return timelineFetcherService.startFetching({timeline, store, credentials, userId, tag}) } - const setUserMute = ({id, muted = true}) => { - return apiService.setUserMute({id, muted, credentials}) - } - const fetchMutes = () => apiService.fetchMutes({credentials}) const muteUser = (id) => apiService.muteUser({credentials, id}) const unmuteUser = (id) => apiService.unmuteUser({credentials, id}) @@ -102,7 +98,6 @@ const backendInteractorService = (credentials) => { fetchAllFollowing, verifyCredentials: apiService.verifyCredentials, startFetching, - setUserMute, fetchMutes, muteUser, unmuteUser, -- cgit v1.2.3-70-g09d2 From 9b690209d056d82fa855b682ffeb74378128460e Mon Sep 17 00:00:00 2001 From: taehoon Date: Fri, 1 Mar 2019 13:30:01 -0500 Subject: Reset old mutes state after fetching new mutes data --- src/modules/users.js | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) (limited to 'src/modules/users.js') diff --git a/src/modules/users.js b/src/modules/users.js index 5e53aafb..668ebabd 100644 --- a/src/modules/users.js +++ b/src/modules/users.js @@ -102,10 +102,15 @@ export const mutations = { } }) }, - saveBlocks (state, blockIds) { + saveBlockIds (state, blockIds) { state.currentUser.blockIds = blockIds }, - saveMutes (state, muteIds) { + updateMutes (state, mutedUsers) { + each(state.users, (user) => { user.muted = false }) + const newUsers = map(mutedUsers, (user) => ({ ...user, muted: true })) + each(newUsers, (user) => mergeOrAdd(state.users, state.usersObject, user)) + }, + saveMuteIds (state, muteIds) { state.currentUser.muteIds = muteIds }, muteUser (state, id) { @@ -180,7 +185,7 @@ const users = { fetchBlocks (store) { return store.rootState.api.backendInteractor.fetchBlocks() .then((blocks) => { - store.commit('saveBlocks', map(blocks, 'id')) + store.commit('saveBlockIds', map(blocks, 'id')) store.commit('addNewUsers', blocks) return blocks }) @@ -205,11 +210,10 @@ const users = { const promises = mutes.map(({ id }) => store.rootState.api.backendInteractor.fetchUser({ id })) return Promise.all(promises) }) - .then((mutedUsers) => { - each(mutedUsers, (user) => { user.muted = true }) - store.commit('addNewUsers', mutedUsers) - store.commit('saveMutes', map(mutedUsers, 'id')) - // TODO: Unset muted property of the rest users + .then((mutes) => { + store.commit('updateMutes', mutes) + store.commit('saveMuteIds', map(mutes, 'id')) + return mutes }) }, muteUser (store, id) { -- cgit v1.2.3-70-g09d2 From 300259fd976bb4496c5e1cca0df9bd47a1947259 Mon Sep 17 00:00:00 2001 From: taehoon Date: Sat, 2 Mar 2019 06:47:05 -0500 Subject: Add todo comment --- src/modules/users.js | 1 + 1 file changed, 1 insertion(+) (limited to 'src/modules/users.js') diff --git a/src/modules/users.js b/src/modules/users.js index 668ebabd..79046371 100644 --- a/src/modules/users.js +++ b/src/modules/users.js @@ -107,6 +107,7 @@ export const mutations = { }, updateMutes (state, mutedUsers) { each(state.users, (user) => { user.muted = false }) + // TODO: Remove this line once we get muted property of user object from the api const newUsers = map(mutedUsers, (user) => ({ ...user, muted: true })) each(newUsers, (user) => mergeOrAdd(state.users, state.usersObject, user)) }, -- cgit v1.2.3-70-g09d2 From d7919109ec30c5a75690d6c5b26f1ecebe74d7bf Mon Sep 17 00:00:00 2001 From: taehoon Date: Sat, 2 Mar 2019 08:20:56 -0500 Subject: Reset statusnet_blocking of all fetched users first while refreshing block list --- src/modules/users.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'src/modules/users.js') diff --git a/src/modules/users.js b/src/modules/users.js index 79046371..dd729410 100644 --- a/src/modules/users.js +++ b/src/modules/users.js @@ -102,6 +102,11 @@ export const mutations = { } }) }, + updateBlocks (state, blockedUsers) { + // Reset statusnet_blocking of all fetched users + each(state.users, (user) => { user.statusnet_blocking = false }) + each(blockedUsers, (user) => mergeOrAdd(state.users, state.usersObject, user)) + }, saveBlockIds (state, blockIds) { state.currentUser.blockIds = blockIds }, @@ -187,7 +192,7 @@ const users = { return store.rootState.api.backendInteractor.fetchBlocks() .then((blocks) => { store.commit('saveBlockIds', map(blocks, 'id')) - store.commit('addNewUsers', blocks) + store.commit('updateBlocks', blocks) return blocks }) }, -- cgit v1.2.3-70-g09d2 From a0bccbce9452c21cc075ecc5ba99c1e99a85dbed Mon Sep 17 00:00:00 2001 From: taehoon Date: Sat, 2 Mar 2019 08:21:15 -0500 Subject: Add comment --- src/modules/users.js | 1 + 1 file changed, 1 insertion(+) (limited to 'src/modules/users.js') diff --git a/src/modules/users.js b/src/modules/users.js index dd729410..d75ac9d4 100644 --- a/src/modules/users.js +++ b/src/modules/users.js @@ -111,6 +111,7 @@ export const mutations = { state.currentUser.blockIds = blockIds }, updateMutes (state, mutedUsers) { + // Reset muted of all fetched users each(state.users, (user) => { user.muted = false }) // TODO: Remove this line once we get muted property of user object from the api const newUsers = map(mutedUsers, (user) => ({ ...user, muted: true })) -- cgit v1.2.3-70-g09d2 From e617ed285e8ecb13829558197bdf04ffb9583ea9 Mon Sep 17 00:00:00 2001 From: Henry Jameson Date: Fri, 22 Mar 2019 00:05:20 +0200 Subject: reactivity fixes --- src/modules/statuses.js | 3 ++- src/modules/users.js | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) (limited to 'src/modules/users.js') diff --git a/src/modules/statuses.js b/src/modules/statuses.js index f14b8703..a16342e0 100644 --- a/src/modules/statuses.js +++ b/src/modules/statuses.js @@ -1,4 +1,5 @@ import { remove, slice, each, find, maxBy, minBy, merge, first, last, isArray, omitBy } from 'lodash' +import { set } from 'vue' import apiService from '../services/api/api.service.js' // import parse from '../services/status_parser/status_parser.js' @@ -82,7 +83,7 @@ const mergeOrAdd = (arr, obj, item) => { // This is a new item, prepare it prepareStatus(item) arr.push(item) - obj[item.id] = item + set(obj, item.id, item) return {item, new: true} } } diff --git a/src/modules/users.js b/src/modules/users.js index 1fe12fc8..2950971f 100644 --- a/src/modules/users.js +++ b/src/modules/users.js @@ -16,9 +16,9 @@ export const mergeOrAdd = (arr, obj, item) => { } else { // This is a new item, prepare it arr.push(item) - obj[item.id] = item + set(obj, item.id, item) if (item.screen_name && !item.screen_name.includes('@')) { - obj[item.screen_name.toLowerCase()] = item + set(obj, item.screen_name.toLowerCase(), item) } return { item, new: true } } -- cgit v1.2.3-70-g09d2 From 883a84b31306f2725737ee408900e20b57dbfdf6 Mon Sep 17 00:00:00 2001 From: taehoon Date: Thu, 21 Mar 2019 21:30:30 -0400 Subject: No need to fetch user data using old api anymore 🎉 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/modules/users.js | 5 ----- 1 file changed, 5 deletions(-) (limited to 'src/modules/users.js') diff --git a/src/modules/users.js b/src/modules/users.js index d75ac9d4..83c90ea5 100644 --- a/src/modules/users.js +++ b/src/modules/users.js @@ -212,11 +212,6 @@ const users = { }, fetchMutes (store) { return store.rootState.api.backendInteractor.fetchMutes() - .then((mutes) => { - // fetchMutes api doesn't return full user data, let's fetch full user data using separate api calls - const promises = mutes.map(({ id }) => store.rootState.api.backendInteractor.fetchUser({ id })) - return Promise.all(promises) - }) .then((mutes) => { store.commit('updateMutes', mutes) store.commit('saveMuteIds', map(mutes, 'id')) -- cgit v1.2.3-70-g09d2 From 379e33f6a531fad17477c43e0112941343c737ef Mon Sep 17 00:00:00 2001 From: taehoon Date: Thu, 21 Mar 2019 21:31:16 -0400 Subject: masto api sends muted property now --- src/modules/users.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'src/modules/users.js') diff --git a/src/modules/users.js b/src/modules/users.js index 83c90ea5..ca4358ca 100644 --- a/src/modules/users.js +++ b/src/modules/users.js @@ -113,9 +113,7 @@ export const mutations = { updateMutes (state, mutedUsers) { // Reset muted of all fetched users each(state.users, (user) => { user.muted = false }) - // TODO: Remove this line once we get muted property of user object from the api - const newUsers = map(mutedUsers, (user) => ({ ...user, muted: true })) - each(newUsers, (user) => mergeOrAdd(state.users, state.usersObject, user)) + each(mutedUsers, (user) => mergeOrAdd(state.users, state.usersObject, user)) }, saveMuteIds (state, muteIds) { state.currentUser.muteIds = muteIds -- cgit v1.2.3-70-g09d2 From 8702d23a137d06607fc525b6c791abe24ed021ff Mon Sep 17 00:00:00 2001 From: taehoon Date: Thu, 21 Mar 2019 21:44:59 -0400 Subject: switch to mastoapi --- src/modules/users.js | 6 +++--- src/services/api/api.service.js | 10 ++++------ 2 files changed, 7 insertions(+), 9 deletions(-) (limited to 'src/modules/users.js') diff --git a/src/modules/users.js b/src/modules/users.js index ca4358ca..f12348d4 100644 --- a/src/modules/users.js +++ b/src/modules/users.js @@ -197,8 +197,8 @@ const users = { }, blockUser (store, userId) { return store.rootState.api.backendInteractor.blockUser(userId) - .then((blockedUser) => { - store.commit('addNewUsers', [blockedUser]) + .then((relationship) => { + store.commit('updateUserRelationship', [relationship]) store.commit('removeStatus', { timeline: 'friends', userId }) store.commit('removeStatus', { timeline: 'public', userId }) store.commit('removeStatus', { timeline: 'publicAndExternal', userId }) @@ -206,7 +206,7 @@ const users = { }, unblockUser (store, id) { return store.rootState.api.backendInteractor.unblockUser(id) - .then((user) => store.commit('addNewUsers', [user])) + .then((relationship) => store.commit('updateUserRelationship', [relationship])) }, fetchMutes (store) { return store.rootState.api.backendInteractor.fetchMutes() diff --git a/src/services/api/api.service.js b/src/services/api/api.service.js index c3f863c8..36441017 100644 --- a/src/services/api/api.service.js +++ b/src/services/api/api.service.js @@ -30,8 +30,6 @@ const PROFILE_UPDATE_URL = '/api/account/update_profile.json' const EXTERNAL_PROFILE_URL = '/api/externalprofile/show.json' const QVITTER_USER_NOTIFICATIONS_URL = '/api/qvitter/statuses/notifications.json' const QVITTER_USER_NOTIFICATIONS_READ_URL = '/api/qvitter/statuses/notifications/read.json' -const BLOCKING_URL = '/api/blocks/create.json' -const UNBLOCKING_URL = '/api/blocks/destroy.json' const FOLLOW_IMPORT_URL = '/api/pleroma/follow_import' const DELETE_ACCOUNT_URL = '/api/pleroma/delete_account' const CHANGE_PASSWORD_URL = '/api/pleroma/change_password' @@ -46,6 +44,8 @@ const MASTODON_USER_RELATIONSHIPS_URL = '/api/v1/accounts/relationships' const MASTODON_USER_TIMELINE_URL = id => `/api/v1/accounts/${id}/statuses` const MASTODON_USER_BLOCKS_URL = '/api/v1/blocks/' const MASTODON_USER_MUTES_URL = '/api/v1/mutes/' +const MASTODON_BLOCK_USER_URL = id => `/api/v1/accounts/${id}/block` +const MASTODON_UNBLOCK_USER_URL = id => `/api/v1/accounts/${id}/unblock` import { each, map } from 'lodash' import { parseStatus, parseUser, parseNotification } from '../entity_normalizer/entity_normalizer.service.js' @@ -228,16 +228,14 @@ const unfollowUser = ({id, credentials}) => { } const blockUser = ({id, credentials}) => { - let url = `${BLOCKING_URL}?user_id=${id}` - return fetch(url, { + return fetch(MASTODON_BLOCK_USER_URL(id), { headers: authHeaders(credentials), method: 'POST' }).then((data) => data.json()) } const unblockUser = ({id, credentials}) => { - let url = `${UNBLOCKING_URL}?user_id=${id}` - return fetch(url, { + return fetch(MASTODON_UNBLOCK_USER_URL(id), { headers: authHeaders(credentials), method: 'POST' }).then((data) => data.json()) -- cgit v1.2.3-70-g09d2 From a64e744c1b4aca4bd4ec2ba78a364dd2bbf81b47 Mon Sep 17 00:00:00 2001 From: taehoon Date: Thu, 21 Mar 2019 21:53:24 -0400 Subject: switch to mastoapi --- src/modules/users.js | 12 ++---------- src/services/api/api.service.js | 11 ++++------- src/utils/url.js | 9 --------- 3 files changed, 6 insertions(+), 26 deletions(-) delete mode 100644 src/utils/url.js (limited to 'src/modules/users.js') diff --git a/src/modules/users.js b/src/modules/users.js index f12348d4..bb9a717f 100644 --- a/src/modules/users.js +++ b/src/modules/users.js @@ -118,14 +118,6 @@ export const mutations = { saveMuteIds (state, muteIds) { state.currentUser.muteIds = muteIds }, - muteUser (state, id) { - const user = state.usersObject[id] - set(user, 'muted', true) - }, - unmuteUser (state, id) { - const user = state.usersObject[id] - set(user, 'muted', false) - }, setUserForStatus (state, status) { status.user = state.usersObject[status.user.id] }, @@ -218,11 +210,11 @@ const users = { }, muteUser (store, id) { return store.rootState.api.backendInteractor.muteUser(id) - .then(() => store.commit('muteUser', id)) + .then((relationship) => store.commit('updateUserRelationship', [relationship])) }, unmuteUser (store, id) { return store.rootState.api.backendInteractor.unmuteUser(id) - .then(() => store.commit('unmuteUser', id)) + .then((relationship) => store.commit('updateUserRelationship', [relationship])) }, addFriends ({ rootState, commit }, fetchBy) { return new Promise((resolve, reject) => { diff --git a/src/services/api/api.service.js b/src/services/api/api.service.js index 36441017..8586f993 100644 --- a/src/services/api/api.service.js +++ b/src/services/api/api.service.js @@ -18,8 +18,6 @@ const MENTIONS_URL = '/api/statuses/mentions.json' const DM_TIMELINE_URL = '/api/statuses/dm_timeline.json' const FOLLOWERS_URL = '/api/statuses/followers.json' const FRIENDS_URL = '/api/statuses/friends.json' -const MUTING_URL = '/api/v1/accounts/:id/mute' -const UNMUTING_URL = '/api/v1/accounts/:id/unmute' const FOLLOWING_URL = '/api/friendships/create.json' const UNFOLLOWING_URL = '/api/friendships/destroy.json' const REGISTRATION_URL = '/api/account/register.json' @@ -46,12 +44,13 @@ const MASTODON_USER_BLOCKS_URL = '/api/v1/blocks/' const MASTODON_USER_MUTES_URL = '/api/v1/mutes/' 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` import { each, map } from 'lodash' import { parseStatus, parseUser, parseNotification } from '../entity_normalizer/entity_normalizer.service.js' import 'whatwg-fetch' import { StatusCodeError } from '../errors/errors' -import { generateUrl } from '../../utils/url' const oldfetch = window.fetch @@ -533,16 +532,14 @@ const fetchMutes = ({credentials}) => { } const muteUser = ({id, credentials}) => { - const url = generateUrl(MUTING_URL, { id }) - return promisedRequest(url, { + return promisedRequest(MASTODON_MUTE_USER_URL(id), { headers: authHeaders(credentials), method: 'POST' }) } const unmuteUser = ({id, credentials}) => { - const url = generateUrl(UNMUTING_URL, { id }) - return promisedRequest(url, { + return promisedRequest(MASTODON_UNMUTE_USER_URL(id), { headers: authHeaders(credentials), method: 'POST' }) diff --git a/src/utils/url.js b/src/utils/url.js deleted file mode 100644 index 79ea7394..00000000 --- a/src/utils/url.js +++ /dev/null @@ -1,9 +0,0 @@ -// Generate url based on template -// Example: /api/v1/accounts/:id/mute -> /api/v1/accounts/123/mute -export const generateUrl = (template, params = {}) => { - let url = template - Object.entries(params).forEach(([key, value]) => { - url = url.replace(':' + key, value) - }) - return url -} -- cgit v1.2.3-70-g09d2 From 9fa1bc63b0d95a2cd0868c0356953117e25f0328 Mon Sep 17 00:00:00 2001 From: taehoon Date: Thu, 21 Mar 2019 21:58:02 -0400 Subject: No need to fetch mutes on load anymore 🙌 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/modules/users.js | 5 ----- 1 file changed, 5 deletions(-) (limited to 'src/modules/users.js') diff --git a/src/modules/users.js b/src/modules/users.js index bb9a717f..9b7b29e7 100644 --- a/src/modules/users.js +++ b/src/modules/users.js @@ -365,11 +365,6 @@ const users = { // Start getting fresh posts. store.dispatch('startFetching', { timeline: 'friends' }) - // Fetch mutes - // TODO: We should not show timeline until fetchMutes is resolved - // However, we can get rid of this logic totally if we can know user muted state from user object - store.dispatch('fetchMutes') - // Fetch our friends store.rootState.api.backendInteractor.fetchFriends({ id: user.id }) .then((friends) => commit('addNewUsers', friends)) -- cgit v1.2.3-70-g09d2 From f03747e84124ea45efd16a2f386d7f14996f736a Mon Sep 17 00:00:00 2001 From: taehoon Date: Sun, 24 Mar 2019 13:04:47 -0400 Subject: Revert changes --- src/modules/users.js | 3 +++ 1 file changed, 3 insertions(+) (limited to 'src/modules/users.js') diff --git a/src/modules/users.js b/src/modules/users.js index 9b7b29e7..f83ae298 100644 --- a/src/modules/users.js +++ b/src/modules/users.js @@ -365,6 +365,9 @@ const users = { // Start getting fresh posts. store.dispatch('startFetching', { timeline: 'friends' }) + // Get user mutes + store.dispatch('fetchMutes') + // Fetch our friends store.rootState.api.backendInteractor.fetchFriends({ id: user.id }) .then((friends) => commit('addNewUsers', friends)) -- cgit v1.2.3-70-g09d2