fix+feat: addParticipants + createGroup (#2344)

* added required modules

* added sendGroupV4Invite implementation

* docs updated accordingly

* bug fixed

* added usage example

* ESLint fix

* extended resulting object

* docs updated accordingly

* added required modules

* updated comments

* bug fixed

* added usage example

* fixed to catch unexpected errors

* removed unnecessary module

* updated usage example

* minor fixes

* changed to return a string if an error is occupied

* fixed usage example

* removed unneccessary module

* added getAddParticipantsRpcResult

* updated addParticipants

- added AddParticipnatsOptions to provide values for sleep, autoSendInviteV4, comment
- combined addParticipants with sendGroupInviteMessage

* removed unneccessary sendGroupV4Invite

* docs updated

* fixed statement fot autoSendInviteV4

* minor fixes

- the returned value of addParticipants is no longer wrapped in an array
- docs updated
- fixed bug with the returned code value when the code is '200'

* added logic of retrieving the group profile picture

this allows to send an invitation with a profile picture thumbnail of the group

* minor fixes

* added fix for the inviteV4 to be sent

* updated usage example

* minor fix

* ESLint fix

* fix for code 419

* function name getProfilePictureThumb changed to be more clear

* refactor: modules moved to window.Store.GroupParticipants

* refactor: edited link of usage examples

* refactor: LidManipulations changed to LidUtils

* refactor: modules regrouping

To keep the modules in order were made some changes:
- JoinInviteV4 renamed to GroupInviteV4 and grouped with module sendGroupInviteMessage
- GroupParticipants grouped with module sendAddParticipantsRPC

* fix: injectToFunction fixed to work properly

* revert docs changes for Chat

* Merge branch 'main' into fix-add-participants

* docs fixed

* minor fix in injectToFunction

* removed data stringifying/parsing

* added random sleep time logic

* code refactoring

* docs updated

* addParticipants method refactored

* createGroup method extended

- added functionality to send private invitations automatically to missing participants
- added ability to provide value for message timer
- added ability to link a group to the community parent group at the stage of creating a group
- extended the returned data after the method call

* docs updated + typo fixed

* added ability to create group with myself only

* example updated

* docs clarified

* small code refactoring

* window.Store.Invite and window.Store.InviteInfo grouped

* window.compareWwebVersions fixed

* small update to improve the performance of findImpl fix

* gid as wid structure

* docs + example updated

* parenthesis

* avoid sleep after the last iteration

* fixed compatibility issue for sendGroupInviteMessage

* fixed issue with stale groupmetadata

in some cases after the participant has left the group, that participant is still stored in groupmetadata

* fixed compatibility issue for sendAddParticipantsRPC

* minor fix

* jsdocs fixed

* fixed issue with group creation

* fixed createGroup method

- added check for unregistered phone number
- extended returning data from method call: added title
- code refactored
- jsdocs fixed

* fixed addParticipants method

- added check for unregistered number
- code refactored

* docs fixed

* usage example fixed

* removed unnecessary method call

* jsdocs fixed

* check for group admin fixed
This commit is contained in:
alechkos 2023-10-11 16:10:26 +03:00 • committed by GitHub
commit c0705a2216
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

107
index.d.ts vendored
View file

@ -35,12 +35,8 @@ declare namespace WAWebJS {
/** Unpins the Chat and returns its new Pin state */
unpinChat(chatId: string): Promise<boolean>
/**
* Create a new group
* @param name group title
* @param participants an array of Contacts or contact IDs to add to the group
*/
createGroup(name: string, participants: Contact[] | string[]): Promise<CreateGroupResult>
/** Creates a new group */
createGroup(title: string, participants?: string | Contact | Contact[] | string[], options?: CreateGroupOptions): Promise<CreateGroupResult|string>
/** Closes the client */
destroy(): Promise<void>
@ -540,14 +536,47 @@ declare namespace WAWebJS {
plugged: boolean,
}
/** An object that handles options for group creation */
export interface CreateGroupOptions {
/**
* The number of seconds for the messages to disappear in the group,
* won't take an effect if the group is been creating with myself only
* @default 0
*/
messageTimer?: number
/**
* The ID of a parent community group to link the newly created group with,
* won't take an effect if the group is been creating with myself only
*/
parentGroupId?: string
/** If true, the inviteV4 will be sent to those participants
* who have restricted others from being automatically added to groups,
* otherwise the inviteV4 won't be sent
* @default true
*/
autoSendInviteV4?: boolean,
/**
* The comment to be added to an inviteV4 (empty string by default)
* @default ''
*/
comment?: string
}
/** An object that handles the result for createGroup method */
export interface CreateGroupResult {
/** ID for the group that was just created */
gid: string,
/** participants that were not added to the group.
* Keys represent the ID for participant that was not added and its value is a status code
* that represents the reason why participant could not be added.
* This is usually 403 if the user's privacy settings don't allow you to add them to groups. */
missingParticipants: Record<string, string>
/** A group title */
title: string;
/** An object that handles the newly created group ID */
gid: ChatId;
/** An object that handles the result value for each added to the group participant */
participants: {
[participantId: string]: {
statusCode: number,
message: string,
isGroupCreator: boolean,
isInviteV4Sent: boolean
};
};
}
export interface GroupNotification {
@ -1196,9 +1225,9 @@ declare namespace WAWebJS {
/** Returns the Contact that corresponds to this Chat. */
getContact: () => Promise<Contact>,
/** Marks this Chat as unread */
markUnread: () => Promise<void>
markUnread: () => Promise<void>,
/** Returns array of all Labels assigned to this Chat */
getLabels: () => Promise<Label[]>
getLabels: () => Promise<Label[]>,
/** Add or remove labels to this Chat */
changeLabels: (labelIds: Array<string | number>) => Promise<void>
}
@ -1258,18 +1287,38 @@ declare namespace WAWebJS {
export type ChangeParticipantsPermissions =
(participantIds: Array<string>) => Promise<{ status: number }>
/** Adds or removes a list of participants by ID to the group */
export type ChangeGroupParticipants =
(participantIds: Array<string>) => Promise<{
status: number;
participants: Array<{
[key: string]: {
code: number
}
}>
} & {
[key: string]: number;
}>
/** An object that handles the result for addParticipants method */
export interface AddParticipantsResult {
[participantId: string]: {
code: number;
message: string;
isInviteV4Sent: boolean,
};
};
/** An object that handles options for adding participants */
export interface AddParticipantsOptions {
/**
* The number of milliseconds to wait before adding the next participant.
* If it is an array, a random sleep time between the sleep[0] and sleep[1] values will be added
* (the difference must be >=100 ms, otherwise, a random sleep time between sleep[1] and sleep[1] + 100
* will be added). If sleep is a number, a sleep time equal to its value will be added
* @default [250,500]
*/
sleep?: Array<number>|number,
/**
* If true, the inviteV4 will be sent to those participants
* who have restricted others from being automatically added to groups,
* otherwise the inviteV4 won't be sent
* @default true
*/
autoSendInviteV4?: boolean,
/**
* The comment to be added to an inviteV4 (empty string by default)
* @default ''
*/
comment?: string
};
/** An object that handles the information about the group membership request */
export interface GroupMembershipRequest {
@ -1313,9 +1362,9 @@ declare namespace WAWebJS {
/** Group participants */
participants: Array<GroupParticipant>;
/** Adds a list of participants by ID to the group */
addParticipants: ChangeGroupParticipants;
addParticipants: (participantIds: string|string[], options?: AddParticipantsOptions) => Promise<Object.<string, AddParticipantsResult>|string>;
/** Removes a list of participants by ID to the group */
removeParticipants: ChangeGroupParticipants;
removeParticipants: (participantIds: string[]) => Promise<{ status: number }>;
/** Promotes participants by IDs to admins */
promoteParticipants: ChangeParticipantsPermissions;
/** Demotes participants by IDs to regular users */