Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions src/actions/tmgr/chats.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,36 @@ export interface ChatFile {
mime: string | null;
}

export type ForwardSourceType = 'task' | 'comment' | 'message';
export type ForwardState = 'live' | 'edited' | 'deleted';

export interface ForwardSource {
type: ForwardSourceType;
id: number;
}

export interface ForwardTask {
key: string | null;
title: string;
status: { name: string; type: string } | null;
assignees: string[];
}

export interface ForwardDto {
type: ForwardSourceType;
id: number;
task_id?: number | null;
chat_id?: number | null;
title?: string | null;
key?: string | null;
author_name?: string | null;
created_at?: string | null;
text?: string | null;
file_names?: string[] | null;
state: ForwardState;
task?: ForwardTask | null;
}

export interface ChatMessage {
id: number;
chat_id: number;
Expand All @@ -107,6 +137,7 @@ export interface ChatMessage {
status?: ChatMessageStatus;
invoked_by?: ChatInvoker | null;
persona_replies?: PersonaReply[];
forward?: ForwardDto | null;
}

export interface ChatMessageHit {
Expand All @@ -132,6 +163,7 @@ export interface SendMessagePayload {
mentions?: ChatMention[];
parent_message_id?: number | null;
files?: ChatFileUpload[];
forward?: ForwardSource;
}

export interface CreateChannelPayload {
Expand Down Expand Up @@ -290,6 +322,17 @@ export const sendMessage = (
): Promise<ChatMessage> =>
unwrap($axios.post(`${chat(chatId)}/messages`, payload));

export const forwardToChat = (
chatId: number,
source: ForwardSource,
options: { body?: string; mentions?: ChatMention[] } = {},
): Promise<ChatMessage> =>
sendMessage(chatId, {
body: options.body ?? '',
mentions: options.mentions ?? [],
forward: source,
});

export const editMessage = (
chatId: number,
messageId: number,
Expand Down
178 changes: 176 additions & 2 deletions src/components/chats/ChatMessageItem.vue
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,83 @@
>
{{ $t('chats.persona.stopped') }}
</p>
<MarkdownText v-else :content="message.body ?? ''" />
<MarkdownText
v-else-if="message.body || !message.forward"
:content="message.body ?? ''"
/>
<div
v-if="forwardView && message.forward && !editing"
class="mt-1 rounded-md border border-l-4 border-line border-l-brand bg-surface p-2 text-sm dark:bg-surface-hover"
data-testid="chat-forward-card"
>
<div
class="flex flex-wrap items-baseline gap-x-2 text-xs text-ink-subtle"
>
<span class="font-semibold">{{
$t('chats.forward.from', { source: forwardLabel })
}}</span>
<template v-if="!forwardView.deleted">
<span v-if="message.forward.author_name">{{
message.forward.author_name
}}</span>
<span v-if="forwardTime">{{ forwardTime }}</span>
</template>
</div>
<p
v-if="forwardView.deleted"
class="mt-1 text-ink-subtle italic"
data-testid="chat-forward-deleted"
>
{{ $t('chats.forward.deleted') }}
</p>
<template v-else>
<p
v-if="forwardView.edited"
class="text-xs text-ink-subtle"
data-testid="chat-forward-edited"
>
{{ $t('chats.forward.edited') }}
</p>
<MarkdownText
v-if="forwardView.text"
:content="forwardView.text"
:untrusted="true"
/>
<ul v-if="forwardView.fileNames.length" class="space-y-0.5 mt-1">
<li
v-for="name in forwardView.fileNames"
:key="name"
class="inline-flex items-center gap-1 text-xs text-ink-subtle"
>
<Paperclip class="h-3 w-3" />
{{ name }}
</li>
</ul>
<router-link
v-if="message.forward.task && forwardTaskLink"
:to="forwardTaskLink"
class="mt-1 block rounded-md border border-line bg-surface-hover p-2 hover:bg-surface-sunken dark:bg-surface"
data-testid="chat-forward-task"
>
<span class="text-xs font-semibold text-brand">{{
message.forward.task.key
}}</span>
<span class="ml-1 text-sm text-ink">{{
message.forward.task.title
}}</span>
<span
class="mt-0.5 flex flex-wrap gap-x-2 text-xs text-ink-subtle"
>
<span v-if="message.forward.task.status">{{
message.forward.task.status.name
}}</span>
<span v-if="message.forward.task.assignees.length">{{
message.forward.task.assignees.join(', ')
}}</span>
</span>
</router-link>
</template>
</div>
<ul v-if="message.files.length" class="space-y-1 mt-1">
<li v-for="file in message.files" :key="file.id">
<button
Expand Down Expand Up @@ -137,6 +213,28 @@
>
<MessageSquare class="h-4 w-4" />
</button>
<button
v-if="sourceActions"
type="button"
class="rounded p-1 text-ink-subtle hover:bg-surface-hover hover:text-ink"
:title="$t('chats.forward.action')"
:aria-label="$t('chats.forward.action')"
data-testid="chat-forward"
@click="forwardOpen = true"
>
<Forward class="h-4 w-4" />
</button>
<button
v-if="sourceActions"
type="button"
class="rounded p-1 text-ink-subtle hover:bg-surface-hover hover:text-ink"
:title="$t('chats.forward.createTask')"
:aria-label="$t('chats.forward.createTask')"
data-testid="chat-create-task"
@click="createTask"
>
<ListPlus class="h-4 w-4" />
</button>
<button
v-if="mayEdit"
type="button"
Expand All @@ -160,6 +258,11 @@
<Trash2 class="h-4 w-4" />
</button>
</div>
<ForwardDialog
v-if="sourceActions"
v-model:open="forwardOpen"
:source="{ type: 'message', id: message.id }"
/>
<AlertDialog v-model:open="confirmDelete">
<AlertDialogContent>
<AlertDialogHeader>
Expand Down Expand Up @@ -188,6 +291,7 @@
<script lang="ts">
import { getFileDownload, toggleReaction } from '@/actions/tmgr/chats';
import type { ChatMessage, ChatReaction } from '@/actions/tmgr/chats';
import ForwardDialog from '@/components/chats/ForwardDialog.vue';
import MarkdownText from '@/components/general/MarkdownText.vue';
import {
AlertDialog,
Expand All @@ -207,10 +311,23 @@
useChats,
} from '@/composable/useChats';
import { t } from '@/i18n';
import {
forwardCardView,
forwardSnapshotLabel,
taskDraftFromMessage,
taskLink,
} from '@/utils/chatForward';
import { canStopMessage, isPersonaMessage } from '@/utils/chatPersonas';
import { isEnterSend } from '@/utils/commentComposer';
import { DEFAULT_REACTION_EMOJIS } from '@/utils/commentReactions';
import { MessageSquare, Paperclip, Pencil, Trash2 } from 'lucide-vue-next';
import {
Forward,
ListPlus,
MessageSquare,
Paperclip,
Pencil,
Trash2,
} from 'lucide-vue-next';
import { useStore } from 'vuex';
import { computed, defineComponent, ref, watch, type PropType } from 'vue';

Expand All @@ -226,6 +343,9 @@
AlertDialogFooter,
AlertDialogHeader,
AlertDialogTitle,
ForwardDialog,
Forward,
ListPlus,
MarkdownText,
MessageSquare,
Paperclip,
Expand All @@ -237,6 +357,7 @@
canWrite: { type: Boolean, default: true },
showReply: { type: Boolean, default: true },
canModerate: { type: Boolean, default: false },
canForward: { type: Boolean, default: false },
members: {
type: Array as PropType<
Array<{ id: number; name: string; kind?: 'user' | 'persona' }>
Expand All @@ -257,6 +378,52 @@
const mayDelete = computed(() =>
canDeleteMessage(props.message, selfId.value, props.canModerate),
);
const sourceActions = computed(
() =>
props.canForward &&
!props.message.deleted &&
(!props.message.status || props.message.status === 'done'),
);
const forwardOpen = ref(false);
const workspaceCode = computed<string>(
() => store.getters.currentWorkspace?.code ?? '',
);
const forwardView = computed(() =>
props.message.forward ? forwardCardView(props.message.forward) : null,
);
const forwardLabel = computed(() =>
props.message.forward
? forwardSnapshotLabel(props.message.forward)
: '',
);
const forwardTime = computed(() =>
props.message.forward?.created_at
? new Date(props.message.forward.created_at).toLocaleString([], {
dateStyle: 'short',
timeStyle: 'short',
})
: '',
);
const forwardTaskLink = computed(() => {
const forward = props.message.forward;
const id =
forward?.task_id ?? (forward?.type === 'task' ? forward.id : null);
return id && workspaceCode.value
? taskLink(workspaceCode.value, id)
: null;
});
const createTask = () => {
store.commit(
'setTaskPrefill',
taskDraftFromMessage(
props.message.body,
workspaceCode.value,
props.message.chat_id,
props.message.id,
),
);
store.commit('setShowCreatingTaskModal');
};
const isPersona = computed(() => isPersonaMessage(props.message));
const mayStop = computed(() =>
canStopMessage(props.message, selfId.value),
Expand Down Expand Up @@ -339,6 +506,13 @@
window.open(download_url, '_blank', 'noopener');
};
return {
sourceActions,
forwardOpen,
forwardView,
forwardLabel,
forwardTime,
forwardTaskLink,
createTask,
reactions,
isPersona,
mayStop,
Expand Down
Loading
Loading