Skip to content

Commit

Permalink
feat: Delete all chats close #483
Browse files Browse the repository at this point in the history
  • Loading branch information
icleitoncosta committed Jul 12, 2022
1 parent 3016f2f commit f47a253
Show file tree
Hide file tree
Showing 3 changed files with 131 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/controller/deviceController.js
Expand Up @@ -233,6 +233,18 @@ export async function deleteChat(req, res) {
returnError(req, res, session, error);
}
}
export async function deleteAllChats(req, res) {
try {
const chats = await req.client.getAllChats();
for (const chat of chats) {
await req.client.deleteChat(chat.chatId);
}
return res.status(200).json({ status: 'success' });
} catch (error) {
req.logger.error(error);
return res.status(500).json({ status: 'error', message: 'Error on delete all chats' });
}
}

export async function clearChat(req, res) {
const { phone } = req.body;
Expand Down
2 changes: 2 additions & 0 deletions src/routes/index.js
Expand Up @@ -163,8 +163,10 @@ routes.get(
routes.get('/api/:session/get-messages/:phone', verifyToken, statusConnection, DeviceController.getMessages);

routes.post('/api/:session/archive-chat', verifyToken, statusConnection, DeviceController.archiveChat);
routes.post('/api/:session/archive-all-chats', verifyToken, statusConnection, DeviceController.archiveAllChats);
routes.post('/api/:session/clear-chat', verifyToken, statusConnection, DeviceController.clearChat);
routes.post('/api/:session/delete-chat', verifyToken, statusConnection, DeviceController.deleteChat);
routes.post('/api/:session/delete-all-chats', verifyToken, statusConnection, DeviceController.deleteAllChats);
routes.post('/api/:session/delete-message', verifyToken, statusConnection, DeviceController.deleteMessage);
routes.post('/api/:session/forward-messages', verifyToken, statusConnection, DeviceController.forwardMessages);
routes.post('/api/:session/mark-unseen', verifyToken, statusConnection, DeviceController.markUnseenMessage);
Expand Down
117 changes: 117 additions & 0 deletions src/swagger.json
Expand Up @@ -3954,6 +3954,116 @@
"deprecated": false
}
},
"/delete-all-chats": {
"post": {
"tags": ["Chat"],
"summary": "Delete all Chat",
"description": "Deletes all chats",
"operationId": "DeleteAllChats",
"parameters": [],
"requestBody": {
"description": "",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/DeleteAllChatsRequest"
},
"example": {}
}
},
"required": true
},
"responses": {
"200": {
"description": "OK",
"headers": {
"X-Powered-By": {
"content": {
"text/plain": {
"schema": {
"type": "string"
},
"example": "Express"
}
}
},
"Access-Control-Allow-Origin": {
"content": {
"text/plain": {
"schema": {
"type": "string"
},
"example": "*"
}
}
},
"Content-Length": {
"content": {
"text/plain": {
"schema": {
"type": "string"
},
"example": "63"
}
}
},
"ETag": {
"content": {
"text/plain": {
"schema": {
"type": "string"
},
"example": "W/\"3f-q668acKEQBOoHvDmmrr2pSlP/zk\""
}
}
},
"Date": {
"content": {
"text/plain": {
"schema": {
"type": "string"
},
"example": "Thu, 13 May 2021 19:26:37 GMT"
}
}
},
"Connection": {
"content": {
"text/plain": {
"schema": {
"type": "string"
},
"example": "keep-alive"
}
}
},
"Keep-Alive": {
"content": {
"text/plain": {
"schema": {
"type": "string"
},
"example": "timeout=5"
}
}
}
},
"content": {
"application/json; charset=utf-8": {
"schema": {
"$ref": "#/components/schemas/DeleteChat"
},
"example": {
"status": "Success",
"message": "Conversas deleteadas com sucesso"
}
}
}
}
},
"deprecated": false
}
},
"/delete-message": {
"post": {
"tags": ["Chat"],
Expand Down Expand Up @@ -14847,6 +14957,13 @@
"phone": "556593077171"
}
},
"DeleteAllChatsRequest": {
"title": "DeleteAllChatsRequest",
"required": [""],
"type": "object",
"properties": {},
"example": {}
},
"DeleteChat": {
"title": "DeleteChat",
"required": ["status", "message"],
Expand Down

0 comments on commit f47a253

Please sign in to comment.