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

View file

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

View file

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