Skip to content

Commit 108753d

Browse files
committed
fix remove session in ui
1 parent bbfce07 commit 108753d

File tree

5 files changed

+31
-28
lines changed

5 files changed

+31
-28
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "unoapi-cloud",
3-
"version": "1.25.0",
3+
"version": "1.25.1",
44
"description": "Unoapi Cloud",
55
"exports": "./dist/index.js",
66
"types": "./dist/index.d.ts",

public/index.html

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -474,7 +474,11 @@ <h5 class="modal-title" id="connectModalLabel">Conectar Sessão</h5>
474474
}
475475
});
476476
}
477+
getSessionAndpopulateTable(token, hideForm)
478+
}
477479

480+
// Populate Datatable with session numbers
481+
function getSessionAndpopulateTable(token, hideForm) {
478482
const headers = { Authorization: `Bearer ${token}` };
479483

480484
fetch(apiUrl + '/sessions', { headers })
@@ -483,7 +487,6 @@ <h5 class="modal-title" id="connectModalLabel">Conectar Sessão</h5>
483487
return response.json();
484488
})
485489
.then(resp => {
486-
localStorage.setItem(tokenKey, token);
487490
if (hideForm) {
488491
$('#navbarDropdown').removeClass('d-none');
489492
$('#login').addClass('d-none');
@@ -537,10 +540,9 @@ <h5 class="modal-title" id="connectModalLabel">Conectar Sessão</h5>
537540
})
538541
.then(response => {
539542
if (!response.ok) throw new Error("Erro no request.");
540-
return response.json();
541543
})
542-
.then(data => {
543-
alert("A sessão foi removida!");
544+
.then(_ => {
545+
alert("A sessão foi removida, recarrega a pagina para atualizar a lista!");
544546
})
545547
.catch(error => alert(error.message));
546548
}
@@ -824,26 +826,26 @@ <h5 class="modal-title" id="connectModalLabel">Conectar Sessão</h5>
824826

825827
// show number add modal
826828
function addInstance() {
827-
const addInstanceModal = new bootstrap.Modal(document.getElementById('addInstanceModal'));
828-
addInstanceModal.show();
829-
}
829+
const addInstanceModal = new bootstrap.Modal(document.getElementById('addInstanceModal'));
830+
addInstanceModal.show();
831+
}
830832

831-
function submitInstanceNumber() {
832-
const numberInput = document.getElementById('instanceNumber').value;
833+
function submitInstanceNumber() {
834+
const numberInput = document.getElementById('instanceNumber').value;
833835

834-
if (numberInput) {
835-
const editModal = $('#editModal');
836-
editModal.data('number', numberInput);
836+
if (numberInput) {
837+
const editModal = $('#editModal');
838+
editModal.data('number', numberInput);
837839

838-
bootstrap.Modal.getInstance(document.getElementById('addInstanceModal')).hide();
840+
bootstrap.Modal.getInstance(document.getElementById('addInstanceModal')).hide();
839841

840-
const editInstanceModal = new bootstrap.Modal(document.getElementById('editModal'));
841-
editInstanceModal.show();
842+
const editInstanceModal = new bootstrap.Modal(document.getElementById('editModal'));
843+
editInstanceModal.show();
842844

843-
} else {
844-
alert('Por favor, insira um número válido.');
845-
}
845+
} else {
846+
alert('Por favor, insira um número válido.');
846847
}
848+
}
847849
</script>
848850
</body>
849851
</html>

src/services/client_baileys.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -351,9 +351,9 @@ export class ClientBaileys implements Client {
351351

352352

353353
async logout() {
354-
await this.disconnect()
355354
logger.debug('Logout client store for %s', this?.phone)
356355
await this.socketLogout()
356+
await this.disconnect()
357357
}
358358

359359
// eslint-disable-next-line @typescript-eslint/no-explicit-any

src/services/socket.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -331,17 +331,18 @@ export const connect = async ({
331331
}
332332

333333
const logout = async () => {
334-
await close()
335-
logger.info(`${phone} destroyed`)
336-
await dataStore.cleanSession()
337-
338-
logger.info(`${phone} disconnected`)
339-
await sessionStore.setStatus(phone, 'disconnected')
334+
logger.info(`${phone} logout`)
340335
try {
341336
return sock && await sock.logout()
342-
} catch (_error) {
337+
} catch (error) {
338+
logger.error(`Error on remove session ${phone}: ${error.message}`,)
343339
// ignore de unique error if already diconected session
340+
} finally {
341+
await sessionStore.setStatus(phone, 'disconnected')
342+
logger.info(`${phone} destroyed`)
343+
await dataStore.cleanSession()
344344
}
345+
await close()
345346
}
346347

347348
const exists: exists = async (localPhone: string) => {

src/services/transformer.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -606,7 +606,7 @@ export const fromBaileysMessageContent = (phone: string, payload: any, config?:
606606
case 'conversation':
607607
case 'extendedTextMessage':
608608
message.text = {
609-
body: binMessage.text || binMessage,
609+
body: binMessage?.text || binMessage,
610610
}
611611
message.type = 'text'
612612
break

0 commit comments

Comments
 (0)