chore: add linting

This commit is contained in:
Adhiraj Singh
2022-01-19 15:54:02 +05:30
parent f7f86e69d6
commit 8f11f0be76
49 changed files with 5800 additions and 4314 deletions

View File

@@ -1,7 +1,7 @@
import { BinaryNode, jidNormalizedUser } from "../WABinary";
import { LegacySocketConfig, GroupModificationResponse, ParticipantAction, GroupMetadata, WAFlag, WAMetric, WAGroupCreateResponse, GroupParticipant } from "../Types";
import { generateMessageID, unixTimestampSeconds } from "../Utils/generics";
import makeMessagesSocket from "./messages";
import { GroupMetadata, GroupModificationResponse, GroupParticipant, LegacySocketConfig, ParticipantAction, WAFlag, WAGroupCreateResponse, WAMetric } from '../Types'
import { generateMessageID, unixTimestampSeconds } from '../Utils/generics'
import { BinaryNode, jidNormalizedUser } from '../WABinary'
import makeMessagesSocket from './messages'
const makeGroupsSocket = (config: LegacySocketConfig) => {
const { logger } = config
@@ -17,9 +17,9 @@ const makeGroupsSocket = (config: LegacySocketConfig) => {
} = sock
/** Generic function for group queries */
const groupQuery = async(type: string, jid?: string, subject?: string, participants?: string[], additionalNodes?: BinaryNode[]) => {
const tag = generateMessageTag()
const result = await setQuery ([
const groupQuery = async(type: string, jid?: string, subject?: string, participants?: string[], additionalNodes?: BinaryNode[]) => {
const tag = generateMessageTag()
const result = await setQuery ([
{
tag: 'group',
attrs: {
@@ -36,12 +36,12 @@ const makeGroupsSocket = (config: LegacySocketConfig) => {
additionalNodes
}
], [WAMetric.group, 136], tag)
return result
}
return result
}
/** Get the metadata of the group from WA */
const groupMetadataFull = async (jid: string) => {
const metadata = await query({
/** Get the metadata of the group from WA */
const groupMetadataFull = async(jid: string) => {
const metadata = await query({
json: ['query', 'GroupMetadata', jid],
expect200: true
})
@@ -62,13 +62,14 @@ const makeGroupsSocket = (config: LegacySocketConfig) => {
}
return meta
}
/** Get the metadata (works after you've left the group also) */
const groupMetadataMinimal = async (jid: string) => {
const { attrs, content }:BinaryNode = await query({
}
/** Get the metadata (works after you've left the group also) */
const groupMetadataMinimal = async(jid: string) => {
const { attrs, content }:BinaryNode = await query({
json: {
tag: 'query',
attrs: {type: 'group', jid: jid, epoch: currentEpoch().toString()}
attrs: { type: 'group', jid: jid, epoch: currentEpoch().toString() }
},
binaryTag: [WAMetric.group, WAFlag.ignore],
expect200: true
@@ -89,16 +90,17 @@ const makeGroupsSocket = (config: LegacySocketConfig) => {
}
}
}
const meta: GroupMetadata = {
id: jid,
owner: attrs?.creator,
creation: +attrs?.create,
subject: null,
desc,
participants
}
const meta: GroupMetadata = {
id: jid,
owner: attrs?.creator,
creation: +attrs?.create,
subject: null,
desc,
participants
}
return meta
}
}
socketEvents.on('CB:Chat,cmd:action', (json: BinaryNode) => {
/*const data = json[1].data
@@ -129,8 +131,11 @@ const makeGroupsSocket = (config: LegacySocketConfig) => {
groupMetadata: async(jid: string, minimal: boolean) => {
let result: GroupMetadata
if(minimal) result = await groupMetadataMinimal(jid)
else result = await groupMetadataFull(jid)
if(minimal) {
result = await groupMetadataMinimal(jid)
} else {
result = await groupMetadataFull(jid)
}
return result
},
@@ -139,13 +144,13 @@ const makeGroupsSocket = (config: LegacySocketConfig) => {
* @param title like, the title of the group
* @param participants people to include in the group
*/
groupCreate: async (title: string, participants: string[]) => {
groupCreate: async(title: string, participants: string[]) => {
const response = await groupQuery('create', null, title, participants) as WAGroupCreateResponse
const gid = response.gid
let metadata: GroupMetadata
try {
metadata = await groupMetadataFull(gid)
} catch (error) {
} catch(error) {
logger.warn (`error in group creation: ${error}, switching gid & checking`)
// if metadata is not available
const comps = gid.replace ('@g.us', '').split ('-')
@@ -154,6 +159,7 @@ const makeGroupsSocket = (config: LegacySocketConfig) => {
metadata = await groupMetadataFull(gid)
logger.warn (`group ID switched from ${gid} to ${response.gid}`)
}
ev.emit('chats.upsert', [
{
id: response.gid!,
@@ -168,7 +174,7 @@ const makeGroupsSocket = (config: LegacySocketConfig) => {
* Leave a group
* @param jid the ID of the group
*/
groupLeave: async (id: string) => {
groupLeave: async(id: string) => {
await groupQuery('leave', id)
ev.emit('chats.update', [ { id, readOnly: true } ])
},
@@ -177,7 +183,7 @@ const makeGroupsSocket = (config: LegacySocketConfig) => {
* @param {string} jid the ID of the group
* @param {string} title the new title of the group
*/
groupUpdateSubject: async (id: string, title: string) => {
groupUpdateSubject: async(id: string, title: string) => {
await groupQuery('subject', id, title)
ev.emit('chats.update', [ { id, name: title } ])
ev.emit('contacts.update', [ { id, name: title } ])
@@ -188,11 +194,11 @@ const makeGroupsSocket = (config: LegacySocketConfig) => {
* @param {string} jid the ID of the group
* @param {string} title the new title of the group
*/
groupUpdateDescription: async (jid: string, description: string) => {
groupUpdateDescription: async(jid: string, description: string) => {
const metadata = await groupMetadataFull(jid)
const node: BinaryNode = {
tag: 'description',
attrs: {id: generateMessageID(), prev: metadata?.descId},
attrs: { id: generateMessageID(), prev: metadata?.descId },
content: Buffer.from(description, 'utf-8')
}
@@ -247,4 +253,5 @@ const makeGroupsSocket = (config: LegacySocketConfig) => {
}
}
export default makeGroupsSocket