diff --git a/src/components/user_profile/user_profile.js b/src/components/user_profile/user_profile.js index f779b823..3ab1adba 100644 --- a/src/components/user_profile/user_profile.js +++ b/src/components/user_profile/user_profile.js @@ -40,7 +40,8 @@ const UserProfile = { error: false, userId: null, tab: defaultTabKey, - footerRef: null + footerRef: null, + note: null } }, created () { @@ -110,9 +111,13 @@ const UserProfile = { const user = this.$store.getters.findUser(userNameOrId) if (user) { loadById(user.id) + this.note = user.relationship.note } else { this.$store.dispatch('fetchUser', userNameOrId) - .then(({ id }) => loadById(id)) + .then(({ id, relationship }) => { + this.note = relationship.note + return loadById(id) + }) .catch((reason) => { const errorMessage = get(reason, 'error.error') if (errorMessage === 'No user with such user_id') { // Known error @@ -145,6 +150,9 @@ const UserProfile = { if (target.tagName === 'A') { window.open(target.href, '_blank') } + }, + setNote () { + this.$store.dispatch('setNote', { id: this.userId, note: this.note }) } }, watch: { diff --git a/src/components/user_profile/user_profile.vue b/src/components/user_profile/user_profile.vue index b1a20269..602c002c 100644 --- a/src/components/user_profile/user_profile.vue +++ b/src/components/user_profile/user_profile.vue @@ -40,6 +40,12 @@ </dd> </dl> </div> + <textarea + v-model="note" + class="note resize-height" + :placeholder="$t('user_card.note')" + @input="setNote" + /> <tab-switcher :active-tab="tab" :render-only-focused="true" @@ -202,6 +208,10 @@ align-items: middle; padding: 2em; } + + .note { + margin: 0.5em 0.75em; + } } .user-profile-placeholder { .panel-body { diff --git a/src/i18n/en.json b/src/i18n/en.json index 3430620b..d17310d6 100644 --- a/src/i18n/en.json +++ b/src/i18n/en.json @@ -845,6 +845,7 @@ "domain_muted": "Unblock domain", "mute_domain": "Block domain", "bot": "Bot", + "note": "Private note", "admin_menu": { "moderation": "Moderation", "grant_admin": "Grant Admin", diff --git a/src/modules/users.js b/src/modules/users.js index 319b6b18..12eb621f 100644 --- a/src/modules/users.js +++ b/src/modules/users.js @@ -102,6 +102,11 @@ const unmuteDomain = (store, domain) => { .then(() => store.commit('removeDomainMute', domain)) } +const setNote = (store, { id, note }) => { + return store.rootState.api.backendInteractor.setNote({ id, note }) + .then((relationship) => store.commit('updateUserRelationship', [relationship])) +} + export const mutations = { tagUser (state, { user: { id }, tag }) { const user = state.usersObject[id] @@ -366,6 +371,9 @@ const users = { unmuteDomains (store, domain = []) { return Promise.all(domain.map(domain => unmuteDomain(store, domain))) }, + setNote (store, { id, note }) { + return setNote(store, { id, note }) + }, fetchFriends ({ rootState, commit }, id) { const user = rootState.users.usersObject[id] const maxId = last(user.friendIds) diff --git a/src/services/api/api.service.js b/src/services/api/api.service.js index fa3439e9..dee5e111 100644 --- a/src/services/api/api.service.js +++ b/src/services/api/api.service.js @@ -63,6 +63,7 @@ const MASTODON_MUTE_USER_URL = id => `/api/v1/accounts/${id}/mute` const MASTODON_UNMUTE_USER_URL = id => `/api/v1/accounts/${id}/unmute` const MASTODON_SUBSCRIBE_USER = id => `/api/v1/pleroma/accounts/${id}/subscribe` const MASTODON_UNSUBSCRIBE_USER = id => `/api/v1/pleroma/accounts/${id}/unsubscribe` +const MASTODON_SET_NOTE_URL = id => `/api/v1/accounts/${id}/note` const MASTODON_BOOKMARK_STATUS_URL = id => `/api/v1/statuses/${id}/bookmark` const MASTODON_UNBOOKMARK_STATUS_URL = id => `/api/v1/statuses/${id}/unbookmark` const MASTODON_POST_STATUS_URL = '/api/v1/statuses' @@ -310,7 +311,7 @@ const denyUser = ({ id, credentials }) => { } const fetchUser = ({ id, credentials }) => { - let url = `${MASTODON_USER_URL}/${id}` + let url = `${MASTODON_USER_URL}/${id}` + '?with_relationships=true' return promisedRequest({ url, credentials }) .then((data) => parseUser(data)) } @@ -948,6 +949,18 @@ const unmuteUser = ({ id, credentials }) => { return promisedRequest({ url: MASTODON_UNMUTE_USER_URL(id), credentials, method: 'POST' }) } +const setNote = ({ id, note, credentials }) => { + const form = new FormData() + + form.append('comment', note) + + return fetch(MASTODON_SET_NOTE_URL(id), { + body: form, + headers: authHeaders(credentials), + method: 'POST' + }).then((data) => data.json()) +} + const fetchMascot = ({ credentials }) => { return promisedRequest({ url: MASTODON_MASCOT_URL, credentials }) } @@ -1405,6 +1418,7 @@ const apiService = { fetchMutes, muteUser, unmuteUser, + setNote, subscribeUser, unsubscribeUser, fetchBlocks,