Fix repo Face identity description bounds
This commit is contained in:
parent
2b81f9d058
commit
aff9ddd04d
3 changed files with 34 additions and 4 deletions
|
|
@ -49,14 +49,30 @@ export interface VoidSelfStateIdentityDefaults {
|
|||
publicDescription?: string;
|
||||
}
|
||||
|
||||
const MAX_PUBLIC_DESCRIPTION_LENGTH = 1000;
|
||||
|
||||
export function normalizeVoidSelfStateIdentityDefaults(
|
||||
identity: VoidSelfStateIdentityDefaults,
|
||||
): VoidSelfStateIdentityDefaults {
|
||||
return {
|
||||
...identity,
|
||||
publicDescription: truncateOptionalText(
|
||||
identity.publicDescription,
|
||||
MAX_PUBLIC_DESCRIPTION_LENGTH,
|
||||
),
|
||||
};
|
||||
}
|
||||
|
||||
export function createEmptyVoidSelfState(
|
||||
options: { createdAt?: string; identity?: VoidSelfStateIdentityDefaults } = {},
|
||||
): VoidSelfStateTypedProjection {
|
||||
const createdAt = options.createdAt ?? new Date().toISOString();
|
||||
const identity = options.identity ?? {
|
||||
agentId: "void-moderator",
|
||||
publicName: "Void",
|
||||
};
|
||||
const identity = normalizeVoidSelfStateIdentityDefaults(
|
||||
options.identity ?? {
|
||||
agentId: "void-moderator",
|
||||
publicName: "Void",
|
||||
},
|
||||
);
|
||||
|
||||
return {
|
||||
selfProfile: voidSelfProfileSchema.parse({
|
||||
|
|
@ -119,6 +135,17 @@ export function createEmptyVoidSelfState(
|
|||
};
|
||||
}
|
||||
|
||||
function truncateOptionalText(value: string | undefined, maxLength: number): string | undefined {
|
||||
const trimmed = value?.trim();
|
||||
if (!trimmed) {
|
||||
return undefined;
|
||||
}
|
||||
if (trimmed.length <= maxLength) {
|
||||
return trimmed;
|
||||
}
|
||||
return trimmed.slice(0, maxLength - 1).trimEnd();
|
||||
}
|
||||
|
||||
export function buildVoidSelfStateContext(
|
||||
typedState: VoidSelfStateTypedProjection,
|
||||
options: VoidSelfStateProjectionOptions,
|
||||
|
|
|
|||
|
|
@ -22,6 +22,7 @@ import {
|
|||
} from "./void-self-state-domain";
|
||||
import {
|
||||
createEmptyVoidSelfState,
|
||||
normalizeVoidSelfStateIdentityDefaults,
|
||||
type VoidSelfStateIdentityDefaults,
|
||||
type VoidSelfStateTypedProjection,
|
||||
} from "./void-self-state-projection";
|
||||
|
|
@ -131,6 +132,7 @@ function repairSelfProfileIdentity(
|
|||
state: VoidSelfStateTypedProjection,
|
||||
identity: VoidSelfStateIdentityDefaults,
|
||||
): void {
|
||||
identity = normalizeVoidSelfStateIdentityDefaults(identity);
|
||||
let changed = false;
|
||||
|
||||
if (state.selfProfile.agentId !== identity.agentId) {
|
||||
|
|
|
|||
Loading…
Reference in a new issue