Skip to content

Commit

Permalink
clean code
Browse files Browse the repository at this point in the history
  • Loading branch information
clairton committed Feb 13, 2025
1 parent 5d1567e commit de9bc05
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 28 deletions.
12 changes: 1 addition & 11 deletions src/services/logout_baileys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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()
}
}
18 changes: 1 addition & 17 deletions src/services/redis.ts
Original file line number Diff line number Diff line change
@@ -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-'
Expand Down Expand Up @@ -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}`
}
Expand Down Expand Up @@ -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<Contact | undefined> => {
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<Contact> | 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)
Expand Down

0 comments on commit de9bc05

Please sign in to comment.