2017-12-28 13:06:06 +00:00
|
|
|
/*
|
|
|
|
This file is part of Telegram Desktop,
|
2018-01-03 10:23:14 +00:00
|
|
|
the official desktop application for the Telegram messaging service.
|
2017-12-28 13:06:06 +00:00
|
|
|
|
2018-01-03 10:23:14 +00:00
|
|
|
For license and copyright information please follow this link:
|
|
|
|
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
2017-12-28 13:06:06 +00:00
|
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
|
2017-12-28 14:58:34 +00:00
|
|
|
#include "history/history_item_components.h"
|
2019-04-02 09:13:30 +00:00
|
|
|
#include "ui/effects/animations.h"
|
2017-12-29 14:58:53 +00:00
|
|
|
#include "base/weak_ptr.h"
|
2017-12-28 14:58:34 +00:00
|
|
|
|
|
|
|
class SharedMediaWithLastSlice;
|
|
|
|
class UserPhotosSlice;
|
2018-10-24 13:09:31 +00:00
|
|
|
struct WebPageCollage;
|
2017-12-28 14:58:34 +00:00
|
|
|
|
2020-06-08 15:17:33 +00:00
|
|
|
namespace Main {
|
|
|
|
class Session;
|
|
|
|
} // namespace Main
|
|
|
|
|
2017-12-28 13:06:06 +00:00
|
|
|
namespace Media {
|
|
|
|
namespace View {
|
|
|
|
|
2017-12-29 14:58:53 +00:00
|
|
|
class GroupThumbs : public base::has_weak_ptr {
|
2017-12-28 13:06:06 +00:00
|
|
|
public:
|
2018-10-24 13:09:31 +00:00
|
|
|
struct CollageKey {
|
|
|
|
int index = 0;
|
|
|
|
|
|
|
|
inline bool operator<(const CollageKey &other) const {
|
|
|
|
return index < other.index;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
struct CollageSlice {
|
|
|
|
FullMsgId context;
|
|
|
|
not_null<const WebPageCollage*> data;
|
|
|
|
|
|
|
|
int size() const;
|
|
|
|
};
|
2020-08-31 08:14:53 +00:00
|
|
|
using Key = std::variant<PhotoId, FullMsgId, CollageKey>;
|
2017-12-29 14:58:53 +00:00
|
|
|
|
2017-12-28 14:58:34 +00:00
|
|
|
static void Refresh(
|
2020-06-08 15:17:33 +00:00
|
|
|
not_null<Main::Session*> session,
|
2017-12-28 14:58:34 +00:00
|
|
|
std::unique_ptr<GroupThumbs> &instance,
|
|
|
|
const SharedMediaWithLastSlice &slice,
|
|
|
|
int index,
|
|
|
|
int availableWidth);
|
|
|
|
static void Refresh(
|
2020-06-08 15:17:33 +00:00
|
|
|
not_null<Main::Session*> session,
|
2017-12-28 14:58:34 +00:00
|
|
|
std::unique_ptr<GroupThumbs> &instance,
|
|
|
|
const UserPhotosSlice &slice,
|
|
|
|
int index,
|
|
|
|
int availableWidth);
|
2018-10-24 13:09:31 +00:00
|
|
|
static void Refresh(
|
2020-06-08 15:17:33 +00:00
|
|
|
not_null<Main::Session*> session,
|
2018-10-24 13:09:31 +00:00
|
|
|
std::unique_ptr<GroupThumbs> &instance,
|
|
|
|
const CollageSlice &slice,
|
|
|
|
int index,
|
|
|
|
int availableWidth);
|
2017-12-28 14:58:34 +00:00
|
|
|
void clear();
|
2017-12-28 13:06:06 +00:00
|
|
|
|
|
|
|
void resizeToWidth(int newWidth);
|
|
|
|
int height() const;
|
2017-12-28 14:58:34 +00:00
|
|
|
bool hiding() const;
|
|
|
|
bool hidden() const;
|
|
|
|
void checkForAnimationStart();
|
|
|
|
|
2019-04-02 09:13:30 +00:00
|
|
|
void paint(Painter &p, int x, int y, int outerWidth);
|
2017-12-29 14:58:53 +00:00
|
|
|
ClickHandlerPtr getState(QPoint point) const;
|
2017-12-28 14:58:34 +00:00
|
|
|
|
|
|
|
rpl::producer<QRect> updateRequests() const {
|
|
|
|
return _updateRequests.events();
|
|
|
|
}
|
|
|
|
|
2017-12-29 14:58:53 +00:00
|
|
|
rpl::producer<Key> activateRequests() const {
|
|
|
|
return _activateStream.events();
|
|
|
|
}
|
|
|
|
|
2017-12-28 14:58:34 +00:00
|
|
|
rpl::lifetime &lifetime() {
|
|
|
|
return _lifetime;
|
|
|
|
}
|
2017-12-28 13:06:06 +00:00
|
|
|
|
2020-08-31 09:04:17 +00:00
|
|
|
using Context = std::variant<
|
|
|
|
v::null_t,
|
2018-10-24 13:09:31 +00:00
|
|
|
PeerId,
|
|
|
|
MessageGroupId,
|
|
|
|
FullMsgId>;
|
2017-12-28 14:58:34 +00:00
|
|
|
|
2020-06-08 15:17:33 +00:00
|
|
|
GroupThumbs(not_null<Main::Session*> session, Context context);
|
2017-12-28 14:58:34 +00:00
|
|
|
~GroupThumbs();
|
2017-12-28 13:06:06 +00:00
|
|
|
|
|
|
|
private:
|
2017-12-28 14:58:34 +00:00
|
|
|
class Thumb;
|
|
|
|
|
|
|
|
template <typename Slice>
|
|
|
|
static void RefreshFromSlice(
|
2020-06-08 15:17:33 +00:00
|
|
|
not_null<Main::Session*> session,
|
2017-12-28 14:58:34 +00:00
|
|
|
std::unique_ptr<GroupThumbs> &instance,
|
|
|
|
const Slice &slice,
|
|
|
|
int index,
|
|
|
|
int availableWidth);
|
|
|
|
template <typename Slice>
|
|
|
|
void fillItems(const Slice &slice, int from, int index, int till);
|
|
|
|
void updateContext(Context context);
|
|
|
|
void markCacheStale();
|
|
|
|
not_null<Thumb*> validateCacheEntry(Key key);
|
|
|
|
std::unique_ptr<Thumb> createThumb(Key key);
|
2018-10-24 13:09:31 +00:00
|
|
|
std::unique_ptr<Thumb> createThumb(
|
|
|
|
Key key,
|
|
|
|
const WebPageCollage &collage,
|
|
|
|
int index);
|
2020-05-25 14:16:04 +00:00
|
|
|
std::unique_ptr<Thumb> createThumb(Key key, not_null<PhotoData*> photo);
|
2020-04-15 14:06:34 +00:00
|
|
|
std::unique_ptr<Thumb> createThumb(
|
|
|
|
Key key,
|
|
|
|
not_null<DocumentData*> document);
|
2020-05-25 14:16:04 +00:00
|
|
|
std::unique_ptr<Thumb> createThumb(Key key, std::nullptr_t);
|
2017-12-28 14:58:34 +00:00
|
|
|
|
|
|
|
void update();
|
|
|
|
void countUpdatedRect();
|
|
|
|
void animateAliveItems(int current);
|
|
|
|
void fillDyingItems(const std::vector<not_null<Thumb*>> &old);
|
|
|
|
void markAsDying(not_null<Thumb*> thumb);
|
|
|
|
void markRestAsDying();
|
|
|
|
void animatePreviouslyAlive(const std::vector<not_null<Thumb*>> &old);
|
|
|
|
void startDelayedAnimation();
|
|
|
|
|
2020-06-08 15:17:33 +00:00
|
|
|
const not_null<Main::Session*> _session;
|
2017-12-28 14:58:34 +00:00
|
|
|
Context _context;
|
|
|
|
bool _waitingForAnimationStart = true;
|
2019-04-02 09:13:30 +00:00
|
|
|
Ui::Animations::Simple _animation;
|
2017-12-28 14:58:34 +00:00
|
|
|
std::vector<not_null<Thumb*>> _items;
|
|
|
|
std::vector<not_null<Thumb*>> _dying;
|
|
|
|
base::flat_map<Key, std::unique_ptr<Thumb>> _cache;
|
|
|
|
int _width = 0;
|
2017-12-29 14:58:53 +00:00
|
|
|
QRect _updatedRect;
|
|
|
|
|
2017-12-28 14:58:34 +00:00
|
|
|
rpl::event_stream<QRect> _updateRequests;
|
2017-12-29 14:58:53 +00:00
|
|
|
rpl::event_stream<Key> _activateStream;
|
2017-12-28 14:58:34 +00:00
|
|
|
rpl::lifetime _lifetime;
|
|
|
|
|
2017-12-28 13:06:06 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace View
|
|
|
|
} // namespace Media
|