Skip to content

armgit / orca

Public Imported from GitHub
0

Orca is the place for working with a fleet of agents (e.g. Grok Bot, Claude Code). Run any coding agent with your own subscription. Available on desktop, mobile and remote runtime.

1.5 KB
Raw Blame
import type { DiffComment } from '../../../src/shared/diff-comment-types'

export type UpdateMobileDiffCommentInput = {
  id: string
  body: string
  updatedAt: number
}

export function updateMobileDiffComment(
  comments: readonly DiffComment[],
  input: UpdateMobileDiffCommentInput
): { comments: DiffComment[]; comment: DiffComment | null } {
  const body = input.body.trim()
  if (!body) {
    return { comments: [...comments], comment: null }
  }
  let updatedComment: DiffComment | null = null
  const next = comments.map((comment) => {
    if (comment.id !== input.id) {
      return comment
    }
    updatedComment = {
      ...comment,
      body,
      updatedAt: input.updatedAt,
      sentAt: undefined
    }
    return updatedComment
  })
  return { comments: next, comment: updatedComment }
}

export function markMobileDiffCommentsSent(
  comments: readonly DiffComment[],
  ids: ReadonlySet<string>,
  sentAt: number
): DiffComment[] {
  if (ids.size === 0) {
    return [...comments]
  }
  return comments.map((comment) => (ids.has(comment.id) ? { ...comment, sentAt } : comment))
}

export function clearSentMobileDiffComments(comments: readonly DiffComment[]): DiffComment[] {
  return comments.filter((comment) => comment.sentAt === undefined)
}

export function getUnsentMobileDiffComments(comments: readonly DiffComment[]): DiffComment[] {
  return comments.filter((comment) => comment.sentAt === undefined)
}

export function countUnsentMobileDiffComments(comments: readonly DiffComment[]): number {
  return getUnsentMobileDiffComments(comments).length
}