Skip to content

Commit

Permalink
fix remove session in ui
Browse files Browse the repository at this point in the history
  • Loading branch information
clairton committed Jan 17, 2025
1 parent bbfce07 commit 108753d
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 28 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "unoapi-cloud",
"version": "1.25.0",
"version": "1.25.1",
"description": "Unoapi Cloud",
"exports": "./dist/index.js",
"types": "./dist/index.d.ts",
Expand Down
38 changes: 20 additions & 18 deletions public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,11 @@ <h5 class="modal-title" id="connectModalLabel">Conectar Sessão</h5>
}
});
}
getSessionAndpopulateTable(token, hideForm)
}

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

fetch(apiUrl + '/sessions', { headers })
Expand All @@ -483,7 +487,6 @@ <h5 class="modal-title" id="connectModalLabel">Conectar Sessão</h5>
return response.json();
})
.then(resp => {
localStorage.setItem(tokenKey, token);
if (hideForm) {
$('#navbarDropdown').removeClass('d-none');
$('#login').addClass('d-none');
Expand Down Expand Up @@ -537,10 +540,9 @@ <h5 class="modal-title" id="connectModalLabel">Conectar Sessão</h5>
})
.then(response => {
if (!response.ok) throw new Error("Erro no request.");
return response.json();
})
.then(data => {
alert("A sessão foi removida!");
.then(_ => {
alert("A sessão foi removida, recarrega a pagina para atualizar a lista!");
})
.catch(error => alert(error.message));
}
Expand Down Expand Up @@ -824,26 +826,26 @@ <h5 class="modal-title" id="connectModalLabel">Conectar Sessão</h5>

// show number add modal
function addInstance() {
const addInstanceModal = new bootstrap.Modal(document.getElementById('addInstanceModal'));
addInstanceModal.show();
}
const addInstanceModal = new bootstrap.Modal(document.getElementById('addInstanceModal'));
addInstanceModal.show();
}

function submitInstanceNumber() {
const numberInput = document.getElementById('instanceNumber').value;
function submitInstanceNumber() {
const numberInput = document.getElementById('instanceNumber').value;

if (numberInput) {
const editModal = $('#editModal');
editModal.data('number', numberInput);
if (numberInput) {
const editModal = $('#editModal');
editModal.data('number', numberInput);

bootstrap.Modal.getInstance(document.getElementById('addInstanceModal')).hide();
bootstrap.Modal.getInstance(document.getElementById('addInstanceModal')).hide();

const editInstanceModal = new bootstrap.Modal(document.getElementById('editModal'));
editInstanceModal.show();
const editInstanceModal = new bootstrap.Modal(document.getElementById('editModal'));
editInstanceModal.show();

} else {
alert('Por favor, insira um número válido.');
}
} else {
alert('Por favor, insira um número válido.');
}
}
</script>
</body>
</html>
2 changes: 1 addition & 1 deletion src/services/client_baileys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -351,9 +351,9 @@ export class ClientBaileys implements Client {


async logout() {
await this.disconnect()
logger.debug('Logout client store for %s', this?.phone)
await this.socketLogout()
await this.disconnect()
}

// eslint-disable-next-line @typescript-eslint/no-explicit-any
Expand Down
15 changes: 8 additions & 7 deletions src/services/socket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -331,17 +331,18 @@ export const connect = async ({
}

const logout = async () => {
await close()
logger.info(`${phone} destroyed`)
await dataStore.cleanSession()

logger.info(`${phone} disconnected`)
await sessionStore.setStatus(phone, 'disconnected')
logger.info(`${phone} logout`)
try {
return sock && await sock.logout()
} catch (_error) {
} catch (error) {
logger.error(`Error on remove session ${phone}: ${error.message}`,)
// ignore de unique error if already diconected session
} finally {
await sessionStore.setStatus(phone, 'disconnected')
logger.info(`${phone} destroyed`)
await dataStore.cleanSession()
}
await close()
}

const exists: exists = async (localPhone: string) => {
Expand Down
2 changes: 1 addition & 1 deletion src/services/transformer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -606,7 +606,7 @@ export const fromBaileysMessageContent = (phone: string, payload: any, config?:
case 'conversation':
case 'extendedTextMessage':
message.text = {
body: binMessage.text || binMessage,
body: binMessage?.text || binMessage,
}
message.type = 'text'
break
Expand Down

0 comments on commit 108753d

Please sign in to comment.