MCPcopy Create free account
hub / github.com/block/buzz / handleUpdateProfile

Function handleUpdateProfile

desktop/src/testing/e2eBridge.ts:4573–4655  ·  view source on GitHub ↗
(
  args: {
    displayName?: string;
    avatarUrl?: string;
    about?: string;
    nip05Handle?: string;
  },
  config: E2eConfig | undefined,
)

Source from the content-addressed store, hash-verified

4571}
4572
4573async function handleUpdateProfile(
4574 args: {
4575 displayName?: string;
4576 avatarUrl?: string;
4577 about?: string;
4578 nip05Handle?: string;
4579 },
4580 config: E2eConfig | undefined,
4581) {
4582 const identity = getIdentity(config);
4583 if (!identity) {
4584 const profileUpdateError = config?.mock?.profileUpdateError;
4585 const profileUpdateErrors = config?.mock?.profileUpdateErrors;
4586 const nextProfileUpdateError = profileUpdateErrors?.shift();
4587 if (nextProfileUpdateError) {
4588 throw new Error(nextProfileUpdateError);
4589 }
4590
4591 if (profileUpdateError) {
4592 if (config?.mock) {
4593 config.mock.profileUpdateError = undefined;
4594 }
4595 throw new Error(profileUpdateError);
4596 }
4597
4598 const profile = ensureMockProfile(config);
4599 const hasDisplayNameUpdate = typeof args.displayName === "string";
4600 const hasAvatarUrlUpdate = typeof args.avatarUrl === "string";
4601 const hasAboutUpdate = typeof args.about === "string";
4602 const hasNip05HandleUpdate = typeof args.nip05Handle === "string";
4603 const nextDisplayName = args.displayName?.trim() ?? "";
4604 const nextAvatarUrl = args.avatarUrl?.trim() ?? "";
4605 const nextAbout = args.about?.trim() ?? "";
4606 const nextNip05Handle = args.nip05Handle?.trim() ?? "";
4607
4608 if (hasDisplayNameUpdate && nextDisplayName !== profile.display_name) {
4609 profile.display_name = nextDisplayName || null;
4610 applyMockDisplayName(profile.pubkey, profile.display_name);
4611 }
4612 if (hasAvatarUrlUpdate && nextAvatarUrl !== profile.avatar_url) {
4613 profile.avatar_url = nextAvatarUrl || null;
4614 }
4615 if (hasAboutUpdate && nextAbout !== profile.about) {
4616 profile.about = nextAbout || null;
4617 }
4618 if (hasNip05HandleUpdate && nextNip05Handle !== profile.nip05_handle) {
4619 profile.nip05_handle = nextNip05Handle || null;
4620 }
4621
4622 return cloneProfile(profile);
4623 }
4624
4625 // Read-merge-write: fetch current profile, merge, sign kind:0.
4626 const currentEvents = await relayQuery(config, [
4627 { kinds: [0], authors: [identity.pubkey], limit: 1 },
4628 ]);
4629 const currentContent = currentEvents[0]
4630 ? JSON.parse(currentEvents[0].content ?? "{}")

Callers 1

handleMockCommandFunction · 0.85

Calls 7

ensureMockProfileFunction · 0.85
applyMockDisplayNameFunction · 0.85
cloneProfileFunction · 0.85
relayQueryFunction · 0.85
submitSignedEventFunction · 0.85
getIdentityFunction · 0.70
parseMethod · 0.45

Tested by

no test coverage detected