nicolium: fix status with multiple accounts
Signed-off-by: nicole mikołajczyk <git@mkljczk.pl>
This commit is contained in:
@ -14,7 +14,10 @@ import type {
|
||||
Translation,
|
||||
} from 'pl-api';
|
||||
|
||||
type Status = BaseStatus | (StatusWithoutAccount & { expectsCard?: boolean });
|
||||
type Status = (BaseStatus | StatusWithoutAccount) & {
|
||||
expectsCard?: boolean;
|
||||
accounts?: Array<BaseAccount>;
|
||||
};
|
||||
|
||||
const STATUS_IMPORT = 'STATUS_IMPORT' as const;
|
||||
const STATUSES_IMPORT = 'STATUSES_IMPORT' as const;
|
||||
@ -80,6 +83,10 @@ const importEntities =
|
||||
processAccount(status.account);
|
||||
}
|
||||
|
||||
if (status.accounts) {
|
||||
for (const account of status.accounts) processAccount(account);
|
||||
}
|
||||
|
||||
if (status.quote && 'quoted_status' in status.quote && status.quote.quoted_status)
|
||||
processStatus(status.quote.quoted_status);
|
||||
if (status.reblog) processStatus(status.reblog);
|
||||
|
||||
@ -11,7 +11,7 @@ interface IAvatarStack {
|
||||
}
|
||||
|
||||
const AvatarStack: React.FC<IAvatarStack> = ({ accountIds, limit = 3 }) => {
|
||||
const { accounts } = useAccounts(accountIds.slice(0, limit));
|
||||
const { data: accounts } = useAccounts(accountIds.slice(0, limit));
|
||||
|
||||
return (
|
||||
<HStack className='relative' aria-hidden>
|
||||
|
||||
@ -19,7 +19,7 @@ interface IResults {
|
||||
|
||||
const Results = ({ accountSearchResult, onSelect }: IResults) => {
|
||||
const { data: accountIds = [], isFetching, hasNextPage, fetchNextPage } = accountSearchResult;
|
||||
const { accounts } = useAccounts(accountIds);
|
||||
const { data: accounts } = useAccounts(accountIds);
|
||||
|
||||
const [isNearBottom, setNearBottom] = useState<boolean>(false);
|
||||
const [isNearTop, setNearTop] = useState<boolean>(true);
|
||||
|
||||
@ -31,7 +31,7 @@ const useAccounts = (accountIds: Array<string>) => {
|
||||
);
|
||||
|
||||
return {
|
||||
accounts,
|
||||
data: accounts,
|
||||
isLoading: queries.some((query) => query.isLoading),
|
||||
isFetching: queries.some((query) => query.isFetching),
|
||||
};
|
||||
|
||||
@ -8,6 +8,7 @@ import { type NormalizedStatus, normalizeStatus } from '@/reducers/statuses';
|
||||
import { useContextsActions } from '@/stores/contexts';
|
||||
|
||||
import { useAccount } from '../accounts/use-account';
|
||||
import { useAccounts } from '../accounts/use-accounts';
|
||||
import { queryKeys } from '../keys';
|
||||
|
||||
import type { Context, AsyncRefreshHeader, Account } from 'pl-api';
|
||||
@ -28,6 +29,7 @@ type MinifiedContext = ReturnType<typeof minifyContext>;
|
||||
|
||||
type SelectedStatus = NormalizedStatus & {
|
||||
account: Account;
|
||||
accounts?: Array<Account>;
|
||||
reblog?: SelectedStatus;
|
||||
quote?: SelectedStatus;
|
||||
};
|
||||
@ -55,6 +57,9 @@ const useStatusQuery = (statusId?: string) => {
|
||||
});
|
||||
|
||||
const account = useAccount(statusQuery.data?.account_id ?? undefined);
|
||||
const { data: accounts } = useAccounts(
|
||||
statusQuery.data?.account_id ? [statusQuery.data.account_id] : [],
|
||||
);
|
||||
|
||||
return useMemo(() => {
|
||||
if (!statusQuery.data) return statusQuery;
|
||||
@ -63,9 +68,10 @@ const useStatusQuery = (statusId?: string) => {
|
||||
data: {
|
||||
...statusQuery.data,
|
||||
account: account.data!,
|
||||
accounts,
|
||||
},
|
||||
};
|
||||
}, [statusQuery.data, account.data]) as unknown as UseQueryResult<NormalizedStatus>;
|
||||
}, [statusQuery.data, account.data, accounts]) as unknown as UseQueryResult<NormalizedStatus>;
|
||||
};
|
||||
|
||||
const useStatus = (
|
||||
@ -93,7 +99,12 @@ const useStatus = (
|
||||
},
|
||||
refetchContext,
|
||||
};
|
||||
}, [statusQuery.data, reblogQuery.data, quoteQuery.data, account.data]);
|
||||
}, [
|
||||
statusQuery.data,
|
||||
reblogQuery.data,
|
||||
quoteQuery.data,
|
||||
account.data,
|
||||
]) as unknown as UseQueryResult<SelectedStatus> & { refetchContext: () => void };
|
||||
};
|
||||
|
||||
const useStatusContext = (statusId?: string) => {
|
||||
|
||||
@ -93,16 +93,15 @@ const getSearchIndex = (
|
||||
const normalizeStatus = (
|
||||
{
|
||||
account,
|
||||
accounts,
|
||||
reblog,
|
||||
quote,
|
||||
poll,
|
||||
group,
|
||||
...status
|
||||
}:
|
||||
| BaseStatus
|
||||
| (StatusWithoutAccount & {
|
||||
accounts?: Array<BaseAccount>;
|
||||
}),
|
||||
}: (BaseStatus | StatusWithoutAccount) & {
|
||||
accounts?: Array<BaseAccount>;
|
||||
},
|
||||
oldStatus?: OldStatus,
|
||||
) => {
|
||||
const searchIndex = getSearchIndex(status, oldStatus, poll);
|
||||
@ -158,6 +157,7 @@ const normalizeStatus = (
|
||||
|
||||
return {
|
||||
account_id: accountId,
|
||||
account_ids: accounts ? accounts.map(({ id }) => id) : [accountId],
|
||||
reblog_id: reblog?.id ?? null,
|
||||
poll_id: poll?.id ?? null,
|
||||
group_id: group?.id ?? null,
|
||||
|
||||
Reference in New Issue
Block a user