Skip to content

Commit

Permalink
Minimal emoji sets support.
Browse files Browse the repository at this point in the history
  • Loading branch information
john-preston committed Jul 26, 2022
1 parent afc7b1d commit ddd5021
Show file tree
Hide file tree
Showing 12 changed files with 182 additions and 49 deletions.
70 changes: 43 additions & 27 deletions Telegram/SourceFiles/boxes/sticker_set_box.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,12 @@ class StickerSetBox::Inner final : public Ui::RpWidget {

void archiveStickers();

bool isMasksSet() const {
return (_setFlags & SetFlag::Masks);
[[nodiscard]] Data::StickersType setType() const {
return (_setFlags & SetFlag::Emoji)
? Data::StickersType::Emoji
: (_setFlags & SetFlag::Masks)
? Data::StickersType::Masks
: Data::StickersType::Stickers;
}

~Inner();
Expand Down Expand Up @@ -271,11 +275,14 @@ void StickerSetBox::prepare() {

_inner->setInstalled(
) | rpl::start_with_next([=](uint64 setId) {
if (_inner->isMasksSet()) {
if (_inner->setType() == Data::StickersType::Masks) {
Ui::Toast::Show(
Ui::BoxShow(this).toastParent(),
tr::lng_masks_installed(tr::now));
} else {
} else if (_inner->setType() == Data::StickersType::Emoji) {
auto &stickers = _controller->session().data().stickers();
stickers.notifyEmojiSetInstalled(setId);
} else if (_inner->setType() == Data::StickersType::Stickers) {
auto &stickers = _controller->session().data().stickers();
stickers.notifyStickerSetInstalled(setId);
}
Expand All @@ -289,23 +296,26 @@ void StickerSetBox::prepare() {

_inner->setArchived(
) | rpl::start_with_next([=](uint64 setId) {
const auto isMasks = _inner->isMasksSet();
const auto type = _inner->setType();
if (type == Data::StickersType::Emoji) {
return;
}

Ui::Toast::Show(
Ui::BoxShow(this).toastParent(),
isMasks
(type == Data::StickersType::Masks)
? tr::lng_masks_has_been_archived(tr::now)
: tr::lng_stickers_has_been_archived(tr::now));

auto &order = isMasks
auto &order = (type == Data::StickersType::Masks)
? _controller->session().data().stickers().maskSetsOrderRef()
: _controller->session().data().stickers().setsOrderRef();
const auto index = order.indexOf(setId);
if (index != -1) {
order.removeAt(index);

auto &local = _controller->session().local();
if (isMasks) {
if (type == Data::StickersType::Masks) {
local.writeInstalledMasks();
local.writeArchivedMasks();
} else {
Expand Down Expand Up @@ -352,11 +362,11 @@ void StickerSetBox::updateTitleAndButtons() {
void StickerSetBox::updateButtons() {
clearButtons();
if (_inner->loaded()) {
const auto isMasks = _inner->isMasksSet();
const auto type = _inner->setType();
if (_inner->notInstalled()) {
auto addText = isMasks
auto addText = (type == Data::StickersType::Masks)
? tr::lng_stickers_add_masks()
: tr::lng_stickers_add_pack();
: tr::lng_stickers_add_pack(); // #TODO emoji
addButton(std::move(addText), [=] { addStickers(); });
addButton(tr::lng_cancel(), [=] { closeBox(); });

Expand All @@ -376,9 +386,9 @@ void StickerSetBox::updateButtons() {
top,
st::popupMenuWithIcons);
(*menu)->addAction(
(isMasks
((type == Data::StickersType::Masks)
? tr::lng_stickers_share_masks
: tr::lng_stickers_share_pack)(tr::now),
: tr::lng_stickers_share_pack)(tr::now), // #TODO emoji
share,
&st::menuIconShare);
(*menu)->popup(QCursor::pos());
Expand All @@ -394,9 +404,9 @@ void StickerSetBox::updateButtons() {
Ui::BoxShow(this).toastParent(),
tr::lng_stickers_copied(tr::now));
};
auto shareText = isMasks
auto shareText = (type == Data::StickersType::Masks)
? tr::lng_stickers_share_masks()
: tr::lng_stickers_share_pack();
: tr::lng_stickers_share_pack(); // #TODO emoji
addButton(std::move(shareText), std::move(share));
addButton(tr::lng_cancel(), [=] { closeBox(); });

Expand All @@ -412,9 +422,9 @@ void StickerSetBox::updateButtons() {
top,
st::popupMenuWithIcons);
(*menu)->addAction(
isMasks
(type == Data::StickersType::Masks)
? tr::lng_masks_archive_pack(tr::now)
: tr::lng_stickers_archive_pack(tr::now),
: tr::lng_stickers_archive_pack(tr::now), // #TODO emoji
archive,
&st::menuIconArchive);
(*menu)->popup(QCursor::pos());
Expand Down Expand Up @@ -599,15 +609,15 @@ void StickerSetBox::Inner::installDone(
const MTPmessages_StickerSetInstallResult &result) {
auto &stickers = _controller->session().data().stickers();
auto &sets = stickers.setsRef();
const auto isMasks = isMasksSet();
const auto type = setType();

const bool wasArchived = (_setFlags & SetFlag::Archived);
if (wasArchived) {
const auto index = (isMasks
if (wasArchived && type != Data::StickersType::Emoji) {
const auto index = ((type == Data::StickersType::Masks)
? stickers.archivedMaskSetsOrderRef()
: stickers.archivedSetsOrderRef()).indexOf(_setId);
if (index >= 0) {
(isMasks
((type == Data::StickersType::Masks)
? stickers.archivedMaskSetsOrderRef()
: stickers.archivedSetsOrderRef()).removeAt(index);
}
Expand Down Expand Up @@ -638,7 +648,9 @@ void StickerSetBox::Inner::installDone(
set->stickers = _pack;
set->emoji = _emoji;

auto &order = isMasks
auto &order = (type == Data::StickersType::Emoji)
? stickers.emojiSetsOrderRef()
: (type == Data::StickersType::Masks)
? stickers.maskSetsOrderRef()
: stickers.setsOrderRef();
const auto insertAtIndex = 0, currentIndex = int(order.indexOf(_setId));
Expand Down Expand Up @@ -668,14 +680,16 @@ void StickerSetBox::Inner::installDone(
result.c_messages_stickerSetInstallResultArchive());
} else {
auto &storage = _controller->session().local();
if (wasArchived) {
if (isMasks) {
if (wasArchived && type != Data::StickersType::Emoji) {
if (type == Data::StickersType::Masks) {
storage.writeArchivedMasks();
} else {
storage.writeArchivedStickers();
}
}
if (isMasks) {
if (type == Data::StickersType::Emoji) {
storage.writeInstalledCustomEmoji();
} else if (type == Data::StickersType::Masks) {
storage.writeInstalledMasks();
} else {
storage.writeInstalledStickers();
Expand Down Expand Up @@ -723,7 +737,9 @@ void StickerSetBox::Inner::mouseReleaseEvent(QMouseEvent *e) {
}
_previewTimer.cancel();
const auto index = stickerFromGlobalPos(e->globalPos());
if (index < 0 || index >= _pack.size() || isMasksSet()) {
if (index < 0
|| index >= _pack.size()
|| setType() != Data::StickersType::Stickers) {
return;
}
send(_pack[index], {});
Expand Down Expand Up @@ -786,7 +802,7 @@ void StickerSetBox::Inner::contextMenuEvent(QContextMenuEvent *e) {

void StickerSetBox::Inner::updateSelected() {
auto selected = stickerFromGlobalPos(QCursor::pos());
setSelected(isMasksSet() ? -1 : selected);
setSelected(setType() != Data::StickersType::Stickers ? -1 : selected);
}

void StickerSetBox::Inner::setSelected(int selected) {
Expand Down
4 changes: 2 additions & 2 deletions Telegram/SourceFiles/boxes/stickers_box.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1001,13 +1001,13 @@ void StickersBox::saveChanges() {
session().api().saveStickerSets(
installed->getOrder(),
installed->getRemovedSets(),
false);
Data::StickersType::Stickers);
}
if (masks) {
session().api().saveStickerSets(
masks->getOrder(),
masks->getRemovedSets(),
true);
Data::StickersType::Masks);
}
}

Expand Down
28 changes: 25 additions & 3 deletions Telegram/SourceFiles/chat_helpers/emoji_list_widget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1024,7 +1024,7 @@ void EmojiListWidget::refreshCustom() {
auto searchFromIndex = 0;
auto old = base::take(_custom);
const auto owner = &controller()->session().data();
const auto &order = owner->stickers().setsOrder();
const auto &order = owner->stickers().emojiSetsOrder();
const auto &sets = owner->stickers().sets();
for (const auto setId : order) {
auto it = sets.find(setId);
Expand Down Expand Up @@ -1158,8 +1158,8 @@ void EmojiListWidget::showEmojiSection(Section section) {
refreshRecent();

auto y = 0;
enumerateSections([&y, sectionForSearch = section](const SectionInfo &info) {
if (static_cast<Section>(info.section) == sectionForSearch) {
enumerateSections([&](const SectionInfo &info) {
if (static_cast<Section>(info.section) == section) {
y = info.top;
return false;
}
Expand All @@ -1172,6 +1172,28 @@ void EmojiListWidget::showEmojiSection(Section section) {
update();
}

void EmojiListWidget::showCustomSet(uint64 setId) {
clearSelection();

refreshCustom();

auto y = 0;
enumerateSections([&](const SectionInfo &info) {
if (info.section >= kEmojiSectionCount) {
if (_custom[info.section - kEmojiSectionCount].id == setId) {
y = info.top;
return false;
}
}
return true;
});
scrollTo(y);

_lastMousePos = QCursor::pos();

update();
}

tr::phrase<> EmojiCategoryTitle(int index) {
switch (index) {
case 1: return tr::lng_emoji_category1;
Expand Down
2 changes: 2 additions & 0 deletions Telegram/SourceFiles/chat_helpers/emoji_list_widget.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ class EmojiListWidget
void showEmojiSection(Section section);
[[nodiscard]] Section currentSection(int yOffset) const;

void showCustomSet(uint64 setId);

// Ui::AbstractTooltipShower interface.
QString tooltipText() const override;
QPoint tooltipPos() const override;
Expand Down
12 changes: 12 additions & 0 deletions Telegram/SourceFiles/chat_helpers/tabbed_selector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,15 @@ TabbedSelector::TabbedSelector(
refreshStickers();
}, lifetime());
}

if (hasEmojiTab()) {
session().data().stickers().emojiSetInstalled(
) | rpl::start_with_next([=](uint64 setId) {
_tabsSlider->setActiveSection(indexByType(SelectorTab::Emoji));
emoji()->showCustomSet(setId);
_showRequests.fire({});
}, lifetime());
}
//setAttribute(Qt::WA_AcceptTouchEvents);
setAttribute(Qt::WA_OpaquePaintEvent, false);
showAll();
Expand Down Expand Up @@ -772,6 +781,9 @@ void TabbedSelector::showStarted() {
if (hasMasksTab()) {
session().api().updateMasks();
}
if (hasEmojiTab()) {
session().api().updateCustomEmoji();
}
currentTab()->widget()->refreshRecent();
currentTab()->widget()->preloadImages();
_a_slide.stop();
Expand Down
8 changes: 4 additions & 4 deletions Telegram/SourceFiles/core/local_url_handlers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ bool ShowStickerSet(
Core::App().hideMediaView();
controller->show(Box<StickerSetBox>(
controller,
StickerSetIdentifier{ .shortName = match->captured(1) }));
StickerSetIdentifier{ .shortName = match->captured(2) }));
controller->window().activate();
return true;
}
Expand Down Expand Up @@ -781,7 +781,7 @@ const std::vector<LocalUrlHandler> &LocalUrlHandlers() {
JoinGroupByHash
},
{
qsl("^addstickers/?\\?set=([a-zA-Z0-9\\.\\_]+)(&|$)"),
qsl("^(addstickers|addemoji)/?\\?set=([a-zA-Z0-9\\.\\_]+)(&|$)"),
ShowStickerSet
},
{
Expand Down Expand Up @@ -885,8 +885,8 @@ QString TryConvertUrlToLocal(QString url) {
return qsl("tg://resolve?phone=") + phoneMatch->captured(1) + (params.isEmpty() ? QString() : '&' + params);
} else if (auto joinChatMatch = regex_match(qsl("^(joinchat/|\\+|\\%20)([a-zA-Z0-9\\.\\_\\-]+)(\\?|$)"), query, matchOptions)) {
return qsl("tg://join?invite=") + url_encode(joinChatMatch->captured(2));
} else if (auto stickerSetMatch = regex_match(qsl("^addstickers/([a-zA-Z0-9\\.\\_]+)(\\?|$)"), query, matchOptions)) {
return qsl("tg://addstickers?set=") + url_encode(stickerSetMatch->captured(1));
} else if (auto stickerSetMatch = regex_match(qsl("^(addstickers|addemoji)/([a-zA-Z0-9\\.\\_]+)(\\?|$)"), query, matchOptions)) {
return qsl("tg://") + stickerSetMatch->captured(1) + "?set=" + url_encode(stickerSetMatch->captured(2));
} else if (auto themeMatch = regex_match(qsl("^addtheme/([a-zA-Z0-9\\.\\_]+)(\\?|$)"), query, matchOptions)) {
return qsl("tg://addtheme?slug=") + url_encode(themeMatch->captured(1));
} else if (auto languageMatch = regex_match(qsl("^setlanguage/([a-zA-Z0-9\\.\\_\\-]+)(\\?|$)"), query, matchOptions)) {
Expand Down
Loading

0 comments on commit ddd5021

Please sign in to comment.