Skip to content

armgit / macro

Public Imported from GitHub
0

Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.

1.8 KB
Raw Blame
import type { ReplyType } from '@app/features/email-compose/core/reply-type';
import type { EmailMessage } from '@app/features/email-message/core/email-message';

import type { Setter } from 'solid-js';
import type { EmailThreadState } from './email-thread-state';

export function openEmailReplyComposerForMessage(args: {
  ctx: EmailThreadState;
  /** Touch layouts reply in the full-screen composer; the inline reply input only
   * renders for non-touch. Phone width alone is not the gate: tablets are
   * touch at desktop widths. */
  isTouch: boolean;
  message: EmailMessage;
  replyType: ReplyType;
  isLastMessage?: boolean;
  setShowReply?: Setter<boolean>;
}) {
  const messageId = args.message.db_id;
  if (!messageId) return false;

  const permissions = args.ctx.permissions();
  if (!permissions.canReply) return false;
  // A forward re-sends the message's attachments, which only the inbox holding
  // them can do; recipients of a shared thread reply instead.
  if (args.replyType === 'forward' && !permissions.isOwner) return false;

  // The reply type and focus land through the reply request: the mounted
  // composer's effect applies them to its own (seed-keyed) form instance.
  // Writing to the form registry from here would target the wrong entry —
  // the registry key includes a seed only the composer knows.
  args.ctx.replyRequest.set(messageId, args.replyType);

  if (args.isTouch) {
    args.ctx.mobileReplyComposer.openForMessage(messageId);
    return true;
  }

  if (args.setShowReply) {
    args.setShowReply(true);
    return true;
  }

  if (args.isLastMessage) {
    args.ctx.messages.setBottomReplyOpen(true);
  } else {
    args.ctx.messages.setExpandedBodyId(messageId, true);
    args.ctx.messages.setFocused(messageId);
    args.ctx.messages.setReplyingToMessageId(messageId);
  }

  return true;
}