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:
parent
49feb3660c
commit
67d305be78
9 changed files with 131 additions and 6 deletions
|
|
@ -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,
|
||||
|
|
|
|||
Loading…
Reference in a new issue