From 01807446a846bdda5581a45562d14e5d6d17acf1 Mon Sep 17 00:00:00 2001 From: tusooa Date: Tue, 27 Dec 2022 13:46:50 -0500 Subject: Make notification settings work --- src/services/api/api.service.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/services/api/api.service.js') diff --git a/src/services/api/api.service.js b/src/services/api/api.service.js index 7174cc5d..00d1c020 100644 --- a/src/services/api/api.service.js +++ b/src/services/api/api.service.js @@ -164,7 +164,7 @@ const updateNotificationSettings = ({ credentials, settings }) => { form.append(key, value) }) - return fetch(NOTIFICATION_SETTINGS_URL, { + return fetch(`${NOTIFICATION_SETTINGS_URL}?${new URLSearchParams(settings)}`, { headers: authHeaders(credentials), method: 'PUT', body: form -- cgit v1.2.3-70-g09d2 From c69878cee7a77364afe6ed44a6df109e84273f3b Mon Sep 17 00:00:00 2001 From: tusooa Date: Sat, 14 Jan 2023 22:17:21 -0500 Subject: Display better error message for unauthenticated timelines --- src/services/api/api.service.js | 30 +++++++++++++----------------- 1 file changed, 13 insertions(+), 17 deletions(-) (limited to 'src/services/api/api.service.js') diff --git a/src/services/api/api.service.js b/src/services/api/api.service.js index 00d1c020..af12265e 100644 --- a/src/services/api/api.service.js +++ b/src/services/api/api.service.js @@ -734,26 +734,22 @@ const fetchTimeline = ({ const queryString = map(params, (param) => `${param[0]}=${param[1]}`).join('&') url += `?${queryString}` - let status = '' - let statusText = '' - - let pagination = {} return fetch(url, { headers: authHeaders(credentials) }) - .then((data) => { - status = data.status - statusText = data.statusText - pagination = parseLinkHeaderPagination(data.headers.get('Link'), { - flakeId: timeline !== 'bookmarks' && timeline !== 'notifications' - }) - return data - }) - .then((data) => data.json()) - .then((data) => { - if (!data.errors) { + .then(async (response) => { + const success = response.ok + + const data = await response.json() + + if (success && !data.errors) { + const pagination = parseLinkHeaderPagination(response.headers.get('Link'), { + flakeId: timeline !== 'bookmarks' && timeline !== 'notifications' + }) + return { data: data.map(isNotifications ? parseNotification : parseStatus), pagination } } else { - data.status = status - data.statusText = statusText + data.errors ||= [] + data.status = response.status + data.statusText = response.statusText return data } }) -- cgit v1.2.3-70-g09d2 From d1876503bc560b9c62d03e219021593cb954fcf4 Mon Sep 17 00:00:00 2001 From: tusooa Date: Fri, 20 Jan 2023 12:33:19 -0500 Subject: Display delete status errors --- src/i18n/en.json | 1 + src/modules/statuses.js | 14 ++++++++++++-- src/services/api/api.service.js | 5 +++-- 3 files changed, 16 insertions(+), 4 deletions(-) (limited to 'src/services/api/api.service.js') diff --git a/src/i18n/en.json b/src/i18n/en.json index 1ee1147a..5e653ad8 100644 --- a/src/i18n/en.json +++ b/src/i18n/en.json @@ -844,6 +844,7 @@ "favorites": "Favorites", "repeats": "Repeats", "delete": "Delete status", + "delete_error": "Error deleting status: {0}", "edit": "Edit status", "edited_at": "(last edited {time})", "pin": "Pin on profile", diff --git a/src/modules/statuses.js b/src/modules/statuses.js index 77dd7e1c..93a4a957 100644 --- a/src/modules/statuses.js +++ b/src/modules/statuses.js @@ -615,9 +615,19 @@ const statuses = { fetchStatusHistory ({ rootState, dispatch }, status) { return apiService.fetchStatusHistory({ status }) }, - deleteStatus ({ rootState, commit }, status) { - commit('setDeleted', { status }) + deleteStatus ({ rootState, commit, dispatch }, status) { apiService.deleteStatus({ id: status.id, credentials: rootState.users.currentUser.credentials }) + .then((_) => { + commit('setDeleted', { status }) + }) + .catch((e) => { + dispatch('pushGlobalNotice', { + level: 'error', + messageKey: 'status.delete_error', + messageArgs: [e.message], + timeout: 5000 + }) + }) }, deleteStatusById ({ rootState, commit }, id) { const status = rootState.statuses.allStatusesObject[id] diff --git a/src/services/api/api.service.js b/src/services/api/api.service.js index af12265e..609f6790 100644 --- a/src/services/api/api.service.js +++ b/src/services/api/api.service.js @@ -923,8 +923,9 @@ const editStatus = ({ } const deleteStatus = ({ id, credentials }) => { - return fetch(MASTODON_DELETE_URL(id), { - headers: authHeaders(credentials), + return promisedRequest({ + url: MASTODON_DELETE_URL(id), + credentials, method: 'DELETE' }) } -- cgit v1.2.3-70-g09d2 From 228a9afdf5ecc10a17de31f88bd88ad1efbe0004 Mon Sep 17 00:00:00 2001 From: Tusooa Zhu Date: Sat, 30 Apr 2022 11:08:19 -0400 Subject: Add timed-mute functionality --- src/components/poll/poll_form.js | 13 ++----------- src/components/user_card/user_card.js | 13 +++++++++++-- src/components/user_card/user_card.scss | 5 +++++ src/components/user_card/user_card.vue | 28 +++++++++++++++++++++++++++- src/modules/users.js | 7 +++++-- src/services/api/api.service.js | 8 ++++++-- src/services/date_utils/date_utils.js | 16 ++++++++++++++++ 7 files changed, 72 insertions(+), 18 deletions(-) (limited to 'src/services/api/api.service.js') diff --git a/src/components/poll/poll_form.js b/src/components/poll/poll_form.js index e30645c3..a2070155 100644 --- a/src/components/poll/poll_form.js +++ b/src/components/poll/poll_form.js @@ -94,19 +94,10 @@ export default { }, convertExpiryToUnit (unit, amount) { // Note: we want seconds and not milliseconds - switch (unit) { - case 'minutes': return (1000 * amount) / DateUtils.MINUTE - case 'hours': return (1000 * amount) / DateUtils.HOUR - case 'days': return (1000 * amount) / DateUtils.DAY - } + return DateUtils.secondsToUnit(unit, amount) }, convertExpiryFromUnit (unit, amount) { - // Note: we want seconds and not milliseconds - switch (unit) { - case 'minutes': return 0.001 * amount * DateUtils.MINUTE - case 'hours': return 0.001 * amount * DateUtils.HOUR - case 'days': return 0.001 * amount * DateUtils.DAY - } + return DateUtils.unitToSeconds(unit, amount) }, expiryAmountChange () { this.expiryAmount = diff --git a/src/components/user_card/user_card.js b/src/components/user_card/user_card.js index 1bcc4341..e17bf8eb 100644 --- a/src/components/user_card/user_card.js +++ b/src/components/user_card/user_card.js @@ -1,3 +1,4 @@ +import { unitToSeconds } from 'src/services/date_utils/date_utils.js' import UserAvatar from '../user_avatar/user_avatar.vue' import RemoteFollow from '../remote_follow/remote_follow.vue' import ProgressButton from '../progress_button/progress_button.vue' @@ -48,7 +49,9 @@ export default { return { followRequestInProgress: false, betterShadow: this.$store.state.interface.browserSupport.cssFilter, - showingConfirmMute: false + showingConfirmMute: false, + muteExpiryAmount: 0, + muteExpiryUnit: 'minutes' } }, created () { @@ -142,6 +145,9 @@ export default { shouldConfirmMute () { return this.mergedConfig.modalOnMute }, + muteExpiryUnits () { + return ['minutes', 'hours', 'days'] + }, ...mapGetters(['mergedConfig']) }, components: { @@ -172,7 +178,10 @@ export default { } }, doMuteUser () { - this.$store.dispatch('muteUser', this.user.id) + this.$store.dispatch('muteUser', { + id: this.user.id, + expiresIn: this.shouldConfirmMute ? unitToSeconds(this.muteExpiryUnit, this.muteExpiryAmount) : 0 + }) this.hideConfirmMute() }, unmuteUser () { diff --git a/src/components/user_card/user_card.scss b/src/components/user_card/user_card.scss index d56b6672..4ab93a8a 100644 --- a/src/components/user_card/user_card.scss +++ b/src/components/user_card/user_card.scss @@ -355,3 +355,8 @@ text-decoration: none; } } + +.mute-expiry { + display: flex; + flex-direction: row; +} diff --git a/src/components/user_card/user_card.vue b/src/components/user_card/user_card.vue index 01882aa8..2de14063 100644 --- a/src/components/user_card/user_card.vue +++ b/src/components/user_card/user_card.vue @@ -325,7 +325,7 @@ > +
+ + + +
diff --git a/src/modules/users.js b/src/modules/users.js index 053e44b6..a1316ba2 100644 --- a/src/modules/users.js +++ b/src/modules/users.js @@ -61,13 +61,16 @@ const editUserNote = (store, { id, comment }) => { .then((relationship) => store.commit('updateUserRelationship', [relationship])) } -const muteUser = (store, id) => { +const muteUser = (store, args) => { + const id = typeof args === 'object' ? args.id : args + const expiresIn = typeof args === 'object' ? args.expiresIn : 0 + const predictedRelationship = store.state.relationships[id] || { id } predictedRelationship.muting = true store.commit('updateUserRelationship', [predictedRelationship]) store.commit('addMuteId', id) - return store.rootState.api.backendInteractor.muteUser({ id }) + return store.rootState.api.backendInteractor.muteUser({ id, expiresIn }) .then((relationship) => { store.commit('updateUserRelationship', [relationship]) store.commit('addMuteId', id) diff --git a/src/services/api/api.service.js b/src/services/api/api.service.js index af12265e..c7a36af9 100644 --- a/src/services/api/api.service.js +++ b/src/services/api/api.service.js @@ -1118,8 +1118,12 @@ const fetchMutes = ({ credentials }) => { .then((users) => users.map(parseUser)) } -const muteUser = ({ id, credentials }) => { - return promisedRequest({ url: MASTODON_MUTE_USER_URL(id), credentials, method: 'POST' }) +const muteUser = ({ id, expiresIn, credentials }) => { + const payload = {} + if (expiresIn) { + payload['expires_in'] = expiresIn + } + return promisedRequest({ url: MASTODON_MUTE_USER_URL(id), credentials, method: 'POST', payload }) } const unmuteUser = ({ id, credentials }) => { diff --git a/src/services/date_utils/date_utils.js b/src/services/date_utils/date_utils.js index c93d2176..ed8e1417 100644 --- a/src/services/date_utils/date_utils.js +++ b/src/services/date_utils/date_utils.js @@ -41,3 +41,19 @@ export const relativeTimeShort = (date, nowThreshold = 1) => { r.key += '_short' return r } + +export const unitToSeconds = (unit, amount) => { + switch (unit) { + case 'minutes': return 0.001 * amount * MINUTE + case 'hours': return 0.001 * amount * HOUR + case 'days': return 0.001 * amount * DAY + } +} + +export const secondsToUnit = (unit, amount) => { + switch (unit) { + case 'minutes': return (1000 * amount) / MINUTE + case 'hours': return (1000 * amount) / HOUR + case 'days': return (1000 * amount) / DAY + } +} -- cgit v1.2.3-70-g09d2 From 5359633c743455739a8b6fe64e246c832656b4d0 Mon Sep 17 00:00:00 2001 From: Tusooa Zhu Date: Mon, 1 Aug 2022 11:08:32 -0400 Subject: Fix timed mute lint --- src/services/api/api.service.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/services/api/api.service.js') diff --git a/src/services/api/api.service.js b/src/services/api/api.service.js index c7a36af9..b8c10b21 100644 --- a/src/services/api/api.service.js +++ b/src/services/api/api.service.js @@ -1121,7 +1121,7 @@ const fetchMutes = ({ credentials }) => { const muteUser = ({ id, expiresIn, credentials }) => { const payload = {} if (expiresIn) { - payload['expires_in'] = expiresIn + payload.expires_in = expiresIn } return promisedRequest({ url: MASTODON_MUTE_USER_URL(id), credentials, method: 'POST', payload }) } -- cgit v1.2.3-70-g09d2 From e516eee479cf6e943b6fc43d0a9d18793c141ba0 Mon Sep 17 00:00:00 2001 From: tusooa Date: Tue, 21 Feb 2023 00:39:16 -0500 Subject: Make block & mute lists able to load more --- src/components/list/list.vue | 6 +++- .../settings_modal/tabs/mutes_and_blocks_tab.js | 7 ++-- src/hocs/with_load_more/with_load_more.jsx | 2 +- src/modules/users.js | 38 ++++++++++++++++++---- src/services/api/api.service.js | 16 ++++++--- 5 files changed, 55 insertions(+), 14 deletions(-) (limited to 'src/services/api/api.service.js') diff --git a/src/components/list/list.vue b/src/components/list/list.vue index f17766b4..a3562c5d 100644 --- a/src/components/list/list.vue +++ b/src/components/list/list.vue @@ -1,9 +1,13 @@ diff --git a/src/components/settings_modal/helpers/setting.js b/src/components/settings_modal/helpers/setting.js index 9195d3e9..0971b919 100644 --- a/src/components/settings_modal/helpers/setting.js +++ b/src/components/settings_modal/helpers/setting.js @@ -1,5 +1,16 @@ +import Checkbox from 'src/components/checkbox/checkbox.vue' +import ModifiedIndicator from './modified_indicator.vue' +import ProfileSettingIndicator from './profile_setting_indicator.vue' +import DraftButtons from './draft_buttons.vue' import { get, set } from 'lodash' + export default { + components: { + Checkbox, + ModifiedIndicator, + DraftButtons, + ProfileSettingIndicator + }, props: { path: { type: String, @@ -23,6 +34,20 @@ export default { source: { type: String, default: 'default' + }, + draftMode: { + type: Boolean, + default: false + } + }, + data () { + return { + draft: null + } + }, + created () { + if (this.draftMode) { + this.draft = this.state } }, computed: { @@ -53,7 +78,7 @@ export default { case 'profile': return (k, v) => this.$store.dispatch('setProfileOption', { name: k, value: v }) case 'admin': - return (k, v) => console.log(this.path, k, v) + return (k, v) => this.$store.dispatch('pushAdminSetting', { path: k, value: v }) default: return (k, v) => this.$store.dispatch('setOption', { name: k, value: v }) } @@ -72,25 +97,56 @@ export default { isChanged () { switch (this.source) { case 'profile': - return false case 'admin': - console.log(this.$store.state.adminSettings.modifiedPaths) - return this.$store.state.adminSettings.modifiedPaths.has(this.path) + return false default: return this.state !== this.defaultState } }, + isDirty () { + return this.draftMode && this.draft !== this.state + }, + canHardReset () { + return this.source === 'admin' && this.$store.state.adminSettings.modifiedPaths.has(this.path) + }, matchesExpertLevel () { return (this.expert || 0) <= this.$store.state.config.expertLevel > 0 } }, methods: { + getValue (e) { + return e.target.value + }, update (e) { - console.log('U', this.path, e) - this.configSink(this.path, e) + if (this.draftMode) { + this.draft = this.getValue(e) + } else { + this.configSink(this.path, this.getValue(e)) + } + }, + commitDraft () { + if (this.draftMode) { + this.configSink(this.path, this.draft) + } }, reset () { - set(this.$store.getters.mergedConfig, this.path, this.defaultState) + console.log('reset') + if (this.draftMode) { + console.log(this.draft) + console.log(this.state) + this.draft = this.state + } else { + set(this.$store.getters.mergedConfig, this.path, this.defaultState) + } + }, + hardReset () { + switch (this.source) { + case 'admin': + return this.$store.dispatch('resetAdminSetting', { path: this.path }) + .then(() => { this.draft = this.state }) + default: + console.warn('Hard reset not implemented yet!') + } } } } diff --git a/src/components/settings_modal/helpers/size_setting.js b/src/components/settings_modal/helpers/size_setting.js index 4a0f7e48..12cef705 100644 --- a/src/components/settings_modal/helpers/size_setting.js +++ b/src/components/settings_modal/helpers/size_setting.js @@ -1,4 +1,3 @@ -import ModifiedIndicator from './modified_indicator.vue' import Select from 'src/components/select/select.vue' import Setting from './setting.js' @@ -7,11 +6,11 @@ export const defaultHorizontalUnits = ['px', 'rem', 'vw'] export const defaultVerticalUnits = ['px', 'rem', 'vh'] export default { + ...Setting, components: { - ModifiedIndicator, + ...Setting.components, Select }, - ...Setting, props: { ...Setting.props, min: Number, diff --git a/src/components/settings_modal/helpers/string_setting.js b/src/components/settings_modal/helpers/string_setting.js index 64f8772d..b368cfc8 100644 --- a/src/components/settings_modal/helpers/string_setting.js +++ b/src/components/settings_modal/helpers/string_setting.js @@ -1,9 +1,5 @@ -import ModifiedIndicator from './modified_indicator.vue' import Setting from './setting.js' export default { - components: { - ModifiedIndicator - }, ...Setting } diff --git a/src/components/settings_modal/helpers/string_setting.vue b/src/components/settings_modal/helpers/string_setting.vue index e4bd2de9..0a71aeab 100644 --- a/src/components/settings_modal/helpers/string_setting.vue +++ b/src/components/settings_modal/helpers/string_setting.vue @@ -11,7 +11,7 @@ class="string-input" step="1" :disabled="disabled" - :value="state" + :value="draftMode ? draft :state" @change="update" > {{ ' ' }} @@ -19,7 +19,9 @@ :changed="isChanged" :onclick="reset" /> + + - + diff --git a/src/modules/adminSettings.js b/src/modules/adminSettings.js index 8006717d..d1df67d4 100644 --- a/src/modules/adminSettings.js +++ b/src/modules/adminSettings.js @@ -22,8 +22,8 @@ const adminSettingsStorage = { }, actions: { setInstanceAdminSettings ({ state, commit, dispatch }, { backendDbConfig }) { - const config = {} - const modifiedPaths = new Set() + const config = state.config || {} + const modifiedPaths = state.modifiedPaths || new Set() backendDbConfig.configs.forEach(c => { const path = c.group + '.' + c.key if (c.db) { @@ -40,8 +40,54 @@ const adminSettingsStorage = { } set(config, path, convert(c.value)) }) - console.log(config) commit('updateAdminSettings', { config, modifiedPaths }) + }, + pushAdminSetting ({ rootState, state, commit, dispatch }, { path, value }) { + const [group, key, ...rest] = path.split(/\./g) + const clone = {} // not actually cloning the entire thing to avoid excessive writes + set(clone, rest.join('.'), value) + + // TODO cleanup paths in modifiedPaths + const convert = (value) => { + if (typeof value !== 'object') { + return value + } else if (Array.isArray(value)) { + return value.map(convert) + } else { + return Object.entries(value).map(([k, v]) => ({ tuple: [k, v] })) + } + } + + rootState.api.backendInteractor.pushInstanceDBConfig({ + payload: { + configs: [{ + group, + key, + value: convert(clone) + }] + } + }) + .then(() => rootState.api.backendInteractor.fetchInstanceDBConfig()) + .then(backendDbConfig => dispatch('setInstanceAdminSettings', { backendDbConfig })) + }, + resetAdminSetting ({ rootState, state, commit, dispatch }, { path }) { + console.log('ASS') + const [group, key, subkey] = path.split(/\./g) + + state.modifiedPaths.delete(path) + + return rootState.api.backendInteractor.pushInstanceDBConfig({ + payload: { + configs: [{ + group, + key, + delete: true, + subkeys: [subkey] + }] + } + }) + .then(() => rootState.api.backendInteractor.fetchInstanceDBConfig()) + .then(backendDbConfig => dispatch('setInstanceAdminSettings', { backendDbConfig })) } } } diff --git a/src/modules/users.js b/src/modules/users.js index 74dbdffc..12e582f4 100644 --- a/src/modules/users.js +++ b/src/modules/users.js @@ -564,7 +564,7 @@ const users = { user.domainMutes = [] commit('setCurrentUser', user) commit('setServerSideStorage', user) - if (user.rights.moderator || user.rights.admin) { + if (user.rights.admin) { store.rootState.api.backendInteractor.fetchInstanceDBConfig() .then(backendDbConfig => dispatch('setInstanceAdminSettings', { backendDbConfig })) } diff --git a/src/services/api/api.service.js b/src/services/api/api.service.js index f0aa898a..71ba1dec 100644 --- a/src/services/api/api.service.js +++ b/src/services/api/api.service.js @@ -108,7 +108,7 @@ const PLEROMA_POST_ANNOUNCEMENT_URL = '/api/v1/pleroma/admin/announcements' const PLEROMA_EDIT_ANNOUNCEMENT_URL = id => `/api/v1/pleroma/admin/announcements/${id}` const PLEROMA_DELETE_ANNOUNCEMENT_URL = id => `/api/v1/pleroma/admin/announcements/${id}` -const PLEROMA_ADMIN_CONFIG_URL = '/api/v1/pleroma/admin/config' +const PLEROMA_ADMIN_CONFIG_URL = '/api/pleroma/admin/config' const oldfetch = window.fetch @@ -1677,6 +1677,27 @@ const fetchInstanceDBConfig = ({ credentials }) => { }) } +const pushInstanceDBConfig = ({ credentials, payload }) => { + return fetch(PLEROMA_ADMIN_CONFIG_URL, { + headers: { + Accept: 'application/json', + 'Content-Type': 'application/json', + ...authHeaders(credentials) + }, + method: 'POST', + body: JSON.stringify(payload) + }) + .then((response) => { + if (response.ok) { + return response.json() + } else { + return { + error: response + } + } + }) +} + const apiService = { verifyCredentials, fetchTimeline, @@ -1791,7 +1812,8 @@ const apiService = { editAnnouncement, deleteAnnouncement, adminFetchAnnouncements, - fetchInstanceDBConfig + fetchInstanceDBConfig, + pushInstanceDBConfig } export default apiService -- cgit v1.2.3-70-g09d2 From 332ad77e3579d2b512ba236b3f2c94ad8875864d Mon Sep 17 00:00:00 2001 From: Henry Jameson Date: Sun, 19 Mar 2023 21:27:07 +0200 Subject: limits tab, backend descriptions --- .../settings_modal/admin_tabs/instance_tab.vue | 103 +++++++++++--- .../settings_modal/admin_tabs/limits_tab.js | 29 ++++ .../settings_modal/admin_tabs/limits_tab.vue | 152 +++++++++++++++++++++ .../settings_modal/helpers/boolean_setting.vue | 13 +- .../settings_modal/helpers/integer_setting.vue | 13 +- src/components/settings_modal/helpers/setting.js | 10 ++ .../settings_modal/helpers/string_setting.vue | 13 +- src/components/settings_modal/settings_modal.scss | 6 + .../settings_modal/settings_modal_admin_content.js | 4 +- .../settings_modal_admin_content.vue | 9 +- src/modules/adminSettings.js | 24 +++- src/modules/users.js | 2 + src/services/api/api.service.js | 17 +++ 13 files changed, 370 insertions(+), 25 deletions(-) create mode 100644 src/components/settings_modal/admin_tabs/limits_tab.js create mode 100644 src/components/settings_modal/admin_tabs/limits_tab.vue (limited to 'src/services/api/api.service.js') diff --git a/src/components/settings_modal/admin_tabs/instance_tab.vue b/src/components/settings_modal/admin_tabs/instance_tab.vue index 18ba6127..ad271293 100644 --- a/src/components/settings_modal/admin_tabs/instance_tab.vue +++ b/src/components/settings_modal/admin_tabs/instance_tab.vue @@ -12,6 +12,15 @@ NAME +
  • + + ADMIN EMAIL + +
  • - - POST LIMIT - + SHORT DESCRIPTION + +
  • +
  • + + INSTANCE THUMBNAIL + +
  • +
  • + + BACKGROUND IMAGE + +
  • +
  • + + PUBLIC + +
  • + + +
    +

    {{ $t('admin_dash.registrations') }}

    +
      +
    • + + REGISTRATIONS OPEN + +
        +
      • + + INVITES ENABLED + +
      • +
      +
    • +
    • + + ACTIVATION REQUIRED + +
    • +
    • + + APPROVAL REQUIRED +
    @@ -36,17 +117,3 @@ - - diff --git a/src/components/settings_modal/admin_tabs/limits_tab.js b/src/components/settings_modal/admin_tabs/limits_tab.js new file mode 100644 index 00000000..684739c3 --- /dev/null +++ b/src/components/settings_modal/admin_tabs/limits_tab.js @@ -0,0 +1,29 @@ +import BooleanSetting from '../helpers/boolean_setting.vue' +import ChoiceSetting from '../helpers/choice_setting.vue' +import IntegerSetting from '../helpers/integer_setting.vue' +import StringSetting from '../helpers/string_setting.vue' + +import SharedComputedObject from '../helpers/shared_computed_object.js' +import { library } from '@fortawesome/fontawesome-svg-core' +import { + faGlobe +} from '@fortawesome/free-solid-svg-icons' + +library.add( + faGlobe +) + +const LimitsTab = { + data () {}, + components: { + BooleanSetting, + ChoiceSetting, + IntegerSetting, + StringSetting + }, + computed: { + ...SharedComputedObject() + } +} + +export default LimitsTab diff --git a/src/components/settings_modal/admin_tabs/limits_tab.vue b/src/components/settings_modal/admin_tabs/limits_tab.vue new file mode 100644 index 00000000..3f07c554 --- /dev/null +++ b/src/components/settings_modal/admin_tabs/limits_tab.vue @@ -0,0 +1,152 @@ + + + diff --git a/src/components/settings_modal/helpers/boolean_setting.vue b/src/components/settings_modal/helpers/boolean_setting.vue index 7e05fe85..aedbf23e 100644 --- a/src/components/settings_modal/helpers/boolean_setting.vue +++ b/src/components/settings_modal/helpers/boolean_setting.vue @@ -12,7 +12,12 @@ v-if="!!$slots.default" class="label" > - + + {{ ' ' }} +

    + {{ backendDescriptionDescription + ' ' }} +

    diff --git a/src/components/settings_modal/helpers/integer_setting.vue b/src/components/settings_modal/helpers/integer_setting.vue index e900b87c..e935dfb0 100644 --- a/src/components/settings_modal/helpers/integer_setting.vue +++ b/src/components/settings_modal/helpers/integer_setting.vue @@ -4,7 +4,12 @@ class="IntegerSetting" > +

    + {{ backendDescriptionDescription + ' ' }} +

    diff --git a/src/components/settings_modal/helpers/setting.js b/src/components/settings_modal/helpers/setting.js index 0971b919..f270216f 100644 --- a/src/components/settings_modal/helpers/setting.js +++ b/src/components/settings_modal/helpers/setting.js @@ -59,6 +59,16 @@ export default { return value } }, + backendDescription () { + console.log(get(this.$store.state.adminSettings.descriptions, this.path)) + return get(this.$store.state.adminSettings.descriptions, this.path) + }, + backendDescriptionLabel () { + return this.backendDescription.label + }, + backendDescriptionDescription () { + return this.backendDescription.description + }, shouldBeDisabled () { const parentValue = this.parentPath !== undefined ? get(this.configSource, this.parentPath) : null return this.disabled || (parentValue !== null ? (this.parentInvert ? parentValue : !parentValue) : false) diff --git a/src/components/settings_modal/helpers/string_setting.vue b/src/components/settings_modal/helpers/string_setting.vue index 0a71aeab..91a4afa4 100644 --- a/src/components/settings_modal/helpers/string_setting.vue +++ b/src/components/settings_modal/helpers/string_setting.vue @@ -4,7 +4,12 @@ class="StringSetting" > +

    + {{ backendDescriptionDescription + ' ' }} +

    diff --git a/src/components/settings_modal/settings_modal.scss b/src/components/settings_modal/settings_modal.scss index f5861229..4cce6099 100644 --- a/src/components/settings_modal/settings_modal.scss +++ b/src/components/settings_modal/settings_modal.scss @@ -17,6 +17,12 @@ } } + .setting-description { + margin-top: 0.2em; + margin-bottom: 2em; + font-size: 70%; + } + .settings-modal-panel { overflow: hidden; transition: transform; diff --git a/src/components/settings_modal/settings_modal_admin_content.js b/src/components/settings_modal/settings_modal_admin_content.js index 88ba1755..c6c8837f 100644 --- a/src/components/settings_modal/settings_modal_admin_content.js +++ b/src/components/settings_modal/settings_modal_admin_content.js @@ -3,6 +3,7 @@ import TabSwitcher from 'src/components/tab_switcher/tab_switcher.jsx' import DataImportExportTab from './tabs/data_import_export_tab.vue' import MutesAndBlocksTab from './tabs/mutes_and_blocks_tab.vue' import InstanceTab from './admin_tabs/instance_tab.vue' +import LimitsTab from './admin_tabs/limits_tab.vue' import { library } from '@fortawesome/fontawesome-svg-core' import { @@ -33,7 +34,8 @@ const SettingsModalAdminContent = { DataImportExportTab, MutesAndBlocksTab, - InstanceTab + InstanceTab, + LimitsTab }, computed: { isLoggedIn () { diff --git a/src/components/settings_modal/settings_modal_admin_content.vue b/src/components/settings_modal/settings_modal_admin_content.vue index 9873b127..16b55828 100644 --- a/src/components/settings_modal/settings_modal_admin_content.vue +++ b/src/components/settings_modal/settings_modal_admin_content.vue @@ -7,12 +7,19 @@ :body-scroll-lock="bodyLock" >
    +
    + +
    diff --git a/src/modules/adminSettings.js b/src/modules/adminSettings.js index d1df67d4..44a4d409 100644 --- a/src/modules/adminSettings.js +++ b/src/modules/adminSettings.js @@ -3,7 +3,8 @@ import { set, cloneDeep } from 'lodash' export const defaultState = { needsReboot: null, config: null, - modifiedPaths: null + modifiedPaths: null, + descriptions: null } export const newUserFlags = { @@ -18,6 +19,9 @@ const adminSettingsStorage = { updateAdminSettings (state, { config, modifiedPaths }) { state.config = config state.modifiedPaths = modifiedPaths + }, + updateAdminDescriptions (state, { descriptions }) { + state.descriptions = descriptions } }, actions: { @@ -40,8 +44,25 @@ const adminSettingsStorage = { } set(config, path, convert(c.value)) }) + console.log(config[':pleroma'][':welcome']) commit('updateAdminSettings', { config, modifiedPaths }) }, + setInstanceAdminDescriptions ({ state, commit, dispatch }, { backendDescriptions }) { + const convert = ({ children, description, label, key = '', group, suggestions }, path, acc) => { + const newPath = group ? group + '.' + key : key + const obj = { description, label, suggestions } + if (Array.isArray(children)) { + children.forEach(c => { + convert(c, '.' + newPath, obj) + }) + } + set(acc, newPath, obj) + } + + const descriptions = {} + backendDescriptions.forEach(d => convert(d, '', descriptions)) + commit('updateAdminDescriptions', { descriptions }) + }, pushAdminSetting ({ rootState, state, commit, dispatch }, { path, value }) { const [group, key, ...rest] = path.split(/\./g) const clone = {} // not actually cloning the entire thing to avoid excessive writes @@ -71,7 +92,6 @@ const adminSettingsStorage = { .then(backendDbConfig => dispatch('setInstanceAdminSettings', { backendDbConfig })) }, resetAdminSetting ({ rootState, state, commit, dispatch }, { path }) { - console.log('ASS') const [group, key, subkey] = path.split(/\./g) state.modifiedPaths.delete(path) diff --git a/src/modules/users.js b/src/modules/users.js index 12e582f4..45cba334 100644 --- a/src/modules/users.js +++ b/src/modules/users.js @@ -567,6 +567,8 @@ const users = { if (user.rights.admin) { store.rootState.api.backendInteractor.fetchInstanceDBConfig() .then(backendDbConfig => dispatch('setInstanceAdminSettings', { backendDbConfig })) + store.rootState.api.backendInteractor.fetchInstanceConfigDescriptions() + .then(backendDescriptions => dispatch('setInstanceAdminDescriptions', { backendDescriptions })) } commit('addNewUsers', [user]) diff --git a/src/services/api/api.service.js b/src/services/api/api.service.js index 71ba1dec..073f40a3 100644 --- a/src/services/api/api.service.js +++ b/src/services/api/api.service.js @@ -109,6 +109,7 @@ const PLEROMA_EDIT_ANNOUNCEMENT_URL = id => `/api/v1/pleroma/admin/announcements const PLEROMA_DELETE_ANNOUNCEMENT_URL = id => `/api/v1/pleroma/admin/announcements/${id}` const PLEROMA_ADMIN_CONFIG_URL = '/api/pleroma/admin/config' +const PLEROMA_ADMIN_DESCRIPTIONS_URL = '/api/pleroma/admin/config/descriptions' const oldfetch = window.fetch @@ -1677,6 +1678,21 @@ const fetchInstanceDBConfig = ({ credentials }) => { }) } +const fetchInstanceConfigDescriptions = ({ credentials }) => { + return fetch(PLEROMA_ADMIN_DESCRIPTIONS_URL, { + headers: authHeaders(credentials) + }) + .then((response) => { + if (response.ok) { + return response.json() + } else { + return { + error: response + } + } + }) +} + const pushInstanceDBConfig = ({ credentials, payload }) => { return fetch(PLEROMA_ADMIN_CONFIG_URL, { headers: { @@ -1813,6 +1829,7 @@ const apiService = { deleteAnnouncement, adminFetchAnnouncements, fetchInstanceDBConfig, + fetchInstanceConfigDescriptions, pushInstanceDBConfig } -- cgit v1.2.3-70-g09d2 From c9072ddb0b5ab1daef1f461982a6c57460a75dfe Mon Sep 17 00:00:00 2001 From: jonossa Date: Tue, 21 Mar 2023 16:43:16 +0200 Subject: add parseInt in poll expires_in to make sure FE sends integers in all cases --- src/services/api/api.service.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/services/api/api.service.js') diff --git a/src/services/api/api.service.js b/src/services/api/api.service.js index b8c10b21..259e5b30 100644 --- a/src/services/api/api.service.js +++ b/src/services/api/api.service.js @@ -840,7 +840,7 @@ const postStatus = ({ }) if (pollOptions.some(option => option !== '')) { const normalizedPoll = { - expires_in: poll.expiresIn, + expires_in: parseInt(poll.expiresIn, 10), multiple: poll.multiple } Object.keys(normalizedPoll).forEach(key => { @@ -897,7 +897,7 @@ const editStatus = ({ if (pollOptions.some(option => option !== '')) { const normalizedPoll = { - expires_in: poll.expiresIn, + expires_in: parseInt(poll.expiresIn, 10), multiple: poll.multiple } Object.keys(normalizedPoll).forEach(key => { -- cgit v1.2.3-70-g09d2 From 7bb28bb23c61e2d648eecf5d59969d32631f78e8 Mon Sep 17 00:00:00 2001 From: Henry Jameson Date: Wed, 29 Mar 2023 00:58:07 +0300 Subject: frontends tab initial implementation, now you can (re)install frontends! yay! --- src/App.scss | 22 ++++++- .../settings_modal/admin_tabs/frontends_tab.js | 58 +++++++++++++++++ .../settings_modal/admin_tabs/frontends_tab.scss | 13 ++++ .../settings_modal/admin_tabs/frontends_tab.vue | 72 ++++++++++++++++++++++ src/components/settings_modal/settings_modal.scss | 1 - .../settings_modal/settings_modal_admin_content.js | 8 +-- src/i18n/en.json | 8 +++ src/modules/adminSettings.js | 15 +++++ src/services/api/api.service.js | 42 ++++++++++++- 9 files changed, 229 insertions(+), 10 deletions(-) create mode 100644 src/components/settings_modal/admin_tabs/frontends_tab.js create mode 100644 src/components/settings_modal/admin_tabs/frontends_tab.scss create mode 100644 src/components/settings_modal/admin_tabs/frontends_tab.vue (limited to 'src/services/api/api.service.js') diff --git a/src/App.scss b/src/App.scss index 3f352e8d..149d640f 100644 --- a/src/App.scss +++ b/src/App.scss @@ -645,6 +645,19 @@ option { } } +.cards-list { + display: grid; + grid-auto-flow: row dense; + grid-template-columns: 1fr 1fr; + + li { + border: 1px solid var(--border); + border-radius: var(--inputRadius); + padding: 0.5em; + margin: 0.25em; + } +} + .btn-block { display: block; width: 100%; @@ -655,16 +668,19 @@ option { display: inline-flex; vertical-align: middle; - button { + button, + .button-dropdown { position: relative; flex: 1 1 auto; - &:not(:last-child) { + &:not(:last-child), + &:not(:last-child) .button-default { border-top-right-radius: 0; border-bottom-right-radius: 0; } - &:not(:first-child) { + &:not(:first-child), + &:not(:first-child) .button-default { border-top-left-radius: 0; border-bottom-left-radius: 0; } diff --git a/src/components/settings_modal/admin_tabs/frontends_tab.js b/src/components/settings_modal/admin_tabs/frontends_tab.js new file mode 100644 index 00000000..a5d33cbe --- /dev/null +++ b/src/components/settings_modal/admin_tabs/frontends_tab.js @@ -0,0 +1,58 @@ +import BooleanSetting from '../helpers/boolean_setting.vue' +import ChoiceSetting from '../helpers/choice_setting.vue' +import IntegerSetting from '../helpers/integer_setting.vue' +import StringSetting from '../helpers/string_setting.vue' +import GroupSetting from '../helpers/group_setting.vue' +import Popover from 'src/components/popover/popover.vue' + +import SharedComputedObject from '../helpers/shared_computed_object.js' +import { library } from '@fortawesome/fontawesome-svg-core' +import { + faGlobe +} from '@fortawesome/free-solid-svg-icons' + +library.add( + faGlobe +) + +const FrontendsTab = { + provide () { + return { + defaultDraftMode: true, + defaultSource: 'admin' + } + }, + components: { + BooleanSetting, + ChoiceSetting, + IntegerSetting, + StringSetting, + GroupSetting, + Popover + }, + created () { + if (this.user.rights.admin) { + this.$store.dispatch('loadFrontendsStuff') + } + }, + computed: { + frontends () { + return this.$store.state.adminSettings.frontends + }, + ...SharedComputedObject() + }, + methods: { + update (frontend, suggestRef) { + const ref = suggestRef || frontend.refs[0] + const { name } = frontend + const payload = { name, ref } + + this.$store.state.api.backendInteractor.installFrontend({ payload }) + .then((externalUser) => { + this.$store.dispatch('loadFrontendsStuff') + }) + } + } +} + +export default FrontendsTab diff --git a/src/components/settings_modal/admin_tabs/frontends_tab.scss b/src/components/settings_modal/admin_tabs/frontends_tab.scss new file mode 100644 index 00000000..1e1881ff --- /dev/null +++ b/src/components/settings_modal/admin_tabs/frontends_tab.scss @@ -0,0 +1,13 @@ +.frontends-tab { + .cards-list { + padding: 0; + } + + dd { + text-overflow: ellipsis; + word-wrap: nowrap; + white-space: nowrap; + overflow-x: hidden; + max-width: 80%; + } +} diff --git a/src/components/settings_modal/admin_tabs/frontends_tab.vue b/src/components/settings_modal/admin_tabs/frontends_tab.vue new file mode 100644 index 00000000..48649dfb --- /dev/null +++ b/src/components/settings_modal/admin_tabs/frontends_tab.vue @@ -0,0 +1,72 @@ + + + + + diff --git a/src/components/settings_modal/settings_modal.scss b/src/components/settings_modal/settings_modal.scss index 4cb506f9..98de736b 100644 --- a/src/components/settings_modal/settings_modal.scss +++ b/src/components/settings_modal/settings_modal.scss @@ -43,7 +43,6 @@ .btn { min-height: 2em; - min-width: 10em; padding: 0 2em; } } diff --git a/src/components/settings_modal/settings_modal_admin_content.js b/src/components/settings_modal/settings_modal_admin_content.js index 1c239e59..b7c0de57 100644 --- a/src/components/settings_modal/settings_modal_admin_content.js +++ b/src/components/settings_modal/settings_modal_admin_content.js @@ -1,9 +1,8 @@ import TabSwitcher from 'src/components/tab_switcher/tab_switcher.jsx' -import DataImportExportTab from './tabs/data_import_export_tab.vue' -import MutesAndBlocksTab from './tabs/mutes_and_blocks_tab.vue' import InstanceTab from './admin_tabs/instance_tab.vue' import LimitsTab from './admin_tabs/limits_tab.vue' +import FrontendsTab from './admin_tabs/frontends_tab.vue' import { library } from '@fortawesome/fontawesome-svg-core' import { @@ -32,10 +31,9 @@ const SettingsModalAdminContent = { components: { TabSwitcher, - DataImportExportTab, - MutesAndBlocksTab, InstanceTab, - LimitsTab + LimitsTab, + FrontendsTab }, computed: { user () { diff --git a/src/i18n/en.json b/src/i18n/en.json index 86ae7f06..ede5d494 100644 --- a/src/i18n/en.json +++ b/src/i18n/en.json @@ -873,6 +873,14 @@ "users": "User profile limits", "profile_fields": "Profile fields limits", "user_uploads": "Profile media limits" + }, + "frontend": { + "repository": "Repository link", + "versions": "Available versions", + "build_url": "Build URL", + "reinstall": "Reinstall", + "install": "Install", + "install_version": "Install version {version}" } }, "time": { diff --git a/src/modules/adminSettings.js b/src/modules/adminSettings.js index b8265949..cad9c0ca 100644 --- a/src/modules/adminSettings.js +++ b/src/modules/adminSettings.js @@ -1,6 +1,7 @@ import { set, get, cloneDeep, differenceWith, isEqual, flatten } from 'lodash' export const defaultState = { + frontends: [], loaded: false, needsReboot: null, config: null, @@ -23,6 +24,16 @@ const adminSettingsStorage = { state.loaded = false state.dbConfigEnabled = false }, + setAvailableFrontends (state, { frontends }) { + state.frontends = frontends.map(f => { + if (f.name === 'pleroma-fe') { + f.refs = ['master', 'develop'] + } else { + f.refs = [f.ref] + } + return f + }) + }, updateAdminSettings (state, { config, modifiedPaths }) { state.loaded = true state.dbConfigEnabled = true @@ -48,6 +59,10 @@ const adminSettingsStorage = { } }, actions: { + loadFrontendsStuff ({ state, rootState, dispatch, commit }) { + rootState.api.backendInteractor.fetchAvailableFrontends() + .then(frontends => commit('setAvailableFrontends', { frontends })) + }, loadAdminStuff ({ state, rootState, dispatch, commit }) { rootState.api.backendInteractor.fetchInstanceDBConfig() .then(backendDbConfig => { diff --git a/src/services/api/api.service.js b/src/services/api/api.service.js index 073f40a3..56e7de71 100644 --- a/src/services/api/api.service.js +++ b/src/services/api/api.service.js @@ -110,6 +110,8 @@ const PLEROMA_DELETE_ANNOUNCEMENT_URL = id => `/api/v1/pleroma/admin/announcemen const PLEROMA_ADMIN_CONFIG_URL = '/api/pleroma/admin/config' const PLEROMA_ADMIN_DESCRIPTIONS_URL = '/api/pleroma/admin/config/descriptions' +const PLEROMA_ADMIN_FRONTENDS_URL = '/api/pleroma/admin/frontends' +const PLEROMA_ADMIN_FRONTENDS_INSTALL_URL = '/api/pleroma/admin/frontends/install' const oldfetch = window.fetch @@ -1693,6 +1695,21 @@ const fetchInstanceConfigDescriptions = ({ credentials }) => { }) } +const fetchAvailableFrontends = ({ credentials }) => { + return fetch(PLEROMA_ADMIN_FRONTENDS_URL, { + headers: authHeaders(credentials) + }) + .then((response) => { + if (response.ok) { + return response.json() + } else { + return { + error: response + } + } + }) +} + const pushInstanceDBConfig = ({ credentials, payload }) => { return fetch(PLEROMA_ADMIN_CONFIG_URL, { headers: { @@ -1714,6 +1731,27 @@ const pushInstanceDBConfig = ({ credentials, payload }) => { }) } +const installFrontend = ({ credentials, payload }) => { + return fetch(PLEROMA_ADMIN_FRONTENDS_INSTALL_URL, { + headers: { + Accept: 'application/json', + 'Content-Type': 'application/json', + ...authHeaders(credentials) + }, + method: 'POST', + body: JSON.stringify(payload) + }) + .then((response) => { + if (response.ok) { + return response.json() + } else { + return { + error: response + } + } + }) +} + const apiService = { verifyCredentials, fetchTimeline, @@ -1830,7 +1868,9 @@ const apiService = { adminFetchAnnouncements, fetchInstanceDBConfig, fetchInstanceConfigDescriptions, - pushInstanceDBConfig + fetchAvailableFrontends, + pushInstanceDBConfig, + installFrontend } export default apiService -- cgit v1.2.3-70-g09d2 From d72486f3e4f2af9db95535f3f93e6257c675e155 Mon Sep 17 00:00:00 2001 From: tusooa Date: Wed, 12 Jul 2023 21:34:19 -0400 Subject: Implement sending quote posts --- .../post_status_form/post_status_form.js | 31 ++++++++++++-- .../post_status_form/post_status_form.vue | 50 ++++++++++++++++++++++ src/i18n/en.json | 2 + src/services/api/api.service.js | 4 ++ .../status_poster/status_poster.service.js | 2 + 5 files changed, 85 insertions(+), 4 deletions(-) (limited to 'src/services/api/api.service.js') diff --git a/src/components/post_status_form/post_status_form.js b/src/components/post_status_form/post_status_form.js index b75fee69..73176132 100644 --- a/src/components/post_status_form/post_status_form.js +++ b/src/components/post_status_form/post_status_form.js @@ -156,7 +156,8 @@ const PostStatusForm = { poll: this.statusPoll || {}, mediaDescriptions: this.statusMediaDescriptions || {}, visibility: this.statusScope || scope, - contentType: statusContentType + contentType: statusContentType, + quoting: false } } @@ -265,6 +266,24 @@ const PostStatusForm = { isEdit () { return typeof this.statusId !== 'undefined' && this.statusId.trim() !== '' }, + quotable () { + if (!this.replyTo) { + return false + } + + const repliedStatus = this.$store.state.statuses.allStatusesObject[this.replyTo] + if (!repliedStatus) { + return false + } + + if (repliedStatus.visibility === 'public' || + repliedStatus.visibility === 'unlisted' || + repliedStatus.visibility === 'local') { + return true + } else if (repliedStatus.visibility === 'private') { + return repliedStatus.account.id === this.$store.state.users.currentUser.id + } + }, ...mapGetters(['mergedConfig']), ...mapState({ mobileLayout: state => state.interface.mobileLayout @@ -292,7 +311,8 @@ const PostStatusForm = { visibility: newStatus.visibility, contentType: newStatus.contentType, poll: {}, - mediaDescriptions: {} + mediaDescriptions: {}, + quoting: false } this.pollFormVisible = false this.$refs.mediaUpload && this.$refs.mediaUpload.clearFile() @@ -340,6 +360,8 @@ const PostStatusForm = { return } + const replyOrQuoteAttr = newStatus.quoting ? 'quoteId' : 'inReplyToStatusId' + const postingOptions = { status: newStatus.status, spoilerText: newStatus.spoilerText || null, @@ -347,7 +369,7 @@ const PostStatusForm = { sensitive: newStatus.nsfw, media: newStatus.files, store: this.$store, - inReplyToStatusId: this.replyTo, + [replyOrQuoteAttr]: this.replyTo, contentType: newStatus.contentType, poll, idempotencyKey: this.idempotencyKey @@ -373,6 +395,7 @@ const PostStatusForm = { } const newStatus = this.newStatus this.previewLoading = true + const replyOrQuoteAttr = newStatus.quoting ? 'quoteId' : 'inReplyToStatusId' statusPoster.postStatus({ status: newStatus.status, spoilerText: newStatus.spoilerText || null, @@ -380,7 +403,7 @@ const PostStatusForm = { sensitive: newStatus.nsfw, media: [], store: this.$store, - inReplyToStatusId: this.replyTo, + [replyOrQuoteAttr]: this.replyTo, contentType: newStatus.contentType, poll: {}, preview: true diff --git a/src/components/post_status_form/post_status_form.vue b/src/components/post_status_form/post_status_form.vue index 86c1f907..e06b88b2 100644 --- a/src/components/post_status_form/post_status_form.vue +++ b/src/components/post_status_form/post_status_form.vue @@ -126,6 +126,42 @@ class="preview-status" /> +
    + + +