2017-03-27 12:24:38 +00:00
|
|
|
/*
|
|
|
|
This file is part of Telegram Desktop,
|
2018-01-03 10:23:14 +00:00
|
|
|
the official desktop application for the Telegram messaging service.
|
2017-03-27 12:24:38 +00:00
|
|
|
|
2018-01-03 10:23:14 +00:00
|
|
|
For license and copyright information please follow this link:
|
|
|
|
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
2017-03-27 12:24:38 +00:00
|
|
|
*/
|
2019-06-06 10:21:40 +00:00
|
|
|
#include "window/window_session_controller.h"
|
2017-03-27 12:24:38 +00:00
|
|
|
|
2019-03-17 08:14:31 +00:00
|
|
|
#include "boxes/peers/edit_peer_info_box.h"
|
2019-09-03 15:24:51 +00:00
|
|
|
#include "window/window_controller.h"
|
2017-04-07 18:10:49 +00:00
|
|
|
#include "window/main_window.h"
|
2020-03-03 12:07:22 +00:00
|
|
|
#include "window/window_filters_menu.h"
|
2017-09-16 16:53:41 +00:00
|
|
|
#include "info/info_memento.h"
|
2018-09-05 19:05:49 +00:00
|
|
|
#include "info/info_controller.h"
|
2018-01-13 12:45:11 +00:00
|
|
|
#include "history/history.h"
|
2018-01-11 19:33:26 +00:00
|
|
|
#include "history/history_item.h"
|
2018-01-17 16:21:01 +00:00
|
|
|
#include "history/view/history_view_element.h"
|
2019-04-15 11:54:03 +00:00
|
|
|
//#include "history/feed/history_feed_section.h" // #feed
|
2019-03-26 08:54:51 +00:00
|
|
|
#include "data/data_media_types.h"
|
2018-01-21 14:49:42 +00:00
|
|
|
#include "data/data_session.h"
|
2019-04-15 11:54:03 +00:00
|
|
|
#include "data/data_folder.h"
|
2019-01-04 11:09:48 +00:00
|
|
|
#include "data/data_channel.h"
|
|
|
|
#include "data/data_chat.h"
|
2020-03-18 09:19:58 +00:00
|
|
|
#include "data/data_chat_filters.h"
|
2018-03-18 08:51:14 +00:00
|
|
|
#include "passport/passport_form_controller.h"
|
2019-08-16 12:44:20 +00:00
|
|
|
#include "chat_helpers/tabbed_selector.h"
|
2018-12-30 12:50:23 +00:00
|
|
|
#include "core/shortcuts.h"
|
2019-07-10 17:28:33 +00:00
|
|
|
#include "base/unixtime.h"
|
2018-01-21 14:49:42 +00:00
|
|
|
#include "boxes/calendar_box.h"
|
2017-04-09 18:06:06 +00:00
|
|
|
#include "mainwidget.h"
|
2017-09-15 17:34:41 +00:00
|
|
|
#include "mainwindow.h"
|
2019-07-24 11:45:24 +00:00
|
|
|
#include "main/main_session.h"
|
2017-08-01 11:43:50 +00:00
|
|
|
#include "apiwrap.h"
|
2018-11-15 15:36:04 +00:00
|
|
|
#include "support/support_helper.h"
|
2019-09-13 06:06:02 +00:00
|
|
|
#include "facades.h"
|
2018-01-21 14:49:42 +00:00
|
|
|
#include "styles/style_window.h"
|
|
|
|
#include "styles/style_dialogs.h"
|
2017-04-07 18:10:49 +00:00
|
|
|
|
|
|
|
namespace Window {
|
2018-12-30 12:50:23 +00:00
|
|
|
namespace {
|
|
|
|
|
|
|
|
constexpr auto kMaxChatEntryHistorySize = 50;
|
|
|
|
|
|
|
|
} // namespace
|
2017-04-07 18:10:49 +00:00
|
|
|
|
2018-02-21 21:17:36 +00:00
|
|
|
DateClickHandler::DateClickHandler(Dialogs::Key chat, QDate date)
|
|
|
|
: _chat(chat)
|
|
|
|
, _date(date) {
|
|
|
|
}
|
|
|
|
|
|
|
|
void DateClickHandler::setDate(QDate date) {
|
|
|
|
_date = date;
|
|
|
|
}
|
|
|
|
|
2018-07-09 18:13:48 +00:00
|
|
|
void DateClickHandler::onClick(ClickContext context) const {
|
2019-06-06 10:21:40 +00:00
|
|
|
App::wnd()->sessionController()->showJumpToDate(_chat, _date);
|
2018-02-21 21:17:36 +00:00
|
|
|
}
|
|
|
|
|
2019-07-24 11:45:24 +00:00
|
|
|
SessionNavigation::SessionNavigation(not_null<Main::Session*> session)
|
2019-06-06 10:21:40 +00:00
|
|
|
: _session(session) {
|
2019-01-18 12:27:37 +00:00
|
|
|
}
|
|
|
|
|
2019-07-24 11:45:24 +00:00
|
|
|
Main::Session &SessionNavigation::session() const {
|
2019-01-18 12:27:37 +00:00
|
|
|
return *_session;
|
|
|
|
}
|
|
|
|
|
2019-06-06 10:21:40 +00:00
|
|
|
void SessionNavigation::showPeerInfo(
|
2019-01-18 12:27:37 +00:00
|
|
|
PeerId peerId,
|
|
|
|
const SectionShow ¶ms) {
|
|
|
|
//if (Adaptive::ThreeColumn()
|
|
|
|
// && !_session->settings().thirdSectionInfoEnabled()) {
|
|
|
|
// _session->settings().setThirdSectionInfoEnabled(true);
|
|
|
|
// _session->saveSettingsDelayed();
|
|
|
|
//}
|
|
|
|
showSection(Info::Memento(peerId), params);
|
|
|
|
}
|
|
|
|
|
2019-06-06 10:21:40 +00:00
|
|
|
void SessionNavigation::showPeerInfo(
|
2019-01-18 12:27:37 +00:00
|
|
|
not_null<PeerData*> peer,
|
|
|
|
const SectionShow ¶ms) {
|
|
|
|
showPeerInfo(peer->id, params);
|
|
|
|
}
|
|
|
|
|
2019-06-06 10:21:40 +00:00
|
|
|
void SessionNavigation::showPeerInfo(
|
2019-01-18 12:27:37 +00:00
|
|
|
not_null<History*> history,
|
|
|
|
const SectionShow ¶ms) {
|
|
|
|
showPeerInfo(history->peer->id, params);
|
|
|
|
}
|
|
|
|
|
2019-06-06 10:21:40 +00:00
|
|
|
void SessionNavigation::showSettings(
|
2019-01-18 12:27:37 +00:00
|
|
|
Settings::Type type,
|
|
|
|
const SectionShow ¶ms) {
|
|
|
|
showSection(
|
|
|
|
Info::Memento(
|
|
|
|
Info::Settings::Tag{ _session->user() },
|
|
|
|
Info::Section(type)),
|
|
|
|
params);
|
|
|
|
}
|
|
|
|
|
2019-06-06 10:21:40 +00:00
|
|
|
void SessionNavigation::showSettings(const SectionShow ¶ms) {
|
2019-01-18 12:27:37 +00:00
|
|
|
showSettings(Settings::Type::Main, params);
|
|
|
|
}
|
|
|
|
|
2020-01-15 11:53:42 +00:00
|
|
|
void SessionNavigation::showPollResults(
|
|
|
|
not_null<PollData*> poll,
|
|
|
|
FullMsgId contextId,
|
|
|
|
const SectionShow ¶ms) {
|
|
|
|
showSection(Info::Memento(poll, contextId), params);
|
|
|
|
}
|
|
|
|
|
2019-06-06 10:21:40 +00:00
|
|
|
SessionController::SessionController(
|
2019-07-24 11:45:24 +00:00
|
|
|
not_null<Main::Session*> session,
|
2019-09-03 15:24:51 +00:00
|
|
|
not_null<Controller*> window)
|
2019-06-06 10:21:40 +00:00
|
|
|
: SessionNavigation(session)
|
2019-08-16 12:44:20 +00:00
|
|
|
, _window(window)
|
|
|
|
, _tabbedSelector(
|
2019-09-03 15:24:51 +00:00
|
|
|
std::make_unique<ChatHelpers::TabbedSelector>(
|
|
|
|
_window->widget(),
|
|
|
|
this)) {
|
2019-01-18 12:27:37 +00:00
|
|
|
init();
|
2019-03-17 08:14:31 +00:00
|
|
|
|
2019-06-06 11:59:00 +00:00
|
|
|
subscribe(session->api().fullPeerUpdated(), [=](PeerData *peer) {
|
2019-03-17 08:14:31 +00:00
|
|
|
if (peer == _showEditPeer) {
|
|
|
|
_showEditPeer = nullptr;
|
2019-07-25 18:55:11 +00:00
|
|
|
Ui::show(Box<EditPeerInfoBox>(this, peer));
|
2019-03-17 08:14:31 +00:00
|
|
|
}
|
|
|
|
});
|
2019-04-24 10:15:10 +00:00
|
|
|
|
|
|
|
session->data().chatsListChanges(
|
|
|
|
) | rpl::filter([=](Data::Folder *folder) {
|
|
|
|
return (folder != nullptr)
|
|
|
|
&& (folder == _openedFolder.current())
|
2020-02-07 09:43:12 +00:00
|
|
|
&& folder->chatsList()->indexed()->empty();
|
2019-04-24 10:15:10 +00:00
|
|
|
}) | rpl::start_with_next([=](Data::Folder *folder) {
|
|
|
|
folder->updateChatListSortPosition();
|
|
|
|
closeFolder();
|
|
|
|
}, lifetime());
|
2020-03-18 09:19:58 +00:00
|
|
|
|
|
|
|
session->data().chatsFilters().changed(
|
|
|
|
) | rpl::start_with_next([=] {
|
2020-03-18 14:10:22 +00:00
|
|
|
checkOpenedFilter();
|
2020-03-18 09:19:58 +00:00
|
|
|
crl::on_main(session, [=] {
|
|
|
|
refreshFiltersMenu();
|
|
|
|
});
|
|
|
|
}, session->lifetime());
|
2019-03-17 08:14:31 +00:00
|
|
|
}
|
|
|
|
|
2019-09-03 15:24:51 +00:00
|
|
|
not_null<::MainWindow*> SessionController::widget() const {
|
|
|
|
return _window->widget();
|
|
|
|
}
|
|
|
|
|
2019-08-16 12:44:20 +00:00
|
|
|
auto SessionController::tabbedSelector() const
|
|
|
|
-> not_null<ChatHelpers::TabbedSelector*> {
|
|
|
|
return _tabbedSelector.get();
|
|
|
|
}
|
|
|
|
|
|
|
|
void SessionController::takeTabbedSelectorOwnershipFrom(
|
|
|
|
not_null<QWidget*> parent) {
|
|
|
|
if (_tabbedSelector->parent() == parent) {
|
2019-09-03 15:24:51 +00:00
|
|
|
if (const auto chats = widget()->chatsWidget()) {
|
2019-08-16 12:44:20 +00:00
|
|
|
chats->returnTabbedSelector();
|
|
|
|
}
|
|
|
|
if (_tabbedSelector->parent() == parent) {
|
|
|
|
_tabbedSelector->hide();
|
2019-09-03 15:24:51 +00:00
|
|
|
_tabbedSelector->setParent(widget());
|
2019-08-16 12:44:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool SessionController::hasTabbedSelectorOwnership() const {
|
2019-09-03 15:24:51 +00:00
|
|
|
return (_tabbedSelector->parent() == widget());
|
2019-08-16 12:44:20 +00:00
|
|
|
}
|
|
|
|
|
2019-06-06 10:21:40 +00:00
|
|
|
void SessionController::showEditPeerBox(PeerData *peer) {
|
2019-03-17 08:14:31 +00:00
|
|
|
_showEditPeer = peer;
|
2019-06-06 11:59:00 +00:00
|
|
|
session().api().requestFullPeer(peer);
|
2019-01-18 12:27:37 +00:00
|
|
|
}
|
|
|
|
|
2019-06-06 10:21:40 +00:00
|
|
|
void SessionController::init() {
|
2019-01-18 12:27:37 +00:00
|
|
|
if (session().supportMode()) {
|
2018-12-30 12:50:23 +00:00
|
|
|
initSupportMode();
|
2018-11-15 15:36:04 +00:00
|
|
|
}
|
2018-01-21 14:49:42 +00:00
|
|
|
}
|
|
|
|
|
2019-06-06 10:21:40 +00:00
|
|
|
void SessionController::initSupportMode() {
|
2019-01-18 12:27:37 +00:00
|
|
|
session().supportHelper().registerWindow(this);
|
2018-12-30 12:50:23 +00:00
|
|
|
|
|
|
|
Shortcuts::Requests(
|
|
|
|
) | rpl::start_with_next([=](not_null<Shortcuts::Request*> request) {
|
|
|
|
using C = Shortcuts::Command;
|
|
|
|
|
|
|
|
request->check(C::SupportHistoryBack) && request->handle([=] {
|
|
|
|
return chatEntryHistoryMove(-1);
|
|
|
|
});
|
|
|
|
request->check(C::SupportHistoryForward) && request->handle([=] {
|
|
|
|
return chatEntryHistoryMove(1);
|
|
|
|
});
|
|
|
|
}, lifetime());
|
|
|
|
}
|
|
|
|
|
2020-03-03 12:07:22 +00:00
|
|
|
void SessionController::toggleFiltersMenu(bool enabled) {
|
|
|
|
if (!enabled == !_filters) {
|
|
|
|
return;
|
|
|
|
} else if (enabled) {
|
2020-03-06 11:37:48 +00:00
|
|
|
_filters = std::make_unique<FiltersMenu>(
|
|
|
|
widget()->bodyWidget(),
|
|
|
|
this);
|
2020-03-03 12:07:22 +00:00
|
|
|
} else {
|
|
|
|
_filters = nullptr;
|
|
|
|
}
|
2020-03-18 12:14:45 +00:00
|
|
|
_filtersMenuChanged.fire({});
|
2020-03-03 12:07:22 +00:00
|
|
|
}
|
|
|
|
|
2020-03-18 09:19:58 +00:00
|
|
|
void SessionController::refreshFiltersMenu() {
|
|
|
|
const auto enabled = !session().data().chatsFilters().list().empty();
|
|
|
|
if (enabled != Global::DialogsFiltersEnabled()) {
|
|
|
|
Global::SetDialogsFiltersEnabled(enabled);
|
|
|
|
session().saveSettingsDelayed();
|
|
|
|
toggleFiltersMenu(enabled);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-18 12:14:45 +00:00
|
|
|
rpl::producer<> SessionController::filtersMenuChanged() const {
|
|
|
|
return _filtersMenuChanged.events();
|
|
|
|
}
|
|
|
|
|
2020-03-18 14:10:22 +00:00
|
|
|
void SessionController::checkOpenedFilter() {
|
|
|
|
if (const auto filterId = activeChatsFilterCurrent()) {
|
|
|
|
const auto &list = session().data().chatsFilters().list();
|
|
|
|
const auto i = ranges::find(list, filterId, &Data::ChatFilter::id);
|
|
|
|
if (i == end(list)) {
|
|
|
|
setActiveChatsFilter(0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-06-06 10:21:40 +00:00
|
|
|
bool SessionController::uniqueChatsInSearchResults() const {
|
2019-04-24 10:15:10 +00:00
|
|
|
return session().supportMode()
|
|
|
|
&& !session().settings().supportAllSearchResults()
|
|
|
|
&& !searchInChat.current();
|
|
|
|
}
|
|
|
|
|
2019-06-06 10:21:40 +00:00
|
|
|
void SessionController::openFolder(not_null<Data::Folder*> folder) {
|
2020-05-12 08:18:52 +00:00
|
|
|
if (_openedFolder.current() != folder) {
|
|
|
|
resetFakeUnreadWhileOpened();
|
|
|
|
}
|
2020-03-20 13:12:13 +00:00
|
|
|
setActiveChatsFilter(0);
|
2019-04-24 10:15:10 +00:00
|
|
|
_openedFolder = folder.get();
|
|
|
|
}
|
|
|
|
|
2019-06-06 10:21:40 +00:00
|
|
|
void SessionController::closeFolder() {
|
2019-04-24 10:15:10 +00:00
|
|
|
_openedFolder = nullptr;
|
|
|
|
}
|
|
|
|
|
2019-06-06 10:21:40 +00:00
|
|
|
const rpl::variable<Data::Folder*> &SessionController::openedFolder() const {
|
2019-04-24 10:15:10 +00:00
|
|
|
return _openedFolder;
|
|
|
|
}
|
|
|
|
|
2019-06-06 10:21:40 +00:00
|
|
|
void SessionController::setActiveChatEntry(Dialogs::RowDescriptor row) {
|
2020-03-23 10:09:27 +00:00
|
|
|
const auto was = _activeChatEntry.current().key.history();
|
|
|
|
const auto now = row.key.history();
|
|
|
|
if (was && was != now) {
|
|
|
|
was->setFakeUnreadWhileOpened(false);
|
2020-03-20 15:19:55 +00:00
|
|
|
}
|
2018-01-22 16:42:25 +00:00
|
|
|
_activeChatEntry = row;
|
2020-03-23 10:09:27 +00:00
|
|
|
if (now) {
|
|
|
|
now->setFakeUnreadWhileOpened(true);
|
2020-03-20 15:19:55 +00:00
|
|
|
}
|
2019-01-18 12:27:37 +00:00
|
|
|
if (session().supportMode()) {
|
2018-12-30 12:50:23 +00:00
|
|
|
pushToChatEntryHistory(row);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-12 08:18:52 +00:00
|
|
|
void SessionController::resetFakeUnreadWhileOpened() {
|
|
|
|
if (const auto history = _activeChatEntry.current().key.history()) {
|
|
|
|
history->setFakeUnreadWhileOpened(false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-06-06 10:21:40 +00:00
|
|
|
bool SessionController::chatEntryHistoryMove(int steps) {
|
2018-12-30 12:50:23 +00:00
|
|
|
if (_chatEntryHistory.empty()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
const auto position = _chatEntryHistoryPosition + steps;
|
|
|
|
if (!base::in_range(position, 0, int(_chatEntryHistory.size()))) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
_chatEntryHistoryPosition = position;
|
|
|
|
return jumpToChatListEntry(_chatEntryHistory[position]);
|
|
|
|
}
|
|
|
|
|
2019-06-06 10:21:40 +00:00
|
|
|
bool SessionController::jumpToChatListEntry(Dialogs::RowDescriptor row) {
|
2018-12-30 12:50:23 +00:00
|
|
|
if (const auto history = row.key.history()) {
|
|
|
|
Ui::showPeerHistory(history, row.fullId.msg);
|
|
|
|
return true;
|
2019-04-15 11:54:03 +00:00
|
|
|
//} else if (const auto feed = row.key.feed()) { // #feed
|
2019-06-06 11:59:00 +00:00
|
|
|
// if (const auto item = session().data().message(row.fullId)) {
|
2019-04-15 11:54:03 +00:00
|
|
|
// showSection(HistoryFeed::Memento(feed, item->position()));
|
|
|
|
// } else {
|
|
|
|
// showSection(HistoryFeed::Memento(feed));
|
|
|
|
// }
|
2018-12-30 12:50:23 +00:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-06-06 10:21:40 +00:00
|
|
|
void SessionController::pushToChatEntryHistory(Dialogs::RowDescriptor row) {
|
2018-12-30 12:50:23 +00:00
|
|
|
if (!_chatEntryHistory.empty()
|
|
|
|
&& _chatEntryHistory[_chatEntryHistoryPosition] == row) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
_chatEntryHistory.resize(++_chatEntryHistoryPosition);
|
|
|
|
_chatEntryHistory.push_back(row);
|
|
|
|
if (_chatEntryHistory.size() > kMaxChatEntryHistorySize) {
|
|
|
|
_chatEntryHistory.pop_front();
|
|
|
|
--_chatEntryHistoryPosition;
|
|
|
|
}
|
2018-01-22 16:42:25 +00:00
|
|
|
}
|
|
|
|
|
2019-06-06 10:21:40 +00:00
|
|
|
void SessionController::setActiveChatEntry(Dialogs::Key key) {
|
2018-02-16 15:46:24 +00:00
|
|
|
setActiveChatEntry({ key, FullMsgId() });
|
2018-01-22 16:42:25 +00:00
|
|
|
}
|
|
|
|
|
2019-06-06 10:21:40 +00:00
|
|
|
Dialogs::RowDescriptor SessionController::activeChatEntryCurrent() const {
|
2018-01-22 16:42:25 +00:00
|
|
|
return _activeChatEntry.current();
|
|
|
|
}
|
|
|
|
|
2019-06-06 10:21:40 +00:00
|
|
|
Dialogs::Key SessionController::activeChatCurrent() const {
|
2018-01-22 16:42:25 +00:00
|
|
|
return activeChatEntryCurrent().key;
|
|
|
|
}
|
|
|
|
|
2019-06-06 10:21:40 +00:00
|
|
|
auto SessionController::activeChatEntryChanges() const
|
2018-01-22 16:42:25 +00:00
|
|
|
-> rpl::producer<Dialogs::RowDescriptor> {
|
|
|
|
return _activeChatEntry.changes();
|
|
|
|
}
|
|
|
|
|
2019-06-06 10:21:40 +00:00
|
|
|
rpl::producer<Dialogs::Key> SessionController::activeChatChanges() const {
|
2018-01-22 16:42:25 +00:00
|
|
|
return activeChatEntryChanges(
|
|
|
|
) | rpl::map([](const Dialogs::RowDescriptor &value) {
|
|
|
|
return value.key;
|
|
|
|
}) | rpl::distinct_until_changed();
|
|
|
|
}
|
|
|
|
|
2019-06-06 10:21:40 +00:00
|
|
|
auto SessionController::activeChatEntryValue() const
|
2018-01-22 16:42:25 +00:00
|
|
|
-> rpl::producer<Dialogs::RowDescriptor> {
|
|
|
|
return _activeChatEntry.value();
|
|
|
|
}
|
|
|
|
|
2019-06-06 10:21:40 +00:00
|
|
|
rpl::producer<Dialogs::Key> SessionController::activeChatValue() const {
|
2018-01-22 16:42:25 +00:00
|
|
|
return activeChatEntryValue(
|
|
|
|
) | rpl::map([](const Dialogs::RowDescriptor &value) {
|
|
|
|
return value.key;
|
|
|
|
}) | rpl::distinct_until_changed();
|
|
|
|
}
|
|
|
|
|
2019-06-06 10:21:40 +00:00
|
|
|
void SessionController::enableGifPauseReason(GifPauseReason reason) {
|
2017-04-07 18:10:49 +00:00
|
|
|
if (!(_gifPauseReasons & reason)) {
|
|
|
|
auto notify = (static_cast<int>(_gifPauseReasons) < static_cast<int>(reason));
|
|
|
|
_gifPauseReasons |= reason;
|
|
|
|
if (notify) {
|
|
|
|
_gifPauseLevelChanged.notify();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-06-06 10:21:40 +00:00
|
|
|
void SessionController::disableGifPauseReason(GifPauseReason reason) {
|
2017-04-07 18:10:49 +00:00
|
|
|
if (_gifPauseReasons & reason) {
|
2017-08-31 16:28:58 +00:00
|
|
|
_gifPauseReasons &= ~reason;
|
|
|
|
if (_gifPauseReasons < reason) {
|
2017-04-07 18:10:49 +00:00
|
|
|
_gifPauseLevelChanged.notify();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-06-06 10:21:40 +00:00
|
|
|
bool SessionController::isGifPausedAtLeastFor(GifPauseReason reason) const {
|
2017-04-07 18:10:49 +00:00
|
|
|
if (reason == GifPauseReason::Any) {
|
2019-09-03 15:24:51 +00:00
|
|
|
return (_gifPauseReasons != 0) || !widget()->isActive();
|
2017-04-07 18:10:49 +00:00
|
|
|
}
|
2019-09-03 15:24:51 +00:00
|
|
|
return (static_cast<int>(_gifPauseReasons) >= 2 * static_cast<int>(reason)) || !widget()->isActive();
|
2017-04-07 18:10:49 +00:00
|
|
|
}
|
|
|
|
|
2019-06-06 10:21:40 +00:00
|
|
|
int SessionController::dialogsSmallColumnWidth() const {
|
2017-05-13 12:02:07 +00:00
|
|
|
return st::dialogsPadding.x() + st::dialogsPhotoSize + st::dialogsPadding.x();
|
|
|
|
}
|
|
|
|
|
2019-06-06 10:21:40 +00:00
|
|
|
int SessionController::minimalThreeColumnWidth() const {
|
2017-09-16 16:53:41 +00:00
|
|
|
return st::columnMinimalWidthLeft
|
|
|
|
+ st::columnMinimalWidthMain
|
|
|
|
+ st::columnMinimalWidthThird;
|
|
|
|
}
|
|
|
|
|
2019-06-06 10:21:40 +00:00
|
|
|
bool SessionController::forceWideDialogs() const {
|
2017-09-19 18:59:10 +00:00
|
|
|
if (dialogsListDisplayForced().value()) {
|
|
|
|
return true;
|
|
|
|
} else if (dialogsListFocused().value()) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return !App::main()->isMainSectionShown();
|
|
|
|
}
|
|
|
|
|
2020-03-06 11:37:48 +00:00
|
|
|
auto SessionController::computeColumnLayout() const -> ColumnLayout {
|
2017-04-09 18:06:06 +00:00
|
|
|
auto layout = Adaptive::WindowLayout::OneColumn;
|
|
|
|
|
2020-03-06 11:37:48 +00:00
|
|
|
auto bodyWidth = widget()->bodyWidget()->width() - filtersWidth();
|
2017-09-19 18:59:10 +00:00
|
|
|
auto dialogsWidth = 0, chatWidth = 0, thirdWidth = 0;
|
|
|
|
|
2018-04-07 08:47:08 +00:00
|
|
|
auto useOneColumnLayout = [&] {
|
2017-09-16 16:53:41 +00:00
|
|
|
auto minimalNormal = st::columnMinimalWidthLeft
|
|
|
|
+ st::columnMinimalWidthMain;
|
|
|
|
if (bodyWidth < minimalNormal) {
|
2017-04-09 18:06:06 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
};
|
2017-05-17 11:50:00 +00:00
|
|
|
|
2018-04-07 08:47:08 +00:00
|
|
|
auto useNormalLayout = [&] {
|
2017-09-16 16:53:41 +00:00
|
|
|
// Used if useSmallColumnLayout() == false.
|
|
|
|
if (bodyWidth < minimalThreeColumnWidth()) {
|
|
|
|
return true;
|
|
|
|
}
|
2019-01-18 12:27:37 +00:00
|
|
|
if (!session().settings().tabbedSelectorSectionEnabled()
|
|
|
|
&& !session().settings().thirdSectionInfoEnabled()) {
|
2017-09-16 16:53:41 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
};
|
|
|
|
|
2017-04-09 18:06:06 +00:00
|
|
|
if (useOneColumnLayout()) {
|
2017-05-17 11:50:00 +00:00
|
|
|
dialogsWidth = chatWidth = bodyWidth;
|
2017-09-16 16:53:41 +00:00
|
|
|
} else if (useNormalLayout()) {
|
2017-04-09 18:06:06 +00:00
|
|
|
layout = Adaptive::WindowLayout::Normal;
|
2017-11-12 16:50:58 +00:00
|
|
|
dialogsWidth = countDialogsWidthFromRatio(bodyWidth);
|
2017-09-19 18:59:10 +00:00
|
|
|
accumulate_min(dialogsWidth, bodyWidth - st::columnMinimalWidthMain);
|
2017-05-17 11:50:00 +00:00
|
|
|
chatWidth = bodyWidth - dialogsWidth;
|
2017-09-16 16:53:41 +00:00
|
|
|
} else {
|
|
|
|
layout = Adaptive::WindowLayout::ThreeColumn;
|
2017-11-12 16:50:58 +00:00
|
|
|
dialogsWidth = countDialogsWidthFromRatio(bodyWidth);
|
|
|
|
thirdWidth = countThirdColumnWidthFromRatio(bodyWidth);
|
|
|
|
auto shrink = shrinkDialogsAndThirdColumns(
|
2017-09-16 16:53:41 +00:00
|
|
|
dialogsWidth,
|
2017-11-12 16:50:58 +00:00
|
|
|
thirdWidth,
|
|
|
|
bodyWidth);
|
|
|
|
dialogsWidth = shrink.dialogsWidth;
|
|
|
|
thirdWidth = shrink.thirdWidth;
|
|
|
|
|
2017-09-16 16:53:41 +00:00
|
|
|
chatWidth = bodyWidth - dialogsWidth - thirdWidth;
|
2017-04-09 18:06:06 +00:00
|
|
|
}
|
2017-09-16 16:53:41 +00:00
|
|
|
return { bodyWidth, dialogsWidth, chatWidth, thirdWidth, layout };
|
2017-04-09 18:06:06 +00:00
|
|
|
}
|
|
|
|
|
2019-06-06 10:21:40 +00:00
|
|
|
int SessionController::countDialogsWidthFromRatio(int bodyWidth) const {
|
2019-01-18 12:27:37 +00:00
|
|
|
auto result = qRound(bodyWidth * session().settings().dialogsWidthRatio());
|
2017-11-12 16:50:58 +00:00
|
|
|
accumulate_max(result, st::columnMinimalWidthLeft);
|
2017-12-12 10:38:59 +00:00
|
|
|
// accumulate_min(result, st::columnMaximalWidthLeft);
|
2017-11-12 16:50:58 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2019-06-06 10:21:40 +00:00
|
|
|
int SessionController::countThirdColumnWidthFromRatio(int bodyWidth) const {
|
2019-01-18 12:27:37 +00:00
|
|
|
auto result = session().settings().thirdColumnWidth();
|
2017-11-12 16:50:58 +00:00
|
|
|
accumulate_max(result, st::columnMinimalWidthThird);
|
|
|
|
accumulate_min(result, st::columnMaximalWidthThird);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2019-06-06 10:21:40 +00:00
|
|
|
SessionController::ShrinkResult SessionController::shrinkDialogsAndThirdColumns(
|
2017-11-12 16:50:58 +00:00
|
|
|
int dialogsWidth,
|
|
|
|
int thirdWidth,
|
|
|
|
int bodyWidth) const {
|
|
|
|
auto chatWidth = st::columnMinimalWidthMain;
|
|
|
|
if (dialogsWidth + thirdWidth + chatWidth <= bodyWidth) {
|
|
|
|
return { dialogsWidth, thirdWidth };
|
|
|
|
}
|
|
|
|
auto thirdWidthNew = ((bodyWidth - chatWidth) * thirdWidth)
|
|
|
|
/ (dialogsWidth + thirdWidth);
|
|
|
|
auto dialogsWidthNew = ((bodyWidth - chatWidth) * dialogsWidth)
|
|
|
|
/ (dialogsWidth + thirdWidth);
|
|
|
|
if (thirdWidthNew < st::columnMinimalWidthThird) {
|
|
|
|
thirdWidthNew = st::columnMinimalWidthThird;
|
|
|
|
dialogsWidthNew = bodyWidth - thirdWidthNew - chatWidth;
|
|
|
|
Assert(dialogsWidthNew >= st::columnMinimalWidthLeft);
|
|
|
|
} else if (dialogsWidthNew < st::columnMinimalWidthLeft) {
|
|
|
|
dialogsWidthNew = st::columnMinimalWidthLeft;
|
|
|
|
thirdWidthNew = bodyWidth - dialogsWidthNew - chatWidth;
|
|
|
|
Assert(thirdWidthNew >= st::columnMinimalWidthThird);
|
|
|
|
}
|
|
|
|
return { dialogsWidthNew, thirdWidthNew };
|
|
|
|
}
|
|
|
|
|
2019-06-06 10:21:40 +00:00
|
|
|
bool SessionController::canShowThirdSection() const {
|
2017-04-09 18:06:06 +00:00
|
|
|
auto currentLayout = computeColumnLayout();
|
2017-11-16 16:43:52 +00:00
|
|
|
auto minimalExtendBy = minimalThreeColumnWidth()
|
2017-09-16 16:53:41 +00:00
|
|
|
- currentLayout.bodyWidth;
|
2019-09-03 15:24:51 +00:00
|
|
|
return (minimalExtendBy <= widget()->maximalExtendBy());
|
2017-05-17 11:50:00 +00:00
|
|
|
}
|
|
|
|
|
2019-06-06 10:21:40 +00:00
|
|
|
bool SessionController::canShowThirdSectionWithoutResize() const {
|
2017-09-19 10:32:34 +00:00
|
|
|
auto currentWidth = computeColumnLayout().bodyWidth;
|
|
|
|
return currentWidth >= minimalThreeColumnWidth();
|
|
|
|
}
|
|
|
|
|
2019-06-06 10:21:40 +00:00
|
|
|
bool SessionController::takeThirdSectionFromLayer() {
|
2017-09-19 10:32:34 +00:00
|
|
|
return App::wnd()->takeThirdSectionFromLayer();
|
|
|
|
}
|
|
|
|
|
2019-06-06 10:21:40 +00:00
|
|
|
void SessionController::resizeForThirdSection() {
|
2017-11-14 08:15:14 +00:00
|
|
|
if (Adaptive::ThreeColumn()) {
|
2017-05-17 11:50:00 +00:00
|
|
|
return;
|
2017-04-09 18:06:06 +00:00
|
|
|
}
|
2017-09-16 16:53:41 +00:00
|
|
|
|
2017-11-14 08:15:14 +00:00
|
|
|
auto layout = computeColumnLayout();
|
2017-09-16 16:53:41 +00:00
|
|
|
auto tabbedSelectorSectionEnabled =
|
2019-01-18 12:27:37 +00:00
|
|
|
session().settings().tabbedSelectorSectionEnabled();
|
2017-09-16 16:53:41 +00:00
|
|
|
auto thirdSectionInfoEnabled =
|
2019-01-18 12:27:37 +00:00
|
|
|
session().settings().thirdSectionInfoEnabled();
|
|
|
|
session().settings().setTabbedSelectorSectionEnabled(false);
|
|
|
|
session().settings().setThirdSectionInfoEnabled(false);
|
2017-09-16 16:53:41 +00:00
|
|
|
|
2017-11-16 16:43:52 +00:00
|
|
|
auto wanted = countThirdColumnWidthFromRatio(layout.bodyWidth);
|
|
|
|
auto minimal = st::columnMinimalWidthThird;
|
|
|
|
auto extendBy = wanted;
|
|
|
|
auto extendedBy = [&] {
|
|
|
|
// Best - extend by third column without moving the window.
|
|
|
|
// Next - extend by minimal third column without moving.
|
|
|
|
// Next - show third column inside the window without moving.
|
|
|
|
// Last - extend with moving.
|
2019-09-03 15:24:51 +00:00
|
|
|
if (widget()->canExtendNoMove(wanted)) {
|
|
|
|
return widget()->tryToExtendWidthBy(wanted);
|
|
|
|
} else if (widget()->canExtendNoMove(minimal)) {
|
2017-11-16 16:43:52 +00:00
|
|
|
extendBy = minimal;
|
2019-09-03 15:24:51 +00:00
|
|
|
return widget()->tryToExtendWidthBy(minimal);
|
2017-11-16 16:43:52 +00:00
|
|
|
} else if (layout.bodyWidth >= minimalThreeColumnWidth()) {
|
|
|
|
return 0;
|
|
|
|
}
|
2019-09-03 15:24:51 +00:00
|
|
|
return widget()->tryToExtendWidthBy(minimal);
|
2017-11-16 16:43:52 +00:00
|
|
|
}();
|
|
|
|
if (extendedBy) {
|
2019-01-18 12:27:37 +00:00
|
|
|
if (extendBy != session().settings().thirdColumnWidth()) {
|
|
|
|
session().settings().setThirdColumnWidth(extendBy);
|
2017-11-16 16:43:52 +00:00
|
|
|
}
|
|
|
|
auto newBodyWidth = layout.bodyWidth + extendedBy;
|
2019-01-18 12:27:37 +00:00
|
|
|
auto currentRatio = session().settings().dialogsWidthRatio();
|
|
|
|
session().settings().setDialogsWidthRatio(
|
2017-11-16 16:43:52 +00:00
|
|
|
(currentRatio * layout.bodyWidth) / newBodyWidth);
|
|
|
|
}
|
|
|
|
auto savedValue = (extendedBy == extendBy) ? -1 : extendedBy;
|
2019-01-18 12:27:37 +00:00
|
|
|
session().settings().setThirdSectionExtendedBy(savedValue);
|
2017-09-16 16:53:41 +00:00
|
|
|
|
2019-01-18 12:27:37 +00:00
|
|
|
session().settings().setTabbedSelectorSectionEnabled(
|
2017-09-16 16:53:41 +00:00
|
|
|
tabbedSelectorSectionEnabled);
|
2019-01-18 12:27:37 +00:00
|
|
|
session().settings().setThirdSectionInfoEnabled(
|
2017-09-16 16:53:41 +00:00
|
|
|
thirdSectionInfoEnabled);
|
|
|
|
}
|
|
|
|
|
2019-06-06 10:21:40 +00:00
|
|
|
void SessionController::closeThirdSection() {
|
2019-09-03 15:24:51 +00:00
|
|
|
auto newWindowSize = widget()->size();
|
2017-09-16 16:53:41 +00:00
|
|
|
auto layout = computeColumnLayout();
|
|
|
|
if (layout.windowLayout == Adaptive::WindowLayout::ThreeColumn) {
|
2019-09-03 15:24:51 +00:00
|
|
|
auto noResize = widget()->isFullScreen()
|
|
|
|
|| widget()->isMaximized();
|
2019-01-18 12:27:37 +00:00
|
|
|
auto savedValue = session().settings().thirdSectionExtendedBy();
|
2017-11-16 16:43:52 +00:00
|
|
|
auto extendedBy = (savedValue == -1)
|
|
|
|
? layout.thirdWidth
|
|
|
|
: savedValue;
|
2017-09-16 16:53:41 +00:00
|
|
|
auto newBodyWidth = noResize
|
|
|
|
? layout.bodyWidth
|
2017-11-16 16:43:52 +00:00
|
|
|
: (layout.bodyWidth - extendedBy);
|
2019-01-18 12:27:37 +00:00
|
|
|
auto currentRatio = session().settings().dialogsWidthRatio();
|
|
|
|
session().settings().setDialogsWidthRatio(
|
2017-11-16 16:43:52 +00:00
|
|
|
(currentRatio * layout.bodyWidth) / newBodyWidth);
|
2017-09-16 16:53:41 +00:00
|
|
|
newWindowSize = QSize(
|
2019-09-03 15:24:51 +00:00
|
|
|
widget()->width() + (newBodyWidth - layout.bodyWidth),
|
|
|
|
widget()->height());
|
2017-09-16 16:53:41 +00:00
|
|
|
}
|
2019-01-18 12:27:37 +00:00
|
|
|
session().settings().setTabbedSelectorSectionEnabled(false);
|
|
|
|
session().settings().setThirdSectionInfoEnabled(false);
|
|
|
|
session().saveSettingsDelayed();
|
2019-09-03 15:24:51 +00:00
|
|
|
if (widget()->size() != newWindowSize) {
|
|
|
|
widget()->resize(newWindowSize);
|
2017-09-16 16:53:41 +00:00
|
|
|
} else {
|
|
|
|
updateColumnLayout();
|
2017-04-09 18:06:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-06-06 10:21:40 +00:00
|
|
|
void SessionController::showJumpToDate(Dialogs::Key chat, QDate requestedDate) {
|
2018-02-21 21:17:36 +00:00
|
|
|
const auto currentPeerDate = [&] {
|
|
|
|
if (const auto history = chat.history()) {
|
2017-08-01 11:43:50 +00:00
|
|
|
if (history->scrollTopItem) {
|
2018-02-03 19:52:35 +00:00
|
|
|
return history->scrollTopItem->dateTime().date();
|
2018-02-21 21:17:36 +00:00
|
|
|
} else if (history->loadedAtTop()
|
|
|
|
&& !history->isEmpty()
|
|
|
|
&& history->peer->migrateFrom()) {
|
2019-01-18 12:27:37 +00:00
|
|
|
if (const auto migrated = history->owner().historyLoaded(history->peer->migrateFrom())) {
|
2017-08-01 11:43:50 +00:00
|
|
|
if (migrated->scrollTopItem) {
|
|
|
|
// We're up in the migrated history.
|
|
|
|
// So current date is the date of first message here.
|
2018-02-03 19:52:35 +00:00
|
|
|
return history->blocks.front()->messages.front()->dateTime().date();
|
2017-08-01 11:43:50 +00:00
|
|
|
}
|
|
|
|
}
|
2019-01-15 11:57:45 +00:00
|
|
|
} else if (history->chatListTimeId() != 0) {
|
2019-07-10 17:28:33 +00:00
|
|
|
return base::unixtime::parse(history->chatListTimeId()).date();
|
2017-08-01 11:43:50 +00:00
|
|
|
}
|
2019-04-15 11:54:03 +00:00
|
|
|
//} else if (const auto feed = chat.feed()) { // #feed
|
|
|
|
// if (chatScrollPosition(feed)) { // #TODO feeds save position
|
2018-02-21 21:17:36 +00:00
|
|
|
|
2019-04-15 11:54:03 +00:00
|
|
|
// } else if (feed->chatListTimeId() != 0) {
|
2019-07-10 17:28:33 +00:00
|
|
|
// return base::unixtime::parse(feed->chatListTimeId()).date();
|
2019-04-15 11:54:03 +00:00
|
|
|
// }
|
2017-08-01 11:43:50 +00:00
|
|
|
}
|
2019-05-28 12:33:42 +00:00
|
|
|
return QDate();
|
|
|
|
}();
|
2018-02-21 21:17:36 +00:00
|
|
|
const auto maxPeerDate = [](Dialogs::Key chat) {
|
|
|
|
if (auto history = chat.history()) {
|
|
|
|
if (const auto channel = history->peer->migrateTo()) {
|
2019-01-18 12:27:37 +00:00
|
|
|
history = channel->owner().historyLoaded(channel);
|
2018-02-21 21:17:36 +00:00
|
|
|
}
|
2019-01-15 11:57:45 +00:00
|
|
|
if (history && history->chatListTimeId() != 0) {
|
2019-07-10 17:28:33 +00:00
|
|
|
return base::unixtime::parse(history->chatListTimeId()).date();
|
2017-08-01 11:43:50 +00:00
|
|
|
}
|
2019-04-15 11:54:03 +00:00
|
|
|
//} else if (const auto feed = chat.feed()) { // #feed
|
|
|
|
// if (feed->chatListTimeId() != 0) {
|
2019-07-10 17:28:33 +00:00
|
|
|
// return base::unixtime::parse(feed->chatListTimeId()).date();
|
2019-04-15 11:54:03 +00:00
|
|
|
// }
|
2017-08-01 11:43:50 +00:00
|
|
|
}
|
|
|
|
return QDate::currentDate();
|
|
|
|
};
|
2018-02-21 21:17:36 +00:00
|
|
|
const auto minPeerDate = [](Dialogs::Key chat) {
|
2017-11-30 12:50:13 +00:00
|
|
|
const auto startDate = [] {
|
|
|
|
// Telegram was launched in August 2013 :)
|
|
|
|
return QDate(2013, 8, 1);
|
|
|
|
};
|
2018-02-21 21:17:36 +00:00
|
|
|
if (const auto history = chat.history()) {
|
|
|
|
if (const auto chat = history->peer->migrateFrom()) {
|
2019-01-18 12:27:37 +00:00
|
|
|
if (const auto history = chat->owner().historyLoaded(chat)) {
|
2018-02-21 21:17:36 +00:00
|
|
|
if (history->loadedAtTop()) {
|
|
|
|
if (!history->isEmpty()) {
|
|
|
|
return history->blocks.front()->messages.front()->dateTime().date();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
return startDate();
|
2017-11-30 12:50:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-08-01 11:43:50 +00:00
|
|
|
if (history->loadedAtTop()) {
|
2017-11-30 12:50:13 +00:00
|
|
|
if (!history->isEmpty()) {
|
2018-02-03 19:52:35 +00:00
|
|
|
return history->blocks.front()->messages.front()->dateTime().date();
|
2017-08-01 11:43:50 +00:00
|
|
|
}
|
2017-11-30 12:50:13 +00:00
|
|
|
return QDate::currentDate();
|
2017-08-01 11:43:50 +00:00
|
|
|
}
|
2019-04-15 11:54:03 +00:00
|
|
|
//} else if (const auto feed = chat.feed()) { // #feed
|
|
|
|
// return startDate();
|
2017-08-01 11:43:50 +00:00
|
|
|
}
|
2017-11-30 12:50:13 +00:00
|
|
|
return startDate();
|
2017-08-01 11:43:50 +00:00
|
|
|
};
|
2019-05-28 12:33:42 +00:00
|
|
|
const auto highlighted = !requestedDate.isNull()
|
|
|
|
? requestedDate
|
|
|
|
: !currentPeerDate.isNull()
|
|
|
|
? currentPeerDate
|
|
|
|
: QDate::currentDate();
|
2018-02-21 21:17:36 +00:00
|
|
|
const auto month = highlighted;
|
|
|
|
auto callback = [=](const QDate &date) {
|
2019-01-18 12:27:37 +00:00
|
|
|
session().api().jumpToDate(chat, date);
|
2017-11-30 12:50:13 +00:00
|
|
|
};
|
|
|
|
auto box = Box<CalendarBox>(
|
|
|
|
month,
|
|
|
|
highlighted,
|
|
|
|
std::move(callback));
|
2018-02-21 21:17:36 +00:00
|
|
|
box->setMinDate(minPeerDate(chat));
|
|
|
|
box->setMaxDate(maxPeerDate(chat));
|
2019-09-08 20:12:48 +00:00
|
|
|
box->setBeginningButton(true);
|
2017-08-01 11:43:50 +00:00
|
|
|
Ui::show(std::move(box));
|
|
|
|
}
|
|
|
|
|
2019-06-06 10:21:40 +00:00
|
|
|
void SessionController::showPassportForm(const Passport::FormRequest &request) {
|
2018-04-06 18:47:29 +00:00
|
|
|
_passportForm = std::make_unique<Passport::FormController>(
|
|
|
|
this,
|
|
|
|
request);
|
|
|
|
_passportForm->show();
|
2018-03-18 08:51:14 +00:00
|
|
|
}
|
|
|
|
|
2019-06-06 10:21:40 +00:00
|
|
|
void SessionController::clearPassportForm() {
|
2018-04-06 18:47:29 +00:00
|
|
|
_passportForm = nullptr;
|
2018-03-31 01:45:40 +00:00
|
|
|
}
|
|
|
|
|
2019-06-06 10:21:40 +00:00
|
|
|
void SessionController::updateColumnLayout() {
|
2017-09-16 16:53:41 +00:00
|
|
|
App::main()->updateColumnLayout();
|
|
|
|
}
|
|
|
|
|
2019-06-06 10:21:40 +00:00
|
|
|
void SessionController::showPeerHistory(
|
2017-09-16 16:53:41 +00:00
|
|
|
PeerId peerId,
|
2017-10-03 13:05:58 +00:00
|
|
|
const SectionShow ¶ms,
|
|
|
|
MsgId msgId) {
|
|
|
|
App::main()->ui_showPeerHistory(
|
2017-09-20 10:23:57 +00:00
|
|
|
peerId,
|
2017-10-03 13:05:58 +00:00
|
|
|
params,
|
|
|
|
msgId);
|
2017-09-16 16:53:41 +00:00
|
|
|
}
|
|
|
|
|
2019-06-06 10:21:40 +00:00
|
|
|
void SessionController::showPeerHistory(
|
2017-09-15 17:34:41 +00:00
|
|
|
not_null<PeerData*> peer,
|
2017-10-03 13:05:58 +00:00
|
|
|
const SectionShow ¶ms,
|
|
|
|
MsgId msgId) {
|
2017-09-20 10:23:57 +00:00
|
|
|
showPeerHistory(
|
|
|
|
peer->id,
|
2017-10-03 13:05:58 +00:00
|
|
|
params,
|
|
|
|
msgId);
|
2017-09-16 16:53:41 +00:00
|
|
|
}
|
|
|
|
|
2019-06-06 10:21:40 +00:00
|
|
|
void SessionController::showPeerHistory(
|
2017-09-16 16:53:41 +00:00
|
|
|
not_null<History*> history,
|
2017-10-03 13:05:58 +00:00
|
|
|
const SectionShow ¶ms,
|
|
|
|
MsgId msgId) {
|
2017-09-20 10:23:57 +00:00
|
|
|
showPeerHistory(
|
|
|
|
history->peer->id,
|
2017-10-03 13:05:58 +00:00
|
|
|
params,
|
|
|
|
msgId);
|
2017-09-16 16:53:41 +00:00
|
|
|
}
|
|
|
|
|
2019-06-06 10:21:40 +00:00
|
|
|
void SessionController::showSection(
|
2017-09-16 16:53:41 +00:00
|
|
|
SectionMemento &&memento,
|
2017-10-03 13:05:58 +00:00
|
|
|
const SectionShow ¶ms) {
|
2018-06-06 19:56:35 +00:00
|
|
|
if (!params.thirdColumn && App::wnd()->showSectionInExistingLayer(
|
2017-10-03 13:05:58 +00:00
|
|
|
&memento,
|
2018-06-06 19:56:35 +00:00
|
|
|
params)) {
|
2017-10-03 13:05:58 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
App::main()->showSection(std::move(memento), params);
|
2017-09-15 17:34:41 +00:00
|
|
|
}
|
|
|
|
|
2019-06-06 10:21:40 +00:00
|
|
|
void SessionController::showBackFromStack(const SectionShow ¶ms) {
|
2017-10-03 13:05:58 +00:00
|
|
|
chats()->showBackFromStack(params);
|
2017-09-15 17:34:41 +00:00
|
|
|
}
|
|
|
|
|
2019-06-06 10:21:40 +00:00
|
|
|
void SessionController::showSpecialLayer(
|
2019-09-18 11:19:05 +00:00
|
|
|
object_ptr<Ui::LayerWidget> &&layer,
|
2017-09-20 10:23:57 +00:00
|
|
|
anim::type animated) {
|
|
|
|
App::wnd()->showSpecialLayer(std::move(layer), animated);
|
2017-09-15 17:34:41 +00:00
|
|
|
}
|
|
|
|
|
2019-06-06 10:21:40 +00:00
|
|
|
void SessionController::removeLayerBlackout() {
|
2018-09-06 14:58:43 +00:00
|
|
|
App::wnd()->ui_removeLayerBlackout();
|
|
|
|
}
|
|
|
|
|
2019-06-06 10:21:40 +00:00
|
|
|
not_null<MainWidget*> SessionController::chats() const {
|
2017-09-15 17:34:41 +00:00
|
|
|
return App::wnd()->chatsWidget();
|
|
|
|
}
|
|
|
|
|
2019-06-06 10:21:40 +00:00
|
|
|
void SessionController::setDefaultFloatPlayerDelegate(
|
2018-11-05 13:18:54 +00:00
|
|
|
not_null<Media::Player::FloatDelegate*> delegate) {
|
|
|
|
Expects(_defaultFloatPlayerDelegate == nullptr);
|
|
|
|
|
|
|
|
_defaultFloatPlayerDelegate = delegate;
|
|
|
|
_floatPlayers = std::make_unique<Media::Player::FloatController>(
|
|
|
|
delegate);
|
|
|
|
}
|
|
|
|
|
2019-06-06 10:21:40 +00:00
|
|
|
void SessionController::replaceFloatPlayerDelegate(
|
2018-11-05 13:18:54 +00:00
|
|
|
not_null<Media::Player::FloatDelegate*> replacement) {
|
|
|
|
Expects(_floatPlayers != nullptr);
|
|
|
|
|
|
|
|
_replacementFloatPlayerDelegate = replacement;
|
|
|
|
_floatPlayers->replaceDelegate(replacement);
|
|
|
|
}
|
|
|
|
|
2019-06-06 10:21:40 +00:00
|
|
|
void SessionController::restoreFloatPlayerDelegate(
|
2018-11-05 13:18:54 +00:00
|
|
|
not_null<Media::Player::FloatDelegate*> replacement) {
|
|
|
|
Expects(_floatPlayers != nullptr);
|
|
|
|
|
|
|
|
if (_replacementFloatPlayerDelegate == replacement) {
|
|
|
|
_replacementFloatPlayerDelegate = nullptr;
|
|
|
|
_floatPlayers->replaceDelegate(_defaultFloatPlayerDelegate);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-06-06 10:21:40 +00:00
|
|
|
rpl::producer<FullMsgId> SessionController::floatPlayerClosed() const {
|
2018-11-05 13:18:54 +00:00
|
|
|
Expects(_floatPlayers != nullptr);
|
|
|
|
|
|
|
|
return _floatPlayers->closeEvents();
|
|
|
|
}
|
|
|
|
|
2020-03-03 12:07:22 +00:00
|
|
|
int SessionController::filtersWidth() const {
|
|
|
|
return _filters ? st::windowFiltersWidth : 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
rpl::producer<FilterId> SessionController::activeChatsFilter() const {
|
|
|
|
return _activeChatsFilter.value();
|
|
|
|
}
|
|
|
|
|
|
|
|
FilterId SessionController::activeChatsFilterCurrent() const {
|
|
|
|
return _activeChatsFilter.current();
|
|
|
|
}
|
|
|
|
|
|
|
|
void SessionController::setActiveChatsFilter(FilterId id) {
|
2020-05-12 08:18:52 +00:00
|
|
|
if (activeChatsFilterCurrent() != id) {
|
|
|
|
resetFakeUnreadWhileOpened();
|
|
|
|
}
|
2020-03-27 09:41:54 +00:00
|
|
|
_activeChatsFilter.force_assign(id);
|
2020-03-20 13:12:13 +00:00
|
|
|
if (id) {
|
|
|
|
closeFolder();
|
|
|
|
}
|
2020-03-20 13:23:52 +00:00
|
|
|
if (Adaptive::OneColumn()) {
|
|
|
|
Ui::showChatsList();
|
|
|
|
}
|
2020-03-03 12:07:22 +00:00
|
|
|
}
|
|
|
|
|
2019-06-06 10:21:40 +00:00
|
|
|
SessionController::~SessionController() = default;
|
2018-01-21 14:49:42 +00:00
|
|
|
|
2017-04-07 18:10:49 +00:00
|
|
|
} // namespace Window
|