From 4424dbad4b5df3157dfc599d415f8ccec94accac Mon Sep 17 00:00:00 2001 From: Kouhai Date: Thu, 29 Dec 2022 22:23:04 -0600 Subject: [PATCH 1/2] fix missing qt summary autofill --- .../flavours/glitch/reducers/compose.js | 94 +++++++++---------- 1 file changed, 46 insertions(+), 48 deletions(-) diff --git a/app/javascript/flavours/glitch/reducers/compose.js b/app/javascript/flavours/glitch/reducers/compose.js index a37d506783..b305496bb9 100644 --- a/app/javascript/flavours/glitch/reducers/compose.js +++ b/app/javascript/flavours/glitch/reducers/compose.js @@ -362,6 +362,51 @@ const updateSuggestionTags = (state, token) => { }); }; +const updateWithReply = (state, action) => { + // doesn't support QT&reply + const isQuote = action.type === COMPOSE_QUOTE; + const parentStatusId = action.status.get('id'); + + return state.withMutations(map => { + map.set('id', null); + map.set('privacy', privacyPreference(action.status.get('visibility'), state.get('default_privacy'))); + map.update( + 'advanced_options', + map => map.merge(new ImmutableMap({ do_not_federate: !!action.status.get('local_only') })), + ); + map.set('focusDate', new Date()); + map.set('caretPosition', null); + map.set('preselectDate', new Date()); + map.set('idempotencyKey', uuid()); + + if (action.status.get('spoiler_text').length > 0) { + let spoilerText = action.status.get('spoiler_text'); + if (action.prependCWRe && !spoilerText.match(/^(re|qt)[: ]/i)) { + spoilerText = isQuote ? `QT: ${spoilerText}` : `re: ${spoilerText}`; + } + map.set('spoiler', true); + map.set('spoiler_text', spoilerText); + } else { + map.set('spoiler', false); + map.set('spoiler_text', ''); + } + + if (isQuote) { + map.set('in_reply_to', null); + map.set('quote_id', parentStatusId); + map.set('text', ''); + } else { + map.set('in_reply_to', parentStatusId); + map.set('quote_id', null); + map.set('text', statusToTextMentions(state, action.status)); + + if (action.status.get('language')) { + map.set('language', action.status.get('language')); + } + } + }); +}; + export default function compose(state = initialState, action) { switch(action.type) { case STORE_HYDRATE: @@ -411,55 +456,8 @@ export default function compose(state = initialState, action) { return state .set('elefriend', (state.get('elefriend') + 1) % totalElefriends); case COMPOSE_REPLY: - return state.withMutations(map => { - map.set('id', null); - map.set('in_reply_to', action.status.get('id')); - map.set('quote_id', null); - map.set('text', statusToTextMentions(state, action.status)); - map.set('privacy', privacyPreference(action.status.get('visibility'), state.get('default_privacy'))); - map.update( - 'advanced_options', - map => map.merge(new ImmutableMap({ do_not_federate: !!action.status.get('local_only') })) - ); - map.set('focusDate', new Date()); - map.set('caretPosition', null); - map.set('preselectDate', new Date()); - map.set('idempotencyKey', uuid()); - - if (action.status.get('language') && !action.status.has('translation')) { - map.set('language', action.status.get('language')); - } else { - map.set('language', state.get('default_language')); - } - - if (action.status.get('spoiler_text').length > 0) { - let spoiler_text = action.status.get('spoiler_text'); - if (action.prependCWRe && !spoiler_text.match(/^re[: ]/i)) { - spoiler_text = 're: '.concat(spoiler_text); - } - map.set('spoiler', true); - map.set('spoiler_text', spoiler_text); - } else { - map.set('spoiler', false); - map.set('spoiler_text', ''); - } - }); case COMPOSE_QUOTE: - return state.withMutations(map => { - map.set('id', null); - map.set('in_reply_to', null); - map.set('quote_id', action.status.get('id')); - map.set('text', ''); - map.set('privacy', privacyPreference(action.status.get('visibility'), state.get('default_privacy'))); - map.update( - 'advanced_options', - map => map.merge(new ImmutableMap({ do_not_federate: !!action.status.get('local_only') })) - ); - map.set('focusDate', new Date()); - map.set('caretPosition', null); - map.set('preselectDate', new Date()); - map.set('idempotencyKey', uuid()); - }); + return updateWithReply(state, action); case COMPOSE_REPLY_CANCEL: state = state.setIn(['advanced_options', 'threaded_mode'], false); case COMPOSE_QUOTE_CANCEL: -- 2.41.0 From 0ff80581b90853774c0a16b07ccf1c20bf5edc66 Mon Sep 17 00:00:00 2001 From: Kouhai Date: Thu, 29 Dec 2022 22:23:09 -0600 Subject: [PATCH 2/2] fix lints --- .../flavours/glitch/reducers/compose.js | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/app/javascript/flavours/glitch/reducers/compose.js b/app/javascript/flavours/glitch/reducers/compose.js index b305496bb9..6162ab6e2d 100644 --- a/app/javascript/flavours/glitch/reducers/compose.js +++ b/app/javascript/flavours/glitch/reducers/compose.js @@ -153,16 +153,16 @@ function apiStatusToTextMentions (state, status) { } return set.union(status.mentions.filter( - mention => mention.id !== me + mention => mention.id !== me, ).map( - mention => `@${mention.acct} ` + mention => `@${mention.acct} `, )).join(''); } function apiStatusToTextHashtags (state, status) { const text = unescapeHTML(status.content); return ImmutableOrderedSet([]).union(recoverHashtags(status.tags, text).map( - (name) => `#${name} ` + (name) => `#${name} `, )).join(''); } @@ -179,7 +179,7 @@ function clearAll(state) { map.set('quote_id', null); map.update( 'advanced_options', - map => map.mergeWith(overwrite, state.get('default_advanced_options')) + map => map.mergeWith(overwrite, state.get('default_advanced_options')), ); map.set('privacy', state.get('default_privacy')); map.set('sensitive', state.get('default_sensitive')); @@ -206,7 +206,7 @@ function continueThread (state, status) { map.set('in_reply_to', status.id); map.update( 'advanced_options', - map => map.merge(new ImmutableMap({ do_not_federate: status.local_only })) + map => map.merge(new ImmutableMap({ do_not_federate: status.local_only })), ); map.set('privacy', status.visibility); map.set('sensitive', false); @@ -460,6 +460,7 @@ export default function compose(state = initialState, action) { return updateWithReply(state, action); case COMPOSE_REPLY_CANCEL: state = state.setIn(['advanced_options', 'threaded_mode'], false); + // fall through case COMPOSE_QUOTE_CANCEL: case COMPOSE_RESET: return state.withMutations(map => { @@ -474,7 +475,7 @@ export default function compose(state = initialState, action) { map.set('poll', null); map.update( 'advanced_options', - map => map.mergeWith(overwrite, state.get('default_advanced_options')) + map => map.mergeWith(overwrite, state.get('default_advanced_options')), ); map.set('idempotencyKey', uuid()); }); @@ -517,6 +518,7 @@ export default function compose(state = initialState, action) { return item; })); case INIT_MEDIA_EDIT_MODAL: + { const media = state.get('media_attachments').find(item => item.get('id') === action.id); return state.set('media_modal', ImmutableMap({ id: action.id, @@ -525,6 +527,7 @@ export default function compose(state = initialState, action) { focusY: media.getIn(['meta', 'focus', 'y'], 0), dirty: false, })); + } case COMPOSE_CHANGE_MEDIA_DESCRIPTION: return state.setIn(['media_modal', 'description'], action.description).setIn(['media_modal', 'dirty'], true); case COMPOSE_CHANGE_MEDIA_FOCUS: @@ -580,6 +583,7 @@ export default function compose(state = initialState, action) { case COMPOSE_DOODLE_SET: return state.mergeIn(['doodle'], action.options); case REDRAFT: + { const do_not_federate = !!action.status.get('local_only'); let text = action.raw_text || unescapeHTML(expandMentions(action.status)); if (do_not_federate) text = text.replace(/ ?👁\ufe0f?\u200b?$/, ''); @@ -596,7 +600,7 @@ export default function compose(state = initialState, action) { map.set('language', action.status.get('language')); map.update( 'advanced_options', - map => map.merge(new ImmutableMap({ do_not_federate })) + map => map.merge(new ImmutableMap({ do_not_federate })), ); map.set('id', null); @@ -620,6 +624,7 @@ export default function compose(state = initialState, action) { })); } }); + } case COMPOSE_SET_STATUS: return state.withMutations(map => { map.set('id', action.status.get('id')); -- 2.41.0