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:
parent
56320c88f8
commit
c0705a2216
1 changed files with 508 additions and 82 deletions
|
|
@ -15,9 +15,8 @@ exports.ExposeStore = (moduleRaidStr) => {
|
|||
window.Store.DownloadManager = window.mR.findModule('downloadManager')[0].downloadManager;
|
||||
window.Store.GroupMetadata = window.mR.findModule('GroupMetadata')[0].default.GroupMetadata;
|
||||
window.Store.GroupMetadata.queryAndUpdate = window.mR.findModule('queryAndUpdateGroupMetadataById')[0].queryAndUpdateGroupMetadataById;
|
||||
window.Store.Invite = window.mR.findModule('resetGroupInviteCode')[0];
|
||||
window.Store.InviteInfo = window.mR.findModule('queryGroupInvite')[0];
|
||||
window.Store.Label = window.mR.findModule('LabelCollection')[0].LabelCollection;
|
||||
window.Store.ContactCollection = window.mR.findModule('ContactCollection')[0].ContactCollection;
|
||||
window.Store.MediaPrep = window.mR.findModule('prepRawMedia')[0];
|
||||
window.Store.MediaObject = window.mR.findModule('getOrCreateMediaObject')[0];
|
||||
window.Store.NumberInfo = window.mR.findModule('formattedPhoneNumber')[0];
|
||||
|
|
@ -26,7 +25,6 @@ exports.ExposeStore = (moduleRaidStr) => {
|
|||
window.Store.MsgKey = window.mR.findModule((module) => module.default && module.default.fromString)[0].default;
|
||||
window.Store.MessageInfo = window.mR.findModule('sendQueryMsgInfo')[0];
|
||||
window.Store.OpaqueData = window.mR.findModule(module => module.default && module.default.createFromData)[0].default;
|
||||
window.Store.QueryExist = window.mR.findModule('queryExists')[0] ? window.mR.findModule('queryExists')[0].queryExists : window.mR.findModule('queryExist')[0].queryWidExists;
|
||||
window.Store.QueryProduct = window.mR.findModule('queryProduct')[0];
|
||||
window.Store.QueryOrder = window.mR.findModule('queryOrder')[0];
|
||||
window.Store.SendClear = window.mR.findModule('sendClear')[0];
|
||||
|
|
@ -45,23 +43,28 @@ exports.ExposeStore = (moduleRaidStr) => {
|
|||
window.Store.ProfilePic = window.mR.findModule('profilePicResync')[0];
|
||||
window.Store.PresenceUtils = window.mR.findModule('sendPresenceAvailable')[0];
|
||||
window.Store.ChatState = window.mR.findModule('sendChatStateComposing')[0];
|
||||
window.Store.GroupParticipants = window.mR.findModule('promoteParticipants')[0];
|
||||
window.Store.JoinInviteV4 = window.mR.findModule('queryGroupInviteV4')[0];
|
||||
window.Store.findCommonGroups = window.mR.findModule('findCommonGroups')[0].findCommonGroups;
|
||||
window.Store.StatusUtils = window.mR.findModule('setMyStatus')[0];
|
||||
window.Store.ConversationMsgs = window.mR.findModule('loadEarlierMsgs')[0];
|
||||
window.Store.sendReactionToMsg = window.mR.findModule('sendReactionToMsg')[0].sendReactionToMsg;
|
||||
window.Store.createOrUpdateReactionsModule = window.mR.findModule('createOrUpdateReactions')[0];
|
||||
window.Store.EphemeralFields = window.mR.findModule('getEphemeralFields')[0];
|
||||
window.Store.ReplyUtils = window.mR.findModule('canReplyMsg').length > 0 && window.mR.findModule('canReplyMsg')[0];
|
||||
window.Store.MsgActionChecks = window.mR.findModule('canSenderRevokeMsg')[0];
|
||||
window.Store.QuotedMsg = window.mR.findModule('getQuotedMsgObj')[0];
|
||||
window.Store.Socket = window.mR.findModule('deprecatedSendIq')[0];
|
||||
window.Store.SocketWap = window.mR.findModule('wap')[0];
|
||||
window.Store.SearchContext = window.mR.findModule('getSearchContext')[0].getSearchContext;
|
||||
window.Store.DrawerManager = window.mR.findModule('DrawerManager')[0].DrawerManager;
|
||||
window.Store.LidUtils = window.mR.findModule('getCurrentLid')[0];
|
||||
window.Store.WidToJid = window.mR.findModule('widToUserJid')[0];
|
||||
window.Store.JidToWid = window.mR.findModule('userJidToUserWid')[0];
|
||||
|
||||
/* eslint-disable no-undef, no-cond-assign */
|
||||
window.Store.QueryExist = ((m = window.mR.findModule('queryExists')[0]) ? m.queryExists : window.mR.findModule('queryExist')[0].queryWidExists);
|
||||
window.Store.ReplyUtils = (m = window.mR.findModule('canReplyMsg')).length > 0 && m[0];
|
||||
if ((m = window.mR.findModule('ChatCollection')[0]) && m.ChatCollection && typeof m.ChatCollection.findImpl === 'undefined' && typeof m.ChatCollection._find !== 'undefined') m.ChatCollection.findImpl = m.ChatCollection._find;
|
||||
/* eslint-enable no-undef, no-cond-assign */
|
||||
|
||||
window.Store.StickerTools = {
|
||||
...window.mR.findModule('toWebpSticker')[0],
|
||||
...window.mR.findModule('addWebpMetadata')[0]
|
||||
|
|
@ -72,6 +75,18 @@ exports.ExposeStore = (moduleRaidStr) => {
|
|||
...window.mR.findModule('sendExitGroup')[0],
|
||||
...window.mR.findModule('sendSetPicture')[0]
|
||||
};
|
||||
window.Store.GroupParticipants = {
|
||||
...window.mR.findModule('promoteParticipants')[0],
|
||||
...window.mR.findModule('sendAddParticipantsRPC')[0]
|
||||
};
|
||||
window.Store.GroupInvite = {
|
||||
...window.mR.findModule('resetGroupInviteCode')[0],
|
||||
...window.mR.findModule('queryGroupInvite')[0]
|
||||
};
|
||||
window.Store.GroupInviteV4 = {
|
||||
...window.mR.findModule('queryGroupInviteV4')[0],
|
||||
...window.mR.findModule('sendGroupInviteMessage')[0]
|
||||
};
|
||||
window.Store.MembershipRequestUtils = {
|
||||
...window.mR.findModule('getMembershipApprovalRequests')[0],
|
||||
...window.mR.findModule('sendMembershipRequestsActionRPC')[0]
|
||||
|
|
@ -86,9 +101,6 @@ exports.ExposeStore = (moduleRaidStr) => {
|
|||
};
|
||||
}
|
||||
|
||||
// eslint-disable-next-line no-undef
|
||||
if ((m = window.mR.findModule('ChatCollection')[0]) && m.ChatCollection && typeof m.ChatCollection.findImpl === 'undefined' && typeof m.ChatCollection._find !== 'undefined') m.ChatCollection.findImpl = m.ChatCollection._find;
|
||||
|
||||
// TODO remove these once everybody has been updated to WWebJS with legacy sessions removed
|
||||
const _linkPreview = window.mR.findModule('queryLinkPreview');
|
||||
if (_linkPreview && _linkPreview[0] && _linkPreview[0].default) {
|
||||
|
|
@ -131,7 +143,7 @@ exports.ExposeStore = (moduleRaidStr) => {
|
|||
|
||||
window.injectToFunction({ moduleId: 'mediaTypeFromProtobuf', index: 0, property: 'mediaTypeFromProtobuf' }, (func, ...args) => { const [proto] = args; return proto.locationMessage ? null : func(...args); });
|
||||
|
||||
window.injectToFunction({ moduleId: 'typeAttributeFromProtobuf', index: 0, property: 'typeAttributeFromProtobuf' }, (func, ...args) => { const [proto] = args; return proto.locationMessage ? 'text' : func(...args); });
|
||||
window.injectToFunction({ moduleId: 'typeAttributeFromProtobuf', index: 0, property: 'typeAttributeFromProtobuf' }, (func, ...args) => { const [proto] = args; return proto.locationMessage || proto.groupInviteMessage ? 'text' : func(...args); });
|
||||
};
|
||||
|
||||
exports.LoadUtils = () => {
|
||||
|
|
@ -865,6 +877,105 @@ exports.LoadUtils = () => {
|
|||
throw err;
|
||||
}
|
||||
};
|
||||
|
||||
window.WWebJS.getProfilePicThumbToBase64 = async (chatWid) => {
|
||||
const profilePicCollection = await window.Store.ProfilePicThumb.find(chatWid);
|
||||
|
||||
const _readImageAsBase64 = (imageBlob) => {
|
||||
return new Promise((resolve) => {
|
||||
const reader = new FileReader();
|
||||
reader.onloadend = function () {
|
||||
const base64Image = reader.result;
|
||||
if (base64Image == null) {
|
||||
resolve(undefined);
|
||||
} else {
|
||||
const base64Data = base64Image.toString().split(',')[1];
|
||||
resolve(base64Data);
|
||||
}
|
||||
};
|
||||
reader.readAsDataURL(imageBlob);
|
||||
});
|
||||
};
|
||||
|
||||
if (profilePicCollection?.img) {
|
||||
try {
|
||||
const response = await fetch(profilePicCollection.img);
|
||||
if (response.ok) {
|
||||
const imageBlob = await response.blob();
|
||||
if (imageBlob) {
|
||||
const base64Image = await _readImageAsBase64(imageBlob);
|
||||
return base64Image;
|
||||
}
|
||||
}
|
||||
} catch (error) { /* empty */ }
|
||||
}
|
||||
return undefined;
|
||||
};
|
||||
|
||||
window.WWebJS.getAddParticipantsRpcResult = async (groupMetadata, groupWid, participantWid) => {
|
||||
const participantLidArgs = groupMetadata?.isLidAddressingMode
|
||||
? {
|
||||
phoneNumber: participantWid,
|
||||
lid: window.Store.LidUtils.getCurrentLid(participantWid)
|
||||
}
|
||||
: { phoneNumber: participantWid };
|
||||
|
||||
const iqTo = window.Store.WidToJid.widToGroupJid(groupWid);
|
||||
|
||||
const participantArgs =
|
||||
participantLidArgs.lid
|
||||
? [{
|
||||
participantJid: window.Store.WidToJid.widToUserJid(participantLidArgs.lid),
|
||||
phoneNumberMixinArgs: {
|
||||
anyPhoneNumber: window.Store.WidToJid.widToUserJid(participantLidArgs.phoneNumber)
|
||||
}
|
||||
}]
|
||||
: [{
|
||||
participantJid: window.Store.WidToJid.widToUserJid(participantLidArgs.phoneNumber)
|
||||
}];
|
||||
|
||||
let rpcResult, resultArgs;
|
||||
const isOldImpl = window.compareWwebVersions(window.Debug.VERSION, '<=', '2.2335.9');
|
||||
const data = {
|
||||
name: undefined,
|
||||
code: undefined,
|
||||
inviteV4Code: undefined,
|
||||
inviteV4CodeExp: undefined
|
||||
};
|
||||
|
||||
try {
|
||||
rpcResult = await window.Store.GroupParticipants.sendAddParticipantsRPC({ participantArgs, iqTo });
|
||||
resultArgs = isOldImpl
|
||||
? rpcResult.value.addParticipant[0].addParticipantsParticipantMixins
|
||||
: rpcResult.value.addParticipant[0]
|
||||
.addParticipantsParticipantAddedOrNonRegisteredWaUserParticipantErrorLidResponseMixinGroup
|
||||
.value
|
||||
.addParticipantsParticipantMixins;
|
||||
} catch (err) {
|
||||
data.code = 400;
|
||||
return data;
|
||||
}
|
||||
|
||||
if (rpcResult.name === 'AddParticipantsResponseSuccess') {
|
||||
const code = resultArgs?.value.error ?? '200';
|
||||
data.name = resultArgs?.name;
|
||||
data.code = +code;
|
||||
data.inviteV4Code = resultArgs?.value.addRequestCode;
|
||||
data.inviteV4CodeExp = resultArgs?.value.addRequestExpiration?.toString();
|
||||
}
|
||||
|
||||
else if (rpcResult.name === 'AddParticipantsResponseClientError') {
|
||||
const { code: code } = rpcResult.value.errorAddParticipantsClientErrors.value;
|
||||
data.code = +code;
|
||||
}
|
||||
|
||||
else if (rpcResult.name === 'AddParticipantsResponseServerError') {
|
||||
const { code: code } = rpcResult.value.errorServerErrors.value;
|
||||
data.code = +code;
|
||||
}
|
||||
|
||||
return data;
|
||||
};
|
||||
|
||||
window.WWebJS.membershipRequestAction = async (groupId, action, requesterIds, sleep) => {
|
||||
const groupWid = window.Store.WidFactory.createWid(groupId);
|
||||
|
|
|
|||
Loading…
Reference in a new issue