From a64e744c1b4aca4bd4ec2ba78a364dd2bbf81b47 Mon Sep 17 00:00:00 2001 From: taehoon Date: Thu, 21 Mar 2019 21:53:24 -0400 Subject: [PATCH] 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 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 -}