Checkpoint: without error

update-compose
danidfra 2024-12-10 23:14:57 -03:00
rodzic 3267c26f59
commit 226eee110b
1 zmienionych plików z 20 dodań i 16 usunięć

Wyświetl plik

@ -1,4 +1,4 @@
import { List as ImmutableList, OrderedSet as ImmutableOrderedSet, fromJS } from 'immutable'; import { OrderedSet as ImmutableOrderedSet, fromJS } from 'immutable';
import { isNativeEmoji } from 'soapbox/features/emoji/index.ts'; import { isNativeEmoji } from 'soapbox/features/emoji/index.ts';
import { Account } from 'soapbox/schemas/index.ts'; import { Account } from 'soapbox/schemas/index.ts';
@ -78,7 +78,7 @@ interface Poll {
multiple: boolean; multiple: boolean;
} }
interface Compose { export interface Compose {
caretPosition: number | null; caretPosition: number | null;
content_type: string; content_type: string;
editorState: string | null; editorState: string | null;
@ -109,7 +109,7 @@ interface Compose {
group_timeline_visible: boolean; // TruthSocial group_timeline_visible: boolean; // TruthSocial
} }
const initialCompose: Compose = { export const initialCompose: Compose = {
caretPosition: null, caretPosition: null,
content_type: 'text/plain', content_type: 'text/plain',
editorState: null, editorState: null,
@ -137,7 +137,7 @@ const initialCompose: Compose = {
tagHistory: [], tagHistory: [],
text: '', text: '',
to: [], to: [],
group_timeline_visible: false, group_timeline_visible: false, // TruthSocial
}; };
// export const ReducerCompose = ImmutableRecord({ // export const ReducerCompose = ImmutableRecord({
@ -171,7 +171,9 @@ const initialCompose: Compose = {
// group_timeline_visible: false, // TruthSocial // group_timeline_visible: false, // TruthSocial
// }); // });
type State = Record<string, Compose>; type State = {
[key: string]: Compose;
};
// type Compose = ReturnType<typeof ReducerCompose>; // type Compose = ReturnType<typeof ReducerCompose>;
const PollRecord = (): Poll => ({ const PollRecord = (): Poll => ({
options: ['', ''], options: ['', ''],
@ -335,21 +337,23 @@ const getExplicitMentions = (me: string, status: Status) => {
return [...new Set(mentions)].sort(); return [...new Set(mentions)].sort();
}; };
const getAccountSettings = (account: ImmutableMap<string, any>) => { const getAccountSettings = (account: APIEntity) => {
return account.getIn(['pleroma', 'settings_store', FE_NAME], ImmutableMap()) as ImmutableMap<string, any>; const settingsStore = account.pleroma?.settings_store;
return settingsStore && settingsStore[FE_NAME] ? settingsStore[FE_NAME] : {};
}; };
const importAccount = (compose: Compose, account: APIEntity) => { const importAccount = (compose: Compose, account: Account | APIEntity) => {
const settings = getAccountSettings(ImmutableMap(fromJS(account))); const settings = getAccountSettings(account);
const defaultPrivacy = settings.get('defaultPrivacy'); const defaultPrivacy = settings.defaultPrivacy;
const defaultContentType = settings.get('defaultContentType'); const defaultContentType = settings.defaultContentType;
return compose.withMutations(compose => { return {
if (defaultPrivacy) compose.set('privacy', defaultPrivacy); ...compose,
if (defaultContentType) compose.set('content_type', defaultContentType); privacy: defaultPrivacy !== undefined ? defaultPrivacy : compose.privacy,
compose.set('tagHistory', ImmutableList(tagHistory.get(account.id))); content_type: defaultContentType !== undefined ? defaultContentType : compose.content_type,
}); tagHistory: tagHistory.get(account.id) || [],
};
}; };
const updateSetting = (compose: Compose, path: string[], value: string) => { const updateSetting = (compose: Compose, path: string[], value: string) => {