feat(events): decrypt event responses (#2056)

This commit is contained in:
vini
2025-11-19 10:17:21 -03:00
committed by GitHub
parent b4863b624e
commit 40f128d88a
4 changed files with 154 additions and 5 deletions
+48
View File
@@ -847,6 +847,19 @@ export const updateMessageWithPollUpdate = (msg: Pick<WAMessage, 'pollUpdates'>,
msg.pollUpdates = reactions
}
/** Update the message with a new event response */
export const updateMessageWithEventResponse = (
msg: Pick<WAMessage, 'eventResponses'>,
update: proto.IEventResponse
) => {
const authorID = getKeyAuthor(update.eventResponseMessageKey)
const responses = (msg.eventResponses || []).filter(r => getKeyAuthor(r.eventResponseMessageKey) !== authorID)
responses.push(update)
msg.eventResponses = responses
}
type VoteAggregation = {
name: string
voters: string[]
@@ -903,6 +916,41 @@ export function getAggregateVotesInPollMessage(
return Object.values(voteHashMap)
}
type ResponseAggregation = {
response: string
responders: string[]
}
/**
* Aggregates all event responses in an event message.
* @param msg the event creation message
* @param meId your jid
* @returns A list of response types & their responders
*/
export function getAggregateResponsesInEventMessage(
{ eventResponses }: Pick<WAMessage, 'eventResponses'>,
meId?: string
) {
const responseTypes = ['GOING', 'NOT_GOING', 'MAYBE']
const responseMap: { [_: string]: ResponseAggregation } = {}
for (const type of responseTypes) {
responseMap[type] = {
response: type,
responders: []
}
}
for (const update of eventResponses || []) {
const responseType = (update as any).eventResponse || 'UNKNOWN'
if (responseType !== 'UNKNOWN' && responseMap[responseType]) {
responseMap[responseType].responders.push(getKeyAuthor(update.eventResponseMessageKey, meId))
}
}
return Object.values(responseMap)
}
/** Given a list of message keys, aggregates them by chat & sender. Useful for sending read receipts in bulk */
export const aggregateMessageKeysNotFromMe = (keys: WAMessageKey[]) => {
const keyMap: { [id: string]: { jid: string; participant: string | undefined; messageIds: string[] } } = {}