From 4a5aef8883d3e92a58e272857cdfb303da61feb2 Mon Sep 17 00:00:00 2001 From: Henry Jameson Date: Sun, 10 Mar 2019 19:15:07 +0200 Subject: [PATCH 1/4] basic user and status actions implemented --- src/modules/statuses.js | 14 ------ src/services/api/api.service.js | 86 +++++++++++++++++++++------------ 2 files changed, 56 insertions(+), 44 deletions(-) diff --git a/src/modules/statuses.js b/src/modules/statuses.js index 7571b62abd..a1ba87c410 100644 --- a/src/modules/statuses.js +++ b/src/modules/statuses.js @@ -429,13 +429,6 @@ const statuses = { // Optimistic favoriting... commit('setFavorited', { status, value: true }) apiService.favorite({ id: status.id, credentials: rootState.users.currentUser.credentials }) - .then(response => { - if (response.ok) { - return response.json() - } else { - return {} - } - }) .then(status => { commit('setFavoritedConfirm', { status }) }) @@ -444,13 +437,6 @@ const statuses = { // Optimistic favoriting... commit('setFavorited', { status, value: false }) apiService.unfavorite({ id: status.id, credentials: rootState.users.currentUser.credentials }) - .then(response => { - if (response.ok) { - return response.json() - } else { - return {} - } - }) .then(status => { commit('setFavoritedConfirm', { status }) }) diff --git a/src/services/api/api.service.js b/src/services/api/api.service.js index 2de87026e6..e2f44a2b86 100644 --- a/src/services/api/api.service.js +++ b/src/services/api/api.service.js @@ -5,12 +5,7 @@ const ALL_FOLLOWING_URL = '/api/qvitter/allfollowing' const PUBLIC_TIMELINE_URL = '/api/statuses/public_timeline.json' const PUBLIC_AND_EXTERNAL_TIMELINE_URL = '/api/statuses/public_and_external_timeline.json' const TAG_TIMELINE_URL = '/api/statusnet/tags/timeline' -const FAVORITE_URL = '/api/favorites/create' -const UNFAVORITE_URL = '/api/favorites/destroy' -const RETWEET_URL = '/api/statuses/retweet' -const UNRETWEET_URL = '/api/statuses/unretweet' const STATUS_UPDATE_URL = '/api/statuses/update.json' -const STATUS_DELETE_URL = '/api/statuses/destroy' const STATUS_URL = '/api/statuses/show' const MEDIA_UPLOAD_URL = '/api/statusnet/media/upload' const CONVERSATION_URL = '/api/statusnet/conversation' @@ -19,9 +14,6 @@ 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 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' @@ -31,8 +23,6 @@ const EXTERNAL_PROFILE_URL = '/api/externalprofile/show.json' const QVITTER_USER_TIMELINE_URL = '/api/qvitter/statuses/user_timeline.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 USER_URL = '/api/users/show.json' const FOLLOW_IMPORT_URL = '/api/pleroma/follow_import' const DELETE_ACCOUNT_URL = '/api/pleroma/delete_account' @@ -43,6 +33,17 @@ 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_FAVORITE_URL = id => `/api/v1/statuses/${id}/favourite` +const MASTODON_UNFAVORITE_URL = id => `/api/v1/statuses/${id}/unfavourite` +const MASTODON_RETWEET_URL = id => `/api/v1/statuses/${id}/reblog` +const MASTODON_UNRETWEET_URL = id => `/api/v1/statuses/${id}/unreblog` +const MASTODON_DELETE_URL = id => `/api/v1/statuses/${id}` +const MASTODON_FOLLOW_URL = id => `/api/v1/accounts/${id}/follow` +const MASTODON_UNFOLLOW_URL = id => `/api/v1/accounts/${id}/unfollow` +const MASTODON_BLOCK_URL = id => `/api/v1/accounts/${id}/block` +const MASTODON_UNBLOCK_URL = id => `/api/v1/accounts/${id}/unblock` +const MASTODON_MUTE_URL = id => `/api/v1/accounts/${id}/mute` +const MASTODON_UNMUTE_URL = id => `/api/v1/accounts/${id}/unmute` import { each, map } from 'lodash' import { parseStatus, parseUser, parseNotification } from '../entity_normalizer/entity_normalizer.service.js' @@ -195,7 +196,7 @@ const externalProfile = ({profileUrl, credentials}) => { } const followUser = ({id, credentials}) => { - let url = `${FOLLOWING_URL}?user_id=${id}` + let url = MASTODON_FOLLOW_URL(id) return fetch(url, { headers: authHeaders(credentials), method: 'POST' @@ -203,7 +204,7 @@ const followUser = ({id, credentials}) => { } const unfollowUser = ({id, credentials}) => { - let url = `${UNFOLLOWING_URL}?user_id=${id}` + let url = MASTODON_UNFOLLOW_URL(id) return fetch(url, { headers: authHeaders(credentials), method: 'POST' @@ -211,7 +212,7 @@ const unfollowUser = ({id, credentials}) => { } const blockUser = ({id, credentials}) => { - let url = `${BLOCKING_URL}?user_id=${id}` + let url = MASTODON_BLOCK_URL(id) return fetch(url, { headers: authHeaders(credentials), method: 'POST' @@ -219,7 +220,7 @@ const blockUser = ({id, credentials}) => { } const unblockUser = ({id, credentials}) => { - let url = `${UNBLOCKING_URL}?user_id=${id}` + let url = MASTODON_UNBLOCK_URL(id) return fetch(url, { headers: authHeaders(credentials), method: 'POST' @@ -324,18 +325,11 @@ const fetchStatus = ({id, credentials}) => { } const setUserMute = ({id, credentials, muted = true}) => { - const form = new FormData() + const url = muted ? MASTODON_MUTE_URL(id) : MASTODON_UNMUTE_URL(id) - const muteInteger = muted ? 1 : 0 - - form.append('namespace', 'qvitter') - form.append('data', muteInteger) - form.append('topic', `mute:${id}`) - - return fetch(QVITTER_USER_PREF_URL, { + return fetch(url, { method: 'POST', - headers: authHeaders(credentials), - body: form + headers: authHeaders(credentials) }) } @@ -407,31 +401,63 @@ const verifyCredentials = (user) => { } const favorite = ({ id, credentials }) => { - return fetch(`${FAVORITE_URL}/${id}.json`, { + return fetch(MASTODON_FAVORITE_URL(id), { headers: authHeaders(credentials), method: 'POST' }) + .then(response => { + if (response.ok) { + return response.json() + } else { + return {} + } + }) + .then((data) => parseStatus(data)) } const unfavorite = ({ id, credentials }) => { - return fetch(`${UNFAVORITE_URL}/${id}.json`, { + return fetch(MASTODON_UNFAVORITE_URL(id), { headers: authHeaders(credentials), method: 'POST' }) + .then(response => { + if (response.ok) { + return response.json() + } else { + return {} + } + }) + .then((data) => parseStatus(data)) } const retweet = ({ id, credentials }) => { - return fetch(`${RETWEET_URL}/${id}.json`, { + return fetch(MASTODON_RETWEET_URL(id), { headers: authHeaders(credentials), method: 'POST' }) + .then(response => { + if (response.ok) { + return response.json() + } else { + return {} + } + }) + .then((data) => parseStatus(data)) } const unretweet = ({ id, credentials }) => { - return fetch(`${UNRETWEET_URL}/${id}.json`, { + return fetch(MASTODON_UNRETWEET_URL(id), { headers: authHeaders(credentials), method: 'POST' }) + .then(response => { + if (response.ok) { + return response.json() + } else { + return {} + } + }) + .then((data) => parseStatus(data)) } const postStatus = ({credentials, status, spoilerText, visibility, sensitive, mediaIds, inReplyToStatusId, contentType, noAttachmentLinks}) => { @@ -468,9 +494,9 @@ const postStatus = ({credentials, status, spoilerText, visibility, sensitive, me } const deleteStatus = ({ id, credentials }) => { - return fetch(`${STATUS_DELETE_URL}/${id}.json`, { + return fetch(MASTODON_DELETE_URL(id), { headers: authHeaders(credentials), - method: 'POST' + method: 'DELETE' }) } From 82f077feb944388d0648be1fdace8db1108c5c45 Mon Sep 17 00:00:00 2001 From: Henry Jameson Date: Mon, 25 Mar 2019 21:12:54 +0200 Subject: [PATCH 2/4] fixup! Merge remote-tracking branch 'upstream/develop' into mastoapi/actions --- src/services/api/api.service.js | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/services/api/api.service.js b/src/services/api/api.service.js index eac151eb56..70aeb2a951 100644 --- a/src/services/api/api.service.js +++ b/src/services/api/api.service.js @@ -33,10 +33,6 @@ const MASTODON_UNRETWEET_URL = id => `/api/v1/statuses/${id}/unreblog` const MASTODON_DELETE_URL = id => `/api/v1/statuses/${id}` const MASTODON_FOLLOW_URL = id => `/api/v1/accounts/${id}/follow` const MASTODON_UNFOLLOW_URL = id => `/api/v1/accounts/${id}/unfollow` -const MASTODON_BLOCK_URL = id => `/api/v1/accounts/${id}/block` -const MASTODON_UNBLOCK_URL = id => `/api/v1/accounts/${id}/unblock` -const MASTODON_MUTE_URL = id => `/api/v1/accounts/${id}/mute` -const MASTODON_UNMUTE_URL = id => `/api/v1/accounts/${id}/unmute` const MASTODON_STATUS_URL = id => `/api/v1/statuses/${id}` const MASTODON_STATUS_CONTEXT_URL = id => `/api/v1/statuses/${id}/context` const MASTODON_USER_URL = '/api/v1/accounts' From d766059deef65ea8c46616b340f6038476b47edf Mon Sep 17 00:00:00 2001 From: Henry Jameson Date: Mon, 25 Mar 2019 21:19:24 +0200 Subject: [PATCH 3/4] correctly update relationship on follow/unfollow --- src/services/follow_manipulate/follow_manipulate.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/services/follow_manipulate/follow_manipulate.js b/src/services/follow_manipulate/follow_manipulate.js index 1e9bd67916..51dafe84ee 100644 --- a/src/services/follow_manipulate/follow_manipulate.js +++ b/src/services/follow_manipulate/follow_manipulate.js @@ -19,7 +19,7 @@ const fetchUser = (attempt, user, store) => new Promise((resolve, reject) => { export const requestFollow = (user, store) => new Promise((resolve, reject) => { store.state.api.backendInteractor.followUser(user.id) .then((updated) => { - store.commit('addNewUsers', [updated]) + store.commit('updateUserRelationship', [updated]) // For locked users we just mark it that we sent the follow request if (updated.locked) { @@ -66,7 +66,7 @@ export const requestFollow = (user, store) => new Promise((resolve, reject) => { export const requestUnfollow = (user, store) => new Promise((resolve, reject) => { store.state.api.backendInteractor.unfollowUser(user.id) .then((updated) => { - store.commit('addNewUsers', [updated]) + store.commit('updateUserRelationship', [updated]) resolve({ updated }) From c2c7e12aadda0ca78f1b0e3789d19bdb6784d89f Mon Sep 17 00:00:00 2001 From: Henry Jameson Date: Wed, 27 Mar 2019 22:18:43 +0200 Subject: [PATCH 4/4] review/remove error hiding --- src/services/api/api.service.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/services/api/api.service.js b/src/services/api/api.service.js index 70aeb2a951..052a46dc95 100644 --- a/src/services/api/api.service.js +++ b/src/services/api/api.service.js @@ -423,7 +423,7 @@ const favorite = ({ id, credentials }) => { if (response.ok) { return response.json() } else { - return {} + throw new Error('Error favoriting post') } }) .then((data) => parseStatus(data)) @@ -438,7 +438,7 @@ const unfavorite = ({ id, credentials }) => { if (response.ok) { return response.json() } else { - return {} + throw new Error('Error removing favorite') } }) .then((data) => parseStatus(data)) @@ -453,7 +453,7 @@ const retweet = ({ id, credentials }) => { if (response.ok) { return response.json() } else { - return {} + throw new Error('Error repeating post') } }) .then((data) => parseStatus(data)) @@ -468,7 +468,7 @@ const unretweet = ({ id, credentials }) => { if (response.ok) { return response.json() } else { - return {} + throw new Error('Error removing repeat') } }) .then((data) => parseStatus(data))