diff --git a/client/src/components/chat-conversation-list/chat-conversation-list.component.jsx b/client/src/components/chat-conversation-list/chat-conversation-list.component.jsx index 3d43a6f78..59d19cb85 100644 --- a/client/src/components/chat-conversation-list/chat-conversation-list.component.jsx +++ b/client/src/components/chat-conversation-list/chat-conversation-list.component.jsx @@ -8,6 +8,7 @@ import { selectSelectedConversation } from "../../redux/messaging/messaging.sele import PhoneFormatter from "../../utils/PhoneFormatter"; import "./chat-conversation-list.styles.scss"; import { useTranslation } from "react-i18next"; +import { TimeAgoFormatter } from "../../utils/DateFormatter"; const mapStateToProps = createStructuredSelector({ selectedConversation: selectSelectedConversation, @@ -60,13 +61,18 @@ export function ChatConversationListComponent({ ) : ( {item.phone_num} )} - {item.job_conversations.length > 0 - ? item.job_conversations.map((j, idx) => ( - - {j.job.ro_number} - - )) - : null} +
+
+ {item.job_conversations.length > 0 + ? item.job_conversations.map((j, idx) => ( + + {j.job.ro_number} + + )) + : null} +
+ {item.updated_at} +
)} diff --git a/client/src/components/chat-messages-list/chat-message-list.component.jsx b/client/src/components/chat-messages-list/chat-message-list.component.jsx index 2780f5441..d6460a89d 100644 --- a/client/src/components/chat-messages-list/chat-message-list.component.jsx +++ b/client/src/components/chat-messages-list/chat-message-list.component.jsx @@ -1,4 +1,5 @@ import Icon from "@ant-design/icons"; +import { Tooltip } from "antd"; import i18n from "i18next"; import moment from "moment"; import React, { useEffect, useRef } from "react"; @@ -9,6 +10,7 @@ import { CellMeasurerCache, List, } from "react-virtualized"; +import { DateTimeFormatter } from "../../utils/DateFormatter"; import "./chat-message-list.styles.scss"; export default function ChatMessageListComponent({ messages }) { @@ -85,17 +87,22 @@ export default function ChatMessageListComponent({ messages }) { const MessageRender = (message) => { return ( -
- {message.image_path && - message.image_path.map((i, idx) => ( -
- - Received - -
- ))} -
{message.text}
-
+ +
+ {message.image_path && + message.image_path.map((i, idx) => ( +
+ + Received + +
+ ))} +
{message.text}
+
+
); }; diff --git a/client/src/graphql/conversations.queries.js b/client/src/graphql/conversations.queries.js index d6b0f4e71..bf54fca29 100644 --- a/client/src/graphql/conversations.queries.js +++ b/client/src/graphql/conversations.queries.js @@ -9,6 +9,7 @@ export const CONVERSATION_LIST_SUBSCRIPTION = gql` ) { phone_num id + updated_at job_conversations { job { id diff --git a/client/src/redux/messaging/messaging.sagas.js b/client/src/redux/messaging/messaging.sagas.js index 40b1f6e53..73e56c37b 100644 --- a/client/src/redux/messaging/messaging.sagas.js +++ b/client/src/redux/messaging/messaging.sagas.js @@ -90,8 +90,6 @@ export function* onSendMessage() { } export function* sendMessage({ payload }) { try { - yield logImEXEvent("messaging_send_message"); - const response = yield call(axios.post, "/sms/send", payload); if (response.status === 200) { yield put(sendMessageSuccess(payload)); diff --git a/hasura/migrations/1632265756746_run_sql_migration/down.yaml b/hasura/migrations/1632265756746_run_sql_migration/down.yaml new file mode 100644 index 000000000..fe51488c7 --- /dev/null +++ b/hasura/migrations/1632265756746_run_sql_migration/down.yaml @@ -0,0 +1 @@ +[] diff --git a/hasura/migrations/1632265756746_run_sql_migration/up.yaml b/hasura/migrations/1632265756746_run_sql_migration/up.yaml new file mode 100644 index 000000000..c752d0996 --- /dev/null +++ b/hasura/migrations/1632265756746_run_sql_migration/up.yaml @@ -0,0 +1,15 @@ +- type: run_sql + args: + cascade: false + read_only: false + sql: |- + CREATE OR REPLACE FUNCTION public.update_conversation_on_message() + RETURNS trigger + LANGUAGE plpgsql + AS $function$ + BEGIN + UPDATE conversations SET updated_at = now() WHERE id = NEW.conversationid; + RETURN NEW; + END; + $function$ + ; diff --git a/hasura/migrations/1632265816135_run_sql_migration/down.yaml b/hasura/migrations/1632265816135_run_sql_migration/down.yaml new file mode 100644 index 000000000..fe51488c7 --- /dev/null +++ b/hasura/migrations/1632265816135_run_sql_migration/down.yaml @@ -0,0 +1 @@ +[] diff --git a/hasura/migrations/1632265816135_run_sql_migration/up.yaml b/hasura/migrations/1632265816135_run_sql_migration/up.yaml new file mode 100644 index 000000000..98acb3742 --- /dev/null +++ b/hasura/migrations/1632265816135_run_sql_migration/up.yaml @@ -0,0 +1,15 @@ +- type: run_sql + args: + cascade: false + read_only: false + sql: |- + CREATE OR REPLACE FUNCTION public.update_conversation_on_message() + RETURNS trigger + LANGUAGE plpgsql + AS $function$ + BEGIN + UPDATE conversations SET updated_at = now() WHERE conversations.id = NEW.conversationid; + RETURN NEW; + END; + $function$ + ; diff --git a/server/graphql-client/queries.js b/server/graphql-client/queries.js index a66ed3fdb..df1397caa 100644 --- a/server/graphql-client/queries.js +++ b/server/graphql-client/queries.js @@ -12,14 +12,24 @@ query FIND_BODYSHOP_BY_MESSAGING_SERVICE_SID( } `; -exports.INSERT_MESSAGE = ` -mutation INSERT_MESSAGE($msg: [messages_insert_input!]!, $conversationid: uuid) { - update_conversations(where: {id: {_eq: $conversationid}}, _set: {archived: false}) { - affected_rows +exports.UNARCHIVE_CONVERSATION = ` +mutation UNARCHIVE_CONVERSATION($id: uuid!) { + update_conversations_by_pk(pk_columns: {id: $id}, _set: {archived: false}) { + id } - insert_messages(objects: $msg) { +} +`; + +exports.INSERT_MESSAGE = ` +mutation INSERT_MESSAGE($msg: [messages_insert_input!]!, $conversationid: uuid!) { + update_conversations_by_pk(pk_columns: {id: $conversationid}, _set: {archived: false}) { + id + } + insert_messages(objects: $msg) { returning { conversation { + id + archived bodyshop { associations(where: {active: {_eq: true}}) { user { diff --git a/server/sms/send.js b/server/sms/send.js index bad13ce9f..f19a51dfd 100644 --- a/server/sms/send.js +++ b/server/sms/send.js @@ -55,7 +55,7 @@ exports.send = (req, res) => { : [], }; gqlClient - .request(queries.INSERT_MESSAGE, { msg: newMessage }) + .request(queries.INSERT_MESSAGE, { msg: newMessage, conversationid }) .then((r2) => { //console.log("Responding GQL Message ID", JSON.stringify(r2)); logger.log("sms-outbound-success", "DEBUG", req.user.email, null, {