2016-04-12 21:31:28 +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.
|
2016-04-12 21:31:28 +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
|
2016-04-12 21:31:28 +00:00
|
|
|
*/
|
2018-01-09 17:08:31 +00:00
|
|
|
#include "history/view/history_view_top_bar_widget.h"
|
2016-04-12 21:31:28 +00:00
|
|
|
|
2017-09-19 19:44:34 +00:00
|
|
|
#include <rpl/combine.h>
|
2017-09-20 18:40:23 +00:00
|
|
|
#include <rpl/combine_previous.h>
|
2018-01-13 12:45:11 +00:00
|
|
|
#include "history/history.h"
|
2017-04-06 14:38:10 +00:00
|
|
|
#include "boxes/add_contact_box.h"
|
|
|
|
#include "boxes/confirm_box.h"
|
2017-09-16 16:53:41 +00:00
|
|
|
#include "info/info_memento.h"
|
2017-12-05 14:07:01 +00:00
|
|
|
#include "info/info_controller.h"
|
|
|
|
#include "storage/storage_shared_media.h"
|
2016-04-12 21:31:28 +00:00
|
|
|
#include "mainwidget.h"
|
2016-11-05 08:36:24 +00:00
|
|
|
#include "mainwindow.h"
|
2019-07-24 11:45:24 +00:00
|
|
|
#include "main/main_session.h"
|
2017-04-13 08:27:10 +00:00
|
|
|
#include "lang/lang_keys.h"
|
2018-11-16 12:15:14 +00:00
|
|
|
#include "core/shortcuts.h"
|
2016-11-11 13:46:04 +00:00
|
|
|
#include "ui/widgets/buttons.h"
|
2016-11-05 08:36:24 +00:00
|
|
|
#include "ui/widgets/dropdown_menu.h"
|
2018-05-10 10:16:21 +00:00
|
|
|
#include "ui/effects/radial_animation.h"
|
2019-09-13 12:22:54 +00:00
|
|
|
#include "ui/special_buttons.h"
|
|
|
|
#include "ui/unread_badge.h"
|
|
|
|
#include "ui/ui_utility.h"
|
2019-06-06 10:21:40 +00:00
|
|
|
#include "window/window_session_controller.h"
|
2017-11-06 18:03:20 +00:00
|
|
|
#include "window/window_peer_menu.h"
|
2017-04-19 18:06:01 +00:00
|
|
|
#include "calls/calls_instance.h"
|
2017-12-17 08:13:26 +00:00
|
|
|
#include "data/data_peer_values.h"
|
2019-04-15 11:54:03 +00:00
|
|
|
#include "data/data_folder.h"
|
2019-01-03 12:36:01 +00:00
|
|
|
#include "data/data_session.h"
|
2019-01-04 11:09:48 +00:00
|
|
|
#include "data/data_channel.h"
|
|
|
|
#include "data/data_chat.h"
|
|
|
|
#include "data/data_user.h"
|
2019-07-10 17:28:33 +00:00
|
|
|
#include "base/unixtime.h"
|
2018-11-15 15:36:04 +00:00
|
|
|
#include "support/support_helper.h"
|
2017-04-28 17:16:14 +00:00
|
|
|
#include "observer_peer.h"
|
2017-11-13 08:05:56 +00:00
|
|
|
#include "apiwrap.h"
|
2019-09-13 06:06:02 +00:00
|
|
|
#include "facades.h"
|
2018-01-13 12:45:11 +00:00
|
|
|
#include "styles/style_window.h"
|
|
|
|
#include "styles/style_dialogs.h"
|
|
|
|
#include "styles/style_history.h"
|
|
|
|
#include "styles/style_info.h"
|
2016-04-12 21:31:28 +00:00
|
|
|
|
2018-01-09 17:08:31 +00:00
|
|
|
namespace HistoryView {
|
|
|
|
|
|
|
|
TopBarWidget::TopBarWidget(
|
2017-09-19 10:32:34 +00:00
|
|
|
QWidget *parent,
|
2019-06-06 10:21:40 +00:00
|
|
|
not_null<Window::SessionController*> controller)
|
2017-09-19 10:32:34 +00:00
|
|
|
: RpWidget(parent)
|
2017-03-27 12:24:38 +00:00
|
|
|
, _controller(controller)
|
2019-06-18 16:53:27 +00:00
|
|
|
, _clear(this, tr::lng_selected_clear(), st::topBarClearButton)
|
|
|
|
, _forward(this, tr::lng_selected_forward(), st::defaultActiveButton)
|
2019-08-09 17:58:58 +00:00
|
|
|
, _sendNow(this, tr::lng_selected_send_now(), st::defaultActiveButton)
|
2019-06-18 16:53:27 +00:00
|
|
|
, _delete(this, tr::lng_selected_delete(), st::defaultActiveButton)
|
2017-11-16 15:24:01 +00:00
|
|
|
, _back(this, st::historyTopBarBack)
|
2017-04-19 18:06:01 +00:00
|
|
|
, _call(this, st::topBarCall)
|
2016-11-05 08:36:24 +00:00
|
|
|
, _search(this, st::topBarSearch)
|
2017-09-16 16:53:41 +00:00
|
|
|
, _infoToggle(this, st::topBarInfo)
|
2017-11-13 08:05:56 +00:00
|
|
|
, _menuToggle(this, st::topBarMenuToggle)
|
2018-11-15 15:36:04 +00:00
|
|
|
, _titlePeerText(st::windowMinWidth / 3)
|
2019-07-24 11:13:51 +00:00
|
|
|
, _onlineUpdater([=] { updateOnlineDisplay(); }) {
|
2019-08-09 17:58:58 +00:00
|
|
|
subscribe(Lang::Current().updated(), [=] { refreshLang(); });
|
2017-11-16 15:24:01 +00:00
|
|
|
setAttribute(Qt::WA_OpaquePaintEvent);
|
2017-05-30 15:21:05 +00:00
|
|
|
|
2019-08-09 17:58:58 +00:00
|
|
|
_forward->setClickedCallback([=] { _forwardSelection.fire({}); });
|
|
|
|
_forward->setWidthChangedCallback([=] { updateControlsGeometry(); });
|
|
|
|
_sendNow->setClickedCallback([=] { _sendNowSelection.fire({}); });
|
|
|
|
_sendNow->setWidthChangedCallback([=] { updateControlsGeometry(); });
|
|
|
|
_delete->setClickedCallback([=] { _deleteSelection.fire({}); });
|
|
|
|
_delete->setWidthChangedCallback([=] { updateControlsGeometry(); });
|
|
|
|
_clear->setClickedCallback([=] { _clearSelection.fire({}); });
|
|
|
|
_call->setClickedCallback([=] { onCall(); });
|
|
|
|
_search->setClickedCallback([=] { onSearch(); });
|
|
|
|
_menuToggle->setClickedCallback([=] { showMenu(); });
|
|
|
|
_infoToggle->setClickedCallback([=] { toggleInfoSection(); });
|
|
|
|
_back->addClickHandler([=] { backClicked(); });
|
2016-04-12 21:31:28 +00:00
|
|
|
|
2017-09-20 18:40:23 +00:00
|
|
|
rpl::combine(
|
2018-02-14 19:38:01 +00:00
|
|
|
_controller->activeChatValue(),
|
|
|
|
_controller->searchInChat.value()
|
2017-12-22 07:05:20 +00:00
|
|
|
) | rpl::combine_previous(
|
2018-02-14 19:38:01 +00:00
|
|
|
std::make_tuple(Dialogs::Key(), Dialogs::Key())
|
2017-12-22 07:05:20 +00:00
|
|
|
) | rpl::map([](
|
2018-02-14 19:38:01 +00:00
|
|
|
const std::tuple<Dialogs::Key, Dialogs::Key> &previous,
|
|
|
|
const std::tuple<Dialogs::Key, Dialogs::Key> ¤t) {
|
2019-04-24 14:12:35 +00:00
|
|
|
const auto &active = std::get<0>(current);
|
|
|
|
const auto &search = std::get<1>(current);
|
|
|
|
const auto activeChanged = (active != std::get<0>(previous));
|
|
|
|
const auto searchInChat = search && (active == search);
|
2018-02-14 19:38:01 +00:00
|
|
|
return std::make_tuple(searchInChat, activeChanged);
|
2019-04-24 14:12:35 +00:00
|
|
|
}) | rpl::start_with_next([=](
|
2018-02-14 19:38:01 +00:00
|
|
|
bool searchInActiveChat,
|
|
|
|
bool activeChanged) {
|
|
|
|
auto animated = activeChanged
|
2017-12-22 07:05:20 +00:00
|
|
|
? anim::type::instant
|
|
|
|
: anim::type::normal;
|
2018-02-14 19:38:01 +00:00
|
|
|
_search->setForceRippled(searchInActiveChat, animated);
|
2017-12-22 07:05:20 +00:00
|
|
|
}, lifetime());
|
2016-11-16 12:06:02 +00:00
|
|
|
|
2019-04-24 14:12:35 +00:00
|
|
|
subscribe(Adaptive::Changed(), [=] { updateAdaptiveLayout(); });
|
|
|
|
refreshUnreadBadge();
|
2019-04-01 14:53:18 +00:00
|
|
|
{
|
|
|
|
using AnimationUpdate = Data::Session::SendActionAnimationUpdate;
|
2019-07-24 11:13:51 +00:00
|
|
|
session().data().sendActionAnimationUpdated(
|
2019-04-01 14:53:18 +00:00
|
|
|
) | rpl::filter([=](const AnimationUpdate &update) {
|
|
|
|
return (update.history == _activeChat.history());
|
|
|
|
}) | rpl::start_with_next([=] {
|
|
|
|
update();
|
|
|
|
}, lifetime());
|
|
|
|
}
|
2019-01-03 12:36:01 +00:00
|
|
|
|
2017-11-13 08:05:56 +00:00
|
|
|
using UpdateFlag = Notify::PeerUpdate::Flag;
|
|
|
|
auto flags = UpdateFlag::UserHasCalls
|
|
|
|
| UpdateFlag::UserOnlineChanged
|
2018-11-20 15:36:36 +00:00
|
|
|
| UpdateFlag::MembersChanged
|
|
|
|
| UpdateFlag::UserSupportInfoChanged;
|
2019-04-01 14:53:18 +00:00
|
|
|
subscribe(Notify::PeerUpdated(), Notify::PeerUpdatedHandler(flags, [=](const Notify::PeerUpdate &update) {
|
2017-11-13 08:05:56 +00:00
|
|
|
if (update.flags & UpdateFlag::UserHasCalls) {
|
|
|
|
if (update.peer->isUser()) {
|
|
|
|
updateControlsVisibility();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
updateOnlineDisplay();
|
2017-04-28 17:16:14 +00:00
|
|
|
}
|
|
|
|
}));
|
2017-09-16 16:53:41 +00:00
|
|
|
subscribe(Global::RefPhoneCallsEnabledChanged(), [this] {
|
2017-11-16 15:24:01 +00:00
|
|
|
updateControlsVisibility();
|
|
|
|
});
|
2017-09-16 16:53:41 +00:00
|
|
|
|
2017-09-19 19:44:34 +00:00
|
|
|
rpl::combine(
|
2019-07-24 11:13:51 +00:00
|
|
|
session().settings().thirdSectionInfoEnabledValue(),
|
|
|
|
session().settings().tabbedReplacedWithInfoValue()
|
2017-12-22 07:05:20 +00:00
|
|
|
) | rpl::start_with_next(
|
|
|
|
[this] { updateInfoToggleActive(); },
|
|
|
|
lifetime());
|
2016-08-27 04:49:18 +00:00
|
|
|
|
2018-05-10 10:16:21 +00:00
|
|
|
rpl::single(rpl::empty_value()) | rpl::then(
|
|
|
|
base::ObservableViewer(Global::RefConnectionTypeChanged())
|
|
|
|
) | rpl::start_with_next(
|
|
|
|
[=] { updateConnectingState(); },
|
|
|
|
lifetime());
|
|
|
|
|
2016-04-12 21:31:28 +00:00
|
|
|
setCursor(style::cur_pointer);
|
2017-04-28 17:16:14 +00:00
|
|
|
updateControlsVisibility();
|
2016-04-12 21:31:28 +00:00
|
|
|
}
|
|
|
|
|
2019-07-24 11:13:51 +00:00
|
|
|
TopBarWidget::~TopBarWidget() = default;
|
|
|
|
|
2019-07-24 11:45:24 +00:00
|
|
|
Main::Session &TopBarWidget::session() const {
|
2019-07-24 11:13:51 +00:00
|
|
|
return _controller->session();
|
|
|
|
}
|
|
|
|
|
2018-05-10 10:16:21 +00:00
|
|
|
void TopBarWidget::updateConnectingState() {
|
|
|
|
const auto mtp = MTP::dcstate();
|
|
|
|
if (mtp == MTP::ConnectedState) {
|
|
|
|
if (_connecting) {
|
|
|
|
_connecting = nullptr;
|
|
|
|
update();
|
|
|
|
}
|
|
|
|
} else if (!_connecting) {
|
|
|
|
_connecting = std::make_unique<Ui::InfiniteRadialAnimation>(
|
2019-04-01 17:44:54 +00:00
|
|
|
[=] { connectingAnimationCallback(); },
|
2018-05-10 10:16:21 +00:00
|
|
|
st::topBarConnectingAnimation);
|
|
|
|
_connecting->start();
|
|
|
|
update();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-01 17:44:54 +00:00
|
|
|
void TopBarWidget::connectingAnimationCallback() {
|
|
|
|
if (!anim::Disabled()) {
|
2018-05-10 10:16:21 +00:00
|
|
|
update();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-09 17:08:31 +00:00
|
|
|
void TopBarWidget::refreshLang() {
|
2017-05-30 15:21:05 +00:00
|
|
|
InvokeQueued(this, [this] { updateControlsGeometry(); });
|
|
|
|
}
|
|
|
|
|
2018-01-09 17:08:31 +00:00
|
|
|
void TopBarWidget::onSearch() {
|
2019-05-26 12:49:12 +00:00
|
|
|
if (_activeChat) {
|
2018-01-22 17:39:20 +00:00
|
|
|
App::main()->searchInChat(_activeChat);
|
2016-07-19 11:37:01 +00:00
|
|
|
}
|
2016-04-12 21:31:28 +00:00
|
|
|
}
|
|
|
|
|
2018-01-09 17:08:31 +00:00
|
|
|
void TopBarWidget::onCall() {
|
2018-01-22 17:39:20 +00:00
|
|
|
if (const auto peer = _activeChat.peer()) {
|
|
|
|
if (const auto user = peer->asUser()) {
|
2019-08-06 16:40:08 +00:00
|
|
|
user->session().calls().startOutgoingCall(user);
|
2018-01-22 17:39:20 +00:00
|
|
|
}
|
2017-04-19 18:06:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-09 17:08:31 +00:00
|
|
|
void TopBarWidget::showMenu() {
|
2018-02-13 16:11:00 +00:00
|
|
|
if (!_activeChat || _menu) {
|
2017-11-13 08:05:56 +00:00
|
|
|
return;
|
2016-11-05 08:36:24 +00:00
|
|
|
}
|
2017-11-13 08:05:56 +00:00
|
|
|
_menu.create(parentWidget());
|
2019-09-13 12:22:54 +00:00
|
|
|
_menu->setHiddenCallback([weak = Ui::MakeWeak(this), menu = _menu.data()]{
|
2017-11-13 08:05:56 +00:00
|
|
|
menu->deleteLater();
|
2017-11-30 18:04:13 +00:00
|
|
|
if (weak && weak->_menu == menu) {
|
|
|
|
weak->_menu = nullptr;
|
|
|
|
weak->_menuToggle->setForceRippled(false);
|
2017-11-13 08:05:56 +00:00
|
|
|
}
|
2019-09-13 12:22:54 +00:00
|
|
|
});
|
2019-04-24 14:12:35 +00:00
|
|
|
_menu->setShowStartCallback(crl::guard(this, [this, menu = _menu.data()]{
|
2017-11-13 08:05:56 +00:00
|
|
|
if (_menu == menu) {
|
|
|
|
_menuToggle->setForceRippled(true);
|
|
|
|
}
|
2019-09-13 12:22:54 +00:00
|
|
|
}));
|
2019-04-24 14:12:35 +00:00
|
|
|
_menu->setHideStartCallback(crl::guard(this, [this, menu = _menu.data()]{
|
2017-11-13 08:05:56 +00:00
|
|
|
if (_menu == menu) {
|
|
|
|
_menuToggle->setForceRippled(false);
|
|
|
|
}
|
2019-09-13 12:22:54 +00:00
|
|
|
}));
|
2017-11-13 08:05:56 +00:00
|
|
|
_menuToggle->installEventFilter(_menu);
|
2018-02-13 16:11:00 +00:00
|
|
|
const auto addAction = [&](
|
2019-04-24 14:12:35 +00:00
|
|
|
const QString & text,
|
|
|
|
Fn<void()> callback) {
|
2018-02-13 16:11:00 +00:00
|
|
|
return _menu->addAction(text, std::move(callback));
|
|
|
|
};
|
|
|
|
if (const auto peer = _activeChat.peer()) {
|
|
|
|
Window::FillPeerMenu(
|
|
|
|
_controller,
|
|
|
|
peer,
|
2020-03-17 13:04:30 +00:00
|
|
|
FilterId(),
|
2018-02-13 16:11:00 +00:00
|
|
|
addAction,
|
|
|
|
Window::PeerMenuSource::History);
|
2019-04-15 11:54:03 +00:00
|
|
|
} else if (const auto folder = _activeChat.folder()) {
|
|
|
|
Window::FillFolderMenu(
|
2018-02-13 16:11:00 +00:00
|
|
|
_controller,
|
2019-04-15 11:54:03 +00:00
|
|
|
folder,
|
2018-02-13 16:11:00 +00:00
|
|
|
addAction,
|
|
|
|
Window::PeerMenuSource::History);
|
|
|
|
} else {
|
|
|
|
Unexpected("Empty active chat in TopBarWidget::showMenu.");
|
|
|
|
}
|
2019-04-24 14:12:35 +00:00
|
|
|
if (_menu->actions().empty()) {
|
|
|
|
_menu.destroy();
|
|
|
|
} else {
|
|
|
|
_menu->moveToRight((parentWidget()->width() - width()) + st::topBarMenuPosition.x(), st::topBarMenuPosition.y());
|
|
|
|
_menu->showAnimated(Ui::PanelAnimation::Origin::TopRight);
|
|
|
|
}
|
2016-11-05 08:36:24 +00:00
|
|
|
}
|
|
|
|
|
2018-01-09 17:08:31 +00:00
|
|
|
void TopBarWidget::toggleInfoSection() {
|
2017-09-16 16:53:41 +00:00
|
|
|
if (Adaptive::ThreeColumn()
|
2019-07-24 11:13:51 +00:00
|
|
|
&& (session().settings().thirdSectionInfoEnabled()
|
|
|
|
|| session().settings().tabbedReplacedWithInfo())) {
|
2017-09-16 16:53:41 +00:00
|
|
|
_controller->closeThirdSection();
|
2019-04-15 11:54:03 +00:00
|
|
|
} else if (_activeChat.peer()) {
|
2017-09-16 16:53:41 +00:00
|
|
|
if (_controller->canShowThirdSection()) {
|
2019-07-24 11:13:51 +00:00
|
|
|
session().settings().setThirdSectionInfoEnabled(true);
|
|
|
|
session().saveSettingsDelayed();
|
2017-09-16 16:53:41 +00:00
|
|
|
if (Adaptive::ThreeColumn()) {
|
2017-12-04 07:33:33 +00:00
|
|
|
_controller->showSection(
|
2019-04-15 11:54:03 +00:00
|
|
|
Info::Memento::Default(_activeChat.peer()),
|
2017-12-04 07:33:33 +00:00
|
|
|
Window::SectionShow().withThirdColumn());
|
2017-09-16 16:53:41 +00:00
|
|
|
} else {
|
|
|
|
_controller->resizeForThirdSection();
|
|
|
|
_controller->updateColumnLayout();
|
|
|
|
}
|
|
|
|
} else {
|
2018-01-22 19:51:38 +00:00
|
|
|
infoClicked();
|
2017-09-16 16:53:41 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
updateControlsVisibility();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-09 17:08:31 +00:00
|
|
|
bool TopBarWidget::eventFilter(QObject *obj, QEvent *e) {
|
2016-06-17 18:18:01 +00:00
|
|
|
if (obj == _membersShowArea) {
|
|
|
|
switch (e->type()) {
|
|
|
|
case QEvent::MouseButtonPress:
|
|
|
|
mousePressEvent(static_cast<QMouseEvent*>(e));
|
|
|
|
return true;
|
|
|
|
|
|
|
|
case QEvent::Enter:
|
2017-11-13 08:05:56 +00:00
|
|
|
_membersShowAreaActive.fire(true);
|
2016-06-17 18:18:01 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case QEvent::Leave:
|
2017-11-13 08:05:56 +00:00
|
|
|
_membersShowAreaActive.fire(false);
|
2016-06-17 18:18:01 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return TWidget::eventFilter(obj, e);
|
|
|
|
}
|
|
|
|
|
2018-01-22 17:39:20 +00:00
|
|
|
int TopBarWidget::resizeGetHeight(int newWidth) {
|
|
|
|
return st::topBarHeight;
|
|
|
|
}
|
|
|
|
|
2018-01-09 17:08:31 +00:00
|
|
|
void TopBarWidget::paintEvent(QPaintEvent *e) {
|
|
|
|
if (_animatingMode) {
|
2017-11-16 15:24:01 +00:00
|
|
|
return;
|
|
|
|
}
|
2016-04-21 17:57:29 +00:00
|
|
|
Painter p(this);
|
2016-04-12 21:31:28 +00:00
|
|
|
|
2016-12-26 22:46:36 +00:00
|
|
|
auto hasSelected = (_selectedCount > 0);
|
2019-04-02 09:13:30 +00:00
|
|
|
auto selectedButtonsTop = countSelectedButtonsTop(_selectedShown.value(hasSelected ? 1. : 0.));
|
2016-12-26 22:46:36 +00:00
|
|
|
|
2016-10-31 12:29:26 +00:00
|
|
|
p.fillRect(QRect(0, 0, width(), st::topBarHeight), st::topBarBg);
|
2016-12-26 22:46:36 +00:00
|
|
|
if (selectedButtonsTop < 0) {
|
|
|
|
p.translate(0, selectedButtonsTop + st::topBarHeight);
|
2019-04-02 09:13:30 +00:00
|
|
|
paintTopBar(p);
|
2017-11-13 08:05:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-02 09:13:30 +00:00
|
|
|
void TopBarWidget::paintTopBar(Painter &p) {
|
2019-04-24 14:12:35 +00:00
|
|
|
if (!_activeChat) {
|
2018-01-22 17:39:20 +00:00
|
|
|
return;
|
|
|
|
}
|
2017-11-16 15:24:01 +00:00
|
|
|
auto nameleft = _leftTaken;
|
2017-11-13 08:05:56 +00:00
|
|
|
auto nametop = st::topBarArrowPadding.top();
|
|
|
|
auto statustop = st::topBarHeight - st::topBarArrowPadding.bottom() - st::dialogsTextFont->height;
|
2019-06-23 12:18:33 +00:00
|
|
|
auto availableWidth = width() - _rightTaken - nameleft;
|
2017-11-13 08:05:56 +00:00
|
|
|
|
2019-08-09 12:15:57 +00:00
|
|
|
const auto history = _activeChat.history();
|
|
|
|
const auto folder = _activeChat.folder();
|
|
|
|
if (folder
|
|
|
|
|| history->peer->isSelf()
|
|
|
|
|| (_section == Section::Scheduled)) {
|
|
|
|
// #TODO feed name emoji.
|
|
|
|
auto text = (_section == Section::Scheduled)
|
2019-08-28 16:46:47 +00:00
|
|
|
? ((history && history->peer->isSelf())
|
|
|
|
? tr::lng_reminder_messages(tr::now)
|
|
|
|
: tr::lng_scheduled_messages(tr::now))
|
2019-08-09 12:15:57 +00:00
|
|
|
: folder
|
|
|
|
? folder->chatListName()
|
|
|
|
: tr::lng_saved_messages(tr::now);
|
2019-06-23 12:18:33 +00:00
|
|
|
const auto textWidth = st::historySavedFont->width(text);
|
|
|
|
if (availableWidth < textWidth) {
|
|
|
|
text = st::historySavedFont->elided(text, availableWidth);
|
2017-12-05 14:07:01 +00:00
|
|
|
}
|
2019-06-23 12:18:33 +00:00
|
|
|
p.setPen(st::dialogsNameFg);
|
2017-12-05 14:07:01 +00:00
|
|
|
p.setFont(st::historySavedFont);
|
|
|
|
p.drawTextLeft(
|
|
|
|
nameleft,
|
|
|
|
(height() - st::historySavedFont->height) / 2,
|
|
|
|
width(),
|
|
|
|
text);
|
2018-01-22 17:39:20 +00:00
|
|
|
} else if (const auto history = _activeChat.history()) {
|
2019-06-23 12:18:33 +00:00
|
|
|
const auto peer = history->peer;
|
|
|
|
const auto &text = peer->topBarNameText();
|
|
|
|
const auto badgeStyle = Ui::PeerBadgeStyle{
|
|
|
|
nullptr,
|
|
|
|
&st::attentionButtonFg };
|
|
|
|
const auto badgeWidth = Ui::DrawPeerBadgeGetWidth(
|
|
|
|
peer,
|
|
|
|
p,
|
|
|
|
QRect(
|
|
|
|
nameleft,
|
|
|
|
nametop,
|
|
|
|
availableWidth,
|
|
|
|
st::msgNameStyle.font->height),
|
|
|
|
text.maxWidth(),
|
|
|
|
width(),
|
|
|
|
badgeStyle);
|
|
|
|
const auto namewidth = availableWidth - badgeWidth;
|
|
|
|
|
|
|
|
p.setPen(st::dialogsNameFg);
|
|
|
|
peer->topBarNameText().drawElided(
|
|
|
|
p,
|
|
|
|
nameleft,
|
|
|
|
nametop,
|
|
|
|
namewidth);
|
2017-12-05 14:07:01 +00:00
|
|
|
|
|
|
|
p.setFont(st::dialogsTextFont);
|
2019-04-02 09:13:30 +00:00
|
|
|
if (paintConnectingState(p, nameleft, statustop, width())) {
|
2018-05-10 10:16:21 +00:00
|
|
|
return;
|
2018-11-20 13:34:07 +00:00
|
|
|
} else if (history->paintSendAction(
|
2018-11-15 15:36:04 +00:00
|
|
|
p,
|
|
|
|
nameleft,
|
|
|
|
statustop,
|
2019-06-23 12:18:33 +00:00
|
|
|
availableWidth,
|
2018-11-15 15:36:04 +00:00
|
|
|
width(),
|
|
|
|
st::historyStatusFgTyping,
|
2019-04-02 09:13:30 +00:00
|
|
|
crl::now())) {
|
2018-05-10 10:16:21 +00:00
|
|
|
return;
|
|
|
|
} else {
|
2019-06-23 12:18:33 +00:00
|
|
|
paintStatus(p, nameleft, statustop, availableWidth, width());
|
2017-12-05 14:07:01 +00:00
|
|
|
}
|
|
|
|
}
|
2016-11-06 17:23:13 +00:00
|
|
|
}
|
|
|
|
|
2018-05-10 10:16:21 +00:00
|
|
|
bool TopBarWidget::paintConnectingState(
|
|
|
|
Painter &p,
|
|
|
|
int left,
|
|
|
|
int top,
|
2019-04-02 09:13:30 +00:00
|
|
|
int outerWidth) {
|
2018-05-10 10:16:21 +00:00
|
|
|
if (!_connecting) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
_connecting->draw(
|
|
|
|
p,
|
|
|
|
{
|
|
|
|
st::topBarConnectingPosition.x() + left,
|
|
|
|
st::topBarConnectingPosition.y() + top
|
|
|
|
},
|
|
|
|
outerWidth);
|
|
|
|
left += st::topBarConnectingPosition.x()
|
|
|
|
+ st::topBarConnectingAnimation.size.width()
|
|
|
|
+ st::topBarConnectingSkip;
|
|
|
|
p.setPen(st::historyStatusFg);
|
2019-06-19 15:09:03 +00:00
|
|
|
p.drawTextLeft(left, top, outerWidth, tr::lng_status_connecting(tr::now));
|
2018-05-10 10:16:21 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void TopBarWidget::paintStatus(
|
|
|
|
Painter &p,
|
|
|
|
int left,
|
|
|
|
int top,
|
|
|
|
int availableWidth,
|
|
|
|
int outerWidth) {
|
2018-11-20 13:34:07 +00:00
|
|
|
p.setPen(_titlePeerTextOnline
|
2018-05-10 10:16:21 +00:00
|
|
|
? st::historyStatusFgActive
|
|
|
|
: st::historyStatusFg);
|
2018-11-15 15:36:04 +00:00
|
|
|
_titlePeerText.drawLeftElided(p, left, top, availableWidth, outerWidth);
|
2018-05-10 10:16:21 +00:00
|
|
|
}
|
|
|
|
|
2018-01-09 17:08:31 +00:00
|
|
|
QRect TopBarWidget::getMembersShowAreaGeometry() const {
|
2017-11-16 15:24:01 +00:00
|
|
|
int membersTextLeft = _leftTaken;
|
2017-11-13 08:05:56 +00:00
|
|
|
int membersTextTop = st::topBarHeight - st::topBarArrowPadding.bottom() - st::dialogsTextFont->height;
|
2018-11-15 15:36:04 +00:00
|
|
|
int membersTextWidth = _titlePeerText.maxWidth();
|
2017-11-13 08:05:56 +00:00
|
|
|
int membersTextHeight = st::topBarHeight - membersTextTop;
|
|
|
|
|
|
|
|
return myrtlrect(membersTextLeft, membersTextTop, membersTextWidth, membersTextHeight);
|
|
|
|
}
|
|
|
|
|
2018-01-09 17:08:31 +00:00
|
|
|
void TopBarWidget::mousePressEvent(QMouseEvent *e) {
|
2017-11-16 15:24:01 +00:00
|
|
|
auto handleClick = (e->button() == Qt::LeftButton)
|
|
|
|
&& (e->pos().y() < st::topBarHeight)
|
|
|
|
&& (!_selectedCount);
|
|
|
|
if (handleClick) {
|
2018-01-09 17:08:31 +00:00
|
|
|
if (_animatingMode && _back->rect().contains(e->pos())) {
|
2017-11-16 15:24:01 +00:00
|
|
|
backClicked();
|
2018-01-22 17:39:20 +00:00
|
|
|
} else {
|
2017-11-16 15:24:01 +00:00
|
|
|
infoClicked();
|
|
|
|
}
|
2016-04-12 21:31:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-09 17:08:31 +00:00
|
|
|
void TopBarWidget::infoClicked() {
|
2019-04-24 14:12:35 +00:00
|
|
|
if (!_activeChat) {
|
2018-01-22 17:39:20 +00:00
|
|
|
return;
|
2019-04-24 14:12:35 +00:00
|
|
|
} else if (_activeChat.folder()) {
|
|
|
|
_controller->closeFolder();
|
2019-04-15 11:54:03 +00:00
|
|
|
//} else if (const auto feed = _activeChat.feed()) { // #feed
|
|
|
|
// _controller->showSection(Info::Memento(
|
|
|
|
// feed,
|
|
|
|
// Info::Section(Info::Section::Type::Profile)));
|
2018-01-22 17:39:20 +00:00
|
|
|
} else if (_activeChat.peer()->isSelf()) {
|
2017-12-05 14:07:01 +00:00
|
|
|
_controller->showSection(Info::Memento(
|
2018-01-22 17:39:20 +00:00
|
|
|
_activeChat.peer()->id,
|
2017-12-05 14:07:01 +00:00
|
|
|
Info::Section(Storage::SharedMediaType::Photo)));
|
|
|
|
} else {
|
2018-01-22 17:39:20 +00:00
|
|
|
_controller->showPeerInfo(_activeChat.peer());
|
2017-12-05 14:07:01 +00:00
|
|
|
}
|
2017-11-16 15:24:01 +00:00
|
|
|
}
|
|
|
|
|
2018-01-09 17:08:31 +00:00
|
|
|
void TopBarWidget::backClicked() {
|
2019-04-24 14:12:35 +00:00
|
|
|
if (_activeChat.folder()) {
|
|
|
|
_controller->closeFolder();
|
|
|
|
} else {
|
|
|
|
_controller->showBackFromStack();
|
|
|
|
}
|
2017-11-13 08:05:56 +00:00
|
|
|
}
|
|
|
|
|
2019-08-09 12:15:57 +00:00
|
|
|
void TopBarWidget::setActiveChat(Dialogs::Key chat, Section section) {
|
|
|
|
if (_activeChat == chat && _section == section) {
|
2019-04-24 14:12:35 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
_activeChat = chat;
|
2019-08-09 12:15:57 +00:00
|
|
|
_section = section;
|
2019-04-24 14:12:35 +00:00
|
|
|
_back->clearState();
|
|
|
|
update();
|
2017-11-19 11:37:15 +00:00
|
|
|
|
2019-04-24 14:12:35 +00:00
|
|
|
updateUnreadBadge();
|
|
|
|
refreshInfoButton();
|
|
|
|
if (_menu) {
|
|
|
|
_menuToggle->removeEventFilter(_menu);
|
|
|
|
_menu->hideFast();
|
2017-11-13 13:19:14 +00:00
|
|
|
}
|
2019-04-24 14:12:35 +00:00
|
|
|
updateOnlineDisplay();
|
|
|
|
updateControlsVisibility();
|
|
|
|
refreshUnreadBadge();
|
2017-11-13 13:19:14 +00:00
|
|
|
}
|
|
|
|
|
2018-01-30 14:31:25 +00:00
|
|
|
void TopBarWidget::refreshInfoButton() {
|
|
|
|
if (const auto peer = _activeChat.peer()) {
|
|
|
|
auto info = object_ptr<Ui::UserpicButton>(
|
|
|
|
this,
|
|
|
|
_controller,
|
|
|
|
peer,
|
|
|
|
Ui::UserpicButton::Role::Custom,
|
|
|
|
st::topBarInfoButton);
|
|
|
|
info->showSavedMessagesOnSelf(true);
|
2018-03-15 15:22:55 +00:00
|
|
|
_info.destroy();
|
2018-01-30 14:31:25 +00:00
|
|
|
_info = std::move(info);
|
2019-04-15 11:54:03 +00:00
|
|
|
//} else if (const auto feed = _activeChat.feed()) { // #feed
|
|
|
|
// _info.destroy();
|
|
|
|
// _info = object_ptr<Ui::FeedUserpicButton>(
|
|
|
|
// this,
|
|
|
|
// _controller,
|
|
|
|
// feed,
|
|
|
|
// st::topBarFeedInfoButton);
|
2018-01-30 14:31:25 +00:00
|
|
|
}
|
|
|
|
if (_info) {
|
|
|
|
_info->setAttribute(Qt::WA_TransparentForMouseEvents);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-09 17:08:31 +00:00
|
|
|
void TopBarWidget::resizeEvent(QResizeEvent *e) {
|
2019-08-16 09:32:42 +00:00
|
|
|
updateSearchVisibility();
|
2016-12-26 22:46:36 +00:00
|
|
|
updateControlsGeometry();
|
|
|
|
}
|
|
|
|
|
2018-01-09 17:08:31 +00:00
|
|
|
int TopBarWidget::countSelectedButtonsTop(float64 selectedShown) {
|
2016-12-26 22:46:36 +00:00
|
|
|
return (1. - selectedShown) * (-st::topBarHeight);
|
|
|
|
}
|
|
|
|
|
2019-08-16 09:32:42 +00:00
|
|
|
void TopBarWidget::updateSearchVisibility() {
|
|
|
|
const auto historyMode = (_section == Section::History);
|
|
|
|
const auto smallDialogsColumn = _activeChat.folder()
|
|
|
|
&& (width() < _back->width() + _search->width());
|
|
|
|
_search->setVisible(historyMode && !smallDialogsColumn);
|
|
|
|
}
|
|
|
|
|
2018-01-09 17:08:31 +00:00
|
|
|
void TopBarWidget::updateControlsGeometry() {
|
2016-12-26 22:46:36 +00:00
|
|
|
auto hasSelected = (_selectedCount > 0);
|
2019-04-02 09:13:30 +00:00
|
|
|
auto selectedButtonsTop = countSelectedButtonsTop(_selectedShown.value(hasSelected ? 1. : 0.));
|
2016-12-26 22:46:36 +00:00
|
|
|
auto otherButtonsTop = selectedButtonsTop + st::topBarHeight;
|
|
|
|
auto buttonsLeft = st::topBarActionSkip + (Adaptive::OneColumn() ? 0 : st::lineWidth);
|
2019-08-09 17:58:58 +00:00
|
|
|
auto buttonsWidth = (_forward->isHidden() ? 0 : _forward->contentWidth())
|
|
|
|
+ (_sendNow->isHidden() ? 0 : _sendNow->contentWidth())
|
|
|
|
+ (_delete->isHidden() ? 0 : _delete->contentWidth())
|
|
|
|
+ _clear->width();
|
2016-06-22 17:11:35 +00:00
|
|
|
buttonsWidth += buttonsLeft + st::topBarActionSkip * 3;
|
|
|
|
|
2016-12-26 22:46:36 +00:00
|
|
|
auto widthLeft = qMin(width() - buttonsWidth, -2 * st::defaultActiveButton.width);
|
2018-06-08 19:26:08 +00:00
|
|
|
auto buttonFullWidth = qMin(-(widthLeft / 2), 0);
|
|
|
|
_forward->setFullWidth(buttonFullWidth);
|
2019-08-09 17:58:58 +00:00
|
|
|
_sendNow->setFullWidth(buttonFullWidth);
|
2018-06-08 19:26:08 +00:00
|
|
|
_delete->setFullWidth(buttonFullWidth);
|
2016-06-22 17:11:35 +00:00
|
|
|
|
2016-12-26 22:46:36 +00:00
|
|
|
selectedButtonsTop += (height() - _forward->height()) / 2;
|
2016-06-22 17:11:35 +00:00
|
|
|
|
2016-12-26 22:46:36 +00:00
|
|
|
_forward->moveToLeft(buttonsLeft, selectedButtonsTop);
|
2017-04-27 21:17:00 +00:00
|
|
|
if (!_forward->isHidden()) {
|
|
|
|
buttonsLeft += _forward->width() + st::topBarActionSkip;
|
|
|
|
}
|
2016-06-22 17:11:35 +00:00
|
|
|
|
2019-08-09 17:58:58 +00:00
|
|
|
_sendNow->moveToLeft(buttonsLeft, selectedButtonsTop);
|
|
|
|
if (!_sendNow->isHidden()) {
|
|
|
|
buttonsLeft += _sendNow->width() + st::topBarActionSkip;
|
|
|
|
}
|
|
|
|
|
2016-12-26 22:46:36 +00:00
|
|
|
_delete->moveToLeft(buttonsLeft, selectedButtonsTop);
|
2018-01-26 15:40:11 +00:00
|
|
|
_clear->moveToRight(st::topBarActionSkip, selectedButtonsTop);
|
2016-06-22 17:11:35 +00:00
|
|
|
|
2017-11-16 15:24:01 +00:00
|
|
|
if (_back->isHidden()) {
|
|
|
|
_leftTaken = st::topBarArrowPadding.right();
|
2017-04-19 18:06:01 +00:00
|
|
|
} else {
|
2019-04-24 14:12:35 +00:00
|
|
|
const auto smallDialogsColumn = _activeChat.folder()
|
|
|
|
&& (width() < _back->width() + _search->width());
|
|
|
|
_leftTaken = smallDialogsColumn ? (width() - _back->width()) / 2 : 0;
|
2017-11-16 15:24:01 +00:00
|
|
|
_back->moveToLeft(_leftTaken, otherButtonsTop);
|
|
|
|
_leftTaken += _back->width();
|
2017-12-05 14:07:01 +00:00
|
|
|
if (_info && !_info->isHidden()) {
|
2017-11-16 15:24:01 +00:00
|
|
|
_info->moveToLeft(_leftTaken, otherButtonsTop);
|
|
|
|
_leftTaken += _info->width();
|
|
|
|
}
|
2017-04-19 18:06:01 +00:00
|
|
|
}
|
2017-11-16 15:24:01 +00:00
|
|
|
|
|
|
|
_rightTaken = 0;
|
|
|
|
_menuToggle->moveToRight(_rightTaken, otherButtonsTop);
|
2019-04-24 14:12:35 +00:00
|
|
|
if (_menuToggle->isHidden()) {
|
|
|
|
_rightTaken += (_menuToggle->width() - _search->width());
|
|
|
|
} else {
|
|
|
|
_rightTaken += _menuToggle->width() + st::topBarSkip;
|
|
|
|
}
|
2017-11-16 15:24:01 +00:00
|
|
|
_infoToggle->moveToRight(_rightTaken, otherButtonsTop);
|
2017-09-16 16:53:41 +00:00
|
|
|
if (!_infoToggle->isHidden()) {
|
2017-11-16 15:24:01 +00:00
|
|
|
_rightTaken += _infoToggle->width() + st::topBarSkip;
|
2017-09-16 16:53:41 +00:00
|
|
|
}
|
2017-11-16 15:24:01 +00:00
|
|
|
_search->moveToRight(_rightTaken, otherButtonsTop);
|
|
|
|
_rightTaken += _search->width() + st::topBarCallSkip;
|
|
|
|
_call->moveToRight(_rightTaken, otherButtonsTop);
|
|
|
|
_rightTaken += _call->width();
|
2017-11-17 14:54:01 +00:00
|
|
|
|
|
|
|
updateMembersShowArea();
|
2016-04-12 21:31:28 +00:00
|
|
|
}
|
|
|
|
|
2018-01-09 17:08:31 +00:00
|
|
|
void TopBarWidget::finishAnimating() {
|
2019-04-02 09:13:30 +00:00
|
|
|
_selectedShown.stop();
|
2017-12-02 10:22:48 +00:00
|
|
|
updateControlsVisibility();
|
2019-04-09 14:10:58 +00:00
|
|
|
update();
|
2017-12-02 10:22:48 +00:00
|
|
|
}
|
|
|
|
|
2018-01-09 17:08:31 +00:00
|
|
|
void TopBarWidget::setAnimatingMode(bool enabled) {
|
|
|
|
if (_animatingMode != enabled) {
|
|
|
|
_animatingMode = enabled;
|
|
|
|
setAttribute(Qt::WA_OpaquePaintEvent, !_animatingMode);
|
2017-12-02 10:22:48 +00:00
|
|
|
finishAnimating();
|
2017-11-16 15:24:01 +00:00
|
|
|
}
|
2016-04-12 21:31:28 +00:00
|
|
|
}
|
|
|
|
|
2018-01-09 17:08:31 +00:00
|
|
|
void TopBarWidget::updateControlsVisibility() {
|
|
|
|
if (_animatingMode) {
|
2017-11-16 15:24:01 +00:00
|
|
|
hideChildren();
|
|
|
|
return;
|
|
|
|
}
|
2018-01-26 15:40:11 +00:00
|
|
|
_clear->show();
|
2016-12-26 22:46:36 +00:00
|
|
|
_delete->setVisible(_canDelete);
|
2017-04-27 21:17:00 +00:00
|
|
|
_forward->setVisible(_canForward);
|
2019-08-09 17:58:58 +00:00
|
|
|
_sendNow->setVisible(_canSendNow);
|
2016-12-26 22:46:36 +00:00
|
|
|
|
2017-11-16 15:24:01 +00:00
|
|
|
auto backVisible = Adaptive::OneColumn()
|
2019-04-24 14:12:35 +00:00
|
|
|
|| (App::main() && !App::main()->stackIsEmpty())
|
|
|
|
|| _activeChat.folder();
|
2017-11-16 15:24:01 +00:00
|
|
|
_back->setVisible(backVisible);
|
|
|
|
if (_info) {
|
2017-12-05 14:07:01 +00:00
|
|
|
_info->setVisible(Adaptive::OneColumn());
|
2016-04-12 21:31:28 +00:00
|
|
|
}
|
2017-11-17 14:54:01 +00:00
|
|
|
if (_unreadBadge) {
|
|
|
|
_unreadBadge->show();
|
|
|
|
}
|
2019-08-09 12:15:57 +00:00
|
|
|
const auto historyMode = (_section == Section::History);
|
2019-08-16 09:32:42 +00:00
|
|
|
updateSearchVisibility();
|
2019-08-09 12:15:57 +00:00
|
|
|
_menuToggle->setVisible(historyMode && !_activeChat.folder());
|
|
|
|
_infoToggle->setVisible(historyMode
|
|
|
|
&& !_activeChat.folder()
|
2019-04-24 14:12:35 +00:00
|
|
|
&& !Adaptive::OneColumn()
|
2017-11-13 13:19:14 +00:00
|
|
|
&& _controller->canShowThirdSection());
|
2018-01-22 17:39:20 +00:00
|
|
|
const auto callsEnabled = [&] {
|
|
|
|
if (const auto peer = _activeChat.peer()) {
|
|
|
|
if (const auto user = peer->asUser()) {
|
|
|
|
return Global::PhoneCallsEnabled() && user->hasCalls();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}();
|
2019-08-09 12:15:57 +00:00
|
|
|
_call->setVisible(historyMode && callsEnabled);
|
2017-11-13 13:19:14 +00:00
|
|
|
|
2016-06-17 18:18:01 +00:00
|
|
|
if (_membersShowArea) {
|
|
|
|
_membersShowArea->show();
|
|
|
|
}
|
2016-12-26 22:46:36 +00:00
|
|
|
updateControlsGeometry();
|
2016-04-12 21:31:28 +00:00
|
|
|
}
|
|
|
|
|
2018-01-09 17:08:31 +00:00
|
|
|
void TopBarWidget::updateMembersShowArea() {
|
2017-11-17 14:54:01 +00:00
|
|
|
if (!App::main()) {
|
|
|
|
return;
|
|
|
|
}
|
2016-06-17 18:18:01 +00:00
|
|
|
auto membersShowAreaNeeded = [this]() {
|
2017-01-07 11:55:05 +00:00
|
|
|
auto peer = App::main()->peer();
|
2017-11-13 08:05:56 +00:00
|
|
|
if ((_selectedCount > 0) || !peer) {
|
2016-06-17 18:18:01 +00:00
|
|
|
return false;
|
|
|
|
}
|
2017-01-07 11:55:05 +00:00
|
|
|
if (auto chat = peer->asChat()) {
|
2016-07-19 11:37:01 +00:00
|
|
|
return chat->amIn();
|
2016-06-17 18:18:01 +00:00
|
|
|
}
|
2017-01-07 11:55:05 +00:00
|
|
|
if (auto megagroup = peer->asMegagroup()) {
|
2016-07-19 11:37:01 +00:00
|
|
|
return megagroup->canViewMembers() && (megagroup->membersCount() < Global::ChatSizeMax());
|
2016-06-17 18:18:01 +00:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
};
|
|
|
|
if (!membersShowAreaNeeded()) {
|
|
|
|
if (_membersShowArea) {
|
2017-11-13 08:05:56 +00:00
|
|
|
_membersShowAreaActive.fire(false);
|
2016-06-17 18:18:01 +00:00
|
|
|
_membersShowArea.destroy();
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
} else if (!_membersShowArea) {
|
2016-12-13 17:07:56 +00:00
|
|
|
_membersShowArea.create(this);
|
2016-06-17 18:18:01 +00:00
|
|
|
_membersShowArea->show();
|
|
|
|
_membersShowArea->installEventFilter(this);
|
|
|
|
}
|
2017-11-13 08:05:56 +00:00
|
|
|
_membersShowArea->setGeometry(getMembersShowAreaGeometry());
|
2016-06-17 18:18:01 +00:00
|
|
|
}
|
|
|
|
|
2018-01-09 17:08:31 +00:00
|
|
|
void TopBarWidget::showSelected(SelectedState state) {
|
2017-04-27 21:17:00 +00:00
|
|
|
auto canDelete = (state.count > 0 && state.count == state.canDeleteCount);
|
|
|
|
auto canForward = (state.count > 0 && state.count == state.canForwardCount);
|
2019-08-09 17:58:58 +00:00
|
|
|
auto canSendNow = (state.count > 0 && state.count == state.canSendNowCount);
|
|
|
|
if (_selectedCount == state.count && _canDelete == canDelete && _canForward == canForward && _canSendNow == canSendNow) {
|
2016-12-26 22:46:36 +00:00
|
|
|
return;
|
|
|
|
}
|
2017-04-27 21:17:00 +00:00
|
|
|
if (state.count == 0) {
|
2016-12-29 16:31:01 +00:00
|
|
|
// Don't change the visible buttons if the selection is cancelled.
|
|
|
|
canDelete = _canDelete;
|
2017-04-27 21:17:00 +00:00
|
|
|
canForward = _canForward;
|
2019-08-09 17:58:58 +00:00
|
|
|
canSendNow = _canSendNow;
|
2016-12-29 16:31:01 +00:00
|
|
|
}
|
2016-12-26 22:46:36 +00:00
|
|
|
|
|
|
|
auto wasSelected = (_selectedCount > 0);
|
2017-04-27 21:17:00 +00:00
|
|
|
_selectedCount = state.count;
|
2016-12-26 22:46:36 +00:00
|
|
|
if (_selectedCount > 0) {
|
2016-12-29 16:31:01 +00:00
|
|
|
_forward->setNumbersText(_selectedCount);
|
2019-08-09 17:58:58 +00:00
|
|
|
_sendNow->setNumbersText(_selectedCount);
|
2016-12-29 16:31:01 +00:00
|
|
|
_delete->setNumbersText(_selectedCount);
|
|
|
|
if (!wasSelected) {
|
|
|
|
_forward->finishNumbersAnimation();
|
2019-08-09 17:58:58 +00:00
|
|
|
_sendNow->finishNumbersAnimation();
|
2016-12-29 16:31:01 +00:00
|
|
|
_delete->finishNumbersAnimation();
|
|
|
|
}
|
2016-12-26 22:46:36 +00:00
|
|
|
}
|
|
|
|
auto hasSelected = (_selectedCount > 0);
|
2019-08-09 17:58:58 +00:00
|
|
|
if (_canDelete != canDelete || _canForward != canForward || _canSendNow != canSendNow) {
|
2016-06-22 17:11:35 +00:00
|
|
|
_canDelete = canDelete;
|
2017-04-27 21:17:00 +00:00
|
|
|
_canForward = canForward;
|
2019-08-09 17:58:58 +00:00
|
|
|
_canSendNow = canSendNow;
|
2017-04-28 17:16:14 +00:00
|
|
|
updateControlsVisibility();
|
2016-06-22 17:11:35 +00:00
|
|
|
}
|
2016-12-26 22:46:36 +00:00
|
|
|
if (wasSelected != hasSelected) {
|
|
|
|
setCursor(hasSelected ? style::cur_default : style::cur_pointer);
|
2016-06-17 18:18:01 +00:00
|
|
|
|
2016-12-26 22:46:36 +00:00
|
|
|
updateMembersShowArea();
|
2017-11-24 15:47:07 +00:00
|
|
|
_selectedShown.start(
|
|
|
|
[this] { selectedShowCallback(); },
|
|
|
|
hasSelected ? 0. : 1.,
|
|
|
|
hasSelected ? 1. : 0.,
|
|
|
|
st::slideWrapDuration,
|
|
|
|
anim::easeOutCirc);
|
2016-12-26 22:46:36 +00:00
|
|
|
} else {
|
|
|
|
updateControlsGeometry();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-09 17:08:31 +00:00
|
|
|
void TopBarWidget::selectedShowCallback() {
|
2016-12-26 22:46:36 +00:00
|
|
|
updateControlsGeometry();
|
|
|
|
update();
|
2016-04-12 21:31:28 +00:00
|
|
|
}
|
|
|
|
|
2018-01-09 17:08:31 +00:00
|
|
|
void TopBarWidget::updateAdaptiveLayout() {
|
2017-04-28 17:16:14 +00:00
|
|
|
updateControlsVisibility();
|
2017-09-16 16:53:41 +00:00
|
|
|
updateInfoToggleActive();
|
2019-04-24 14:12:35 +00:00
|
|
|
refreshUnreadBadge();
|
2017-09-16 16:53:41 +00:00
|
|
|
}
|
|
|
|
|
2019-04-24 14:12:35 +00:00
|
|
|
void TopBarWidget::refreshUnreadBadge() {
|
|
|
|
if (!Adaptive::OneColumn() && !_activeChat.folder()) {
|
|
|
|
if (_unreadBadge) {
|
|
|
|
unsubscribe(base::take(_unreadCounterSubscription));
|
|
|
|
_unreadBadge.destroy();
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
} else if (_unreadBadge) {
|
2017-11-17 14:54:01 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
_unreadBadge.create(this);
|
2019-05-26 12:08:34 +00:00
|
|
|
|
|
|
|
rpl::combine(
|
|
|
|
_back->geometryValue(),
|
|
|
|
_unreadBadge->widthValue()
|
|
|
|
) | rpl::start_with_next([=](QRect geometry, int width) {
|
|
|
|
_unreadBadge->move(
|
|
|
|
geometry.x() + geometry.width() - width,
|
|
|
|
geometry.y() + st::titleUnreadCounterTop);
|
|
|
|
}, _unreadBadge->lifetime());
|
|
|
|
|
2017-11-17 14:54:01 +00:00
|
|
|
_unreadBadge->show();
|
|
|
|
_unreadBadge->setAttribute(Qt::WA_TransparentForMouseEvents);
|
|
|
|
_unreadCounterSubscription = subscribe(
|
|
|
|
Global::RefUnreadCounterUpdate(),
|
2019-04-24 14:12:35 +00:00
|
|
|
[=] { updateUnreadBadge(); });
|
2017-11-17 14:54:01 +00:00
|
|
|
updateUnreadBadge();
|
|
|
|
}
|
|
|
|
|
2018-01-09 17:08:31 +00:00
|
|
|
void TopBarWidget::updateUnreadBadge() {
|
2017-11-17 14:54:01 +00:00
|
|
|
if (!_unreadBadge) return;
|
|
|
|
|
2019-07-24 11:13:51 +00:00
|
|
|
const auto muted = session().data().unreadBadgeMutedIgnoreOne(_activeChat);
|
|
|
|
const auto counter = session().data().unreadBadgeIgnoreOne(_activeChat);
|
2018-12-04 10:32:06 +00:00
|
|
|
const auto text = [&] {
|
|
|
|
if (!counter) {
|
|
|
|
return QString();
|
2017-11-17 14:54:01 +00:00
|
|
|
}
|
2018-12-04 10:32:06 +00:00
|
|
|
return (counter > 999)
|
|
|
|
? qsl("..%1").arg(counter % 100, 2, 10, QChar('0'))
|
|
|
|
: QString::number(counter);
|
|
|
|
}();
|
2019-04-24 14:12:35 +00:00
|
|
|
_unreadBadge->setText(text, !muted);
|
2017-11-17 14:54:01 +00:00
|
|
|
}
|
|
|
|
|
2018-01-09 17:08:31 +00:00
|
|
|
void TopBarWidget::updateInfoToggleActive() {
|
2017-09-16 16:53:41 +00:00
|
|
|
auto infoThirdActive = Adaptive::ThreeColumn()
|
2019-07-24 11:13:51 +00:00
|
|
|
&& (session().settings().thirdSectionInfoEnabled()
|
|
|
|
|| session().settings().tabbedReplacedWithInfo());
|
2017-09-16 16:53:41 +00:00
|
|
|
auto iconOverride = infoThirdActive
|
|
|
|
? &st::topBarInfoActive
|
|
|
|
: nullptr;
|
2017-11-07 15:12:54 +00:00
|
|
|
auto rippleOverride = infoThirdActive
|
2017-09-16 16:53:41 +00:00
|
|
|
? &st::lightButtonBgOver
|
|
|
|
: nullptr;
|
|
|
|
_infoToggle->setIconOverride(iconOverride, iconOverride);
|
2017-11-07 15:12:54 +00:00
|
|
|
_infoToggle->setRippleColorOverride(rippleOverride);
|
2016-04-12 21:31:28 +00:00
|
|
|
}
|
|
|
|
|
2018-01-09 17:08:31 +00:00
|
|
|
void TopBarWidget::updateOnlineDisplay() {
|
2018-01-22 17:39:20 +00:00
|
|
|
if (!_activeChat.peer()) return;
|
2017-11-13 08:05:56 +00:00
|
|
|
|
|
|
|
QString text;
|
2019-07-10 17:28:33 +00:00
|
|
|
const auto now = base::unixtime::now();
|
2017-11-13 08:05:56 +00:00
|
|
|
bool titlePeerTextOnline = false;
|
2018-11-20 13:34:07 +00:00
|
|
|
if (const auto user = _activeChat.peer()->asUser()) {
|
2019-07-24 11:13:51 +00:00
|
|
|
if (session().supportMode()
|
|
|
|
&& !session().supportHelper().infoCurrent(user).text.empty()) {
|
2018-11-20 15:36:36 +00:00
|
|
|
text = QString::fromUtf8("\xe2\x9a\xa0\xef\xb8\x8f check info");
|
|
|
|
titlePeerTextOnline = false;
|
|
|
|
} else {
|
|
|
|
text = Data::OnlineText(user, now);
|
|
|
|
titlePeerTextOnline = Data::OnlineTextActive(user, now);
|
|
|
|
}
|
2018-01-22 17:39:20 +00:00
|
|
|
} else if (const auto chat = _activeChat.peer()->asChat()) {
|
2017-11-13 08:05:56 +00:00
|
|
|
if (!chat->amIn()) {
|
2019-06-19 15:09:03 +00:00
|
|
|
text = tr::lng_chat_status_unaccessible(tr::now);
|
2017-12-01 18:38:44 +00:00
|
|
|
} else if (chat->participants.empty()) {
|
2017-11-13 08:05:56 +00:00
|
|
|
if (!_titlePeerText.isEmpty()) {
|
2019-04-08 11:53:08 +00:00
|
|
|
text = _titlePeerText.toString();
|
2017-11-13 08:05:56 +00:00
|
|
|
} else if (chat->count <= 0) {
|
2019-06-19 15:09:03 +00:00
|
|
|
text = tr::lng_group_status(tr::now);
|
2017-11-13 08:05:56 +00:00
|
|
|
} else {
|
2019-06-19 16:39:25 +00:00
|
|
|
text = tr::lng_chat_status_members(tr::now, lt_count_decimal, chat->count);
|
2017-11-13 08:05:56 +00:00
|
|
|
}
|
|
|
|
} else {
|
2019-07-24 11:13:51 +00:00
|
|
|
const auto self = session().user();
|
2017-11-13 08:05:56 +00:00
|
|
|
auto online = 0;
|
|
|
|
auto onlyMe = true;
|
2019-01-13 08:03:34 +00:00
|
|
|
for (const auto user : chat->participants) {
|
2017-12-17 08:13:26 +00:00
|
|
|
if (user->onlineTill > now) {
|
2017-11-13 08:05:56 +00:00
|
|
|
++online;
|
2018-09-11 12:50:40 +00:00
|
|
|
if (onlyMe && user != self) onlyMe = false;
|
2017-11-13 08:05:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (online > 0 && !onlyMe) {
|
2019-06-19 16:39:25 +00:00
|
|
|
auto membersCount = tr::lng_chat_status_members(tr::now, lt_count_decimal, chat->participants.size());
|
|
|
|
auto onlineCount = tr::lng_chat_status_online(tr::now, lt_count, online);
|
|
|
|
text = tr::lng_chat_status_members_online(tr::now, lt_members_count, membersCount, lt_online_count, onlineCount);
|
2017-11-13 08:05:56 +00:00
|
|
|
} else if (chat->participants.size() > 0) {
|
2019-06-19 16:39:25 +00:00
|
|
|
text = tr::lng_chat_status_members(tr::now, lt_count_decimal, chat->participants.size());
|
2017-11-13 08:05:56 +00:00
|
|
|
} else {
|
2019-06-19 15:09:03 +00:00
|
|
|
text = tr::lng_group_status(tr::now);
|
2017-11-13 08:05:56 +00:00
|
|
|
}
|
|
|
|
}
|
2018-01-22 17:39:20 +00:00
|
|
|
} else if (const auto channel = _activeChat.peer()->asChannel()) {
|
2017-11-13 08:05:56 +00:00
|
|
|
if (channel->isMegagroup() && channel->membersCount() > 0 && channel->membersCount() <= Global::ChatSizeMax()) {
|
2020-03-13 19:14:23 +00:00
|
|
|
if (channel->lastParticipantsRequestNeeded()) {
|
2019-07-24 11:13:51 +00:00
|
|
|
session().api().requestLastParticipants(channel);
|
2017-11-13 08:05:56 +00:00
|
|
|
}
|
2019-07-24 11:13:51 +00:00
|
|
|
const auto self = session().user();
|
2017-11-13 08:05:56 +00:00
|
|
|
auto online = 0;
|
2018-09-11 12:50:40 +00:00
|
|
|
auto onlyMe = true;
|
2017-11-13 08:05:56 +00:00
|
|
|
for (auto &participant : std::as_const(channel->mgInfo->lastParticipants)) {
|
2017-12-17 08:13:26 +00:00
|
|
|
if (participant->onlineTill > now) {
|
2017-11-13 08:05:56 +00:00
|
|
|
++online;
|
2018-09-11 12:50:40 +00:00
|
|
|
if (onlyMe && participant != self) {
|
2017-11-13 08:05:56 +00:00
|
|
|
onlyMe = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (online && !onlyMe) {
|
2019-06-19 16:39:25 +00:00
|
|
|
auto membersCount = tr::lng_chat_status_members(tr::now, lt_count_decimal, channel->membersCount());
|
|
|
|
auto onlineCount = tr::lng_chat_status_online(tr::now, lt_count, online);
|
|
|
|
text = tr::lng_chat_status_members_online(tr::now, lt_members_count, membersCount, lt_online_count, onlineCount);
|
2017-11-13 08:05:56 +00:00
|
|
|
} else if (channel->membersCount() > 0) {
|
2019-06-19 16:39:25 +00:00
|
|
|
text = tr::lng_chat_status_members(tr::now, lt_count_decimal, channel->membersCount());
|
2017-11-13 08:05:56 +00:00
|
|
|
} else {
|
2019-06-19 15:09:03 +00:00
|
|
|
text = tr::lng_group_status(tr::now);
|
2017-11-13 08:05:56 +00:00
|
|
|
}
|
|
|
|
} else if (channel->membersCount() > 0) {
|
2019-06-19 16:39:25 +00:00
|
|
|
text = tr::lng_chat_status_members(tr::now, lt_count_decimal, channel->membersCount());
|
2019-06-19 15:09:03 +00:00
|
|
|
|
2017-11-13 08:05:56 +00:00
|
|
|
} else {
|
2019-06-19 15:09:03 +00:00
|
|
|
text = channel->isMegagroup() ? tr::lng_group_status(tr::now) : tr::lng_channel_status(tr::now);
|
2017-11-13 08:05:56 +00:00
|
|
|
}
|
|
|
|
}
|
2019-04-08 11:53:08 +00:00
|
|
|
if (_titlePeerText.toString() != text) {
|
2018-11-15 15:36:04 +00:00
|
|
|
_titlePeerText.setText(st::dialogsTextStyle, text);
|
2017-11-13 08:05:56 +00:00
|
|
|
_titlePeerTextOnline = titlePeerTextOnline;
|
|
|
|
updateMembersShowArea();
|
|
|
|
update();
|
|
|
|
}
|
|
|
|
updateOnlineDisplayTimer();
|
|
|
|
}
|
|
|
|
|
2018-01-09 17:08:31 +00:00
|
|
|
void TopBarWidget::updateOnlineDisplayTimer() {
|
2018-01-22 17:39:20 +00:00
|
|
|
if (!_activeChat.peer()) return;
|
2017-11-13 08:05:56 +00:00
|
|
|
|
2019-07-10 17:28:33 +00:00
|
|
|
const auto now = base::unixtime::now();
|
2019-02-19 06:57:53 +00:00
|
|
|
auto minTimeout = crl::time(86400);
|
2017-12-08 14:15:00 +00:00
|
|
|
const auto handleUser = [&](not_null<UserData*> user) {
|
2017-12-17 08:13:26 +00:00
|
|
|
auto hisTimeout = Data::OnlineChangeTimeout(user, now);
|
|
|
|
accumulate_min(minTimeout, hisTimeout);
|
2017-12-08 14:15:00 +00:00
|
|
|
};
|
2018-01-22 17:39:20 +00:00
|
|
|
if (const auto user = _activeChat.peer()->asUser()) {
|
2017-12-08 14:15:00 +00:00
|
|
|
handleUser(user);
|
2018-01-22 17:39:20 +00:00
|
|
|
} else if (auto chat = _activeChat.peer()->asChat()) {
|
2019-01-13 08:03:34 +00:00
|
|
|
for (const auto user : chat->participants) {
|
2017-12-08 14:15:00 +00:00
|
|
|
handleUser(user);
|
2017-11-13 08:05:56 +00:00
|
|
|
}
|
2018-01-22 17:39:20 +00:00
|
|
|
} else if (_activeChat.peer()->isChannel()) {
|
2017-11-13 08:05:56 +00:00
|
|
|
}
|
2017-12-17 08:13:26 +00:00
|
|
|
updateOnlineDisplayIn(minTimeout);
|
2016-04-12 21:31:28 +00:00
|
|
|
}
|
|
|
|
|
2019-02-19 06:57:53 +00:00
|
|
|
void TopBarWidget::updateOnlineDisplayIn(crl::time timeout) {
|
2017-11-13 08:05:56 +00:00
|
|
|
_onlineUpdater.callOnce(timeout);
|
|
|
|
}
|
2018-01-09 17:08:31 +00:00
|
|
|
|
|
|
|
} // namespace HistoryView
|