From cbbaadd3307bba182e8cc88a3a1279b0a42825f5 Mon Sep 17 00:00:00 2001 From: Sebastian Martinez Date: Tue, 12 Jul 2022 14:57:20 +0200 Subject: [PATCH] Improve handling unresolved identities Signed-off-by: Sebastian Martinez --- src/base/projects/Issue.svelte | 14 +++---------- .../projects/Issue/IssueAuthorship.svelte | 6 +++--- src/base/projects/Issue/IssueComment.svelte | 21 ++++++++++++++----- src/base/projects/Issue/IssueTeaser.svelte | 2 +- src/issue.ts | 16 ++++++++++---- 5 files changed, 35 insertions(+), 24 deletions(-) diff --git a/src/base/projects/Issue.svelte b/src/base/projects/Issue.svelte index 865295b37..db0bfefb8 100644 --- a/src/base/projects/Issue.svelte +++ b/src/base/projects/Issue.svelte @@ -2,9 +2,10 @@ import type { Config } from "@app/config"; import Loading from "@app/Loading.svelte"; import type { Blob, Project } from "@app/project"; - import { canonicalize, capitalize, formatTimestamp } from "@app/utils"; + import { canonicalize, capitalize } from "@app/utils"; import IssueComment from "@app/base/projects/Issue/IssueComment.svelte"; import { Issue } from "@app/issue"; + import IssueAuthorship from "@app/base/projects/Issue/IssueAuthorship.svelte"; export let issue: string; export let project: Project; @@ -97,9 +98,6 @@ .closed { background-color: var(--color-negative-2); } - .date { - color: var(--color-foreground-80); - } .replies { margin-left: 2rem; } @@ -131,13 +129,7 @@ {capitalize(issue.state.status)} -
- {issue.author.identity.name} - opened on - - {formatTimestamp(issue.timestamp)} - -
+
diff --git a/src/base/projects/Issue/IssueAuthorship.svelte b/src/base/projects/Issue/IssueAuthorship.svelte index 1c4ba875d..c0113de62 100644 --- a/src/base/projects/Issue/IssueAuthorship.svelte +++ b/src/base/projects/Issue/IssueAuthorship.svelte @@ -35,13 +35,13 @@ {#if profile}
- {:else if author.identity.name} + {:else if author.kind === "resolved"} {author.identity.name} - {:else} + {:else if author.urn} - {formatRadicleUrn(author.identity.urn)} + {formatRadicleUrn(author.urn)} {/if}  {caption}  diff --git a/src/base/projects/Issue/IssueComment.svelte b/src/base/projects/Issue/IssueComment.svelte index 4c8cfbadb..7710222eb 100644 --- a/src/base/projects/Issue/IssueComment.svelte +++ b/src/base/projects/Issue/IssueComment.svelte @@ -18,11 +18,20 @@ let profile: Profile | null = null; onMount(async () => { - if (comment.author.identity.ens?.name) { + if (comment.author.kind === "resolved" && comment.author.identity.ens?.name) { profile = await Profile.get(comment.author.identity.ens.name, ProfileType.Minimal, config); } }); + $: source = profile?.avatar || + (comment.author.kind === "resolved" + ? comment.author.identity.urn + : comment.author.urn); + $: title = profile?.name || + (comment.author.kind === "resolved" + ? comment.author.identity.name + : comment.author.urn); + const selectReaction = (event: { detail: string }) => { // TODO: Once we allow adding reactions through the http-api, we should call it here. console.log(event.detail); @@ -67,19 +76,21 @@
- +
- +
{#if comment.reactions.length > 0}
- +
{/if}
diff --git a/src/base/projects/Issue/IssueTeaser.svelte b/src/base/projects/Issue/IssueTeaser.svelte index db696f4f4..3cafb6a9e 100644 --- a/src/base/projects/Issue/IssueTeaser.svelte +++ b/src/base/projects/Issue/IssueTeaser.svelte @@ -13,7 +13,7 @@ let profile: Profile | null = null; onMount(async () => { - if (issue.author.identity.ens?.name) { + if (issue.author.kind === "resolved" && issue.author.identity.ens?.name) { profile = await Profile.get(issue.author.identity.ens.name, ProfileType.Minimal, config); } }); diff --git a/src/issue.ts b/src/issue.ts index ca15f1d04..e62da68c0 100644 --- a/src/issue.ts +++ b/src/issue.ts @@ -26,16 +26,24 @@ export interface Comment { timestamp: number; } -export interface Author { +export type Author = ResolvedIdentity | UnresolvedIdentity; + +export interface ResolvedIdentity { + kind: "resolved"; peer: PeerId; identity: { urn: string; - name?: string; - ens?: { + name: string; + ens: { name: string; - }; + } | null; }; } +export interface UnresolvedIdentity { + kind: "unresolved"; + peer: PeerId; + urn: string; +} export interface CommentWithReplies extends Comment { replies: Comment[];