From d8c07be0214db16eb1f2fe1ce8c053b08b2a6fe6 Mon Sep 17 00:00:00 2001 From: Claire Date: Mon, 25 Aug 2025 14:25:35 +0200 Subject: [PATCH] =?UTF-8?q?Fix=20Edit=20as=20well=20as=20=E2=80=9CDelete?= =?UTF-8?q?=20&=20Redraft=E2=80=9D=20on=20a=20poll=20not=20inserting=20emp?= =?UTF-8?q?ty=20option=20(#35892)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/javascript/mastodon/actions/compose.js | 17 +++++++++++------ app/javascript/mastodon/actions/statuses.js | 13 +++++++++---- app/javascript/mastodon/reducers/compose.js | 14 ++++++++++++-- 3 files changed, 32 insertions(+), 12 deletions(-) diff --git a/app/javascript/mastodon/actions/compose.js b/app/javascript/mastodon/actions/compose.js index 41b2336bc22..e3584897561 100644 --- a/app/javascript/mastodon/actions/compose.js +++ b/app/javascript/mastodon/actions/compose.js @@ -97,12 +97,17 @@ export const ensureComposeIsVisible = (getState) => { }; export function setComposeToStatus(status, text, spoiler_text) { - return{ - type: COMPOSE_SET_STATUS, - status, - text, - spoiler_text, - }; + return (dispatch, getState) => { + const maxOptions = getState().server.getIn(['server', 'configuration', 'polls', 'max_options']); + + dispatch({ + type: COMPOSE_SET_STATUS, + status, + text, + spoiler_text, + maxOptions, + }); + } } export function changeCompose(text) { diff --git a/app/javascript/mastodon/actions/statuses.js b/app/javascript/mastodon/actions/statuses.js index 42d0c1c0f11..58728936b71 100644 --- a/app/javascript/mastodon/actions/statuses.js +++ b/app/javascript/mastodon/actions/statuses.js @@ -89,10 +89,15 @@ export function fetchStatusFail(id, error, skipLoading) { } export function redraft(status, raw_text) { - return { - type: REDRAFT, - status, - raw_text, + return (dispatch, getState) => { + const maxOptions = getState().server.getIn(['server', 'configuration', 'polls', 'max_options']); + + dispatch({ + type: REDRAFT, + status, + raw_text, + maxOptions, + }); }; } diff --git a/app/javascript/mastodon/reducers/compose.js b/app/javascript/mastodon/reducers/compose.js index bb4ce9ce112..7f9fc9eeaa2 100644 --- a/app/javascript/mastodon/reducers/compose.js +++ b/app/javascript/mastodon/reducers/compose.js @@ -526,8 +526,13 @@ export const composeReducer = (state = initialState, action) => { } if (action.status.get('poll')) { + let options = ImmutableList(action.status.get('poll').options.map(x => x.title)); + if (options.size < action.maxOptions) { + options = options.push(''); + } + map.set('poll', ImmutableMap({ - options: ImmutableList(action.status.get('poll').options.map(x => x.title)), + options: options, multiple: action.status.get('poll').multiple, expires_in: expiresInFromExpiresAt(action.status.get('poll').expires_at), })); @@ -558,8 +563,13 @@ export const composeReducer = (state = initialState, action) => { } if (action.status.get('poll')) { + let options = ImmutableList(action.status.get('poll').options.map(x => x.title)); + if (options.size < action.maxOptions) { + options = options.push(''); + } + map.set('poll', ImmutableMap({ - options: ImmutableList(action.status.get('poll').options.map(x => x.title)), + options: options, multiple: action.status.get('poll').multiple, expires_in: expiresInFromExpiresAt(action.status.get('poll').expires_at), }));