Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve chat history #1085

Merged
merged 1 commit into from
Dec 17, 2024
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
-- liquibase formatted sql
-- changeset Janno Stern:20241210105636
ALTER TABLE chat_history_comments
ADD COLUMN IF NOT EXISTS created TIMESTAMP WITH TIME ZONE;

-- Update existing rows with a default timestamp (e.g., the current time or a specific value)
UPDATE chat_history_comments
SET created = NOW()
WHERE created IS NULL;
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
-- liquibase formatted sql
-- changeset Janno Stern:20241211105438
ALTER TABLE chat_history_comments
ADD COLUMN author_display_name TEXT;
2 changes: 1 addition & 1 deletion DSL/Resql/get-chat-history-comment-by-id.sql
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
SELECT id, chat_id, comment
SELECT id, chat_id, comment, created, author_display_name
FROM chat_history_comments
WHERE chat_id = :chatId
ORDER BY id DESC
Expand Down
31 changes: 23 additions & 8 deletions DSL/Resql/get-cs-all-ended-chats.sql
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,23 @@ WITH MaxChatHistoryComments AS (
FROM chat_history_comments
GROUP BY chat_id
),
ChatUser AS (
SELECT DISTINCT ON (id_code)
id_code,
display_name,
first_name,
last_name
FROM "user"
ORDER BY id_code, id DESC
),
ChatHistoryComments AS (
SELECT comment, chat_id
SELECT
comment,
chat_id,
created,
author_display_name
FROM chat_history_comments
JOIN MaxChatHistoryComments ON id = maxId
JOIN MaxChatHistoryComments ON id = maxId
),
MessageWithContent AS (
SELECT
Expand Down Expand Up @@ -52,7 +65,7 @@ FROM message
GROUP BY chat_base_id
),
Messages AS (
SELECT event, updated, chat_base_id
SELECT event, updated, chat_base_id, author_id
FROM message
JOIN MaxMessages ON id = maxID
),
Expand Down Expand Up @@ -129,6 +142,11 @@ SELECT c.base_id AS id,
c.received_from,
c.labels,
s.comment,
s.created as comment_added_date,
s.author_display_name as comment_author,
mu.display_name AS user_display_name,
cu.first_name AS customer_support_first_name,
cu.last_name AS customer_support_last_name,
LastContentMessage.content AS last_message,
(CASE WHEN m.event = '' THEN NULL ELSE LOWER(m.event) END) AS last_message_event,
ContactsMessage.content AS contacts_message,
Expand All @@ -140,16 +158,14 @@ SELECT c.base_id AS id,
FROM EndedChatMessages AS c
JOIN Messages AS m ON c.base_id = m.chat_base_id
LEFT JOIN ChatHistoryComments AS s ON s.chat_id = m.chat_base_id
LEFT JOIN ChatUser AS mu ON mu.id_code = m.author_id
LEFT JOIN ChatUser AS cu ON cu.id_code = c.customer_support_id
JOIN LastContentMessage ON c.base_id = LastContentMessage.chat_base_id
JOIN FirstContentMessage ON c.base_id = FirstContentMessage.chat_base_id
LEFT JOIN ContactsMessage ON ContactsMessage.chat_base_id = c.base_id
CROSS JOIN TitleVisibility
CROSS JOIN NPS
WHERE (
(
LENGTH(:customerSupportIds) = 0 OR
c.customer_support_id = ANY(string_to_array(:customerSupportIds, ','))
) AND (
:search IS NULL OR
:search = '' OR
LOWER(c.customer_support_display_name) LIKE LOWER('%' || :search || '%') OR
Expand All @@ -168,7 +184,6 @@ WHERE (
AND LOWER(msg.content) LIKE LOWER('%' || :search || '%')
)
)
)
ORDER BY
CASE WHEN :sorting = 'created asc' THEN FirstContentMessage.created END ASC,
CASE WHEN :sorting = 'created desc' THEN FirstContentMessage.created END DESC,
Expand Down
6 changes: 3 additions & 3 deletions DSL/Resql/insert-chat-history-comment.sql
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
INSERT INTO "chat_history_comments" (chat_id, comment)
VALUES (:chatId, :comment)
RETURNING id, chat_id, comment;
INSERT INTO "chat_history_comments" (chat_id, comment, created, author_display_name)
VALUES (:chatId, :comment, :created::timestamp with time zone, :authorDisplayName)
RETURNING id, chat_id, comment, created, author_display_name;
6 changes: 6 additions & 0 deletions DSL/Ruuter.private/DSL/POST/comments/history.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,15 @@ declaration:
- field: comment
type: string
description: "Body field 'comment'"
- field: authorDisplayName
type: string
description: "Body field 'authorDisplayName'"

extractRequestData:
assign:
comment: ${incoming.body.comment}
chatId: ${incoming.body.chatId}
authorDisplayName: ${incoming.body.authorDisplayName}

setChatComment:
call: http.post
Expand All @@ -27,6 +31,8 @@ setChatComment:
body:
comment: ${comment}
chatId: ${chatId}
created: "${new Date().toISOString()}"
authorDisplayName: ${authorDisplayName}
result: res

return_result:
Expand Down
23 changes: 20 additions & 3 deletions GUI/src/pages/Chat/ChatHistory/History.scss
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
@import 'src/styles/tools/spacing';
@import 'src/styles/tools/color';
@import 'src/styles/settings/variables/typography';

.card-drawer-container {
display: flex;
width: 100%;
Expand All @@ -12,15 +16,28 @@
}

.drawer-container {
width: 700px;
flex: 1;
height: 100%;
flex-shrink: 0;
overflow-y: auto;
box-shadow: -2px 0 5px rgba(0, 0, 0, 0.1);
border: 1px solid get-color(black-coral-2);
}

.drawer-container > * {
position: static !important;
width: 100%;
height: 100%;
}
}

.side-meta {
background-color: get-color(white);
border: 1px solid get-color(black-coral-2);
color: get-color(black-coral-12);
display: flex;
flex: 0 0 288px;
flex-direction: column;
font-size: $veera-font-size-80;
gap: 4px;
overflow-y: auto;
padding: get-spacing(haapsalu);
}
Loading