kopia lustrzana https://gitlab.com/soapbox-pub/soapbox
`default` cleanup
Signed-off-by: marcin mikołajczak <git@mkljczk.pl>environments/review-gleasonato-trtlxz/deployments/985
rodzic
cb3df8211c
commit
c31e13b0a5
|
@ -31,8 +31,6 @@ describe('compose reducer', () => {
|
||||||
poll: null,
|
poll: null,
|
||||||
suggestion_token: null,
|
suggestion_token: null,
|
||||||
suggestions: [],
|
suggestions: [],
|
||||||
default_privacy: 'public',
|
|
||||||
default_sensitive: false,
|
|
||||||
tagHistory: [],
|
tagHistory: [],
|
||||||
content_type: 'text/plain',
|
content_type: 'text/plain',
|
||||||
},
|
},
|
||||||
|
@ -100,7 +98,7 @@ describe('compose reducer', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('uses \'direct\' scope when replying to a DM', () => {
|
it('uses \'direct\' scope when replying to a DM', () => {
|
||||||
const state = initialState.set('default', ReducerCompose({ default_privacy: 'public' }));
|
const state = initialState.set('default', ReducerCompose({ privacy: 'public' }));
|
||||||
const action = {
|
const action = {
|
||||||
type: actions.COMPOSE_REPLY,
|
type: actions.COMPOSE_REPLY,
|
||||||
status: ImmutableRecord({ visibility: 'direct' })(),
|
status: ImmutableRecord({ visibility: 'direct' })(),
|
||||||
|
@ -110,7 +108,7 @@ describe('compose reducer', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('uses \'private\' scope when replying to a private post', () => {
|
it('uses \'private\' scope when replying to a private post', () => {
|
||||||
const state = initialState.set('default', ReducerCompose({ default_privacy: 'public' }));
|
const state = initialState.set('default', ReducerCompose({ privacy: 'public' }));
|
||||||
const action = {
|
const action = {
|
||||||
type: actions.COMPOSE_REPLY,
|
type: actions.COMPOSE_REPLY,
|
||||||
status: ImmutableRecord({ visibility: 'private' })(),
|
status: ImmutableRecord({ visibility: 'private' })(),
|
||||||
|
@ -120,7 +118,7 @@ describe('compose reducer', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('uses \'unlisted\' scope when replying to an unlisted post', () => {
|
it('uses \'unlisted\' scope when replying to an unlisted post', () => {
|
||||||
const state = initialState.set('default', ReducerCompose({ default_privacy: 'public' }));
|
const state = initialState.set('default', ReducerCompose({ privacy: 'public' }));
|
||||||
const action = {
|
const action = {
|
||||||
type: actions.COMPOSE_REPLY,
|
type: actions.COMPOSE_REPLY,
|
||||||
status: ImmutableRecord({ visibility: 'unlisted' })(),
|
status: ImmutableRecord({ visibility: 'unlisted' })(),
|
||||||
|
@ -130,7 +128,7 @@ describe('compose reducer', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('uses \'private\' scope when set as preference and replying to a public post', () => {
|
it('uses \'private\' scope when set as preference and replying to a public post', () => {
|
||||||
const state = initialState.set('default', ReducerCompose({ default_privacy: 'private' }));
|
const state = initialState.set('default', ReducerCompose({ privacy: 'private' }));
|
||||||
const action = {
|
const action = {
|
||||||
type: actions.COMPOSE_REPLY,
|
type: actions.COMPOSE_REPLY,
|
||||||
status: ImmutableRecord({ visibility: 'public' })(),
|
status: ImmutableRecord({ visibility: 'public' })(),
|
||||||
|
@ -140,7 +138,7 @@ describe('compose reducer', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('uses \'unlisted\' scope when set as preference and replying to a public post', () => {
|
it('uses \'unlisted\' scope when set as preference and replying to a public post', () => {
|
||||||
const state = initialState.set('default', ReducerCompose({ default_privacy: 'unlisted' }));
|
const state = initialState.set('default', ReducerCompose({ privacy: 'unlisted' }));
|
||||||
const action = {
|
const action = {
|
||||||
type: actions.COMPOSE_REPLY,
|
type: actions.COMPOSE_REPLY,
|
||||||
status: ImmutableRecord({ visibility: 'public' })(),
|
status: ImmutableRecord({ visibility: 'public' })(),
|
||||||
|
@ -150,38 +148,35 @@ describe('compose reducer', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('sets preferred scope on user login', () => {
|
it('sets preferred scope on user login', () => {
|
||||||
const state = initialState.set('default', ReducerCompose({ default_privacy: 'public' }));
|
const state = initialState.set('default', ReducerCompose({ privacy: 'public' }));
|
||||||
const action = {
|
const action = {
|
||||||
type: ME_FETCH_SUCCESS,
|
type: ME_FETCH_SUCCESS,
|
||||||
me: { pleroma: { settings_store: { soapbox_fe: { defaultPrivacy: 'unlisted' } } } },
|
me: { pleroma: { settings_store: { soapbox_fe: { defaultPrivacy: 'unlisted' } } } },
|
||||||
};
|
};
|
||||||
expect(reducer(state, action).toJS().default).toMatchObject({
|
expect(reducer(state, action).toJS().default).toMatchObject({
|
||||||
default_privacy: 'unlisted',
|
|
||||||
privacy: 'unlisted',
|
privacy: 'unlisted',
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('sets preferred scope on settings change', () => {
|
it('sets preferred scope on settings change', () => {
|
||||||
const state = initialState.set('default', ReducerCompose({ default_privacy: 'public' }));
|
const state = initialState.set('default', ReducerCompose({ privacy: 'public' }));
|
||||||
const action = {
|
const action = {
|
||||||
type: SETTING_CHANGE,
|
type: SETTING_CHANGE,
|
||||||
path: ['defaultPrivacy'],
|
path: ['defaultPrivacy'],
|
||||||
value: 'unlisted',
|
value: 'unlisted',
|
||||||
};
|
};
|
||||||
expect(reducer(state, action).toJS().default).toMatchObject({
|
expect(reducer(state, action).toJS().default).toMatchObject({
|
||||||
default_privacy: 'unlisted',
|
|
||||||
privacy: 'unlisted',
|
privacy: 'unlisted',
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('sets default scope on settings save (but retains current scope)', () => {
|
it('sets default scope on settings save (but retains current scope)', () => {
|
||||||
const state = initialState.set('default', ReducerCompose({ default_privacy: 'public', privacy: 'public' }));
|
const state = initialState.set('default', ReducerCompose({ privacy: 'public' }));
|
||||||
const action = {
|
const action = {
|
||||||
type: ME_PATCH_SUCCESS,
|
type: ME_PATCH_SUCCESS,
|
||||||
me: { pleroma: { settings_store: { soapbox_fe: { defaultPrivacy: 'unlisted' } } } },
|
me: { pleroma: { settings_store: { soapbox_fe: { defaultPrivacy: 'unlisted' } } } },
|
||||||
};
|
};
|
||||||
expect(reducer(state, action).toJS().default).toMatchObject({
|
expect(reducer(state, action).toJS().default).toMatchObject({
|
||||||
default_privacy: 'unlisted',
|
|
||||||
privacy: 'public',
|
privacy: 'public',
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -293,7 +288,7 @@ describe('compose reducer', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should handle COMPOSE_SUBMIT_SUCCESS', () => {
|
it('should handle COMPOSE_SUBMIT_SUCCESS', () => {
|
||||||
const state = initialState.set('home', ReducerCompose({ default_privacy: 'public', privacy: 'private' }));
|
const state = initialState.set('home', ReducerCompose({ privacy: 'private' }));
|
||||||
const action = {
|
const action = {
|
||||||
type: actions.COMPOSE_SUBMIT_SUCCESS,
|
type: actions.COMPOSE_SUBMIT_SUCCESS,
|
||||||
id: 'home',
|
id: 'home',
|
||||||
|
|
|
@ -77,9 +77,6 @@ const PollRecord = ImmutableRecord({
|
||||||
export const ReducerCompose = ImmutableRecord({
|
export const ReducerCompose = ImmutableRecord({
|
||||||
caretPosition: null as number | null,
|
caretPosition: null as number | null,
|
||||||
content_type: 'text/plain',
|
content_type: 'text/plain',
|
||||||
default_content_type: 'text/plain',
|
|
||||||
default_privacy: 'public',
|
|
||||||
default_sensitive: false,
|
|
||||||
focusDate: null as Date | null,
|
focusDate: null as Date | null,
|
||||||
idempotencyKey: '',
|
idempotencyKey: '',
|
||||||
id: null as string | null,
|
id: null as string | null,
|
||||||
|
@ -138,7 +135,7 @@ export const statusToMentionsAccountIdsArray = (status: StatusEntity, account: A
|
||||||
.delete(account.id) as ImmutableOrderedSet<string>;
|
.delete(account.id) as ImmutableOrderedSet<string>;
|
||||||
};
|
};
|
||||||
|
|
||||||
function appendMedia(compose: Compose, media: APIEntity) {
|
const appendMedia = (compose: Compose, media: APIEntity, defaultSensitive?: boolean) => {
|
||||||
const prevSize = compose.media_attachments.size;
|
const prevSize = compose.media_attachments.size;
|
||||||
|
|
||||||
return compose.withMutations(map => {
|
return compose.withMutations(map => {
|
||||||
|
@ -147,13 +144,13 @@ function appendMedia(compose: Compose, media: APIEntity) {
|
||||||
map.set('resetFileKey', Math.floor((Math.random() * 0x10000)));
|
map.set('resetFileKey', Math.floor((Math.random() * 0x10000)));
|
||||||
map.set('idempotencyKey', uuid());
|
map.set('idempotencyKey', uuid());
|
||||||
|
|
||||||
if (prevSize === 0 && (compose.default_sensitive || compose.spoiler)) {
|
if (prevSize === 0 && (defaultSensitive || compose.spoiler)) {
|
||||||
map.set('sensitive', true);
|
map.set('sensitive', true);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
};
|
||||||
|
|
||||||
function removeMedia(compose: Compose, mediaId: string) {
|
const removeMedia = (compose: Compose, mediaId: string) => {
|
||||||
const prevSize = compose.media_attachments.size;
|
const prevSize = compose.media_attachments.size;
|
||||||
|
|
||||||
return compose.withMutations(map => {
|
return compose.withMutations(map => {
|
||||||
|
@ -164,7 +161,7 @@ function removeMedia(compose: Compose, mediaId: string) {
|
||||||
map.set('sensitive', false);
|
map.set('sensitive', false);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
};
|
||||||
|
|
||||||
const insertSuggestion = (compose: Compose, position: number, token: string, completion: string, path: Array<string | number>) => {
|
const insertSuggestion = (compose: Compose, position: number, token: string, completion: string, path: Array<string | number>) => {
|
||||||
return compose.withMutations(map => {
|
return compose.withMutations(map => {
|
||||||
|
@ -243,9 +240,7 @@ const importAccount = (compose: Compose, account: APIEntity) => {
|
||||||
const defaultContentType = settings.get('defaultContentType', 'text/plain');
|
const defaultContentType = settings.get('defaultContentType', 'text/plain');
|
||||||
|
|
||||||
return compose.merge({
|
return compose.merge({
|
||||||
default_privacy: defaultPrivacy,
|
|
||||||
privacy: defaultPrivacy,
|
privacy: defaultPrivacy,
|
||||||
default_content_type: defaultContentType,
|
|
||||||
content_type: defaultContentType,
|
content_type: defaultContentType,
|
||||||
tagHistory: ImmutableList(tagHistory.get(account.id)),
|
tagHistory: ImmutableList(tagHistory.get(account.id)),
|
||||||
});
|
});
|
||||||
|
@ -258,8 +253,8 @@ const updateAccount = (compose: Compose, account: APIEntity) => {
|
||||||
const defaultContentType = settings.get('defaultContentType');
|
const defaultContentType = settings.get('defaultContentType');
|
||||||
|
|
||||||
return compose.withMutations(compose => {
|
return compose.withMutations(compose => {
|
||||||
if (defaultPrivacy) compose.set('default_privacy', defaultPrivacy);
|
if (defaultPrivacy) compose.set('privacy', defaultPrivacy);
|
||||||
if (defaultContentType) compose.set('default_content_type', defaultContentType);
|
if (defaultContentType) compose.set('content_type', defaultContentType);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -267,9 +262,9 @@ const updateSetting = (compose: Compose, path: string[], value: string) => {
|
||||||
const pathString = path.join(',');
|
const pathString = path.join(',');
|
||||||
switch (pathString) {
|
switch (pathString) {
|
||||||
case 'defaultPrivacy':
|
case 'defaultPrivacy':
|
||||||
return compose.set('default_privacy', value).set('privacy', value);
|
return compose.set('privacy', value);
|
||||||
case 'defaultContentType':
|
case 'defaultContentType':
|
||||||
return compose.set('default_content_type', value).set('content_type', value);
|
return compose.set('content_type', value);
|
||||||
default:
|
default:
|
||||||
return compose;
|
return compose;
|
||||||
}
|
}
|
||||||
|
@ -323,14 +318,16 @@ export default function compose(state = initialState, action: AnyAction) {
|
||||||
return updateCompose(state, action.id, compose => compose.set('is_composing', action.value));
|
return updateCompose(state, action.id, compose => compose.set('is_composing', action.value));
|
||||||
case COMPOSE_REPLY:
|
case COMPOSE_REPLY:
|
||||||
return updateCompose(state, 'compose-modal', compose => compose.withMutations(map => {
|
return updateCompose(state, 'compose-modal', compose => compose.withMutations(map => {
|
||||||
|
const defaultCompose = state.get('default')!;
|
||||||
|
|
||||||
map.set('in_reply_to', action.status.get('id'));
|
map.set('in_reply_to', action.status.get('id'));
|
||||||
map.set('to', action.explicitAddressing ? statusToMentionsArray(action.status, action.account) : ImmutableOrderedSet<string>());
|
map.set('to', action.explicitAddressing ? statusToMentionsArray(action.status, action.account) : ImmutableOrderedSet<string>());
|
||||||
map.set('text', !action.explicitAddressing ? statusToTextMentions(action.status, action.account) : '');
|
map.set('text', !action.explicitAddressing ? statusToTextMentions(action.status, action.account) : '');
|
||||||
map.set('privacy', privacyPreference(action.status.visibility, compose.default_privacy));
|
map.set('privacy', privacyPreference(action.status.visibility, defaultCompose.privacy));
|
||||||
map.set('focusDate', new Date());
|
map.set('focusDate', new Date());
|
||||||
map.set('caretPosition', null);
|
map.set('caretPosition', null);
|
||||||
map.set('idempotencyKey', uuid());
|
map.set('idempotencyKey', uuid());
|
||||||
map.set('content_type', compose.default_content_type);
|
map.set('content_type', defaultCompose.content_type);
|
||||||
|
|
||||||
if (action.status.get('spoiler_text', '').length > 0) {
|
if (action.status.get('spoiler_text', '').length > 0) {
|
||||||
map.set('spoiler', true);
|
map.set('spoiler', true);
|
||||||
|
@ -342,14 +339,16 @@ export default function compose(state = initialState, action: AnyAction) {
|
||||||
}));
|
}));
|
||||||
case COMPOSE_QUOTE:
|
case COMPOSE_QUOTE:
|
||||||
return updateCompose(state, 'compose-modal', compose => compose.withMutations(map => {
|
return updateCompose(state, 'compose-modal', compose => compose.withMutations(map => {
|
||||||
|
const defaultCompose = state.get('default')!;
|
||||||
|
|
||||||
map.set('quote', action.status.get('id'));
|
map.set('quote', action.status.get('id'));
|
||||||
map.set('to', ImmutableOrderedSet());
|
map.set('to', ImmutableOrderedSet());
|
||||||
map.set('text', '');
|
map.set('text', '');
|
||||||
map.set('privacy', privacyPreference(action.status.visibility, compose.default_privacy));
|
map.set('privacy', privacyPreference(action.status.visibility, defaultCompose.privacy));
|
||||||
map.set('focusDate', new Date());
|
map.set('focusDate', new Date());
|
||||||
map.set('caretPosition', null);
|
map.set('caretPosition', null);
|
||||||
map.set('idempotencyKey', uuid());
|
map.set('idempotencyKey', uuid());
|
||||||
map.set('content_type', compose.default_content_type);
|
map.set('content_type', defaultCompose.content_type);
|
||||||
map.set('spoiler', false);
|
map.set('spoiler', false);
|
||||||
map.set('spoiler_text', '');
|
map.set('spoiler_text', '');
|
||||||
}));
|
}));
|
||||||
|
@ -369,7 +368,7 @@ export default function compose(state = initialState, action: AnyAction) {
|
||||||
case COMPOSE_UPLOAD_REQUEST:
|
case COMPOSE_UPLOAD_REQUEST:
|
||||||
return updateCompose(state, action.id, compose => compose.set('is_uploading', true));
|
return updateCompose(state, action.id, compose => compose.set('is_uploading', true));
|
||||||
case COMPOSE_UPLOAD_SUCCESS:
|
case COMPOSE_UPLOAD_SUCCESS:
|
||||||
return updateCompose(state, action.id, compose => appendMedia(compose, fromJS(action.media)));
|
return updateCompose(state, action.id, compose => appendMedia(compose, fromJS(action.media), state.get('default')!.sensitive));
|
||||||
case COMPOSE_UPLOAD_FAIL:
|
case COMPOSE_UPLOAD_FAIL:
|
||||||
return updateCompose(state, action.id, compose => compose.set('is_uploading', false));
|
return updateCompose(state, action.id, compose => compose.set('is_uploading', false));
|
||||||
case COMPOSE_UPLOAD_UNDO:
|
case COMPOSE_UPLOAD_UNDO:
|
||||||
|
|
Ładowanie…
Reference in New Issue