Apply editions in realtime, show badge.

This commit is contained in:
John Preston 2023-07-05 16:18:55 +04:00
parent ee507722ba
commit 12fe0a836a
8 changed files with 54 additions and 6 deletions

View File

@ -260,6 +260,10 @@ bool Story::forbidsForward() const {
return _noForwards;
}
bool Story::edited() const {
return _edited;
}
bool Story::canDownload() const {
return !forbidsForward() || _peer->isSelf();
}
@ -369,6 +373,7 @@ void Story::applyViewsSlice(
bool Story::applyChanges(StoryMedia media, const MTPDstoryItem &data) {
const auto pinned = data.is_pinned();
const auto edited = data.is_edited();
const auto isPublic = data.is_public();
const auto closeFriends = data.is_close_friends();
const auto noForwards = data.is_noforwards();
@ -395,6 +400,7 @@ bool Story::applyChanges(StoryMedia media, const MTPDstoryItem &data) {
const auto changed = (_media != media)
|| (_pinned != pinned)
|| (_edited != edited)
|| (_isPublic != isPublic)
|| (_closeFriends != closeFriends)
|| (_noForwards != noForwards)
@ -405,6 +411,7 @@ bool Story::applyChanges(StoryMedia media, const MTPDstoryItem &data) {
return false;
}
_media = std::move(media);
_edited = edited;
_pinned = pinned;
_isPublic = isPublic;
_closeFriends = closeFriends;

View File

@ -89,6 +89,7 @@ public:
[[nodiscard]] bool isPublic() const;
[[nodiscard]] bool closeFriends() const;
[[nodiscard]] bool forbidsForward() const;
[[nodiscard]] bool edited() const;
[[nodiscard]] bool canDownload() const;
[[nodiscard]] bool canShare() const;
@ -128,6 +129,7 @@ private:
bool _isPublic : 1 = false;
bool _closeFriends : 1 = false;
bool _noForwards : 1 = false;
bool _edited : 1 = false;
};

View File

@ -741,20 +741,24 @@ void Controller::show(
_slider->raise();
}
if (_shown == storyId) {
_captionText = story->caption();
_captionFullView = nullptr;
_header->show({
.user = user,
.date = story->date(),
.edited = story->edited(),
});
if (_shown == storyId && _session == &story->session()) {
return;
}
_shown = storyId;
_viewed = false;
_captionText = story->caption();
_captionFullView = nullptr;
invalidate_weak_ptrs(&_viewsLoadGuard);
_reactions->hide();
if (_replyFocused) {
unfocusReply();
}
_header->show({ .user = user, .date = story->date() });
_replyArea->show({
.user = unsupported ? nullptr : user,
.id = story->id(),
@ -781,6 +785,14 @@ void Controller::show(
checkWaitingFor();
}
}, _sessionLifetime);
session->changes().storyUpdates(
Data::StoryUpdate::Flag::Edited
) | rpl::filter([=](const Data::StoryUpdate &update) {
return (update.story == this->story());
}) | rpl::start_with_next([=](const Data::StoryUpdate &update) {
show(update.story, _context);
_delegate->storiesRedisplay(update.story);
}, _sessionLifetime);
_sessionLifetime.add([=] {
session->data().stories().setPreloadingInViewer({});
});

View File

@ -13,6 +13,7 @@ struct FileChosen;
} // namespace ChatHelpers
namespace Data {
class Story;
struct StoriesContext;
} // namespace Data
@ -49,6 +50,7 @@ public:
-> rpl::producer<ChatHelpers::FileChosen> = 0;
[[nodiscard]] virtual auto storiesCachedReactionIconFactory()
-> HistoryView::Reactions::CachedIconFactory & = 0;
virtual void storiesRedisplay(not_null<Data::Story*> story) = 0;
virtual void storiesJumpTo(
not_null<Main::Session*> session,
FullStoryId id,

View File

@ -75,6 +75,15 @@ struct Timestamp {
return { Ui::FormatDateTime(whenFull) };
}
[[nodiscard]] Timestamp ComposeDetails(HeaderData data, TimeId now) {
auto result = ComposeTimestamp(data.date, now);
if (data.edited) {
result.text.append(
QString::fromUtf8(" \xE2\x80\xA2 ") + tr::lng_edited(tr::now));
}
return result;
}
} // namespace
Header::Header(not_null<Controller*> controller)
@ -123,7 +132,7 @@ void Header::show(HeaderData data) {
raw->setGeometry(layout.header);
}, raw->lifetime());
}
auto timestamp = ComposeTimestamp(data.date, base::unixtime::now());
auto timestamp = ComposeDetails(data, base::unixtime::now());
_date = std::make_unique<Ui::FlatLabel>(
_widget.get(),
std::move(timestamp.text),
@ -148,7 +157,7 @@ void Header::updateDateText() {
if (!_date || !_data || !_data->date) {
return;
}
auto timestamp = ComposeTimestamp(_data->date, base::unixtime::now());
auto timestamp = ComposeDetails(*_data, base::unixtime::now());
_date->setText(timestamp.text);
if (timestamp.changes > 0) {
_dateUpdateTimer.callOnce(timestamp.changes * crl::time(1000));

View File

@ -22,6 +22,7 @@ class Controller;
struct HeaderData {
not_null<UserData*> user;
TimeId date = 0;
bool edited = false;
friend inline auto operator<=>(HeaderData, HeaderData) = default;
friend inline bool operator==(HeaderData, HeaderData) = default;

View File

@ -4167,6 +4167,20 @@ void OverlayWidget::storiesJumpTo(
});
}
void OverlayWidget::storiesRedisplay(not_null<Data::Story*> story) {
Expects(_stories != nullptr);
clearStreaming();
_streamingStartPaused = false;
v::match(story->media().data, [&](not_null<PhotoData*> photo) {
displayPhoto(photo, anim::activation::background);
}, [&](not_null<DocumentData*> document) {
displayDocument(document, anim::activation::background);
}, [&](v::null_t) {
displayDocument(nullptr, anim::activation::background);
});
}
void OverlayWidget::storiesClose() {
close();
}

View File

@ -250,6 +250,7 @@ private:
-> rpl::producer<ChatHelpers::FileChosen> override;
auto storiesCachedReactionIconFactory()
-> HistoryView::Reactions::CachedIconFactory & override;
void storiesRedisplay(not_null<Data::Story*> story) override;
void storiesJumpTo(
not_null<Main::Session*> session,
FullStoryId id,