Skip to content

Commit

Permalink
Revert "feat: vote_update event (pedroslopez#2596)"
Browse files Browse the repository at this point in the history
This reverts commit 9cac8fd.
  • Loading branch information
ninajika committed May 7, 2024
1 parent b94903b commit bb2b696
Show file tree
Hide file tree
Showing 8 changed files with 3 additions and 132 deletions.
7 changes: 1 addition & 6 deletions example.js
Original file line number Diff line number Diff line change
Expand Up @@ -593,9 +593,4 @@ client.on('group_membership_request', async (notification) => {
/** You can approve or reject the newly appeared membership request: */
await client.approveGroupMembershipRequestss(notification.chatId, notification.author);
await client.rejectGroupMembershipRequests(notification.chatId, notification.author);
});

client.on('vote_update', (vote) => {
/** The vote that was affected: */
console.log(vote);
});
});
36 changes: 0 additions & 36 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -374,14 +374,6 @@ declare namespace WAWebJS {

/** Emitted when the RemoteAuth session is saved successfully on the external Database */
on(event: 'remote_session_saved', listener: () => void): this

/**
* Emitted when some poll option is selected or deselected,
* shows a user's current selected option(s) on the poll
*/
on(event: 'vote_update', listener: (
vote: PollVote
) => void): this
}

/** Current connection information */
Expand Down Expand Up @@ -1029,34 +1021,6 @@ declare namespace WAWebJS {
constructor(pollName: string, pollOptions: Array<string>, options?: PollSendOptions)
}

/** Represents a Poll Vote on WhatsApp */
export interface PollVote {
/** The person who voted */
voter: string;

/**
* The selected poll option(s)
* If it's an empty array, the user hasn't selected any options on the poll,
* may occur when they deselected all poll options
*/
selectedOptions: SelectedPollOption[];

/** Timestamp the option was selected or deselected at */
interractedAtTs: number;

/** The poll creation message associated with the poll vote */
parentMessage: Message;
}

/** Selected poll option structure */
export interface SelectedPollOption {
/** The local selected option ID */
id: number;

/** The option name */
name: string;
}

export interface Label {
/** Label name */
name: string,
Expand Down
17 changes: 1 addition & 16 deletions src/Client.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const { ExposeStore, LoadUtils } = require('./util/Injected');
const ChatFactory = require('./factories/ChatFactory');
const ContactFactory = require('./factories/ContactFactory');
const WebCacheFactory = require('./webCache/WebCacheFactory');
const { ClientInfo, Message, MessageMedia, Contact, Location, Poll, PollVote, GroupNotification, Label, Call, Buttons, List, Reaction } = require('./structures');
const { ClientInfo, Message, MessageMedia, Contact, Location, Poll, GroupNotification, Label, Call, Buttons, List, Reaction } = require('./structures');
const LegacySessionAuth = require('./authStrategies/LegacySessionAuth');
const NoAuth = require('./authStrategies/NoAuth');

Expand Down Expand Up @@ -54,7 +54,6 @@ const NoAuth = require('./authStrategies/NoAuth');
* @fires Client#contact_changed
* @fires Client#group_admin_changed
* @fires Client#group_membership_request
* @fires Client#vote_update
*/
class Client extends EventEmitter {
constructor(options = {}) {
Expand Down Expand Up @@ -710,16 +709,6 @@ class Client extends EventEmitter {
this.emit(Events.MESSAGE_CIPHERTEXT, new Message(this, msg));
});

await page.exposeFunction('onPollVoteEvent', (vote) => {
const _vote = new PollVote(this, vote);
/**
* Emitted when some poll option is selected or deselected,
* shows a user's current selected option(s) on the poll
* @event Client#vote_update
*/
this.emit(Events.VOTE_UPDATE, _vote);
});

await page.evaluate(() => {
window.Store.Msg.on('change', (msg) => { window.onChangeMessageEvent(window.WWebJS.getMessageModel(msg)); });
window.Store.Msg.on('change:type', (msg) => { window.onChangeMessageTypeEvent(window.WWebJS.getMessageModel(msg)); });
Expand All @@ -744,10 +733,6 @@ class Client extends EventEmitter {
}
});
window.Store.Chat.on('change:unreadCount', (chat) => {window.onChatUnreadCountEvent(chat);});
window.Store.PollVote.on('add', (vote) => {
const pollVoteModel = window.WWebJS.getPollVoteModel(vote);
pollVoteModel && window.onPollVoteEvent(pollVoteModel);
});

{
const module = window.Store.createOrUpdateReactionsModule;
Expand Down
1 change: 0 additions & 1 deletion src/structures/Message.js
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,6 @@ class Message extends Base {
this.allowMultipleAnswers = Boolean(!data.pollSelectableOptionsCount);
this.pollInvalidated = data.pollInvalidated;
this.isSentCagPollCreation = data.isSentCagPollCreation;
this.messageSecret = Object.keys(data.messageSecret).map((key) => data.messageSecret[key]);
}

return super._patch(data);
Expand Down
61 changes: 0 additions & 61 deletions src/structures/PollVote.js

This file was deleted.

1 change: 0 additions & 1 deletion src/structures/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,4 @@ module.exports = {
Payment: require('./Payment'),
Reaction: require('./Reaction'),
Poll: require('./Poll'),
PollVote: require('./PollVote')
};
3 changes: 1 addition & 2 deletions src/util/Constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,7 @@ exports.Events = {
STATE_CHANGED: 'change_state',
BATTERY_CHANGED: 'change_battery',
INCOMING_CALL: 'call',
REMOTE_SESSION_SAVED: 'remote_session_saved',
VOTE_UPDATE: 'vote_update'
REMOTE_SESSION_SAVED: 'remote_session_saved'
};

/**
Expand Down
9 changes: 0 additions & 9 deletions src/util/Injected.js
Original file line number Diff line number Diff line change
Expand Up @@ -557,15 +557,6 @@ exports.LoadUtils = () => {
return msg;
};

window.WWebJS.getPollVoteModel = (vote) => {
const _vote = vote.serialize();
if (vote.parentMsgKey) {
const msg = window.Store.Msg.get(vote.parentMsgKey);
msg && (_vote.parentMessage = window.WWebJS.getMessageModel(msg));
return _vote;
}
return null;
};

window.WWebJS.getChatModel = async chat => {

Expand Down

0 comments on commit bb2b696

Please sign in to comment.