Fix scheduled posts

Fixes https://gitlab.com/soapbox-pub/soapbox/-/issues/1445
This commit is contained in:
Alex Gleason 2023-07-17 10:19:27 -05:00
parent 77cf9e9d1e
commit 6b8be7af3c
No known key found for this signature in database
GPG Key ID: 7211D1F99744FBB7
3 changed files with 11 additions and 2 deletions

View File

@ -22,7 +22,6 @@ interface IScheduledStatus {
const ScheduledStatus: React.FC<IScheduledStatus> = ({ statusId, ...other }) => {
const status = useAppSelector((state) => {
const scheduledStatus = state.scheduled_statuses.get(statusId);
if (!scheduledStatus) return null;
return buildStatus(state, scheduledStatus);
}) as StatusEntity | null;

View File

@ -14,6 +14,7 @@ import { normalizeAttachment } from 'soapbox/normalizers/attachment';
import { normalizeEmoji } from 'soapbox/normalizers/emoji';
import { normalizeMention } from 'soapbox/normalizers/mention';
import { accountSchema, cardSchema, groupSchema, pollSchema, tombstoneSchema } from 'soapbox/schemas';
import { maybeFromJS } from 'soapbox/utils/normalizers';
import type { Account, Attachment, Card, Emoji, Group, Mention, Poll, EmbeddedEntity } from 'soapbox/types/entities';
@ -245,7 +246,7 @@ const normalizeDislikes = (status: ImmutableMap<string, any>) => {
const parseAccount = (status: ImmutableMap<string, any>) => {
try {
const account = accountSchema.parse(status.get('account').toJS());
const account = accountSchema.parse(maybeFromJS(status.get('account')));
return status.set('account', account);
} catch (_e) {
return status.set('account', null);

View File

@ -26,4 +26,13 @@ export type Normalizer<V, R> = (value: V) => R;
*/
export const toSchema = <V, R>(normalizer: Normalizer<V, R>) => {
return z.custom<V>().transform<R>(normalizer);
};
/** Legacy normalizer transition helper function. */
export const maybeFromJS = (value: any): unknown => {
if ('toJS' in value) {
return value.toJS();
} else {
return value;
}
};