IO-1365 Update Messaging Issues.

This commit is contained in:
Patrick Fic
2021-09-21 17:33:39 -07:00
parent c64c49ab6e
commit 186ad2d7a2
10 changed files with 80 additions and 26 deletions

View File

@@ -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({
) : (
<PhoneFormatter>{item.phone_num}</PhoneFormatter>
)}
{item.job_conversations.length > 0
? item.job_conversations.map((j, idx) => (
<Tag key={idx} className="ro-number-tag">
{j.job.ro_number}
</Tag>
))
: null}
<div sryle={{ display: "inline-block" }}>
<div>
{item.job_conversations.length > 0
? item.job_conversations.map((j, idx) => (
<Tag key={idx} className="ro-number-tag">
{j.job.ro_number}
</Tag>
))
: null}
</div>
<TimeAgoFormatter>{item.updated_at}</TimeAgoFormatter>
</div>
<Badge count={item.messages_aggregate.aggregate.count || 0} />
</List.Item>
)}

View File

@@ -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 (
<div>
{message.image_path &&
message.image_path.map((i, idx) => (
<div key={idx} style={{ display: "flex", justifyContent: "center" }}>
<a href={i} target="__blank">
<img alt="Received" className="message-img" src={i} />
</a>
</div>
))}
<div>{message.text}</div>
</div>
<Tooltip title={DateTimeFormatter({ children: message.created_at })}>
<div>
{message.image_path &&
message.image_path.map((i, idx) => (
<div
key={idx}
style={{ display: "flex", justifyContent: "center" }}
>
<a href={i} target="__blank">
<img alt="Received" className="message-img" src={i} />
</a>
</div>
))}
<div>{message.text}</div>
</div>
</Tooltip>
);
};

View File

@@ -9,6 +9,7 @@ export const CONVERSATION_LIST_SUBSCRIPTION = gql`
) {
phone_num
id
updated_at
job_conversations {
job {
id

View File

@@ -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));

View File

@@ -0,0 +1 @@
[]

View File

@@ -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$
;

View File

@@ -0,0 +1 @@
[]

View File

@@ -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$
;

View File

@@ -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 {

View File

@@ -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, {