fix-qt-summary #42

Merged
kouhai merged 2 commits from fix-qt-summary into main 2022-12-30 04:30:15 +00:00
1 changed files with 58 additions and 55 deletions

View File

@ -153,16 +153,16 @@ function apiStatusToTextMentions (state, status) {
} }
return set.union(status.mentions.filter( return set.union(status.mentions.filter(
mention => mention.id !== me mention => mention.id !== me,
).map( ).map(
mention => `@${mention.acct} ` mention => `@${mention.acct} `,
)).join(''); )).join('');
} }
function apiStatusToTextHashtags (state, status) { function apiStatusToTextHashtags (state, status) {
const text = unescapeHTML(status.content); const text = unescapeHTML(status.content);
return ImmutableOrderedSet([]).union(recoverHashtags(status.tags, text).map( return ImmutableOrderedSet([]).union(recoverHashtags(status.tags, text).map(
(name) => `#${name} ` (name) => `#${name} `,
)).join(''); )).join('');
} }
@ -179,7 +179,7 @@ function clearAll(state) {
map.set('quote_id', null); map.set('quote_id', null);
map.update( map.update(
'advanced_options', '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('privacy', state.get('default_privacy'));
map.set('sensitive', state.get('default_sensitive')); map.set('sensitive', state.get('default_sensitive'));
@ -206,7 +206,7 @@ function continueThread (state, status) {
map.set('in_reply_to', status.id); map.set('in_reply_to', status.id);
map.update( map.update(
'advanced_options', '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('privacy', status.visibility);
map.set('sensitive', false); map.set('sensitive', false);
@ -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) { export default function compose(state = initialState, action) {
switch(action.type) { switch(action.type) {
case STORE_HYDRATE: case STORE_HYDRATE:
@ -411,57 +456,11 @@ export default function compose(state = initialState, action) {
return state return state
.set('elefriend', (state.get('elefriend') + 1) % totalElefriends); .set('elefriend', (state.get('elefriend') + 1) % totalElefriends);
case COMPOSE_REPLY: 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: case COMPOSE_QUOTE:
return state.withMutations(map => { return updateWithReply(state, action);
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());
});
case COMPOSE_REPLY_CANCEL: case COMPOSE_REPLY_CANCEL:
state = state.setIn(['advanced_options', 'threaded_mode'], false); state = state.setIn(['advanced_options', 'threaded_mode'], false);
// fall through
case COMPOSE_QUOTE_CANCEL: case COMPOSE_QUOTE_CANCEL:
case COMPOSE_RESET: case COMPOSE_RESET:
return state.withMutations(map => { return state.withMutations(map => {
@ -476,7 +475,7 @@ export default function compose(state = initialState, action) {
map.set('poll', null); map.set('poll', null);
map.update( map.update(
'advanced_options', 'advanced_options',
map => map.mergeWith(overwrite, state.get('default_advanced_options')) map => map.mergeWith(overwrite, state.get('default_advanced_options')),
); );
map.set('idempotencyKey', uuid()); map.set('idempotencyKey', uuid());
}); });
@ -519,6 +518,7 @@ export default function compose(state = initialState, action) {
return item; return item;
})); }));
case INIT_MEDIA_EDIT_MODAL: case INIT_MEDIA_EDIT_MODAL:
{
const media = state.get('media_attachments').find(item => item.get('id') === action.id); const media = state.get('media_attachments').find(item => item.get('id') === action.id);
return state.set('media_modal', ImmutableMap({ return state.set('media_modal', ImmutableMap({
id: action.id, id: action.id,
@ -527,6 +527,7 @@ export default function compose(state = initialState, action) {
focusY: media.getIn(['meta', 'focus', 'y'], 0), focusY: media.getIn(['meta', 'focus', 'y'], 0),
dirty: false, dirty: false,
})); }));
}
case COMPOSE_CHANGE_MEDIA_DESCRIPTION: case COMPOSE_CHANGE_MEDIA_DESCRIPTION:
return state.setIn(['media_modal', 'description'], action.description).setIn(['media_modal', 'dirty'], true); return state.setIn(['media_modal', 'description'], action.description).setIn(['media_modal', 'dirty'], true);
case COMPOSE_CHANGE_MEDIA_FOCUS: case COMPOSE_CHANGE_MEDIA_FOCUS:
@ -582,6 +583,7 @@ export default function compose(state = initialState, action) {
case COMPOSE_DOODLE_SET: case COMPOSE_DOODLE_SET:
return state.mergeIn(['doodle'], action.options); return state.mergeIn(['doodle'], action.options);
case REDRAFT: case REDRAFT:
{
const do_not_federate = !!action.status.get('local_only'); const do_not_federate = !!action.status.get('local_only');
let text = action.raw_text || unescapeHTML(expandMentions(action.status)); let text = action.raw_text || unescapeHTML(expandMentions(action.status));
if (do_not_federate) text = text.replace(/ ?👁\ufe0f?\u200b?$/, ''); if (do_not_federate) text = text.replace(/ ?👁\ufe0f?\u200b?$/, '');
@ -598,7 +600,7 @@ export default function compose(state = initialState, action) {
map.set('language', action.status.get('language')); map.set('language', action.status.get('language'));
map.update( map.update(
'advanced_options', 'advanced_options',
map => map.merge(new ImmutableMap({ do_not_federate })) map => map.merge(new ImmutableMap({ do_not_federate })),
); );
map.set('id', null); map.set('id', null);
@ -622,6 +624,7 @@ export default function compose(state = initialState, action) {
})); }));
} }
}); });
}
case COMPOSE_SET_STATUS: case COMPOSE_SET_STATUS:
return state.withMutations(map => { return state.withMutations(map => {
map.set('id', action.status.get('id')); map.set('id', action.status.get('id'));