signal-desktop/ts/util/longAttachment.ts
automated-signal 52c57e3000
Inline long-text messages in the backup proto
Co-authored-by: trevor-signal <131492920+trevor-signal@users.noreply.github.com>
2025-07-21 13:53:24 -05:00

24 lines
545 B
TypeScript

// Copyright 2023 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
import { unicodeSlice } from './unicodeSlice';
const LONG_ATTACHMENT_LIMIT = 2048;
export function isBodyTooLong(
body: string,
length = LONG_ATTACHMENT_LIMIT
): boolean {
return Buffer.byteLength(body) > length;
}
export function trimBody(body: string, length = LONG_ATTACHMENT_LIMIT): string {
const sliced = unicodeSlice(body, 0, length);
if (sliced.length > 0) {
return sliced;
}
// Failover, for degenerate cases
return '\uFFFE';
}