Improve empty / archived stories section.

This commit is contained in:
John Preston 2023-06-21 09:34:59 +04:00
parent d2dd63e90a
commit 19d0bf142c
10 changed files with 73 additions and 33 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.6 KiB

View File

@ -3818,6 +3818,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
"lng_stories_archive_button" = "Stories Archive"; "lng_stories_archive_button" = "Stories Archive";
"lng_stories_recent_button" = "Recent Stories"; "lng_stories_recent_button" = "Recent Stories";
"lng_stories_archive_title" = "Stories Archive"; "lng_stories_archive_title" = "Stories Archive";
"lng_stories_archive_about" = "Only you can see archived stories unless you choose to save them to your profile.";
"lng_stories_reply_sent" = "Message Sent"; "lng_stories_reply_sent" = "Message Sent";
"lng_stories_hidden_to_contacts" = "Those stories are now shown only in your Contacts list."; "lng_stories_hidden_to_contacts" = "Those stories are now shown only in your Contacts list.";
"lng_stories_shown_in_chats" = "Those stories are now shown in your Chats list."; "lng_stories_shown_in_chats" = "Those stories are now shown in your Chats list.";

View File

@ -345,6 +345,7 @@ Content State::next() {
.thumbnail = std::move(userpic), .thumbnail = std::move(userpic),
.unread = info.unread, .unread = info.unread,
.hidden = info.hidden, .hidden = info.hidden,
.profile = true,
.skipSmall = user->isSelf(), .skipSmall = user->isSelf(),
}); });
} }
@ -419,7 +420,7 @@ rpl::producer<Content> LastForPeer(not_null<PeerData*> peer) {
return; return;
} }
auto resolving = false; auto resolving = false;
auto result = Content(); auto result = Content{ .full = true };
for (const auto id : ids) { for (const auto id : ids) {
const auto storyId = FullStoryId{ peerId, id }; const auto storyId = FullStoryId{ peerId, id };
const auto maybe = stories->lookup(storyId); const auto maybe = stories->lookup(storyId);

View File

@ -763,9 +763,11 @@ void List::contextMenuEvent(QContextMenuEvent *e) {
const auto id = item.element.id; const auto id = item.element.id;
const auto hidden = item.element.hidden; const auto hidden = item.element.hidden;
_menu->addAction(tr::lng_context_view_profile(tr::now), [=] { if (item.element.profile) {
_showProfileRequests.fire_copy(id); _menu->addAction(tr::lng_context_view_profile(tr::now), [=] {
}); _showProfileRequests.fire_copy(id);
});
}
if (!_content.full || hidden) { if (!_content.full || hidden) {
_menu->addAction(hidden _menu->addAction(hidden
? tr::lng_stories_show_in_chats(tr::now) ? tr::lng_stories_show_in_chats(tr::now)

View File

@ -36,6 +36,7 @@ struct Element {
std::shared_ptr<Thumbnail> thumbnail; std::shared_ptr<Thumbnail> thumbnail;
bool unread = false; bool unread = false;
bool hidden = false; bool hidden = false;
bool profile = false;
bool skipSmall = false; bool skipSmall = false;
friend inline bool operator==( friend inline bool operator==(

View File

@ -576,6 +576,7 @@ infoEmptyAudio: icon {{ "info/info_media_audio_empty", infoEmptyFg }};
infoEmptyFile: icon {{ "info/info_media_file_empty", infoEmptyFg }}; infoEmptyFile: icon {{ "info/info_media_file_empty", infoEmptyFg }};
infoEmptyVoice: icon {{ "info/info_media_voice_empty", infoEmptyFg }}; infoEmptyVoice: icon {{ "info/info_media_voice_empty", infoEmptyFg }};
infoEmptyLink: icon {{ "info/info_media_link_empty", infoEmptyFg }}; infoEmptyLink: icon {{ "info/info_media_link_empty", infoEmptyFg }};
infoEmptyStories: icon {{ "info/info_media_story_empty", infoEmptyFg }};
infoEmptyIconTop: 120px; infoEmptyIconTop: 120px;
infoEmptyLabelTop: 40px; infoEmptyLabelTop: 40px;
infoEmptyLabelSkip: 20px; infoEmptyLabelSkip: 20px;
@ -584,6 +585,14 @@ infoEmptyLabel: FlatLabel(defaultFlatLabel) {
textFg: windowSubTextFg; textFg: windowSubTextFg;
} }
infoStoriesAboutArchive: FlatLabel(defaultFlatLabel) {
minWidth: 245px;
align: align(top);
textFg: windowSubTextFg;
style: defaultTextStyle;
}
infoStoriesAboutArchivePadding: margins(22px, 8px, 22px, 16px);
editPeerBottomButtonsLayoutMargins: margins(0px, 7px, 0px, 0px); editPeerBottomButtonsLayoutMargins: margins(0px, 7px, 0px, 0px);
editPeerTopButtonsLayoutSkip: 13px; editPeerTopButtonsLayoutSkip: 13px;

View File

@ -59,7 +59,7 @@ void EmptyWidget::setFullHeight(rpl::producer<int> fullHeightValue) {
) | rpl::start_with_next([this](int fullHeight) { ) | rpl::start_with_next([this](int fullHeight) {
// Make icon center be on 1/3 height. // Make icon center be on 1/3 height.
auto iconCenter = fullHeight / 3; auto iconCenter = fullHeight / 3;
auto iconHeight = st::infoEmptyFile.height(); auto iconHeight = st::infoEmptyStories.height();
auto iconTop = iconCenter - iconHeight / 2; auto iconTop = iconCenter - iconHeight / 2;
_height = iconTop + st::infoEmptyIconTop; _height = iconTop + st::infoEmptyIconTop;
resizeToWidth(width()); resizeToWidth(width());
@ -81,9 +81,9 @@ int EmptyWidget::resizeGetHeight(int newWidth) {
void EmptyWidget::paintEvent(QPaintEvent *e) { void EmptyWidget::paintEvent(QPaintEvent *e) {
auto p = QPainter(this); auto p = QPainter(this);
const auto iconLeft = (width() - st::infoEmptyFile.width()) / 2; const auto iconLeft = (width() - st::infoEmptyStories.width()) / 2;
const auto iconTop = height() - st::infoEmptyIconTop; const auto iconTop = height() - st::infoEmptyIconTop;
st::infoEmptyFile.paint(p, iconLeft, iconTop, width()); st::infoEmptyStories.paint(p, iconLeft, iconTop, width());
} }
InnerWidget::InnerWidget( InnerWidget::InnerWidget(
@ -99,28 +99,31 @@ InnerWidget::InnerWidget(
_list = setupList(); _list = setupList();
} }
void InnerWidget::setupArchive() { void InnerWidget::setupTop() {
const auto key = _controller->key(); const auto key = _controller->key();
const auto peer = key.storiesPeer(); const auto peer = key.storiesPeer();
if (peer if (peer
&& peer->isSelf() && peer->isSelf()
&& key.storiesTab() == Stories::Tab::Saved && key.storiesTab() == Stories::Tab::Saved
&& _isStackBottom) { && _isStackBottom) {
createArchiveButton(); createButtons();
} else if (key.storiesTab() == Stories::Tab::Archive) {
createAboutArchive();
} else { } else {
_buttons.destroy(); _top.destroy();
refreshHeight(); refreshHeight();
} }
} }
void InnerWidget::createArchiveButton() { void InnerWidget::createButtons() {
_buttons.create(this); _top.create(this);
_buttons->show(); _top->show();
_topHeight = _top->heightValue();
const auto stories = &_controller->session().data().stories(); const auto stories = &_controller->session().data().stories();
const auto self = _controller->session().user(); const auto self = _controller->session().user();
const auto archive = ::Settings::AddButton( const auto archive = ::Settings::AddButton(
_buttons, _top,
tr::lng_stories_archive_button(), tr::lng_stories_archive_button(),
st::infoSharedMediaButton); st::infoSharedMediaButton);
archive->addClickHandler([=] { archive->addClickHandler([=] {
@ -144,11 +147,11 @@ void InnerWidget::createArchiveButton() {
st::infoIconMediaStoriesArchive, st::infoIconMediaStoriesArchive,
st::infoSharedMediaButtonIconPosition)->show(); st::infoSharedMediaButtonIconPosition)->show();
const auto recentWrap = _buttons->add( const auto recentWrap = _top->add(
object_ptr<Ui::SlideWrap<Ui::SettingsButton>>( object_ptr<Ui::SlideWrap<Ui::SettingsButton>>(
_buttons, _top,
::Settings::CreateButton( ::Settings::CreateButton(
_buttons, _top,
tr::lng_stories_recent_button(), tr::lng_stories_recent_button(),
st::infoSharedMediaButton))); st::infoSharedMediaButton)));
@ -204,16 +207,36 @@ void InnerWidget::createArchiveButton() {
return !content.elements.empty(); return !content.elements.empty();
})); }));
_buttons->add(object_ptr<Ui::FixedHeightWidget>( _top->add(object_ptr<Ui::FixedHeightWidget>(
_buttons, _top,
st::infoProfileSkip)); st::infoProfileSkip));
_buttons->add(object_ptr<Ui::BoxContentDivider>(_buttons)); _top->add(object_ptr<Ui::BoxContentDivider>(_top));
_buttons->resizeToWidth(width()); _top->resizeToWidth(width());
_buttons->heightValue( _top->heightValue(
) | rpl::start_with_next([=] { ) | rpl::start_with_next([=] {
refreshHeight(); refreshHeight();
}, _buttons->lifetime()); }, _top->lifetime());
}
void InnerWidget::createAboutArchive() {
_top.create(this);
_top->show();
_topHeight = _top->heightValue();
_top->add(object_ptr<Ui::DividerLabel>(
_top,
object_ptr<Ui::FlatLabel>(
_top,
tr::lng_stories_archive_about(),
st::infoStoriesAboutArchive),
st::infoStoriesAboutArchivePadding));
_top->resizeToWidth(width());
_top->heightValue(
) | rpl::start_with_next([=] {
refreshHeight();
}, _top->lifetime());
} }
void InnerWidget::visibleTopBottomUpdated( void InnerWidget::visibleTopBottomUpdated(
@ -277,8 +300,8 @@ int InnerWidget::resizeGetHeight(int newWidth) {
_inResize = true; _inResize = true;
auto guard = gsl::finally([this] { _inResize = false; }); auto guard = gsl::finally([this] { _inResize = false; });
if (_buttons) { if (_top) {
_buttons->resizeToWidth(newWidth); _top->resizeToWidth(newWidth);
} }
_list->resizeToWidth(newWidth); _list->resizeToWidth(newWidth);
_empty->resizeToWidth(newWidth); _empty->resizeToWidth(newWidth);
@ -294,9 +317,9 @@ void InnerWidget::refreshHeight() {
int InnerWidget::recountHeight() { int InnerWidget::recountHeight() {
auto top = 0; auto top = 0;
if (_buttons) { if (_top) {
_buttons->moveToLeft(0, top); _top->moveToLeft(0, top);
top += _buttons->heightNoMargins() - st::lineWidth; top += _top->heightNoMargins() - st::lineWidth;
} }
auto listHeight = 0; auto listHeight = 0;
if (_list) { if (_list) {
@ -321,7 +344,8 @@ void InnerWidget::setScrollHeightValue(rpl::producer<int> value) {
_listTops.events_starting_with( _listTops.events_starting_with(
_list->topValue() _list->topValue()
) | rpl::flatten_latest(), ) | rpl::flatten_latest(),
_1 - _2)); _topHeight.value(),
_1 - _2 + _3));
} }
rpl::producer<Ui::ScrollToRequest> InnerWidget::scrollToRequests() const { rpl::producer<Ui::ScrollToRequest> InnerWidget::scrollToRequests() const {

View File

@ -40,7 +40,7 @@ public:
bool showInternal(not_null<Memento*> memento); bool showInternal(not_null<Memento*> memento);
void setIsStackBottom(bool isStackBottom) { void setIsStackBottom(bool isStackBottom) {
_isStackBottom = isStackBottom; _isStackBottom = isStackBottom;
setupArchive(); setupTop();
} }
void saveState(not_null<Memento*> memento); void saveState(not_null<Memento*> memento);
@ -64,14 +64,15 @@ private:
int recountHeight(); int recountHeight();
void refreshHeight(); void refreshHeight();
void setupArchive(); void setupTop();
void createArchiveButton(); void createButtons();
void createAboutArchive();
object_ptr<Media::ListWidget> setupList(); object_ptr<Media::ListWidget> setupList();
const not_null<Controller*> _controller; const not_null<Controller*> _controller;
object_ptr<Ui::VerticalLayout> _buttons = { nullptr }; object_ptr<Ui::VerticalLayout> _top = { nullptr };
object_ptr<Media::ListWidget> _list = { nullptr }; object_ptr<Media::ListWidget> _list = { nullptr };
object_ptr<EmptyWidget> _empty; object_ptr<EmptyWidget> _empty;
@ -81,6 +82,7 @@ private:
rpl::event_stream<Ui::ScrollToRequest> _scrollToRequests; rpl::event_stream<Ui::ScrollToRequest> _scrollToRequests;
rpl::event_stream<rpl::producer<SelectedItems>> _selectedLists; rpl::event_stream<rpl::producer<SelectedItems>> _selectedLists;
rpl::event_stream<rpl::producer<int>> _listTops; rpl::event_stream<rpl::producer<int>> _listTops;
rpl::variable<int> _topHeight;
}; };