Allow link previews to be added to an edit if original msg had no links
This commit is contained in:
parent
d8ea785f4e
commit
1315d3cfe0
1 changed files with 27 additions and 4 deletions
|
@ -20,13 +20,17 @@ import type { BoundActionCreatorsMapObject } from '../../hooks/useBoundActions';
|
||||||
import type { DraftBodyRanges } from '../../types/BodyRange';
|
import type { DraftBodyRanges } from '../../types/BodyRange';
|
||||||
import { BodyRange } from '../../types/BodyRange';
|
import { BodyRange } from '../../types/BodyRange';
|
||||||
import type { LinkPreviewType } from '../../types/message/LinkPreviews';
|
import type { LinkPreviewType } from '../../types/message/LinkPreviews';
|
||||||
import type { MessageAttributesType } from '../../model-types.d';
|
import type {
|
||||||
|
DraftEditMessageType,
|
||||||
|
MessageAttributesType,
|
||||||
|
} from '../../model-types.d';
|
||||||
import type { NoopActionType } from './noop';
|
import type { NoopActionType } from './noop';
|
||||||
import type { ShowToastActionType } from './toast';
|
import type { ShowToastActionType } from './toast';
|
||||||
import type { StateType as RootStateType } from '../reducer';
|
import type { StateType as RootStateType } from '../reducer';
|
||||||
import type { UUIDStringType } from '../../types/UUID';
|
import type { UUIDStringType } from '../../types/UUID';
|
||||||
import * as log from '../../logging/log';
|
import * as log from '../../logging/log';
|
||||||
import * as Errors from '../../types/errors';
|
import * as Errors from '../../types/errors';
|
||||||
|
import * as LinkPreview from '../../types/LinkPreview';
|
||||||
import {
|
import {
|
||||||
ADD_PREVIEW as ADD_LINK_PREVIEW,
|
ADD_PREVIEW as ADD_LINK_PREVIEW,
|
||||||
REMOVE_PREVIEW as REMOVE_LINK_PREVIEW,
|
REMOVE_PREVIEW as REMOVE_LINK_PREVIEW,
|
||||||
|
@ -252,6 +256,24 @@ export const actions = {
|
||||||
setQuotedMessage,
|
setQuotedMessage,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
function hadSameLinkPreviewDismissed(
|
||||||
|
messageText: string,
|
||||||
|
draftEditMessage: DraftEditMessageType | undefined
|
||||||
|
): boolean {
|
||||||
|
if (!draftEditMessage) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
const currentLink = LinkPreview.findLinks(messageText).find(
|
||||||
|
LinkPreview.shouldPreviewHref
|
||||||
|
);
|
||||||
|
const prevLink = LinkPreview.findLinks(draftEditMessage.body).find(
|
||||||
|
LinkPreview.shouldPreviewHref
|
||||||
|
);
|
||||||
|
|
||||||
|
return currentLink === prevLink && !draftEditMessage.preview;
|
||||||
|
}
|
||||||
|
|
||||||
function incrementSendCounter(conversationId: string): IncrementSendActionType {
|
function incrementSendCounter(conversationId: string): IncrementSendActionType {
|
||||||
return {
|
return {
|
||||||
type: INCREMENT_SEND_COUNTER,
|
type: INCREMENT_SEND_COUNTER,
|
||||||
|
@ -994,9 +1016,10 @@ function onEditorStateChange({
|
||||||
includePending: true,
|
includePending: true,
|
||||||
}) ||
|
}) ||
|
||||||
Boolean(conversation.attributes.draftEditMessage?.attachmentThumbnail) ||
|
Boolean(conversation.attributes.draftEditMessage?.attachmentThumbnail) ||
|
||||||
// If we already didn't have a preview attached, don't fetch another one
|
hadSameLinkPreviewDismissed(
|
||||||
(conversation.attributes.draftEditMessage &&
|
messageText,
|
||||||
!conversation.attributes.draftEditMessage.preview)
|
conversation.attributes.draftEditMessage
|
||||||
|
)
|
||||||
) {
|
) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue