feat: send polls (#2377)

* feat: added Poll class

* feat: logic for sending polls added

* updated poll properties on returned message instance

* docs updated

* usage example updated

* module fixed

* 'pollSendOptions' changed to 'options'

* window.compareWwebVersions fixed

* small update to improve the performance of findImpl fix

* added option for custom message secret

* usage example updated
This commit is contained in:
alechkos 2023-10-19 19:37:30 +03:00 • committed by GitHub
commit 67d305be78
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 131 additions and 6 deletions

View file

@ -142,7 +142,7 @@ exports.ExposeStore = (moduleRaidStr) => {
const modifiedFunction = (...args) => callback(originalFunction, ...args);
module[target.index][target.property] = modifiedFunction;
};
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 || proto.groupInviteMessage ? 'text' : func(...args); });
@ -215,6 +215,23 @@ exports.LoadUtils = () => {
delete options.location;
}
let _pollOptions = {};
if (options.poll) {
const { pollName, pollOptions } = options.poll;
const { allowMultipleAnswers, messageSecret } = options.poll.options;
_pollOptions = {
type: 'poll_creation',
pollName: pollName,
pollOptions: pollOptions,
pollSelectableOptionsCount: allowMultipleAnswers ? 0 : 1,
messageSecret:
Array.isArray(messageSecret) && messageSecret.length === 32
? new Uint8Array(messageSecret)
: window.crypto.getRandomValues(new Uint8Array(32))
};
delete options.poll;
}
let vcardOptions = {};
if (options.contactCard) {
let contact = window.Store.Contact.get(options.contactCard);
@ -334,6 +351,7 @@ exports.LoadUtils = () => {
type: 'chat',
...ephemeralFields,
...locationOptions,
..._pollOptions,
...attOptions,
...(attOptions.toJSON ? attOptions.toJSON() : {}),
...quotedMsgOptions,