mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-05 06:33:57 +02:00
Support cloud view_as_messages forum setting.
This commit is contained in:
parent
43a8733fc7
commit
0ffda016da
10 changed files with 102 additions and 9 deletions
|
@ -4170,6 +4170,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
"lng_forum_create_topic" = "Create topic";
|
"lng_forum_create_topic" = "Create topic";
|
||||||
"lng_forum_discard_sure" = "Are you sure you want to discard this topic?";
|
"lng_forum_discard_sure" = "Are you sure you want to discard this topic?";
|
||||||
"lng_forum_view_as_messages" = "View as Messages";
|
"lng_forum_view_as_messages" = "View as Messages";
|
||||||
|
"lng_forum_view_as_topics" = "View as Topics";
|
||||||
"lng_forum_no_messages" = "No messages";
|
"lng_forum_no_messages" = "No messages";
|
||||||
"lng_forum_messages#one" = "{count} message";
|
"lng_forum_messages#one" = "{count} message";
|
||||||
"lng_forum_messages#other" = "{count} messages";
|
"lng_forum_messages#other" = "{count} messages";
|
||||||
|
|
|
@ -2326,6 +2326,14 @@ void Updates::feedUpdate(const MTPUpdate &update) {
|
||||||
}
|
}
|
||||||
} break;
|
} break;
|
||||||
|
|
||||||
|
case mtpc_updateChannelViewForumAsMessages: {
|
||||||
|
const auto &d = update.c_updateChannelViewForumAsMessages();
|
||||||
|
const auto id = ChannelId(d.vchannel_id());
|
||||||
|
if (const auto channel = session().data().channelLoaded(id)) {
|
||||||
|
channel->setViewAsMessagesFlag(mtpIsTrue(d.venabled()));
|
||||||
|
}
|
||||||
|
} break;
|
||||||
|
|
||||||
// Pinned message.
|
// Pinned message.
|
||||||
case mtpc_updatePinnedMessages: {
|
case mtpc_updatePinnedMessages: {
|
||||||
const auto &d = update.c_updatePinnedMessages();
|
const auto &d = update.c_updatePinnedMessages();
|
||||||
|
|
|
@ -475,6 +475,14 @@ void ChannelData::applyEditBanned(
|
||||||
session().changes().peerUpdated(this, flags);
|
session().changes().peerUpdated(this, flags);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ChannelData::setViewAsMessagesFlag(bool enabled) {
|
||||||
|
if (viewForumAsMessages() == enabled) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
setFlags((flags() & ~Flag::ViewAsMessages)
|
||||||
|
| (enabled ? Flag::ViewAsMessages : Flag()));
|
||||||
|
}
|
||||||
|
|
||||||
void ChannelData::markForbidden() {
|
void ChannelData::markForbidden() {
|
||||||
owner().processChat(MTP_channelForbidden(
|
owner().processChat(MTP_channelForbidden(
|
||||||
MTP_flags(isMegagroup()
|
MTP_flags(isMegagroup()
|
||||||
|
@ -998,7 +1006,8 @@ void ApplyChannelUpdate(
|
||||||
| Flag::AntiSpam
|
| Flag::AntiSpam
|
||||||
| Flag::Location
|
| Flag::Location
|
||||||
| Flag::ParticipantsHidden
|
| Flag::ParticipantsHidden
|
||||||
| Flag::CanGetStatistics;
|
| Flag::CanGetStatistics
|
||||||
|
| Flag::ViewAsMessages;
|
||||||
channel->setFlags((channel->flags() & ~mask)
|
channel->setFlags((channel->flags() & ~mask)
|
||||||
| (update.is_can_set_username() ? Flag::CanSetUsername : Flag())
|
| (update.is_can_set_username() ? Flag::CanSetUsername : Flag())
|
||||||
| (update.is_can_view_participants()
|
| (update.is_can_view_participants()
|
||||||
|
@ -1011,7 +1020,10 @@ void ApplyChannelUpdate(
|
||||||
| (update.is_participants_hidden()
|
| (update.is_participants_hidden()
|
||||||
? Flag::ParticipantsHidden
|
? Flag::ParticipantsHidden
|
||||||
: Flag())
|
: Flag())
|
||||||
| (update.is_can_view_stats() ? Flag::CanGetStatistics : Flag()));
|
| (update.is_can_view_stats() ? Flag::CanGetStatistics : Flag())
|
||||||
|
| (update.is_view_forum_as_messages()
|
||||||
|
? Flag::ViewAsMessages
|
||||||
|
: Flag()));
|
||||||
channel->setUserpicPhoto(update.vchat_photo());
|
channel->setUserpicPhoto(update.vchat_photo());
|
||||||
if (const auto migratedFrom = update.vmigrated_from_chat_id()) {
|
if (const auto migratedFrom = update.vmigrated_from_chat_id()) {
|
||||||
channel->addFlags(Flag::Megagroup);
|
channel->addFlags(Flag::Megagroup);
|
||||||
|
|
|
@ -63,6 +63,7 @@ enum class ChannelDataFlag {
|
||||||
HasActiveStories = (1 << 27),
|
HasActiveStories = (1 << 27),
|
||||||
HasUnreadStories = (1 << 28),
|
HasUnreadStories = (1 << 28),
|
||||||
CanGetStatistics = (1 << 29),
|
CanGetStatistics = (1 << 29),
|
||||||
|
ViewAsMessages = (1 << 30),
|
||||||
};
|
};
|
||||||
inline constexpr bool is_flag_type(ChannelDataFlag) { return true; };
|
inline constexpr bool is_flag_type(ChannelDataFlag) { return true; };
|
||||||
using ChannelDataFlags = base::flags<ChannelDataFlag>;
|
using ChannelDataFlags = base::flags<ChannelDataFlag>;
|
||||||
|
@ -233,6 +234,9 @@ public:
|
||||||
[[nodiscard]] bool hasStoriesHidden() const {
|
[[nodiscard]] bool hasStoriesHidden() const {
|
||||||
return flags() & Flag::StoriesHidden;
|
return flags() & Flag::StoriesHidden;
|
||||||
}
|
}
|
||||||
|
[[nodiscard]] bool viewForumAsMessages() const {
|
||||||
|
return flags() & Flag::ViewAsMessages;
|
||||||
|
}
|
||||||
|
|
||||||
[[nodiscard]] static ChatRestrictionsInfo KickedRestrictedRights(
|
[[nodiscard]] static ChatRestrictionsInfo KickedRestrictedRights(
|
||||||
not_null<PeerData*> participant);
|
not_null<PeerData*> participant);
|
||||||
|
@ -249,6 +253,7 @@ public:
|
||||||
not_null<PeerData*> participant,
|
not_null<PeerData*> participant,
|
||||||
ChatRestrictionsInfo oldRights,
|
ChatRestrictionsInfo oldRights,
|
||||||
ChatRestrictionsInfo newRights);
|
ChatRestrictionsInfo newRights);
|
||||||
|
void setViewAsMessagesFlag(bool enabled);
|
||||||
|
|
||||||
void markForbidden();
|
void markForbidden();
|
||||||
|
|
||||||
|
|
|
@ -4545,6 +4545,25 @@ void Session::applyStatsDcId(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Session::saveViewAsMessages(
|
||||||
|
not_null<Forum*> forum,
|
||||||
|
bool viewAsMessages) {
|
||||||
|
const auto channel = forum->channel();
|
||||||
|
if (const auto requestId = _viewAsMessagesRequests.take(channel)) {
|
||||||
|
_session->api().request(*requestId).cancel();
|
||||||
|
}
|
||||||
|
_viewAsMessagesRequests[channel] = _session->api().request(
|
||||||
|
MTPchannels_ToggleViewForumAsMessages(
|
||||||
|
channel->inputChannel,
|
||||||
|
MTP_bool(viewAsMessages))
|
||||||
|
).done([=] {
|
||||||
|
_viewAsMessagesRequests.remove(channel);
|
||||||
|
}).fail([=] {
|
||||||
|
_viewAsMessagesRequests.remove(channel);
|
||||||
|
}).send();
|
||||||
|
channel->setViewAsMessagesFlag(viewAsMessages);
|
||||||
|
}
|
||||||
|
|
||||||
void Session::webViewResultSent(WebViewResultSent &&sent) {
|
void Session::webViewResultSent(WebViewResultSent &&sent) {
|
||||||
return _webViewResultSent.fire(std::move(sent));
|
return _webViewResultSent.fire(std::move(sent));
|
||||||
}
|
}
|
||||||
|
|
|
@ -727,6 +727,8 @@ public:
|
||||||
void webViewResultSent(WebViewResultSent &&sent);
|
void webViewResultSent(WebViewResultSent &&sent);
|
||||||
[[nodiscard]] rpl::producer<WebViewResultSent> webViewResultSent() const;
|
[[nodiscard]] rpl::producer<WebViewResultSent> webViewResultSent() const;
|
||||||
|
|
||||||
|
void saveViewAsMessages(not_null<Forum*> forum, bool viewAsMessages);
|
||||||
|
|
||||||
[[nodiscard]] auto peerDecorationsUpdated() const
|
[[nodiscard]] auto peerDecorationsUpdated() const
|
||||||
-> rpl::producer<not_null<PeerData*>>;
|
-> rpl::producer<not_null<PeerData*>>;
|
||||||
|
|
||||||
|
@ -1022,6 +1024,9 @@ private:
|
||||||
rpl::event_stream<WebViewResultSent> _webViewResultSent;
|
rpl::event_stream<WebViewResultSent> _webViewResultSent;
|
||||||
|
|
||||||
rpl::event_stream<not_null<PeerData*>> _peerDecorationsUpdated;
|
rpl::event_stream<not_null<PeerData*>> _peerDecorationsUpdated;
|
||||||
|
base::flat_map<
|
||||||
|
not_null<ChannelData*>,
|
||||||
|
mtpRequestId> _viewAsMessagesRequests;
|
||||||
|
|
||||||
Groups _groups;
|
Groups _groups;
|
||||||
const std::unique_ptr<ChatFilters> _chatsFilters;
|
const std::unique_ptr<ChatFilters> _chatsFilters;
|
||||||
|
|
|
@ -1251,7 +1251,8 @@ void InnerWidget::selectByMouse(QPoint globalPosition) {
|
||||||
const auto selectedTopicJump = selected
|
const auto selectedTopicJump = selected
|
||||||
&& selected->lookupIsInTopicJump(
|
&& selected->lookupIsInTopicJump(
|
||||||
local.x(),
|
local.x(),
|
||||||
mouseY - offset - selected->top());
|
mouseY - offset - selected->top())
|
||||||
|
&& _controller->adaptive().isOneColumn();
|
||||||
if (_collapsedSelected != collapsedSelected
|
if (_collapsedSelected != collapsedSelected
|
||||||
|| _selected != selected
|
|| _selected != selected
|
||||||
|| _selectedTopicJump != selectedTopicJump) {
|
|| _selectedTopicJump != selectedTopicJump) {
|
||||||
|
@ -1293,7 +1294,8 @@ void InnerWidget::selectByMouse(QPoint globalPosition) {
|
||||||
const auto selectedTopicJump = (filteredSelected >= 0)
|
const auto selectedTopicJump = (filteredSelected >= 0)
|
||||||
&& _filterResults[filteredSelected].row->lookupIsInTopicJump(
|
&& _filterResults[filteredSelected].row->lookupIsInTopicJump(
|
||||||
local.x(),
|
local.x(),
|
||||||
mouseY - skip - _filterResults[filteredSelected].top);
|
mouseY - skip - _filterResults[filteredSelected].top)
|
||||||
|
&& _controller->adaptive().isOneColumn();
|
||||||
if (_filteredSelected != filteredSelected
|
if (_filteredSelected != filteredSelected
|
||||||
|| _selectedTopicJump != selectedTopicJump) {
|
|| _selectedTopicJump != selectedTopicJump) {
|
||||||
updateSelectedRow();
|
updateSelectedRow();
|
||||||
|
|
|
@ -520,18 +520,37 @@ void Widget::chosenRow(const ChosenRow &row) {
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
} else if (const auto topic = row.key.topic()) {
|
} else if (const auto topic = row.key.topic()) {
|
||||||
|
session().data().saveViewAsMessages(topic->forum(), false);
|
||||||
controller()->showThread(
|
controller()->showThread(
|
||||||
topic,
|
topic,
|
||||||
row.message.fullId.msg,
|
row.message.fullId.msg,
|
||||||
Window::SectionShow::Way::ClearStack);
|
Window::SectionShow::Way::ClearStack);
|
||||||
} else if (history && history->isForum() && !row.message.fullId) {
|
} else if (history
|
||||||
|
&& history->isForum()
|
||||||
|
&& !row.message.fullId
|
||||||
|
&& (!controller()->adaptive().isOneColumn()
|
||||||
|
|| !history->peer->forum()->channel()->viewForumAsMessages())) {
|
||||||
const auto forum = history->peer->forum();
|
const auto forum = history->peer->forum();
|
||||||
if (controller()->shownForum().current() == forum) {
|
if (controller()->shownForum().current() == forum) {
|
||||||
controller()->closeForum();
|
controller()->closeForum();
|
||||||
} else {
|
return;
|
||||||
controller()->showForum(
|
}
|
||||||
forum,
|
controller()->showForum(
|
||||||
Window::SectionShow().withChildColumn());
|
forum,
|
||||||
|
Window::SectionShow().withChildColumn());
|
||||||
|
if (forum->channel()->viewForumAsMessages()) {
|
||||||
|
controller()->showThread(
|
||||||
|
history,
|
||||||
|
ShowAtUnreadMsgId,
|
||||||
|
Window::SectionShow::Way::ClearStack);
|
||||||
|
} else if (!controller()->adaptive().isOneColumn()) {
|
||||||
|
const auto item = history->chatListMessage();
|
||||||
|
if (const auto topic = item ? item->topic() : nullptr) {
|
||||||
|
controller()->showThread(
|
||||||
|
topic,
|
||||||
|
ShowAtUnreadMsgId,
|
||||||
|
Window::SectionShow::Way::ClearStack);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
} else if (history) {
|
} else if (history) {
|
||||||
|
|
|
@ -2808,6 +2808,7 @@ void History::applyDialog(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
channel->setViewAsMessagesFlag(data.is_view_forum_as_messages());
|
||||||
}
|
}
|
||||||
owner().notifySettings().apply(
|
owner().notifySettings().apply(
|
||||||
MTP_notifyPeer(data.vpeer()),
|
MTP_notifyPeer(data.vpeer()),
|
||||||
|
|
|
@ -281,6 +281,7 @@ private:
|
||||||
void addGiftPremium();
|
void addGiftPremium();
|
||||||
void addCreateTopic();
|
void addCreateTopic();
|
||||||
void addViewAsMessages();
|
void addViewAsMessages();
|
||||||
|
void addViewAsTopics();
|
||||||
void addSearchTopics();
|
void addSearchTopics();
|
||||||
void addDeleteTopic();
|
void addDeleteTopic();
|
||||||
void addVideoChat();
|
void addVideoChat();
|
||||||
|
@ -1147,10 +1148,29 @@ void Filler::addViewAsMessages() {
|
||||||
const auto peer = _peer;
|
const auto peer = _peer;
|
||||||
const auto controller = _controller;
|
const auto controller = _controller;
|
||||||
_addAction(tr::lng_forum_view_as_messages(tr::now), [=] {
|
_addAction(tr::lng_forum_view_as_messages(tr::now), [=] {
|
||||||
|
if (const auto forum = peer->forum()) {
|
||||||
|
peer->owner().saveViewAsMessages(forum, true);
|
||||||
|
}
|
||||||
controller->showPeerHistory(peer->id);
|
controller->showPeerHistory(peer->id);
|
||||||
}, &st::menuIconViewReplies);
|
}, &st::menuIconViewReplies);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Filler::addViewAsTopics() {
|
||||||
|
if (!_peer
|
||||||
|
|| !_peer->isForum()
|
||||||
|
|| !_controller->adaptive().isOneColumn()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const auto peer = _peer;
|
||||||
|
const auto controller = _controller;
|
||||||
|
_addAction(tr::lng_forum_view_as_topics(tr::now), [=] {
|
||||||
|
if (const auto forum = peer->forum()) {
|
||||||
|
peer->owner().saveViewAsMessages(forum, false);
|
||||||
|
controller->showForum(forum);
|
||||||
|
}
|
||||||
|
}, &st::menuIconViewReplies);
|
||||||
|
}
|
||||||
|
|
||||||
void Filler::addSearchTopics() {
|
void Filler::addSearchTopics() {
|
||||||
const auto forum = _peer ? _peer->forum() : nullptr;
|
const auto forum = _peer ? _peer->forum() : nullptr;
|
||||||
if (!forum) {
|
if (!forum) {
|
||||||
|
@ -1235,6 +1255,7 @@ void Filler::fillContextMenuActions() {
|
||||||
void Filler::fillHistoryActions() {
|
void Filler::fillHistoryActions() {
|
||||||
addToggleMuteSubmenu(true);
|
addToggleMuteSubmenu(true);
|
||||||
addInfo();
|
addInfo();
|
||||||
|
addViewAsTopics();
|
||||||
addStoryArchive();
|
addStoryArchive();
|
||||||
addSupportInfo();
|
addSupportInfo();
|
||||||
addManageChat();
|
addManageChat();
|
||||||
|
|
Loading…
Add table
Reference in a new issue