Radish alpha
r
Radicle web interface
Radicle
Git (anonymous pull)
Log in to clone via SSH
Add `alias` to `Patch`
xphoniex committed 2 years ago
commit 39874d8d51cf61d53b6ffb2b63bb03fbdddfd88d
parent 46494461f2b5c03081798131374ecae298df1a7c
4 files changed +56 -19
modified httpd-client/lib/project/patch.ts
@@ -10,7 +10,6 @@ import {
  optional,
  strictObject,
  string,
-
  tuple,
  union,
} from "zod";

@@ -28,13 +27,13 @@ const patchStateSchema = union([
]) satisfies ZodSchema<PatchState>;

export interface Merge {
-
  node: string;
+
  author: { id: string; alias?: string };
  commit: string;
  timestamp: number;
}

const mergeSchema = strictObject({
-
  node: string(),
+
  author: strictObject({ id: string(), alias: string().optional() }),
  commit: string(),
  timestamp: number(),
}) satisfies ZodSchema<Merge>;
@@ -72,6 +71,7 @@ const codeCommentSchema = strictObject({
type Verdict = "accept" | "reject";

export interface Review {
+
  author: { id: string; alias?: string };
  verdict?: Verdict | null;
  comment?: string | null;
  inline: CodeComment[];
@@ -79,6 +79,7 @@ export interface Review {
}

const reviewSchema = strictObject({
+
  author: strictObject({ id: string(), alias: string().optional() }),
  verdict: optional(union([literal("accept"), literal("reject")]).nullable()),
  comment: optional(string().nullable()),
  inline: array(codeCommentSchema),
@@ -92,7 +93,7 @@ export interface Revision {
  oid: string;
  refs: string[];
  discussions: Comment[];
-
  reviews: [string, Review][];
+
  reviews: Review[];
  merges: Merge[];
  timestamp: number;
}
@@ -104,7 +105,7 @@ const revisionSchema = strictObject({
  oid: string(),
  refs: array(string()),
  discussions: array(commentSchema),
-
  reviews: array(tuple([string(), reviewSchema])),
+
  reviews: array(reviewSchema),
  merges: array(mergeSchema),
  timestamp: number(),
}) satisfies ZodSchema<Revision>;
@@ -142,6 +143,7 @@ export type PatchUpdateAction =
  | { type: "redact"; revision: string }
  | {
      type: "review";
+
      author: { id: string; alias?: string };
      revision: string;
      verdict?: Verdict;
      comment?: string;
modified src/components/Authorship.svelte
@@ -4,6 +4,12 @@

  export let authorId: string;
  export let authorAlias: string | undefined = undefined;
+
  export let authorAliasColor:
+
    | "--color-primary-5"
+
    | "--color-foreground-5"
+
    | "--color-positive-5"
+
    | "--color-negative-5"
+
    | undefined = "--color-foreground-5";
  export let caption: string | undefined = undefined;
  export let noAvatar: boolean = false;
  export let timestamp: number | undefined = undefined;
@@ -28,9 +34,6 @@
  .body {
    white-space: nowrap;
  }
-
  .alias {
-
    color: var(--color-foreground-5);
-
  }
</style>

<span class="authorship txt-tiny">
@@ -40,13 +43,13 @@
  <span class="id layout-desktop">
    {formatNodeId(authorId)}
    {#if authorAlias}
-
      <span class="alias">({authorAlias})</span>
+
      <span style:color="var({authorAliasColor})">({authorAlias})</span>
    {/if}
  </span>
  <span class="id layout-mobile">
    {formatNodeId(authorId).replace("did:key:", "")}
    {#if authorAlias}
-
      <span class="alias">({authorAlias})</span>
+
      <span style:color="var({authorAliasColor})">({authorAlias})</span>
    {/if}
  </span>
  {#if !caption}
modified src/views/projects/Cob/Revision.svelte
@@ -21,6 +21,7 @@
  import ThreadComponent from "@app/components/Thread.svelte";

  export let authorId: string;
+
  export let authorAlias: string | undefined = undefined;
  export let baseUrl: BaseUrl;
  export let expanded: boolean = true;
  export let patchId: string;
@@ -48,6 +49,17 @@
    }
  }

+
  function aliasColorForVerdict(verdict?: string | null) {
+
    switch (verdict) {
+
      case "accept":
+
        return "--color-positive-5";
+
      case "reject":
+
        return "--color-negative-5";
+
      default:
+
        return "--color-foreground-5";
+
    }
+
  }
+

  let response: DiffResponse | undefined = undefined;
  let error: any | undefined = undefined;

@@ -228,13 +240,17 @@
              <CommentComponent
                {caption}
                {authorId}
+
                {authorAlias}
                timestamp={element.timestamp}
                rawPath={utils.getRawBasePath(projectId, baseUrl, projectHead)}
                body={element.inner.description} />
            </div>
          {:else}
            <div class="action-padding action-background txt-tiny">
-
              <Authorship {authorId} timestamp={element.timestamp}>
+
              <Authorship
+
                {authorId}
+
                {authorAlias}
+
                timestamp={element.timestamp}>
                {caption}
              </Authorship>
            </div>
@@ -275,8 +291,10 @@
            class="action-padding action-background merge layout-desktop txt-tiny">
            <div class="action-content">
              <Authorship
-
                authorId={element.inner.node}
-
                timestamp={element.timestamp}>
+
                authorId={element.inner.author.id}
+
                authorAlias={element.inner.author.alias}
+
                timestamp={element.timestamp}
+
                authorAliasColor="--color-primary-5">
                merged
                {utils.formatCommit(element.inner.commit)}
              </Authorship>
@@ -285,7 +303,10 @@
          <div
            class="action-padding action-background merge layout-mobile txt-tiny">
            <div class="action-content">
-
              <Authorship authorId={element.inner.node}>
+
              <Authorship
+
                authorId={element.inner.author.id}
+
                authorAlias={element.inner.author.alias}
+
                authorAliasColor="--color-primary-5">
                merged
                {utils.formatCommit(element.inner.commit)}
              </Authorship>
@@ -301,6 +322,7 @@
              <CommentComponent
                caption={formatVerdict(revisionId, review.verdict)}
                authorId={author}
+
                authorAlias={review.author.alias}
                timestamp={review.timestamp}
                rawPath={utils.getRawBasePath(projectId, baseUrl, projectHead)}
                body={review.comment} />
@@ -311,7 +333,11 @@
              class:positive-review={element.inner[2].verdict === "accept"}
              class:negative-review={element.inner[2].verdict === "reject"}>
              <div class="action-content">
-
                <Authorship authorId={author} timestamp={element.timestamp}>
+
                <Authorship
+
                  authorId={author}
+
                  authorAlias={review.author.alias}
+
                  authorAliasColor={aliasColorForVerdict(review.verdict)}
+
                  timestamp={element.timestamp}>
                  {formatVerdict(revisionId, review.verdict)}
                </Authorship>
              </div>
@@ -321,7 +347,10 @@
              class:positive-review={element.inner[2].verdict === "accept"}
              class:negative-review={element.inner[2].verdict === "reject"}>
              <div class="action-content">
-
                <Authorship authorId={author}>
+
                <Authorship
+
                  authorId={author}
+
                  authorAlias={review.author.alias}
+
                  authorAliasColor={aliasColorForVerdict(review.verdict)}>
                  {formatVerdict(revisionId, review.verdict)}
                </Authorship>
              </div>
modified src/views/projects/Patch.svelte
@@ -153,10 +153,10 @@
      revisionOid: rev.oid,
    },
    [
-
      ...rev.reviews.map<TimelineReview>(([author, review]) => ({
+
      ...rev.reviews.map<TimelineReview>(review => ({
        timestamp: review.timestamp,
        type: "review",
-
        inner: [rev.id, author, review],
+
        inner: [rev.id, review.author.id, review],
      })),
      ...rev.merges.map<TimelineMerge>(inner => ({
        timestamp: inner.timestamp,
@@ -279,7 +279,9 @@
        {/if}
      </svelte:fragment>
      <div class="author" slot="author">
-
        opened by <Authorship authorId={patch.author.id} />
+
        opened by <Authorship
+
          authorId={patch.author.id}
+
          authorAlias={patch.author.alias} />
        {utils.formatTimestamp(patch.revisions[0].timestamp)}
      </div>
    </CobHeader>
@@ -379,6 +381,7 @@
            on:reply={createReply}
            patchId={patch.id}
            authorId={patch.author.id}
+
            authorAlias={patch.author.alias}
            expanded={index === patch.revisions.length - 1}
            previousRevId={previousRevision?.id}
            previousRevOid={previousRevision?.oid} />