Fix text story background color

This commit is contained in:
Fedor Indutny
2026-03-19 16:54:17 -07:00
committed by GitHub
parent 1d884929ea
commit 100db18701

View File

@@ -55,6 +55,7 @@ import { Address } from '../types/Address.std.js';
import { QualifiedAddress } from '../types/QualifiedAddress.std.js'; import { QualifiedAddress } from '../types/QualifiedAddress.std.js';
import { normalizeStoryDistributionId } from '../types/StoryDistributionId.std.js'; import { normalizeStoryDistributionId } from '../types/StoryDistributionId.std.js';
import type { ServiceIdString, AciString } from '../types/ServiceId.std.js'; import type { ServiceIdString, AciString } from '../types/ServiceId.std.js';
import type { TextAttachmentType } from '../types/Attachment.std.js';
import { import {
fromPniObject, fromPniObject,
isPniString, isPniString,
@@ -176,7 +177,7 @@ import {
import { toNumber } from '../util/toNumber.std.js'; import { toNumber } from '../util/toNumber.std.js';
const { isBoolean, isNumber, isString, noop, omit } = lodash; const { isBoolean, isNumber, isString, noop } = lodash;
const log = createLogger('MessageReceiver'); const log = createLogger('MessageReceiver');
@@ -2170,30 +2171,33 @@ export default class MessageReceiver
// If a text attachment has a link preview we remove it from the // If a text attachment has a link preview we remove it from the
// textAttachment data structure and instead process the preview and add // textAttachment data structure and instead process the preview and add
// it as a "preview" property for the message attributes. // it as a "preview" property for the message attributes.
const { text, preview: unprocessedPreview } = const {
msg.attachment.textAttachment; preview: unprocessedPreview,
background,
...textAttachment
} = msg.attachment.textAttachment;
if (unprocessedPreview) { if (unprocessedPreview) {
preview = processPreview([unprocessedPreview]); preview = processPreview([unprocessedPreview]);
} else if (!text) { } else if (!textAttachment.text) {
throw new Error('Text attachments must have text or link preview!'); throw new Error('Text attachments must have text or link preview!');
} }
attachments.push({ attachments.push({
size: text?.length ?? 0, size: textAttachment.text?.length ?? 0,
contentType: TEXT_ATTACHMENT, contentType: TEXT_ATTACHMENT,
textAttachment: { textAttachment: {
...omit(msg.attachment.textAttachment, 'preview'), ...textAttachment,
textStyle: isKnownProtoEnumMember( textStyle: isKnownProtoEnumMember(
Proto.TextAttachment.Style, Proto.TextAttachment.Style,
msg.attachment.textAttachment.textStyle textAttachment.textStyle
) )
? msg.attachment.textAttachment.textStyle ? textAttachment.textStyle
: 0, : 0,
}, gradient: background?.gradient,
color: background?.color,
} satisfies TextAttachmentType,
blurHash: generateBlurHash( blurHash: generateBlurHash(
(msg.attachment.textAttachment.background?.color || background?.color ?? background?.gradient?.startColor ?? undefined
msg.attachment.textAttachment.background?.gradient?.startColor) ??
undefined
), ),
}); });
} }