Files
23rd 2b89fb9d40 [poll-shared] Added Polls section.
- Introduced SharedMediaType::Poll and registered poll messages
as shared media in data_media_types.

- Added Data::PollMessagesViewer — a producer that loaded poll
message slices for a given history/topic/monoforum peer.
(data_poll_messages.cpp/h)

- Implemented Info::Polls::ListWidget and ListMemento — a new content
widget that rendered poll messages using HistoryView::ListWidget
with a custom chat theme, similar to existing shared media sections.

- Connected the new section into info_memento, info_controller,
info_media_buttons, and info_media_widget so it appeared as a button
in the Shared Media panel.
2026-03-28 10:29:08 +03:00

70 lines
1.9 KiB
C++

/*
This file is part of Telegram Desktop,
the official desktop application for the Telegram messaging service.
For license and copyright information please follow this link:
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
*/
#include "data/data_poll_messages.h"
#include "data/data_messages.h"
#include "data/data_shared_media.h"
#include "data/data_sparse_ids.h"
#include "data/data_chat.h"
#include "history/history.h"
#include "main/main_session.h"
#include "storage/storage_shared_media.h"
namespace Data {
rpl::producer<MessagesSlice> PollMessagesViewer(
not_null<Main::Session*> session,
not_null<History*> history,
MsgId topicRootId,
PeerId monoforumPeerId,
MessagePosition aroundId,
int limitBefore,
int limitAfter) {
const auto peerId = history->peer->id;
const auto migrateFrom = history->peer->migrateFrom();
const auto migratedPeerId = migrateFrom ? migrateFrom->id : PeerId(0);
const auto messageId = ((aroundId.fullId.msg == ShowAtTheEndMsgId)
|| (aroundId == MaxMessagePosition))
? (ServerMaxMsgId - 1)
: (aroundId.fullId.peer == peerId)
? aroundId.fullId.msg
: (aroundId.fullId.msg
? (aroundId.fullId.msg - ServerMaxMsgId)
: (ServerMaxMsgId - 1));
const auto key = SharedMediaMergedKey(
SparseIdsMergedSlice::Key(
peerId,
topicRootId,
monoforumPeerId,
migratedPeerId,
messageId),
Storage::SharedMediaType::Poll);
return SharedMediaMergedViewer(
session,
key,
limitBefore,
limitAfter
) | rpl::map([=](SparseIdsMergedSlice &&slice) {
auto result = MessagesSlice();
result.fullCount = slice.fullCount();
result.skippedAfter = slice.skippedAfter();
result.skippedBefore = slice.skippedBefore();
const auto count = slice.size();
result.ids.reserve(count);
if (const auto msgId = slice.nearest(messageId)) {
result.nearestToAround = *msgId;
}
for (auto i = 0; i != count; ++i) {
result.ids.push_back(slice[i]);
}
return result;
});
}
} // namespace Data