Skip to content

Commit

Permalink
Exibição da Msg Apaga pelo cliente
Browse files Browse the repository at this point in the history
  • Loading branch information
rtenorioh committed Mar 5, 2023
1 parent bfc403f commit 491c42f
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 22 deletions.
61 changes: 60 additions & 1 deletion backend/src/services/WbotServices/wbotMessageListener.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/* eslint-disable no-plusplus */
/* eslint-disable no-nested-ternary */
import { join } from "path";
import { promisify } from "util";
import { writeFile } from "fs";
Expand Down Expand Up @@ -64,6 +66,52 @@ const verifyQuotedMessage = async (
return quotedMsg;
};

const verifyRevoked = async (msgBody: string | undefined): Promise<void> => {
await new Promise(r => setTimeout(r, 500));

const io = getIO();

try {
const message = await Message.findOne({
where: {
body: msgBody
}
});

if (!message) {
return;
}

if (message) {
// console.log(message);
await Message.update(
{ isDeleted: true },
{
where: { id: message.id }
}
);

const msgIsDeleted = await Message.findOne({
where: {
body: msgBody
}
});

if (!msgIsDeleted) {
return;
}

io.to(msgIsDeleted.ticketId.toString()).emit("appMessage", {
action: "update",
message: msgIsDeleted
});
}
} catch (err) {
Sentry.captureException(err);
logger.error(`Error Message Revoke. Err: ${err}`);
}
};

const verifyMediaMessage = async (
msg: WbotMessage,
ticket: Ticket,
Expand Down Expand Up @@ -406,6 +454,7 @@ const handleMessage = async (
try {
const array = msg.body.split("\n");
const obj = [];
// eslint-disable-next-line no-shadow
let contact = "";
for (let index = 0; index < array.length; index++) {
const v = array[index];
Expand All @@ -419,7 +468,9 @@ const handleMessage = async (
}
}
}
// eslint-disable-next-line no-restricted-syntax
for await (const ob of obj) {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const cont = await CreateContactService({
name: contact,
number: ob.number.replace(/\D/g, "")
Expand Down Expand Up @@ -491,6 +542,7 @@ const handleMessage = async (
}
} */

// eslint-disable-next-line block-scoped-var
if (msg.type === "call_log" && callSetting === "disabled") {
const sentMessage = await wbot.sendMessage(
`${contact.number}@c.us`,
Expand All @@ -504,6 +556,7 @@ const handleMessage = async (
}
};

// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
const handleMsgAck = async (msg: WbotMessage, ack: MessageAck) => {
await new Promise(r => setTimeout(r, 500));

Expand All @@ -520,6 +573,7 @@ const handleMsgAck = async (msg: WbotMessage, ack: MessageAck) => {
}
]
});

if (!messageToUpdate) {
return;
}
Expand All @@ -535,7 +589,7 @@ const handleMsgAck = async (msg: WbotMessage, ack: MessageAck) => {
}
};

const wbotMessageListener = (wbot: Session): void => {
const wbotMessageListener = async (wbot: Session): Promise<void> => {
wbot.on("message_create", async msg => {
handleMessage(msg, wbot);
});
Expand All @@ -547,6 +601,11 @@ const wbotMessageListener = (wbot: Session): void => {
wbot.on("message_ack", async (msg, ack) => {
handleMsgAck(msg, ack);
});

wbot.on("message_revoke_everyone", async (after, before) => {
const msgBody = before?.body;
verifyRevoked(msgBody);
});
};

export { wbotMessageListener, handleMessage, handleMsgAck };
34 changes: 13 additions & 21 deletions frontend/src/components/MessagesList/index.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import React, { useState, useEffect, useReducer, useRef } from "react";

import {
isSameDay,
parseISO,
format
} from "date-fns";
import openSocket from "../../services/socket-io";
import clsx from "clsx";

import { blue } from "@material-ui/core/colors";
import {
blue,
red
} from "@material-ui/core/colors";
import {
Button,
CircularProgress,
Expand Down Expand Up @@ -252,6 +253,11 @@ const useStyles = makeStyles((theme) => ({
fontSize: 18,
verticalAlign: "middle",
marginRight: 4,
color: red[200]
},

deletedMsg: {
color: red[200]
},

ackDoneAllIcon: {
Expand Down Expand Up @@ -327,14 +333,14 @@ const reducer = (state, action) => {

if (action.type === "UPDATE_MESSAGE") {
const messageToUpdate = action.payload;

const messageIndex = state.findIndex((m) => m.id === messageToUpdate.id);

if (messageToUpdate.isDeleted === true) {
//toast.info(`Mensagem apagada: ${messageToUpdate.body} `,{autoClose: false});
toast.info(<ToastDisplay
body={messageToUpdate.body}
>
</ToastDisplay>, { autoClose: false });
</ToastDisplay>);
}

if (messageIndex !== -1) {
Expand Down Expand Up @@ -742,27 +748,13 @@ const MessagesList = ({ ticketId, isGroup }) => {
{message.isDeleted && (

<div>
<span className={"message-deleted"}


>Mensagem apagada pelo contato


<Block
color=""
fontSize="small"
className={classes.deletedIcon}
/>
<Block
color=""
fontSize="small"
className={classes.deletedIcon}
/>
<span className={classes.deletedMsg}>
<Block
color=""
fontSize="small"
className={classes.deletedIcon}
/>
Mensagem apagada
</span>
</div>

Expand Down

0 comments on commit 491c42f

Please sign in to comment.