From 84e6fe112d1f7f6a67136dd3cd062ca0f0c96674 Mon Sep 17 00:00:00 2001 From: canove Date: Tue, 12 Jan 2021 08:43:36 -0300 Subject: [PATCH 1/9] improvement: remove await from "sent seen" method before sending messages. --- backend/src/controllers/MessageController.ts | 2 +- backend/src/services/WbotServices/wbotMessageListener.ts | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/backend/src/controllers/MessageController.ts b/backend/src/controllers/MessageController.ts index a381676..a4e59f4 100644 --- a/backend/src/controllers/MessageController.ts +++ b/backend/src/controllers/MessageController.ts @@ -42,7 +42,7 @@ export const store = async (req: Request, res: Response): Promise => { const ticket = await ShowTicketService(ticketId); - await SetTicketMessagesAsRead(ticket); + SetTicketMessagesAsRead(ticket); if (medias) { await Promise.all( diff --git a/backend/src/services/WbotServices/wbotMessageListener.ts b/backend/src/services/WbotServices/wbotMessageListener.ts index ac687e4..4b03abb 100644 --- a/backend/src/services/WbotServices/wbotMessageListener.ts +++ b/backend/src/services/WbotServices/wbotMessageListener.ts @@ -182,11 +182,13 @@ const handleMessage = async ( groupContact = await verifyContact(msgGroupContact); } + const unreadMessages = msg.fromMe ? 0 : chat.unreadCount; + const contact = await verifyContact(msgContact); const ticket = await FindOrCreateTicketService( contact, wbot.id!, - chat.unreadCount, + unreadMessages, groupContact ); From 09b0c8e1f7de69f44b298d5a9d53165cea5abb7b Mon Sep 17 00:00:00 2001 From: canove Date: Tue, 12 Jan 2021 10:51:37 -0300 Subject: [PATCH 2/9] chore: updated dependencies --- backend/package.json | 8 ++++---- frontend/package.json | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/backend/package.json b/backend/package.json index 8d2f9d8..ffa20a3 100644 --- a/backend/package.json +++ b/backend/package.json @@ -15,7 +15,7 @@ "author": "", "license": "MIT", "dependencies": { - "@sentry/node": "5.27.0", + "@sentry/node": "^5.29.2", "@types/pino": "^6.3.4", "bcryptjs": "^2.4.3", "cookie-parser": "^1.4.5", @@ -36,9 +36,9 @@ "sequelize": "^5.22.3", "sequelize-cli": "^5.5.1", "sequelize-typescript": "^1.1.0", - "socket.io": "^2.3.0", - "whatsapp-web.js": "1.11.1", - "yup": "^0.29.3" + "socket.io": "^3.0.5", + "whatsapp-web.js": "^1.12.0", + "yup": "^0.32.8" }, "devDependencies": { "@types/bcryptjs": "^2.4.2", diff --git a/frontend/package.json b/frontend/package.json index 078c767..3725edd 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -24,10 +24,10 @@ "react-router-dom": "^5.2.0", "react-scripts": "3.4.3", "react-toastify": "^6.0.9", - "recharts": "^1.8.5", - "socket.io-client": "^2.3.1", - "use-sound": "^1.0.2", - "yup": "^0.29.3" + "recharts": "^2.0.2", + "socket.io-client": "^3.0.5", + "use-sound": "^2.0.1", + "yup": "^0.32.8" }, "scripts": { "start": "react-scripts start", From 2f7aeb738e7f6bb349b66d4082d956b8bdb2bda9 Mon Sep 17 00:00:00 2001 From: canove Date: Tue, 12 Jan 2021 10:51:52 -0300 Subject: [PATCH 3/9] fix: handle CORS in socket.io --- backend/src/libs/socket.ts | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/backend/src/libs/socket.ts b/backend/src/libs/socket.ts index d7eff50..7169e23 100644 --- a/backend/src/libs/socket.ts +++ b/backend/src/libs/socket.ts @@ -1,4 +1,4 @@ -import socketIo, { Server as SocketIO } from "socket.io"; +import { Server as SocketIO } from "socket.io"; import { Server } from "http"; import AppError from "../errors/AppError"; import { logger } from "../utils/logger"; @@ -6,11 +6,15 @@ import { logger } from "../utils/logger"; let io: SocketIO; export const initIO = (httpServer: Server): SocketIO => { - io = socketIo(httpServer); + io = new SocketIO(httpServer, { + cors: { + origin: process.env.FRONTEND_URL + } + }); io.on("connection", socket => { logger.info("Client Connected"); - socket.on("joinChatBox", ticketId => { + socket.on("joinChatBox", (ticketId: string) => { logger.info("A client joined a ticket channel"); socket.join(ticketId); }); @@ -20,7 +24,7 @@ export const initIO = (httpServer: Server): SocketIO => { socket.join("notification"); }); - socket.on("joinTickets", status => { + socket.on("joinTickets", (status: string) => { logger.info(`A client joined to ${status} tickets channel.`); socket.join(status); }); @@ -31,6 +35,7 @@ export const initIO = (httpServer: Server): SocketIO => { }); return io; }; + export const getIO = (): SocketIO => { if (!io) { throw new AppError("Socket IO not initialized"); From cda722161157cd402671cab03a5a4bd65b68c95e Mon Sep 17 00:00:00 2001 From: canove Date: Tue, 12 Jan 2021 14:06:31 -0300 Subject: [PATCH 4/9] chore: remove await for sendSeen method when listing messages --- backend/src/controllers/MessageController.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/src/controllers/MessageController.ts b/backend/src/controllers/MessageController.ts index a4e59f4..21f90aa 100644 --- a/backend/src/controllers/MessageController.ts +++ b/backend/src/controllers/MessageController.ts @@ -30,7 +30,7 @@ export const index = async (req: Request, res: Response): Promise => { ticketId }); - await SetTicketMessagesAsRead(ticket); + SetTicketMessagesAsRead(ticket); return res.json({ count, messages, ticket, hasMore }); }; From c775b7c72dadd0354d3d955b05e027b23cd945d1 Mon Sep 17 00:00:00 2001 From: canove Date: Tue, 12 Jan 2021 14:10:59 -0300 Subject: [PATCH 5/9] chore: update README --- README.md | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 23b9ab3..86bcd75 100644 --- a/README.md +++ b/README.md @@ -368,13 +368,15 @@ sudo service nginx restart Now, enable SSL (https) on your sites to use all app features like notifications and sending audio messages. A easy way to this is using Certbot: -Install certbor with snapd: +Install certbot: ```bash -sudo snap install --classic certbot +sudo add-apt-repository ppa:certbot/certbot +sudo apt update +sudo apt install python-certbot-nginx ``` -Enable SSL on nginx (Accept all information asked): +Enable SSL on nginx (Fill / Accept all information asked): ```bash sudo certbot --nginx @@ -428,12 +430,11 @@ This project helps you and you want to help keep it going? Buy me a coffee: Para doações em BRL, você pode doar utilizando o Paypal:
- - - + +
Any help and suggestions are welcome! From 053fc85f76821293b97ade2d8f2502f74b314eca Mon Sep 17 00:00:00 2001 From: canove Date: Tue, 12 Jan 2021 16:54:45 -0300 Subject: [PATCH 6/9] update README --- README.md | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 86bcd75..a405942 100644 --- a/README.md +++ b/README.md @@ -425,19 +425,15 @@ chmod +x updateWhaticket This project helps you and you want to help keep it going? Buy me a coffee: -Buy Me A Coffee +Buy Me A Coffee -Para doações em BRL, você pode doar utilizando o Paypal: +Para doações em BRL, utilize o Paypal: -
- - - - - -
+ + Donate with PayPal + -Any help and suggestions are welcome! +Any help and suggestions will be apreciated. ## Disclaimer From 0b01740da83bd4605492e4e45635c862932d679f Mon Sep 17 00:00:00 2001 From: canove Date: Tue, 12 Jan 2021 16:58:35 -0300 Subject: [PATCH 7/9] update README --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index a405942..5b035ff 100644 --- a/README.md +++ b/README.md @@ -430,7 +430,7 @@ This project helps you and you want to help keep it going? Buy me a coffee: Para doações em BRL, utilize o Paypal: - Donate with PayPal + Donate with PayPal Any help and suggestions will be apreciated. From a9cfb1311f8be81b329a569a2c2da54c9f0e7e22 Mon Sep 17 00:00:00 2001 From: canove Date: Tue, 12 Jan 2021 17:00:52 -0300 Subject: [PATCH 8/9] update README --- README.md | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 5b035ff..afb84a3 100644 --- a/README.md +++ b/README.md @@ -425,12 +425,15 @@ chmod +x updateWhaticket This project helps you and you want to help keep it going? Buy me a coffee: -Buy Me A Coffee +Buy Me A Coffee Para doações em BRL, utilize o Paypal: - Donate with PayPal +
+ Donate with PayPal +
+
Any help and suggestions will be apreciated. From 6571b5457a4e553614e6c851fd95ed17e4f1730c Mon Sep 17 00:00:00 2001 From: canove Date: Tue, 12 Jan 2021 17:02:52 -0300 Subject: [PATCH 9/9] update README --- README.md | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/README.md b/README.md index afb84a3..35dd20b 100644 --- a/README.md +++ b/README.md @@ -429,12 +429,7 @@ This project helps you and you want to help keep it going? Buy me a coffee: Para doações em BRL, utilize o Paypal: - -
- Donate with PayPal -
- -
+[![Donate](https://img.shields.io/badge/Donate-PayPal-green.svg)](https://www.paypal.com/donate?business=VWW3BHW4AWHUY&item_name=Desenvolvimento+de+Software¤cy_code=BRL) Any help and suggestions will be apreciated.