Trim group name and description from group state

This commit is contained in:
trevor-signal 2024-11-15 12:06:57 -05:00 committed by GitHub
parent 2c22dca023
commit 692b0ae189
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 21 additions and 14 deletions

View file

@ -4513,6 +4513,10 @@ async function integrateGroupChange({
}; };
} }
function normalizeTextField(text: string | null | undefined): string {
return text?.trim() ?? '';
}
function extractDiffs({ function extractDiffs({
current, current,
dropInitialJoinMessage, dropInitialJoinMessage,
@ -4617,11 +4621,12 @@ function extractDiffs({
} }
// name // name
const oldName = normalizeTextField(old.name);
if (old.name !== current.name) { const newName = normalizeTextField(current.name);
if (oldName !== newName) {
details.push({ details.push({
type: 'title', type: 'title',
newTitle: current.name, newTitle: newName,
}); });
} }
@ -4640,11 +4645,13 @@ function extractDiffs({
} }
// description // description
if (old.description !== current.description) { const oldDescription = normalizeTextField(old.description);
const newDescription = normalizeTextField(current.description);
if (oldDescription !== newDescription) {
details.push({ details.push({
type: 'description', type: 'description',
removed: !current.description, removed: !newDescription,
description: current.description, description: newDescription,
}); });
} }
@ -5373,7 +5380,7 @@ async function applyGroupChange({
if (actions.modifyTitle) { if (actions.modifyTitle) {
const { title } = actions.modifyTitle; const { title } = actions.modifyTitle;
if (title && title.content === 'title') { if (title && title.content === 'title') {
result.name = dropNull(title.title); result.name = dropNull(title.title)?.trim();
} else { } else {
log.warn( log.warn(
`applyGroupChange/${logId}: Clearing group title due to missing data.` `applyGroupChange/${logId}: Clearing group title due to missing data.`
@ -5575,7 +5582,7 @@ async function applyGroupChange({
if (actions.modifyDescription) { if (actions.modifyDescription) {
const { descriptionBytes } = actions.modifyDescription; const { descriptionBytes } = actions.modifyDescription;
if (descriptionBytes && descriptionBytes.content === 'descriptionText') { if (descriptionBytes && descriptionBytes.content === 'descriptionText') {
result.description = dropNull(descriptionBytes.descriptionText); result.description = dropNull(descriptionBytes.descriptionText)?.trim();
} else { } else {
log.warn( log.warn(
`applyGroupChange/${logId}: Clearing group description due to missing data.` `applyGroupChange/${logId}: Clearing group description due to missing data.`
@ -5809,7 +5816,7 @@ async function applyGroupState({
// Note: During decryption, title becomes a GroupAttributeBlob // Note: During decryption, title becomes a GroupAttributeBlob
const { title } = groupState; const { title } = groupState;
if (title && title.content === 'title') { if (title && title.content === 'title') {
result.name = dropNull(title.title); result.name = dropNull(title.title)?.trim();
} else { } else {
result.name = undefined; result.name = undefined;
} }
@ -6019,7 +6026,7 @@ async function applyGroupState({
// descriptionBytes // descriptionBytes
const { descriptionBytes } = groupState; const { descriptionBytes } = groupState;
if (descriptionBytes && descriptionBytes.content === 'descriptionText') { if (descriptionBytes && descriptionBytes.content === 'descriptionText') {
result.description = dropNull(descriptionBytes.descriptionText); result.description = dropNull(descriptionBytes.descriptionText)?.trim();
} else { } else {
result.description = undefined; result.description = undefined;
} }

View file

@ -890,12 +890,12 @@ export class BackupExportStream extends Readable {
storySendMode, storySendMode,
snapshot: { snapshot: {
title: { title: {
title: convo.name ?? '', title: convo.name?.trim() ?? '',
}, },
description: description:
convo.description != null convo.description != null
? { ? {
descriptionText: convo.description, descriptionText: convo.description.trim(),
} }
: null, : null,
avatarUrl: convo.avatar?.url, avatarUrl: convo.avatar?.url,

View file

@ -927,8 +927,8 @@ export class BackupImportStream extends Writable {
: undefined, : undefined,
// Snapshot // Snapshot
name: dropNull(title?.title), name: dropNull(title?.title)?.trim(),
description: dropNull(description?.descriptionText), description: dropNull(description?.descriptionText)?.trim(),
expireTimer: expirationTimerS expireTimer: expirationTimerS
? DurationInSeconds.fromSeconds(expirationTimerS) ? DurationInSeconds.fromSeconds(expirationTimerS)
: undefined, : undefined,