mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-05 06:33:57 +02:00
Use Ui::DynamicImage and ui/dynamic_thumbnails module.
This commit is contained in:
parent
f674ace805
commit
0fd8ceca6b
18 changed files with 429 additions and 347 deletions
|
@ -1417,6 +1417,8 @@ PRIVATE
|
||||||
ui/widgets/level_meter.h
|
ui/widgets/level_meter.h
|
||||||
ui/countryinput.cpp
|
ui/countryinput.cpp
|
||||||
ui/countryinput.h
|
ui/countryinput.h
|
||||||
|
ui/dynamic_thumbnails.cpp
|
||||||
|
ui/dynamic_thumbnails.h
|
||||||
ui/filter_icons.cpp
|
ui/filter_icons.cpp
|
||||||
ui/filter_icons.h
|
ui/filter_icons.h
|
||||||
ui/filter_icon_panel.cpp
|
ui/filter_icon_panel.cpp
|
||||||
|
|
|
@ -19,14 +19,18 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
#include "data/data_peer.h"
|
#include "data/data_peer.h"
|
||||||
#include "data/data_message_reactions.h"
|
#include "data/data_message_reactions.h"
|
||||||
#include "data/stickers/data_stickers.h"
|
#include "data/stickers/data_stickers.h"
|
||||||
|
#include "dialogs/ui/dialogs_stories_content.h"
|
||||||
|
#include "dialogs/ui/dialogs_stories_content.h"
|
||||||
#include "lottie/lottie_common.h"
|
#include "lottie/lottie_common.h"
|
||||||
#include "lottie/lottie_frame_generator.h"
|
#include "lottie/lottie_frame_generator.h"
|
||||||
#include "ffmpeg/ffmpeg_frame_generator.h"
|
#include "ffmpeg/ffmpeg_frame_generator.h"
|
||||||
#include "chat_helpers/stickers_lottie.h"
|
#include "chat_helpers/stickers_lottie.h"
|
||||||
#include "storage/file_download.h" // kMaxFileInMemory
|
#include "storage/file_download.h" // kMaxFileInMemory
|
||||||
#include "ui/widgets/fields/input_field.h"
|
#include "ui/widgets/fields/input_field.h"
|
||||||
|
#include "ui/text/custom_emoji_instance.h"
|
||||||
#include "ui/text/text_custom_emoji.h"
|
#include "ui/text/text_custom_emoji.h"
|
||||||
#include "ui/text/text_utilities.h"
|
#include "ui/text/text_utilities.h"
|
||||||
|
#include "ui/dynamic_thumbnails.h"
|
||||||
#include "ui/ui_utility.h"
|
#include "ui/ui_utility.h"
|
||||||
#include "apiwrap.h"
|
#include "apiwrap.h"
|
||||||
#include "styles/style_chat.h"
|
#include "styles/style_chat.h"
|
||||||
|
@ -94,6 +98,10 @@ private:
|
||||||
return u"internal:"_q;
|
return u"internal:"_q;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[[nodiscard]] QString UserpicEmojiPrefix() {
|
||||||
|
return u"userpic:"_q;
|
||||||
|
}
|
||||||
|
|
||||||
[[nodiscard]] QString InternalPadding(QMargins value) {
|
[[nodiscard]] QString InternalPadding(QMargins value) {
|
||||||
return value.isNull() ? QString() : QString(",%1,%2,%3,%4"
|
return value.isNull() ? QString() : QString(",%1,%2,%3,%4"
|
||||||
).arg(value.left()
|
).arg(value.left()
|
||||||
|
@ -528,6 +536,10 @@ std::unique_ptr<Ui::Text::CustomEmoji> CustomEmojiManager::create(
|
||||||
int sizeOverride) {
|
int sizeOverride) {
|
||||||
if (data.startsWith(InternalPrefix())) {
|
if (data.startsWith(InternalPrefix())) {
|
||||||
return internal(data);
|
return internal(data);
|
||||||
|
} else if (data.startsWith(UserpicEmojiPrefix())) {
|
||||||
|
const auto ratio = style::DevicePixelRatio();
|
||||||
|
const auto size = FrameSizeFromTag(tag, sizeOverride) / ratio;
|
||||||
|
return userpic(data, std::move(update), size);
|
||||||
}
|
}
|
||||||
const auto parsed = ParseCustomEmojiData(data);
|
const auto parsed = ParseCustomEmojiData(data);
|
||||||
return parsed
|
return parsed
|
||||||
|
@ -575,6 +587,26 @@ std::unique_ptr<Ui::Text::CustomEmoji> CustomEmojiManager::internal(
|
||||||
info.textColor);
|
info.textColor);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::unique_ptr<Ui::Text::CustomEmoji> CustomEmojiManager::userpic(
|
||||||
|
QStringView data,
|
||||||
|
Fn<void()> update,
|
||||||
|
int size) {
|
||||||
|
const auto v = data.mid(UserpicEmojiPrefix().size()).split(',');
|
||||||
|
if (v.size() != 5 && v.size() != 1) {
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
const auto id = PeerId(v[0].toULongLong());
|
||||||
|
const auto padding = (v.size() == 5)
|
||||||
|
? QMargins(v[1].toInt(), v[2].toInt(), v[3].toInt(), v[4].toInt())
|
||||||
|
: QMargins();
|
||||||
|
return std::make_unique<Ui::CustomEmoji::DynamicImageEmoji>(
|
||||||
|
data.toString(),
|
||||||
|
Ui::MakeUserpicThumbnail(_owner->peer(id)),
|
||||||
|
std::move(update),
|
||||||
|
padding,
|
||||||
|
size);
|
||||||
|
}
|
||||||
|
|
||||||
void CustomEmojiManager::resolve(
|
void CustomEmojiManager::resolve(
|
||||||
QStringView data,
|
QStringView data,
|
||||||
not_null<Listener*> listener) {
|
not_null<Listener*> listener) {
|
||||||
|
@ -955,6 +987,14 @@ QString CustomEmojiManager::registerInternalEmoji(
|
||||||
return result + InternalPadding(padding);
|
return result + InternalPadding(padding);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[[nodiscard]] QString CustomEmojiManager::peerUserpicEmojiData(
|
||||||
|
not_null<PeerData*> peer,
|
||||||
|
QMargins padding) {
|
||||||
|
return UserpicEmojiPrefix()
|
||||||
|
+ QString::number(peer->id.value)
|
||||||
|
+ InternalPadding(padding);
|
||||||
|
}
|
||||||
|
|
||||||
int FrameSizeFromTag(SizeTag tag) {
|
int FrameSizeFromTag(SizeTag tag) {
|
||||||
const auto emoji = EmojiSizeFromTag(tag);
|
const auto emoji = EmojiSizeFromTag(tag);
|
||||||
const auto factor = style::DevicePixelRatio();
|
const auto factor = style::DevicePixelRatio();
|
||||||
|
|
|
@ -92,6 +92,10 @@ public:
|
||||||
QMargins padding = {},
|
QMargins padding = {},
|
||||||
bool textColor = true);
|
bool textColor = true);
|
||||||
|
|
||||||
|
[[nodiscard]] QString peerUserpicEmojiData(
|
||||||
|
not_null<PeerData*> peer,
|
||||||
|
QMargins padding = {});
|
||||||
|
|
||||||
[[nodiscard]] uint64 coloredSetId() const;
|
[[nodiscard]] uint64 coloredSetId() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -146,6 +150,10 @@ private:
|
||||||
LoaderFactory factory);
|
LoaderFactory factory);
|
||||||
[[nodiscard]] std::unique_ptr<Ui::Text::CustomEmoji> internal(
|
[[nodiscard]] std::unique_ptr<Ui::Text::CustomEmoji> internal(
|
||||||
QStringView data);
|
QStringView data);
|
||||||
|
[[nodiscard]] std::unique_ptr<Ui::Text::CustomEmoji> userpic(
|
||||||
|
QStringView data,
|
||||||
|
Fn<void()> update,
|
||||||
|
int size);
|
||||||
[[nodiscard]] static int SizeIndex(SizeTag tag);
|
[[nodiscard]] static int SizeIndex(SizeTag tag);
|
||||||
|
|
||||||
const not_null<Session*> _owner;
|
const not_null<Session*> _owner;
|
||||||
|
|
|
@ -10,7 +10,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
#include "dialogs/dialogs_three_state_icon.h"
|
#include "dialogs/dialogs_three_state_icon.h"
|
||||||
#include "dialogs/ui/dialogs_layout.h"
|
#include "dialogs/ui/dialogs_layout.h"
|
||||||
#include "dialogs/ui/dialogs_stories_content.h"
|
#include "dialogs/ui/dialogs_stories_content.h"
|
||||||
#include "dialogs/ui/dialogs_stories_list.h"
|
|
||||||
#include "dialogs/ui/dialogs_video_userpic.h"
|
#include "dialogs/ui/dialogs_video_userpic.h"
|
||||||
#include "dialogs/dialogs_indexed_list.h"
|
#include "dialogs/dialogs_indexed_list.h"
|
||||||
#include "dialogs/dialogs_widget.h"
|
#include "dialogs/dialogs_widget.h"
|
||||||
|
|
|
@ -22,6 +22,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
#include "info/info_memento.h"
|
#include "info/info_memento.h"
|
||||||
#include "main/main_session.h"
|
#include "main/main_session.h"
|
||||||
#include "lang/lang_keys.h"
|
#include "lang/lang_keys.h"
|
||||||
|
#include "ui/dynamic_image.h"
|
||||||
|
#include "ui/dynamic_thumbnails.h"
|
||||||
#include "ui/painter.h"
|
#include "ui/painter.h"
|
||||||
#include "window/window_session_controller.h"
|
#include "window/window_session_controller.h"
|
||||||
#include "styles/style_menu_icons.h"
|
#include "styles/style_menu_icons.h"
|
||||||
|
@ -31,99 +33,6 @@ namespace {
|
||||||
|
|
||||||
constexpr auto kShownLastCount = 3;
|
constexpr auto kShownLastCount = 3;
|
||||||
|
|
||||||
class PeerUserpic final : public Thumbnail {
|
|
||||||
public:
|
|
||||||
explicit PeerUserpic(not_null<PeerData*> peer);
|
|
||||||
|
|
||||||
QImage image(int size) override;
|
|
||||||
void subscribeToUpdates(Fn<void()> callback) override;
|
|
||||||
|
|
||||||
private:
|
|
||||||
struct Subscribed {
|
|
||||||
explicit Subscribed(Fn<void()> callback)
|
|
||||||
: callback(std::move(callback)) {
|
|
||||||
}
|
|
||||||
|
|
||||||
Ui::PeerUserpicView view;
|
|
||||||
Fn<void()> callback;
|
|
||||||
InMemoryKey key;
|
|
||||||
rpl::lifetime photoLifetime;
|
|
||||||
rpl::lifetime downloadLifetime;
|
|
||||||
};
|
|
||||||
|
|
||||||
[[nodiscard]] bool waitingUserpicLoad() const;
|
|
||||||
void processNewPhoto();
|
|
||||||
|
|
||||||
const not_null<PeerData*> _peer;
|
|
||||||
QImage _frame;
|
|
||||||
std::unique_ptr<Subscribed> _subscribed;
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
class StoryThumbnail : public Thumbnail {
|
|
||||||
public:
|
|
||||||
explicit StoryThumbnail(FullStoryId id);
|
|
||||||
virtual ~StoryThumbnail() = default;
|
|
||||||
|
|
||||||
QImage image(int size) override;
|
|
||||||
void subscribeToUpdates(Fn<void()> callback) override;
|
|
||||||
|
|
||||||
protected:
|
|
||||||
struct Thumb {
|
|
||||||
Image *image = nullptr;
|
|
||||||
bool blurred = false;
|
|
||||||
};
|
|
||||||
[[nodiscard]] virtual Main::Session &session() = 0;
|
|
||||||
[[nodiscard]] virtual Thumb loaded(FullStoryId id) = 0;
|
|
||||||
virtual void clear() = 0;
|
|
||||||
|
|
||||||
private:
|
|
||||||
const FullStoryId _id;
|
|
||||||
QImage _full;
|
|
||||||
rpl::lifetime _subscription;
|
|
||||||
QImage _prepared;
|
|
||||||
bool _blurred = false;
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
class PhotoThumbnail final : public StoryThumbnail {
|
|
||||||
public:
|
|
||||||
PhotoThumbnail(not_null<PhotoData*> photo, FullStoryId id);
|
|
||||||
|
|
||||||
private:
|
|
||||||
Main::Session &session() override;
|
|
||||||
Thumb loaded(FullStoryId id) override;
|
|
||||||
void clear() override;
|
|
||||||
|
|
||||||
const not_null<PhotoData*> _photo;
|
|
||||||
std::shared_ptr<Data::PhotoMedia> _media;
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
class VideoThumbnail final : public StoryThumbnail {
|
|
||||||
public:
|
|
||||||
VideoThumbnail(not_null<DocumentData*> video, FullStoryId id);
|
|
||||||
|
|
||||||
private:
|
|
||||||
Main::Session &session() override;
|
|
||||||
Thumb loaded(FullStoryId id) override;
|
|
||||||
void clear() override;
|
|
||||||
|
|
||||||
const not_null<DocumentData*> _video;
|
|
||||||
std::shared_ptr<Data::DocumentMedia> _media;
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
class EmptyThumbnail final : public Thumbnail {
|
|
||||||
public:
|
|
||||||
QImage image(int size) override;
|
|
||||||
void subscribeToUpdates(Fn<void()> callback) override;
|
|
||||||
|
|
||||||
private:
|
|
||||||
QImage _cached;
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
class State final {
|
class State final {
|
||||||
public:
|
public:
|
||||||
State(not_null<Data::Stories*> data, Data::StorySourcesList list);
|
State(not_null<Data::Stories*> data, Data::StorySourcesList list);
|
||||||
|
@ -135,193 +44,10 @@ private:
|
||||||
const Data::StorySourcesList _list;
|
const Data::StorySourcesList _list;
|
||||||
base::flat_map<
|
base::flat_map<
|
||||||
not_null<PeerData*>,
|
not_null<PeerData*>,
|
||||||
std::shared_ptr<Thumbnail>> _userpics;
|
std::shared_ptr<Ui::DynamicImage>> _userpics;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
PeerUserpic::PeerUserpic(not_null<PeerData*> peer)
|
|
||||||
: _peer(peer) {
|
|
||||||
}
|
|
||||||
|
|
||||||
QImage PeerUserpic::image(int size) {
|
|
||||||
Expects(_subscribed != nullptr);
|
|
||||||
|
|
||||||
const auto good = (_frame.width() == size * _frame.devicePixelRatio());
|
|
||||||
const auto key = _peer->userpicUniqueKey(_subscribed->view);
|
|
||||||
if (!good || (_subscribed->key != key && !waitingUserpicLoad())) {
|
|
||||||
const auto ratio = style::DevicePixelRatio();
|
|
||||||
_subscribed->key = key;
|
|
||||||
_frame = QImage(
|
|
||||||
QSize(size, size) * ratio,
|
|
||||||
QImage::Format_ARGB32_Premultiplied);
|
|
||||||
_frame.setDevicePixelRatio(ratio);
|
|
||||||
_frame.fill(Qt::transparent);
|
|
||||||
|
|
||||||
auto p = Painter(&_frame);
|
|
||||||
_peer->paintUserpic(p, _subscribed->view, 0, 0, size);
|
|
||||||
}
|
|
||||||
return _frame;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool PeerUserpic::waitingUserpicLoad() const {
|
|
||||||
return _peer->hasUserpic() && _peer->useEmptyUserpic(_subscribed->view);
|
|
||||||
}
|
|
||||||
|
|
||||||
void PeerUserpic::subscribeToUpdates(Fn<void()> callback) {
|
|
||||||
if (!callback) {
|
|
||||||
_subscribed = nullptr;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
_subscribed = std::make_unique<Subscribed>(std::move(callback));
|
|
||||||
|
|
||||||
_peer->session().changes().peerUpdates(
|
|
||||||
_peer,
|
|
||||||
Data::PeerUpdate::Flag::Photo
|
|
||||||
) | rpl::start_with_next([=] {
|
|
||||||
_subscribed->callback();
|
|
||||||
processNewPhoto();
|
|
||||||
}, _subscribed->photoLifetime);
|
|
||||||
|
|
||||||
processNewPhoto();
|
|
||||||
}
|
|
||||||
|
|
||||||
void PeerUserpic::processNewPhoto() {
|
|
||||||
Expects(_subscribed != nullptr);
|
|
||||||
|
|
||||||
if (!waitingUserpicLoad()) {
|
|
||||||
_subscribed->downloadLifetime.destroy();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
_peer->session().downloaderTaskFinished(
|
|
||||||
) | rpl::filter([=] {
|
|
||||||
return !waitingUserpicLoad();
|
|
||||||
}) | rpl::start_with_next([=] {
|
|
||||||
_subscribed->callback();
|
|
||||||
_subscribed->downloadLifetime.destroy();
|
|
||||||
}, _subscribed->downloadLifetime);
|
|
||||||
}
|
|
||||||
|
|
||||||
StoryThumbnail::StoryThumbnail(FullStoryId id)
|
|
||||||
: _id(id) {
|
|
||||||
}
|
|
||||||
|
|
||||||
QImage StoryThumbnail::image(int size) {
|
|
||||||
const auto ratio = style::DevicePixelRatio();
|
|
||||||
if (_prepared.width() != size * ratio) {
|
|
||||||
if (_full.isNull()) {
|
|
||||||
_prepared = QImage(
|
|
||||||
QSize(size, size) * ratio,
|
|
||||||
QImage::Format_ARGB32_Premultiplied);
|
|
||||||
_prepared.fill(Qt::black);
|
|
||||||
} else {
|
|
||||||
const auto width = _full.width();
|
|
||||||
const auto skip = std::max((_full.height() - width) / 2, 0);
|
|
||||||
_prepared = _full.copy(0, skip, width, width).scaled(
|
|
||||||
QSize(size, size) * ratio,
|
|
||||||
Qt::IgnoreAspectRatio,
|
|
||||||
Qt::SmoothTransformation);
|
|
||||||
}
|
|
||||||
_prepared = Images::Circle(std::move(_prepared));
|
|
||||||
_prepared.setDevicePixelRatio(ratio);
|
|
||||||
}
|
|
||||||
return _prepared;
|
|
||||||
}
|
|
||||||
|
|
||||||
void StoryThumbnail::subscribeToUpdates(Fn<void()> callback) {
|
|
||||||
_subscription.destroy();
|
|
||||||
if (!callback) {
|
|
||||||
clear();
|
|
||||||
return;
|
|
||||||
} else if (!_full.isNull() && !_blurred) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
const auto thumbnail = loaded(_id);
|
|
||||||
if (const auto image = thumbnail.image) {
|
|
||||||
_full = image->original();
|
|
||||||
}
|
|
||||||
_blurred = thumbnail.blurred;
|
|
||||||
if (!_blurred) {
|
|
||||||
_prepared = QImage();
|
|
||||||
} else {
|
|
||||||
_subscription = session().downloaderTaskFinished(
|
|
||||||
) | rpl::filter([=] {
|
|
||||||
const auto thumbnail = loaded(_id);
|
|
||||||
if (!thumbnail.blurred) {
|
|
||||||
_full = thumbnail.image->original();
|
|
||||||
_prepared = QImage();
|
|
||||||
_blurred = false;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}) | rpl::take(1) | rpl::start_with_next(callback);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
PhotoThumbnail::PhotoThumbnail(not_null<PhotoData*> photo, FullStoryId id)
|
|
||||||
: StoryThumbnail(id)
|
|
||||||
, _photo(photo) {
|
|
||||||
}
|
|
||||||
|
|
||||||
Main::Session &PhotoThumbnail::session() {
|
|
||||||
return _photo->session();
|
|
||||||
}
|
|
||||||
|
|
||||||
StoryThumbnail::Thumb PhotoThumbnail::loaded(FullStoryId id) {
|
|
||||||
if (!_media) {
|
|
||||||
_media = _photo->createMediaView();
|
|
||||||
_media->wanted(Data::PhotoSize::Small, id);
|
|
||||||
}
|
|
||||||
if (const auto small = _media->image(Data::PhotoSize::Small)) {
|
|
||||||
return { .image = small };
|
|
||||||
}
|
|
||||||
return { .image = _media->thumbnailInline(), .blurred = true };
|
|
||||||
}
|
|
||||||
|
|
||||||
void PhotoThumbnail::clear() {
|
|
||||||
_media = nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
VideoThumbnail::VideoThumbnail(
|
|
||||||
not_null<DocumentData*> video,
|
|
||||||
FullStoryId id)
|
|
||||||
: StoryThumbnail(id)
|
|
||||||
, _video(video) {
|
|
||||||
}
|
|
||||||
|
|
||||||
Main::Session &VideoThumbnail::session() {
|
|
||||||
return _video->session();
|
|
||||||
}
|
|
||||||
|
|
||||||
StoryThumbnail::Thumb VideoThumbnail::loaded(FullStoryId id) {
|
|
||||||
if (!_media) {
|
|
||||||
_media = _video->createMediaView();
|
|
||||||
_media->thumbnailWanted(id);
|
|
||||||
}
|
|
||||||
if (const auto small = _media->thumbnail()) {
|
|
||||||
return { .image = small };
|
|
||||||
}
|
|
||||||
return { .image = _media->thumbnailInline(), .blurred = true };
|
|
||||||
}
|
|
||||||
|
|
||||||
void VideoThumbnail::clear() {
|
|
||||||
_media = nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
QImage EmptyThumbnail::image(int size) {
|
|
||||||
const auto ratio = style::DevicePixelRatio();
|
|
||||||
if (_cached.width() != size * ratio) {
|
|
||||||
_cached = QImage(
|
|
||||||
QSize(size, size) * ratio,
|
|
||||||
QImage::Format_ARGB32_Premultiplied);
|
|
||||||
_cached.fill(Qt::black);
|
|
||||||
_cached.setDevicePixelRatio(ratio);
|
|
||||||
}
|
|
||||||
return _cached;
|
|
||||||
}
|
|
||||||
|
|
||||||
void EmptyThumbnail::subscribeToUpdates(Fn<void()> callback) {
|
|
||||||
}
|
|
||||||
|
|
||||||
State::State(not_null<Data::Stories*> data, Data::StorySourcesList list)
|
State::State(not_null<Data::Stories*> data, Data::StorySourcesList list)
|
||||||
: _data(data)
|
: _data(data)
|
||||||
, _list(list) {
|
, _list(list) {
|
||||||
|
@ -335,12 +61,12 @@ Content State::next() {
|
||||||
const auto source = _data->source(info.id);
|
const auto source = _data->source(info.id);
|
||||||
Assert(source != nullptr);
|
Assert(source != nullptr);
|
||||||
|
|
||||||
auto userpic = std::shared_ptr<Thumbnail>();
|
auto userpic = std::shared_ptr<Ui::DynamicImage>();
|
||||||
const auto peer = source->peer;
|
const auto peer = source->peer;
|
||||||
if (const auto i = _userpics.find(peer); i != end(_userpics)) {
|
if (const auto i = _userpics.find(peer); i != end(_userpics)) {
|
||||||
userpic = i->second;
|
userpic = i->second;
|
||||||
} else {
|
} else {
|
||||||
userpic = MakeUserpicThumbnail(peer);
|
userpic = Ui::MakeUserpicThumbnail(peer);
|
||||||
_userpics.emplace(peer, userpic);
|
_userpics.emplace(peer, userpic);
|
||||||
}
|
}
|
||||||
result.elements.push_back({
|
result.elements.push_back({
|
||||||
|
@ -430,7 +156,7 @@ rpl::producer<Content> LastForPeer(not_null<PeerData*> peer) {
|
||||||
result.elements.reserve(ids.size());
|
result.elements.reserve(ids.size());
|
||||||
result.elements.push_back({
|
result.elements.push_back({
|
||||||
.id = uint64(id),
|
.id = uint64(id),
|
||||||
.thumbnail = MakeStoryThumbnail(*maybe),
|
.thumbnail = Ui::MakeStoryThumbnail(*maybe),
|
||||||
.count = 1U,
|
.count = 1U,
|
||||||
.unreadCount = unread ? 1U : 0U,
|
.unreadCount = unread ? 1U : 0U,
|
||||||
});
|
});
|
||||||
|
@ -479,23 +205,6 @@ rpl::producer<Content> LastForPeer(not_null<PeerData*> peer) {
|
||||||
}) | rpl::flatten_latest();
|
}) | rpl::flatten_latest();
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<Thumbnail> MakeUserpicThumbnail(not_null<PeerData*> peer) {
|
|
||||||
return std::make_shared<PeerUserpic>(peer);
|
|
||||||
}
|
|
||||||
|
|
||||||
std::shared_ptr<Thumbnail> MakeStoryThumbnail(
|
|
||||||
not_null<Data::Story*> story) {
|
|
||||||
using Result = std::shared_ptr<Thumbnail>;
|
|
||||||
const auto id = story->fullId();
|
|
||||||
return v::match(story->media().data, [](v::null_t) -> Result {
|
|
||||||
return std::make_shared<EmptyThumbnail>();
|
|
||||||
}, [&](not_null<PhotoData*> photo) -> Result {
|
|
||||||
return std::make_shared<PhotoThumbnail>(photo, id);
|
|
||||||
}, [&](not_null<DocumentData*> video) -> Result {
|
|
||||||
return std::make_shared<VideoThumbnail>(video, id);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
void FillSourceMenu(
|
void FillSourceMenu(
|
||||||
not_null<Window::SessionController*> controller,
|
not_null<Window::SessionController*> controller,
|
||||||
const ShowMenuRequest &request) {
|
const ShowMenuRequest &request) {
|
||||||
|
|
|
@ -23,7 +23,6 @@ class SessionController;
|
||||||
namespace Dialogs::Stories {
|
namespace Dialogs::Stories {
|
||||||
|
|
||||||
struct Content;
|
struct Content;
|
||||||
class Thumbnail;
|
|
||||||
struct ShowMenuRequest;
|
struct ShowMenuRequest;
|
||||||
|
|
||||||
[[nodiscard]] rpl::producer<Content> ContentForSession(
|
[[nodiscard]] rpl::producer<Content> ContentForSession(
|
||||||
|
@ -32,11 +31,6 @@ struct ShowMenuRequest;
|
||||||
|
|
||||||
[[nodiscard]] rpl::producer<Content> LastForPeer(not_null<PeerData*> peer);
|
[[nodiscard]] rpl::producer<Content> LastForPeer(not_null<PeerData*> peer);
|
||||||
|
|
||||||
[[nodiscard]] std::shared_ptr<Thumbnail> MakeUserpicThumbnail(
|
|
||||||
not_null<PeerData*> peer);
|
|
||||||
[[nodiscard]] std::shared_ptr<Thumbnail> MakeStoryThumbnail(
|
|
||||||
not_null<Data::Story*> story);
|
|
||||||
|
|
||||||
void FillSourceMenu(
|
void FillSourceMenu(
|
||||||
not_null<Window::SessionController*> controller,
|
not_null<Window::SessionController*> controller,
|
||||||
const ShowMenuRequest &request);
|
const ShowMenuRequest &request);
|
||||||
|
|
|
@ -17,6 +17,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
#include "ui/widgets/labels.h"
|
#include "ui/widgets/labels.h"
|
||||||
#include "ui/widgets/popup_menu.h"
|
#include "ui/widgets/popup_menu.h"
|
||||||
#include "ui/widgets/tooltip.h"
|
#include "ui/widgets/tooltip.h"
|
||||||
|
#include "ui/dynamic_image.h"
|
||||||
#include "ui/painter.h"
|
#include "ui/painter.h"
|
||||||
#include "styles/style_dialogs.h"
|
#include "styles/style_dialogs.h"
|
||||||
|
|
||||||
|
|
|
@ -10,9 +10,10 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
#include "base/qt/qt_compare.h"
|
#include "base/qt/qt_compare.h"
|
||||||
#include "base/timer.h"
|
#include "base/timer.h"
|
||||||
#include "base/weak_ptr.h"
|
#include "base/weak_ptr.h"
|
||||||
|
#include "ui/effects/animations.h"
|
||||||
|
#include "ui/text/text_custom_emoji.h"
|
||||||
#include "ui/widgets/menu/menu_add_action_callback.h"
|
#include "ui/widgets/menu/menu_add_action_callback.h"
|
||||||
#include "ui/rp_widget.h"
|
#include "ui/rp_widget.h"
|
||||||
#include "ui/effects/animations.h"
|
|
||||||
|
|
||||||
class QPainter;
|
class QPainter;
|
||||||
|
|
||||||
|
@ -23,22 +24,17 @@ struct DialogsStoriesList;
|
||||||
|
|
||||||
namespace Ui {
|
namespace Ui {
|
||||||
class PopupMenu;
|
class PopupMenu;
|
||||||
|
class DynamicImage;
|
||||||
struct OutlineSegment;
|
struct OutlineSegment;
|
||||||
class ImportantTooltip;
|
class ImportantTooltip;
|
||||||
} // namespace Ui
|
} // namespace Ui
|
||||||
|
|
||||||
namespace Dialogs::Stories {
|
namespace Dialogs::Stories {
|
||||||
|
|
||||||
class Thumbnail {
|
|
||||||
public:
|
|
||||||
[[nodiscard]] virtual QImage image(int size) = 0;
|
|
||||||
virtual void subscribeToUpdates(Fn<void()> callback) = 0;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct Element {
|
struct Element {
|
||||||
uint64 id = 0;
|
uint64 id = 0;
|
||||||
QString name;
|
QString name;
|
||||||
std::shared_ptr<Thumbnail> thumbnail;
|
std::shared_ptr<Ui::DynamicImage> thumbnail;
|
||||||
uint32 count : 15 = 0;
|
uint32 count : 15 = 0;
|
||||||
uint32 unreadCount : 15 = 0;
|
uint32 unreadCount : 15 = 0;
|
||||||
uint32 skipSmall : 1 = 0;
|
uint32 skipSmall : 1 = 0;
|
||||||
|
|
|
@ -15,8 +15,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
#include "data/data_channel.h"
|
#include "data/data_channel.h"
|
||||||
#include "data/data_document.h"
|
#include "data/data_document.h"
|
||||||
#include "data/data_media_types.h"
|
#include "data/data_media_types.h"
|
||||||
#include "dialogs/ui/dialogs_stories_content.h"
|
|
||||||
#include "dialogs/ui/dialogs_stories_list.h"
|
|
||||||
#include "history/history.h"
|
#include "history/history.h"
|
||||||
#include "history/history_item.h"
|
#include "history/history_item.h"
|
||||||
#include "history/history_item_components.h"
|
#include "history/history_item_components.h"
|
||||||
|
@ -30,6 +28,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
#include "ui/effects/ripple_animation.h"
|
#include "ui/effects/ripple_animation.h"
|
||||||
#include "ui/text/text_utilities.h"
|
#include "ui/text/text_utilities.h"
|
||||||
#include "ui/widgets/tooltip.h"
|
#include "ui/widgets/tooltip.h"
|
||||||
|
#include "ui/dynamic_image.h"
|
||||||
|
#include "ui/dynamic_thumbnails.h"
|
||||||
#include "ui/painter.h"
|
#include "ui/painter.h"
|
||||||
#include "ui/round_rect.h"
|
#include "ui/round_rect.h"
|
||||||
#include "styles/style_chat.h"
|
#include "styles/style_chat.h"
|
||||||
|
@ -446,7 +446,7 @@ PeerBubbleListPart::PeerBubbleListPart(
|
||||||
peer->name(),
|
peer->name(),
|
||||||
kDefaultTextOptions,
|
kDefaultTextOptions,
|
||||||
st::msgMinWidth),
|
st::msgMinWidth),
|
||||||
.thumbnail = Dialogs::Stories::MakeUserpicThumbnail(peer),
|
.thumbnail = Ui::MakeUserpicThumbnail(peer),
|
||||||
.link = peer->openLink(),
|
.link = peer->openLink(),
|
||||||
.colorIndex = peer->colorIndex(),
|
.colorIndex = peer->colorIndex(),
|
||||||
});
|
});
|
||||||
|
|
|
@ -15,11 +15,8 @@ struct GiveawayStart;
|
||||||
struct GiveawayResults;
|
struct GiveawayResults;
|
||||||
} // namespace Data
|
} // namespace Data
|
||||||
|
|
||||||
namespace Dialogs::Stories {
|
|
||||||
class Thumbnail;
|
|
||||||
} // namespace Dialogs::Stories
|
|
||||||
|
|
||||||
namespace Ui {
|
namespace Ui {
|
||||||
|
class DynamicImage;
|
||||||
class RippleAnimation;
|
class RippleAnimation;
|
||||||
} // namespace Ui
|
} // namespace Ui
|
||||||
|
|
||||||
|
@ -208,10 +205,9 @@ public:
|
||||||
private:
|
private:
|
||||||
int layout(int x, int y, int available);
|
int layout(int x, int y, int available);
|
||||||
|
|
||||||
using Thumbnail = Dialogs::Stories::Thumbnail;
|
|
||||||
struct Peer {
|
struct Peer {
|
||||||
Ui::Text::String name;
|
Ui::Text::String name;
|
||||||
std::shared_ptr<Thumbnail> thumbnail;
|
std::shared_ptr<Ui::DynamicImage> thumbnail;
|
||||||
QRect geometry;
|
QRect geometry;
|
||||||
ClickHandlerPtr link;
|
ClickHandlerPtr link;
|
||||||
mutable std::unique_ptr<Ui::RippleAnimation> ripple;
|
mutable std::unique_ptr<Ui::RippleAnimation> ripple;
|
||||||
|
|
|
@ -14,8 +14,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
#include "data/data_channel.h"
|
#include "data/data_channel.h"
|
||||||
#include "data/data_premium_limits.h"
|
#include "data/data_premium_limits.h"
|
||||||
#include "data/data_session.h"
|
#include "data/data_session.h"
|
||||||
#include "dialogs/ui/dialogs_stories_content.h"
|
|
||||||
#include "dialogs/ui/dialogs_stories_list.h"
|
|
||||||
#include "history/view/history_view_element.h"
|
#include "history/view/history_view_element.h"
|
||||||
#include "history/view/history_view_cursor_state.h"
|
#include "history/view/history_view_cursor_state.h"
|
||||||
#include "history/history.h"
|
#include "history/history.h"
|
||||||
|
@ -30,6 +28,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
#include "ui/chat/chat_theme.h"
|
#include "ui/chat/chat_theme.h"
|
||||||
#include "ui/effects/ripple_animation.h"
|
#include "ui/effects/ripple_animation.h"
|
||||||
#include "ui/text/text_utilities.h"
|
#include "ui/text/text_utilities.h"
|
||||||
|
#include "ui/dynamic_image.h"
|
||||||
|
#include "ui/dynamic_thumbnails.h"
|
||||||
#include "ui/painter.h"
|
#include "ui/painter.h"
|
||||||
#include "window/window_session_controller.h"
|
#include "window/window_session_controller.h"
|
||||||
#include "styles/style_chat.h"
|
#include "styles/style_chat.h"
|
||||||
|
@ -373,7 +373,7 @@ void SimilarChannels::fillMoreThumbnails() const {
|
||||||
if (similar.list.size() <= _channels.size() + i) {
|
if (similar.list.size() <= _channels.size() + i) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
_moreThumbnails[i] = Dialogs::Stories::MakeUserpicThumbnail(
|
_moreThumbnails[i] = Ui::MakeUserpicThumbnail(
|
||||||
similar.list[_channels.size() + i]);
|
similar.list[_channels.size() + i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -556,7 +556,7 @@ QSize SimilarChannels::countOptimalSize() {
|
||||||
: channel->name()),
|
: channel->name()),
|
||||||
kDefaultTextOptions,
|
kDefaultTextOptions,
|
||||||
st::chatSimilarChannelPhoto),
|
st::chatSimilarChannelPhoto),
|
||||||
.thumbnail = Dialogs::Stories::MakeUserpicThumbnail(channel),
|
.thumbnail = Ui::MakeUserpicThumbnail(channel),
|
||||||
.more = uint32(moreCounter),
|
.more = uint32(moreCounter),
|
||||||
.moreLocked = uint32((moreCounter && !premium) ? 1 : 0),
|
.moreLocked = uint32((moreCounter && !premium) ? 1 : 0),
|
||||||
});
|
});
|
||||||
|
|
|
@ -9,11 +9,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
|
|
||||||
#include "history/view/media/history_view_media.h"
|
#include "history/view/media/history_view_media.h"
|
||||||
|
|
||||||
namespace Dialogs::Stories {
|
|
||||||
class Thumbnail;
|
|
||||||
} // namespace Dialogs::Stories
|
|
||||||
|
|
||||||
namespace Ui {
|
namespace Ui {
|
||||||
|
class DynamicImage;
|
||||||
class RippleAnimation;
|
class RippleAnimation;
|
||||||
} // namespace Ui
|
} // namespace Ui
|
||||||
|
|
||||||
|
@ -58,11 +55,10 @@ public:
|
||||||
bool consumeHorizontalScroll(QPoint position, int delta) override;
|
bool consumeHorizontalScroll(QPoint position, int delta) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
using Thumbnail = Dialogs::Stories::Thumbnail;
|
|
||||||
struct Channel {
|
struct Channel {
|
||||||
QRect geometry;
|
QRect geometry;
|
||||||
Ui::Text::String name;
|
Ui::Text::String name;
|
||||||
std::shared_ptr<Thumbnail> thumbnail;
|
std::shared_ptr<Ui::DynamicImage> thumbnail;
|
||||||
ClickHandlerPtr link;
|
ClickHandlerPtr link;
|
||||||
QString counter;
|
QString counter;
|
||||||
mutable QRect counterRect;
|
mutable QRect counterRect;
|
||||||
|
@ -99,7 +95,7 @@ private:
|
||||||
mutable uint32 _hasHeavyPart : 1 = 0;
|
mutable uint32 _hasHeavyPart : 1 = 0;
|
||||||
|
|
||||||
std::vector<Channel> _channels;
|
std::vector<Channel> _channels;
|
||||||
mutable std::array<std::shared_ptr<Thumbnail>, 2> _moreThumbnails;
|
mutable std::array<std::shared_ptr<Ui::DynamicImage>, 2> _moreThumbnails;
|
||||||
mutable ClickHandlerPtr _viewAllLink;
|
mutable ClickHandlerPtr _viewAllLink;
|
||||||
mutable ClickHandlerPtr _toggleLink;
|
mutable ClickHandlerPtr _toggleLink;
|
||||||
|
|
||||||
|
|
|
@ -15,8 +15,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
#include "data/data_file_click_handler.h"
|
#include "data/data_file_click_handler.h"
|
||||||
#include "data/data_session.h"
|
#include "data/data_session.h"
|
||||||
#include "data/data_stories.h"
|
#include "data/data_stories.h"
|
||||||
#include "dialogs/ui/dialogs_stories_content.h"
|
|
||||||
#include "dialogs/ui/dialogs_stories_list.h"
|
|
||||||
#include "editor/photo_editor_common.h"
|
#include "editor/photo_editor_common.h"
|
||||||
#include "editor/photo_editor_layer_widget.h"
|
#include "editor/photo_editor_layer_widget.h"
|
||||||
#include "history/history.h"
|
#include "history/history.h"
|
||||||
|
@ -31,6 +29,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
#include "ui/effects/outline_segments.h"
|
#include "ui/effects/outline_segments.h"
|
||||||
#include "ui/text/text_utilities.h"
|
#include "ui/text/text_utilities.h"
|
||||||
#include "ui/toast/toast.h"
|
#include "ui/toast/toast.h"
|
||||||
|
#include "ui/dynamic_image.h"
|
||||||
|
#include "ui/dynamic_thumbnails.h"
|
||||||
#include "ui/painter.h"
|
#include "ui/painter.h"
|
||||||
#include "mainwidget.h"
|
#include "mainwidget.h"
|
||||||
#include "apiwrap.h"
|
#include "apiwrap.h"
|
||||||
|
@ -102,12 +102,11 @@ void StoryMention::draw(
|
||||||
const QRect &geometry) {
|
const QRect &geometry) {
|
||||||
const auto showStory = _story->forbidsForward() ? 0 : 1;
|
const auto showStory = _story->forbidsForward() ? 0 : 1;
|
||||||
if (!_thumbnail || _thumbnailFromStory != showStory) {
|
if (!_thumbnail || _thumbnailFromStory != showStory) {
|
||||||
using namespace Dialogs::Stories;
|
|
||||||
const auto item = _parent->data();
|
const auto item = _parent->data();
|
||||||
const auto history = item->history();
|
const auto history = item->history();
|
||||||
_thumbnail = showStory
|
_thumbnail = showStory
|
||||||
? MakeStoryThumbnail(_story)
|
? Ui::MakeStoryThumbnail(_story)
|
||||||
: MakeUserpicThumbnail(item->out()
|
: Ui::MakeUserpicThumbnail(item->out()
|
||||||
? history->session().user()
|
? history->session().user()
|
||||||
: history->peer);
|
: history->peer);
|
||||||
_thumbnailFromStory = showStory;
|
_thumbnailFromStory = showStory;
|
||||||
|
|
|
@ -15,9 +15,9 @@ namespace Data {
|
||||||
class Story;
|
class Story;
|
||||||
} // namespace Data
|
} // namespace Data
|
||||||
|
|
||||||
namespace Dialogs::Stories {
|
namespace Ui {
|
||||||
class Thumbnail;
|
class DynamicImage;
|
||||||
} // namespace Dialogs::Stories
|
} // namespace Ui
|
||||||
|
|
||||||
namespace HistoryView {
|
namespace HistoryView {
|
||||||
|
|
||||||
|
@ -53,13 +53,11 @@ public:
|
||||||
void unloadHeavyPart() override;
|
void unloadHeavyPart() override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
using Thumbnail = Dialogs::Stories::Thumbnail;
|
|
||||||
|
|
||||||
bool changeSubscribedTo(uint32 value);
|
bool changeSubscribedTo(uint32 value);
|
||||||
|
|
||||||
const not_null<Element*> _parent;
|
const not_null<Element*> _parent;
|
||||||
const not_null<Data::Story*> _story;
|
const not_null<Data::Story*> _story;
|
||||||
std::shared_ptr<Thumbnail> _thumbnail;
|
std::shared_ptr<Ui::DynamicImage> _thumbnail;
|
||||||
QBrush _unreadBrush;
|
QBrush _unreadBrush;
|
||||||
uint32 _paletteVersion : 29 = 0;
|
uint32 _paletteVersion : 29 = 0;
|
||||||
uint32 _thumbnailFromStory : 1 = 0;
|
uint32 _thumbnailFromStory : 1 = 0;
|
||||||
|
|
|
@ -7,9 +7,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
*/
|
*/
|
||||||
#include "info/info_top_bar.h"
|
#include "info/info_top_bar.h"
|
||||||
|
|
||||||
#include <rpl/never.h>
|
|
||||||
#include <rpl/merge.h>
|
|
||||||
#include "dialogs/ui/dialogs_stories_content.h"
|
|
||||||
#include "dialogs/ui/dialogs_stories_list.h"
|
#include "dialogs/ui/dialogs_stories_list.h"
|
||||||
#include "lang/lang_keys.h"
|
#include "lang/lang_keys.h"
|
||||||
#include "lang/lang_numbers_animation.h"
|
#include "lang/lang_numbers_animation.h"
|
||||||
|
|
322
Telegram/SourceFiles/ui/dynamic_thumbnails.cpp
Normal file
322
Telegram/SourceFiles/ui/dynamic_thumbnails.cpp
Normal file
|
@ -0,0 +1,322 @@
|
||||||
|
/*
|
||||||
|
This file is part of Telegram Desktop,
|
||||||
|
the official desktop application for the Telegram messaging service.
|
||||||
|
|
||||||
|
For license and copyright information please follow this link:
|
||||||
|
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
|
*/
|
||||||
|
#include "ui/dynamic_thumbnails.h"
|
||||||
|
|
||||||
|
#include "data/data_changes.h"
|
||||||
|
#include "data/data_document.h"
|
||||||
|
#include "data/data_document_media.h"
|
||||||
|
#include "data/data_file_origin.h"
|
||||||
|
#include "data/data_peer.h"
|
||||||
|
#include "data/data_photo.h"
|
||||||
|
#include "data/data_photo_media.h"
|
||||||
|
#include "data/data_story.h"
|
||||||
|
#include "main/main_session.h"
|
||||||
|
#include "ui/dynamic_image.h"
|
||||||
|
#include "ui/painter.h"
|
||||||
|
#include "ui/userpic_view.h"
|
||||||
|
|
||||||
|
namespace Ui {
|
||||||
|
namespace {
|
||||||
|
|
||||||
|
class PeerUserpic final : public DynamicImage {
|
||||||
|
public:
|
||||||
|
explicit PeerUserpic(not_null<PeerData*> peer);
|
||||||
|
|
||||||
|
QImage image(int size) override;
|
||||||
|
void subscribeToUpdates(Fn<void()> callback) override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
struct Subscribed {
|
||||||
|
explicit Subscribed(Fn<void()> callback)
|
||||||
|
: callback(std::move(callback)) {
|
||||||
|
}
|
||||||
|
|
||||||
|
Ui::PeerUserpicView view;
|
||||||
|
Fn<void()> callback;
|
||||||
|
InMemoryKey key;
|
||||||
|
rpl::lifetime photoLifetime;
|
||||||
|
rpl::lifetime downloadLifetime;
|
||||||
|
};
|
||||||
|
|
||||||
|
[[nodiscard]] bool waitingUserpicLoad() const;
|
||||||
|
void processNewPhoto();
|
||||||
|
|
||||||
|
const not_null<PeerData*> _peer;
|
||||||
|
QImage _frame;
|
||||||
|
std::unique_ptr<Subscribed> _subscribed;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
class StoryThumbnail : public DynamicImage {
|
||||||
|
public:
|
||||||
|
explicit StoryThumbnail(FullStoryId id);
|
||||||
|
virtual ~StoryThumbnail() = default;
|
||||||
|
|
||||||
|
QImage image(int size) override;
|
||||||
|
void subscribeToUpdates(Fn<void()> callback) override;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
struct Thumb {
|
||||||
|
Image *image = nullptr;
|
||||||
|
bool blurred = false;
|
||||||
|
};
|
||||||
|
[[nodiscard]] virtual Main::Session &session() = 0;
|
||||||
|
[[nodiscard]] virtual Thumb loaded(FullStoryId id) = 0;
|
||||||
|
virtual void clear() = 0;
|
||||||
|
|
||||||
|
private:
|
||||||
|
const FullStoryId _id;
|
||||||
|
QImage _full;
|
||||||
|
rpl::lifetime _subscription;
|
||||||
|
QImage _prepared;
|
||||||
|
bool _blurred = false;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
class PhotoThumbnail final : public StoryThumbnail {
|
||||||
|
public:
|
||||||
|
PhotoThumbnail(not_null<PhotoData*> photo, FullStoryId id);
|
||||||
|
|
||||||
|
private:
|
||||||
|
Main::Session &session() override;
|
||||||
|
Thumb loaded(FullStoryId id) override;
|
||||||
|
void clear() override;
|
||||||
|
|
||||||
|
const not_null<PhotoData*> _photo;
|
||||||
|
std::shared_ptr<Data::PhotoMedia> _media;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
class VideoThumbnail final : public StoryThumbnail {
|
||||||
|
public:
|
||||||
|
VideoThumbnail(not_null<DocumentData*> video, FullStoryId id);
|
||||||
|
|
||||||
|
private:
|
||||||
|
Main::Session &session() override;
|
||||||
|
Thumb loaded(FullStoryId id) override;
|
||||||
|
void clear() override;
|
||||||
|
|
||||||
|
const not_null<DocumentData*> _video;
|
||||||
|
std::shared_ptr<Data::DocumentMedia> _media;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
class EmptyThumbnail final : public DynamicImage {
|
||||||
|
public:
|
||||||
|
QImage image(int size) override;
|
||||||
|
void subscribeToUpdates(Fn<void()> callback) override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
QImage _cached;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
PeerUserpic::PeerUserpic(not_null<PeerData*> peer)
|
||||||
|
: _peer(peer) {
|
||||||
|
}
|
||||||
|
|
||||||
|
QImage PeerUserpic::image(int size) {
|
||||||
|
Expects(_subscribed != nullptr);
|
||||||
|
|
||||||
|
const auto good = (_frame.width() == size * _frame.devicePixelRatio());
|
||||||
|
const auto key = _peer->userpicUniqueKey(_subscribed->view);
|
||||||
|
if (!good || (_subscribed->key != key && !waitingUserpicLoad())) {
|
||||||
|
const auto ratio = style::DevicePixelRatio();
|
||||||
|
_subscribed->key = key;
|
||||||
|
_frame = QImage(
|
||||||
|
QSize(size, size) * ratio,
|
||||||
|
QImage::Format_ARGB32_Premultiplied);
|
||||||
|
_frame.setDevicePixelRatio(ratio);
|
||||||
|
_frame.fill(Qt::transparent);
|
||||||
|
|
||||||
|
auto p = Painter(&_frame);
|
||||||
|
_peer->paintUserpic(p, _subscribed->view, 0, 0, size);
|
||||||
|
}
|
||||||
|
return _frame;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool PeerUserpic::waitingUserpicLoad() const {
|
||||||
|
return _peer->hasUserpic() && _peer->useEmptyUserpic(_subscribed->view);
|
||||||
|
}
|
||||||
|
|
||||||
|
void PeerUserpic::subscribeToUpdates(Fn<void()> callback) {
|
||||||
|
if (!callback) {
|
||||||
|
_subscribed = nullptr;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
_subscribed = std::make_unique<Subscribed>(std::move(callback));
|
||||||
|
|
||||||
|
_peer->session().changes().peerUpdates(
|
||||||
|
_peer,
|
||||||
|
Data::PeerUpdate::Flag::Photo
|
||||||
|
) | rpl::start_with_next([=] {
|
||||||
|
_subscribed->callback();
|
||||||
|
processNewPhoto();
|
||||||
|
}, _subscribed->photoLifetime);
|
||||||
|
|
||||||
|
processNewPhoto();
|
||||||
|
}
|
||||||
|
|
||||||
|
void PeerUserpic::processNewPhoto() {
|
||||||
|
Expects(_subscribed != nullptr);
|
||||||
|
|
||||||
|
if (!waitingUserpicLoad()) {
|
||||||
|
_subscribed->downloadLifetime.destroy();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
_peer->session().downloaderTaskFinished(
|
||||||
|
) | rpl::filter([=] {
|
||||||
|
return !waitingUserpicLoad();
|
||||||
|
}) | rpl::start_with_next([=] {
|
||||||
|
_subscribed->callback();
|
||||||
|
_subscribed->downloadLifetime.destroy();
|
||||||
|
}, _subscribed->downloadLifetime);
|
||||||
|
}
|
||||||
|
|
||||||
|
StoryThumbnail::StoryThumbnail(FullStoryId id)
|
||||||
|
: _id(id) {
|
||||||
|
}
|
||||||
|
|
||||||
|
QImage StoryThumbnail::image(int size) {
|
||||||
|
const auto ratio = style::DevicePixelRatio();
|
||||||
|
if (_prepared.width() != size * ratio) {
|
||||||
|
if (_full.isNull()) {
|
||||||
|
_prepared = QImage(
|
||||||
|
QSize(size, size) * ratio,
|
||||||
|
QImage::Format_ARGB32_Premultiplied);
|
||||||
|
_prepared.fill(Qt::black);
|
||||||
|
} else {
|
||||||
|
const auto width = _full.width();
|
||||||
|
const auto skip = std::max((_full.height() - width) / 2, 0);
|
||||||
|
_prepared = _full.copy(0, skip, width, width).scaled(
|
||||||
|
QSize(size, size) * ratio,
|
||||||
|
Qt::IgnoreAspectRatio,
|
||||||
|
Qt::SmoothTransformation);
|
||||||
|
}
|
||||||
|
_prepared = Images::Circle(std::move(_prepared));
|
||||||
|
_prepared.setDevicePixelRatio(ratio);
|
||||||
|
}
|
||||||
|
return _prepared;
|
||||||
|
}
|
||||||
|
|
||||||
|
void StoryThumbnail::subscribeToUpdates(Fn<void()> callback) {
|
||||||
|
_subscription.destroy();
|
||||||
|
if (!callback) {
|
||||||
|
clear();
|
||||||
|
return;
|
||||||
|
} else if (!_full.isNull() && !_blurred) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const auto thumbnail = loaded(_id);
|
||||||
|
if (const auto image = thumbnail.image) {
|
||||||
|
_full = image->original();
|
||||||
|
}
|
||||||
|
_blurred = thumbnail.blurred;
|
||||||
|
if (!_blurred) {
|
||||||
|
_prepared = QImage();
|
||||||
|
} else {
|
||||||
|
_subscription = session().downloaderTaskFinished(
|
||||||
|
) | rpl::filter([=] {
|
||||||
|
const auto thumbnail = loaded(_id);
|
||||||
|
if (!thumbnail.blurred) {
|
||||||
|
_full = thumbnail.image->original();
|
||||||
|
_prepared = QImage();
|
||||||
|
_blurred = false;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}) | rpl::take(1) | rpl::start_with_next(callback);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
PhotoThumbnail::PhotoThumbnail(not_null<PhotoData*> photo, FullStoryId id)
|
||||||
|
: StoryThumbnail(id)
|
||||||
|
, _photo(photo) {
|
||||||
|
}
|
||||||
|
|
||||||
|
Main::Session &PhotoThumbnail::session() {
|
||||||
|
return _photo->session();
|
||||||
|
}
|
||||||
|
|
||||||
|
StoryThumbnail::Thumb PhotoThumbnail::loaded(FullStoryId id) {
|
||||||
|
if (!_media) {
|
||||||
|
_media = _photo->createMediaView();
|
||||||
|
_media->wanted(Data::PhotoSize::Small, id);
|
||||||
|
}
|
||||||
|
if (const auto small = _media->image(Data::PhotoSize::Small)) {
|
||||||
|
return { .image = small };
|
||||||
|
}
|
||||||
|
return { .image = _media->thumbnailInline(), .blurred = true };
|
||||||
|
}
|
||||||
|
|
||||||
|
void PhotoThumbnail::clear() {
|
||||||
|
_media = nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
VideoThumbnail::VideoThumbnail(
|
||||||
|
not_null<DocumentData*> video,
|
||||||
|
FullStoryId id)
|
||||||
|
: StoryThumbnail(id)
|
||||||
|
, _video(video) {
|
||||||
|
}
|
||||||
|
|
||||||
|
Main::Session &VideoThumbnail::session() {
|
||||||
|
return _video->session();
|
||||||
|
}
|
||||||
|
|
||||||
|
StoryThumbnail::Thumb VideoThumbnail::loaded(FullStoryId id) {
|
||||||
|
if (!_media) {
|
||||||
|
_media = _video->createMediaView();
|
||||||
|
_media->thumbnailWanted(id);
|
||||||
|
}
|
||||||
|
if (const auto small = _media->thumbnail()) {
|
||||||
|
return { .image = small };
|
||||||
|
}
|
||||||
|
return { .image = _media->thumbnailInline(), .blurred = true };
|
||||||
|
}
|
||||||
|
|
||||||
|
void VideoThumbnail::clear() {
|
||||||
|
_media = nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
QImage EmptyThumbnail::image(int size) {
|
||||||
|
const auto ratio = style::DevicePixelRatio();
|
||||||
|
if (_cached.width() != size * ratio) {
|
||||||
|
_cached = QImage(
|
||||||
|
QSize(size, size) * ratio,
|
||||||
|
QImage::Format_ARGB32_Premultiplied);
|
||||||
|
_cached.fill(Qt::black);
|
||||||
|
_cached.setDevicePixelRatio(ratio);
|
||||||
|
}
|
||||||
|
return _cached;
|
||||||
|
}
|
||||||
|
|
||||||
|
void EmptyThumbnail::subscribeToUpdates(Fn<void()> callback) {
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace
|
||||||
|
|
||||||
|
std::shared_ptr<DynamicImage> MakeUserpicThumbnail(
|
||||||
|
not_null<PeerData*> peer) {
|
||||||
|
return std::make_shared<PeerUserpic>(peer);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::shared_ptr<DynamicImage> MakeStoryThumbnail(
|
||||||
|
not_null<Data::Story*> story) {
|
||||||
|
using Result = std::shared_ptr<DynamicImage>;
|
||||||
|
const auto id = story->fullId();
|
||||||
|
return v::match(story->media().data, [](v::null_t) -> Result {
|
||||||
|
return std::make_shared<EmptyThumbnail>();
|
||||||
|
}, [&](not_null<PhotoData*> photo) -> Result {
|
||||||
|
return std::make_shared<PhotoThumbnail>(photo, id);
|
||||||
|
}, [&](not_null<DocumentData*> video) -> Result {
|
||||||
|
return std::make_shared<VideoThumbnail>(video, id);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace Ui
|
25
Telegram/SourceFiles/ui/dynamic_thumbnails.h
Normal file
25
Telegram/SourceFiles/ui/dynamic_thumbnails.h
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
/*
|
||||||
|
This file is part of Telegram Desktop,
|
||||||
|
the official desktop application for the Telegram messaging service.
|
||||||
|
|
||||||
|
For license and copyright information please follow this link:
|
||||||
|
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
|
*/
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
class PeerData;
|
||||||
|
|
||||||
|
namespace Data {
|
||||||
|
class Story;
|
||||||
|
} // namespace Data
|
||||||
|
|
||||||
|
namespace Ui {
|
||||||
|
|
||||||
|
class DynamicImage;
|
||||||
|
|
||||||
|
[[nodiscard]] std::shared_ptr<DynamicImage> MakeUserpicThumbnail(
|
||||||
|
not_null<PeerData*> peer);
|
||||||
|
[[nodiscard]] std::shared_ptr<DynamicImage> MakeStoryThumbnail(
|
||||||
|
not_null<Data::Story*> story);
|
||||||
|
|
||||||
|
} // namespace Ui
|
|
@ -1 +1 @@
|
||||||
Subproject commit 7328e2786248c673e3599695a56989d9c1062303
|
Subproject commit d4247511355a666903e9a57d821b1eb58884aade
|
Loading…
Add table
Reference in a new issue