Initial Poll message receive support

This commit is contained in:
yash-signal
2025-09-18 11:06:43 -05:00
committed by GitHub
parent 976a3135e5
commit 93ae2a4c48
15 changed files with 1072 additions and 6 deletions

View File

@@ -22,6 +22,9 @@ import type {
ProcessedPreview,
ProcessedSticker,
ProcessedReaction,
ProcessedPollCreate,
ProcessedPollVote,
ProcessedPollTerminate,
ProcessedDelete,
ProcessedGiftBadge,
ProcessedStoryContext,
@@ -309,6 +312,53 @@ export function processReaction(
};
}
export function processPollCreate(
pollCreate?: Proto.DataMessage.IPollCreate | null
): ProcessedPollCreate | undefined {
if (!pollCreate) {
return undefined;
}
return {
question: dropNull(pollCreate.question),
options: pollCreate.options?.filter(isNotNil) || [],
allowMultiple: Boolean(pollCreate.allowMultiple),
};
}
export function processPollVote(
pollVote?: Proto.DataMessage.IPollVote | null
): ProcessedPollVote | undefined {
if (!pollVote) {
return undefined;
}
const targetAuthorAci = fromAciUuidBytesOrString(
pollVote.targetAuthorAciBinary,
undefined,
'PollVote.targetAuthorAci'
);
return {
targetAuthorAci,
targetTimestamp: pollVote.targetSentTimestamp?.toNumber(),
optionIndexes: pollVote.optionIndexes?.filter(isNotNil) || [],
voteCount: pollVote.voteCount || 0,
};
}
export function processPollTerminate(
pollTerminate?: Proto.DataMessage.IPollTerminate | null
): ProcessedPollTerminate | undefined {
if (!pollTerminate) {
return undefined;
}
return {
targetTimestamp: pollTerminate.targetSentTimestamp?.toNumber(),
};
}
export function processDelete(
del?: Proto.DataMessage.IDelete | null
): ProcessedDelete | undefined {
@@ -407,6 +457,9 @@ export function processDataMessage(
requiredProtocolVersion: dropNull(message.requiredProtocolVersion),
isViewOnce: Boolean(message.isViewOnce),
reaction: processReaction(message.reaction),
pollCreate: processPollCreate(message.pollCreate),
pollVote: processPollVote(message.pollVote),
pollTerminate: processPollTerminate(message.pollTerminate),
delete: processDelete(message.delete),
bodyRanges: filterAndClean(message.bodyRanges),
groupCallUpdate: dropNull(message.groupCallUpdate),