From de9bc05a8cc61f73821c0b90799b80e8b88880ce Mon Sep 17 00:00:00 2001 From: Clairton Rodrigo Heinzen Date: Thu, 13 Feb 2025 19:38:48 -0300 Subject: [PATCH] clean code --- src/services/logout_baileys.ts | 12 +----------- src/services/redis.ts | 18 +----------------- 2 files changed, 2 insertions(+), 28 deletions(-) diff --git a/src/services/logout_baileys.ts b/src/services/logout_baileys.ts index 5279439..19c345c 100644 --- a/src/services/logout_baileys.ts +++ b/src/services/logout_baileys.ts @@ -4,8 +4,6 @@ import { getConfig } from '../services/config' import { getClient } from '../services/client' import { OnNewLogin } from '../services/socket' import { Logout } from './logout' -import { CLEAN_CONFIG_ON_DISCONNECT } from '../defaults' - export class LogoutBaileys implements Logout { private getClient: getClient @@ -30,14 +28,6 @@ export class LogoutBaileys implements Logout { getConfig: this.getConfig, onNewLogin: this.onNewLogin, }) - try { - await client.logout() - } catch (error) {} - if (CLEAN_CONFIG_ON_DISCONNECT) { - const config = await this.getConfig(phone) - const store = await config.getStore(phone, config) - const { dataStore } = store - await dataStore.cleanSession() - } + await client.logout() } } diff --git a/src/services/redis.ts b/src/services/redis.ts index 2d24ab5..32bdc10 100644 --- a/src/services/redis.ts +++ b/src/services/redis.ts @@ -1,7 +1,7 @@ import { createClient } from '@redis/client' import { REDIS_URL, DATA_JID_TTL, DATA_TTL, SESSION_TTL, DATA_URL_TTL } from '../defaults' import logger from './logger' -import { Contact, GroupMetadata } from 'baileys' +import { GroupMetadata } from 'baileys' import { Webhook, configs } from './config' export const BASE_KEY = 'unoapi-' @@ -139,10 +139,6 @@ const connectCountKey = (phone: string, ordinal: number | string) => { return `${BASE_KEY}connect-count:${phone}:${ordinal}` } -const contactKey = (phone: string, id: string) => { - return `${BASE_KEY}contact:${phone}:${id}` -} - export const sessionStatusKey = (phone: string) => { return `${BASE_KEY}status:${phone}` } @@ -226,18 +222,6 @@ export const setSessionStatus = async (phone: string, status: string) => { await client.set(key, status) } -export const getContact = async (phone: string, id: string): Promise => { - const key = contactKey(phone, id) - const json = await redisGet(key) - return json ? JSON.parse(json) as Contact : undefined -} - -export const setContact = async (phone: string, id: string, contact: Partial | undefined ) => { - const key = contactKey(phone, id) - const currentContact = await getContact(phone, id) || {} - await client.set(key, JSON.stringify({ ...currentContact, ...(contact || {} )})) -} - export const getMessageStatus = async (phone: string, id: string) => { const key = messageStatusKey(phone, id) return redisGet(key)