diff --git a/src/intl/en-US.js b/src/intl/en-US.js index 72632918..297d1530 100644 --- a/src/intl/en-US.js +++ b/src/intl/en-US.js @@ -309,6 +309,10 @@ export default { true {(follow requested)} other {} }`, + notifyLabel: `Subscribe`, + denotifyLabel: `Unsubscribe`, + subscribedAccount: 'Subscribed to account', + unsubscribedAccount: 'Unsubscribed to account', unblock: 'Unblock', nameAndFollowing: 'Name and following', clickToSeeAvatar: 'Click to see avatar', @@ -631,6 +635,8 @@ export default { unableToShowReblogs: 'Unable to show boosts: {error}', unableToHideReblogs: 'Unable to hide boosts: {error}', unableToShare: 'Unable to share: {error}', + unableToSubscribe: 'Unable to subscribe: {error}', + unableToUnsubscribe: 'Unable to unsubscribe: {error}', showingOfflineContent: 'Internet request failed. Showing offline content.', youAreOffline: 'You seem to be offline. You can still read toots while offline.', // Snackbar UI diff --git a/src/routes/_actions/notify.js b/src/routes/_actions/notify.js new file mode 100644 index 00000000..383182b0 --- /dev/null +++ b/src/routes/_actions/notify.js @@ -0,0 +1,27 @@ +import { store } from '../_store/store.js' +import { notifyAccount, denotifyAccount } from '../_api/notify.js' +import { toast } from '../_components/toast/toast.js' +import { updateLocalRelationship } from './accounts.js' +import { formatIntl } from '../_utils/formatIntl.js' + +export async function setAccountNotify (accountId, notify, toastOnSuccess) { + const { currentInstance, accessToken } = store.get() + try { + let relationship + if (notify) { + relationship = await notifyAccount(currentInstance, accessToken, accountId) + } else { + relationship = await denotifyAccount(currentInstance, accessToken, accountId) + } + await updateLocalRelationship(currentInstance, accountId, relationship) + if (toastOnSuccess) { + /* no await */ toast.say(follow ? 'intl.subscribedAccount' : 'intl.unsubscribedAccount') + } + } catch (e) { + console.error(e) + /* no await */ toast.say(follow + ? formatIntl('intl.unableToSubscribe', { error: (e.message || '') }) + : formatIntl('intl.unableToUnsubscribe', { error: (e.message || '') }) + ) + } +} diff --git a/src/routes/_api/notify.js b/src/routes/_api/notify.js new file mode 100644 index 00000000..e06fbb8b --- /dev/null +++ b/src/routes/_api/notify.js @@ -0,0 +1,16 @@ +import { post, WRITE_TIMEOUT } from '../_utils/ajax.js' +import { auth, basename } from './utils.js' + +export async function notifyAccount (instanceName, accessToken, accountId) { + const url = `${basename(instanceName)}/api/v1/accounts/${accountId}/follow` + return post(url, { + "notify": true, + }, auth(accessToken), { timeout: WRITE_TIMEOUT }) +} + +export async function denotifyAccount (instanceName, accessToken, accountId) { + const url = `${basename(instanceName)}/api/v1/accounts/${accountId}/follow` + return post(url, { + "notify": false + }, auth(accessToken), { timeout: WRITE_TIMEOUT }) +} diff --git a/src/routes/_components/profile/AccountProfile.html b/src/routes/_components/profile/AccountProfile.html index 19323172..0a2f5c12 100644 --- a/src/routes/_components/profile/AccountProfile.html +++ b/src/routes/_components/profile/AccountProfile.html @@ -8,6 +8,7 @@