Allow forwarding polls to monoforums.

This commit is contained in:
John Preston 2025-06-02 18:19:16 +04:00
parent 6c80d443b9
commit dd8fdfc3d4
9 changed files with 60 additions and 33 deletions

View file

@ -156,12 +156,6 @@ bool CanSendAnyOf(
}
return false;
} else if (const auto channel = peer->asChannel()) {
if (channel->isMonoforum()) {
rights &= ~ChatRestriction::SendPolls;
if (!rights) {
return false;
}
}
using Flag = ChannelDataFlag;
const auto allowed = channel->amIn()
|| ((channel->flags() & Flag::HasLink)

View file

@ -668,6 +668,8 @@ bool PeerData::canCreatePolls() const {
&& !user->isSupport()
&& !user->isRepliesChat()
&& !user->isVerifyCodes());
} else if (isMonoforum()) {
return false;
}
return Data::CanSend(this, ChatRestriction::SendPolls);
}

View file

@ -274,12 +274,6 @@ inline auto DefaultRestrictionValue(
| Flag::Forbidden
| Flag::Creator
| Flag::Broadcast;
if (channel->isMonoforum()) {
rights &= ~ChatRestriction::SendPolls;
if (!rights) {
return rpl::single(false);
}
}
return rpl::combine(
PeerFlagsValue(channel, mask),
AdminRightValue(

View file

@ -1464,11 +1464,7 @@ bool InnerWidget::isRowActive(
}
return false;
} else if (const auto sublist = entry.key.sublist()) {
if (!sublist->parentChat()) {
// In case we're viewing a Saved Messages sublist,
// we want to highlight the Saved Messages row as active.
return key.history() && key.peer()->isSelf();
}
return key.history() && key.history() == sublist->owningHistory();
}
return false;
}
@ -1909,9 +1905,14 @@ RowDescriptor InnerWidget::computeChatPreviewRow() const {
auto result = computeChosenRow();
if (const auto peer = result.key.peer()) {
const auto topicId = _pressedTopicJump
? _pressedTopicJumpRootId // #TODO monoforums
: 0;
if (const auto topic = peer->forumTopicFor(topicId)) {
? _pressedTopicJumpRootId
: MsgId();
const auto sublistPeerId = _pressedTopicJump
? _pressedSublistJumpPeerId
: PeerId();
if (const auto sublist = peer->monoforumSublistFor(sublistPeerId)) {
return { sublist, FullMsgId() };
} else if (const auto topic = peer->forumTopicFor(topicId)) {
return { topic, FullMsgId() };
}
}
@ -2422,6 +2423,7 @@ void InnerWidget::mousePressReleased(
auto collapsedPressed = _collapsedPressed;
setCollapsedPressed(-1);
const auto pressedTopicRootId = _pressedTopicJumpRootId;
const auto pressedSublistPeerId = _pressedSublistJumpPeerId;
const auto pressedTopicJump = _pressedTopicJump;
const auto pressedRightButton = _pressedRightButton;
auto pressed = _pressed;
@ -2505,7 +2507,10 @@ void InnerWidget::mousePressReleased(
} else if (pressedRightButton && peerSearchPressed >= 0) {
showSponsoredMenu(peerSearchPressed, globalPosition);
} else {
chooseRow(modifiers, pressedTopicRootId);
chooseRow(
modifiers,
pressedTopicRootId,
pressedSublistPeerId);
}
}
}
@ -2557,6 +2562,9 @@ void InnerWidget::setPressed(
: nullptr;
const auto item = history ? history->chatListMessage() : nullptr;
_pressedTopicJumpRootId = item ? item->topicRootId() : MsgId();
_pressedSublistJumpPeerId = item
? item->sublistPeerId()
: PeerId();
}
}
}
@ -2603,6 +2611,9 @@ void InnerWidget::setFilteredPressed(
: nullptr;
const auto item = history ? history->chatListMessage() : nullptr;
_pressedTopicJumpRootId = item ? item->topicRootId() : MsgId();
_pressedSublistJumpPeerId = item
? item->sublistPeerId()
: PeerId();
}
}
}
@ -4763,7 +4774,8 @@ bool InnerWidget::isUserpicPressOnWide() const {
bool InnerWidget::chooseRow(
Qt::KeyboardModifiers modifiers,
MsgId pressedTopicRootId) {
MsgId pressedTopicRootId,
PeerId pressedSublistPeerId) {
if (chooseHashtag()) {
return true;
} else if (_selectedMorePosts) {
@ -4805,12 +4817,9 @@ bool InnerWidget::chooseRow(
if (!chosen.message.fullId) {
if (const auto history = chosen.key.history()) {
if (history->peer->forum()) {
if (pressedTopicRootId) {
chosen.message.fullId = {
history->peer->id,
pressedTopicRootId,
};
}
chosen.topicJumpRootId = pressedTopicRootId;
} else if (history->peer->amMonoforumAdmin()) {
chosen.sublistJumpPeerId = pressedSublistPeerId;
}
}
}

View file

@ -84,6 +84,8 @@ enum class ChatTypeFilter : uchar;
struct ChosenRow {
Key key;
Data::MessagePosition message;
MsgId topicJumpRootId;
PeerId sublistJumpPeerId;
QByteArray sponsoredRandomId;
bool userpicClick : 1 = false;
bool filteredRow : 1 = false;
@ -163,7 +165,8 @@ public:
void chatPreviewShown(bool shown, RowDescriptor row = {});
bool chooseRow(
Qt::KeyboardModifiers modifiers = {},
MsgId pressedTopicRootId = {});
MsgId pressedTopicRootId = {},
PeerId pressedSublistPeerId = {});
void scrollToEntry(const RowDescriptor &entry);
@ -543,6 +546,7 @@ private:
Row *_selected = nullptr;
Row *_pressed = nullptr;
MsgId _pressedTopicJumpRootId;
PeerId _pressedSublistJumpPeerId;
bool _selectedTopicJump = false;
bool _pressedTopicJump = false;

View file

@ -860,7 +860,10 @@ void Widget::chosenRow(const ChosenRow &row) {
const auto history = row.key.history();
const auto topicJump = history
? history->peer->forumTopicFor(row.message.fullId.msg)
? history->peer->forumTopicFor(row.topicJumpRootId)
: nullptr;
const auto sublistJump = history
? history->peer->monoforumSublistFor(row.sublistJumpPeerId)
: nullptr;
if (topicJump) {
@ -880,6 +883,16 @@ void Widget::chosenRow(const ChosenRow &row) {
Window::SectionShow::Way::ClearStack);
}
return;
} else if (sublistJump) {
if (row.newWindow) {
controller()->showInNewWindow(Window::SeparateId(sublistJump));
} else {
controller()->showThread(
sublistJump,
ShowAtUnreadMsgId,
Window::SectionShow::Way::ClearStack);
}
return;
} else if (const auto topic = row.key.topic()) {
auto params = Window::SectionShow(
Window::SectionShow::Way::ClearStack);

View file

@ -267,11 +267,18 @@ int MessageView::countWidth() const {
auto result = 0;
if (!_senderCache.isEmpty()) {
result += _senderCache.maxWidth();
if (!_imagesCache.empty()) {
if (!_imagesCache.empty() && !_leftIcon) {
result += st::dialogsMiniPreviewSkip
+ st::dialogsMiniPreviewRight;
}
}
if (_leftIcon) {
const auto w = _leftIcon->icon.icon.width();
result += w
+ (_imagesCache.empty()
? _leftIcon->skipText
: _leftIcon->skipMedia);
}
if (!_imagesCache.empty()) {
result += (_imagesCache.size()
* (st::dialogsMiniPreview + st::dialogsMiniPreviewSkip))

View file

@ -2126,7 +2126,10 @@ void HistoryWidget::setupDirectMessageButton() {
}, _directMessage->lifetime());
_directMessage->setClickedCallback([=] {
if (const auto channel = _peer ? _peer->asChannel() : nullptr) {
if (const auto monoforum = channel->monoforumLink()) {
if (channel->invitePeekExpires()) {
controller()->showToast(
tr::lng_channel_invite_private(tr::now));
} else if (const auto monoforum = channel->monoforumLink()) {
controller()->showPeerHistory(
monoforum,
Window::SectionShow::Way::Forward);
@ -6038,7 +6041,7 @@ bool HistoryWidget::showSendingFilesError(
return true;
}
MsgId HistoryWidget::resolveReplyToTopicRootId() { // #TODO monoforums
MsgId HistoryWidget::resolveReplyToTopicRootId() {
Expects(_peer != nullptr);
const auto replyToInfo = replyTo();

View file

@ -660,6 +660,7 @@ bool SubsectionTabs::switchTo(
}
_shadow->setParent(parent);
_shadow->show();
_refreshed.fire({});
return true;
}