3441 modify message table change date to receivedat (#3452)

* changed date to receivedAt

* update saving messages

* update custom resolver
This commit is contained in:
bosiraphael
2024-01-15 14:48:25 +01:00
committed by GitHub
parent ed6458e833
commit 8682f3c0c0
3 changed files with 15 additions and 15 deletions

View File

@ -27,19 +27,19 @@ export class TimelineMessagingService {
message_count,
last_message_subject,
last_message_body,
last_message_date,
last_message_received_at,
last_message_recipient_handle,
last_message_recipient_displayName
FROM (
SELECT
mt.*,
COUNT(m."id") OVER (PARTITION BY mt."id") AS message_count,
FIRST_VALUE(m."subject") OVER (PARTITION BY mt."id" ORDER BY m."date" DESC) AS last_message_subject,
FIRST_VALUE(m."body") OVER (PARTITION BY mt."id" ORDER BY m."date" DESC) AS last_message_body,
FIRST_VALUE(m."date") OVER (PARTITION BY mt."id" ORDER BY m."date" DESC) AS last_message_date,
FIRST_VALUE(mr."handle") OVER (PARTITION BY mt."id" ORDER BY m."date" DESC) AS last_message_recipient_handle,
FIRST_VALUE(mr."displayName") OVER (PARTITION BY mt."id" ORDER BY m."date" DESC) AS last_message_recipient_displayName,
ROW_NUMBER() OVER (PARTITION BY mt."id" ORDER BY m."date" DESC) AS rn
FIRST_VALUE(m."subject") OVER (PARTITION BY mt."id" ORDER BY m."receivedAt" DESC) AS last_message_subject,
FIRST_VALUE(m."body") OVER (PARTITION BY mt."id" ORDER BY m."receivedAt" DESC) AS last_message_body,
FIRST_VALUE(m."receivedAt") OVER (PARTITION BY mt."id" ORDER BY m."receivedAt" DESC) AS last_message_received_at,
FIRST_VALUE(mr."handle") OVER (PARTITION BY mt."id" ORDER BY m."receivedAt" DESC) AS last_message_recipient_handle,
FIRST_VALUE(mr."displayName") OVER (PARTITION BY mt."id" ORDER BY m."receivedAt" DESC) AS last_message_recipient_displayName,
ROW_NUMBER() OVER (PARTITION BY mt."id" ORDER BY m."receivedAt" DESC) AS rn
FROM
${dataSourceMetadata.schema}."messageThread" mt
LEFT JOIN
@ -52,7 +52,7 @@ export class TimelineMessagingService {
WHERE
subquery.rn = 1
ORDER BY
subquery.last_message_date DESC
subquery.last_message_received_at DESC
LIMIT 10;
`,
[personIds],
@ -66,7 +66,7 @@ export class TimelineMessagingService {
numberOfMessagesInThread: messageThread.message_count,
subject: messageThread.last_message_subject,
body: messageThread.last_message_body,
receivedAt: messageThread.last_message_date,
receivedAt: messageThread.last_message_received_at,
};
});

View File

@ -83,7 +83,7 @@ export class MessagingUtilsService {
text,
} = message;
const date = new Date(parseInt(internalDate));
const receivedAt = new Date(parseInt(internalDate));
const messageThread = await workspaceDataSource?.query(
`SELECT * FROM ${dataSourceMetadata.schema}."messageThread" WHERE "externalId" = $1`,
@ -113,13 +113,13 @@ export class MessagingUtilsService {
await workspaceDataSource?.transaction(async (manager) => {
await manager.query(
`INSERT INTO ${dataSourceMetadata.schema}."message" ("id", "externalId", "headerMessageId", "subject", "date", "messageThreadId", "direction", "body") VALUES ($1, $2, $3, $4, $5, $6, $7, $8)`,
`INSERT INTO ${dataSourceMetadata.schema}."message" ("id", "externalId", "headerMessageId", "subject", "receivedAt", "messageThreadId", "direction", "body") VALUES ($1, $2, $3, $4, $5, $6, $7, $8)`,
[
messageId,
externalId,
headerMessageId,
subject,
date,
receivedAt,
messageThread[0]?.id,
messageDirection,
text,

View File

@ -81,12 +81,12 @@ export class MessageObjectMetadata extends BaseObjectMetadata {
@FieldMetadata({
type: FieldMetadataType.DATE_TIME,
label: 'Date',
description: 'Date',
label: 'Received At',
description: 'The date the message was received',
icon: 'IconCalendar',
})
@IsNullable()
date: string;
receivedAt: string;
@FieldMetadata({
type: FieldMetadataType.RELATION,