mirror of
https://github.com/funamitech/mastodon
synced 2024-12-15 15:18:30 +09:00
09376a8207
Port a0e237a96f
to glitch-soc
Signed-off-by: Claire <claire.github-309c@sitedethib.com>
48 lines
1.4 KiB
TypeScript
48 lines
1.4 KiB
TypeScript
import { createSelector } from '@reduxjs/toolkit';
|
|
import { Record as ImmutableRecord } from 'immutable';
|
|
|
|
import { accountDefaultValues } from 'flavours/glitch/models/account';
|
|
import type { Account, AccountShape } from 'flavours/glitch/models/account';
|
|
import type { Relationship } from 'flavours/glitch/models/relationship';
|
|
import type { RootState } from 'flavours/glitch/store';
|
|
|
|
const getAccountBase = (state: RootState, id: string) =>
|
|
state.accounts.get(id, null);
|
|
|
|
const getAccountRelationship = (state: RootState, id: string) =>
|
|
state.relationships.get(id, null);
|
|
|
|
const getAccountMoved = (state: RootState, id: string) => {
|
|
const movedToId = state.accounts.get(id)?.moved;
|
|
|
|
if (!movedToId) return undefined;
|
|
|
|
return state.accounts.get(movedToId);
|
|
};
|
|
|
|
interface FullAccountShape extends Omit<AccountShape, 'moved'> {
|
|
relationship: Relationship | null;
|
|
moved: Account | null;
|
|
}
|
|
|
|
const FullAccountFactory = ImmutableRecord<FullAccountShape>({
|
|
...accountDefaultValues,
|
|
moved: null,
|
|
relationship: null,
|
|
});
|
|
|
|
export function makeGetAccount() {
|
|
return createSelector(
|
|
[getAccountBase, getAccountRelationship, getAccountMoved],
|
|
(base, relationship, moved) => {
|
|
if (base === null) {
|
|
return null;
|
|
}
|
|
|
|
return FullAccountFactory(base)
|
|
.set('relationship', relationship)
|
|
.set('moved', moved ?? null);
|
|
},
|
|
);
|
|
}
|