2016-10-20 16:32:15 +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.
|
2016-10-20 16:32:15 +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
|
2016-10-20 16:32:15 +00:00
|
|
|
*/
|
|
|
|
#include "stickers_box.h"
|
|
|
|
|
2017-09-26 11:49:16 +00:00
|
|
|
#include "data/data_document.h"
|
2018-01-04 10:22:53 +00:00
|
|
|
#include "data/data_session.h"
|
2019-01-04 11:09:48 +00:00
|
|
|
#include "data/data_channel.h"
|
2019-12-05 08:32:33 +00:00
|
|
|
#include "data/data_file_origin.h"
|
2020-04-09 14:02:09 +00:00
|
|
|
#include "data/data_document_media.h"
|
2020-06-08 17:24:36 +00:00
|
|
|
#include "data/stickers/data_stickers.h"
|
2019-01-21 13:42:21 +00:00
|
|
|
#include "core/application.h"
|
2017-04-13 08:27:10 +00:00
|
|
|
#include "lang/lang_keys.h"
|
2016-10-20 16:32:15 +00:00
|
|
|
#include "mainwidget.h"
|
2019-06-24 15:09:37 +00:00
|
|
|
#include "mainwindow.h"
|
2021-10-18 21:36:55 +00:00
|
|
|
#include "ui/boxes/confirm_box.h"
|
2017-04-06 14:38:10 +00:00
|
|
|
#include "boxes/sticker_set_box.h"
|
2016-10-20 16:32:15 +00:00
|
|
|
#include "apiwrap.h"
|
2020-06-09 16:57:05 +00:00
|
|
|
#include "storage/storage_account.h"
|
2021-10-01 10:48:52 +00:00
|
|
|
#include "dialogs/ui/dialogs_layout.h"
|
2019-07-02 13:20:04 +00:00
|
|
|
#include "lottie/lottie_single_player.h"
|
2020-06-08 17:24:36 +00:00
|
|
|
#include "chat_helpers/stickers_lottie.h"
|
2016-11-11 13:46:04 +00:00
|
|
|
#include "ui/widgets/buttons.h"
|
2017-08-05 20:01:20 +00:00
|
|
|
#include "ui/widgets/labels.h"
|
2016-11-16 10:44:06 +00:00
|
|
|
#include "ui/widgets/scroll_area.h"
|
2017-09-30 18:26:45 +00:00
|
|
|
#include "ui/widgets/shadow.h"
|
2016-11-16 16:04:25 +00:00
|
|
|
#include "ui/effects/ripple_animation.h"
|
2016-11-24 19:28:23 +00:00
|
|
|
#include "ui/effects/slide_animation.h"
|
2016-11-22 09:48:13 +00:00
|
|
|
#include "ui/widgets/discrete_sliders.h"
|
2017-08-05 20:01:20 +00:00
|
|
|
#include "ui/widgets/input_fields.h"
|
2018-10-23 09:44:42 +00:00
|
|
|
#include "ui/image/image.h"
|
2020-10-13 15:11:53 +00:00
|
|
|
#include "ui/cached_round_corners.h"
|
2019-07-02 13:20:04 +00:00
|
|
|
#include "window/window_session_controller.h"
|
2022-01-24 12:33:31 +00:00
|
|
|
#include "media/clip/media_clip_reader.h"
|
2019-07-24 11:45:24 +00:00
|
|
|
#include "main/main_session.h"
|
2019-09-18 11:19:05 +00:00
|
|
|
#include "styles/style_layers.h"
|
2019-07-02 13:20:04 +00:00
|
|
|
#include "styles/style_boxes.h"
|
|
|
|
#include "styles/style_chat_helpers.h"
|
2016-10-20 16:32:15 +00:00
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
2020-06-08 17:24:36 +00:00
|
|
|
using Data::StickersSet;
|
|
|
|
using Data::StickersSetsOrder;
|
|
|
|
using Data::StickersSetThumbnailView;
|
2021-07-09 06:08:58 +00:00
|
|
|
using SetFlag = Data::StickersSetFlag;
|
2020-06-08 17:24:36 +00:00
|
|
|
|
2017-08-05 20:01:20 +00:00
|
|
|
constexpr auto kArchivedLimitFirstRequest = 10;
|
|
|
|
constexpr auto kArchivedLimitPerPage = 30;
|
2019-02-19 06:57:53 +00:00
|
|
|
constexpr auto kHandleMegagroupSetAddressChangeTimeout = crl::time(1000);
|
2016-10-20 16:32:15 +00:00
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
2017-11-05 17:07:27 +00:00
|
|
|
class StickersBox::CounterWidget : public Ui::RpWidget {
|
2016-11-22 09:48:13 +00:00
|
|
|
public:
|
2019-08-06 16:40:08 +00:00
|
|
|
CounterWidget(QWidget *parent, rpl::producer<int> count);
|
2016-11-22 09:48:13 +00:00
|
|
|
|
|
|
|
protected:
|
|
|
|
void paintEvent(QPaintEvent *e) override;
|
|
|
|
|
|
|
|
private:
|
2017-11-05 17:07:27 +00:00
|
|
|
void setCounter(int counter);
|
2016-11-22 09:48:13 +00:00
|
|
|
|
|
|
|
QString _text;
|
2021-10-01 10:57:24 +00:00
|
|
|
Dialogs::Ui::UnreadBadgeStyle _st;
|
2016-11-22 09:48:13 +00:00
|
|
|
|
|
|
|
};
|
|
|
|
|
2020-06-08 17:24:36 +00:00
|
|
|
// This class is hold in header because it requires Qt preprocessing.
|
2021-05-25 10:14:12 +00:00
|
|
|
class StickersBox::Inner : public Ui::RpWidget {
|
2020-06-08 17:24:36 +00:00
|
|
|
public:
|
|
|
|
using Section = StickersBox::Section;
|
|
|
|
|
|
|
|
Inner(
|
|
|
|
QWidget *parent,
|
2020-06-23 17:21:58 +00:00
|
|
|
not_null<Window::SessionController*> controller,
|
2020-06-08 17:24:36 +00:00
|
|
|
Section section);
|
2020-06-23 17:21:58 +00:00
|
|
|
Inner(
|
|
|
|
QWidget *parent,
|
|
|
|
not_null<Window::SessionController*> controller,
|
|
|
|
not_null<ChannelData*> megagroup);
|
|
|
|
|
|
|
|
[[nodiscard]] Main::Session &session() const;
|
2020-06-08 17:24:36 +00:00
|
|
|
|
2021-05-25 10:14:12 +00:00
|
|
|
rpl::producer<int> scrollsToY() const {
|
|
|
|
return _scrollsToY.events();
|
|
|
|
}
|
2020-06-08 17:24:36 +00:00
|
|
|
void setInnerFocus();
|
|
|
|
|
|
|
|
void saveGroupSet();
|
|
|
|
|
2021-03-30 15:51:45 +00:00
|
|
|
void rebuild(bool masks);
|
2020-06-08 17:24:36 +00:00
|
|
|
void updateSize(int newWidth = 0);
|
|
|
|
void updateRows(); // refresh only pack cover stickers
|
|
|
|
bool appendSet(not_null<StickersSet*> set);
|
|
|
|
|
|
|
|
StickersSetsOrder getOrder() const;
|
|
|
|
StickersSetsOrder getFullOrder() const;
|
|
|
|
StickersSetsOrder getRemovedSets() const;
|
|
|
|
|
|
|
|
void setFullOrder(const StickersSetsOrder &order);
|
|
|
|
void setRemovedSets(const StickersSetsOrder &removed);
|
|
|
|
|
|
|
|
void setInstallSetCallback(Fn<void(uint64 setId)> callback) {
|
|
|
|
_installSetCallback = std::move(callback);
|
|
|
|
}
|
|
|
|
void setLoadMoreCallback(Fn<void()> callback) {
|
|
|
|
_loadMoreCallback = std::move(callback);
|
|
|
|
}
|
|
|
|
|
|
|
|
void setMinHeight(int newWidth, int minHeight);
|
|
|
|
|
|
|
|
int getVisibleTop() const {
|
|
|
|
return _visibleTop;
|
|
|
|
}
|
|
|
|
|
|
|
|
[[nodiscard]] rpl::producer<int> draggingScrollDelta() const {
|
|
|
|
return _draggingScrollDelta.events();
|
|
|
|
}
|
|
|
|
|
|
|
|
~Inner();
|
|
|
|
|
|
|
|
protected:
|
|
|
|
void visibleTopBottomUpdated(
|
|
|
|
int visibleTop,
|
|
|
|
int visibleBottom) override;
|
|
|
|
|
|
|
|
void paintEvent(QPaintEvent *e) override;
|
|
|
|
void resizeEvent(QResizeEvent *e) override;
|
|
|
|
void mousePressEvent(QMouseEvent *e) override;
|
|
|
|
void mouseMoveEvent(QMouseEvent *e) override;
|
|
|
|
void mouseReleaseEvent(QMouseEvent *e) override;
|
|
|
|
void leaveEventHook(QEvent *e) override;
|
|
|
|
void leaveToChildEvent(QEvent *e, QWidget *child) override;
|
|
|
|
|
|
|
|
private:
|
|
|
|
struct Row {
|
|
|
|
Row(
|
|
|
|
not_null<StickersSet*> set,
|
|
|
|
DocumentData *sticker,
|
|
|
|
int32 count,
|
|
|
|
const QString &title,
|
|
|
|
int titleWidth,
|
2022-01-24 12:33:31 +00:00
|
|
|
Data::StickersSetFlags flagsOverride,
|
2020-06-08 17:24:36 +00:00
|
|
|
bool removed,
|
|
|
|
int32 pixw,
|
|
|
|
int32 pixh);
|
|
|
|
~Row();
|
|
|
|
|
|
|
|
bool isRecentSet() const;
|
2021-03-29 23:00:04 +00:00
|
|
|
bool isMasksSet() const;
|
2022-07-18 13:56:14 +00:00
|
|
|
bool isEmojiSet() const;
|
2022-01-24 12:33:31 +00:00
|
|
|
bool isWebm() const;
|
|
|
|
bool isInstalled() const;
|
|
|
|
bool isUnread() const;
|
|
|
|
bool isArchived() const;
|
2020-06-08 17:24:36 +00:00
|
|
|
|
|
|
|
const not_null<StickersSet*> set;
|
|
|
|
DocumentData *sticker = nullptr;
|
|
|
|
std::shared_ptr<Data::DocumentMedia> stickerMedia;
|
|
|
|
std::shared_ptr<StickersSetThumbnailView> thumbnailMedia;
|
|
|
|
int32 count = 0;
|
|
|
|
QString title;
|
|
|
|
int titleWidth = 0;
|
2022-01-24 12:33:31 +00:00
|
|
|
Data::StickersSetFlags flagsOverride;
|
2020-06-08 17:24:36 +00:00
|
|
|
bool removed = false;
|
|
|
|
int32 pixw = 0;
|
|
|
|
int32 pixh = 0;
|
|
|
|
anim::value yadd;
|
|
|
|
std::unique_ptr<Ui::RippleAnimation> ripple;
|
|
|
|
std::unique_ptr<Lottie::SinglePlayer> lottie;
|
2022-01-24 12:33:31 +00:00
|
|
|
Media::Clip::ReaderPointer webm;
|
2020-06-08 17:24:36 +00:00
|
|
|
};
|
|
|
|
struct MegagroupSet {
|
|
|
|
inline bool operator==(const MegagroupSet &other) const {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
inline bool operator!=(const MegagroupSet &other) const {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
};
|
2020-08-31 09:04:17 +00:00
|
|
|
using SelectedRow = std::variant<v::null_t, MegagroupSet, int>;
|
2020-06-08 17:24:36 +00:00
|
|
|
class AddressField : public Ui::UsernameInput {
|
|
|
|
public:
|
|
|
|
using UsernameInput::UsernameInput;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
void correctValue(
|
|
|
|
const QString &was,
|
|
|
|
int wasCursor,
|
|
|
|
QString &now,
|
|
|
|
int &nowCursor) override;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
template <typename Check>
|
|
|
|
StickersSetsOrder collectSets(Check check) const;
|
|
|
|
|
|
|
|
void updateSelected();
|
|
|
|
|
|
|
|
void checkLoadMore();
|
|
|
|
void updateScrollbarWidth();
|
|
|
|
int getRowIndex(uint64 setId) const;
|
|
|
|
void setRowRemoved(int index, bool removed);
|
|
|
|
|
|
|
|
void setSelected(SelectedRow selected);
|
|
|
|
void setActionDown(int newActionDown);
|
|
|
|
void setPressed(SelectedRow pressed);
|
|
|
|
void setup();
|
|
|
|
QRect relativeButtonRect(bool removeButton) const;
|
|
|
|
void ensureRipple(const style::RippleAnimation &st, QImage mask, bool removeButton);
|
|
|
|
|
|
|
|
bool shiftingAnimationCallback(crl::time now);
|
|
|
|
void paintRow(Painter &p, not_null<Row*> row, int index);
|
|
|
|
void paintRowThumbnail(Painter &p, not_null<Row*> row, int left);
|
|
|
|
void paintFakeButton(Painter &p, not_null<Row*> row, int index);
|
|
|
|
void clear();
|
|
|
|
void updateCursor();
|
|
|
|
void setActionSel(int32 actionSel);
|
|
|
|
float64 aboveShadowOpacity() const;
|
|
|
|
void validateLottieAnimation(not_null<Row*> row);
|
2022-01-24 12:33:31 +00:00
|
|
|
void validateWebmAnimation(not_null<Row*> row);
|
|
|
|
void validateAnimation(not_null<Row*> row);
|
2020-06-08 17:24:36 +00:00
|
|
|
void updateRowThumbnail(not_null<Row*> row);
|
|
|
|
|
2022-01-25 07:09:55 +00:00
|
|
|
void clipCallback(
|
|
|
|
not_null<Row*> row,
|
|
|
|
Media::Clip::Notification notification);
|
|
|
|
|
2020-06-08 17:24:36 +00:00
|
|
|
void readVisibleSets();
|
|
|
|
|
|
|
|
void updateControlsGeometry();
|
|
|
|
void rebuildAppendSet(not_null<StickersSet*> set, int maxNameWidth);
|
|
|
|
void fillSetCover(not_null<StickersSet*> set, DocumentData **outSticker, int *outWidth, int *outHeight) const;
|
|
|
|
int fillSetCount(not_null<StickersSet*> set) const;
|
2022-01-24 12:33:31 +00:00
|
|
|
[[nodiscard]] QString fillSetTitle(
|
|
|
|
not_null<StickersSet*> set,
|
|
|
|
int maxNameWidth,
|
|
|
|
int *outTitleWidth) const;
|
|
|
|
[[nodiscard]] Data::StickersSetFlags fillSetFlags(
|
|
|
|
not_null<StickersSet*> set) const;
|
2020-06-08 17:24:36 +00:00
|
|
|
void rebuildMegagroupSet();
|
|
|
|
void handleMegagroupSetAddressChange();
|
2021-07-08 16:42:57 +00:00
|
|
|
void setMegagroupSelectedSet(const StickerSetIdentifier &set);
|
2020-06-08 17:24:36 +00:00
|
|
|
|
|
|
|
int countMaxNameWidth() const;
|
2022-06-08 06:28:45 +00:00
|
|
|
[[nodiscard]] bool skipPremium() const;
|
2020-06-08 17:24:36 +00:00
|
|
|
|
2020-06-23 17:21:58 +00:00
|
|
|
const not_null<Window::SessionController*> _controller;
|
2020-06-08 17:24:36 +00:00
|
|
|
MTP::Sender _api;
|
|
|
|
|
2021-03-29 17:37:03 +00:00
|
|
|
const Section _section;
|
|
|
|
const bool _isInstalled;
|
2020-06-08 17:24:36 +00:00
|
|
|
|
|
|
|
int32 _rowHeight;
|
|
|
|
|
|
|
|
std::vector<std::unique_ptr<Row>> _rows;
|
2021-12-31 14:08:34 +00:00
|
|
|
std::vector<std::unique_ptr<Row>> _oldRows;
|
2020-06-08 17:24:36 +00:00
|
|
|
std::vector<crl::time> _shiftingStartTimes;
|
|
|
|
crl::time _aboveShadowFadeStart = 0;
|
|
|
|
anim::value _aboveShadowFadeOpacity;
|
|
|
|
Ui::Animations::Basic _shiftingAnimation;
|
|
|
|
|
|
|
|
Fn<void(uint64 setId)> _installSetCallback;
|
|
|
|
Fn<void()> _loadMoreCallback;
|
|
|
|
|
|
|
|
int _visibleTop = 0;
|
|
|
|
int _visibleBottom = 0;
|
|
|
|
int _itemsTop = 0;
|
|
|
|
|
|
|
|
int _actionSel = -1;
|
|
|
|
int _actionDown = -1;
|
|
|
|
|
|
|
|
QString _addText;
|
|
|
|
int _addWidth = 0;
|
|
|
|
QString _undoText;
|
|
|
|
int _undoWidth = 0;
|
|
|
|
|
|
|
|
QPoint _mouse;
|
|
|
|
bool _inDragArea = false;
|
|
|
|
SelectedRow _selected;
|
|
|
|
SelectedRow _pressed;
|
|
|
|
QPoint _dragStart;
|
|
|
|
int _started = -1;
|
|
|
|
int _dragging = -1;
|
|
|
|
int _above = -1;
|
|
|
|
rpl::event_stream<int> _draggingScrollDelta;
|
|
|
|
|
2021-05-25 10:14:12 +00:00
|
|
|
rpl::event_stream<int> _scrollsToY;
|
|
|
|
|
2020-06-08 17:24:36 +00:00
|
|
|
int _minHeight = 0;
|
|
|
|
|
|
|
|
int _scrollbar = 0;
|
|
|
|
ChannelData *_megagroupSet = nullptr;
|
2021-07-08 16:42:57 +00:00
|
|
|
StickerSetIdentifier _megagroupSetInput;
|
2020-06-08 17:24:36 +00:00
|
|
|
std::unique_ptr<Row> _megagroupSelectedSet;
|
|
|
|
object_ptr<AddressField> _megagroupSetField = { nullptr };
|
|
|
|
object_ptr<Ui::PlainShadow> _megagroupSelectedShadow = { nullptr };
|
|
|
|
object_ptr<Ui::CrossButton> _megagroupSelectedRemove = { nullptr };
|
|
|
|
object_ptr<Ui::BoxContentDivider> _megagroupDivider = { nullptr };
|
|
|
|
object_ptr<Ui::FlatLabel> _megagroupSubTitle = { nullptr };
|
|
|
|
base::Timer _megagroupSetAddressChangedTimer;
|
|
|
|
mtpRequestId _megagroupSetRequestId = 0;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2019-08-06 16:40:08 +00:00
|
|
|
StickersBox::CounterWidget::CounterWidget(
|
|
|
|
QWidget *parent,
|
|
|
|
rpl::producer<int> count)
|
2017-11-05 17:07:27 +00:00
|
|
|
: RpWidget(parent) {
|
2016-11-22 09:48:13 +00:00
|
|
|
setAttribute(Qt::WA_TransparentForMouseEvents);
|
|
|
|
|
2021-10-01 10:57:24 +00:00
|
|
|
_st.sizeId = Dialogs::Ui::UnreadBadgeInStickersBox;
|
2016-11-22 09:48:13 +00:00
|
|
|
_st.textTop = st::stickersFeaturedBadgeTextTop;
|
|
|
|
_st.size = st::stickersFeaturedBadgeSize;
|
|
|
|
_st.padding = st::stickersFeaturedBadgePadding;
|
|
|
|
_st.font = st::stickersFeaturedBadgeFont;
|
|
|
|
|
2019-08-06 16:40:08 +00:00
|
|
|
std::move(
|
|
|
|
count
|
|
|
|
) | rpl::start_with_next([=](int count) {
|
2017-12-22 07:05:20 +00:00
|
|
|
setCounter(count);
|
|
|
|
update();
|
|
|
|
}, lifetime());
|
2016-11-22 09:48:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void StickersBox::CounterWidget::setCounter(int counter) {
|
|
|
|
_text = (counter > 0) ? QString::number(counter) : QString();
|
|
|
|
auto dummy = QImage(1, 1, QImage::Format_ARGB32_Premultiplied);
|
|
|
|
Painter p(&dummy);
|
|
|
|
|
2022-01-26 11:47:23 +00:00
|
|
|
const auto badge = Dialogs::Ui::PaintUnreadBadge(p, _text, 0, 0, _st);
|
2016-11-22 09:48:13 +00:00
|
|
|
|
2022-01-26 11:47:23 +00:00
|
|
|
resize(badge.width(), st::stickersFeaturedBadgeSize);
|
2016-11-22 09:48:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void StickersBox::CounterWidget::paintEvent(QPaintEvent *e) {
|
|
|
|
Painter p(this);
|
|
|
|
|
|
|
|
if (!_text.isEmpty()) {
|
2022-01-26 11:47:23 +00:00
|
|
|
const auto unreadRight = rtl() ? 0 : width();
|
|
|
|
const auto unreadTop = 0;
|
|
|
|
Dialogs::Ui::PaintUnreadBadge(p, _text, unreadRight, unreadTop, _st);
|
2016-11-22 09:48:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-13 17:07:56 +00:00
|
|
|
template <typename ...Args>
|
|
|
|
StickersBox::Tab::Tab(int index, Args&&... args)
|
|
|
|
: _index(index)
|
2017-02-21 13:45:56 +00:00
|
|
|
, _widget(std::forward<Args>(args)...)
|
2016-12-13 17:07:56 +00:00
|
|
|
, _weak(_widget) {
|
|
|
|
}
|
|
|
|
|
|
|
|
object_ptr<StickersBox::Inner> StickersBox::Tab::takeWidget() {
|
2017-02-21 13:45:56 +00:00
|
|
|
return std::move(_widget);
|
2016-12-13 17:07:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void StickersBox::Tab::returnWidget(object_ptr<Inner> widget) {
|
2017-02-21 13:45:56 +00:00
|
|
|
_widget = std::move(widget);
|
2017-08-17 09:06:26 +00:00
|
|
|
Assert(_widget == _weak);
|
2016-12-13 17:07:56 +00:00
|
|
|
}
|
|
|
|
|
2021-03-29 17:37:03 +00:00
|
|
|
StickersBox::Inner *StickersBox::Tab::widget() const {
|
2020-06-08 17:24:36 +00:00
|
|
|
return _weak;
|
|
|
|
}
|
|
|
|
|
|
|
|
int StickersBox::Tab::index() const {
|
|
|
|
return _index;
|
|
|
|
}
|
|
|
|
|
2016-12-13 17:07:56 +00:00
|
|
|
void StickersBox::Tab::saveScrollTop() {
|
|
|
|
_scrollTop = widget()->getVisibleTop();
|
|
|
|
}
|
|
|
|
|
2019-08-06 16:40:08 +00:00
|
|
|
StickersBox::StickersBox(
|
|
|
|
QWidget*,
|
2020-06-23 17:21:58 +00:00
|
|
|
not_null<Window::SessionController*> controller,
|
2021-03-30 14:54:11 +00:00
|
|
|
Section section,
|
|
|
|
bool masks)
|
2020-06-23 17:21:58 +00:00
|
|
|
: _controller(controller)
|
|
|
|
, _api(&controller->session().mtp())
|
2019-08-06 16:40:08 +00:00
|
|
|
, _tabs(this, st::stickersTabs)
|
2020-06-08 17:24:36 +00:00
|
|
|
, _unreadBadge(
|
|
|
|
this,
|
2020-06-23 17:21:58 +00:00
|
|
|
controller->session().data().stickers().featuredSetsUnreadCountValue())
|
2016-10-20 16:32:15 +00:00
|
|
|
, _section(section)
|
2021-03-30 14:54:11 +00:00
|
|
|
, _isMasks(masks)
|
2022-07-27 09:26:22 +00:00
|
|
|
, _isEmoji(false)
|
2021-03-30 14:54:11 +00:00
|
|
|
, _installed(_isMasks ? Tab() : Tab(0, this, controller, Section::Installed))
|
|
|
|
, _masks(_isMasks ? Tab(0, this, controller, Section::Masks) : Tab())
|
|
|
|
, _featured(_isMasks ? Tab() : Tab(1, this, controller, Section::Featured))
|
|
|
|
, _archived((_isMasks ? 1 : 2), this, controller, Section::Archived) {
|
2017-04-08 15:20:12 +00:00
|
|
|
_tabs->setRippleTopRoundRadius(st::boxRadius);
|
2016-10-20 16:32:15 +00:00
|
|
|
}
|
|
|
|
|
2020-06-23 17:21:58 +00:00
|
|
|
StickersBox::StickersBox(
|
|
|
|
QWidget*,
|
|
|
|
not_null<Window::SessionController*> controller,
|
|
|
|
not_null<ChannelData*> megagroup)
|
|
|
|
: _controller(controller)
|
|
|
|
, _api(&controller->session().mtp())
|
2019-08-06 16:40:08 +00:00
|
|
|
, _section(Section::Installed)
|
2021-03-30 14:54:11 +00:00
|
|
|
, _isMasks(false)
|
2022-07-27 09:26:22 +00:00
|
|
|
, _isEmoji(false)
|
2020-06-23 17:21:58 +00:00
|
|
|
, _installed(0, this, controller, megagroup)
|
2017-08-05 10:48:21 +00:00
|
|
|
, _megagroupSet(megagroup) {
|
2021-05-25 10:14:12 +00:00
|
|
|
_installed.widget()->scrollsToY(
|
|
|
|
) | rpl::start_with_next([=](int y) {
|
2022-02-23 01:11:34 +00:00
|
|
|
scrollToY(y);
|
2021-05-25 10:14:12 +00:00
|
|
|
}, lifetime());
|
2017-08-05 10:48:21 +00:00
|
|
|
}
|
|
|
|
|
2019-08-06 16:40:08 +00:00
|
|
|
StickersBox::StickersBox(
|
|
|
|
QWidget*,
|
2020-06-23 17:21:58 +00:00
|
|
|
not_null<Window::SessionController*> controller,
|
2019-08-06 16:40:08 +00:00
|
|
|
const MTPVector<MTPStickerSetCovered> &attachedSets)
|
2020-06-23 17:21:58 +00:00
|
|
|
: _controller(controller)
|
|
|
|
, _api(&controller->session().mtp())
|
2019-08-06 16:40:08 +00:00
|
|
|
, _section(Section::Attached)
|
2021-03-30 14:54:11 +00:00
|
|
|
, _isMasks(false)
|
2022-07-27 09:26:22 +00:00
|
|
|
, _isEmoji(false)
|
2020-06-23 17:21:58 +00:00
|
|
|
, _attached(0, this, controller, Section::Attached)
|
2022-07-18 13:56:14 +00:00
|
|
|
, _attachedType(Data::StickersType::Stickers)
|
2019-03-10 12:55:24 +00:00
|
|
|
, _attachedSets(attachedSets) {
|
|
|
|
}
|
|
|
|
|
2022-07-18 13:56:14 +00:00
|
|
|
StickersBox::StickersBox(
|
|
|
|
QWidget*,
|
|
|
|
not_null<Window::SessionController*> controller,
|
|
|
|
const std::vector<StickerSetIdentifier> &emojiSets)
|
|
|
|
: _controller(controller)
|
|
|
|
, _api(&controller->session().mtp())
|
|
|
|
, _section(Section::Attached)
|
|
|
|
, _isMasks(false)
|
2022-07-27 09:26:22 +00:00
|
|
|
, _isEmoji(true)
|
2022-07-18 13:56:14 +00:00
|
|
|
, _attached(0, this, controller, Section::Attached)
|
|
|
|
, _attachedType(Data::StickersType::Emoji)
|
|
|
|
, _emojiSets(emojiSets) {
|
|
|
|
}
|
|
|
|
|
2020-06-23 17:21:58 +00:00
|
|
|
Main::Session &StickersBox::session() const {
|
|
|
|
return _controller->session();
|
|
|
|
}
|
|
|
|
|
2019-03-10 12:55:24 +00:00
|
|
|
void StickersBox::showAttachedStickers() {
|
2022-07-18 13:56:14 +00:00
|
|
|
const auto stickers = &session().data().stickers();
|
|
|
|
|
2019-03-10 12:55:24 +00:00
|
|
|
auto addedSet = false;
|
2022-07-18 13:56:14 +00:00
|
|
|
const auto add = [&](not_null<StickersSet*> set) {
|
|
|
|
if (_attached.widget()->appendSet(set)) {
|
|
|
|
addedSet = true;
|
|
|
|
if (set->stickers.isEmpty()
|
|
|
|
|| (set->flags & SetFlag::NotLoaded)) {
|
|
|
|
session().api().scheduleStickerSetRequest(
|
|
|
|
set->id,
|
|
|
|
set->accessHash);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
2022-07-19 09:31:12 +00:00
|
|
|
for (const auto &set : _attachedSets.v) {
|
|
|
|
add(stickers->feedSetCovered(set));
|
2022-07-18 13:56:14 +00:00
|
|
|
}
|
|
|
|
for (const auto &setId : _emojiSets) {
|
|
|
|
const auto i = stickers->sets().find(setId.id);
|
|
|
|
if (i != end(stickers->sets())) {
|
|
|
|
add(i->second.get());
|
2019-03-10 12:55:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (addedSet) {
|
|
|
|
_attached.widget()->updateSize();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (_section == Section::Attached && addedSet) {
|
2020-06-23 17:21:58 +00:00
|
|
|
session().api().requestStickerSets();
|
2019-03-10 12:55:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-08 17:24:36 +00:00
|
|
|
void StickersBox::getArchivedDone(
|
2020-06-11 16:09:46 +00:00
|
|
|
const MTPmessages_ArchivedStickers &result,
|
|
|
|
uint64 offsetId) {
|
2016-10-20 16:32:15 +00:00
|
|
|
_archivedRequestId = 0;
|
2016-11-22 09:48:13 +00:00
|
|
|
_archivedLoaded = true;
|
2016-10-20 16:32:15 +00:00
|
|
|
if (result.type() != mtpc_messages_archivedStickers) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto &stickers = result.c_messages_archivedStickers();
|
2021-03-30 15:51:45 +00:00
|
|
|
auto &archived = archivedSetsOrderRef();
|
2016-10-20 16:32:15 +00:00
|
|
|
if (offsetId) {
|
|
|
|
auto index = archived.indexOf(offsetId);
|
|
|
|
if (index >= 0) {
|
|
|
|
archived = archived.mid(0, index + 1);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
archived.clear();
|
|
|
|
}
|
|
|
|
|
2016-12-13 17:07:56 +00:00
|
|
|
auto addedSet = false;
|
|
|
|
auto changedSets = false;
|
2022-07-19 09:31:12 +00:00
|
|
|
for (const auto &data : stickers.vsets().v) {
|
|
|
|
const auto set = session().data().stickers().feedSetCovered(data);
|
|
|
|
const auto index = archived.indexOf(set->id);
|
|
|
|
if (archived.isEmpty() || index != archived.size() - 1) {
|
|
|
|
changedSets = true;
|
|
|
|
if (index >= 0 && index < archived.size() - 1) {
|
|
|
|
archived.removeAt(index);
|
2016-10-20 16:32:15 +00:00
|
|
|
}
|
2022-07-19 09:31:12 +00:00
|
|
|
archived.push_back(set->id);
|
2016-10-20 16:32:15 +00:00
|
|
|
}
|
2022-07-19 09:31:12 +00:00
|
|
|
if (_archived.widget()->appendSet(set)) {
|
|
|
|
addedSet = true;
|
|
|
|
if (set->flags & SetFlag::NotLoaded) {
|
|
|
|
session().api().scheduleStickerSetRequest(
|
|
|
|
set->id,
|
|
|
|
set->accessHash);
|
2016-10-20 16:32:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-11-22 09:48:13 +00:00
|
|
|
if (addedSet) {
|
2016-12-13 17:07:56 +00:00
|
|
|
_archived.widget()->updateSize();
|
2016-11-22 09:48:13 +00:00
|
|
|
} else {
|
2019-07-05 13:38:38 +00:00
|
|
|
_allArchivedLoaded = stickers.vsets().v.isEmpty()
|
2018-03-02 17:17:33 +00:00
|
|
|
|| (!changedSets && offsetId != 0);
|
2016-12-21 15:05:58 +00:00
|
|
|
if (changedSets) {
|
2016-12-13 17:07:56 +00:00
|
|
|
loadMoreArchived();
|
|
|
|
}
|
2016-11-22 09:48:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
refreshTabs();
|
|
|
|
_someArchivedLoaded = true;
|
|
|
|
if (_section == Section::Archived && addedSet) {
|
2020-06-23 17:21:58 +00:00
|
|
|
session().api().requestStickerSets();
|
2016-10-20 16:32:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-13 17:07:56 +00:00
|
|
|
void StickersBox::prepare() {
|
2016-10-20 16:32:15 +00:00
|
|
|
if (_section == Section::Installed) {
|
2017-08-05 10:48:21 +00:00
|
|
|
if (_tabs) {
|
2021-03-30 15:51:45 +00:00
|
|
|
if (_isMasks) {
|
|
|
|
session().local().readArchivedMasks();
|
|
|
|
} else {
|
|
|
|
session().local().readArchivedStickers();
|
|
|
|
}
|
2017-08-05 10:48:21 +00:00
|
|
|
} else {
|
2019-06-18 15:00:55 +00:00
|
|
|
setTitle(tr::lng_stickers_group_set());
|
2017-08-05 10:48:21 +00:00
|
|
|
}
|
2016-10-20 16:32:15 +00:00
|
|
|
} else if (_section == Section::Archived) {
|
2016-11-22 09:48:13 +00:00
|
|
|
requestArchivedSets();
|
2019-03-10 12:55:24 +00:00
|
|
|
} else if (_section == Section::Attached) {
|
2022-07-18 13:56:14 +00:00
|
|
|
setTitle(_attachedType == Data::StickersType::Emoji
|
|
|
|
? tr::lng_custom_emoji_used_sets()
|
|
|
|
: tr::lng_stickers_attached_sets());
|
2016-10-20 16:32:15 +00:00
|
|
|
}
|
2016-11-22 09:48:13 +00:00
|
|
|
if (_tabs) {
|
2021-03-30 15:51:45 +00:00
|
|
|
if (archivedSetsOrder().isEmpty()) {
|
2017-08-05 10:48:21 +00:00
|
|
|
preloadArchivedSets();
|
|
|
|
}
|
2016-12-13 17:07:56 +00:00
|
|
|
setNoContentMargin(true);
|
2017-12-22 07:05:20 +00:00
|
|
|
_tabs->sectionActivated(
|
2021-12-31 13:50:43 +00:00
|
|
|
) | rpl::filter([=] {
|
|
|
|
return !_ignoreTabActivation;
|
|
|
|
}) | rpl::start_with_next(
|
2017-12-22 07:05:20 +00:00
|
|
|
[this] { switchTab(); },
|
|
|
|
lifetime());
|
2016-11-22 09:48:13 +00:00
|
|
|
refreshTabs();
|
|
|
|
}
|
2021-03-29 17:37:03 +00:00
|
|
|
if (_installed.widget() && _section != Section::Installed) {
|
|
|
|
_installed.widget()->hide();
|
|
|
|
}
|
|
|
|
if (_masks.widget() && _section != Section::Masks) {
|
|
|
|
_masks.widget()->hide();
|
|
|
|
}
|
|
|
|
if (_featured.widget() && _section != Section::Featured) {
|
|
|
|
_featured.widget()->hide();
|
|
|
|
}
|
|
|
|
if (_archived.widget() && _section != Section::Archived) {
|
|
|
|
_archived.widget()->hide();
|
|
|
|
}
|
|
|
|
if (_attached.widget() && _section != Section::Attached) {
|
|
|
|
_attached.widget()->hide();
|
|
|
|
}
|
2016-10-20 16:32:15 +00:00
|
|
|
|
2021-03-29 17:37:03 +00:00
|
|
|
const auto installCallback = [=](uint64 setId) { installSet(setId); };
|
2016-12-13 17:07:56 +00:00
|
|
|
if (_featured.widget()) {
|
2021-03-29 17:37:03 +00:00
|
|
|
_featured.widget()->setInstallSetCallback(installCallback);
|
2016-11-22 09:48:13 +00:00
|
|
|
}
|
2017-08-05 10:48:21 +00:00
|
|
|
if (_archived.widget()) {
|
2021-03-29 17:37:03 +00:00
|
|
|
_archived.widget()->setInstallSetCallback(installCallback);
|
|
|
|
_archived.widget()->setLoadMoreCallback([=] { loadMoreArchived(); });
|
2017-08-05 10:48:21 +00:00
|
|
|
}
|
2019-03-10 12:55:24 +00:00
|
|
|
if (_attached.widget()) {
|
2021-03-29 17:37:03 +00:00
|
|
|
_attached.widget()->setInstallSetCallback(installCallback);
|
|
|
|
_attached.widget()->setLoadMoreCallback([=] { showAttachedStickers(); });
|
2019-03-10 12:55:24 +00:00
|
|
|
}
|
2016-10-20 16:32:15 +00:00
|
|
|
|
2017-08-05 20:01:20 +00:00
|
|
|
if (_megagroupSet) {
|
2019-06-18 16:53:27 +00:00
|
|
|
addButton(
|
|
|
|
tr::lng_settings_save(),
|
|
|
|
[=] { _installed.widget()->saveGroupSet(); closeBox(); });
|
|
|
|
addButton(tr::lng_cancel(), [=] { closeBox(); });
|
2017-08-05 20:01:20 +00:00
|
|
|
} else {
|
2019-03-10 12:55:24 +00:00
|
|
|
const auto close = _section == Section::Attached;
|
2019-06-18 16:53:27 +00:00
|
|
|
addButton(
|
|
|
|
close ? tr::lng_close() : tr::lng_about_done(),
|
|
|
|
[=] { closeBox(); });
|
2017-08-05 20:01:20 +00:00
|
|
|
}
|
2016-10-20 16:32:15 +00:00
|
|
|
|
2016-11-22 09:48:13 +00:00
|
|
|
if (_section == Section::Installed) {
|
|
|
|
_tab = &_installed;
|
2021-03-29 17:37:03 +00:00
|
|
|
} else if (_section == Section::Masks) {
|
|
|
|
_tab = &_masks;
|
2016-10-20 16:32:15 +00:00
|
|
|
} else if (_section == Section::Archived) {
|
2016-11-22 09:48:13 +00:00
|
|
|
_tab = &_archived;
|
2019-03-10 12:55:24 +00:00
|
|
|
} else if (_section == Section::Attached) {
|
|
|
|
_tab = &_attached;
|
2016-11-22 09:48:13 +00:00
|
|
|
} else { // _section == Section::Featured
|
|
|
|
_tab = &_featured;
|
2016-10-20 16:32:15 +00:00
|
|
|
}
|
2016-12-13 17:07:56 +00:00
|
|
|
setInnerWidget(_tab->takeWidget(), getTopSkip());
|
2017-09-09 09:04:20 +00:00
|
|
|
setDimensions(st::boxWideWidth, st::boxMaxListHeight);
|
2016-10-20 16:32:15 +00:00
|
|
|
|
2022-07-27 09:26:22 +00:00
|
|
|
session().data().stickers().updated(_isEmoji
|
|
|
|
? Data::StickersType::Emoji
|
|
|
|
: _isMasks
|
|
|
|
? Data::StickersType::Masks
|
|
|
|
: Data::StickersType::Stickers
|
2022-07-26 14:45:41 +00:00
|
|
|
) | rpl::start_with_next([=] {
|
|
|
|
handleStickersUpdated();
|
|
|
|
}, lifetime());
|
2022-07-27 09:26:22 +00:00
|
|
|
|
|
|
|
if (_isEmoji) {
|
|
|
|
session().api().updateCustomEmoji();
|
|
|
|
} else if (_isMasks) {
|
|
|
|
session().api().updateMasks();
|
|
|
|
} else {
|
|
|
|
session().api().updateStickers();
|
|
|
|
}
|
2021-03-29 17:37:03 +00:00
|
|
|
|
|
|
|
for (const auto &widget : { _installed.widget(), _masks.widget() }) {
|
|
|
|
if (widget) {
|
|
|
|
widget->draggingScrollDelta(
|
|
|
|
) | rpl::start_with_next([=](int delta) {
|
|
|
|
scrollByDraggingDelta(delta);
|
|
|
|
}, widget->lifetime());
|
2017-08-13 16:09:14 +00:00
|
|
|
}
|
2016-11-22 09:48:13 +00:00
|
|
|
}
|
2021-03-29 17:37:03 +00:00
|
|
|
if (!_megagroupSet) {
|
|
|
|
boxClosing() | rpl::start_with_next([=] {
|
|
|
|
saveChanges();
|
|
|
|
}, lifetime());
|
|
|
|
}
|
2016-10-20 16:32:15 +00:00
|
|
|
|
2016-12-13 17:07:56 +00:00
|
|
|
if (_tabs) {
|
|
|
|
_tabs->raise();
|
2016-12-31 13:34:41 +00:00
|
|
|
_unreadBadge->raise();
|
2016-12-13 17:07:56 +00:00
|
|
|
}
|
2016-10-20 16:32:15 +00:00
|
|
|
rebuildList();
|
|
|
|
}
|
|
|
|
|
2016-11-22 09:48:13 +00:00
|
|
|
void StickersBox::refreshTabs() {
|
2021-03-30 14:54:11 +00:00
|
|
|
if (!_tabs) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto &stickers = session().data().stickers();
|
2016-11-22 09:48:13 +00:00
|
|
|
|
|
|
|
_tabIndices.clear();
|
2021-03-15 10:51:13 +00:00
|
|
|
auto sections = std::vector<QString>();
|
2021-03-30 14:54:11 +00:00
|
|
|
if (_installed.widget()) {
|
|
|
|
sections.push_back(tr::lng_stickers_installed_tab(tr::now).toUpper());
|
|
|
|
_tabIndices.push_back(Section::Installed);
|
|
|
|
}
|
2021-03-31 00:26:32 +00:00
|
|
|
if (_masks.widget()) {
|
2021-03-29 17:37:03 +00:00
|
|
|
sections.push_back(tr::lng_stickers_masks_tab(tr::now).toUpper());
|
|
|
|
_tabIndices.push_back(Section::Masks);
|
|
|
|
}
|
2021-03-30 14:54:11 +00:00
|
|
|
if (!stickers.featuredSetsOrder().isEmpty() && _featured.widget()) {
|
2019-06-19 15:09:03 +00:00
|
|
|
sections.push_back(tr::lng_stickers_featured_tab(tr::now).toUpper());
|
2016-11-22 09:48:13 +00:00
|
|
|
_tabIndices.push_back(Section::Featured);
|
|
|
|
}
|
2021-03-30 15:51:45 +00:00
|
|
|
if (!archivedSetsOrder().isEmpty() && _archived.widget()) {
|
2019-06-19 15:09:03 +00:00
|
|
|
sections.push_back(tr::lng_stickers_archived_tab(tr::now).toUpper());
|
2016-11-22 09:48:13 +00:00
|
|
|
_tabIndices.push_back(Section::Archived);
|
|
|
|
}
|
|
|
|
_tabs->setSections(sections);
|
|
|
|
if ((_tab == &_archived && !_tabIndices.contains(Section::Archived))
|
2021-03-29 17:37:03 +00:00
|
|
|
|| (_tab == &_featured && !_tabIndices.contains(Section::Featured))
|
|
|
|
|| (_tab == &_masks && !_tabIndices.contains(Section::Masks))) {
|
2016-11-22 09:48:13 +00:00
|
|
|
switchTab();
|
2021-12-31 13:50:43 +00:00
|
|
|
} else {
|
|
|
|
_ignoreTabActivation = true;
|
|
|
|
_tabs->setActiveSectionFast(_tabIndices.indexOf((_tab == &_archived)
|
|
|
|
? Section::Archived
|
|
|
|
: (_tab == &_featured)
|
|
|
|
? Section::Featured
|
|
|
|
: (_tab == &_masks)
|
|
|
|
? Section::Masks
|
|
|
|
: Section::Installed));
|
|
|
|
_ignoreTabActivation = false;
|
2016-11-22 09:48:13 +00:00
|
|
|
}
|
|
|
|
updateTabsGeometry();
|
2016-10-20 16:32:15 +00:00
|
|
|
}
|
|
|
|
|
2016-12-13 17:07:56 +00:00
|
|
|
void StickersBox::loadMoreArchived() {
|
2020-06-08 17:24:36 +00:00
|
|
|
if (_section != Section::Archived
|
|
|
|
|| _allArchivedLoaded
|
|
|
|
|| _archivedRequestId) {
|
2016-12-13 17:07:56 +00:00
|
|
|
return;
|
|
|
|
}
|
2016-10-20 16:32:15 +00:00
|
|
|
|
2016-12-13 17:07:56 +00:00
|
|
|
uint64 lastId = 0;
|
2021-03-30 15:51:45 +00:00
|
|
|
const auto &order = archivedSetsOrder();
|
2020-06-23 17:21:58 +00:00
|
|
|
const auto &sets = session().data().stickers().sets();
|
2020-05-28 10:00:51 +00:00
|
|
|
for (auto setIt = order.cend(), e = order.cbegin(); setIt != e;) {
|
2016-12-13 17:07:56 +00:00
|
|
|
--setIt;
|
2020-05-28 10:00:51 +00:00
|
|
|
auto it = sets.find(*setIt);
|
|
|
|
if (it != sets.cend()) {
|
2021-07-09 06:08:58 +00:00
|
|
|
if (it->second->flags & SetFlag::Archived) {
|
2020-05-28 10:00:51 +00:00
|
|
|
lastId = it->second->id;
|
2016-12-13 17:07:56 +00:00
|
|
|
break;
|
2016-10-20 16:32:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-03-30 15:51:45 +00:00
|
|
|
const auto flags = _isMasks
|
|
|
|
? MTPmessages_GetArchivedStickers::Flag::f_masks
|
|
|
|
: MTPmessages_GetArchivedStickers::Flags(0);
|
2020-06-11 16:09:46 +00:00
|
|
|
_archivedRequestId = _api.request(MTPmessages_GetArchivedStickers(
|
2021-03-30 15:51:45 +00:00
|
|
|
MTP_flags(flags),
|
2020-06-11 16:09:46 +00:00
|
|
|
MTP_long(lastId),
|
|
|
|
MTP_int(kArchivedLimitPerPage)
|
|
|
|
)).done([=](const MTPmessages_ArchivedStickers &result) {
|
|
|
|
getArchivedDone(result, lastId);
|
|
|
|
}).send();
|
2016-10-20 16:32:15 +00:00
|
|
|
}
|
|
|
|
|
2016-11-22 09:48:13 +00:00
|
|
|
void StickersBox::paintEvent(QPaintEvent *e) {
|
2016-12-13 17:07:56 +00:00
|
|
|
BoxContent::paintEvent(e);
|
2016-11-22 09:48:13 +00:00
|
|
|
|
|
|
|
Painter p(this);
|
|
|
|
|
2016-11-24 19:28:23 +00:00
|
|
|
if (_slideAnimation) {
|
2019-04-02 09:13:30 +00:00
|
|
|
_slideAnimation->paintFrame(p, 0, getTopSkip(), width());
|
2016-11-24 19:28:23 +00:00
|
|
|
if (!_slideAnimation->animating()) {
|
|
|
|
_slideAnimation.reset();
|
2016-12-13 17:07:56 +00:00
|
|
|
setInnerVisible(true);
|
2016-11-22 09:48:13 +00:00
|
|
|
update();
|
|
|
|
}
|
2016-10-20 16:32:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-22 09:48:13 +00:00
|
|
|
void StickersBox::updateTabsGeometry() {
|
|
|
|
if (!_tabs) return;
|
|
|
|
|
2021-03-30 14:54:11 +00:00
|
|
|
const auto maxTabs = _isMasks ? 2 : 3;
|
2021-03-29 17:37:03 +00:00
|
|
|
|
|
|
|
_tabs->resizeToWidth(_tabIndices.size() * width() / maxTabs);
|
2016-11-22 09:48:13 +00:00
|
|
|
_unreadBadge->setVisible(_tabIndices.contains(Section::Featured));
|
|
|
|
|
2016-12-13 17:07:56 +00:00
|
|
|
setInnerTopSkip(getTopSkip());
|
|
|
|
|
2021-03-29 17:37:03 +00:00
|
|
|
auto featuredLeft = width() / maxTabs;
|
|
|
|
auto featuredRight = 2 * width() / maxTabs;
|
2019-12-14 14:46:31 +00:00
|
|
|
auto featuredTextWidth = st::stickersTabs.labelStyle.font->width(tr::lng_stickers_featured_tab(tr::now).toUpper());
|
2016-11-22 09:48:13 +00:00
|
|
|
auto featuredTextRight = featuredLeft + (featuredRight - featuredLeft - featuredTextWidth) / 2 + featuredTextWidth;
|
|
|
|
auto unreadBadgeLeft = featuredTextRight - st::stickersFeaturedBadgeSkip;
|
|
|
|
auto unreadBadgeTop = st::stickersFeaturedBadgeTop;
|
|
|
|
if (unreadBadgeLeft + _unreadBadge->width() > featuredRight) {
|
|
|
|
unreadBadgeLeft = featuredRight - _unreadBadge->width();
|
2016-10-20 16:32:15 +00:00
|
|
|
}
|
2016-11-22 09:48:13 +00:00
|
|
|
_unreadBadge->moveToLeft(unreadBadgeLeft, unreadBadgeTop);
|
|
|
|
|
|
|
|
_tabs->moveToLeft(0, 0);
|
2016-10-20 16:32:15 +00:00
|
|
|
}
|
|
|
|
|
2016-12-13 17:07:56 +00:00
|
|
|
int StickersBox::getTopSkip() const {
|
2017-09-09 09:04:20 +00:00
|
|
|
return _tabs ? (_tabs->height() - st::lineWidth) : 0;
|
2016-12-13 17:07:56 +00:00
|
|
|
}
|
|
|
|
|
2016-11-22 09:48:13 +00:00
|
|
|
void StickersBox::switchTab() {
|
|
|
|
if (!_tabs) return;
|
2016-10-20 16:32:15 +00:00
|
|
|
|
2016-11-22 09:48:13 +00:00
|
|
|
auto tab = _tabs->activeSection();
|
2017-08-17 09:06:26 +00:00
|
|
|
Assert(tab >= 0 && tab < _tabIndices.size());
|
2016-11-22 09:48:13 +00:00
|
|
|
auto newSection = _tabIndices[tab];
|
|
|
|
|
|
|
|
auto newTab = _tab;
|
|
|
|
if (newSection == Section::Installed) {
|
|
|
|
newTab = &_installed;
|
|
|
|
} else if (newSection == Section::Featured) {
|
|
|
|
newTab = &_featured;
|
|
|
|
} else if (newSection == Section::Archived) {
|
|
|
|
newTab = &_archived;
|
|
|
|
requestArchivedSets();
|
2021-03-29 17:37:03 +00:00
|
|
|
} else if (newSection == Section::Masks) {
|
|
|
|
newTab = &_masks;
|
|
|
|
session().api().updateMasks();
|
2016-11-22 09:48:13 +00:00
|
|
|
}
|
2017-03-28 12:30:38 +00:00
|
|
|
if (_tab == newTab) {
|
2022-02-23 01:11:34 +00:00
|
|
|
scrollToY(0);
|
2017-03-28 12:30:38 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (_tab == &_installed) {
|
|
|
|
_localOrder = _tab->widget()->getFullOrder();
|
|
|
|
_localRemoved = _tab->widget()->getRemovedSets();
|
2016-10-20 16:32:15 +00:00
|
|
|
}
|
2017-03-28 12:30:38 +00:00
|
|
|
auto wasCache = grabContentCache();
|
|
|
|
auto wasIndex = _tab->index();
|
|
|
|
_tab->saveScrollTop();
|
|
|
|
auto widget = takeInnerWidget<Inner>();
|
|
|
|
widget->setParent(this);
|
|
|
|
widget->hide();
|
|
|
|
_tab->returnWidget(std::move(widget));
|
|
|
|
_tab = newTab;
|
|
|
|
_section = newSection;
|
|
|
|
setInnerWidget(_tab->takeWidget(), getTopSkip());
|
|
|
|
_tabs->raise();
|
|
|
|
_unreadBadge->raise();
|
|
|
|
_tab->widget()->show();
|
|
|
|
rebuildList();
|
2022-02-23 01:11:34 +00:00
|
|
|
scrollToY(_tab->getScrollTop());
|
2017-04-11 14:02:11 +00:00
|
|
|
setInnerVisible(true);
|
2017-03-28 12:30:38 +00:00
|
|
|
auto nowCache = grabContentCache();
|
|
|
|
auto nowIndex = _tab->index();
|
|
|
|
|
|
|
|
_slideAnimation = std::make_unique<Ui::SlideAnimation>();
|
|
|
|
_slideAnimation->setSnapshots(std::move(wasCache), std::move(nowCache));
|
|
|
|
auto slideLeft = wasIndex > nowIndex;
|
2021-03-29 17:37:03 +00:00
|
|
|
_slideAnimation->start(slideLeft, [=] { update(); }, st::slideDuration);
|
2017-03-28 12:30:38 +00:00
|
|
|
setInnerVisible(false);
|
|
|
|
|
|
|
|
setFocus();
|
|
|
|
update();
|
2016-10-20 16:32:15 +00:00
|
|
|
}
|
|
|
|
|
2016-11-22 09:48:13 +00:00
|
|
|
QPixmap StickersBox::grabContentCache() {
|
|
|
|
_tabs->hide();
|
2016-12-13 17:07:56 +00:00
|
|
|
auto result = grabInnerCache();
|
2016-11-22 09:48:13 +00:00
|
|
|
_tabs->show();
|
2017-02-21 14:37:53 +00:00
|
|
|
return result;
|
2016-10-20 16:32:15 +00:00
|
|
|
}
|
|
|
|
|
2021-03-29 17:37:03 +00:00
|
|
|
std::array<StickersBox::Inner*, 5> StickersBox::widgets() const {
|
|
|
|
return {
|
|
|
|
_installed.widget(),
|
|
|
|
_featured.widget(),
|
|
|
|
_archived.widget(),
|
|
|
|
_attached.widget(),
|
|
|
|
_masks.widget()
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2016-11-22 09:48:13 +00:00
|
|
|
void StickersBox::installSet(uint64 setId) {
|
2020-06-23 17:21:58 +00:00
|
|
|
const auto &sets = session().data().stickers().sets();
|
2020-05-31 08:18:24 +00:00
|
|
|
const auto it = sets.find(setId);
|
2016-11-22 09:48:13 +00:00
|
|
|
if (it == sets.cend()) {
|
|
|
|
rebuildList();
|
|
|
|
return;
|
|
|
|
}
|
2016-10-20 16:32:15 +00:00
|
|
|
|
2020-05-28 10:00:51 +00:00
|
|
|
const auto set = it->second.get();
|
2016-11-22 09:48:13 +00:00
|
|
|
if (_localRemoved.contains(setId)) {
|
|
|
|
_localRemoved.removeOne(setId);
|
2021-03-29 17:37:03 +00:00
|
|
|
for (const auto &widget : widgets()) {
|
|
|
|
if (widget) {
|
|
|
|
widget->setRemovedSets(_localRemoved);
|
|
|
|
}
|
|
|
|
}
|
2016-11-22 09:48:13 +00:00
|
|
|
}
|
2021-07-09 06:08:58 +00:00
|
|
|
if (!(set->flags & SetFlag::Installed)
|
|
|
|
|| (set->flags & SetFlag::Archived)) {
|
2020-06-11 16:09:46 +00:00
|
|
|
_api.request(MTPmessages_InstallStickerSet(
|
|
|
|
set->mtpInput(),
|
|
|
|
MTP_boolFalse()
|
|
|
|
)).done([=](const MTPmessages_StickerSetInstallResult &result) {
|
|
|
|
installDone(result);
|
2021-03-12 12:48:00 +00:00
|
|
|
}).fail([=](const MTP::Error &error) {
|
2020-06-11 16:09:46 +00:00
|
|
|
installFail(error, setId);
|
|
|
|
}).send();
|
2016-11-19 14:47:28 +00:00
|
|
|
|
2020-06-23 17:21:58 +00:00
|
|
|
session().data().stickers().installLocally(setId);
|
2016-11-22 09:48:13 +00:00
|
|
|
}
|
|
|
|
}
|
2016-10-20 16:32:15 +00:00
|
|
|
|
2022-07-26 14:45:41 +00:00
|
|
|
void StickersBox::installDone(
|
|
|
|
const MTPmessages_StickerSetInstallResult &result) {
|
2016-11-22 09:48:13 +00:00
|
|
|
if (result.type() == mtpc_messages_stickerSetInstallResultArchive) {
|
2020-06-23 17:21:58 +00:00
|
|
|
session().data().stickers().applyArchivedResult(
|
2018-01-25 12:28:48 +00:00
|
|
|
result.c_messages_stickerSetInstallResultArchive());
|
2016-11-22 09:48:13 +00:00
|
|
|
}
|
|
|
|
}
|
2016-10-20 16:32:15 +00:00
|
|
|
|
2021-03-12 12:48:00 +00:00
|
|
|
void StickersBox::installFail(const MTP::Error &error, uint64 setId) {
|
2020-06-23 17:21:58 +00:00
|
|
|
const auto &sets = session().data().stickers().sets();
|
2020-05-31 08:18:24 +00:00
|
|
|
const auto it = sets.find(setId);
|
2016-11-22 09:48:13 +00:00
|
|
|
if (it == sets.cend()) {
|
|
|
|
rebuildList();
|
2020-06-11 16:09:46 +00:00
|
|
|
} else {
|
2020-06-23 17:21:58 +00:00
|
|
|
session().data().stickers().undoInstallLocally(setId);
|
2016-10-20 16:32:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-22 09:48:13 +00:00
|
|
|
void StickersBox::preloadArchivedSets() {
|
2020-06-11 16:09:46 +00:00
|
|
|
if (!_tabs) {
|
|
|
|
return;
|
|
|
|
}
|
2016-11-22 09:48:13 +00:00
|
|
|
if (!_archivedRequestId) {
|
2021-03-30 15:51:45 +00:00
|
|
|
const auto flags = _isMasks
|
|
|
|
? MTPmessages_GetArchivedStickers::Flag::f_masks
|
|
|
|
: MTPmessages_GetArchivedStickers::Flags(0);
|
2020-06-11 16:09:46 +00:00
|
|
|
_archivedRequestId = _api.request(MTPmessages_GetArchivedStickers(
|
2021-03-30 15:51:45 +00:00
|
|
|
MTP_flags(flags),
|
2020-06-11 16:09:46 +00:00
|
|
|
MTP_long(0),
|
|
|
|
MTP_int(kArchivedLimitFirstRequest)
|
|
|
|
)).done([=](const MTPmessages_ArchivedStickers &result) {
|
|
|
|
getArchivedDone(result, 0);
|
|
|
|
}).send();
|
2016-10-20 16:32:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-22 09:48:13 +00:00
|
|
|
void StickersBox::requestArchivedSets() {
|
|
|
|
// Reload the archived list.
|
|
|
|
if (!_archivedLoaded) {
|
|
|
|
preloadArchivedSets();
|
2016-10-20 16:32:15 +00:00
|
|
|
}
|
2016-11-22 09:48:13 +00:00
|
|
|
|
2020-06-23 17:21:58 +00:00
|
|
|
const auto &sets = session().data().stickers().sets();
|
2021-03-30 15:51:45 +00:00
|
|
|
const auto &order = archivedSetsOrder();
|
2020-05-28 10:00:51 +00:00
|
|
|
for (const auto setId : order) {
|
|
|
|
auto it = sets.find(setId);
|
2016-11-22 09:48:13 +00:00
|
|
|
if (it != sets.cend()) {
|
2020-05-28 10:00:51 +00:00
|
|
|
const auto set = it->second.get();
|
2021-07-09 06:08:58 +00:00
|
|
|
if (set->stickers.isEmpty()
|
|
|
|
&& (set->flags & SetFlag::NotLoaded)) {
|
2021-08-25 08:15:05 +00:00
|
|
|
session().api().scheduleStickerSetRequest(
|
|
|
|
setId,
|
|
|
|
set->accessHash);
|
2016-11-22 09:48:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-06-23 17:21:58 +00:00
|
|
|
session().api().requestStickerSets();
|
2016-10-20 16:32:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void StickersBox::resizeEvent(QResizeEvent *e) {
|
2016-12-13 17:07:56 +00:00
|
|
|
BoxContent::resizeEvent(e);
|
|
|
|
|
2016-11-22 09:48:13 +00:00
|
|
|
if (_tabs) {
|
|
|
|
updateTabsGeometry();
|
2016-10-20 16:32:15 +00:00
|
|
|
}
|
2016-12-13 17:07:56 +00:00
|
|
|
if (_titleShadow) {
|
|
|
|
_titleShadow->setGeometry(0, 0, width(), st::lineWidth);
|
2016-10-20 16:32:15 +00:00
|
|
|
}
|
2021-03-29 17:37:03 +00:00
|
|
|
for (const auto &widget : widgets()) {
|
|
|
|
if (widget) {
|
|
|
|
widget->resize(width(), widget->height());
|
|
|
|
}
|
|
|
|
}
|
2016-10-20 16:32:15 +00:00
|
|
|
}
|
|
|
|
|
2017-08-05 10:48:21 +00:00
|
|
|
void StickersBox::handleStickersUpdated() {
|
2021-03-29 17:37:03 +00:00
|
|
|
if (_section == Section::Installed
|
|
|
|
|| _section == Section::Featured
|
|
|
|
|| _section == Section::Masks) {
|
2016-10-20 16:32:15 +00:00
|
|
|
rebuildList();
|
|
|
|
} else {
|
2016-12-13 17:07:56 +00:00
|
|
|
_tab->widget()->updateRows();
|
2016-11-22 09:48:13 +00:00
|
|
|
}
|
2021-03-30 15:51:45 +00:00
|
|
|
if (archivedSetsOrder().isEmpty()) {
|
2016-11-22 09:48:13 +00:00
|
|
|
preloadArchivedSets();
|
|
|
|
} else {
|
|
|
|
refreshTabs();
|
2016-10-20 16:32:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-22 13:30:27 +00:00
|
|
|
void StickersBox::rebuildList(Tab *tab) {
|
2021-03-29 17:37:03 +00:00
|
|
|
if (_section == Section::Attached) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (!tab) {
|
|
|
|
tab = _tab;
|
|
|
|
}
|
2016-12-22 13:30:27 +00:00
|
|
|
|
2021-03-29 17:37:03 +00:00
|
|
|
if ((tab == &_installed) || (tab == &_masks)) {
|
2016-12-22 13:30:27 +00:00
|
|
|
_localOrder = tab->widget()->getFullOrder();
|
|
|
|
_localRemoved = tab->widget()->getRemovedSets();
|
2016-11-22 09:48:13 +00:00
|
|
|
}
|
2021-03-30 15:51:45 +00:00
|
|
|
tab->widget()->rebuild(_isMasks);
|
2021-03-29 17:37:03 +00:00
|
|
|
if ((tab == &_installed) || (tab == &_masks)) {
|
2016-12-22 13:30:27 +00:00
|
|
|
tab->widget()->setFullOrder(_localOrder);
|
2016-10-20 16:32:15 +00:00
|
|
|
}
|
2016-12-22 13:30:27 +00:00
|
|
|
tab->widget()->setRemovedSets(_localRemoved);
|
2016-10-20 16:32:15 +00:00
|
|
|
}
|
|
|
|
|
2017-08-13 16:09:14 +00:00
|
|
|
void StickersBox::saveChanges() {
|
2021-03-30 14:54:11 +00:00
|
|
|
const auto installed = _installed.widget();
|
|
|
|
const auto masks = _masks.widget();
|
|
|
|
|
2016-12-22 13:30:27 +00:00
|
|
|
// Make sure that our changes in other tabs are applied in the Installed tab.
|
2021-03-30 14:54:11 +00:00
|
|
|
if (installed) {
|
|
|
|
rebuildList(&_installed);
|
|
|
|
}
|
|
|
|
if (masks) {
|
|
|
|
rebuildList(&_masks);
|
|
|
|
}
|
2016-12-22 13:30:27 +00:00
|
|
|
|
2016-11-22 09:48:13 +00:00
|
|
|
if (_someArchivedLoaded) {
|
2021-03-30 15:51:45 +00:00
|
|
|
if (_isMasks) {
|
|
|
|
session().local().writeArchivedMasks();
|
|
|
|
} else {
|
|
|
|
session().local().writeArchivedStickers();
|
|
|
|
}
|
2016-10-20 16:32:15 +00:00
|
|
|
}
|
2021-03-30 14:54:11 +00:00
|
|
|
if (installed) {
|
2021-03-29 17:37:03 +00:00
|
|
|
session().api().saveStickerSets(
|
2021-03-30 14:54:11 +00:00
|
|
|
installed->getOrder(),
|
|
|
|
installed->getRemovedSets(),
|
2022-07-08 18:07:14 +00:00
|
|
|
Data::StickersType::Stickers);
|
2021-03-29 17:37:03 +00:00
|
|
|
}
|
2021-03-30 14:54:11 +00:00
|
|
|
if (masks) {
|
2021-03-29 17:37:03 +00:00
|
|
|
session().api().saveStickerSets(
|
2021-03-30 14:54:11 +00:00
|
|
|
masks->getOrder(),
|
|
|
|
masks->getRemovedSets(),
|
2022-07-08 18:07:14 +00:00
|
|
|
Data::StickersType::Masks);
|
2021-03-29 17:37:03 +00:00
|
|
|
}
|
2016-10-20 16:32:15 +00:00
|
|
|
}
|
|
|
|
|
2017-08-05 20:01:20 +00:00
|
|
|
void StickersBox::setInnerFocus() {
|
|
|
|
if (_megagroupSet) {
|
|
|
|
_installed.widget()->setInnerFocus();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-03-30 15:51:45 +00:00
|
|
|
const Data::StickersSetsOrder &StickersBox::archivedSetsOrder() const {
|
|
|
|
return !_isMasks
|
|
|
|
? session().data().stickers().archivedSetsOrder()
|
|
|
|
: session().data().stickers().archivedMaskSetsOrder();
|
|
|
|
}
|
|
|
|
|
|
|
|
Data::StickersSetsOrder &StickersBox::archivedSetsOrderRef() {
|
|
|
|
return !_isMasks
|
|
|
|
? session().data().stickers().archivedSetsOrderRef()
|
|
|
|
: session().data().stickers().archivedMaskSetsOrderRef();
|
|
|
|
}
|
|
|
|
|
2016-11-24 19:28:23 +00:00
|
|
|
StickersBox::~StickersBox() = default;
|
|
|
|
|
2018-07-13 21:25:47 +00:00
|
|
|
StickersBox::Inner::Row::Row(
|
2020-06-08 17:24:36 +00:00
|
|
|
not_null<StickersSet*> set,
|
2018-07-13 21:25:47 +00:00
|
|
|
DocumentData *sticker,
|
|
|
|
int32 count,
|
|
|
|
const QString &title,
|
|
|
|
int titleWidth,
|
2022-01-24 12:33:31 +00:00
|
|
|
Data::StickersSetFlags flagsOverride,
|
2018-07-13 21:25:47 +00:00
|
|
|
bool removed,
|
|
|
|
int32 pixw,
|
|
|
|
int32 pixh)
|
2020-05-28 11:58:50 +00:00
|
|
|
: set(set)
|
2017-08-05 20:01:20 +00:00
|
|
|
, sticker(sticker)
|
|
|
|
, count(count)
|
|
|
|
, title(title)
|
|
|
|
, titleWidth(titleWidth)
|
2022-01-24 12:33:31 +00:00
|
|
|
, flagsOverride(flagsOverride)
|
2017-08-05 20:01:20 +00:00
|
|
|
, removed(removed)
|
|
|
|
, pixw(pixw)
|
|
|
|
, pixh(pixh) {
|
2022-07-27 09:26:22 +00:00
|
|
|
++set->locked;
|
2017-08-05 20:01:20 +00:00
|
|
|
}
|
|
|
|
|
2022-07-27 09:26:22 +00:00
|
|
|
StickersBox::Inner::Row::~Row() {
|
|
|
|
if (!--set->locked) {
|
|
|
|
const auto installed = !!(set->flags & SetFlag::Installed);
|
|
|
|
const auto featured = !!(set->flags & SetFlag::Featured);
|
|
|
|
const auto special = !!(set->flags & SetFlag::Special);
|
|
|
|
const auto archived = !!(set->flags & SetFlag::Archived);
|
|
|
|
if (!installed && !featured && !special && !archived) {
|
|
|
|
auto &sets = set->owner().stickers().setsRef();
|
|
|
|
if (const auto i = sets.find(set->id); i != end(sets)) {
|
|
|
|
sets.erase(i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-08-05 20:01:20 +00:00
|
|
|
|
2020-05-28 10:00:51 +00:00
|
|
|
bool StickersBox::Inner::Row::isRecentSet() const {
|
2021-03-29 17:37:03 +00:00
|
|
|
return (set->id == Data::Stickers::CloudRecentSetId)
|
|
|
|
|| (set->id == Data::Stickers::CloudRecentAttachedSetId);
|
2020-05-28 10:00:51 +00:00
|
|
|
}
|
|
|
|
|
2021-03-29 23:00:04 +00:00
|
|
|
bool StickersBox::Inner::Row::isMasksSet() const {
|
2022-07-22 16:00:06 +00:00
|
|
|
return (set->type() == Data::StickersType::Masks);
|
2021-03-29 23:00:04 +00:00
|
|
|
}
|
|
|
|
|
2022-07-18 13:56:14 +00:00
|
|
|
bool StickersBox::Inner::Row::isEmojiSet() const {
|
2022-07-22 16:00:06 +00:00
|
|
|
return (set->type() == Data::StickersType::Emoji);
|
2022-07-18 13:56:14 +00:00
|
|
|
}
|
|
|
|
|
2022-01-24 12:33:31 +00:00
|
|
|
bool StickersBox::Inner::Row::isWebm() const {
|
|
|
|
return (set->flags & SetFlag::Webm);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool StickersBox::Inner::Row::isInstalled() const {
|
|
|
|
return (flagsOverride & SetFlag::Installed);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool StickersBox::Inner::Row::isUnread() const {
|
|
|
|
return (flagsOverride & SetFlag::Unread);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool StickersBox::Inner::Row::isArchived() const {
|
|
|
|
return (flagsOverride & SetFlag::Archived);
|
|
|
|
}
|
|
|
|
|
2019-08-06 16:40:08 +00:00
|
|
|
StickersBox::Inner::Inner(
|
|
|
|
QWidget *parent,
|
2020-06-23 17:21:58 +00:00
|
|
|
not_null<Window::SessionController*> controller,
|
2019-08-06 16:40:08 +00:00
|
|
|
StickersBox::Section section)
|
2019-07-02 13:20:04 +00:00
|
|
|
: RpWidget(parent)
|
2020-06-23 17:21:58 +00:00
|
|
|
, _controller(controller)
|
|
|
|
, _api(&_controller->session().mtp())
|
2016-10-20 16:32:15 +00:00
|
|
|
, _section(section)
|
2021-03-29 17:37:03 +00:00
|
|
|
, _isInstalled(_section == Section::Installed || _section == Section::Masks)
|
2016-10-20 16:32:15 +00:00
|
|
|
, _rowHeight(st::contactsPadding.top() + st::contactsPhotoSize + st::contactsPadding.bottom())
|
2019-04-01 17:44:54 +00:00
|
|
|
, _shiftingAnimation([=](crl::time now) {
|
|
|
|
return shiftingAnimationCallback(now);
|
|
|
|
})
|
2016-12-13 17:07:56 +00:00
|
|
|
, _itemsTop(st::membersMarginTop)
|
2019-06-19 15:09:03 +00:00
|
|
|
, _addText(tr::lng_stickers_featured_add(tr::now).toUpper())
|
2016-11-22 09:48:13 +00:00
|
|
|
, _addWidth(st::stickersTrendingAdd.font->width(_addText))
|
2019-06-19 15:09:03 +00:00
|
|
|
, _undoText(tr::lng_stickers_return(tr::now).toUpper())
|
2016-12-13 17:07:56 +00:00
|
|
|
, _undoWidth(st::stickersUndoRemove.font->width(_undoText)) {
|
2016-10-20 16:32:15 +00:00
|
|
|
setup();
|
|
|
|
}
|
|
|
|
|
2020-06-23 17:21:58 +00:00
|
|
|
StickersBox::Inner::Inner(
|
|
|
|
QWidget *parent,
|
|
|
|
not_null<Window::SessionController*> controller,
|
|
|
|
not_null<ChannelData*> megagroup)
|
2019-07-02 13:20:04 +00:00
|
|
|
: RpWidget(parent)
|
2020-06-23 17:21:58 +00:00
|
|
|
, _controller(controller)
|
|
|
|
, _api(&_controller->session().mtp())
|
2017-08-05 10:48:21 +00:00
|
|
|
, _section(StickersBox::Section::Installed)
|
2021-03-29 17:37:03 +00:00
|
|
|
, _isInstalled(_section == Section::Installed || _section == Section::Masks)
|
2017-08-05 10:48:21 +00:00
|
|
|
, _rowHeight(st::contactsPadding.top() + st::contactsPhotoSize + st::contactsPadding.bottom())
|
2019-04-01 17:44:54 +00:00
|
|
|
, _shiftingAnimation([=](crl::time now) {
|
|
|
|
return shiftingAnimationCallback(now);
|
|
|
|
})
|
2017-08-05 10:48:21 +00:00
|
|
|
, _itemsTop(st::membersMarginTop)
|
2017-08-05 20:01:20 +00:00
|
|
|
, _megagroupSet(megagroup)
|
|
|
|
, _megagroupSetInput(_megagroupSet->mgInfo->stickerSet)
|
2020-06-17 09:36:25 +00:00
|
|
|
, _megagroupSetField(
|
|
|
|
this,
|
|
|
|
st::groupStickersField,
|
|
|
|
rpl::single(qsl("stickerset")),
|
|
|
|
QString(),
|
2020-06-23 17:21:58 +00:00
|
|
|
_controller->session().createInternalLink(QString()))
|
2017-08-05 20:01:20 +00:00
|
|
|
, _megagroupDivider(this)
|
2019-06-19 15:09:03 +00:00
|
|
|
, _megagroupSubTitle(this, tr::lng_stickers_group_from_your(tr::now), st::boxTitle) {
|
2020-06-17 09:36:25 +00:00
|
|
|
_megagroupSetField->setLinkPlaceholder(
|
2020-06-23 17:21:58 +00:00
|
|
|
_controller->session().createInternalLink(qsl("addstickers/")));
|
2017-08-05 20:01:20 +00:00
|
|
|
_megagroupSetField->setPlaceholderHidden(false);
|
|
|
|
_megagroupSetAddressChangedTimer.setCallback([this] { handleMegagroupSetAddressChange(); });
|
2017-11-05 17:07:27 +00:00
|
|
|
connect(
|
|
|
|
_megagroupSetField,
|
|
|
|
&Ui::MaskedInputField::changed,
|
2018-05-31 12:20:28 +00:00
|
|
|
[=] {
|
2017-11-05 17:07:27 +00:00
|
|
|
_megagroupSetAddressChangedTimer.callOnce(
|
|
|
|
kHandleMegagroupSetAddressChangeTimeout);
|
|
|
|
});
|
|
|
|
connect(
|
|
|
|
_megagroupSetField,
|
|
|
|
&Ui::MaskedInputField::submitted,
|
2018-05-31 12:20:28 +00:00
|
|
|
[=] {
|
2017-11-05 17:07:27 +00:00
|
|
|
_megagroupSetAddressChangedTimer.cancel();
|
|
|
|
handleMegagroupSetAddressChange();
|
|
|
|
});
|
2017-08-05 20:01:20 +00:00
|
|
|
|
2017-08-05 10:48:21 +00:00
|
|
|
setup();
|
|
|
|
}
|
|
|
|
|
2020-06-23 17:21:58 +00:00
|
|
|
Main::Session &StickersBox::Inner::session() const {
|
|
|
|
return _controller->session();
|
|
|
|
}
|
|
|
|
|
2016-10-20 16:32:15 +00:00
|
|
|
void StickersBox::Inner::setup() {
|
2020-07-01 08:03:34 +00:00
|
|
|
session().downloaderTaskFinished(
|
|
|
|
) | rpl::start_with_next([=] {
|
2016-11-22 09:48:13 +00:00
|
|
|
update();
|
|
|
|
readVisibleSets();
|
2020-07-01 08:03:34 +00:00
|
|
|
}, lifetime());
|
|
|
|
|
2016-10-20 16:32:15 +00:00
|
|
|
setMouseTracking(true);
|
|
|
|
}
|
|
|
|
|
2017-08-05 20:01:20 +00:00
|
|
|
void StickersBox::Inner::setInnerFocus() {
|
|
|
|
if (_megagroupSetField) {
|
|
|
|
_megagroupSetField->setFocusFast();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-10-20 16:32:15 +00:00
|
|
|
void StickersBox::Inner::paintEvent(QPaintEvent *e) {
|
|
|
|
Painter p(this);
|
|
|
|
|
2017-08-05 20:01:20 +00:00
|
|
|
auto clip = e->rect();
|
|
|
|
p.fillRect(clip, st::boxBg);
|
|
|
|
p.setClipRect(clip);
|
|
|
|
|
|
|
|
if (_megagroupSelectedSet) {
|
|
|
|
auto setTop = _megagroupDivider->y() - _rowHeight;
|
|
|
|
p.translate(0, setTop);
|
2019-04-02 09:13:30 +00:00
|
|
|
paintRow(p, _megagroupSelectedSet.get(), -1);
|
2017-08-05 20:01:20 +00:00
|
|
|
p.translate(0, -setTop);
|
|
|
|
}
|
2016-10-20 16:32:15 +00:00
|
|
|
|
2016-12-13 17:07:56 +00:00
|
|
|
auto y = _itemsTop;
|
2017-08-05 20:01:20 +00:00
|
|
|
if (_rows.empty()) {
|
2016-10-20 16:32:15 +00:00
|
|
|
p.setFont(st::noContactsFont);
|
|
|
|
p.setPen(st::noContactsColor);
|
2019-06-19 15:09:03 +00:00
|
|
|
p.drawText(QRect(0, y, width(), st::noContactsHeight), tr::lng_contacts_loading(tr::now), style::al_center);
|
2016-10-20 16:32:15 +00:00
|
|
|
} else {
|
|
|
|
p.translate(0, _itemsTop);
|
|
|
|
|
2017-08-05 20:01:20 +00:00
|
|
|
int32 yFrom = clip.y() - _itemsTop, yTo = clip.y() + clip.height() - _itemsTop;
|
2016-10-20 16:32:15 +00:00
|
|
|
int32 from = floorclamp(yFrom - _rowHeight, _rowHeight, 0, _rows.size());
|
|
|
|
int32 to = ceilclamp(yTo + _rowHeight, _rowHeight, 0, _rows.size());
|
|
|
|
p.translate(0, from * _rowHeight);
|
|
|
|
for (int32 i = from; i < to; ++i) {
|
|
|
|
if (i != _above) {
|
2019-04-02 09:13:30 +00:00
|
|
|
paintRow(p, _rows[i].get(), i);
|
2016-10-20 16:32:15 +00:00
|
|
|
}
|
|
|
|
p.translate(0, _rowHeight);
|
|
|
|
}
|
|
|
|
if (from <= _above && _above < to) {
|
|
|
|
p.translate(0, (_above - to) * _rowHeight);
|
2019-04-02 09:13:30 +00:00
|
|
|
paintRow(p, _rows[_above].get(), _above);
|
2016-10-20 16:32:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-05 20:01:20 +00:00
|
|
|
void StickersBox::Inner::resizeEvent(QResizeEvent *e) {
|
|
|
|
updateControlsGeometry();
|
|
|
|
}
|
|
|
|
|
|
|
|
void StickersBox::Inner::updateControlsGeometry() {
|
|
|
|
if (_megagroupSet) {
|
|
|
|
auto top = st::groupStickersFieldPadding.top();
|
2019-11-02 17:06:47 +00:00
|
|
|
auto fieldLeft = st::boxTitlePosition.x();
|
2017-08-05 20:01:20 +00:00
|
|
|
_megagroupSetField->setGeometryToLeft(fieldLeft, top, width() - fieldLeft - st::groupStickersFieldPadding.right(), _megagroupSetField->height());
|
|
|
|
top += _megagroupSetField->height() + st::groupStickersFieldPadding.bottom();
|
|
|
|
if (_megagroupSelectedRemove) {
|
|
|
|
_megagroupSelectedShadow->setGeometryToLeft(0, top, width(), st::lineWidth);
|
|
|
|
top += st::lineWidth;
|
|
|
|
_megagroupSelectedRemove->moveToRight(st::groupStickersRemovePosition.x(), top + st::groupStickersRemovePosition.y());
|
|
|
|
top += _rowHeight;
|
|
|
|
}
|
|
|
|
_megagroupDivider->setGeometryToLeft(0, top, width(), _megagroupDivider->height());
|
|
|
|
top += _megagroupDivider->height();
|
2019-11-02 17:06:47 +00:00
|
|
|
_megagroupSubTitle->resizeToNaturalWidth(width() - 2 * st::boxTitlePosition.x());
|
|
|
|
_megagroupSubTitle->moveToLeft(st::boxTitlePosition.x(), top + st::boxTitlePosition.y());
|
2017-08-05 20:01:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-22 09:48:13 +00:00
|
|
|
QRect StickersBox::Inner::relativeButtonRect(bool removeButton) const {
|
|
|
|
auto buttonw = st::stickersRemove.width;
|
|
|
|
auto buttonh = st::stickersRemove.height;
|
|
|
|
auto buttonshift = st::stickersRemoveSkip;
|
|
|
|
if (!removeButton) {
|
2021-03-29 17:37:03 +00:00
|
|
|
const auto &st = _isInstalled
|
|
|
|
? st::stickersUndoRemove
|
|
|
|
: st::stickersTrendingAdd;
|
|
|
|
const auto textWidth = _isInstalled ? _undoWidth : _addWidth;
|
2016-11-22 09:48:13 +00:00
|
|
|
buttonw = textWidth - st.width;
|
|
|
|
buttonh = st.height;
|
|
|
|
buttonshift = 0;
|
|
|
|
}
|
|
|
|
auto buttonx = width() - st::contactsPadding.right() - st::contactsCheckPosition.x() - buttonw + buttonshift;
|
|
|
|
auto buttony = st::contactsPadding.top() + (st::contactsPhotoSize - buttonh) / 2;
|
|
|
|
return QRect(buttonx, buttony, buttonw, buttonh);
|
2016-11-16 16:04:25 +00:00
|
|
|
}
|
|
|
|
|
2020-05-28 11:58:50 +00:00
|
|
|
void StickersBox::Inner::paintRow(Painter &p, not_null<Row*> row, int index) {
|
|
|
|
auto xadd = 0, yadd = qRound(row->yadd.current());
|
2016-10-20 16:32:15 +00:00
|
|
|
if (xadd || yadd) p.translate(xadd, yadd);
|
|
|
|
|
2017-08-05 20:01:20 +00:00
|
|
|
if (_megagroupSet) {
|
2017-11-05 17:07:27 +00:00
|
|
|
auto selectedIndex = [&] {
|
2020-08-31 09:04:17 +00:00
|
|
|
if (auto index = std::get_if<int>(&_selected)) {
|
2017-11-05 17:07:27 +00:00
|
|
|
return *index;
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}();
|
|
|
|
if (index >= 0 && index == selectedIndex) {
|
2017-08-05 20:01:20 +00:00
|
|
|
p.fillRect(0, 0, width(), _rowHeight, st::contactsBgOver);
|
2020-05-28 11:58:50 +00:00
|
|
|
if (row->ripple) {
|
|
|
|
row->ripple->paint(p, 0, 0, width());
|
2017-08-05 20:01:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-03-29 17:37:03 +00:00
|
|
|
if (_isInstalled) {
|
2017-08-05 20:01:20 +00:00
|
|
|
if (index >= 0 && index == _above) {
|
2016-12-13 17:07:56 +00:00
|
|
|
auto current = _aboveShadowFadeOpacity.current();
|
2016-10-20 16:32:15 +00:00
|
|
|
if (_started >= 0) {
|
2016-12-13 17:07:56 +00:00
|
|
|
auto reachedOpacity = aboveShadowOpacity();
|
|
|
|
if (reachedOpacity > current) {
|
|
|
|
_aboveShadowFadeOpacity = anim::value(reachedOpacity, reachedOpacity);
|
|
|
|
current = reachedOpacity;
|
2016-10-20 16:32:15 +00:00
|
|
|
}
|
|
|
|
}
|
2020-05-28 11:58:50 +00:00
|
|
|
auto rect = myrtlrect(st::contactsPadding.left() / 2, st::contactsPadding.top() / 2, width() - (st::contactsPadding.left() / 2) - _scrollbar - st::contactsPadding.left() / 2, _rowHeight - ((st::contactsPadding.top() + st::contactsPadding.bottom()) / 2));
|
2016-10-20 16:32:15 +00:00
|
|
|
p.setOpacity(current);
|
2020-05-28 11:58:50 +00:00
|
|
|
Ui::Shadow::paint(p, rect, width(), st::boxRoundShadow);
|
2016-10-20 16:32:15 +00:00
|
|
|
p.setOpacity(1);
|
2016-12-13 17:07:56 +00:00
|
|
|
|
2020-10-13 15:11:53 +00:00
|
|
|
Ui::FillRoundRect(p, rect, st::boxBg, Ui::BoxCorners);
|
2016-12-13 17:07:56 +00:00
|
|
|
|
|
|
|
p.setOpacity(1. - current);
|
2020-05-28 11:58:50 +00:00
|
|
|
paintFakeButton(p, row, index);
|
2016-12-13 17:07:56 +00:00
|
|
|
p.setOpacity(1.);
|
2017-08-05 10:48:21 +00:00
|
|
|
} else if (!_megagroupSet) {
|
2020-05-28 11:58:50 +00:00
|
|
|
paintFakeButton(p, row, index);
|
2016-10-20 16:32:15 +00:00
|
|
|
}
|
2017-08-05 10:48:21 +00:00
|
|
|
} else if (!_megagroupSet) {
|
2020-05-28 11:58:50 +00:00
|
|
|
paintFakeButton(p, row, index);
|
2016-10-20 16:32:15 +00:00
|
|
|
}
|
|
|
|
|
2021-03-29 17:37:03 +00:00
|
|
|
if (row->removed && _isInstalled) {
|
2016-10-20 16:32:15 +00:00
|
|
|
p.setOpacity(st::stickersRowDisabledOpacity);
|
|
|
|
}
|
2016-11-22 09:48:13 +00:00
|
|
|
|
|
|
|
auto stickerx = st::contactsPadding.left();
|
|
|
|
|
2021-03-29 17:37:03 +00:00
|
|
|
if (!_megagroupSet && _isInstalled) {
|
2016-11-22 09:48:13 +00:00
|
|
|
stickerx += st::stickersReorderIcon.width() + st::stickersReorderSkip;
|
2020-05-28 11:58:50 +00:00
|
|
|
if (!row->isRecentSet()) {
|
2016-11-22 09:48:13 +00:00
|
|
|
st::stickersReorderIcon.paint(p, st::contactsPadding.left(), (_rowHeight - st::stickersReorderIcon.height()) / 2, width());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-28 11:58:50 +00:00
|
|
|
if (row->sticker) {
|
|
|
|
paintRowThumbnail(p, row, stickerx);
|
2016-10-20 16:32:15 +00:00
|
|
|
}
|
|
|
|
|
2016-11-22 09:48:13 +00:00
|
|
|
int namex = stickerx + st::contactsPhotoSize + st::contactsPadding.left();
|
2016-10-20 16:32:15 +00:00
|
|
|
int namey = st::contactsPadding.top() + st::contactsNameTop;
|
2016-11-22 09:48:13 +00:00
|
|
|
|
2016-10-20 16:32:15 +00:00
|
|
|
int statusx = namex;
|
|
|
|
int statusy = st::contactsPadding.top() + st::contactsStatusTop;
|
|
|
|
|
2016-12-23 13:21:01 +00:00
|
|
|
p.setFont(st::contactsNameStyle.font);
|
2016-10-31 12:29:26 +00:00
|
|
|
p.setPen(st::contactsNameFg);
|
2020-05-28 11:58:50 +00:00
|
|
|
p.drawTextLeft(namex, namey, width(), row->title, row->titleWidth);
|
2016-10-20 16:32:15 +00:00
|
|
|
|
2022-01-24 12:33:31 +00:00
|
|
|
if (row->isUnread()) {
|
2016-10-20 16:32:15 +00:00
|
|
|
p.setPen(Qt::NoPen);
|
|
|
|
p.setBrush(st::stickersFeaturedUnreadBg);
|
|
|
|
|
2016-12-03 12:10:35 +00:00
|
|
|
{
|
|
|
|
PainterHighQualityEnabler hq(p);
|
2020-05-28 11:58:50 +00:00
|
|
|
p.drawEllipse(style::rtlrect(namex + row->titleWidth + st::stickersFeaturedUnreadSkip, namey + st::stickersFeaturedUnreadTop, st::stickersFeaturedUnreadSize, st::stickersFeaturedUnreadSize, width()));
|
2016-12-03 12:10:35 +00:00
|
|
|
}
|
2016-10-20 16:32:15 +00:00
|
|
|
}
|
|
|
|
|
2021-03-29 23:00:04 +00:00
|
|
|
const auto statusText = (row->count == 0)
|
|
|
|
? tr::lng_contacts_loading(tr::now)
|
2022-07-18 13:56:14 +00:00
|
|
|
: row->isEmojiSet()
|
|
|
|
? tr::lng_custom_emoji_count(tr::now, lt_count, row->count)
|
2021-03-29 23:00:04 +00:00
|
|
|
: row->isMasksSet()
|
|
|
|
? tr::lng_masks_count(tr::now, lt_count, row->count)
|
|
|
|
: tr::lng_stickers_count(tr::now, lt_count, row->count);
|
2017-06-02 11:46:02 +00:00
|
|
|
|
2016-10-20 16:32:15 +00:00
|
|
|
p.setFont(st::contactsStatusFont);
|
|
|
|
p.setPen(st::contactsStatusFg);
|
2017-06-02 11:46:02 +00:00
|
|
|
p.drawTextLeft(statusx, statusy, width(), statusText);
|
2016-10-20 16:32:15 +00:00
|
|
|
|
|
|
|
p.setOpacity(1);
|
|
|
|
if (xadd || yadd) p.translate(-xadd, -yadd);
|
|
|
|
}
|
|
|
|
|
2019-07-02 13:20:04 +00:00
|
|
|
void StickersBox::Inner::paintRowThumbnail(
|
|
|
|
Painter &p,
|
2020-05-28 11:58:50 +00:00
|
|
|
not_null<Row*> row,
|
2019-07-02 13:20:04 +00:00
|
|
|
int left) {
|
|
|
|
const auto origin = Data::FileOriginStickerSet(
|
2020-05-28 11:58:50 +00:00
|
|
|
row->set->id,
|
2021-08-25 08:15:05 +00:00
|
|
|
row->set->accessHash);
|
2020-05-28 11:58:50 +00:00
|
|
|
if (row->set->hasThumbnail()) {
|
|
|
|
if (!row->thumbnailMedia) {
|
|
|
|
row->thumbnailMedia = row->set->createThumbnailView();
|
|
|
|
row->set->loadThumbnail();
|
|
|
|
}
|
|
|
|
} else if (row->sticker) {
|
|
|
|
if (!row->stickerMedia) {
|
|
|
|
row->stickerMedia = row->sticker->createMediaView();
|
|
|
|
row->stickerMedia->thumbnailWanted(origin);
|
|
|
|
}
|
|
|
|
}
|
2022-01-24 12:33:31 +00:00
|
|
|
validateAnimation(row);
|
2022-01-25 07:09:55 +00:00
|
|
|
const auto thumb = row->thumbnailMedia
|
|
|
|
? row->thumbnailMedia->image()
|
|
|
|
: row->stickerMedia
|
|
|
|
? row->stickerMedia->thumbnail()
|
|
|
|
: nullptr;
|
|
|
|
const auto paused = _controller->isGifPausedAtLeastFor(
|
|
|
|
Window::GifPauseReason::Layer);
|
|
|
|
const auto x = left + (st::contactsPhotoSize - row->pixw) / 2;
|
|
|
|
const auto y = st::contactsPadding.top() + (st::contactsPhotoSize - row->pixh) / 2;
|
|
|
|
if (row->lottie && row->lottie->ready()) {
|
2020-05-28 11:58:50 +00:00
|
|
|
const auto frame = row->lottie->frame();
|
2019-07-02 13:20:04 +00:00
|
|
|
const auto size = frame.size() / cIntRetinaFactor();
|
|
|
|
p.drawImage(
|
|
|
|
QRect(
|
|
|
|
left + (st::contactsPhotoSize - size.width()) / 2,
|
|
|
|
st::contactsPadding.top() + (st::contactsPhotoSize - size.height()) / 2,
|
|
|
|
size.width(),
|
|
|
|
size.height()),
|
|
|
|
frame);
|
|
|
|
if (!paused) {
|
2020-05-28 11:58:50 +00:00
|
|
|
row->lottie->markFrameShown();
|
2019-07-02 13:20:04 +00:00
|
|
|
}
|
2022-01-25 07:09:55 +00:00
|
|
|
} else if (row->webm && row->webm->started()) {
|
|
|
|
p.drawPixmapLeft(
|
|
|
|
x,
|
|
|
|
y,
|
|
|
|
width(),
|
|
|
|
row->webm->current(
|
|
|
|
{ .frame = { row->pixw, row->pixh }, .keepAlpha = true },
|
|
|
|
paused ? 0 : crl::now()));
|
|
|
|
} else if (thumb) {
|
|
|
|
p.drawPixmapLeft(
|
|
|
|
x,
|
|
|
|
y,
|
|
|
|
width(),
|
|
|
|
thumb->pix(row->pixw, row->pixh));
|
2019-07-02 13:20:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-28 11:58:50 +00:00
|
|
|
void StickersBox::Inner::validateLottieAnimation(not_null<Row*> row) {
|
|
|
|
if (row->lottie
|
2020-06-08 17:24:36 +00:00
|
|
|
|| !ChatHelpers::HasLottieThumbnail(
|
2022-01-24 12:33:31 +00:00
|
|
|
row->set->flags,
|
2020-05-28 11:58:50 +00:00
|
|
|
row->thumbnailMedia.get(),
|
|
|
|
row->stickerMedia.get())) {
|
2019-07-02 13:20:04 +00:00
|
|
|
return;
|
|
|
|
}
|
2020-06-08 17:24:36 +00:00
|
|
|
auto player = ChatHelpers::LottieThumbnail(
|
2020-05-28 11:58:50 +00:00
|
|
|
row->thumbnailMedia.get(),
|
|
|
|
row->stickerMedia.get(),
|
2020-06-08 17:24:36 +00:00
|
|
|
ChatHelpers::StickerLottieSize::SetsListThumbnail,
|
2019-07-02 13:20:04 +00:00
|
|
|
QSize(
|
|
|
|
st::contactsPhotoSize,
|
|
|
|
st::contactsPhotoSize) * cIntRetinaFactor());
|
|
|
|
if (!player) {
|
|
|
|
return;
|
|
|
|
}
|
2020-05-28 11:58:50 +00:00
|
|
|
row->lottie = std::move(player);
|
|
|
|
row->lottie->updates(
|
2019-07-02 13:20:04 +00:00
|
|
|
) | rpl::start_with_next([=] {
|
2020-05-28 11:58:50 +00:00
|
|
|
updateRowThumbnail(row);
|
2019-07-02 13:20:04 +00:00
|
|
|
}, lifetime());
|
|
|
|
}
|
|
|
|
|
2022-01-24 12:33:31 +00:00
|
|
|
void StickersBox::Inner::validateWebmAnimation(not_null<Row*> row) {
|
|
|
|
if (row->webm
|
|
|
|
|| !ChatHelpers::HasWebmThumbnail(
|
|
|
|
row->set->flags,
|
|
|
|
row->thumbnailMedia.get(),
|
|
|
|
row->stickerMedia.get())) {
|
|
|
|
return;
|
|
|
|
}
|
2022-01-25 07:09:55 +00:00
|
|
|
auto callback = [=](Media::Clip::Notification notification) {
|
|
|
|
clipCallback(row, notification);
|
|
|
|
};
|
2022-01-24 12:33:31 +00:00
|
|
|
row->webm = ChatHelpers::WebmThumbnail(
|
|
|
|
row->thumbnailMedia.get(),
|
|
|
|
row->stickerMedia.get(),
|
2022-01-25 07:09:55 +00:00
|
|
|
std::move(callback));
|
|
|
|
}
|
|
|
|
|
|
|
|
void StickersBox::Inner::clipCallback(
|
|
|
|
not_null<Row*> row,
|
|
|
|
Media::Clip::Notification notification) {
|
|
|
|
using namespace Media::Clip;
|
|
|
|
switch (notification) {
|
|
|
|
case Notification::Reinit: {
|
|
|
|
if (!row->webm) {
|
|
|
|
return;
|
|
|
|
} else if (row->webm->state() == State::Error) {
|
|
|
|
row->webm.setBad();
|
|
|
|
} else if (row->webm->ready() && !row->webm->started()) {
|
|
|
|
row->webm->start({
|
|
|
|
.frame = { row->pixw, row->pixh },
|
|
|
|
.keepAlpha = true,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
} break;
|
|
|
|
|
|
|
|
case Notification::Repaint: break;
|
|
|
|
}
|
|
|
|
updateRowThumbnail(row);
|
2022-01-24 12:33:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void StickersBox::Inner::validateAnimation(not_null<Row*> row) {
|
|
|
|
validateWebmAnimation(row);
|
|
|
|
validateLottieAnimation(row);
|
|
|
|
}
|
|
|
|
|
2020-05-28 11:58:50 +00:00
|
|
|
void StickersBox::Inner::updateRowThumbnail(not_null<Row*> row) {
|
2019-07-02 13:20:04 +00:00
|
|
|
const auto rowTop = [&] {
|
2020-05-28 11:58:50 +00:00
|
|
|
if (row == _megagroupSelectedSet.get()) {
|
2019-07-02 13:20:04 +00:00
|
|
|
return _megagroupDivider->y() - _rowHeight;
|
|
|
|
}
|
|
|
|
auto top = _itemsTop;
|
2020-05-28 11:58:50 +00:00
|
|
|
for (const auto &entry : _rows) {
|
|
|
|
if (entry.get() == row) {
|
2019-07-02 13:20:04 +00:00
|
|
|
return top + qRound(row->yadd.current());
|
|
|
|
}
|
|
|
|
top += _rowHeight;
|
|
|
|
}
|
|
|
|
Unexpected("StickersBox::Inner::updateRowThumbnail: row not found");
|
|
|
|
}();
|
|
|
|
const auto left = st::contactsPadding.left()
|
2021-03-29 17:37:03 +00:00
|
|
|
+ ((!_megagroupSet && _isInstalled)
|
2019-07-02 13:20:04 +00:00
|
|
|
? st::stickersReorderIcon.width() + st::stickersReorderSkip
|
|
|
|
: 0);
|
|
|
|
update(
|
|
|
|
left,
|
|
|
|
rowTop + st::contactsPadding.top(),
|
|
|
|
st::contactsPhotoSize,
|
|
|
|
st::contactsPhotoSize);
|
|
|
|
}
|
|
|
|
|
2020-05-28 11:58:50 +00:00
|
|
|
void StickersBox::Inner::paintFakeButton(Painter &p, not_null<Row*> row, int index) {
|
2021-03-29 17:37:03 +00:00
|
|
|
auto removeButton = (_isInstalled && !row->removed);
|
2016-11-22 09:48:13 +00:00
|
|
|
auto rect = relativeButtonRect(removeButton);
|
2022-01-24 12:33:31 +00:00
|
|
|
if (!_isInstalled && row->isInstalled() && !row->isArchived() && !row->removed) {
|
2016-11-22 09:48:13 +00:00
|
|
|
// Checkbox after installed from Trending or Archived.
|
|
|
|
int checkx = width() - (st::contactsPadding.right() + st::contactsCheckPosition.x() + (rect.width() + st::stickersFeaturedInstalled.width()) / 2);
|
|
|
|
int checky = st::contactsPadding.top() + (st::contactsPhotoSize - st::stickersFeaturedInstalled.height()) / 2;
|
|
|
|
st::stickersFeaturedInstalled.paint(p, QPoint(checkx, checky), width());
|
|
|
|
} else {
|
|
|
|
auto selected = (index == _actionSel && _actionDown < 0) || (index == _actionDown);
|
|
|
|
if (removeButton) {
|
|
|
|
// Trash icon button when not disabled in Installed.
|
2020-05-28 11:58:50 +00:00
|
|
|
if (row->ripple) {
|
|
|
|
row->ripple->paint(p, rect.x(), rect.y(), width());
|
|
|
|
if (row->ripple->empty()) {
|
|
|
|
row->ripple.reset();
|
2016-11-22 09:48:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
auto &icon = selected ? st::stickersRemove.iconOver : st::stickersRemove.icon;
|
|
|
|
auto position = st::stickersRemove.iconPosition;
|
|
|
|
if (position.x() < 0) position.setX((rect.width() - icon.width()) / 2);
|
|
|
|
if (position.y() < 0) position.setY((rect.height() - icon.height()) / 2);
|
2019-04-02 09:13:30 +00:00
|
|
|
icon.paint(p, rect.topLeft() + position, width());
|
2016-11-22 09:48:13 +00:00
|
|
|
} else {
|
|
|
|
// Round button ADD when not installed from Trending or Archived.
|
|
|
|
// Or round button UNDO after disabled from Installed.
|
2021-03-29 17:37:03 +00:00
|
|
|
const auto &st = _isInstalled
|
|
|
|
? st::stickersUndoRemove
|
|
|
|
: st::stickersTrendingAdd;
|
|
|
|
const auto textWidth = _isInstalled ? _undoWidth : _addWidth;
|
|
|
|
const auto &text = _isInstalled ? _undoText : _addText;
|
|
|
|
const auto &textBg = selected ? st.textBgOver : st.textBg;
|
2020-10-13 15:11:53 +00:00
|
|
|
Ui::FillRoundRect(p, myrtlrect(rect), textBg, ImageRoundRadius::Small);
|
2020-05-28 11:58:50 +00:00
|
|
|
if (row->ripple) {
|
|
|
|
row->ripple->paint(p, rect.x(), rect.y(), width());
|
|
|
|
if (row->ripple->empty()) {
|
|
|
|
row->ripple.reset();
|
2016-11-22 09:48:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
p.setFont(st.font);
|
|
|
|
p.setPen(selected ? st.textFgOver : st.textFg);
|
|
|
|
p.drawTextLeft(rect.x() - (st.width / 2), rect.y() + st.textTop, width(), text, textWidth);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-10-20 16:32:15 +00:00
|
|
|
void StickersBox::Inner::mousePressEvent(QMouseEvent *e) {
|
|
|
|
if (_dragging >= 0) mouseReleaseEvent(e);
|
|
|
|
_mouse = e->globalPos();
|
2020-06-08 17:24:36 +00:00
|
|
|
updateSelected();
|
2016-10-20 16:32:15 +00:00
|
|
|
|
2017-08-05 20:01:20 +00:00
|
|
|
setPressed(_selected);
|
2016-10-20 16:32:15 +00:00
|
|
|
if (_actionSel >= 0) {
|
2016-11-16 16:04:25 +00:00
|
|
|
setActionDown(_actionSel);
|
2016-10-20 16:32:15 +00:00
|
|
|
update(0, _itemsTop + _actionSel * _rowHeight, width(), _rowHeight);
|
2020-08-31 09:04:17 +00:00
|
|
|
} else if (auto selectedIndex = std::get_if<int>(&_selected)) {
|
2021-03-29 17:37:03 +00:00
|
|
|
if (_isInstalled && !_rows[*selectedIndex]->isRecentSet() && _inDragArea) {
|
2017-11-05 17:07:27 +00:00
|
|
|
_above = _dragging = _started = *selectedIndex;
|
|
|
|
_dragStart = mapFromGlobal(_mouse);
|
|
|
|
}
|
2016-10-20 16:32:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-16 16:04:25 +00:00
|
|
|
void StickersBox::Inner::setActionDown(int newActionDown) {
|
|
|
|
if (_actionDown == newActionDown) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (_actionDown >= 0 && _actionDown < _rows.size()) {
|
|
|
|
update(0, _itemsTop + _actionDown * _rowHeight, width(), _rowHeight);
|
2020-05-28 11:58:50 +00:00
|
|
|
const auto row = _rows[_actionDown].get();
|
|
|
|
if (row->ripple) {
|
|
|
|
row->ripple->lastStop();
|
2016-11-16 16:04:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
_actionDown = newActionDown;
|
|
|
|
if (_actionDown >= 0 && _actionDown < _rows.size()) {
|
|
|
|
update(0, _itemsTop + _actionDown * _rowHeight, width(), _rowHeight);
|
2020-05-28 11:58:50 +00:00
|
|
|
const auto row = _rows[_actionDown].get();
|
2021-03-29 17:37:03 +00:00
|
|
|
auto removeButton = (_isInstalled && !row->removed);
|
2020-05-28 11:58:50 +00:00
|
|
|
if (!row->ripple) {
|
2021-03-29 17:37:03 +00:00
|
|
|
if (_isInstalled) {
|
2020-05-28 11:58:50 +00:00
|
|
|
if (row->removed) {
|
2016-11-22 09:48:13 +00:00
|
|
|
auto rippleSize = QSize(_undoWidth - st::stickersUndoRemove.width, st::stickersUndoRemove.height);
|
2020-12-08 07:19:23 +00:00
|
|
|
auto rippleMask = Ui::RippleAnimation::roundRectMask(rippleSize, st::roundRadiusSmall);
|
2017-02-21 13:45:56 +00:00
|
|
|
ensureRipple(st::stickersUndoRemove.ripple, std::move(rippleMask), removeButton);
|
2016-11-22 09:48:13 +00:00
|
|
|
} else {
|
|
|
|
auto rippleSize = st::stickersRemove.rippleAreaSize;
|
|
|
|
auto rippleMask = Ui::RippleAnimation::ellipseMask(QSize(rippleSize, rippleSize));
|
2017-02-21 13:45:56 +00:00
|
|
|
ensureRipple(st::stickersRemove.ripple, std::move(rippleMask), removeButton);
|
2016-11-22 09:48:13 +00:00
|
|
|
}
|
2022-01-24 12:33:31 +00:00
|
|
|
} else if (!row->isInstalled() || row->isArchived() || row->removed) {
|
2016-11-22 09:48:13 +00:00
|
|
|
auto rippleSize = QSize(_addWidth - st::stickersTrendingAdd.width, st::stickersTrendingAdd.height);
|
2020-12-08 07:19:23 +00:00
|
|
|
auto rippleMask = Ui::RippleAnimation::roundRectMask(rippleSize, st::roundRadiusSmall);
|
2017-02-21 13:45:56 +00:00
|
|
|
ensureRipple(st::stickersTrendingAdd.ripple, std::move(rippleMask), removeButton);
|
2016-11-22 09:48:13 +00:00
|
|
|
}
|
|
|
|
}
|
2020-05-28 11:58:50 +00:00
|
|
|
if (row->ripple) {
|
2016-11-22 09:48:13 +00:00
|
|
|
auto rect = relativeButtonRect(removeButton);
|
2020-05-28 11:58:50 +00:00
|
|
|
row->ripple->add(mapFromGlobal(QCursor::pos()) - QPoint(myrtlrect(rect).x(), _itemsTop + _actionDown * _rowHeight + rect.y()));
|
2016-11-16 16:04:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-05 17:07:27 +00:00
|
|
|
void StickersBox::Inner::setSelected(SelectedRow selected) {
|
2017-08-05 20:01:20 +00:00
|
|
|
if (_selected == selected) {
|
|
|
|
return;
|
|
|
|
}
|
2017-11-05 17:07:27 +00:00
|
|
|
auto countSelectedIndex = [&] {
|
2020-08-31 09:04:17 +00:00
|
|
|
if (auto index = std::get_if<int>(&_selected)) {
|
2017-11-05 17:07:27 +00:00
|
|
|
return *index;
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
};
|
|
|
|
auto selectedIndex = countSelectedIndex();
|
|
|
|
if (_megagroupSet && selectedIndex >= 0 && selectedIndex < _rows.size()) {
|
|
|
|
update(0, _itemsTop + selectedIndex * _rowHeight, width(), _rowHeight);
|
2017-08-05 20:01:20 +00:00
|
|
|
}
|
|
|
|
_selected = selected;
|
2020-05-28 11:58:50 +00:00
|
|
|
updateCursor();
|
2017-11-05 17:07:27 +00:00
|
|
|
selectedIndex = countSelectedIndex();
|
|
|
|
if (_megagroupSet && selectedIndex >= 0 && selectedIndex < _rows.size()) {
|
|
|
|
update(0, _itemsTop + selectedIndex * _rowHeight, width(), _rowHeight);
|
2017-08-05 20:01:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-05 17:07:27 +00:00
|
|
|
void StickersBox::Inner::setPressed(SelectedRow pressed) {
|
2017-08-05 20:01:20 +00:00
|
|
|
if (_pressed == pressed) {
|
|
|
|
return;
|
|
|
|
}
|
2017-11-05 17:07:27 +00:00
|
|
|
auto countPressedIndex = [&] {
|
2020-08-31 09:04:17 +00:00
|
|
|
if (auto index = std::get_if<int>(&_pressed)) {
|
2017-11-05 17:07:27 +00:00
|
|
|
return *index;
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
};
|
|
|
|
auto pressedIndex = countPressedIndex();
|
|
|
|
if (_megagroupSet && pressedIndex >= 0 && pressedIndex < _rows.size()) {
|
|
|
|
update(0, _itemsTop + pressedIndex * _rowHeight, width(), _rowHeight);
|
2020-05-28 11:58:50 +00:00
|
|
|
const auto row = _rows[pressedIndex].get();
|
|
|
|
if (row->ripple) {
|
|
|
|
row->ripple->lastStop();
|
2017-08-05 20:01:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
_pressed = pressed;
|
2017-11-05 17:07:27 +00:00
|
|
|
pressedIndex = countPressedIndex();
|
|
|
|
if (_megagroupSet && pressedIndex >= 0 && pressedIndex < _rows.size()) {
|
|
|
|
update(0, _itemsTop + pressedIndex * _rowHeight, width(), _rowHeight);
|
|
|
|
auto &set = _rows[pressedIndex];
|
2017-08-05 20:01:20 +00:00
|
|
|
auto rippleMask = Ui::RippleAnimation::rectMask(QSize(width(), _rowHeight));
|
Remove unused variable
The following are commits related to removed variables.
apiwrap.cpp
e050e27: kSaveDraftBeforeQuitTimeout
app.cpp
113f665: serviceImageCacheSize
boxes/auto_download_box.cpp
a0c6104: checked(Source source, Type type)
boxes/background_preview_box.cpp
b6edf45: resultBytesPerPixel
fe21b5a: ms
boxes/calendar_box.cpp
ae97704: yearIndex, monthIndex
99bb093: ms
boxes/connection_box.cpp
f794d8d: ping
boxes/dictionaries_manager.cpp
8353867: session
boxes/peer_list_box.cpp
2ce2a14: grayedWidth
boxes/peers/add_participants_box.cpp
07e010d: chat, channel
boxes/self_destruction_box.cpp
fe9f02e: count
chat_helpers/emoji_suggestions_widget.cpp
a12bc60: is(QLatin1String string)
chat_helpers/field_autocomplete.cpp
8c7a35c: atwidth, hashwidth
chat_helpers/gifs_list_widget.cpp
ff65734: inlineItems
3d846fc: newSelected
d1687ab: kSaveDraftBeforeQuitTimeout
chat_helpers/stickers_dice_pack.cpp
c83e297: kZeroDiceDocumentId
chat_helpers/stickers_emoji_pack.cpp
d298953: length
chat_helpers/stickers_list_widget.cpp
eb75859: index, x
core/crash_reports.cpp
5940ae6: LaunchedDateTimeStr, LaunchedBinaryName
data/data_changes.cpp
3c4e959:clearRealtime
data/data_cloud_file.cpp
4b354b0: fromCloud, cacheTag
data/data_document_media.cpp
7db5359: kMaxVideoFrameArea
data/data_messages.cpp
794e315: wasCount
data/data_photo_media.cpp
e27d2bc: index
data/data_wall_paper.cpp
b6edf45: resultBytesPerPixel
data/data_types.cpp
aa8f62d: kWebDocumentCacheTag, kStorageCacheMask
history/admin_log/history_admin_log_inner.cpp
794e315: canDelete, canForward
history/history_location_manager.cpp
60f45ab: kCoordPrecision
9f90d3a: kMaxHttpRedirects
history/history_message.cpp
cedf8a6: kPinnedMessageTextLimit
history/history_widget.cpp
b305924: serviceColor
efa5fc4: hasForward
5e7aa4f: kTabbedSelectorToggleTooltipTimeoutMs, kTabbedSelectorToggleTooltipCount
history/view/history_view_context_menu.cpp
fe1a90b: isVideoLink, isVoiceLink, isAudioLink
settings.cpp
e2f54eb: defaultRecent
settings/settings_folders.cpp
e8bf5bb: kRefreshSuggestedTimeout
ui/filter_icon_panel.cpp
c4a0bc1: kDelayedHideTimeoutMs
window/themes/window_theme_preview.cpp
ef927c8: mutedCounter
-----
Modified variables
boxes/stickers_box.cpp
554eb3a: _rows[pressedIndex] -> set
data/data_notify_settings.cpp
734c410: muteForSeconds -> muteUntil
history/view/history_view_list_widget.cpp
07528be: _items[index] -> view
e5f3bed: fromState, tillState
history/history.cpp
cd3c1c6: kStatusShowClientsideRecordVideo -> kStatusShowClientsideRecordVoice
storage/download_manager_mtproto.cpp
ae8fb14: _queues[dcId] -> queue
storage/localstorage.cpp
357caf8: MTP::Environment::Production -> production
2020-07-02 10:42:30 +00:00
|
|
|
if (!set->ripple) {
|
2020-11-29 18:26:49 +00:00
|
|
|
set->ripple = std::make_unique<Ui::RippleAnimation>(st::defaultRippleAnimation, std::move(rippleMask), [this, pressedIndex] {
|
2017-11-05 17:07:27 +00:00
|
|
|
update(0, _itemsTop + pressedIndex * _rowHeight, width(), _rowHeight);
|
2017-08-05 20:01:20 +00:00
|
|
|
});
|
|
|
|
}
|
Remove unused variable
The following are commits related to removed variables.
apiwrap.cpp
e050e27: kSaveDraftBeforeQuitTimeout
app.cpp
113f665: serviceImageCacheSize
boxes/auto_download_box.cpp
a0c6104: checked(Source source, Type type)
boxes/background_preview_box.cpp
b6edf45: resultBytesPerPixel
fe21b5a: ms
boxes/calendar_box.cpp
ae97704: yearIndex, monthIndex
99bb093: ms
boxes/connection_box.cpp
f794d8d: ping
boxes/dictionaries_manager.cpp
8353867: session
boxes/peer_list_box.cpp
2ce2a14: grayedWidth
boxes/peers/add_participants_box.cpp
07e010d: chat, channel
boxes/self_destruction_box.cpp
fe9f02e: count
chat_helpers/emoji_suggestions_widget.cpp
a12bc60: is(QLatin1String string)
chat_helpers/field_autocomplete.cpp
8c7a35c: atwidth, hashwidth
chat_helpers/gifs_list_widget.cpp
ff65734: inlineItems
3d846fc: newSelected
d1687ab: kSaveDraftBeforeQuitTimeout
chat_helpers/stickers_dice_pack.cpp
c83e297: kZeroDiceDocumentId
chat_helpers/stickers_emoji_pack.cpp
d298953: length
chat_helpers/stickers_list_widget.cpp
eb75859: index, x
core/crash_reports.cpp
5940ae6: LaunchedDateTimeStr, LaunchedBinaryName
data/data_changes.cpp
3c4e959:clearRealtime
data/data_cloud_file.cpp
4b354b0: fromCloud, cacheTag
data/data_document_media.cpp
7db5359: kMaxVideoFrameArea
data/data_messages.cpp
794e315: wasCount
data/data_photo_media.cpp
e27d2bc: index
data/data_wall_paper.cpp
b6edf45: resultBytesPerPixel
data/data_types.cpp
aa8f62d: kWebDocumentCacheTag, kStorageCacheMask
history/admin_log/history_admin_log_inner.cpp
794e315: canDelete, canForward
history/history_location_manager.cpp
60f45ab: kCoordPrecision
9f90d3a: kMaxHttpRedirects
history/history_message.cpp
cedf8a6: kPinnedMessageTextLimit
history/history_widget.cpp
b305924: serviceColor
efa5fc4: hasForward
5e7aa4f: kTabbedSelectorToggleTooltipTimeoutMs, kTabbedSelectorToggleTooltipCount
history/view/history_view_context_menu.cpp
fe1a90b: isVideoLink, isVoiceLink, isAudioLink
settings.cpp
e2f54eb: defaultRecent
settings/settings_folders.cpp
e8bf5bb: kRefreshSuggestedTimeout
ui/filter_icon_panel.cpp
c4a0bc1: kDelayedHideTimeoutMs
window/themes/window_theme_preview.cpp
ef927c8: mutedCounter
-----
Modified variables
boxes/stickers_box.cpp
554eb3a: _rows[pressedIndex] -> set
data/data_notify_settings.cpp
734c410: muteForSeconds -> muteUntil
history/view/history_view_list_widget.cpp
07528be: _items[index] -> view
e5f3bed: fromState, tillState
history/history.cpp
cd3c1c6: kStatusShowClientsideRecordVideo -> kStatusShowClientsideRecordVoice
storage/download_manager_mtproto.cpp
ae8fb14: _queues[dcId] -> queue
storage/localstorage.cpp
357caf8: MTP::Environment::Production -> production
2020-07-02 10:42:30 +00:00
|
|
|
set->ripple->add(mapFromGlobal(QCursor::pos()) - QPoint(0, _itemsTop + pressedIndex * _rowHeight));
|
2017-08-05 20:01:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-22 09:48:13 +00:00
|
|
|
void StickersBox::Inner::ensureRipple(const style::RippleAnimation &st, QImage mask, bool removeButton) {
|
2017-08-05 20:01:20 +00:00
|
|
|
_rows[_actionDown]->ripple = std::make_unique<Ui::RippleAnimation>(st, std::move(mask), [this, index = _actionDown, removeButton] {
|
2016-11-22 09:48:13 +00:00
|
|
|
update(myrtlrect(relativeButtonRect(removeButton).translated(0, _itemsTop + index * _rowHeight)));
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2016-10-20 16:32:15 +00:00
|
|
|
void StickersBox::Inner::mouseMoveEvent(QMouseEvent *e) {
|
|
|
|
_mouse = e->globalPos();
|
2020-06-08 17:24:36 +00:00
|
|
|
updateSelected();
|
2016-10-20 16:32:15 +00:00
|
|
|
}
|
|
|
|
|
2020-06-08 17:24:36 +00:00
|
|
|
void StickersBox::Inner::updateSelected() {
|
2016-12-01 19:20:33 +00:00
|
|
|
auto local = mapFromGlobal(_mouse);
|
2016-10-20 16:32:15 +00:00
|
|
|
if (_dragging >= 0) {
|
2016-12-01 19:20:33 +00:00
|
|
|
auto shift = 0;
|
2019-04-01 17:44:54 +00:00
|
|
|
auto now = crl::now();
|
2016-10-20 16:32:15 +00:00
|
|
|
int firstSetIndex = 0;
|
2016-11-22 09:48:13 +00:00
|
|
|
if (_rows.at(firstSetIndex)->isRecentSet()) {
|
2016-10-20 16:32:15 +00:00
|
|
|
++firstSetIndex;
|
|
|
|
}
|
|
|
|
if (_dragStart.y() > local.y() && _dragging > 0) {
|
|
|
|
shift = -floorclamp(_dragStart.y() - local.y() + (_rowHeight / 2), _rowHeight, 0, _dragging - firstSetIndex);
|
|
|
|
for (int32 from = _dragging, to = _dragging + shift; from > to; --from) {
|
|
|
|
qSwap(_rows[from], _rows[from - 1]);
|
2016-12-05 11:01:08 +00:00
|
|
|
_rows[from]->yadd = anim::value(_rows[from]->yadd.current() - _rowHeight, 0);
|
2019-04-01 17:44:54 +00:00
|
|
|
_shiftingStartTimes[from] = now;
|
2016-10-20 16:32:15 +00:00
|
|
|
}
|
|
|
|
} else if (_dragStart.y() < local.y() && _dragging + 1 < _rows.size()) {
|
|
|
|
shift = floorclamp(local.y() - _dragStart.y() + (_rowHeight / 2), _rowHeight, 0, _rows.size() - _dragging - 1);
|
|
|
|
for (int32 from = _dragging, to = _dragging + shift; from < to; ++from) {
|
|
|
|
qSwap(_rows[from], _rows[from + 1]);
|
2016-12-05 11:01:08 +00:00
|
|
|
_rows[from]->yadd = anim::value(_rows[from]->yadd.current() + _rowHeight, 0);
|
2019-04-01 17:44:54 +00:00
|
|
|
_shiftingStartTimes[from] = now;
|
2016-10-20 16:32:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (shift) {
|
|
|
|
_dragging += shift;
|
|
|
|
_above = _dragging;
|
|
|
|
_dragStart.setY(_dragStart.y() + shift * _rowHeight);
|
2019-04-01 17:44:54 +00:00
|
|
|
if (!_shiftingAnimation.animating()) {
|
|
|
|
_shiftingAnimation.start();
|
2016-10-20 16:32:15 +00:00
|
|
|
}
|
|
|
|
}
|
2016-12-05 11:01:08 +00:00
|
|
|
_rows[_dragging]->yadd = anim::value(local.y() - _dragStart.y(), local.y() - _dragStart.y());
|
2019-04-01 17:44:54 +00:00
|
|
|
_shiftingStartTimes[_dragging] = 0;
|
|
|
|
shiftingAnimationCallback(now);
|
2016-10-20 16:32:15 +00:00
|
|
|
|
2020-06-08 17:24:36 +00:00
|
|
|
_draggingScrollDelta.fire_copy([&] {
|
2016-12-13 17:07:56 +00:00
|
|
|
if (local.y() < _visibleTop) {
|
|
|
|
return local.y() - _visibleTop;
|
|
|
|
} else if (local.y() >= _visibleBottom) {
|
|
|
|
return local.y() + 1 - _visibleBottom;
|
|
|
|
}
|
|
|
|
return 0;
|
2020-06-08 17:24:36 +00:00
|
|
|
}());
|
2016-10-20 16:32:15 +00:00
|
|
|
} else {
|
2016-12-13 17:07:56 +00:00
|
|
|
bool in = rect().marginsRemoved(QMargins(0, _itemsTop, 0, st::membersMarginBottom)).contains(local);
|
2017-11-05 17:07:27 +00:00
|
|
|
auto selected = SelectedRow();
|
2016-11-22 09:48:13 +00:00
|
|
|
auto actionSel = -1;
|
|
|
|
auto inDragArea = false;
|
2017-08-05 20:01:20 +00:00
|
|
|
if (in && !_rows.empty()) {
|
2017-11-05 17:07:27 +00:00
|
|
|
auto selectedIndex = floorclamp(local.y() - _itemsTop, _rowHeight, 0, _rows.size() - 1);
|
|
|
|
selected = selectedIndex;
|
|
|
|
local.setY(local.y() - _itemsTop - selectedIndex * _rowHeight);
|
2020-05-28 11:58:50 +00:00
|
|
|
const auto row = _rows[selectedIndex].get();
|
2022-01-24 12:33:31 +00:00
|
|
|
if (!_megagroupSet && (_isInstalled || !row->isInstalled() || row->isArchived() || row->removed)) {
|
2021-03-29 17:37:03 +00:00
|
|
|
auto removeButton = (_isInstalled && !row->removed);
|
2016-11-22 09:48:13 +00:00
|
|
|
auto rect = myrtlrect(relativeButtonRect(removeButton));
|
2017-11-05 17:07:27 +00:00
|
|
|
actionSel = rect.contains(local) ? selectedIndex : -1;
|
2016-10-20 16:32:15 +00:00
|
|
|
} else {
|
2016-11-22 09:48:13 +00:00
|
|
|
actionSel = -1;
|
|
|
|
}
|
2021-03-29 17:37:03 +00:00
|
|
|
if (!_megagroupSet && _isInstalled && !row->isRecentSet()) {
|
2016-11-22 09:48:13 +00:00
|
|
|
auto dragAreaWidth = st::contactsPadding.left() + st::stickersReorderIcon.width() + st::stickersReorderSkip;
|
|
|
|
auto dragArea = myrtlrect(0, 0, dragAreaWidth, _rowHeight);
|
|
|
|
inDragArea = dragArea.contains(local);
|
2016-10-20 16:32:15 +00:00
|
|
|
}
|
2017-11-05 17:07:27 +00:00
|
|
|
} else if (_megagroupSelectedSet) {
|
|
|
|
auto setTop = _megagroupDivider->y() - _rowHeight;
|
|
|
|
if (QRect(0, setTop, width(), _rowHeight).contains(local)) {
|
|
|
|
selected = MegagroupSet();
|
2016-10-20 16:32:15 +00:00
|
|
|
}
|
|
|
|
}
|
2017-11-05 17:07:27 +00:00
|
|
|
setSelected(selected);
|
2016-11-22 09:48:13 +00:00
|
|
|
if (_inDragArea != inDragArea) {
|
|
|
|
_inDragArea = inDragArea;
|
2020-05-28 11:58:50 +00:00
|
|
|
updateCursor();
|
2016-11-22 09:48:13 +00:00
|
|
|
}
|
2016-10-20 16:32:15 +00:00
|
|
|
setActionSel(actionSel);
|
2020-06-08 17:24:36 +00:00
|
|
|
_draggingScrollDelta.fire(0);
|
2016-10-20 16:32:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-28 11:58:50 +00:00
|
|
|
void StickersBox::Inner::updateCursor() {
|
|
|
|
setCursor(_inDragArea
|
|
|
|
? style::cur_sizeall
|
2021-03-29 17:37:03 +00:00
|
|
|
: (!_megagroupSet && _isInstalled)
|
2020-05-28 11:58:50 +00:00
|
|
|
? ((_actionSel >= 0 && (_actionDown < 0 || _actionDown == _actionSel))
|
|
|
|
? style::cur_pointer
|
|
|
|
: style::cur_default)
|
2020-08-31 09:04:17 +00:00
|
|
|
: (!v::is_null(_selected) || !v::is_null(_pressed))
|
2020-05-28 11:58:50 +00:00
|
|
|
? style::cur_pointer
|
|
|
|
: style::cur_default);
|
|
|
|
}
|
|
|
|
|
2016-10-20 16:32:15 +00:00
|
|
|
float64 StickersBox::Inner::aboveShadowOpacity() const {
|
|
|
|
if (_above < 0) return 0;
|
|
|
|
|
2016-12-05 11:01:08 +00:00
|
|
|
auto dx = 0;
|
|
|
|
auto dy = qAbs(_above * _rowHeight + qRound(_rows[_above]->yadd.current()) - _started * _rowHeight);
|
2016-10-20 16:32:15 +00:00
|
|
|
return qMin((dx + dy) * 2. / _rowHeight, 1.);
|
|
|
|
}
|
|
|
|
|
|
|
|
void StickersBox::Inner::mouseReleaseEvent(QMouseEvent *e) {
|
2017-11-05 17:07:27 +00:00
|
|
|
auto pressed = std::exchange(_pressed, SelectedRow());
|
2016-10-20 16:32:15 +00:00
|
|
|
|
2020-05-28 11:58:50 +00:00
|
|
|
updateCursor();
|
2016-10-20 16:32:15 +00:00
|
|
|
|
|
|
|
_mouse = e->globalPos();
|
2020-06-08 17:24:36 +00:00
|
|
|
updateSelected();
|
2016-10-20 16:32:15 +00:00
|
|
|
if (_actionDown == _actionSel && _actionSel >= 0) {
|
2021-03-29 17:37:03 +00:00
|
|
|
if (_isInstalled) {
|
2016-11-22 09:48:13 +00:00
|
|
|
setRowRemoved(_actionDown, !_rows[_actionDown]->removed);
|
|
|
|
} else if (_installSetCallback) {
|
2020-05-28 11:58:50 +00:00
|
|
|
_installSetCallback(_rows[_actionDown]->set->id);
|
2016-10-20 16:32:15 +00:00
|
|
|
}
|
|
|
|
} else if (_dragging >= 0) {
|
2016-12-05 11:01:08 +00:00
|
|
|
_rows[_dragging]->yadd.start(0.);
|
2019-04-01 17:44:54 +00:00
|
|
|
_aboveShadowFadeStart = _shiftingStartTimes[_dragging] = crl::now();
|
2016-12-05 11:01:08 +00:00
|
|
|
_aboveShadowFadeOpacity = anim::value(aboveShadowOpacity(), 0);
|
2019-04-01 17:44:54 +00:00
|
|
|
if (!_shiftingAnimation.animating()) {
|
|
|
|
_shiftingAnimation.start();
|
2016-10-20 16:32:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
_dragging = _started = -1;
|
|
|
|
} else if (pressed == _selected && _actionSel < 0 && _actionDown < 0) {
|
2020-05-28 11:58:50 +00:00
|
|
|
const auto selectedIndex = [&] {
|
2020-08-31 09:04:17 +00:00
|
|
|
if (auto index = std::get_if<int>(&_selected)) {
|
2017-11-05 17:07:27 +00:00
|
|
|
return *index;
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}();
|
2020-05-28 11:58:50 +00:00
|
|
|
const auto showSetByRow = [&](const Row &row) {
|
|
|
|
setSelected(SelectedRow());
|
2021-06-13 07:37:52 +00:00
|
|
|
_controller->show(
|
2022-07-22 11:39:28 +00:00
|
|
|
Box<StickerSetBox>(_controller, row.set),
|
2020-05-28 11:58:50 +00:00
|
|
|
Ui::LayerOption::KeepOther);
|
2017-11-05 17:07:27 +00:00
|
|
|
};
|
|
|
|
if (selectedIndex >= 0 && !_inDragArea) {
|
2020-05-28 11:58:50 +00:00
|
|
|
const auto row = _rows[selectedIndex].get();
|
|
|
|
if (!row->isRecentSet()) {
|
|
|
|
if (_megagroupSet) {
|
2021-07-08 16:42:57 +00:00
|
|
|
setMegagroupSelectedSet(row->set->identifier());
|
2020-05-28 11:58:50 +00:00
|
|
|
} else {
|
|
|
|
showSetByRow(*row);
|
2017-11-05 17:07:27 +00:00
|
|
|
}
|
|
|
|
}
|
2020-08-31 09:04:17 +00:00
|
|
|
} else if (_megagroupSelectedSet && v::is<MegagroupSet>(_selected)) {
|
2017-11-05 17:07:27 +00:00
|
|
|
showSetByRow(*_megagroupSelectedSet);
|
2016-10-20 16:32:15 +00:00
|
|
|
}
|
|
|
|
}
|
2016-11-16 16:04:25 +00:00
|
|
|
setActionDown(-1);
|
2016-10-20 16:32:15 +00:00
|
|
|
}
|
|
|
|
|
2017-08-05 20:01:20 +00:00
|
|
|
void StickersBox::Inner::saveGroupSet() {
|
|
|
|
Expects(_megagroupSet != nullptr);
|
2019-03-22 09:33:13 +00:00
|
|
|
|
2021-07-08 16:42:57 +00:00
|
|
|
auto oldId = _megagroupSet->mgInfo->stickerSet.id;
|
|
|
|
auto newId = _megagroupSetInput.id;
|
2017-08-05 20:01:20 +00:00
|
|
|
if (newId != oldId) {
|
2020-06-23 17:21:58 +00:00
|
|
|
session().api().setGroupStickerSet(_megagroupSet, _megagroupSetInput);
|
2021-03-29 22:28:19 +00:00
|
|
|
session().data().stickers().notifyStickerSetInstalled(
|
|
|
|
Data::Stickers::MegagroupSetId);
|
2017-08-05 20:01:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-22 09:48:13 +00:00
|
|
|
void StickersBox::Inner::setRowRemoved(int index, bool removed) {
|
2017-08-05 20:01:20 +00:00
|
|
|
auto &row = _rows[index];
|
2016-11-22 09:48:13 +00:00
|
|
|
if (row->removed != removed) {
|
|
|
|
row->removed = removed;
|
|
|
|
row->ripple.reset();
|
|
|
|
update(0, _itemsTop + index * _rowHeight, width(), _rowHeight);
|
2020-06-08 17:24:36 +00:00
|
|
|
updateSelected();
|
2016-10-20 16:32:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-02-11 11:24:37 +00:00
|
|
|
void StickersBox::Inner::leaveEventHook(QEvent *e) {
|
2016-11-22 09:48:13 +00:00
|
|
|
_mouse = QPoint(-1, -1);
|
2020-06-08 17:24:36 +00:00
|
|
|
updateSelected();
|
2016-10-20 16:32:15 +00:00
|
|
|
}
|
|
|
|
|
2017-08-05 20:01:20 +00:00
|
|
|
void StickersBox::Inner::leaveToChildEvent(QEvent *e, QWidget *child) {
|
|
|
|
_mouse = QPoint(-1, -1);
|
2020-06-08 17:24:36 +00:00
|
|
|
updateSelected();
|
2017-08-05 20:01:20 +00:00
|
|
|
}
|
|
|
|
|
2019-04-01 17:44:54 +00:00
|
|
|
bool StickersBox::Inner::shiftingAnimationCallback(crl::time now) {
|
2018-09-20 16:39:59 +00:00
|
|
|
if (anim::Disabled()) {
|
2019-04-01 17:44:54 +00:00
|
|
|
now += st::stickersRowDuration;
|
2018-09-20 16:39:59 +00:00
|
|
|
}
|
2016-12-01 19:20:33 +00:00
|
|
|
auto animating = false;
|
|
|
|
auto updateMin = -1;
|
|
|
|
auto updateMax = 0;
|
2019-04-01 17:44:54 +00:00
|
|
|
for (auto i = 0, count = int(_shiftingStartTimes.size()); i != count; ++i) {
|
|
|
|
const auto start = _shiftingStartTimes[i];
|
2016-10-20 16:32:15 +00:00
|
|
|
if (start) {
|
2019-04-01 17:44:54 +00:00
|
|
|
if (updateMin < 0) {
|
|
|
|
updateMin = i;
|
|
|
|
}
|
2016-10-20 16:32:15 +00:00
|
|
|
updateMax = i;
|
2019-04-01 17:44:54 +00:00
|
|
|
if (start + st::stickersRowDuration > now && now >= start) {
|
|
|
|
_rows[i]->yadd.update(float64(now - start) / st::stickersRowDuration, anim::sineInOut);
|
2016-10-20 16:32:15 +00:00
|
|
|
animating = true;
|
|
|
|
} else {
|
2016-12-05 11:01:08 +00:00
|
|
|
_rows[i]->yadd.finish();
|
2019-04-01 17:44:54 +00:00
|
|
|
_shiftingStartTimes[i] = 0;
|
2016-10-20 16:32:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (_aboveShadowFadeStart) {
|
|
|
|
if (updateMin < 0 || updateMin > _above) updateMin = _above;
|
|
|
|
if (updateMax < _above) updateMin = _above;
|
2019-04-01 17:44:54 +00:00
|
|
|
if (_aboveShadowFadeStart + st::stickersRowDuration > now && now > _aboveShadowFadeStart) {
|
|
|
|
_aboveShadowFadeOpacity.update(float64(now - _aboveShadowFadeStart) / st::stickersRowDuration, anim::sineInOut);
|
2016-10-20 16:32:15 +00:00
|
|
|
animating = true;
|
|
|
|
} else {
|
|
|
|
_aboveShadowFadeOpacity.finish();
|
|
|
|
_aboveShadowFadeStart = 0;
|
|
|
|
}
|
|
|
|
}
|
2019-04-01 17:44:54 +00:00
|
|
|
if (_dragging >= 0) {
|
|
|
|
if (updateMin < 0 || updateMin > _dragging) {
|
|
|
|
updateMin = _dragging;
|
2016-10-20 16:32:15 +00:00
|
|
|
}
|
2019-04-01 17:44:54 +00:00
|
|
|
if (updateMax < _dragging) updateMax = _dragging;
|
|
|
|
}
|
|
|
|
if (updateMin == 1 && _rows[0]->isRecentSet()) {
|
|
|
|
updateMin = 0; // Repaint from the very top of the content.
|
|
|
|
}
|
|
|
|
if (updateMin >= 0) {
|
|
|
|
update(0, _itemsTop + _rowHeight * (updateMin - 1), width(), _rowHeight * (updateMax - updateMin + 3));
|
2016-10-20 16:32:15 +00:00
|
|
|
}
|
|
|
|
if (!animating) {
|
|
|
|
_above = _dragging;
|
|
|
|
}
|
2019-04-01 17:44:54 +00:00
|
|
|
return animating;
|
2016-10-20 16:32:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void StickersBox::Inner::clear() {
|
|
|
|
_rows.clear();
|
2019-04-01 17:44:54 +00:00
|
|
|
_shiftingStartTimes.clear();
|
2016-10-20 16:32:15 +00:00
|
|
|
_aboveShadowFadeStart = 0;
|
2016-12-05 11:01:08 +00:00
|
|
|
_aboveShadowFadeOpacity = anim::value();
|
2019-04-01 17:44:54 +00:00
|
|
|
_shiftingAnimation.stop();
|
2016-10-20 16:32:15 +00:00
|
|
|
_above = _dragging = _started = -1;
|
2017-11-05 17:07:27 +00:00
|
|
|
setSelected(SelectedRow());
|
|
|
|
setPressed(SelectedRow());
|
2016-10-20 16:32:15 +00:00
|
|
|
setActionSel(-1);
|
2017-08-05 20:01:20 +00:00
|
|
|
setActionDown(-1);
|
2016-10-20 16:32:15 +00:00
|
|
|
update();
|
|
|
|
}
|
|
|
|
|
|
|
|
void StickersBox::Inner::setActionSel(int32 actionSel) {
|
|
|
|
if (actionSel != _actionSel) {
|
|
|
|
if (_actionSel >= 0) update(0, _itemsTop + _actionSel * _rowHeight, width(), _rowHeight);
|
|
|
|
_actionSel = actionSel;
|
|
|
|
if (_actionSel >= 0) update(0, _itemsTop + _actionSel * _rowHeight, width(), _rowHeight);
|
2020-05-28 11:58:50 +00:00
|
|
|
updateCursor();
|
2016-10-20 16:32:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-05 17:07:27 +00:00
|
|
|
void StickersBox::Inner::AddressField::correctValue(
|
|
|
|
const QString &was,
|
|
|
|
int wasCursor,
|
|
|
|
QString &now,
|
|
|
|
int &nowCursor) {
|
|
|
|
auto newText = now;
|
|
|
|
auto newCursor = nowCursor;
|
|
|
|
auto removeFromBeginning = {
|
|
|
|
qstr("http://"),
|
|
|
|
qstr("https://"),
|
|
|
|
qstr("www.t.me/"),
|
|
|
|
qstr("www.telegram.me/"),
|
|
|
|
qstr("www.telegram.dog/"),
|
|
|
|
qstr("t.me/"),
|
|
|
|
qstr("telegram.me/"),
|
|
|
|
qstr("telegram.dog/"),
|
|
|
|
qstr("addstickers/"),
|
|
|
|
};
|
|
|
|
for (auto &removePhrase : removeFromBeginning) {
|
|
|
|
if (newText.startsWith(removePhrase)) {
|
|
|
|
newText = newText.mid(removePhrase.size());
|
|
|
|
newCursor = newText.size();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
setCorrectedText(now, nowCursor, newText, newCursor);
|
|
|
|
}
|
|
|
|
|
2017-08-05 20:01:20 +00:00
|
|
|
void StickersBox::Inner::handleMegagroupSetAddressChange() {
|
|
|
|
auto text = _megagroupSetField->getLastText().trimmed();
|
|
|
|
if (text.isEmpty()) {
|
|
|
|
if (_megagroupSelectedSet) {
|
2020-06-23 17:21:58 +00:00
|
|
|
const auto &sets = session().data().stickers().sets();
|
2020-05-28 11:58:50 +00:00
|
|
|
const auto it = sets.find(_megagroupSelectedSet->set->id);
|
2020-05-28 10:00:51 +00:00
|
|
|
if (it != sets.cend() && !it->second->shortName.isEmpty()) {
|
2021-07-08 16:42:57 +00:00
|
|
|
setMegagroupSelectedSet({});
|
2017-08-05 20:01:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (!_megagroupSetRequestId) {
|
2019-11-27 08:02:56 +00:00
|
|
|
_megagroupSetRequestId = _api.request(MTPmessages_GetStickerSet(
|
2021-11-19 19:04:40 +00:00
|
|
|
MTP_inputStickerSetShortName(MTP_string(text)),
|
|
|
|
MTP_int(0) // hash
|
2019-11-27 08:02:56 +00:00
|
|
|
)).done([=](const MTPmessages_StickerSet &result) {
|
2017-08-05 20:01:20 +00:00
|
|
|
_megagroupSetRequestId = 0;
|
2021-11-19 19:04:40 +00:00
|
|
|
result.match([&](const MTPDmessages_stickerSet &data) {
|
|
|
|
const auto set = session().data().stickers().feedSetFull(data);
|
|
|
|
setMegagroupSelectedSet(set->identifier());
|
|
|
|
}, [](const MTPDmessages_stickerSetNotModified &) {
|
|
|
|
LOG(("API Error: Unexpected messages.stickerSetNotModified."));
|
|
|
|
});
|
2021-11-26 20:46:53 +00:00
|
|
|
}).fail([=] {
|
2017-08-05 20:01:20 +00:00
|
|
|
_megagroupSetRequestId = 0;
|
2021-07-08 16:42:57 +00:00
|
|
|
setMegagroupSelectedSet({});
|
2017-08-05 20:01:20 +00:00
|
|
|
}).send();
|
|
|
|
} else {
|
|
|
|
_megagroupSetAddressChangedTimer.callOnce(kHandleMegagroupSetAddressChangeTimeout);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void StickersBox::Inner::rebuildMegagroupSet() {
|
|
|
|
Expects(_megagroupSet != nullptr);
|
2021-07-08 16:42:57 +00:00
|
|
|
|
2021-09-01 10:45:32 +00:00
|
|
|
const auto clearCurrent = [&] {
|
2017-08-05 20:01:20 +00:00
|
|
|
if (_megagroupSelectedSet) {
|
|
|
|
_megagroupSetField->setText(QString());
|
2017-09-30 19:20:40 +00:00
|
|
|
_megagroupSetField->finishAnimating();
|
2017-08-05 20:01:20 +00:00
|
|
|
}
|
2021-09-01 10:45:32 +00:00
|
|
|
_megagroupSelectedSet = nullptr;
|
2017-08-05 20:01:20 +00:00
|
|
|
_megagroupSelectedRemove.destroy();
|
|
|
|
_megagroupSelectedShadow.destroy();
|
2021-09-01 10:45:32 +00:00
|
|
|
};
|
|
|
|
if (!_megagroupSetInput.id) {
|
|
|
|
clearCurrent();
|
2017-08-05 20:01:20 +00:00
|
|
|
return;
|
|
|
|
}
|
2021-07-08 16:42:57 +00:00
|
|
|
auto setId = _megagroupSetInput.id;
|
2020-06-23 17:21:58 +00:00
|
|
|
const auto &sets = session().data().stickers().sets();
|
2017-08-05 20:01:20 +00:00
|
|
|
auto it = sets.find(setId);
|
2020-05-28 10:00:51 +00:00
|
|
|
if (it == sets.cend()
|
2021-07-09 06:08:58 +00:00
|
|
|
|| (it->second->flags & SetFlag::NotLoaded)) {
|
2021-09-01 10:45:32 +00:00
|
|
|
// It may have been in sets and stored in _megagroupSelectedSet
|
|
|
|
// already, but then removed from sets. We need to clear the stored
|
|
|
|
// pointer, otherwise we may crash in paint event while loading.
|
|
|
|
clearCurrent();
|
2020-06-23 17:21:58 +00:00
|
|
|
session().api().scheduleStickerSetRequest(
|
2021-07-08 16:42:57 +00:00
|
|
|
_megagroupSetInput.id,
|
|
|
|
_megagroupSetInput.accessHash);
|
2017-08-05 20:01:20 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-05-28 10:00:51 +00:00
|
|
|
const auto set = it->second.get();
|
2017-08-05 20:01:20 +00:00
|
|
|
auto maxNameWidth = countMaxNameWidth();
|
|
|
|
auto titleWidth = 0;
|
2020-05-28 11:58:50 +00:00
|
|
|
auto title = fillSetTitle(set, maxNameWidth, &titleWidth);
|
|
|
|
auto count = fillSetCount(set);
|
2017-08-05 20:01:20 +00:00
|
|
|
auto sticker = (DocumentData*)nullptr;
|
|
|
|
auto pixw = 0, pixh = 0;
|
2020-05-28 11:58:50 +00:00
|
|
|
fillSetCover(set, &sticker, &pixw, &pixh);
|
2022-01-24 12:33:31 +00:00
|
|
|
auto flagsOverride = SetFlag::Installed;
|
|
|
|
auto removed = false;
|
|
|
|
if (!_megagroupSelectedSet
|
|
|
|
|| _megagroupSelectedSet->set->id != set->id) {
|
2020-05-28 10:00:51 +00:00
|
|
|
_megagroupSetField->setText(set->shortName);
|
2017-09-30 19:20:40 +00:00
|
|
|
_megagroupSetField->finishAnimating();
|
2017-08-05 20:01:20 +00:00
|
|
|
}
|
2018-07-13 21:25:47 +00:00
|
|
|
_megagroupSelectedSet = std::make_unique<Row>(
|
2020-05-28 11:58:50 +00:00
|
|
|
set,
|
2018-07-13 21:25:47 +00:00
|
|
|
sticker,
|
|
|
|
count,
|
|
|
|
title,
|
|
|
|
titleWidth,
|
2022-01-24 12:33:31 +00:00
|
|
|
flagsOverride,
|
2018-07-13 21:25:47 +00:00
|
|
|
removed,
|
|
|
|
pixw,
|
|
|
|
pixh);
|
2017-08-05 20:01:20 +00:00
|
|
|
_itemsTop += st::lineWidth + _rowHeight;
|
|
|
|
|
|
|
|
if (!_megagroupSelectedRemove) {
|
|
|
|
_megagroupSelectedRemove.create(this, st::groupStickersRemove);
|
2017-11-27 11:43:57 +00:00
|
|
|
_megagroupSelectedRemove->show(anim::type::instant);
|
2017-08-05 20:01:20 +00:00
|
|
|
_megagroupSelectedRemove->setClickedCallback([this] {
|
2021-07-08 16:42:57 +00:00
|
|
|
setMegagroupSelectedSet({});
|
2017-08-05 20:01:20 +00:00
|
|
|
});
|
|
|
|
_megagroupSelectedShadow.create(this);
|
|
|
|
updateControlsGeometry();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-03-30 15:51:45 +00:00
|
|
|
void StickersBox::Inner::rebuild(bool masks) {
|
2016-12-13 17:07:56 +00:00
|
|
|
_itemsTop = st::membersMarginTop;
|
2016-10-20 16:32:15 +00:00
|
|
|
|
2017-08-05 20:01:20 +00:00
|
|
|
if (_megagroupSet) {
|
|
|
|
_itemsTop += st::groupStickersFieldPadding.top() + _megagroupSetField->height() + st::groupStickersFieldPadding.bottom();
|
|
|
|
_itemsTop += _megagroupDivider->height() + st::groupStickersSubTitleHeight;
|
|
|
|
rebuildMegagroupSet();
|
|
|
|
}
|
|
|
|
|
|
|
|
auto maxNameWidth = countMaxNameWidth();
|
2016-10-20 16:32:15 +00:00
|
|
|
|
2021-12-31 14:08:34 +00:00
|
|
|
_oldRows = std::move(_rows);
|
2016-10-20 16:32:15 +00:00
|
|
|
clear();
|
2020-06-08 17:24:36 +00:00
|
|
|
const auto &order = ([&]() -> const StickersSetsOrder & {
|
2016-10-20 16:32:15 +00:00
|
|
|
if (_section == Section::Installed) {
|
2020-06-23 17:21:58 +00:00
|
|
|
auto &result = session().data().stickers().setsOrder();
|
2017-11-22 09:03:36 +00:00
|
|
|
if (_megagroupSet && result.empty()) {
|
2020-06-23 17:21:58 +00:00
|
|
|
return session().data().stickers().featuredSetsOrder();
|
2017-11-22 09:03:36 +00:00
|
|
|
}
|
|
|
|
return result;
|
2021-03-29 17:37:03 +00:00
|
|
|
} else if (_section == Section::Masks) {
|
|
|
|
return session().data().stickers().maskSetsOrder();
|
2016-10-20 16:32:15 +00:00
|
|
|
} else if (_section == Section::Featured) {
|
2020-06-23 17:21:58 +00:00
|
|
|
return session().data().stickers().featuredSetsOrder();
|
2016-10-20 16:32:15 +00:00
|
|
|
}
|
2021-03-30 15:51:45 +00:00
|
|
|
return masks
|
|
|
|
? session().data().stickers().archivedMaskSetsOrder()
|
|
|
|
: session().data().stickers().archivedSetsOrder();
|
2016-10-20 16:32:15 +00:00
|
|
|
})();
|
|
|
|
_rows.reserve(order.size() + 1);
|
2019-04-01 17:44:54 +00:00
|
|
|
_shiftingStartTimes.reserve(order.size() + 1);
|
2016-10-20 16:32:15 +00:00
|
|
|
|
2020-06-23 17:21:58 +00:00
|
|
|
const auto &sets = session().data().stickers().sets();
|
2017-11-22 09:03:36 +00:00
|
|
|
if (_megagroupSet) {
|
2020-06-23 17:21:58 +00:00
|
|
|
auto usingFeatured = session().data().stickers().setsOrder().empty();
|
2019-06-19 15:09:03 +00:00
|
|
|
_megagroupSubTitle->setText(usingFeatured
|
|
|
|
? tr::lng_stickers_group_from_featured(tr::now)
|
|
|
|
: tr::lng_stickers_group_from_your(tr::now));
|
2017-11-22 09:03:36 +00:00
|
|
|
updateControlsGeometry();
|
2021-03-29 17:37:03 +00:00
|
|
|
} else if (_isInstalled) {
|
|
|
|
const auto cloudIt = sets.find((_section == Section::Masks)
|
|
|
|
? Data::Stickers::CloudRecentAttachedSetId
|
|
|
|
: Data::Stickers::CloudRecentSetId); // Section::Installed.
|
2020-05-28 10:00:51 +00:00
|
|
|
if (cloudIt != sets.cend() && !cloudIt->second->stickers.isEmpty()) {
|
2020-05-28 11:58:50 +00:00
|
|
|
rebuildAppendSet(cloudIt->second.get(), maxNameWidth);
|
2016-10-20 16:32:15 +00:00
|
|
|
}
|
|
|
|
}
|
2020-05-28 10:00:51 +00:00
|
|
|
for (const auto setId : order) {
|
|
|
|
auto it = sets.find(setId);
|
2016-10-20 16:32:15 +00:00
|
|
|
if (it == sets.cend()) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2020-05-28 10:00:51 +00:00
|
|
|
const auto set = it->second.get();
|
2020-05-28 11:58:50 +00:00
|
|
|
rebuildAppendSet(set, maxNameWidth);
|
2016-10-20 16:32:15 +00:00
|
|
|
|
2020-05-28 10:00:51 +00:00
|
|
|
if (set->stickers.isEmpty()
|
2021-07-09 06:08:58 +00:00
|
|
|
|| (set->flags & SetFlag::NotLoaded)) {
|
2021-08-25 08:15:05 +00:00
|
|
|
session().api().scheduleStickerSetRequest(
|
|
|
|
set->id,
|
|
|
|
set->accessHash);
|
2016-10-20 16:32:15 +00:00
|
|
|
}
|
|
|
|
}
|
2021-12-31 14:08:34 +00:00
|
|
|
_oldRows.clear();
|
2020-06-23 17:21:58 +00:00
|
|
|
session().api().requestStickerSets();
|
2016-10-20 16:32:15 +00:00
|
|
|
updateSize();
|
|
|
|
}
|
|
|
|
|
2021-08-25 08:15:05 +00:00
|
|
|
void StickersBox::Inner::setMegagroupSelectedSet(
|
|
|
|
const StickerSetIdentifier &set) {
|
2017-08-05 20:01:20 +00:00
|
|
|
_megagroupSetInput = set;
|
2021-03-30 15:51:45 +00:00
|
|
|
rebuild(false);
|
2021-05-25 10:14:12 +00:00
|
|
|
_scrollsToY.fire(0);
|
2020-06-08 17:24:36 +00:00
|
|
|
updateSelected();
|
2017-08-05 20:01:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void StickersBox::Inner::setMinHeight(int newWidth, int minHeight) {
|
|
|
|
_minHeight = minHeight;
|
|
|
|
updateSize(newWidth);
|
|
|
|
}
|
|
|
|
|
|
|
|
void StickersBox::Inner::updateSize(int newWidth) {
|
|
|
|
auto naturalHeight = _itemsTop + int(_rows.size()) * _rowHeight + st::membersMarginBottom;
|
|
|
|
resize(newWidth ? newWidth : width(), qMax(_minHeight, naturalHeight));
|
2017-11-22 09:03:36 +00:00
|
|
|
updateControlsGeometry();
|
2016-12-13 17:07:56 +00:00
|
|
|
checkLoadMore();
|
2016-10-20 16:32:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void StickersBox::Inner::updateRows() {
|
|
|
|
int maxNameWidth = countMaxNameWidth();
|
2020-06-23 17:21:58 +00:00
|
|
|
const auto &sets = session().data().stickers().sets();
|
2019-07-02 13:20:04 +00:00
|
|
|
for (const auto &row : _rows) {
|
2020-05-28 11:58:50 +00:00
|
|
|
const auto it = sets.find(row->set->id);
|
2019-07-02 13:20:04 +00:00
|
|
|
if (it == sets.cend()) {
|
|
|
|
continue;
|
|
|
|
}
|
2020-05-28 10:00:51 +00:00
|
|
|
const auto set = it->second.get();
|
2019-07-02 13:20:04 +00:00
|
|
|
if (!row->sticker) {
|
|
|
|
auto sticker = (DocumentData*)nullptr;
|
|
|
|
auto pixw = 0, pixh = 0;
|
2020-05-28 11:58:50 +00:00
|
|
|
fillSetCover(set, &sticker, &pixw, &pixh);
|
2019-07-02 13:20:04 +00:00
|
|
|
if (sticker) {
|
2020-05-28 11:58:50 +00:00
|
|
|
if (row->sticker != sticker && !row->thumbnailMedia) {
|
2019-07-02 13:20:04 +00:00
|
|
|
row->lottie = nullptr;
|
2020-05-28 11:58:50 +00:00
|
|
|
row->stickerMedia = nullptr;
|
2016-10-20 16:32:15 +00:00
|
|
|
}
|
2019-07-02 13:20:04 +00:00
|
|
|
row->sticker = sticker;
|
|
|
|
row->pixw = pixw;
|
|
|
|
row->pixh = pixh;
|
2016-10-20 16:32:15 +00:00
|
|
|
}
|
2019-07-02 13:20:04 +00:00
|
|
|
}
|
|
|
|
if (!row->isRecentSet()) {
|
2022-01-24 12:33:31 +00:00
|
|
|
auto wasInstalled = row->isInstalled();
|
|
|
|
auto wasArchived = row->isArchived();
|
|
|
|
row->flagsOverride = fillSetFlags(set);
|
2021-03-29 17:37:03 +00:00
|
|
|
if (_isInstalled) {
|
2022-01-24 12:33:31 +00:00
|
|
|
row->flagsOverride &= ~SetFlag::Archived;
|
2019-07-02 13:20:04 +00:00
|
|
|
}
|
2022-01-24 12:33:31 +00:00
|
|
|
if (row->isInstalled() != wasInstalled
|
|
|
|
|| row->isArchived() != wasArchived) {
|
2019-07-02 13:20:04 +00:00
|
|
|
row->ripple.reset();
|
2016-10-20 16:32:15 +00:00
|
|
|
}
|
|
|
|
}
|
2020-05-28 11:58:50 +00:00
|
|
|
row->title = fillSetTitle(set, maxNameWidth, &row->titleWidth);
|
|
|
|
row->count = fillSetCount(set);
|
2016-10-20 16:32:15 +00:00
|
|
|
}
|
|
|
|
update();
|
|
|
|
}
|
|
|
|
|
2020-06-08 17:24:36 +00:00
|
|
|
bool StickersBox::Inner::appendSet(not_null<StickersSet*> set) {
|
2020-05-28 11:58:50 +00:00
|
|
|
for (const auto &row : _rows) {
|
|
|
|
if (row->set == set) {
|
2016-10-20 16:32:15 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
rebuildAppendSet(set, countMaxNameWidth());
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2022-06-08 06:28:45 +00:00
|
|
|
bool StickersBox::Inner::skipPremium() const {
|
|
|
|
return !_controller->session().premiumPossible();
|
|
|
|
}
|
|
|
|
|
2016-10-20 16:32:15 +00:00
|
|
|
int StickersBox::Inner::countMaxNameWidth() const {
|
|
|
|
int namex = st::contactsPadding.left() + st::contactsPhotoSize + st::contactsPadding.left();
|
2021-03-29 17:37:03 +00:00
|
|
|
if (!_megagroupSet && _isInstalled) {
|
2017-11-05 17:07:27 +00:00
|
|
|
namex += st::stickersReorderIcon.width() + st::stickersReorderSkip;
|
|
|
|
}
|
2016-10-20 16:32:15 +00:00
|
|
|
int namew = st::boxWideWidth - namex - st::contactsPadding.right() - st::contactsCheckPosition.x();
|
2021-03-29 17:37:03 +00:00
|
|
|
if (_isInstalled) {
|
2017-11-05 17:07:27 +00:00
|
|
|
if (!_megagroupSet) {
|
|
|
|
namew -= _undoWidth - st::stickersUndoRemove.width;
|
|
|
|
}
|
2016-10-20 16:32:15 +00:00
|
|
|
} else {
|
2016-11-22 09:48:13 +00:00
|
|
|
namew -= _addWidth - st::stickersTrendingAdd.width;
|
|
|
|
if (_section == Section::Featured) {
|
|
|
|
namew -= st::stickersFeaturedUnreadSize + st::stickersFeaturedUnreadSkip;
|
|
|
|
}
|
2016-10-20 16:32:15 +00:00
|
|
|
}
|
|
|
|
return namew;
|
|
|
|
}
|
|
|
|
|
2020-05-28 11:58:50 +00:00
|
|
|
void StickersBox::Inner::rebuildAppendSet(
|
2020-06-08 17:24:36 +00:00
|
|
|
not_null<StickersSet*> set,
|
2020-05-28 11:58:50 +00:00
|
|
|
int maxNameWidth) {
|
2022-01-24 12:33:31 +00:00
|
|
|
auto flagsOverride = (set->id != Data::Stickers::CloudRecentSetId)
|
|
|
|
? fillSetFlags(set)
|
|
|
|
: SetFlag::Installed;
|
|
|
|
auto removed = false;
|
|
|
|
if (_isInstalled && (flagsOverride & SetFlag::Archived)) {
|
2016-10-20 16:32:15 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
DocumentData *sticker = nullptr;
|
|
|
|
int pixw = 0, pixh = 0;
|
2020-05-28 11:58:50 +00:00
|
|
|
fillSetCover(set, &sticker, &pixw, &pixh);
|
2016-10-20 16:32:15 +00:00
|
|
|
|
|
|
|
int titleWidth = 0;
|
|
|
|
QString title = fillSetTitle(set, maxNameWidth, &titleWidth);
|
|
|
|
int count = fillSetCount(set);
|
|
|
|
|
2021-12-31 14:08:34 +00:00
|
|
|
const auto existing = [&]{
|
|
|
|
const auto now = int(_rows.size());
|
|
|
|
const auto setProj = [](const std::unique_ptr<Row> &row) {
|
|
|
|
return row ? row->set.get() : nullptr;
|
|
|
|
};
|
|
|
|
if (_oldRows.size() > now
|
|
|
|
&& setProj(_oldRows[now]) == set.get()) {
|
|
|
|
return _oldRows.begin() + now;
|
|
|
|
}
|
|
|
|
return ranges::find(_oldRows, set.get(), setProj);
|
|
|
|
}();
|
|
|
|
if (existing != end(_oldRows)) {
|
|
|
|
const auto raw = existing->get();
|
|
|
|
raw->sticker = sticker;
|
|
|
|
raw->count = count;
|
|
|
|
raw->title = title;
|
|
|
|
raw->titleWidth = titleWidth;
|
2022-01-24 12:33:31 +00:00
|
|
|
raw->flagsOverride = flagsOverride;
|
2021-12-31 14:08:34 +00:00
|
|
|
raw->removed = removed;
|
|
|
|
raw->pixw = pixw;
|
|
|
|
raw->pixh = pixh;
|
|
|
|
raw->yadd = {};
|
|
|
|
auto oldStickerMedia = std::move(raw->stickerMedia);
|
|
|
|
auto oldThumbnailMedia = std::move(raw->thumbnailMedia);
|
2022-01-19 15:52:01 +00:00
|
|
|
raw->stickerMedia = sticker ? sticker->activeMediaView() : nullptr;
|
2021-12-31 14:08:34 +00:00
|
|
|
raw->thumbnailMedia = set->activeThumbnailView();
|
|
|
|
if (raw->thumbnailMedia != oldThumbnailMedia
|
|
|
|
|| (!raw->thumbnailMedia && raw->stickerMedia != oldStickerMedia)) {
|
|
|
|
raw->lottie = nullptr;
|
|
|
|
}
|
|
|
|
_rows.push_back(std::move(*existing));
|
|
|
|
} else {
|
|
|
|
_rows.push_back(std::make_unique<Row>(
|
|
|
|
set,
|
|
|
|
sticker,
|
|
|
|
count,
|
|
|
|
title,
|
|
|
|
titleWidth,
|
2022-01-24 12:33:31 +00:00
|
|
|
flagsOverride,
|
2021-12-31 14:08:34 +00:00
|
|
|
removed,
|
|
|
|
pixw,
|
|
|
|
pixh));
|
|
|
|
}
|
2019-04-01 17:44:54 +00:00
|
|
|
_shiftingStartTimes.push_back(0);
|
2016-10-20 16:32:15 +00:00
|
|
|
}
|
|
|
|
|
2020-05-28 11:58:50 +00:00
|
|
|
void StickersBox::Inner::fillSetCover(
|
2020-06-08 17:24:36 +00:00
|
|
|
not_null<StickersSet*> set,
|
2020-05-28 11:58:50 +00:00
|
|
|
DocumentData **outSticker,
|
|
|
|
int *outWidth,
|
|
|
|
int *outHeight) const {
|
|
|
|
if (set->stickers.isEmpty()) {
|
2016-10-20 16:32:15 +00:00
|
|
|
*outSticker = nullptr;
|
|
|
|
*outWidth = *outHeight = 0;
|
|
|
|
return;
|
|
|
|
}
|
2020-05-28 11:58:50 +00:00
|
|
|
auto sticker = *outSticker = set->stickers.front();
|
2016-10-20 16:32:15 +00:00
|
|
|
|
2020-05-28 11:58:50 +00:00
|
|
|
const auto size = set->hasThumbnail()
|
2020-05-28 10:00:51 +00:00
|
|
|
? QSize(
|
2020-05-28 11:58:50 +00:00
|
|
|
set->thumbnailLocation().width(),
|
|
|
|
set->thumbnailLocation().height())
|
2020-04-15 14:06:34 +00:00
|
|
|
: sticker->hasThumbnail()
|
|
|
|
? QSize(
|
|
|
|
sticker->thumbnailLocation().width(),
|
|
|
|
sticker->thumbnailLocation().height())
|
2019-01-25 14:37:28 +00:00
|
|
|
: QSize(1, 1);
|
|
|
|
auto pixw = size.width();
|
|
|
|
auto pixh = size.height();
|
2016-10-20 16:32:15 +00:00
|
|
|
if (pixw > st::contactsPhotoSize) {
|
|
|
|
if (pixw > pixh) {
|
|
|
|
pixh = (pixh * st::contactsPhotoSize) / pixw;
|
|
|
|
pixw = st::contactsPhotoSize;
|
|
|
|
} else {
|
|
|
|
pixw = (pixw * st::contactsPhotoSize) / pixh;
|
|
|
|
pixh = st::contactsPhotoSize;
|
|
|
|
}
|
|
|
|
} else if (pixh > st::contactsPhotoSize) {
|
|
|
|
pixw = (pixw * st::contactsPhotoSize) / pixh;
|
|
|
|
pixh = st::contactsPhotoSize;
|
|
|
|
}
|
|
|
|
*outWidth = pixw;
|
|
|
|
*outHeight = pixh;
|
|
|
|
}
|
|
|
|
|
2020-06-08 17:24:36 +00:00
|
|
|
int StickersBox::Inner::fillSetCount(not_null<StickersSet*> set) const {
|
2022-06-08 06:28:45 +00:00
|
|
|
const auto skipPremium = this->skipPremium();
|
2020-05-28 11:58:50 +00:00
|
|
|
int result = set->stickers.isEmpty()
|
|
|
|
? set->count
|
|
|
|
: set->stickers.size();
|
2022-06-08 06:28:45 +00:00
|
|
|
if (skipPremium && !set->stickers.isEmpty()) {
|
|
|
|
result -= ranges::count(
|
|
|
|
set->stickers,
|
|
|
|
true,
|
|
|
|
&DocumentData::isPremiumSticker);
|
|
|
|
}
|
2020-05-28 11:58:50 +00:00
|
|
|
auto added = 0;
|
2020-06-08 17:24:36 +00:00
|
|
|
if (set->id == Data::Stickers::CloudRecentSetId) {
|
2020-06-23 17:21:58 +00:00
|
|
|
const auto &sets = session().data().stickers().sets();
|
2022-06-08 06:28:45 +00:00
|
|
|
const auto &recent = session().data().stickers().getRecentPack();
|
2020-06-08 17:24:36 +00:00
|
|
|
auto customIt = sets.find(Data::Stickers::CustomSetId);
|
2020-05-28 10:00:51 +00:00
|
|
|
if (customIt != sets.cend()) {
|
2022-06-08 06:28:45 +00:00
|
|
|
auto &custom = customIt->second->stickers;
|
|
|
|
added = custom.size();
|
|
|
|
if (skipPremium) {
|
|
|
|
added -= ranges::count(
|
|
|
|
custom,
|
|
|
|
true,
|
|
|
|
&DocumentData::isPremiumSticker);
|
|
|
|
}
|
2020-05-28 10:00:51 +00:00
|
|
|
for (const auto &sticker : recent) {
|
2022-06-08 06:28:45 +00:00
|
|
|
if (skipPremium && sticker.first->isPremiumSticker()) {
|
|
|
|
continue;
|
|
|
|
} else if (customIt->second->stickers.indexOf(sticker.first) < 0) {
|
2016-10-20 16:32:15 +00:00
|
|
|
++added;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
2022-06-08 06:28:45 +00:00
|
|
|
added = recent.size();
|
2016-10-20 16:32:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return result + added;
|
|
|
|
}
|
|
|
|
|
2020-05-28 11:58:50 +00:00
|
|
|
QString StickersBox::Inner::fillSetTitle(
|
2020-06-08 17:24:36 +00:00
|
|
|
not_null<StickersSet*> set,
|
2020-05-28 11:58:50 +00:00
|
|
|
int maxNameWidth,
|
|
|
|
int *outTitleWidth) const {
|
|
|
|
auto result = set->title;
|
2016-12-23 13:21:01 +00:00
|
|
|
int titleWidth = st::contactsNameStyle.font->width(result);
|
2016-10-20 16:32:15 +00:00
|
|
|
if (titleWidth > maxNameWidth) {
|
2016-12-23 13:21:01 +00:00
|
|
|
result = st::contactsNameStyle.font->elided(result, maxNameWidth);
|
|
|
|
titleWidth = st::contactsNameStyle.font->width(result);
|
2016-10-20 16:32:15 +00:00
|
|
|
}
|
|
|
|
if (outTitleWidth) {
|
|
|
|
*outTitleWidth = titleWidth;
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2022-01-24 12:33:31 +00:00
|
|
|
Data::StickersSetFlags StickersBox::Inner::fillSetFlags(
|
|
|
|
not_null<StickersSet*> set) const {
|
|
|
|
const auto result = set->flags;
|
|
|
|
return (_section == Section::Featured)
|
|
|
|
? result
|
|
|
|
: (result & ~SetFlag::Unread);
|
2016-10-20 16:32:15 +00:00
|
|
|
}
|
|
|
|
|
2016-11-22 09:48:13 +00:00
|
|
|
template <typename Check>
|
2020-06-08 17:24:36 +00:00
|
|
|
StickersSetsOrder StickersBox::Inner::collectSets(Check check) const {
|
|
|
|
StickersSetsOrder result;
|
2016-10-20 16:32:15 +00:00
|
|
|
result.reserve(_rows.size());
|
2020-06-08 17:24:36 +00:00
|
|
|
for (const auto &row : _rows) {
|
2017-08-05 20:01:20 +00:00
|
|
|
if (check(row.get())) {
|
2020-05-28 11:58:50 +00:00
|
|
|
result.push_back(row->set->id);
|
2016-10-20 16:32:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2020-06-08 17:24:36 +00:00
|
|
|
StickersSetsOrder StickersBox::Inner::getOrder() const {
|
2016-11-22 09:48:13 +00:00
|
|
|
return collectSets([](Row *row) {
|
2022-01-24 12:33:31 +00:00
|
|
|
return !row->isArchived() && !row->removed && !row->isRecentSet();
|
2016-11-22 09:48:13 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2020-06-08 17:24:36 +00:00
|
|
|
StickersSetsOrder StickersBox::Inner::getFullOrder() const {
|
2016-11-22 09:48:13 +00:00
|
|
|
return collectSets([](Row *row) {
|
|
|
|
return !row->isRecentSet();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2020-06-08 17:24:36 +00:00
|
|
|
StickersSetsOrder StickersBox::Inner::getRemovedSets() const {
|
2016-11-22 09:48:13 +00:00
|
|
|
return collectSets([](Row *row) {
|
|
|
|
return row->removed;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
int StickersBox::Inner::getRowIndex(uint64 setId) const {
|
2017-08-05 20:01:20 +00:00
|
|
|
for (auto i = 0, count = int(_rows.size()); i != count; ++i) {
|
|
|
|
auto &row = _rows[i];
|
2020-05-28 11:58:50 +00:00
|
|
|
if (row->set->id == setId) {
|
2016-11-22 09:48:13 +00:00
|
|
|
return i;
|
2016-10-20 16:32:15 +00:00
|
|
|
}
|
|
|
|
}
|
2016-11-22 09:48:13 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2020-06-08 17:24:36 +00:00
|
|
|
void StickersBox::Inner::setFullOrder(const StickersSetsOrder &order) {
|
2021-09-03 11:09:57 +00:00
|
|
|
for (const auto setId : order) {
|
2016-11-22 09:48:13 +00:00
|
|
|
auto index = getRowIndex(setId);
|
|
|
|
if (index >= 0) {
|
2017-08-05 20:01:20 +00:00
|
|
|
auto row = std::move(_rows[index]);
|
2016-11-22 09:48:13 +00:00
|
|
|
auto count = _rows.size();
|
|
|
|
for (auto i = index + 1; i != count; ++i) {
|
2017-08-05 20:01:20 +00:00
|
|
|
_rows[i - 1] = std::move(_rows[i]);
|
2016-11-22 09:48:13 +00:00
|
|
|
}
|
2017-08-05 20:01:20 +00:00
|
|
|
_rows[count - 1] = std::move(row);
|
2016-11-22 09:48:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-08 17:24:36 +00:00
|
|
|
void StickersBox::Inner::setRemovedSets(const StickersSetsOrder &removed) {
|
2017-08-05 20:01:20 +00:00
|
|
|
for (auto i = 0, count = int(_rows.size()); i != count; ++i) {
|
2020-05-28 11:58:50 +00:00
|
|
|
setRowRemoved(i, removed.contains(_rows[i]->set->id));
|
2016-11-22 09:48:13 +00:00
|
|
|
}
|
2016-10-20 16:32:15 +00:00
|
|
|
}
|
|
|
|
|
2017-09-13 16:57:44 +00:00
|
|
|
void StickersBox::Inner::visibleTopBottomUpdated(
|
|
|
|
int visibleTop,
|
|
|
|
int visibleBottom) {
|
2016-12-13 17:07:56 +00:00
|
|
|
_visibleTop = visibleTop;
|
|
|
|
_visibleBottom = visibleBottom;
|
|
|
|
updateScrollbarWidth();
|
2016-10-20 16:32:15 +00:00
|
|
|
if (_section == Section::Featured) {
|
|
|
|
readVisibleSets();
|
|
|
|
}
|
2016-12-13 17:07:56 +00:00
|
|
|
checkLoadMore();
|
|
|
|
}
|
|
|
|
|
|
|
|
void StickersBox::Inner::checkLoadMore() {
|
|
|
|
if (_loadMoreCallback) {
|
|
|
|
auto scrollHeight = (_visibleBottom - _visibleTop);
|
|
|
|
int scrollTop = _visibleTop, scrollTopMax = height() - scrollHeight;
|
|
|
|
if (scrollTop + PreloadHeightsCount * scrollHeight >= scrollTopMax) {
|
|
|
|
_loadMoreCallback();
|
|
|
|
}
|
|
|
|
}
|
2016-10-20 16:32:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void StickersBox::Inner::readVisibleSets() {
|
|
|
|
auto itemsVisibleTop = _visibleTop - _itemsTop;
|
|
|
|
auto itemsVisibleBottom = _visibleBottom - _itemsTop;
|
|
|
|
int rowFrom = floorclamp(itemsVisibleTop, _rowHeight, 0, _rows.size());
|
|
|
|
int rowTo = ceilclamp(itemsVisibleBottom, _rowHeight, 0, _rows.size());
|
|
|
|
for (int i = rowFrom; i < rowTo; ++i) {
|
2020-06-04 08:16:56 +00:00
|
|
|
const auto row = _rows[i].get();
|
2022-01-24 12:33:31 +00:00
|
|
|
if (!row->isUnread()) {
|
2016-10-20 16:32:15 +00:00
|
|
|
continue;
|
|
|
|
}
|
2020-06-04 08:16:56 +00:00
|
|
|
if ((i * _rowHeight < itemsVisibleTop)
|
|
|
|
|| ((i + 1) * _rowHeight > itemsVisibleBottom)) {
|
2016-10-20 16:32:15 +00:00
|
|
|
continue;
|
|
|
|
}
|
2020-06-04 08:16:56 +00:00
|
|
|
const auto thumbnailLoading = row->set->hasThumbnail()
|
|
|
|
? row->set->thumbnailLoading()
|
|
|
|
: row->sticker
|
|
|
|
? row->sticker->thumbnailLoading()
|
2020-04-15 14:06:34 +00:00
|
|
|
: false;
|
2020-06-04 08:16:56 +00:00
|
|
|
const auto thumbnailLoaded = row->set->hasThumbnail()
|
|
|
|
? (row->thumbnailMedia
|
|
|
|
&& (row->thumbnailMedia->image()
|
|
|
|
|| !row->thumbnailMedia->content().isEmpty()))
|
|
|
|
: row->sticker
|
|
|
|
? (row->stickerMedia && row->stickerMedia->loaded())
|
|
|
|
: true;
|
|
|
|
if (!thumbnailLoading || thumbnailLoaded) {
|
2020-06-23 17:21:58 +00:00
|
|
|
session().api().readFeaturedSetDelayed(row->set->id);
|
2016-10-20 16:32:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-13 17:07:56 +00:00
|
|
|
void StickersBox::Inner::updateScrollbarWidth() {
|
2019-11-02 17:06:47 +00:00
|
|
|
auto width = (_visibleBottom - _visibleTop < height()) ? (st::boxScroll.width - st::boxScroll.deltax) : 0;
|
2016-12-13 17:07:56 +00:00
|
|
|
if (_scrollbar != width) {
|
|
|
|
_scrollbar = width;
|
|
|
|
update();
|
|
|
|
}
|
2016-10-20 16:32:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
StickersBox::Inner::~Inner() {
|
|
|
|
clear();
|
|
|
|
}
|