Poll: Handle unread votes update (#6951)

This commit is contained in:
zubiden 2026-06-01 01:15:32 +02:00 committed by Alexander Zinchuk
parent ec9add5c67
commit c4b1bad481
3 changed files with 47 additions and 2 deletions

View File

@ -474,7 +474,9 @@ export function updater(update: Update) {
}, },
}); });
} else if (update instanceof GramJs.UpdateMessagePoll) { } else if (update instanceof GramJs.UpdateMessagePoll) {
const { pollId, poll, results } = update; const {
pollId, poll, results, peer, msgId, topMsgId,
} = update;
const apiPoll = poll && buildPoll(poll); const apiPoll = poll && buildPoll(poll);
const pollResults = buildPollResults(results); const pollResults = buildPollResults(results);
@ -483,6 +485,16 @@ export function updater(update: Update) {
pollId: pollId.toString(), pollId: pollId.toString(),
pollUpdate: omitUndefined({ summary: apiPoll, results: pollResults }), pollUpdate: omitUndefined({ summary: apiPoll, results: pollResults }),
}); });
if (peer && msgId && results.hasUnreadVotes && !results.min) {
sendApiUpdate({
'@type': 'updateMessagePollUnread',
chatId: getApiChatIdFromMtpPeer(peer),
messageId: msgId,
threadId: topMsgId || MAIN_THREAD_ID,
pollId: pollId.toString(),
});
}
} else if (update instanceof GramJs.UpdateMessagePollVote) { } else if (update instanceof GramJs.UpdateMessagePollVote) {
sendApiUpdate({ sendApiUpdate({
'@type': 'updateMessagePollVote', '@type': 'updateMessagePollVote',

View File

@ -389,6 +389,14 @@ export type ApiUpdateMessagePoll = {
pollUpdate: Partial<ApiMessagePoll>; pollUpdate: Partial<ApiMessagePoll>;
}; };
export type ApiUpdateMessagePollUnread = {
'@type': 'updateMessagePollUnread';
chatId: string;
messageId: number;
threadId: ThreadId;
pollId: string;
};
export type ApiUpdateMessagePollVote = { export type ApiUpdateMessagePollVote = {
'@type': 'updateMessagePollVote'; '@type': 'updateMessagePollVote';
pollId: string; pollId: string;
@ -937,7 +945,8 @@ export type ApiUpdate = (
| ApiUpdateChatPinned | ApiUpdatePinnedMessageIds | | ApiUpdateChatPinned | ApiUpdatePinnedMessageIds |
ApiUpdateChatListType | ApiUpdateChatFolder | ApiUpdateChatFoldersOrder | ApiUpdateRecommendedChatFolders | ApiUpdateChatListType | ApiUpdateChatFolder | ApiUpdateChatFoldersOrder | ApiUpdateRecommendedChatFolders |
ApiUpdateNewMessage | ApiUpdateMessage | ApiUpdateThreadInfo | ApiUpdateCommonBoxMessages | ApiUpdatePasskeyOption | ApiUpdateNewMessage | ApiUpdateMessage | ApiUpdateThreadInfo | ApiUpdateCommonBoxMessages | ApiUpdatePasskeyOption |
ApiUpdateDeleteMessages | ApiUpdateMessagePoll | ApiUpdateMessagePollVote | ApiUpdateDeleteHistory | ApiUpdateDeleteMessages | ApiUpdateMessagePoll | ApiUpdateMessagePollUnread | ApiUpdateMessagePollVote |
ApiUpdateDeleteHistory |
ApiDeleteParticipantHistory | ApiUpdateMessageSendSucceeded | ApiUpdateMessageSendFailed | ApiDeleteParticipantHistory | ApiUpdateMessageSendSucceeded | ApiUpdateMessageSendFailed |
ApiUpdateServiceNotification | ApiDeleteContact | ApiUpdateUser | ApiUpdateUserStatus | ApiUpdateServiceNotification | ApiDeleteContact | ApiUpdateUser | ApiUpdateUserStatus |
ApiUpdateUserFullInfo | ApiUpdateVideoProcessingPending | ApiUpdatePeerSettings | ApiUpdateUserAlreadyAuthorized | ApiUpdateUserFullInfo | ApiUpdateVideoProcessingPending | ApiUpdatePeerSettings | ApiUpdateUserAlreadyAuthorized |

View File

@ -64,6 +64,7 @@ import {
updateQuickReplyMessage, updateQuickReplyMessage,
updateScheduledMessage, updateScheduledMessage,
} from '../../reducers'; } from '../../reducers';
import { addUnreadPollVotes } from '../../reducers/polls';
import { addUnreadReactions, removeUnreadReactions } from '../../reducers/reactions'; import { addUnreadReactions, removeUnreadReactions } from '../../reducers/reactions';
import { updateTabState } from '../../reducers/tabs'; import { updateTabState } from '../../reducers/tabs';
import { import {
@ -923,6 +924,29 @@ addActionHandler('apiUpdate', (global, actions, update): ActionReturnType => {
break; break;
} }
case 'updateMessagePollUnread': {
const { chatId, messageId, threadId } = update;
const readState = selectThreadReadState(global, chatId, threadId);
if (!readState?.unreadPollVotes) {
actions.loadUnreadPollVotes({ chatId, threadId });
break;
}
if (readState.unreadPollVotes.includes(messageId)) break;
// We can't calculate threads without local messages, so reload instead.
if (!selectChatMessage(global, chatId, messageId)) {
actions.loadUnreadPollVotes({ chatId, threadId });
break;
}
global = addUnreadPollVotes({ global, chatId, ids: [messageId] });
setGlobal(global);
break;
}
case 'updateServiceNotification': { case 'updateServiceNotification': {
const { message } = update; const { message } = update;