Skip to content

The open alternative to Salesforce, designed for AI.

Reply to app conversations from the thread (#29327)

martmull329218cea527
diff --git a/packages/twenty-front/src/generated-metadata/graphql.ts b/packages/twenty-front/src/generated-metadata/graphql.ts
index c2d0b6848ab..c698174f270 100644
--- a/packages/twenty-front/src/generated-metadata/graphql.ts
+++ b/packages/twenty-front/src/generated-metadata/graphql.ts
@@ -32,6 +32,13 @@ export type CancelMessageCampaignMutationVariables = Exact<{
export type CancelMessageCampaignMutation = { cancelMessageCampaign: { __typename: 'CancelMessageCampaignOutputDTO', campaignId: string, canceledMessageCount: number } };
+export type SendAppChannelMessageMutationVariables = Exact<{
+ input: Types.SendAppChannelMessageInput;
+}>;
+
+
+export type SendAppChannelMessageMutation = { sendAppChannelMessage: { __typename: 'SendAppChannelMessageOutput', messageId: string, messageThreadId: string } };
+
export type SendEmailMutationVariables = Exact<{
input: Types.SendEmailInput;
}>;
@@ -1767,7 +1774,7 @@ export type MyMessageChannelsQueryVariables = Exact<{
}>;
-export type MyMessageChannelsQuery = { myMessageChannels: Array<{ __typename: 'MessageChannel', id: string, handle: string, displayName: string | null, visibility: Types.MessageChannelVisibility, type: Types.MessageChannelType, isContactAutoCreationEnabled: boolean, contactAutoCreationPolicy: Types.MessageChannelContactAutoCreationPolicy, messageFolderImportPolicy: Types.MessageFolderImportPolicy, excludeNonProfessionalEmails: boolean, excludeGroupEmails: boolean, isSyncEnabled: boolean, syncStatus: Types.MessageChannelSyncStatus, syncStage: Types.MessageChannelSyncStage, syncStageStartedAt: string | null, importProgress: number | null, connectedAccountId: string, createdAt: string, updatedAt: string, connectedAccount: { __typename: 'ConnectedAccountPublicDTO', id: string, handle: string } | null }> };
+export type MyMessageChannelsQuery = { myMessageChannels: Array<{ __typename: 'MessageChannel', id: string, handle: string, displayName: string | null, visibility: Types.MessageChannelVisibility, type: Types.MessageChannelType, isContactAutoCreationEnabled: boolean, contactAutoCreationPolicy: Types.MessageChannelContactAutoCreationPolicy, messageFolderImportPolicy: Types.MessageFolderImportPolicy, excludeNonProfessionalEmails: boolean, excludeGroupEmails: boolean, isSyncEnabled: boolean, messagingProviderUniversalIdentifier: string | null, syncStatus: Types.MessageChannelSyncStatus, syncStage: Types.MessageChannelSyncStage, syncStageStartedAt: string | null, importProgress: number | null, connectedAccountId: string, createdAt: string, updatedAt: string, connectedAccount: { __typename: 'ConnectedAccountPublicDTO', id: string, handle: string } | null }> };
export type MyMessageFoldersQueryVariables = Exact<{
messageChannelId?: string | null | undefined;
@@ -2983,6 +2990,7 @@ export const CreateCalendarEventDocument = {"kind":"Document","definitions":[{"k
export const PreviewMessageCampaignSendDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"query","name":{"kind":"Name","value":"PreviewMessageCampaignSend"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"input"}},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"PreviewMessageCampaignSendInput"}}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"previewMessageCampaignSend"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"input"},"value":{"kind":"Variable","name":{"kind":"Name","value":"input"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"audience"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"totalMembers"}},{"kind":"Field","name":{"kind":"Name","value":"withoutEmail"}},{"kind":"Field","name":{"kind":"Name","value":"duplicateEmails"}},{"kind":"Field","name":{"kind":"Name","value":"hardSuppressed"}},{"kind":"Field","name":{"kind":"Name","value":"globallyUnsubscribed"}},{"kind":"Field","name":{"kind":"Name","value":"topicUnsubscribed"}},{"kind":"Field","name":{"kind":"Name","value":"trackingRefused"}},{"kind":"Field","name":{"kind":"Name","value":"sendable"}}]}},{"kind":"Field","name":{"kind":"Name","value":"blockers"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"code"}},{"kind":"Field","name":{"kind":"Name","value":"message"}}]}}]}}]}}]} as unknown as DocumentNode<PreviewMessageCampaignSendQuery, PreviewMessageCampaignSendQueryVariables>;
export const UnsubscribeTopicsDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"query","name":{"kind":"Name","value":"UnsubscribeTopics"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"unsubscribeTopics"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"name"}},{"kind":"Field","name":{"kind":"Name","value":"description"}},{"kind":"Field","name":{"kind":"Name","value":"visibility"}}]}}]}}]} as unknown as DocumentNode<UnsubscribeTopicsQuery, UnsubscribeTopicsQueryVariables>;
export const CancelMessageCampaignDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"mutation","name":{"kind":"Name","value":"CancelMessageCampaign"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"input"}},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"CancelMessageCampaignInput"}}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"cancelMessageCampaign"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"input"},"value":{"kind":"Variable","name":{"kind":"Name","value":"input"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"campaignId"}},{"kind":"Field","name":{"kind":"Name","value":"canceledMessageCount"}}]}}]}}]} as unknown as DocumentNode<CancelMessageCampaignMutation, CancelMessageCampaignMutationVariables>;
+export const SendAppChannelMessageDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"mutation","name":{"kind":"Name","value":"SendAppChannelMessage"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"input"}},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"SendAppChannelMessageInput"}}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"sendAppChannelMessage"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"input"},"value":{"kind":"Variable","name":{"kind":"Name","value":"input"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"messageId"}},{"kind":"Field","name":{"kind":"Name","value":"messageThreadId"}}]}}]}}]} as unknown as DocumentNode<SendAppChannelMessageMutation, SendAppChannelMessageMutationVariables>;
export const SendEmailDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"mutation","name":{"kind":"Name","value":"SendEmail"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"input"}},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"SendEmailInput"}}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"sendEmail"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"input"},"value":{"kind":"Variable","name":{"kind":"Name","value":"input"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"success"}},{"kind":"Field","name":{"kind":"Name","value":"error"}},{"kind":"Field","name":{"kind":"Name","value":"messageThreadId"}}]}}]}}]} as unknown as DocumentNode<SendEmailMutation, SendEmailMutationVariables>;
export const SendMessageCampaignDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"mutation","name":{"kind":"Name","value":"SendMessageCampaign"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"input"}},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"SendMessageCampaignInput"}}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"sendMessageCampaign"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"input"},"value":{"kind":"Variable","name":{"kind":"Name","value":"input"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"campaignId"}},{"kind":"Field","name":{"kind":"Name","value":"queuedCount"}},{"kind":"Field","name":{"kind":"Name","value":"audience"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"totalMembers"}},{"kind":"Field","name":{"kind":"Name","value":"withoutEmail"}},{"kind":"Field","name":{"kind":"Name","value":"duplicateEmails"}},{"kind":"Field","name":{"kind":"Name","value":"hardSuppressed"}},{"kind":"Field","name":{"kind":"Name","value":"globallyUnsubscribed"}},{"kind":"Field","name":{"kind":"Name","value":"topicUnsubscribed"}},{"kind":"Field","name":{"kind":"Name","value":"trackingRefused"}},{"kind":"Field","name":{"kind":"Name","value":"sendable"}}]}}]}}]}}]} as unknown as DocumentNode<SendMessageCampaignMutation, SendMessageCampaignMutationVariables>;
export const SendMessageCampaignTestDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"mutation","name":{"kind":"Name","value":"SendMessageCampaignTest"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"input"}},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"SendMessageCampaignTestInput"}}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"sendMessageCampaignTest"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"input"},"value":{"kind":"Variable","name":{"kind":"Name","value":"input"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"messageId"}}]}}]}}]} as unknown as DocumentNode<SendMessageCampaignTestMutation, SendMessageCampaignTestMutationVariables>;
@@ -3170,7 +3178,7 @@ export const UpdateMessageFoldersDocument = {"kind":"Document","definitions":[{"
export const GetConnectedImapSmtpCaldavAccountDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"query","name":{"kind":"Name","value":"GetConnectedImapSmtpCaldavAccount"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"id"}},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"UUID"}}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"getConnectedImapSmtpCaldavAccount"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"id"},"value":{"kind":"Variable","name":{"kind":"Name","value":"id"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"handle"}},{"kind":"Field","name":{"kind":"Name","value":"provider"}},{"kind":"Field","name":{"kind":"Name","value":"userWorkspaceId"}},{"kind":"Field","name":{"kind":"Name","value":"connectionParameters"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"name"}},{"kind":"Field","name":{"kind":"Name","value":"IMAP"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"host"}},{"kind":"Field","name":{"kind":"Name","value":"port"}},{"kind":"Field","name":{"kind":"Name","value":"connectionSecurity"}},{"kind":"Field","name":{"kind":"Name","value":"username"}}]}},{"kind":"Field","name":{"kind":"Name","value":"SMTP"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"host"}},{"kind":"Field","name":{"kind":"Name","value":"username"}},{"kind":"Field","name":{"kind":"Name","value":"port"}},{"kind":"Field","name":{"kind":"Name","value":"connectionSecurity"}}]}},{"kind":"Field","name":{"kind":"Name","value":"CALDAV"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"host"}},{"kind":"Field","name":{"kind":"Name","value":"port"}},{"kind":"Field","name":{"kind":"Name","value":"connectionSecurity"}},{"kind":"Field","name":{"kind":"Name","value":"username"}}]}}]}}]}}]}}]} as unknown as DocumentNode<GetConnectedImapSmtpCaldavAccountQuery, GetConnectedImapSmtpCaldavAccountQueryVariables>;
export const MyCalendarChannelsDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"query","name":{"kind":"Name","value":"MyCalendarChannels"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"connectedAccountId"}},"type":{"kind":"NamedType","name":{"kind":"Name","value":"UUID"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"myCalendarChannels"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"connectedAccountId"},"value":{"kind":"Variable","name":{"kind":"Name","value":"connectedAccountId"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"handle"}},{"kind":"Field","name":{"kind":"Name","value":"visibility"}},{"kind":"Field","name":{"kind":"Name","value":"syncStatus"}},{"kind":"Field","name":{"kind":"Name","value":"syncStage"}},{"kind":"Field","name":{"kind":"Name","value":"syncStageStartedAt"}},{"kind":"Field","name":{"kind":"Name","value":"isContactAutoCreationEnabled"}},{"kind":"Field","name":{"kind":"Name","value":"contactAutoCreationPolicy"}},{"kind":"Field","name":{"kind":"Name","value":"excludePrivateEvents"}},{"kind":"Field","name":{"kind":"Name","value":"isSyncEnabled"}},{"kind":"Field","name":{"kind":"Name","value":"connectedAccountId"}},{"kind":"Field","name":{"kind":"Name","value":"createdAt"}},{"kind":"Field","name":{"kind":"Name","value":"updatedAt"}}]}}]}}]} as unknown as DocumentNode<MyCalendarChannelsQuery, MyCalendarChannelsQueryVariables>;
export const MyConnectedAccountsDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"query","name":{"kind":"Name","value":"MyConnectedAccounts"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"myConnectedAccounts"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"handle"}},{"kind":"Field","name":{"kind":"Name","value":"provider"}},{"kind":"Field","name":{"kind":"Name","value":"authFailedAt"}},{"kind":"Field","name":{"kind":"Name","value":"authFailedReason"}},{"kind":"Field","name":{"kind":"Name","value":"archivedAt"}},{"kind":"Field","name":{"kind":"Name","value":"scopes"}},{"kind":"Field","name":{"kind":"Name","value":"handleAliases"}},{"kind":"Field","name":{"kind":"Name","value":"lastSignedInAt"}},{"kind":"Field","name":{"kind":"Name","value":"userWorkspaceId"}},{"kind":"Field","name":{"kind":"Name","value":"connectionProviderId"}},{"kind":"Field","name":{"kind":"Name","value":"applicationId"}},{"kind":"Field","name":{"kind":"Name","value":"name"}},{"kind":"Field","name":{"kind":"Name","value":"scope"}},{"kind":"Field","name":{"kind":"Name","value":"lastCredentialsRefreshedAt"}},{"kind":"Field","name":{"kind":"Name","value":"connectionParameters"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"IMAP"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"host"}},{"kind":"Field","name":{"kind":"Name","value":"port"}},{"kind":"Field","name":{"kind":"Name","value":"connectionSecurity"}},{"kind":"Field","name":{"kind":"Name","value":"username"}}]}},{"kind":"Field","name":{"kind":"Name","value":"SMTP"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"host"}},{"kind":"Field","name":{"kind":"Name","value":"port"}},{"kind":"Field","name":{"kind":"Name","value":"connectionSecurity"}},{"kind":"Field","name":{"kind":"Name","value":"username"}}]}},{"kind":"Field","name":{"kind":"Name","value":"CALDAV"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"host"}},{"kind":"Field","name":{"kind":"Name","value":"username"}}]}}]}},{"kind":"Field","name":{"kind":"Name","value":"createdAt"}},{"kind":"Field","name":{"kind":"Name","value":"updatedAt"}}]}}]}}]} as unknown as DocumentNode<MyConnectedAccountsQuery, MyConnectedAccountsQueryVariables>;
-export const MyMessageChannelsDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"query","name":{"kind":"Name","value":"MyMessageChannels"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"connectedAccountId"}},"type":{"kind":"NamedType","name":{"kind":"Name","value":"UUID"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"myMessageChannels"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"connectedAccountId"},"value":{"kind":"Variable","name":{"kind":"Name","value":"connectedAccountId"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"handle"}},{"kind":"Field","name":{"kind":"Name","value":"displayName"}},{"kind":"Field","name":{"kind":"Name","value":"visibility"}},{"kind":"Field","name":{"kind":"Name","value":"type"}},{"kind":"Field","name":{"kind":"Name","value":"isContactAutoCreationEnabled"}},{"kind":"Field","name":{"kind":"Name","value":"contactAutoCreationPolicy"}},{"kind":"Field","name":{"kind":"Name","value":"messageFolderImportPolicy"}},{"kind":"Field","name":{"kind":"Name","value":"excludeNonProfessionalEmails"}},{"kind":"Field","name":{"kind":"Name","value":"excludeGroupEmails"}},{"kind":"Field","name":{"kind":"Name","value":"isSyncEnabled"}},{"kind":"Field","name":{"kind":"Name","value":"syncStatus"}},{"kind":"Field","name":{"kind":"Name","value":"syncStage"}},{"kind":"Field","name":{"kind":"Name","value":"syncStageStartedAt"}},{"kind":"Field","name":{"kind":"Name","value":"importProgress"}},{"kind":"Field","name":{"kind":"Name","value":"connectedAccountId"}},{"kind":"Field","name":{"kind":"Name","value":"connectedAccount"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"handle"}}]}},{"kind":"Field","name":{"kind":"Name","value":"createdAt"}},{"kind":"Field","name":{"kind":"Name","value":"updatedAt"}}]}}]}}]} as unknown as DocumentNode<MyMessageChannelsQuery, MyMessageChannelsQueryVariables>;
+export const MyMessageChannelsDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"query","name":{"kind":"Name","value":"MyMessageChannels"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"connectedAccountId"}},"type":{"kind":"NamedType","name":{"kind":"Name","value":"UUID"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"myMessageChannels"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"connectedAccountId"},"value":{"kind":"Variable","name":{"kind":"Name","value":"connectedAccountId"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"handle"}},{"kind":"Field","name":{"kind":"Name","value":"displayName"}},{"kind":"Field","name":{"kind":"Name","value":"visibility"}},{"kind":"Field","name":{"kind":"Name","value":"type"}},{"kind":"Field","name":{"kind":"Name","value":"isContactAutoCreationEnabled"}},{"kind":"Field","name":{"kind":"Name","value":"contactAutoCreationPolicy"}},{"kind":"Field","name":{"kind":"Name","value":"messageFolderImportPolicy"}},{"kind":"Field","name":{"kind":"Name","value":"excludeNonProfessionalEmails"}},{"kind":"Field","name":{"kind":"Name","value":"excludeGroupEmails"}},{"kind":"Field","name":{"kind":"Name","value":"isSyncEnabled"}},{"kind":"Field","name":{"kind":"Name","value":"messagingProviderUniversalIdentifier"}},{"kind":"Field","name":{"kind":"Name","value":"syncStatus"}},{"kind":"Field","name":{"kind":"Name","value":"syncStage"}},{"kind":"Field","name":{"kind":"Name","value":"syncStageStartedAt"}},{"kind":"Field","name":{"kind":"Name","value":"importProgress"}},{"kind":"Field","name":{"kind":"Name","value":"connectedAccountId"}},{"kind":"Field","name":{"kind":"Name","value":"connectedAccount"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"handle"}}]}},{"kind":"Field","name":{"kind":"Name","value":"createdAt"}},{"kind":"Field","name":{"kind":"Name","value":"updatedAt"}}]}}]}}]} as unknown as DocumentNode<MyMessageChannelsQuery, MyMessageChannelsQueryVariables>;
export const MyMessageFoldersDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"query","name":{"kind":"Name","value":"MyMessageFolders"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"messageChannelId"}},"type":{"kind":"NamedType","name":{"kind":"Name","value":"UUID"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"myMessageFolders"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"messageChannelId"},"value":{"kind":"Variable","name":{"kind":"Name","value":"messageChannelId"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"name"}},{"kind":"Field","name":{"kind":"Name","value":"isSynced"}},{"kind":"Field","name":{"kind":"Name","value":"isSentFolder"}},{"kind":"Field","name":{"kind":"Name","value":"parentFolderId"}},{"kind":"Field","name":{"kind":"Name","value":"externalId"}},{"kind":"Field","name":{"kind":"Name","value":"pendingSyncAction"}},{"kind":"Field","name":{"kind":"Name","value":"messageChannelId"}},{"kind":"Field","name":{"kind":"Name","value":"createdAt"}},{"kind":"Field","name":{"kind":"Name","value":"updatedAt"}}]}}]}}]} as unknown as DocumentNode<MyMessageFoldersQuery, MyMessageFoldersQueryVariables>;
export const UpdateMyUserApplicationVariableDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"mutation","name":{"kind":"Name","value":"UpdateMyUserApplicationVariable"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"applicationUniversalIdentifier"}},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"String"}}}},{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"key"}},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"String"}}}},{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"value"}},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"String"}}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"updateMyUserApplicationVariable"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"applicationUniversalIdentifier"},"value":{"kind":"Variable","name":{"kind":"Name","value":"applicationUniversalIdentifier"}}},{"kind":"Argument","name":{"kind":"Name","value":"key"},"value":{"kind":"Variable","name":{"kind":"Name","value":"key"}}},{"kind":"Argument","name":{"kind":"Name","value":"value"},"value":{"kind":"Variable","name":{"kind":"Name","value":"value"}}}]}]}}]} as unknown as DocumentNode<UpdateMyUserApplicationVariableMutation, UpdateMyUserApplicationVariableMutationVariables>;
export const MyApplicationPreferencesDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"query","name":{"kind":"Name","value":"MyApplicationPreferences"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"myApplicationPreferences"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"applicationId"}},{"kind":"Field","name":{"kind":"Name","value":"settingsMenuItems"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"universalIdentifier"}},{"kind":"Field","name":{"kind":"Name","value":"applicationId"}},{"kind":"Field","name":{"kind":"Name","value":"frontComponentId"}},{"kind":"Field","name":{"kind":"Name","value":"title"}},{"kind":"Field","name":{"kind":"Name","value":"icon"}},{"kind":"Field","name":{"kind":"Name","value":"position"}},{"kind":"Field","name":{"kind":"Name","value":"scope"}},{"kind":"Field","name":{"kind":"Name","value":"slug"}}]}},{"kind":"Field","name":{"kind":"Name","value":"variables"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"key"}},{"kind":"Field","name":{"kind":"Name","value":"value"}},{"kind":"Field","name":{"kind":"Name","value":"description"}},{"kind":"Field","name":{"kind":"Name","value":"label"}},{"kind":"Field","name":{"kind":"Name","value":"isSecret"}},{"kind":"Field","name":{"kind":"Name","value":"isDeprecated"}},{"kind":"Field","name":{"kind":"Name","value":"isRequired"}},{"kind":"Field","name":{"kind":"Name","value":"type"}},{"kind":"Field","name":{"kind":"Name","value":"options"}}]}},{"kind":"Field","name":{"kind":"Name","value":"connectionProviders"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"FragmentSpread","name":{"kind":"Name","value":"ApplicationConnectionProviderFragment"}}]}}]}}]}},{"kind":"FragmentDefinition","name":{"kind":"Name","value":"ApplicationConnectionProviderFragment"},"typeCondition":{"kind":"NamedType","name":{"kind":"Name","value":"ApplicationConnectionProvider"}},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"applicationId"}},{"kind":"Field","name":{"kind":"Name","value":"type"}},{"kind":"Field","name":{"kind":"Name","value":"name"}},{"kind":"Field","name":{"kind":"Name","value":"displayName"}},{"kind":"Field","name":{"kind":"Name","value":"scope"}},{"kind":"Field","name":{"kind":"Name","value":"logoUrl"}},{"kind":"Field","name":{"kind":"Name","value":"oauth"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"scopes"}},{"kind":"Field","name":{"kind":"Name","value":"isClientCredentialsConfigured"}}]}}]}}]} as unknown as DocumentNode<MyApplicationPreferencesQuery, MyApplicationPreferencesQueryVariables>;
diff --git a/packages/twenty-front/src/modules/activities/emails/components/ChatThreadComposer.tsx b/packages/twenty-front/src/modules/activities/emails/components/ChatThreadComposer.tsx
new file mode 100644
index 00000000000..dec22c86d6a
--- /dev/null
+++ b/packages/twenty-front/src/modules/activities/emails/components/ChatThreadComposer.tsx
@@ -0,0 +1,217 @@
+import { styled } from '@linaria/react';
+import { useLingui } from '@lingui/react/macro';
+import { type KeyboardEvent, useState } from 'react';
+import TextareaAutosize from 'react-textarea-autosize';
+import { v4 } from 'uuid';
+
+import { ChatThreadPendingMessage } from '@/activities/emails/components/ChatThreadPendingMessage';
+import { useSendAppChannelMessage } from '@/activities/emails/hooks/useSendAppChannelMessage';
+import { type PendingChatMessage } from '@/activities/emails/types/PendingChatMessage';
+import { isNonEmptyString } from '@sniptt/guards';
+import { IconButton } from 'twenty-ui/components/input';
+import { IconArrowUp } from 'twenty-ui/icon';
+import { themeCssVariables } from 'twenty-ui/theme';
+
+const StyledContainer = styled.div`
+ display: flex;
+ flex-direction: column;
+ flex-shrink: 0;
+ gap: ${themeCssVariables.spacing[2]};
+ padding: ${themeCssVariables.spacing[4]};
+`;
+
+const StyledPendingMessages = styled.div`
+ display: flex;
+ flex-direction: column;
+ gap: ${themeCssVariables.spacing[2]};
+ max-height: ${themeCssVariables.spacing[30]};
+ overflow-y: auto;
+`;
+
+const StyledInputBox = styled.div`
+ background: ${themeCssVariables.background.secondary};
+ border: 1px solid ${themeCssVariables.border.color.medium};
+ border-radius: ${themeCssVariables.border.radius.md};
+ display: flex;
+ flex-direction: column;
+ gap: ${themeCssVariables.spacing[2]};
+ padding: ${themeCssVariables.spacing[2]};
+
+ &:focus-within {
+ border-color: ${themeCssVariables.color.blue};
+ }
+`;
+
+const StyledTextarea = styled(TextareaAutosize)`
+ background: transparent;
+ border: none;
+ color: ${themeCssVariables.font.color.primary};
+ font-family: inherit;
+ font-size: ${themeCssVariables.font.size.md};
+ line-height: ${themeCssVariables.text.lineHeight.lg};
+ outline: none;
+ padding: 0;
+ resize: none;
+
+ &::placeholder {
+ color: ${themeCssVariables.font.color.light};
+ }
+`;
+
+const StyledFooter = styled.div`
+ align-items: center;
+ display: flex;
+ justify-content: flex-end;
+`;
+
+type ChatThreadComposerProps = {
+ messageThreadId: string;
+ messageChannelId: string;
+ channelName: string;
+ recipientName: string | null;
+ isDisconnected: boolean;
+ onMessageSent: () => Promise<unknown>;
+};
+
+export const ChatThreadComposer = ({
+ messageThreadId,
+ messageChannelId,
+ channelName,
+ recipientName,
+ isDisconnected,
+ onMessageSent,
+}: ChatThreadComposerProps) => {
+ const { t } = useLingui();
+ const { sendAppChannelMessage } = useSendAppChannelMessage();
+ const [draft, setDraft] = useState('');
+ const [pendingMessages, setPendingMessages] = useState<PendingChatMessage[]>(
+ [],
+ );
+
+ const setPendingMessageStatus = (
+ id: string,
+ status: PendingChatMessage['status'] | null,
+ ) =>
+ setPendingMessages((currentPendingMessages) =>
+ status === null
+ ? currentPendingMessages.filter((message) => message.id !== id)
+ : currentPendingMessages.map((message) =>
+ message.id === id ? { ...message, status } : message,
+ ),
+ );
+
+ const send = async (pendingMessage: PendingChatMessage) => {
+ setPendingMessageStatus(pendingMessage.id, 'sending');
+
+ try {
+ await sendAppChannelMessage({
+ messageChannelId,
+ messageThreadId,
+ text: pendingMessage.text,
+ idempotencyKey: pendingMessage.id,
+ });
+ } catch {
+ setPendingMessageStatus(pendingMessage.id, 'failed');
+
+ return;
+ }
+
+ const isRefetched = await onMessageSent().then(
+ () => true,
+ () => false,
+ );
+
+ if (isRefetched) {
+ setPendingMessages((currentPendingMessages) =>
+ currentPendingMessages.filter(
+ (message) =>
+ message.id !== pendingMessage.id && message.status !== 'sent',
+ ),
+ );
+
+ return;
+ }
+
+ setPendingMessageStatus(pendingMessage.id, 'sent');
+ };
+
+ const handleSubmit = () => {
+ const text = draft.trim();
+
+ if (!isNonEmptyString(text) || isDisconnected) {
+ return;
+ }
+
+ const pendingMessage: PendingChatMessage = {
+ id: v4(),
+ text,
+ status: 'sending',
+ };
+
+ setPendingMessages((currentPendingMessages) => [
+ ...currentPendingMessages,
+ pendingMessage,
+ ]);
+ setDraft('');
+ send(pendingMessage);
+ };
+
+ const handleKeyDown = (event: KeyboardEvent<HTMLTextAreaElement>) => {
+ if (event.key === 'Enter' && !event.shiftKey) {
+ event.preventDefault();
+ handleSubmit();
+ }
+ };
+
+ const getPlaceholder = () => {
+ if (isDisconnected) {
+ return t`Reconnect ${channelName} to send messages`;
+ }
+
+ return isNonEmptyString(recipientName)
+ ? t`Message ${recipientName}`
+ : t`Write a message`;
+ };
+
+ return (
+ <StyledContainer>
+ {pendingMessages.length > 0 && (
+ <StyledPendingMessages>
+ {pendingMessages.map((pendingMessage) => (
+ <ChatThreadPendingMessage
+ key={pendingMessage.id}
+ pendingMessage={pendingMessage}
+ onRetry={send}
+ onDiscard={({ id }) => setPendingMessageStatus(id, null)}
+ />
+ ))}
+ </StyledPendingMessages>
+ )}
+ <StyledInputBox>
+ <StyledTextarea
+ aria-label={t`Message`}
+ placeholder={getPlaceholder()}
+ minRows={1}
+ maxRows={8}
+ value={draft}
+ disabled={isDisconnected}
+ onChange={(event) => setDraft(event.target.value)}
+ onKeyDown={handleKeyDown}
+ />
+ <StyledFooter>
+ <IconButton
+ variant="solid"
+ color="accent"
+ shape="round"
+ size="sm"
+ aria-label={t`Send`}
+ disabled={isDisconnected || !isNonEmptyString(draft.trim())}
+ onClick={handleSubmit}
+ >
+ <IconArrowUp />
+ </IconButton>
+ </StyledFooter>
+ </StyledInputBox>
+ </StyledContainer>
+ );
+};
diff --git a/packages/twenty-front/src/modules/activities/emails/components/ChatThreadDisconnectedBanner.tsx b/packages/twenty-front/src/modules/activities/emails/components/ChatThreadDisconnectedBanner.tsx
new file mode 100644
index 00000000000..a5e1bae75f5
--- /dev/null
+++ b/packages/twenty-front/src/modules/activities/emails/components/ChatThreadDisconnectedBanner.tsx
@@ -0,0 +1,43 @@
+import { useLingui } from '@lingui/react/macro';
+
+import { InformationBanner } from '@/information-banner/components/InformationBanner';
+import { useTriggerAppOAuth } from '@/settings/applications/hooks/useTriggerAppOAuth';
+import { IconRefresh } from 'twenty-ui/icon';
+
+type ChatThreadDisconnectedBannerProps = {
+ applicationId: string;
+ connectionProviderName: string;
+ channelName: string;
+ connectedAccountId: string;
+ canReconnect: boolean;
+};
+
+export const ChatThreadDisconnectedBanner = ({
+ applicationId,
+ connectionProviderName,
+ channelName,
+ connectedAccountId,
+ canReconnect,
+}: ChatThreadDisconnectedBannerProps) => {
+ const { t } = useLingui();
+ const { triggerAppOAuth } = useTriggerAppOAuth();
+
+ const handleReconnect = () =>
+ triggerAppOAuth({
+ applicationId,
+ providerName: connectionProviderName,
+ reconnectingConnectedAccountId: connectedAccountId,
+ redirectLocation: `${window.location.pathname}${window.location.search}${window.location.hash}`,
+ });
+
+ return (
+ <InformationBanner
+ componentInstanceId={`chat-thread-disconnected-${connectedAccountId}`}
+ status="error"
+ message={t`${channelName} is disconnected.`}
+ buttonTitle={canReconnect ? t`Reconnect` : undefined}
+ buttonIcon={IconRefresh}
+ buttonOnClick={canReconnect ? handleReconnect : undefined}
+ />
+ );
+};
diff --git a/packages/twenty-front/src/modules/activities/emails/components/ChatThreadMessageGroup.tsx b/packages/twenty-front/src/modules/activities/emails/components/ChatThreadMessageGroup.tsx
index cf96f405cdd..ca3fa4ebd25 100644
--- a/packages/twenty-front/src/modules/activities/emails/components/ChatThreadMessageGroup.tsx
+++ b/packages/twenty-front/src/modules/activities/emails/components/ChatThreadMessageGroup.tsx
@@ -1,7 +1,7 @@
import { styled } from '@linaria/react';
import Linkify from 'linkify-react';
-import { CHAT_MESSAGE_BUBBLE_MAX_WIDTH } from '@/activities/emails/constants/ChatMessageBubbleMaxWidth';
+import { StyledChatMessageBubble } from '@/activities/emails/components/StyledChatMessageBubble';
import { ParticipantChip } from '@/activities/components/ParticipantChip';
import { EmailThreadNotShared } from '@/activities/emails/components/EmailThreadNotShared';
import { type ChatMessageGroup } from '@/activities/emails/types/ChatMessageGroup';
@@ -28,29 +28,6 @@ const StyledSentAt = styled.span`
font-size: ${themeCssVariables.font.size.sm};
`;
-const StyledBubble = styled.div<{ isOutgoing: boolean }>`
- background: ${({ isOutgoing }) =>
- isOutgoing
- ? themeCssVariables.background.transparent.light
- : themeCssVariables.background.primary};
- border: 1px solid
- ${({ isOutgoing }) =>
- isOutgoing ? 'transparent' : themeCssVariables.border.color.medium};
- border-radius: ${themeCssVariables.border.radius.md};
- box-sizing: border-box;
- color: ${themeCssVariables.font.color.primary};
- line-height: ${themeCssVariables.text.lineHeight.lg};
- max-width: ${CHAT_MESSAGE_BUBBLE_MAX_WIDTH};
- overflow-wrap: break-word;
- padding: ${themeCssVariables.spacing[1]} ${themeCssVariables.spacing[2]};
- white-space: pre-line;
-
- a {
- color: inherit;
- text-decoration: underline;
- }
-`;
-
type ChatThreadMessageGroupProps = {
group: ChatMessageGroup;
};
@@ -81,11 +58,14 @@ export const ChatThreadMessageGroup = ({
visibility={MessageChannelVisibility.METADATA}
/>
) : (
- <StyledBubble key={message.id} isOutgoing={group.isOutgoing}>
+ <StyledChatMessageBubble
+ key={message.id}
+ isOutgoing={group.isOutgoing}
+ >
<Linkify options={{ target: '_blank', rel: 'noopener noreferrer' }}>
{message.text}
</Linkify>
- </StyledBubble>
+ </StyledChatMessageBubble>
),
)}
</StyledGroup>
diff --git a/packages/twenty-front/src/modules/activities/emails/components/ChatThreadPendingMessage.tsx b/packages/twenty-front/src/modules/activities/emails/components/ChatThreadPendingMessage.tsx
new file mode 100644
index 00000000000..e99c37e1f90
--- /dev/null
+++ b/packages/twenty-front/src/modules/activities/emails/components/ChatThreadPendingMessage.tsx
@@ -0,0 +1,65 @@
+import { styled } from '@linaria/react';
+import { useLingui } from '@lingui/react/macro';
+
+import { StyledChatMessageBubble } from '@/activities/emails/components/StyledChatMessageBubble';
+import { type PendingChatMessage } from '@/activities/emails/types/PendingChatMessage';
+import { LightIconButton } from 'twenty-ui/components/input';
+import { IconRefresh, IconTrash } from 'twenty-ui/icon';
+import { themeCssVariables } from 'twenty-ui/theme';
+
+const StyledContainer = styled.div`
+ align-items: flex-end;
+ display: flex;
+ flex-direction: column;
+ gap: ${themeCssVariables.spacing[1]};
+`;
+
+const StyledFailedRow = styled.div`
+ align-items: center;
+ color: ${themeCssVariables.color.red};
+ display: flex;
+ font-size: ${themeCssVariables.font.size.sm};
+ gap: ${themeCssVariables.spacing[1]};
+`;
+
+type ChatThreadPendingMessageProps = {
+ pendingMessage: PendingChatMessage;
+ onRetry: (pendingMessage: PendingChatMessage) => void;
+ onDiscard: (pendingMessage: PendingChatMessage) => void;
+};
+
+export const ChatThreadPendingMessage = ({
+ pendingMessage,
+ onRetry,
+ onDiscard,
+}: ChatThreadPendingMessageProps) => {
+ const { t } = useLingui();
+
+ return (
+ <StyledContainer>
+ <StyledChatMessageBubble
+ isOutgoing
+ isDimmed={pendingMessage.status === 'sending'}
+ >
+ {pendingMessage.text}
+ </StyledChatMessageBubble>
+ {pendingMessage.status === 'failed' && (
+ <StyledFailedRow>
+ {t`Sending failed`}
+ <LightIconButton
+ aria-label={t`Retry`}
+ onClick={() => onRetry(pendingMessage)}
+ >
+ <IconRefresh />
+ </LightIconButton>
+ <LightIconButton
+ aria-label={t`Delete`}
+ onClick={() => onDiscard(pendingMessage)}
+ >
+ <IconTrash />
+ </LightIconButton>
+ </StyledFailedRow>
+ )}
+ </StyledContainer>
+ );
+};
diff --git a/packages/twenty-front/src/modules/activities/emails/components/ChatThreadSidePanelTitle.tsx b/packages/twenty-front/src/modules/activities/emails/components/ChatThreadSidePanelTitle.tsx
new file mode 100644
index 00000000000..a66f7d71998
--- /dev/null
+++ b/packages/twenty-front/src/modules/activities/emails/components/ChatThreadSidePanelTitle.tsx
@@ -0,0 +1,23 @@
+import { MessageChannelLogo } from '@/activities/emails/components/MessageChannelLogo';
+import { useChatThreadTitle } from '@/activities/emails/hooks/useChatThreadTitle';
+import { HeaderIdentifier } from '@/ui/layout/page/components/HeaderIdentifier';
+import { type TimelineThreadChannel } from '~/generated/graphql';
+
+type ChatThreadSidePanelTitleProps = {
+ messageThreadId: string;
+ channel: TimelineThreadChannel;
+};
+
+export const ChatThreadSidePanelTitle = ({
+ messageThreadId,
+ channel,
+}: ChatThreadSidePanelTitleProps) => {
+ const title = useChatThreadTitle(messageThreadId);
+
+ return (
+ <HeaderIdentifier
+ icon={<MessageChannelLogo channel={channel} />}
+ title={title ?? ''}
+ />
+ );
+};
diff --git a/packages/twenty-front/src/modules/activities/emails/components/MessageThreadSidePanelTitle.tsx b/packages/twenty-front/src/modules/activities/emails/components/MessageThreadSidePanelTitle.tsx
new file mode 100644
index 00000000000..fc629502b83
--- /dev/null
+++ b/packages/twenty-front/src/modules/activities/emails/components/MessageThreadSidePanelTitle.tsx
@@ -0,0 +1,37 @@
+import { type ReactNode } from 'react';
+import { isDefined } from 'twenty-shared/utils';
+
+import { ChatThreadSidePanelTitle } from '@/activities/emails/components/ChatThreadSidePanelTitle';
+import { useMessageThreadChannel } from '@/activities/emails/hooks/useMessageThreadChannel';
+import { isChatTimelineThreadChannel } from '@/activities/emails/utils/isChatTimelineThreadChannel';
+
+type MessageThreadSidePanelTitleProps = {
+ messageThreadId: string;
+ emailThreadTitle: ReactNode;
+};
+
+export const MessageThreadSidePanelTitle = ({
+ messageThreadId,
+ emailThreadTitle,
+}: MessageThreadSidePanelTitleProps) => {
+ const { messageThreadChannel, messageThreadChannelLoading } =
+ useMessageThreadChannel(messageThreadId);
+
+ if (messageThreadChannelLoading) {
+ return null;
+ }
+
+ if (
+ isDefined(messageThreadChannel) &&
+ isChatTimelineThreadChannel(messageThreadChannel)
+ ) {
+ return (
+ <ChatThreadSidePanelTitle
+ messageThreadId={messageThreadId}
+ channel={messageThreadChannel}
+ />
+ );
+ }
+
+ return emailThreadTitle;
+};
diff --git a/packages/twenty-front/src/modules/activities/emails/components/StyledChatMessageBubble.tsx b/packages/twenty-front/src/modules/activities/emails/components/StyledChatMessageBubble.tsx
new file mode 100644
index 00000000000..1305be03b86
--- /dev/null
+++ b/packages/twenty-front/src/modules/activities/emails/components/StyledChatMessageBubble.tsx
@@ -0,0 +1,31 @@
+import { styled } from '@linaria/react';
+
+import { CHAT_MESSAGE_BUBBLE_MAX_WIDTH } from '@/activities/emails/constants/ChatMessageBubbleMaxWidth';
+import { themeCssVariables } from 'twenty-ui/theme';
+
+export const StyledChatMessageBubble = styled.div<{
+ isOutgoing: boolean;
+ isDimmed?: boolean;
+}>`
+ background: ${({ isOutgoing }) =>
+ isOutgoing
+ ? themeCssVariables.background.transparent.light
+ : themeCssVariables.background.primary};
+ border: 1px solid
+ ${({ isOutgoing }) =>
+ isOutgoing ? 'transparent' : themeCssVariables.border.color.medium};
+ border-radius: ${themeCssVariables.border.radius.md};
+ box-sizing: border-box;
+ color: ${themeCssVariables.font.color.primary};
+ line-height: ${themeCssVariables.text.lineHeight.lg};
+ max-width: ${CHAT_MESSAGE_BUBBLE_MAX_WIDTH};
+ opacity: ${({ isDimmed }) => (isDimmed ? 0.6 : 1)};
+ overflow-wrap: break-word;
+ padding: ${themeCssVariables.spacing[1]} ${themeCssVariables.spacing[2]};
+ white-space: pre-line;
+
+ a {
+ color: inherit;
+ text-decoration: underline;
+ }
+`;
diff --git a/packages/twenty-front/src/modules/activities/emails/components/__tests__/ChatThreadComposer.test.tsx b/packages/twenty-front/src/modules/activities/emails/components/__tests__/ChatThreadComposer.test.tsx
new file mode 100644
index 00000000000..0f3722717ca
--- /dev/null
+++ b/packages/twenty-front/src/modules/activities/emails/components/__tests__/ChatThreadComposer.test.tsx
@@ -0,0 +1,83 @@
+import { i18n } from '@lingui/core';
+import { I18nProvider } from '@lingui/react';
+import { render, screen, waitFor } from '@testing-library/react';
+import userEvent from '@testing-library/user-event';
+
+import { ChatThreadComposer } from '@/activities/emails/components/ChatThreadComposer';
+
+const mockSendAppChannelMessage = jest.fn();
+
+jest.mock('@/activities/emails/hooks/useSendAppChannelMessage', () => ({
+ useSendAppChannelMessage: () => ({
+ sendAppChannelMessage: mockSendAppChannelMessage,
+ }),
+}));
+
+describe('ChatThreadComposer', () => {
+ it('retries a failed message with the same idempotency key', async () => {
+ mockSendAppChannelMessage
+ .mockRejectedValueOnce(new Error('Network error'))
+ .mockResolvedValueOnce(undefined);
+
+ const onMessageSent = jest.fn().mockResolvedValue(undefined);
+
+ render(
+ <I18nProvider i18n={i18n}>
+ <ChatThreadComposer
+ messageThreadId="thread-id"
+ messageChannelId="channel-id"
+ channelName="LinkedIn"
+ recipientName="Ada"
+ isDisconnected={false}
+ onMessageSent={onMessageSent}
+ />
+ </I18nProvider>,
+ );
+
+ await userEvent.type(screen.getByRole('textbox'), 'Hello{Enter}');
+ await userEvent.click(await screen.findByRole('button', { name: 'Retry' }));
+
+ await waitFor(() => expect(onMessageSent).toHaveBeenCalledTimes(1));
+
+ const [firstCall, secondCall] = mockSendAppChannelMessage.mock.calls;
+
+ expect(firstCall[0].idempotencyKey).toEqual(expect.any(String));
+ expect(secondCall[0].idempotencyKey).toBe(firstCall[0].idempotencyKey);
+ });
+
+ it('keeps the sent message until the thread is refreshed', async () => {
+ mockSendAppChannelMessage.mockResolvedValueOnce(undefined);
+
+ let finishRefresh: () => void = () => undefined;
+ const onMessageSent = jest.fn(
+ () =>
+ new Promise<void>((resolve) => {
+ finishRefresh = resolve;
+ }),
+ );
+
+ render(
+ <I18nProvider i18n={i18n}>
+ <ChatThreadComposer
+ messageThreadId="thread-id"
+ messageChannelId="channel-id"
+ channelName="LinkedIn"
+ recipientName="Ada"
+ isDisconnected={false}
+ onMessageSent={onMessageSent}
+ />
+ </I18nProvider>,
+ );
+
+ await userEvent.type(screen.getByRole('textbox'), 'Hello{Enter}');
+ await waitFor(() => expect(onMessageSent).toHaveBeenCalledTimes(1));
+
+ expect(screen.getByText('Hello')).toBeInTheDocument();
+
+ finishRefresh();
+
+ await waitFor(() =>
+ expect(screen.queryByText('Hello')).not.toBeInTheDocument(),
+ );
+ });
+});
diff --git a/packages/twenty-front/src/modules/activities/emails/components/__tests__/MessageThreadSidePanelTitle.test.tsx b/packages/twenty-front/src/modules/activities/emails/components/__tests__/MessageThreadSidePanelTitle.test.tsx
new file mode 100644
index 00000000000..97942cbce59
--- /dev/null
+++ b/packages/twenty-front/src/modules/activities/emails/components/__tests__/MessageThreadSidePanelTitle.test.tsx
@@ -0,0 +1,78 @@
+import { render, screen } from '@testing-library/react';
+
+import { MessageThreadSidePanelTitle } from '@/activities/emails/components/MessageThreadSidePanelTitle';
+import { MessageChannelType } from '~/generated/graphql';
+
+const mockUseMessageThreadChannel = jest.fn();
+
+jest.mock('@/activities/emails/hooks/useMessageThreadChannel', () => ({
+ useMessageThreadChannel: () => mockUseMessageThreadChannel(),
+}));
+
+jest.mock('@/activities/emails/hooks/useChatThreadTitle', () => ({
+ useChatThreadTitle: () => 'Sundar Pichai',
+}));
+
+jest.mock('@/activities/emails/components/MessageChannelLogo', () => ({
+ MessageChannelLogo: () => <span>Channel logo</span>,
+}));
+
+const renderTitle = () =>
+ render(
+ <MessageThreadSidePanelTitle
+ messageThreadId="thread-id"
+ emailThreadTitle={<span>Email subject</span>}
+ />,
+ );
+
+const mockChannel = ({
+ type,
+ messageThreadChannelLoading = false,
+}: {
+ type: MessageChannelType | null;
+ messageThreadChannelLoading?: boolean;
+}) =>
+ mockUseMessageThreadChannel.mockReturnValue({
+ messageThreadChannel:
+ type === null
+ ? null
+ : { type, provider: 'whatsapp', applicationId: null },
+ messageThreadChannelLoading,
+ });
+
+describe('MessageThreadSidePanelTitle', () => {
+ it('should show the channel logo and the contact name on an app chat', () => {
+ mockChannel({ type: MessageChannelType.APP });
+
+ renderTitle();
+
+ expect(screen.getByText('Channel logo')).toBeVisible();
+ expect(screen.getByText('Sundar Pichai')).toBeVisible();
+ expect(screen.queryByText('Email subject')).not.toBeInTheDocument();
+ });
+
+ it('should keep the record title on an email thread', () => {
+ mockChannel({ type: MessageChannelType.EMAIL });
+
+ renderTitle();
+
+ expect(screen.getByText('Email subject')).toBeVisible();
+ expect(screen.queryByText('Sundar Pichai')).not.toBeInTheDocument();
+ });
+
+ it('should keep the record title when the channel is unknown', () => {
+ mockChannel({ type: null });
+
+ renderTitle();
+
+ expect(screen.getByText('Email subject')).toBeVisible();
+ });
+
+ it('should render nothing while the channel is loading', () => {
+ mockChannel({ type: null, messageThreadChannelLoading: true });
+
+ const { container } = renderTitle();
+
+ expect(container).toBeEmptyDOMElement();
+ });
+});
diff --git a/packages/twenty-front/src/modules/activities/emails/graphql/mutations/sendAppChannelMessage.ts b/packages/twenty-front/src/modules/activities/emails/graphql/mutations/sendAppChannelMessage.ts
new file mode 100644
index 00000000000..01070bb2892
--- /dev/null
+++ b/packages/twenty-front/src/modules/activities/emails/graphql/mutations/sendAppChannelMessage.ts
@@ -0,0 +1,10 @@
+import gql from 'graphql-tag';
+
+export const SEND_APP_CHANNEL_MESSAGE = gql`
+ mutation SendAppChannelMessage($input: SendAppChannelMessageInput!) {
+ sendAppChannelMessage(input: $input) {
+ messageId
+ messageThreadId
+ }
+ }
+`;
diff --git a/packages/twenty-front/src/modules/activities/emails/hooks/__tests__/useReplyConnectedAccount.test.ts b/packages/twenty-front/src/modules/activities/emails/hooks/__tests__/useReplyConnectedAccount.test.ts
index a04d247479f..1ff3b14cc5b 100644
--- a/packages/twenty-front/src/modules/activities/emails/hooks/__tests__/useReplyConnectedAccount.test.ts
+++ b/packages/twenty-front/src/modules/activities/emails/hooks/__tests__/useReplyConnectedAccount.test.ts
@@ -63,7 +63,7 @@ describe('useReplyConnectedAccount', () => {
useReplyConnectedAccount('channel-imap'),
);
- expect(result.current).toEqual({
+ expect(result.current).toMatchObject({
connectedAccountId: 'account-imap',
connectedAccountHandle: '[email protected]',
connectedAccountProvider: ConnectedAccountProvider.IMAP_SMTP_CALDAV,
diff --git a/packages/twenty-front/src/modules/activities/emails/hooks/useChatThreadCounterparts.ts b/packages/twenty-front/src/modules/activities/emails/hooks/useChatThreadCounterparts.ts
new file mode 100644
index 00000000000..da616b2f0e9
--- /dev/null
+++ b/packages/twenty-front/src/modules/activities/emails/hooks/useChatThreadCounterparts.ts
@@ -0,0 +1,22 @@
+import { type EmailThreadMessageWithSender } from '@/activities/emails/types/EmailThreadMessageWithSender';
+import { getChatThreadCounterparts } from '@/activities/emails/utils/getChatThreadCounterparts';
+import { getOutgoingMessageIds } from '@/activities/emails/utils/getOutgoingMessageIds';
+import { useMyMessageChannels } from '@/settings/accounts/hooks/useMyMessageChannels';
+
+export const useChatThreadCounterparts = (
+ messages: EmailThreadMessageWithSender[],
+) => {
+ const { channels, hasLoaded, loading } = useMyMessageChannels();
+
+ if (!hasLoaded && loading) {
+ return null;
+ }
+
+ return getChatThreadCounterparts({
+ messages,
+ outgoingMessageIds: getOutgoingMessageIds({
+ messages,
+ viewerMessageChannelIds: new Set(channels.map(({ id }) => id)),
+ }),
+ });
+};
diff --git a/packages/twenty-front/src/modules/activities/emails/hooks/useChatThreadTitle.ts b/packages/twenty-front/src/modules/activities/emails/hooks/useChatThreadTitle.ts
new file mode 100644
index 00000000000..26c3cd1fe10
--- /dev/null
+++ b/packages/twenty-front/src/modules/activities/emails/hooks/useChatThreadTitle.ts
@@ -0,0 +1,18 @@
+import { isNonEmptyString, isNull } from '@sniptt/guards';
+
+import { useChatThreadCounterparts } from '@/activities/emails/hooks/useChatThreadCounterparts';
+import { useEmailThread } from '@/activities/emails/hooks/useEmailThread';
+
+export const useChatThreadTitle = (messageThreadId: string) => {
+ const { messages } = useEmailThread(messageThreadId);
+ const counterparts = useChatThreadCounterparts(messages);
+
+ if (isNull(counterparts)) {
+ return null;
+ }
+
+ return counterparts
+ .map(({ displayName }) => displayName)
+ .filter(isNonEmptyString)
+ .join(', ');
+};
diff --git a/packages/twenty-front/src/modules/activities/emails/hooks/useEmailThread.ts b/packages/twenty-front/src/modules/activities/emails/hooks/useEmailThread.ts
index 772e9869cbb..c65b0445da4 100644
--- a/packages/twenty-front/src/modules/activities/emails/hooks/useEmailThread.ts
+++ b/packages/twenty-front/src/modules/activities/emails/hooks/useEmailThread.ts
@@ -9,6 +9,7 @@ import { type EmailThreadMessageWithSender } from '@/activities/emails/types/Ema
import { type MessageChannelMessageAssociation } from '@/activities/emails/types/MessageChannelMessageAssociation';
import { useFindManyRecords } from '@/object-record/hooks/useFindManyRecords';
import { useFindOneRecord } from '@/object-record/hooks/useFindOneRecord';
+import { useMyMessageChannels } from '@/settings/accounts/hooks/useMyMessageChannels';
import { useUpsertRecordsInStore } from '@/object-record/record-store/hooks/useUpsertRecordsInStore';
import {
CoreObjectNameSingular,
@@ -17,6 +18,7 @@ import {
export const useEmailThread = (threadId: string | null) => {
const { upsertRecordsInStore } = useUpsertRecordsInStore();
+ const { channels: viewerMessageChannels } = useMyMessageChannels();
const [lastMessageId, setLastMessageId] = useState<string | null>(null);
const [isMessagesFetchComplete, setIsMessagesFetchComplete] = useState(false);
@@ -45,6 +47,7 @@ export const useEmailThread = (threadId: string | null) => {
loading: messagesLoading,
fetchMoreRecords,
hasNextPage,
+ refetch: refetchMessages,
} = useFindManyRecords<EmailThreadMessage>({
limit: FETCH_ALL_MESSAGES_OPERATION_SIGNATURE.variables.limit,
filter: FETCH_ALL_MESSAGES_OPERATION_SIGNATURE.variables.filter,
@@ -123,7 +126,14 @@ export const useEmailThread = (threadId: string | null) => {
skip: !lastMessageId || !isMessagesFetchComplete,
});
- const lastMessageAssociation = messageChannelMessageAssociations[0];
+ const viewerMessageChannelIds = new Set(
+ viewerMessageChannels.map(({ id }) => id),
+ );
+
+ const lastMessageAssociation =
+ messageChannelMessageAssociations.find(({ messageChannelId }) =>
+ viewerMessageChannelIds.has(messageChannelId),
+ ) ?? messageChannelMessageAssociations[0];
const messageThreadExternalId =
lastMessageAssociation?.messageThreadExternalId ?? null;
const lastMessageExternalId =
@@ -163,6 +173,8 @@ export const useEmailThread = (threadId: string | null) => {
threadLoading: threadRecordLoading || messagesLoading,
messageChannelLoading,
lastMessageExternalId,
+ lastMessageChannelId,
fetchMoreMessages,
+ refetchMessages,
};
};
diff --git a/packages/twenty-front/src/modules/activities/emails/hooks/useMessageThreadChannel.ts b/packages/twenty-front/src/modules/activities/emails/hooks/useMessageThreadChannel.ts
index bb0c7e44cf1..52a6851a067 100644
--- a/packages/twenty-front/src/modules/activities/emails/hooks/useMessageThreadChannel.ts
+++ b/packages/twenty-front/src/modules/activities/emails/hooks/useMessageThreadChannel.ts
@@ -3,12 +3,16 @@ import { useQuery } from '@apollo/client/react';
import { useApolloCoreClient } from '@/object-metadata/hooks/useApolloCoreClient';
import { GetMessageThreadChannelDocument } from '~/generated/graphql';
-export const useMessageThreadChannel = (messageThreadId: string) => {
+export const useMessageThreadChannel = (
+ messageThreadId: string,
+ { skip = false }: { skip?: boolean } = {},
+) => {
const apolloCoreClient = useApolloCoreClient();
const { data, loading } = useQuery(GetMessageThreadChannelDocument, {
client: apolloCoreClient,
variables: { messageThreadId },
+ skip,
});
return {
diff --git a/packages/twenty-front/src/modules/activities/emails/hooks/useReplyConnectedAccount.ts b/packages/twenty-front/src/modules/activities/emails/hooks/useReplyConnectedAccount.ts
index a0596219fab..cfe7ef459c6 100644
--- a/packages/twenty-front/src/modules/activities/emails/hooks/useReplyConnectedAccount.ts
+++ b/packages/twenty-front/src/modules/activities/emails/hooks/useReplyConnectedAccount.ts
@@ -25,6 +25,8 @@ export const useReplyConnectedAccount = (messageChannelId: string | null) => {
) ?? null;
return {
+ messageChannel: threadMessageChannel,
+ connectedAccount: replyConnectedAccount,
connectedAccountId: replyConnectedAccount?.id ?? null,
connectedAccountHandle: replyConnectedAccount?.handle ?? null,
connectedAccountProvider:
diff --git a/packages/twenty-front/src/modules/activities/emails/hooks/useSendAppChannelMessage.ts b/packages/twenty-front/src/modules/activities/emails/hooks/useSendAppChannelMessage.ts
new file mode 100644
index 00000000000..de6fb48856d
--- /dev/null
+++ b/packages/twenty-front/src/modules/activities/emails/hooks/useSendAppChannelMessage.ts
@@ -0,0 +1,41 @@
+import { useMutation } from '@apollo/client/react';
+
+import { getTimelineThreadsFromObjectRecord } from '@/activities/emails/graphql/queries/getTimelineThreadsFromObjectRecord';
+import { SEND_APP_CHANNEL_MESSAGE } from '@/activities/emails/graphql/mutations/sendAppChannelMessage';
+import { useApolloCoreClient } from '@/object-metadata/hooks/useApolloCoreClient';
+import {
+ type SendAppChannelMessageMutation,
+ type SendAppChannelMessageMutationVariables,
+} from '~/generated-metadata/graphql';
+
+export const useSendAppChannelMessage = () => {
+ const apolloCoreClient = useApolloCoreClient();
+ const [sendAppChannelMessageMutation] = useMutation<
+ SendAppChannelMessageMutation,
+ SendAppChannelMessageMutationVariables
+ >(SEND_APP_CHANNEL_MESSAGE);
+
+ const sendAppChannelMessage = async ({
+ messageChannelId,
+ messageThreadId,
+ text,
+ idempotencyKey,
+ }: {
+ messageChannelId: string;
+ messageThreadId: string;
+ text: string;
+ idempotencyKey: string;
+ }) => {
+ await sendAppChannelMessageMutation({
+ variables: {
+ input: { messageChannelId, messageThreadId, text, idempotencyKey },
+ },
+ });
+
+ await apolloCoreClient
+ .refetchQueries({ include: [getTimelineThreadsFromObjectRecord] })
+ .catch(() => undefined);
+ };
+
+ return { sendAppChannelMessage };
+};
diff --git a/packages/twenty-front/src/modules/activities/emails/hooks/useStickToBottomScroll.ts b/packages/twenty-front/src/modules/activities/emails/hooks/useStickToBottomScroll.ts
new file mode 100644
index 00000000000..772b2aa3a9d
--- /dev/null
+++ b/packages/twenty-front/src/modules/activities/emails/hooks/useStickToBottomScroll.ts
@@ -0,0 +1,27 @@
+import { type UIEvent, useEffect, useRef, useState } from 'react';
+import { isDefined } from 'twenty-shared/utils';
+
+const BOTTOM_THRESHOLD_IN_PX = 8;
+
+export const useStickToBottomScroll = (contentSize: number) => {
+ const scrollContainerRef = useRef<HTMLDivElement>(null);
+ const [isPinnedToBottom, setIsPinnedToBottom] = useState(true);
+
+ useEffect(() => {
+ const scrollContainer = scrollContainerRef.current;
+
+ if (isDefined(scrollContainer) && isPinnedToBottom) {
+ scrollContainer.scrollTop = scrollContainer.scrollHeight;
+ }
+ }, [contentSize, isPinnedToBottom]);
+
+ const handleScroll = (event: UIEvent<HTMLDivElement>) => {
+ const { scrollHeight, scrollTop, clientHeight } = event.currentTarget;
+
+ setIsPinnedToBottom(
+ scrollHeight - scrollTop - clientHeight <= BOTTOM_THRESHOLD_IN_PX,
+ );
+ };
+
+ return { scrollContainerRef, handleScroll };
+};
diff --git a/packages/twenty-front/src/modules/activities/emails/types/PendingChatMessage.ts b/packages/twenty-front/src/modules/activities/emails/types/PendingChatMessage.ts
new file mode 100644
index 00000000000..563cd46bc85
--- /dev/null
+++ b/packages/twenty-front/src/modules/activities/emails/types/PendingChatMessage.ts
@@ -0,0 +1,5 @@
+export type PendingChatMessage = {
+ id: string;
+ text: string;
+ status: 'sending' | 'sent' | 'failed';
+};
diff --git a/packages/twenty-front/src/modules/activities/emails/utils/__tests__/getChatThreadCounterparts.test.ts b/packages/twenty-front/src/modules/activities/emails/utils/__tests__/getChatThreadCounterparts.test.ts
new file mode 100644
index 00000000000..8aafeabc467
--- /dev/null
+++ b/packages/twenty-front/src/modules/activities/emails/utils/__tests__/getChatThreadCounterparts.test.ts
@@ -0,0 +1,89 @@
+import { MessageParticipantRole } from 'twenty-shared/types';
+
+import { getChatThreadCounterparts } from '@/activities/emails/utils/getChatThreadCounterparts';
+
+const participant = ({
+ handle,
+ displayName,
+ role = MessageParticipantRole.FROM,
+}: {
+ handle: string;
+ displayName: string;
+ role?: MessageParticipantRole;
+}) => ({ handle, displayName, role });
+
+const buildMessage = ({
+ id,
+ sender,
+ recipients = [],
+}: {
+ id: string;
+ sender?: ReturnType<typeof participant>;
+ recipients?: ReturnType<typeof participant>[];
+}) => ({
+ id,
+ sender,
+ messageParticipants: [...(sender ? [sender] : []), ...recipients],
+});
+
+const SUNDAR = participant({ handle: 'sundar', displayName: 'Sundar Pichai' });
+const THOMAS = participant({ handle: 'thomas', displayName: 'Thomas Kurian' });
+const PHIL = participant({ handle: 'phil', displayName: 'Phil Schiller' });
+
+const names = (participants: { displayName: string }[]) =>
+ participants.map(({ displayName }) => displayName);
+
+describe('getChatThreadCounterparts', () => {
+ it('should return the senders of incoming messages only', () => {
+ expect(
+ names(
+ getChatThreadCounterparts({
+ messages: [
+ buildMessage({ id: '1', sender: SUNDAR }),
+ buildMessage({ id: '2', sender: PHIL }),
+ buildMessage({ id: '3', sender: SUNDAR }),
+ ],
+ outgoingMessageIds: new Set(['2']),
+ }),
+ ),
+ ).toEqual(['Sundar Pichai']);
+ });
+
+ it('should list each sender of a group chat once, in order', () => {
+ expect(
+ names(
+ getChatThreadCounterparts({
+ messages: [
+ buildMessage({ id: '1', sender: THOMAS }),
+ buildMessage({ id: '2', sender: SUNDAR }),
+ buildMessage({ id: '3', sender: THOMAS }),
+ ],
+ outgoingMessageIds: new Set(),
+ }),
+ ),
+ ).toEqual(['Thomas Kurian', 'Sundar Pichai']);
+ });
+
+ it('should fall back to the recipients when the contact never replied', () => {
+ expect(
+ names(
+ getChatThreadCounterparts({
+ messages: [
+ buildMessage({
+ id: '1',
+ sender: PHIL,
+ recipients: [
+ participant({
+ handle: 'sundar',
+ displayName: 'Sundar Pichai',
+ role: MessageParticipantRole.TO,
+ }),
+ ],
+ }),
+ ],
+ outgoingMessageIds: new Set(['1']),
+ }),
+ ),
+ ).toEqual(['Sundar Pichai']);
+ });
+});
diff --git a/packages/twenty-front/src/modules/activities/emails/utils/getChatThreadCounterparts.ts b/packages/twenty-front/src/modules/activities/emails/utils/getChatThreadCounterparts.ts
new file mode 100644
index 00000000000..5b807dd1fa0
--- /dev/null
+++ b/packages/twenty-front/src/modules/activities/emails/utils/getChatThreadCounterparts.ts
@@ -0,0 +1,51 @@
+import { MessageParticipantRole } from 'twenty-shared/types';
+import { isDefined } from 'twenty-shared/utils';
+
+import { type EmailThreadMessageParticipant } from '@/activities/emails/types/EmailThreadMessageParticipant';
+
+type ChatThreadParticipant = Pick<
+ EmailThreadMessageParticipant,
+ 'handle' | 'role'
+>;
+
+type ChatThreadMessage<TParticipant extends ChatThreadParticipant> = {
+ id: string;
+ sender?: TParticipant;
+ messageParticipants?: TParticipant[];
+};
+
+const uniqueByHandle = <TParticipant extends ChatThreadParticipant>(
+ participants: TParticipant[],
+) => [
+ ...new Map(
+ participants.map((participant) => [participant.handle, participant]),
+ ).values(),
+];
+
+export const getChatThreadCounterparts = <
+ TParticipant extends ChatThreadParticipant,
+>({
+ messages,
+ outgoingMessageIds,
+}: {
+ messages: ChatThreadMessage<TParticipant>[];
+ outgoingMessageIds: ReadonlySet<string>;
+}): TParticipant[] => {
+ const incomingSenders = uniqueByHandle(
+ messages
+ .filter(({ id }) => !outgoingMessageIds.has(id))
+ .map(({ sender }) => sender)
+ .filter(isDefined),
+ );
+
+ if (incomingSenders.length > 0) {
+ return incomingSenders;
+ }
+
+ return uniqueByHandle(
+ messages
+ .filter(({ id }) => outgoingMessageIds.has(id))
+ .flatMap(({ messageParticipants }) => messageParticipants ?? [])
+ .filter(({ role }) => role === MessageParticipantRole.TO),
+ );
+};
diff --git a/packages/twenty-front/src/modules/object-record/record-show/components/PageLayoutRecordPageRenderer.tsx b/packages/twenty-front/src/modules/object-record/record-show/components/PageLayoutRecordPageRenderer.tsx
index 945ae046ffd..6b3719799dd 100644
--- a/packages/twenty-front/src/modules/object-record/record-show/components/PageLayoutRecordPageRenderer.tsx
+++ b/packages/twenty-front/src/modules/object-record/record-show/components/PageLayoutRecordPageRenderer.tsx
@@ -3,13 +3,13 @@ import { RecordPageSidePanelPinnedCommandMenuItems } from '@/command-menu-item/c
import { RecordPageSidePanelWidgetCommandMenuItems } from '@/command-menu-item/components/RecordPageSidePanelWidgetCommandMenuItems';
import { InformationBannerDeletedRecord } from '@/information-banner/components/deleted-record/InformationBannerDeletedRecord';
import { RecordShowContainerContextStoreTargetedRecordsEffect } from '@/object-record/record-show/components/RecordShowContainerContextStoreTargetedRecordsEffect';
+import { useDisplaySidePanelFooter } from '@/object-record/record-show/hooks/useDisplaySidePanelFooter';
import { recordStoreFamilySelector } from '@/object-record/record-store/states/selectors/recordStoreFamilySelector';
import { PageLayoutRenderer } from '@/page-layout/components/PageLayoutRenderer';
import { usePageLayoutIdForRecord } from '@/page-layout/hooks/usePageLayoutIdForRecord';
import { PageLayoutIdContext } from '@/page-layout/states/currentPageLayoutIdState';
import { LayoutRenderingProvider } from '@/ui/layout/contexts/LayoutRenderingContext';
import { type TargetRecordIdentifier } from '@/ui/layout/contexts/TargetRecordIdentifier';
-import { useWorkspaceSurface } from '@/ui/layout/hooks/useWorkspaceSurface';
import { SidePanelFooter } from '@/ui/layout/side-panel/components/SidePanelFooter';
import { useAtomFamilySelectorValue } from '@/ui/utilities/state/jotai/hooks/useAtomFamilySelectorValue';
import { styled } from '@linaria/react';
@@ -47,7 +47,9 @@ export const PageLayoutRecordPageRenderer = ({
targetRecordIdentifier: TargetRecordIdentifier;
isRecordIdentifierBarHidden?: boolean;
}) => {
- const isInSidePanel = useWorkspaceSurface().type === 'side-panel';
+ const displaySidePanelFooter = useDisplaySidePanelFooter(
+ targetRecordIdentifier,
+ );
const recordDeletedAt = useAtomFamilySelectorValue(
recordStoreFamilySelector,
{
@@ -99,7 +101,7 @@ export const PageLayoutRecordPageRenderer = ({
</LayoutRenderingProvider>
</StyledContentContainer>
- {isInSidePanel && (
+ {displaySidePanelFooter && (
<SidePanelFooter
actions={[
<RecordPageSidePanelCommandMenu key="options" />,
diff --git a/packages/twenty-front/src/modules/object-record/record-show/hooks/__tests__/useDisplaySidePanelFooter.test.tsx b/packages/twenty-front/src/modules/object-record/record-show/hooks/__tests__/useDisplaySidePanelFooter.test.tsx
new file mode 100644
index 00000000000..ff258b895d6
--- /dev/null
+++ b/packages/twenty-front/src/modules/object-record/record-show/hooks/__tests__/useDisplaySidePanelFooter.test.tsx
@@ -0,0 +1,92 @@
+import { renderHook } from '@testing-library/react';
+import { CoreObjectNameSingular } from 'twenty-shared/types';
+
+import { useDisplaySidePanelFooter } from '@/object-record/record-show/hooks/useDisplaySidePanelFooter';
+import { MessageChannelType } from '~/generated/graphql';
+
+let mockWorkspaceSurfaceType = 'side-panel';
+const mockUseMessageThreadChannel = jest.fn();
+
+jest.mock('@/ui/layout/hooks/useWorkspaceSurface', () => ({
+ useWorkspaceSurface: () => ({ type: mockWorkspaceSurfaceType }),
+}));
+
+jest.mock('@/activities/emails/hooks/useMessageThreadChannel', () => ({
+ useMessageThreadChannel: (...args: unknown[]) =>
+ mockUseMessageThreadChannel(...args),
+}));
+
+const MESSAGE_THREAD = {
+ id: 'thread-id',
+ targetObjectNameSingular: CoreObjectNameSingular.MessageThread,
+};
+
+const mockChannel = (
+ type: MessageChannelType | null,
+ messageThreadChannelLoading = false,
+) =>
+ mockUseMessageThreadChannel.mockReturnValue({
+ messageThreadChannel: type === null ? null : { type },
+ messageThreadChannelLoading,
+ });
+
+describe('useDisplaySidePanelFooter', () => {
+ beforeEach(() => {
+ mockWorkspaceSurfaceType = 'side-panel';
+ mockChannel(null);
+ });
+
+ it('hides the footer outside the side panel', () => {
+ mockWorkspaceSurfaceType = 'main';
+
+ const { result } = renderHook(() =>
+ useDisplaySidePanelFooter({
+ id: 'company-id',
+ targetObjectNameSingular: CoreObjectNameSingular.Company,
+ }),
+ );
+
+ expect(result.current).toBe(false);
+ });
+
+ it('shows the footer for other records', () => {
+ const { result } = renderHook(() =>
+ useDisplaySidePanelFooter({
+ id: 'company-id',
+ targetObjectNameSingular: CoreObjectNameSingular.Company,
+ }),
+ );
+
+ expect(result.current).toBe(true);
+ });
+
+ it('shows the footer for an email thread', () => {
+ mockChannel(MessageChannelType.EMAIL);
+
+ const { result } = renderHook(() =>
+ useDisplaySidePanelFooter(MESSAGE_THREAD),
+ );
+
+ expect(result.current).toBe(true);
+ });
+
+ it('hides the footer for an app chat thread', () => {
+ mockChannel(MessageChannelType.APP);
+
+ const { result } = renderHook(() =>
+ useDisplaySidePanelFooter(MESSAGE_THREAD),
+ );
+
+ expect(result.current).toBe(false);
+ });
+
+ it('hides the footer while the thread channel is loading', () => {
+ mockChannel(null, true);
+
+ const { result } = renderHook(() =>
+ useDisplaySidePanelFooter(MESSAGE_THREAD),
+ );
+
+ expect(result.current).toBe(false);
+ });
+});
diff --git a/packages/twenty-front/src/modules/object-record/record-show/hooks/useDisplaySidePanelFooter.ts b/packages/twenty-front/src/modules/object-record/record-show/hooks/useDisplaySidePanelFooter.ts
new file mode 100644
index 00000000000..a823c0edb2e
--- /dev/null
+++ b/packages/twenty-front/src/modules/object-record/record-show/hooks/useDisplaySidePanelFooter.ts
@@ -0,0 +1,30 @@
+import { useMessageThreadChannel } from '@/activities/emails/hooks/useMessageThreadChannel';
+import { isChatTimelineThreadChannel } from '@/activities/emails/utils/isChatTimelineThreadChannel';
+import { type TargetRecordIdentifier } from '@/ui/layout/contexts/TargetRecordIdentifier';
+import { useWorkspaceSurface } from '@/ui/layout/hooks/useWorkspaceSurface';
+import { CoreObjectNameSingular } from 'twenty-shared/types';
+
+export const useDisplaySidePanelFooter = ({
+ id,
+ targetObjectNameSingular,
+}: TargetRecordIdentifier) => {
+ const isInSidePanel = useWorkspaceSurface().type === 'side-panel';
+ const isMessageThread =
+ targetObjectNameSingular === CoreObjectNameSingular.MessageThread;
+
+ const { messageThreadChannel, messageThreadChannelLoading } =
+ useMessageThreadChannel(id, { skip: !isInSidePanel || !isMessageThread });
+
+ if (!isInSidePanel) {
+ return false;
+ }
+
+ if (!isMessageThread) {
+ return true;
+ }
+
+ return (
+ !messageThreadChannelLoading &&
+ !isChatTimelineThreadChannel(messageThreadChannel)
+ );
+};
diff --git a/packages/twenty-front/src/modules/page-layout/widgets/email-thread/components/ChatThreadWidgetContent.tsx b/packages/twenty-front/src/modules/page-layout/widgets/email-thread/components/ChatThreadWidgetContent.tsx
index 11a0d23226b..4bc6c8e578b 100644
--- a/packages/twenty-front/src/modules/page-layout/widgets/email-thread/components/ChatThreadWidgetContent.tsx
+++ b/packages/twenty-front/src/modules/page-layout/widgets/email-thread/components/ChatThreadWidgetContent.tsx
@@ -1,31 +1,122 @@
import { CustomResolverFetchMoreLoader } from '@/activities/components/CustomResolverFetchMoreLoader';
+import { ChatThreadComposer } from '@/activities/emails/components/ChatThreadComposer';
+import { ChatThreadDisconnectedBanner } from '@/activities/emails/components/ChatThreadDisconnectedBanner';
import { ChatThreadMessages } from '@/activities/emails/components/ChatThreadMessages';
+import { useChatThreadCounterparts } from '@/activities/emails/hooks/useChatThreadCounterparts';
+import { useReplyConnectedAccount } from '@/activities/emails/hooks/useReplyConnectedAccount';
+import { useStickToBottomScroll } from '@/activities/emails/hooks/useStickToBottomScroll';
import { type EmailThreadMessageWithSender } from '@/activities/emails/types/EmailThreadMessageWithSender';
+import { getDisplayNameFromParticipant } from '@/activities/emails/utils/getDisplayNameFromParticipant';
+import { currentWorkspaceMemberState } from '@/auth/states/currentWorkspaceMemberState';
import { WidgetRelationsHeader } from '@/page-layout/widgets/components/WidgetRelationsHeader';
+import { useApplicationsWithPreferences } from '@/settings/app-preferences/hooks/useApplicationsWithPreferences';
+import { isPersonalConnectedAccount } from '@/settings/app-preferences/utils/isPersonalConnectedAccount';
+import { canStartConnectionProviderAuthorization } from '@/settings/applications/utils/canStartConnectionProviderAuthorization';
+import { isApplicationConnectionReconnectNeeded } from '@/settings/applications/utils/isApplicationConnectionReconnectNeeded';
+import { useHasPermissionFlag } from '@/settings/roles/hooks/useHasPermissionFlag';
import {
StyledWidgetContentContainer,
StyledWidgetScrollContainer,
} from '@/ui/layout/components/WidgetContentContainer';
+import { useAtomStateValue } from '@/ui/utilities/state/jotai/hooks/useAtomStateValue';
+import { isNonEmptyString } from '@sniptt/guards';
+import { isDefined } from 'twenty-shared/utils';
+import { PermissionFlagType } from '~/generated-metadata/graphql';
type ChatThreadWidgetContentProps = {
+ messageThreadId: string;
messages: EmailThreadMessageWithSender[];
loading: boolean;
onFetchMoreMessages: () => void;
+ messageChannelId: string | null;
+ onMessageSent: () => Promise<unknown>;
};
export const ChatThreadWidgetContent = ({
+ messageThreadId,
messages,
loading,
onFetchMoreMessages,
-}: ChatThreadWidgetContentProps) => (
- <StyledWidgetContentContainer>
- <WidgetRelationsHeader />
- <StyledWidgetScrollContainer>
- <ChatThreadMessages messages={messages} />
- <CustomResolverFetchMoreLoader
- loading={loading}
- onLastRowVisible={onFetchMoreMessages}
- />
- </StyledWidgetScrollContainer>
- </StyledWidgetContentContainer>
-);
+ messageChannelId,
+ onMessageSent,
+}: ChatThreadWidgetContentProps) => {
+ const { messageChannel, connectedAccount } =
+ useReplyConnectedAccount(messageChannelId);
+ const { applicationsWithPreferences } = useApplicationsWithPreferences();
+ const currentWorkspaceMember = useAtomStateValue(currentWorkspaceMemberState);
+ const hasSendPermission = useHasPermissionFlag(
+ PermissionFlagType.SEND_EMAIL_TOOL,
+ );
+ const counterparts = useChatThreadCounterparts(messages);
+ const firstCounterpart = counterparts?.[0];
+ const { scrollContainerRef, handleScroll } = useStickToBottomScroll(
+ messages.length,
+ );
+
+ const connectionProvider = applicationsWithPreferences
+ .flatMap(({ connectionProviders }) => connectionProviders)
+ .find(({ id }) => id === connectedAccount?.connectionProviderId);
+
+ const isDisconnected =
+ isDefined(connectedAccount) &&
+ isApplicationConnectionReconnectNeeded(connectedAccount);
+
+ const userWorkspaceId = currentWorkspaceMember?.userWorkspaceId;
+
+ const canReconnect =
+ isDefined(connectedAccount) &&
+ isDefined(connectionProvider) &&
+ isNonEmptyString(userWorkspaceId) &&
+ isPersonalConnectedAccount({
+ account: connectedAccount,
+ userWorkspaceId,
+ }) &&
+ canStartConnectionProviderAuthorization(connectionProvider);
+
+ const canChannelSend =
+ isDefined(messageChannel) &&
+ isNonEmptyString(messageChannel.messagingProviderUniversalIdentifier) &&
+ messageChannel.isSyncEnabled;
+
+ return (
+ <StyledWidgetContentContainer>
+ <WidgetRelationsHeader />
+ {isDisconnected &&
+ isDefined(connectionProvider) &&
+ isDefined(connectedAccount.applicationId) && (
+ <ChatThreadDisconnectedBanner
+ applicationId={connectedAccount.applicationId}
+ connectionProviderName={connectionProvider.name}
+ channelName={connectionProvider.displayName}
+ connectedAccountId={connectedAccount.id}
+ canReconnect={canReconnect}
+ />
+ )}
+ <StyledWidgetScrollContainer
+ ref={scrollContainerRef}
+ onScroll={handleScroll}
+ >
+ <ChatThreadMessages messages={messages} />
+ <CustomResolverFetchMoreLoader
+ loading={loading}
+ onLastRowVisible={onFetchMoreMessages}
+ />
+ </StyledWidgetScrollContainer>
+ {hasSendPermission && canChannelSend && isDefined(connectionProvider) && (
+ <ChatThreadComposer
+ key={messageThreadId}
+ messageThreadId={messageThreadId}
+ messageChannelId={messageChannel.id}
+ channelName={connectionProvider.displayName}
+ recipientName={
+ isDefined(firstCounterpart)
+ ? getDisplayNameFromParticipant({ participant: firstCounterpart })
+ : null
+ }
+ isDisconnected={isDisconnected}
+ onMessageSent={onMessageSent}
+ />
+ )}
+ </StyledWidgetContentContainer>
+ );
+};
diff --git a/packages/twenty-front/src/modules/page-layout/widgets/email-thread/components/MessageThreadWidget.tsx b/packages/twenty-front/src/modules/page-layout/widgets/email-thread/components/MessageThreadWidget.tsx
index 93ebd4aa605..f47d5943361 100644
--- a/packages/twenty-front/src/modules/page-layout/widgets/email-thread/components/MessageThreadWidget.tsx
+++ b/packages/twenty-front/src/modules/page-layout/widgets/email-thread/components/MessageThreadWidget.tsx
@@ -25,9 +25,14 @@ export const MessageThreadWidget = ({
}: MessageThreadWidgetProps) => {
const targetRecord = useTargetRecord();
- const { thread, messages, fetchMoreMessages, threadLoading } = useEmailThread(
- targetRecord.id,
- );
+ const {
+ thread,
+ messages,
+ fetchMoreMessages,
+ refetchMessages,
+ threadLoading,
+ lastMessageChannelId,
+ } = useEmailThread(targetRecord.id);
const { messageThreadChannel, messageThreadChannelLoading } =
useMessageThreadChannel(targetRecord.id);
@@ -70,9 +75,12 @@ export const MessageThreadWidget = ({
if (isChatTimelineThreadChannel(messageThreadChannel)) {
return (
<ChatThreadWidgetContent
+ messageThreadId={thread.id}
messages={messages}
loading={threadLoading}
onFetchMoreMessages={fetchMoreMessages}
+ messageChannelId={lastMessageChannelId}
+ onMessageSent={refetchMessages}
/>
);
}
diff --git a/packages/twenty-front/src/modules/settings/accounts/graphql/queries/getMyMessageChannels.ts b/packages/twenty-front/src/modules/settings/accounts/graphql/queries/getMyMessageChannels.ts
index 606ddf93f7f..ab0129e5d0b 100644
--- a/packages/twenty-front/src/modules/settings/accounts/graphql/queries/getMyMessageChannels.ts
+++ b/packages/twenty-front/src/modules/settings/accounts/graphql/queries/getMyMessageChannels.ts
@@ -14,6 +14,7 @@ export const GET_MY_MESSAGE_CHANNELS = gql`
excludeNonProfessionalEmails
excludeGroupEmails
isSyncEnabled
+ messagingProviderUniversalIdentifier
syncStatus
syncStage
syncStageStartedAt
diff --git a/packages/twenty-front/src/modules/settings/app-preferences/utils/isPersonalConnectedAccount.ts b/packages/twenty-front/src/modules/settings/app-preferences/utils/isPersonalConnectedAccount.ts
index 09acc542871..a4fb50a607a 100644
--- a/packages/twenty-front/src/modules/settings/app-preferences/utils/isPersonalConnectedAccount.ts
+++ b/packages/twenty-front/src/modules/settings/app-preferences/utils/isPersonalConnectedAccount.ts
@@ -5,7 +5,9 @@ export const isPersonalConnectedAccount = ({
account,
userWorkspaceId,
}: {
- account: Pick<ConnectedAccount, 'provider' | 'scope' | 'userWorkspaceId'>;
+ account: Pick<ConnectedAccount, 'scope' | 'userWorkspaceId'> & {
+ provider: string;
+ };
userWorkspaceId: string;
}) =>
account.userWorkspaceId === userWorkspaceId &&
diff --git a/packages/twenty-front/src/pages/object-record/RecordShowPageHeader.tsx b/packages/twenty-front/src/pages/object-record/RecordShowPageHeader.tsx
index cec4c76c08f..430af3663b9 100644
--- a/packages/twenty-front/src/pages/object-record/RecordShowPageHeader.tsx
+++ b/packages/twenty-front/src/pages/object-record/RecordShowPageHeader.tsx
@@ -1,3 +1,4 @@
+import { MessageThreadSidePanelTitle } from '@/activities/emails/components/MessageThreadSidePanelTitle';
import { getObjectMetadataIdentifierFields } from '@/object-metadata/utils/getObjectMetadataIdentifierFields';
import { ObjectRecordShowPageBreadcrumb } from '@/object-record/record-show/components/ObjectRecordShowPageBreadcrumb';
import { RecordIdentifierBarTitle } from '@/object-record/record-show/components/RecordIdentifierBarTitle';
@@ -6,6 +7,7 @@ import { type RecordShowPageHeaderTitleMode } from '@/object-record/record-show/
import { useRecordShowPagePagination } from '@/object-record/record-show/hooks/useRecordShowPagePagination';
import { useWorkspaceSurface } from '@/ui/layout/hooks/useWorkspaceSurface';
import { PageCardHeader } from '@/ui/layout/page/components/PageCardHeader';
+import { CoreObjectNameSingular } from 'twenty-shared/types';
type RecordShowPageHeaderProps = {
objectNameSingular: string;
@@ -75,21 +77,34 @@ const RecordShowPagePanelHeader = ({
objectNameSingular,
objectRecordId,
titleAccessory,
-}: RecordShowPagePanelHeaderProps) => (
- <PageCardHeader
- title={
- <>
- <RecordIdentifierBarTitle
- objectNameSingular={objectNameSingular}
- objectRecordId={objectRecordId}
- variant="side-panel"
- recordLinkSurface="main"
- />
- {titleAccessory}
- </>
- }
- />
-);
+}: RecordShowPagePanelHeaderProps) => {
+ const recordTitle = (
+ <RecordIdentifierBarTitle
+ objectNameSingular={objectNameSingular}
+ objectRecordId={objectRecordId}
+ variant="side-panel"
+ recordLinkSurface="main"
+ />
+ );
+
+ return (
+ <PageCardHeader
+ title={
+ <>
+ {objectNameSingular === CoreObjectNameSingular.MessageThread ? (
+ <MessageThreadSidePanelTitle
+ messageThreadId={objectRecordId}
+ emailThreadTitle={recordTitle}
+ />
+ ) : (
+ recordTitle
+ )}
+ {titleAccessory}
+ </>
+ }
+ />
+ );
+};
export const RecordShowPageHeader = ({
objectNameSingular,
diff --git a/packages/twenty-front/src/pages/settings/accounts/__stories__/mockedAccountGroups.ts b/packages/twenty-front/src/pages/settings/accounts/__stories__/mockedAccountGroups.ts
index db5b30ee291..5ff6759dcd7 100644
--- a/packages/twenty-front/src/pages/settings/accounts/__stories__/mockedAccountGroups.ts
+++ b/packages/twenty-front/src/pages/settings/accounts/__stories__/mockedAccountGroups.ts
@@ -83,6 +83,7 @@ const buildMessageChannel = (
excludeNonProfessionalEmails: false,
excludeGroupEmails: false,
isSyncEnabled: true,
+ messagingProviderUniversalIdentifier: null,
syncStatus: 'ACTIVE',
syncStage: 'MESSAGE_LIST_FETCH_PENDING',
syncStageStartedAt: null,