diff --git a/app/soapbox/actions/accounts.js b/app/soapbox/actions/accounts.js index a5dbc9c11..bd2b199ba 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,76 @@ 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 => { + dispatch(subscribeAccountSuccess(response.data)); + }).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) { + return { + type: ACCOUNT_SUBSCRIBE_SUCCESS, + relationship, + }; +}; + +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/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.", 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..02a09f641 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: 0; + 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 {