signal-desktop/ts/state/selectors/linkPreviews.ts

28 lines
669 B
TypeScript
Raw Normal View History

2021-04-27 22:35:35 +00:00
// Copyright 2021 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
import { createSelector } from 'reselect';
import { assert } from '../../util/assert';
import { getDomain } from '../../types/LinkPreview';
2021-04-27 22:35:35 +00:00
import { StateType } from '../reducer';
export const getLinkPreview = createSelector(
({ linkPreviews }: StateType) => linkPreviews.linkPreview,
linkPreview => {
if (linkPreview) {
const domain = getDomain(linkPreview.url);
assert(domain !== undefined, "Domain of linkPreview can't be undefined");
2021-04-27 22:35:35 +00:00
return {
...linkPreview,
domain,
2021-04-27 22:35:35 +00:00
isLoaded: true,
};
}
return undefined;
}
);