update broadcast lists

This commit is contained in:
Adhiraj Singh
2021-07-16 23:48:43 +05:30
parent f356fa1811
commit e65f060664
4 changed files with 37 additions and 20 deletions

View File

@@ -1,6 +1,6 @@
import BinaryNode from "../BinaryNode";
import { EventEmitter } from 'events'
import { Chat, Contact, Presence, PresenceData, WABroadcastListInfo, SocketConfig, WAFlag, WAMetric, WABusinessProfile, ChatModification, WAMessageKey, WAMessage } from "../Types";
import { Chat, Contact, Presence, PresenceData, SocketConfig, WAFlag, WAMetric, WABusinessProfile, ChatModification, WAMessageKey, WAMessage } from "../Types";
import { debouncedTimeout, unixTimestampSeconds, whatsappID } from "../Utils/generics";
import makeAuthSocket from "./auth";
import { Attributes, BinaryNode as BinaryNodeBase } from "../BinaryNode/types";
@@ -413,14 +413,6 @@ const makeChatsSocket = (config: SocketConfig) => {
}
return response
},
/** Query broadcast list info */
getBroadcastListInfo: (jid: string) => {
return query({
json: ['query', 'contact', jid],
expect200: true,
requiresPhoneConnection: true
}) as Promise<WABroadcastListInfo>
},
/**
* Update the profile picture
* @param jid

View File

@@ -1,7 +1,7 @@
import BinaryNode from "../BinaryNode";
import { EventEmitter } from 'events'
import { SocketConfig, GroupModificationResponse, ParticipantAction, GroupMetadata, WAFlag, WAMetric, WAGroupCreateResponse, GroupParticipant } from "../Types";
import { generateMessageID, unixTimestampSeconds } from "../Utils/generics";
import { generateMessageID, unixTimestampSeconds, whatsappID } from "../Utils/generics";
import makeMessagesSocket from "./messages";
const makeGroupsSocket = (config: SocketConfig) => {
@@ -47,8 +47,9 @@ const makeGroupsSocket = (config: SocketConfig) => {
expect200: true
})
metadata.participants = metadata.participants.map(p => (
{ ...p, id: undefined, jid: p.jid }
{ ...p, id: undefined, jid: whatsappID(p.id) }
))
metadata.owner = whatsappID(metadata.owner)
return metadata as GroupMetadata
}
/** Get the metadata (works after you've left the group also) */
@@ -153,7 +154,7 @@ const makeGroupsSocket = (config: SocketConfig) => {
],
type: 'upsert'
})
return response
return metadata
},
/**
* Leave a group
@@ -200,8 +201,33 @@ const makeGroupsSocket = (config: SocketConfig) => {
const jids = Object.keys(result.participants || {})
ev.emit('group-participants.update', { jid, participants: jids, action })
return jids
}
},
/** Query broadcast list info */
getBroadcastListInfo: async(jid: string) => {
interface WABroadcastListInfo {
status: number
name: string
recipients?: {id: string}[]
}
const result = await query({
json: ['query', 'contact', jid],
expect200: true,
requiresPhoneConnection: true
}) as WABroadcastListInfo
const metadata: GroupMetadata = {
subject: result.name,
id: jid,
creation: undefined,
owner: getState().user?.jid,
participants: result.recipients!.map(({id}) => (
{ jid: whatsappID(id), isAdmin: false, isSuperAdmin: false }
))
}
return metadata
}
}
}

View File

@@ -249,6 +249,12 @@ export default(
groupMetadata[jid] = await sock?.groupMetadata(jid, chats.get(jid)?.read_only === 'true')
}
return groupMetadata[jid]
},
fetchBroadcastListInfo: async(jid: string, sock: Connection | undefined) => {
if(!groupMetadata[jid]) {
groupMetadata[jid] = await sock?.getBroadcastListInfo(jid)
}
return groupMetadata[jid]
}
}
}

View File

@@ -137,13 +137,6 @@ export type WAInitResponse = {
status: 200
}
export interface WABroadcastListInfo {
status: number
name: string
recipients?: {id: string}[]
}
type WABusinessHoursConfig = {
day_of_week: string
mode: string