sforkowany z mirror/soapbox
normalizeStatus: refactor baseStatus
rodzic
717a0917a3
commit
7877fce7ba
|
@ -3,12 +3,16 @@ import { Map as ImmutableMap, List as ImmutableList } from 'immutable';
|
||||||
import { accountToMention } from 'soapbox/utils/accounts';
|
import { accountToMention } from 'soapbox/utils/accounts';
|
||||||
|
|
||||||
// Some backends can return null, or omit these required fields
|
// Some backends can return null, or omit these required fields
|
||||||
const setRequiredFields = status => {
|
const baseStatus = ImmutableMap({
|
||||||
return status.merge({
|
emojis: ImmutableList(),
|
||||||
emojis: status.get('emojis') || ImmutableList(),
|
spoiler_text: '',
|
||||||
spoiler_text: status.get('spoiler_text') || '',
|
mentions: ImmutableList(),
|
||||||
mentions: status.get('mentions') || ImmutableList(),
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const mergeDefined = (oldVal, newVal) => oldVal === undefined ? newVal : oldVal;
|
||||||
|
|
||||||
|
const setRequiredFields = status => {
|
||||||
|
return status.mergeDeepWith(mergeDefined, baseStatus);
|
||||||
};
|
};
|
||||||
|
|
||||||
// Ensure attachments have required fields
|
// Ensure attachments have required fields
|
||||||
|
|
Ładowanie…
Reference in New Issue