Display empty feed placeholder.

This commit is contained in:
John Preston 2018-02-05 23:19:51 +03:00
parent e102cb1469
commit 6726826c17
11 changed files with 102 additions and 8 deletions

View File

@ -1423,6 +1423,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
"lng_feed_ungroup" = "Ungroup from feed";
"lng_feed_channel_added" = "Channel added to your feed.";
"lng_feed_channel_removed" = "Channel removed from your feed.";
"lng_feed_no_messages" = "No messages in this feed yet";
"lng_info_feed_title" = "Feed Info";

View File

@ -332,6 +332,7 @@ bool MessagesSliceBuilder::removeFromChannel(ChannelId channelId) {
}
}
_skippedBefore = _skippedAfter = base::none;
checkInsufficient();
return true;
}

View File

@ -237,6 +237,9 @@ bool SparseIdsSliceBuilder::removeOne(MsgId messageId) {
changed = true;
}
}
if (changed) {
checkInsufficient();
}
return changed;
}

View File

@ -13,6 +13,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "history/view/history_view_message.h"
#include "history/view/history_view_service_message.h"
#include "history/history_item.h"
#include "history/history_service.h"
#include "history/history_inner_widget.h"
#include "core/event_filter.h"
#include "lang/lang_keys.h"
#include "ui/widgets/buttons.h"
@ -380,7 +382,34 @@ base::optional<int> Widget::listUnreadBarView(
return base::make_optional(int(minimal - begin(elements)));
}
void Widget::validateEmptyTextItem() {
if (!_inner->isEmpty()) {
_emptyTextView = nullptr;
_emptyTextItem = nullptr;
update();
return;
} else if (_emptyTextItem) {
return;
}
const auto channels = _feed->channels();
if (channels.empty()) {
return;
}
const auto history = channels[0];
_emptyTextItem.reset(new HistoryService(
history,
clientMsgId(),
unixtime(),
{ lang(lng_feed_no_messages) }));
_emptyTextView = _emptyTextItem->createView(
HistoryInner::ElementDelegate());
updateControlsGeometry();
update();
}
void Widget::listContentRefreshed() {
validateEmptyTextItem();
if (!_nextAnimatedScrollPosition) {
return;
}
@ -457,6 +486,10 @@ void Widget::updateControlsGeometry() {
contentWidth,
_showNext->height());
_showNext->setGeometry(fullWidthButtonRect);
if (_emptyTextView) {
_emptyTextView->resizeGetHeight(width());
}
}
void Widget::paintEvent(QPaintEvent *e) {
@ -475,6 +508,22 @@ void Widget::paintEvent(QPaintEvent *e) {
_scrollDownShown.step(ms);
SectionWidget::PaintBackground(this, e);
if (_emptyTextView) {
Painter p(this);
const auto clip = e->rect();
const auto left = 0;
const auto top = (height()
- _showNext->height()
- _emptyTextView->height()) / 2;
p.translate(left, top);
_emptyTextView->draw(
p,
clip.translated(-left, -top),
TextSelection(),
getms());
}
}
void Widget::onScroll() {

View File

@ -11,6 +11,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "window/section_widget.h"
#include "window/section_memento.h"
#include "data/data_feed.h"
#include "history/history_item.h"
#include "history/admin_log/history_admin_log_item.h"
namespace Ui {
class ScrollArea;
@ -103,6 +105,7 @@ private:
void restoreState(not_null<Memento*> memento);
void showAtPosition(Data::MessagePosition position);
bool showAtPositionNow(Data::MessagePosition position);
void validateEmptyTextItem();
void setupScrollDownButton();
void scrollDownClicked();
@ -122,6 +125,8 @@ private:
object_ptr<Ui::FlatButton> _showNext;
bool _skipScrollEvent = false;
bool _undefinedAroundPosition = false;
std::unique_ptr<HistoryItem, HistoryItem::Destroyer> _emptyTextItem;
std::unique_ptr<HistoryView::Element> _emptyTextView;
base::optional<Data::MessagePosition> _nextAnimatedScrollPosition;
int _nextAnimatedScrollDelta = 0;

View File

@ -71,6 +71,12 @@ not_null<HistoryItem*> CreateUnsupportedMessage(
} // namespace
void HistoryItem::HistoryItem::Destroyer::operator()(HistoryItem *value) {
if (value) {
value->destroy();
}
}
HistoryItem::HistoryItem(
not_null<History*> history,
MsgId id,

View File

@ -60,6 +60,11 @@ public:
not_null<History*> history,
const MTPMessage &message);
struct Destroyer {
void operator()(HistoryItem *value);
};
virtual void dependencyItemRemoved(HistoryItem *dependency) {
}
virtual bool updateDependencyItem() {

View File

@ -6690,14 +6690,27 @@ void HistoryWidget::paintEvent(QPaintEvent *e) {
HistoryView::paintEmpty(p, width(), height() - _field->height() - 2 * st::historySendPadding);
}
} else {
style::font font(st::msgServiceFont);
int32 w = font->width(lang(lng_willbe_history)) + st::msgPadding.left() + st::msgPadding.right(), h = font->height + st::msgServicePadding.top() + st::msgServicePadding.bottom() + 2;
QRect tr((width() - w) / 2, (height() - _field->height() - 2 * st::historySendPadding - h) / 2, w, h);
const auto w = st::msgServiceFont->width(lang(lng_willbe_history))
+ st::msgPadding.left()
+ st::msgPadding.right();
const auto h = st::msgServiceFont->height
+ st::msgServicePadding.top()
+ st::msgServicePadding.bottom();
const auto tr = QRect(
(width() - w) / 2,
st::msgServiceMargin.top() + (height()
- _field->height()
- 2 * st::historySendPadding
- h
- st::msgServiceMargin.top()
- st::msgServiceMargin.bottom()) / 2,
w,
h);
HistoryView::ServiceMessagePainter::paintBubble(p, tr.x(), tr.y(), tr.width(), tr.height());
p.setPen(st::msgServiceFg);
p.setFont(font->f);
p.drawText(tr.left() + st::msgPadding.left(), tr.top() + st::msgServicePadding.top() + 1 + font->ascent, lang(lng_willbe_history));
p.setFont(st::msgServiceFont->f);
p.drawTextLeft(tr.left() + st::msgPadding.left(), tr.top() + st::msgServicePadding.top(), width(), lang(lng_willbe_history));
}
}

View File

@ -463,7 +463,11 @@ not_null<Element*> ListWidget::enforceViewForItem(
void ListWidget::updateAroundPositionFromRows() {
_aroundIndex = findNearestItem(_aroundPosition);
if (_aroundIndex >= 0) {
_aroundPosition = _items[_aroundIndex]->data()->position();
const auto newPosition = _items[_aroundIndex]->data()->position();
if (_aroundPosition != newPosition) {
_aroundPosition = newPosition;
crl::on_main(this, [=] { refreshViewer(); });
}
}
}
@ -923,6 +927,10 @@ bool ListWidget::loadedAtBottom() const {
return _slice.skippedAfter && (*_slice.skippedAfter == 0);
}
bool ListWidget::isEmpty() const {
return loadedAtTop() && loadedAtBottom() && (_itemsHeight == 0);
}
int ListWidget::itemMinimalHeight() const {
return st::msgMarginTopAttached
+ st::msgPhotoSize
@ -2235,6 +2243,7 @@ void ListWidget::refreshAttachmentsFromTill(int from, int till) {
Expects(from >= 0 && from <= till && till <= int(_items.size()));
if (from == till) {
updateSize();
return;
}
auto view = _items[from].get();

View File

@ -159,6 +159,7 @@ public:
bool loadedAtTop() const;
bool loadedAtBottomKnown() const;
bool loadedAtBottom() const;
bool isEmpty() const;
// AbstractTooltipShower interface
QString tooltipText() const override;

View File

@ -860,10 +860,11 @@ void FeedUserpicButton::checkParts() {
bool FeedUserpicButton::partsAreValid() const {
const auto &channels = _feed->channels();
if (std::min(int(channels.size()), 4) != _parts.size()) {
const auto count = std::min(int(channels.size()), 4);
if (count != _parts.size()) {
return false;
}
for (auto i = 0; i != 4; ++i) {
for (auto i = 0; i != count; ++i) {
if (channels[i]->peer != _parts[i].channel) {
return false;
}