From a690f2661379baf5a93b8f1692f4238cc07643ac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?marcin=20miko=C5=82ajczak?= Date: Sat, 26 Jun 2021 19:27:53 +0200 Subject: [PATCH 1/4] Allow to subscribe to an account MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: marcin mikołajczak --- app/soapbox/actions/accounts.js | 80 +++++++++++++++++++ .../features/account/components/header.js | 2 + .../ui/components/subscription_button.js | 63 +++++++++++++++ app/soapbox/reducers/relationships.js | 4 + app/styles/components/account-header.scss | 26 ++++++ 5 files changed, 175 insertions(+) create mode 100644 app/soapbox/features/ui/components/subscription_button.js diff --git a/app/soapbox/actions/accounts.js b/app/soapbox/actions/accounts.js index a5dbc9c11..4d5c5700c 100644 --- a/app/soapbox/actions/accounts.js +++ b/app/soapbox/actions/accounts.js @@ -40,6 +40,14 @@ export const ACCOUNT_UNMUTE_REQUEST = 'ACCOUNT_UNMUTE_REQUEST'; export const ACCOUNT_UNMUTE_SUCCESS = 'ACCOUNT_UNMUTE_SUCCESS'; export const ACCOUNT_UNMUTE_FAIL = 'ACCOUNT_UNMUTE_FAIL'; +export const ACCOUNT_SUBSCRIBE_REQUEST = 'ACCOUNT_SUBSCRIBE_REQUEST'; +export const ACCOUNT_SUBSCRIBE_SUCCESS = 'ACCOUNT_SUBSCRIBE_SUCCESS'; +export const ACCOUNT_SUBSCRIBE_FAIL = 'ACCOUNT_SUBSCRIBE_FAIL'; + +export const ACCOUNT_UNSUBSCRIBE_REQUEST = 'ACCOUNT_UNSUBSCRIBE_REQUEST'; +export const ACCOUNT_UNSUBSCRIBE_SUCCESS = 'ACCOUNT_UNSUBSCRIBE_SUCCESS'; +export const ACCOUNT_UNSUBSCRIBE_FAIL = 'ACCOUNT_UNSUBSCRIBE_FAIL'; + export const ACCOUNT_PIN_REQUEST = 'ACCOUNT_PIN_REQUEST'; export const ACCOUNT_PIN_SUCCESS = 'ACCOUNT_PIN_SUCCESS'; export const ACCOUNT_PIN_FAIL = 'ACCOUNT_PIN_FAIL'; @@ -410,6 +418,78 @@ export function unmuteAccountFail(error) { }; +export function subscribeAccount(id, notifications) { + return (dispatch, getState) => { + if (!isLoggedIn(getState)) return; + + dispatch(subscribeAccountRequest(id)); + + api(getState).post(`/api/v1/pleroma/accounts/${id}/subscribe`, { notifications }).then(response => { + // Pass in entire statuses map so we can use it to filter stuff in different parts of the reducers + dispatch(subscribeAccountSuccess(response.data, getState().get('statuses'))); + }).catch(error => { + dispatch(subscribeAccountFail(id, error)); + }); + }; +}; + +export function unsubscribeAccount(id) { + return (dispatch, getState) => { + if (!isLoggedIn(getState)) return; + + dispatch(unsubscribeAccountRequest(id)); + + api(getState).post(`/api/v1/pleroma/accounts/${id}/unsubscribe`).then(response => { + dispatch(unsubscribeAccountSuccess(response.data)); + }).catch(error => { + dispatch(unsubscribeAccountFail(id, error)); + }); + }; +}; + +export function subscribeAccountRequest(id) { + return { + type: ACCOUNT_SUBSCRIBE_REQUEST, + id, + }; +}; + +export function subscribeAccountSuccess(relationship, statuses) { + return { + type: ACCOUNT_SUBSCRIBE_SUCCESS, + relationship, + statuses, + }; +}; + +export function subscribeAccountFail(error) { + return { + type: ACCOUNT_SUBSCRIBE_FAIL, + error, + }; +}; + +export function unsubscribeAccountRequest(id) { + return { + type: ACCOUNT_UNSUBSCRIBE_REQUEST, + id, + }; +}; + +export function unsubscribeAccountSuccess(relationship) { + return { + type: ACCOUNT_UNSUBSCRIBE_SUCCESS, + relationship, + }; +}; + +export function unsubscribeAccountFail(error) { + return { + type: ACCOUNT_UNSUBSCRIBE_FAIL, + error, + }; +}; + export function fetchFollowers(id) { return (dispatch, getState) => { if (!isLoggedIn(getState)) return; diff --git a/app/soapbox/features/account/components/header.js b/app/soapbox/features/account/components/header.js index e535959ee..242ac2311 100644 --- a/app/soapbox/features/account/components/header.js +++ b/app/soapbox/features/account/components/header.js @@ -19,6 +19,7 @@ import ProfileInfoPanel from '../../ui/components/profile_info_panel'; import { debounce } from 'lodash'; import StillImage from 'soapbox/components/still_image'; import ActionButton from 'soapbox/features/ui/components/action_button'; +import SubscriptionButton from 'soapbox/features/ui/components/subscription_button'; import { isVerified } from 'soapbox/utils/accounts'; import { openModal } from 'soapbox/actions/modal'; import { List as ImmutableList, Map as ImmutableMap } from 'immutable'; @@ -326,6 +327,7 @@ class Header extends ImmutablePureComponent { }
+ {me && account.get('id') !== me && account.getIn(['pleroma', 'accepts_chat_messages'], false) === true && ); + } + + return subscriptionButton; + } + +} \ No newline at end of file diff --git a/app/soapbox/reducers/relationships.js b/app/soapbox/reducers/relationships.js index 032582bc1..af69c1b33 100644 --- a/app/soapbox/reducers/relationships.js +++ b/app/soapbox/reducers/relationships.js @@ -9,6 +9,8 @@ import { ACCOUNT_UNBLOCK_SUCCESS, ACCOUNT_MUTE_SUCCESS, ACCOUNT_UNMUTE_SUCCESS, + ACCOUNT_SUBSCRIBE_SUCCESS, + ACCOUNT_UNSUBSCRIBE_SUCCESS, ACCOUNT_PIN_SUCCESS, ACCOUNT_UNPIN_SUCCESS, RELATIONSHIPS_FETCH_SUCCESS, @@ -98,6 +100,8 @@ export default function relationships(state = initialState, action) { case ACCOUNT_UNBLOCK_SUCCESS: case ACCOUNT_MUTE_SUCCESS: case ACCOUNT_UNMUTE_SUCCESS: + case ACCOUNT_SUBSCRIBE_SUCCESS: + case ACCOUNT_UNSUBSCRIBE_SUCCESS: case ACCOUNT_PIN_SUCCESS: case ACCOUNT_UNPIN_SUCCESS: return normalizeRelationship(state, action.relationship); diff --git a/app/styles/components/account-header.scss b/app/styles/components/account-header.scss index 5fec07327..db8a58bdf 100644 --- a/app/styles/components/account-header.scss +++ b/app/styles/components/account-header.scss @@ -149,6 +149,32 @@ } .button { margin-right: 10px; } + + .subscription-button { + padding: 0px; + height: 36px; + line-height: 36px; + width: 36px; + margin-right: 10px; + font-size: 20px; + text-align: center; + border: 1px solid var(--brand-color); + background: transparent; + color: var(--primary-text-color); + + &:hover, + &.active { + border-color: $error-red; + background: $error-red; + color: #fff; + } + } + + .button-active { + border-color: #008000; + background: #008000; + color: #fff; + } } &__links { From b744cc5580c1c9f0b863c86a277abb2986b2cfc4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?marcin=20miko=C5=82ajczak?= Date: Sat, 26 Jun 2021 19:29:32 +0200 Subject: [PATCH 2/4] Polish translation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: marcin mikołajczak --- app/soapbox/locales/pl.json | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/soapbox/locales/pl.json b/app/soapbox/locales/pl.json index 7f4f72473..06330adb3 100644 --- a/app/soapbox/locales/pl.json +++ b/app/soapbox/locales/pl.json @@ -40,12 +40,14 @@ "account.requested_small": "Oczekująca prośba", "account.share": "Udostępnij profil @{name}", "account.show_reblogs": "Pokazuj podbicia od @{name}", + "account.subscribe": "Subskrybuj wpisy @{name}", "account.unblock": "Odblokuj @{name}", "account.unblock_domain": "Odblokuj domenę {domain}", "account.unendorse": "Przestań polecać", "account.unfollow": "Przestań śledzić", "account.unmute": "Cofnij wyciszenie @{name}", "account.unmute_notifications": "Cofnij wyciszenie powiadomień od @{name}", + "account.unsubscribe": "Przestań subskrybować wpisy @{name}", "account_gallery.none": "Brak zawartości multimedialnej do wyświetlenia.", "admin.awaiting_approval.approved_message": "Przyjęto {acct}!", "admin.awaiting_approval.empty_message": "Nikt nie oczekuje przyjęcia. Gdy zarejestruje się nowy użytkownik, możesz zatwierdzić go tutaj.", From 25ceec244d8de7bb7868540b6e990fb51e51c938 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?marcin=20miko=C5=82ajczak?= Date: Sat, 26 Jun 2021 19:36:16 +0200 Subject: [PATCH 3/4] think before you copy n paste MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: marcin mikołajczak --- app/soapbox/actions/accounts.js | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/app/soapbox/actions/accounts.js b/app/soapbox/actions/accounts.js index 4d5c5700c..bd2b199ba 100644 --- a/app/soapbox/actions/accounts.js +++ b/app/soapbox/actions/accounts.js @@ -425,8 +425,7 @@ export function subscribeAccount(id, notifications) { dispatch(subscribeAccountRequest(id)); api(getState).post(`/api/v1/pleroma/accounts/${id}/subscribe`, { notifications }).then(response => { - // Pass in entire statuses map so we can use it to filter stuff in different parts of the reducers - dispatch(subscribeAccountSuccess(response.data, getState().get('statuses'))); + dispatch(subscribeAccountSuccess(response.data)); }).catch(error => { dispatch(subscribeAccountFail(id, error)); }); @@ -454,11 +453,10 @@ export function subscribeAccountRequest(id) { }; }; -export function subscribeAccountSuccess(relationship, statuses) { +export function subscribeAccountSuccess(relationship) { return { type: ACCOUNT_SUBSCRIBE_SUCCESS, relationship, - statuses, }; }; From 2137d4a91b91b246b2cb8363e68e6d6f6220323d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?marcin=20miko=C5=82ajczak?= Date: Sat, 26 Jun 2021 19:43:18 +0200 Subject: [PATCH 4/4] lint MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: marcin mikołajczak --- app/styles/components/account-header.scss | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/styles/components/account-header.scss b/app/styles/components/account-header.scss index db8a58bdf..02a09f641 100644 --- a/app/styles/components/account-header.scss +++ b/app/styles/components/account-header.scss @@ -151,7 +151,7 @@ .button { margin-right: 10px; } .subscription-button { - padding: 0px; + padding: 0; height: 36px; line-height: 36px; width: 36px;