2021-04-27 22:35:35 +00:00
|
|
|
// Copyright 2021 Signal Messenger, LLC
|
|
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
|
|
|
import { createSelector } from 'reselect';
|
|
|
|
|
2022-09-15 19:17:15 +00:00
|
|
|
import { assertDev } from '../../util/assert';
|
2024-09-09 21:00:21 +00:00
|
|
|
import { getSafeDomain } from '../../types/LinkPreview';
|
2021-06-30 17:00:02 +00:00
|
|
|
|
2022-06-17 00:48:57 +00:00
|
|
|
import type { LinkPreviewSourceType } from '../../types/LinkPreview';
|
2021-10-26 19:15:33 +00:00
|
|
|
import type { StateType } from '../reducer';
|
2021-04-27 22:35:35 +00:00
|
|
|
|
|
|
|
export const getLinkPreview = createSelector(
|
2022-06-17 00:48:57 +00:00
|
|
|
({ linkPreviews }: StateType) => linkPreviews,
|
|
|
|
({ linkPreview, source }) => {
|
|
|
|
return (fromSource: LinkPreviewSourceType) => {
|
|
|
|
if (!linkPreview) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (source !== fromSource) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2024-09-09 21:00:21 +00:00
|
|
|
const domain = getSafeDomain(linkPreview.url);
|
2022-09-15 19:17:15 +00:00
|
|
|
assertDev(
|
|
|
|
domain !== undefined,
|
|
|
|
"Domain of linkPreview can't be undefined"
|
|
|
|
);
|
2021-06-30 17:00:02 +00:00
|
|
|
|
2021-04-27 22:35:35 +00:00
|
|
|
return {
|
|
|
|
...linkPreview,
|
2021-06-30 17:00:02 +00:00
|
|
|
domain,
|
2021-04-27 22:35:35 +00:00
|
|
|
isLoaded: true,
|
|
|
|
};
|
2022-06-17 00:48:57 +00:00
|
|
|
};
|
2021-04-27 22:35:35 +00:00
|
|
|
}
|
|
|
|
);
|