Remove counter from unread bar.

This commit is contained in:
John Preston 2020-02-20 18:16:42 +04:00
parent 1980c1004e
commit ee3e9af63a
7 changed files with 26 additions and 85 deletions

View File

@ -1369,7 +1369,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
"lng_user_action_upload_file" = "{user} is sending a file";
"lng_unread_bar#one" = "{count} unread message";
"lng_unread_bar#other" = "{count} unread messages";
//"lng_unread_bar_some" = "Unread messages";
"lng_unread_bar_some" = "Unread messages";
"lng_maps_point" = "Location";
"lng_save_photo" = "Save image";

View File

@ -1367,8 +1367,8 @@ HistoryBlock *History::prepareBlockForAddingItem() {
}
void History::viewReplaced(not_null<const Element*> was, Element *now) {
if (scrollTopItem == was) scrollTopItem= now;
if (_firstUnreadView == was) _firstUnreadView= now;
if (scrollTopItem == was) scrollTopItem = now;
if (_firstUnreadView == was) _firstUnreadView = now;
if (_unreadBarView == was) _unreadBarView = now;
}
@ -1803,14 +1803,6 @@ void History::setUnreadCount(int newUnreadCount) {
calculateFirstUnreadMessage();
}
}
if (_unreadBarView) {
const auto count = chatListUnreadCount();
if (count > 0) {
_unreadBarView->setUnreadBarCount(count);
} else {
_unreadBarView->setUnreadBarFreezed();
}
}
Notify::peerUpdatedDelayed(
peer,
Notify::PeerUpdate::Flag::UnreadViewChanged);
@ -2064,7 +2056,7 @@ void History::addUnreadBar() {
}
if (const auto count = chatListUnreadCount()) {
_unreadBarView = _firstUnreadView;
_unreadBarView->setUnreadBarCount(count);
_unreadBarView->createUnreadBar();
}
}
@ -2074,17 +2066,6 @@ void History::destroyUnreadBar() {
}
}
bool History::hasNotFreezedUnreadBar() const {
if (_firstUnreadView) {
if (const auto view = _unreadBarView) {
if (const auto bar = view->Get<HistoryView::UnreadBar>()) {
return !bar->freezed;
}
}
}
return false;
}
void History::unsetFirstUnreadMessage() {
_firstUnreadView = nullptr;
}

View File

@ -205,7 +205,6 @@ public:
bool changeMute(bool newMute);
void addUnreadBar();
void destroyUnreadBar();
[[nodiscard]] bool hasNotFreezedUnreadBar() const;
[[nodiscard]] Element *unreadBar() const;
void calculateFirstUnreadMessage();
void unsetFirstUnreadMessage();

View File

@ -2389,7 +2389,7 @@ void HistoryWidget::messagesReceived(PeerData *peer, const MTPmessages_Messages
_preloadDownRequest = 0;
preloadHistoryIfNeeded();
if (_history->loadedAtBottom()) {
App::wnd()->checkHistoryActivation();
checkHistoryActivation();
}
} else if (_firstLoadRequest == requestId) {
if (toMigrated) {
@ -3138,7 +3138,7 @@ void HistoryWidget::doneShow() {
handlePendingHistoryUpdate();
}
preloadHistoryIfNeeded();
App::wnd()->checkHistoryActivation();
checkHistoryActivation();
App::wnd()->setInnerFocus();
}
@ -4986,7 +4986,6 @@ int HistoryWidget::countAutomaticScrollTop() {
if (history->unreadBar() != nullptr) {
setMsgId(ShowAtUnreadMsgId);
result = countInitialScrollTop();
App::wnd()->checkHistoryActivation();
if (session().supportMode()) {
history->unsetFirstUnreadMessage();
}
@ -5109,7 +5108,7 @@ void HistoryWidget::updateHistoryGeometry(
_historyInited = true;
_scrollToAnimation.stop();
}
auto newScrollTop = initial
const auto newScrollTop = initial
? countInitialScrollTop()
: countAutomaticScrollTop();
if (_scroll->scrollTop() == newScrollTop) {

View File

@ -127,14 +127,8 @@ TextSelection ShiftItemSelection(
return ShiftItemSelection(selection, byText.length());
}
void UnreadBar::init(int newCount) {
if (freezed) {
return;
}
count = newCount;
text = /*(count == kCountUnknown) // #feed
? tr::lng_unread_bar_some(tr::now)
: */tr::lng_unread_bar(tr::now, lt_count, count);
void UnreadBar::init() {
text = tr::lng_unread_bar_some(tr::now);
width = st::semiboldFont->width(text);
}
@ -416,6 +410,18 @@ bool Element::computeIsAttachToPrevious(not_null<Element*> previous) {
return false;
}
void Element::createUnreadBar() {
if (!AddComponents(UnreadBar::Bit())) {
return;
}
const auto bar = Get<UnreadBar>();
bar->init();
if (data()->mainView() == this) {
recountAttachToPreviousInBlocks();
}
history()->owner().requestViewResize(this);
}
void Element::destroyUnreadBar() {
if (!Has<UnreadBar>()) {
return;
@ -427,29 +433,6 @@ void Element::destroyUnreadBar() {
}
}
void Element::setUnreadBarCount(int count) {
const auto changed = AddComponents(UnreadBar::Bit());
const auto bar = Get<UnreadBar>();
if (bar->freezed) {
return;
}
bar->init(count);
if (changed) {
if (data()->mainView() == this) {
recountAttachToPreviousInBlocks();
}
history()->owner().requestViewResize(this);
} else {
history()->owner().requestViewRepaint(this);
}
}
void Element::setUnreadBarFreezed() {
if (const auto bar = Get<UnreadBar>()) {
bar->freezed = true;
}
}
int Element::displayedDateHeight() const {
if (auto date = Get<DateBadge>()) {
return date->height();

View File

@ -96,26 +96,15 @@ TextSelection ShiftItemSelection(
// Any HistoryView::Element can have this Component for
// displaying the unread messages bar above the message.
struct UnreadBar : public RuntimeComponent<UnreadBar, Element> {
void init(int newCount);
void init();
static int height();
static int marginTop();
void paint(Painter &p, int y, int w) const;
static constexpr auto kCountUnknown = std::numeric_limits<int>::max();
QString text;
int width = 0;
int count = 0;
// If unread bar is freezed the new messages do not
// increment the counter displayed by this bar.
//
// It happens when we've opened the conversation and
// we've seen the bar and new messages are marked as read
// as soon as they are added to the chat history.
bool freezed = false;
};
@ -192,14 +181,9 @@ public:
bool computeIsAttachToPrevious(not_null<Element*> previous);
void setUnreadBarCount(int count);
void createUnreadBar();
void destroyUnreadBar();
// marks the unread bar as freezed so that unread
// messages count will not change for this bar
// when the new messages arrive in this chat history
void setUnreadBarFreezed();
int displayedDateHeight() const;
bool displayDate() const;
bool isInOneDayWithPrevious() const;

View File

@ -462,7 +462,7 @@ void ListWidget::checkUnreadBarCreation() {
if (!_unreadBarElement) {
if (const auto index = _delegate->listUnreadBarView(_items)) {
_unreadBarElement = _items[*index].get();
_unreadBarElement->setUnreadBarCount(UnreadBar::kCountUnknown);
_unreadBarElement->createUnreadBar();
refreshAttachmentsAtIndex(*index);
}
}
@ -2497,14 +2497,9 @@ void ListWidget::viewReplaced(not_null<const Element*> was, Element *now) {
if (_overElement == was) _overElement = now;
if (_unreadBarElement == was) {
const auto bar = _unreadBarElement->Get<UnreadBar>();
const auto count = bar ? bar->count : 0;
const auto freezed = bar ? bar->freezed : false;
_unreadBarElement = now;
if (now && count) {
_unreadBarElement->setUnreadBarCount(count);
if (freezed) {
_unreadBarElement->setUnreadBarFreezed();
}
if (now && bar) {
_unreadBarElement->createUnreadBar();
}
}
}