Show pinned icon in stories.

This commit is contained in:
John Preston 2024-04-17 15:09:11 +04:00
parent 468d8b04d6
commit 9036e9e8e3
9 changed files with 52 additions and 2 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 754 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 KiB

View File

@ -390,7 +390,12 @@ TextWithEntities Story::inReplyText() const {
}
void Story::setPinnedToTop(bool pinned) {
_pinnedToTop = pinned;
if (_pinnedToTop != pinned) {
_pinnedToTop = pinned;
if (const auto item = _peer->owner().stories().lookupItem(this)) {
item->setIsPinned(pinned);
}
}
}
bool Story::pinnedToTop() const {

View File

@ -1360,6 +1360,10 @@ void HistoryItem::setIsPinned(bool pinned) {
const auto changed = (isPinned() != pinned);
if (pinned) {
_flags |= MessageFlag::Pinned;
if (_flags & MessageFlag::StoryItem) {
return;
}
auto &storage = _history->session().storage();
storage.add(Storage::SharedMediaAddExisting(
_history->peer->id,
@ -1379,6 +1383,10 @@ void HistoryItem::setIsPinned(bool pinned) {
}
} else {
_flags &= ~MessageFlag::Pinned;
if (_flags & MessageFlag::StoryItem) {
return;
}
_history->session().storage().remove(Storage::SharedMediaRemoveOne(
_history->peer->id,
Storage::SharedMediaType::Pinned,
@ -1687,6 +1695,11 @@ void HistoryItem::setStoryFields(not_null<Data::Story*> story) {
/*ttlSeconds = */0);
}
setText(story->caption());
if (story->pinnedToTop()) {
_flags |= MessageFlag::Pinned;
} else {
_flags &= ~MessageFlag::Pinned;
}
}
void HistoryItem::applyEdition(const MTPDmessageService &message) {

View File

@ -343,7 +343,10 @@ std::unique_ptr<BaseLayout> Provider::createLayout(
return nullptr;
};
using namespace Overview::Layout;
const auto options = MediaOptions{ .story = true };
const auto options = MediaOptions{
.pinned = item->isPinned(),
.story = true,
};
if (const auto photo = getPhoto()) {
return std::make_unique<Photo>(delegate, item, photo, options);
} else if (const auto file = getFile()) {

View File

@ -140,3 +140,12 @@ overviewVideoPlaySelected: icon {{ "overview_video_play", historyFileThumbIconFg
overviewVideoDownload: icon {{ "overview_video_download", historyFileThumbIconFg }};
overviewVideoDownloadSelected: icon {{ "overview_video_download", historyFileThumbIconFgSelected }};
overviewVideoRadialSize: 36px;
storyPinnedIcon: icon{
{ "dialogs/dialogs_pinned_shadow", windowShadowFg },
{ "dialogs/dialogs_pinned", historyFileThumbIconFg }
};
storyPinnedIconSelected: icon{
{ "dialogs/dialogs_pinned_shadow", windowShadowFg },
{ "dialogs/dialogs_pinned", historyFileThumbIconFgSelected }
};

View File

@ -339,6 +339,7 @@ Photo::Photo(
, _spoiler(options.spoiler ? std::make_unique<Ui::SpoilerAnimation>([=] {
delegate->repaintItem(this);
}) : nullptr)
, _pinned(options.pinned)
, _story(options.story) {
if (_data->inlineThumbnailBytes().isEmpty()
&& (_data->hasExact(Data::PhotoSize::Small)
@ -407,6 +408,14 @@ void Photo::paint(Painter &p, const QRect &clip, TextSelection selection, const
if (selected) {
p.fillRect(0, 0, _width, _height, st::overviewPhotoSelectOverlay);
}
if (_pinned) {
const auto &icon = selected
? st::storyPinnedIconSelected
: st::storyPinnedIcon;
icon.paint(p, _width - icon.width(), 0, _width);
}
const auto checkDelta = st::overviewCheckSkip + st::overviewCheck.size;
const auto checkLeft = _width - checkDelta;
const auto checkTop = _height - checkDelta;
@ -475,6 +484,7 @@ Video::Video(
, _spoiler(options.spoiler ? std::make_unique<Ui::SpoilerAnimation>([=] {
delegate->repaintItem(this);
}) : nullptr)
, _pinned(options.pinned)
, _story(options.story) {
setDocumentLinks(_data);
_data->loadThumbnail(parent->fullId());
@ -547,6 +557,13 @@ void Video::paint(Painter &p, const QRect &clip, TextSelection selection, const
p.fillRect(QRect(0, 0, _width, _height), st::overviewPhotoSelectOverlay);
}
if (_pinned) {
const auto &icon = selected
? st::storyPinnedIconSelected
: st::storyPinnedIcon;
icon.paint(p, _width - icon.width(), 0, _width);
}
if (!selected && !context->selecting && radialOpacity < 1.) {
if (clip.intersects(QRect(0, _height - st::normalFont->height, _width, st::normalFont->height))) {
const auto download = !loaded && !_dataMedia->canBePlayed(parent());

View File

@ -185,6 +185,7 @@ struct Info : public RuntimeComponent<Info, LayoutItemBase> {
struct MediaOptions {
bool spoiler = false;
bool pinned = false;
bool story = false;
};
@ -218,6 +219,7 @@ private:
QPixmap _pix;
bool _goodLoaded = false;
bool _pinned = false;
bool _story = false;
};
@ -318,6 +320,7 @@ private:
QPixmap _pix;
bool _pixBlurred = true;
bool _pinned = false;
bool _story = false;
};