Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
john-preston committed Oct 23, 2024
1 parent d6b0430 commit 26e97c7
Show file tree
Hide file tree
Showing 45 changed files with 613 additions and 192 deletions.
20 changes: 19 additions & 1 deletion Telegram/SourceFiles/chat_helpers/stickers_emoji_pack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,6 @@ void EmojiPack::remove(not_null<const ViewElement*> view) {
}
}

#if 0 // mtp
auto EmojiPack::stickerForEmoji(EmojiPtr emoji) -> Sticker {
Expects(emoji != nullptr);

Expand All @@ -165,16 +164,35 @@ auto EmojiPack::stickerForEmoji(EmojiPtr emoji) -> Sticker {
return { i->second.get(), nullptr };
}
if (!emoji->colored()) {
request(emoji);
return {};
}
const auto j = _map.find(emoji->original());
if (j != end(_map)) {
const auto index = emoji->variantIndex(emoji);
return { j->second.get(), ColorReplacements(index) };
}
request(emoji->original());
return {};
}

void EmojiPack::request(EmojiPtr emoji) {
if (!_requested.emplace(emoji).second) {
return;
}
_session->sender().request(TLgetAnimatedEmoji(
tl_string(emoji->id())
)).done([=](const TLanimatedEmoji &result) {
const auto &data = result.data();
if (const auto &sticker = data.vsticker()) {
const auto document = _session->data().processDocument(*sticker);
_map.emplace(emoji, document);
_refreshed.fire({});
}
}).send();
}

#if 0 // mtp
auto EmojiPack::stickerForEmoji(const IsolatedEmoji &emoji) -> Sticker {
Expects(!emoji.empty());

Expand Down
9 changes: 5 additions & 4 deletions Telegram/SourceFiles/chat_helpers/stickers_emoji_pack.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ class EmojiPack final {
bool add(not_null<ViewElement*> view);
void remove(not_null<const ViewElement*> view);

#if 0 // mtp
[[nodiscard]] Sticker stickerForEmoji(EmojiPtr emoji);
#if 0 // mtp
[[nodiscard]] Sticker stickerForEmoji(const IsolatedEmoji &emoji);
#endif
[[nodiscard]] std::shared_ptr<LargeEmojiImage> image(EmojiPtr emoji);
Expand All @@ -100,10 +100,10 @@ class EmojiPack final {
[[nodiscard]] int animationsVersion() const {
return _animationsVersion;
}
#endif
[[nodiscard]] rpl::producer<> refreshed() const {
return _refreshed.events();
}
#endif

[[nodiscard]] std::unique_ptr<Lottie::SinglePlayer> effectPlayer(
not_null<DocumentData*> document,
Expand Down Expand Up @@ -160,10 +160,11 @@ class EmojiPack final {
void refreshItems(const base::flat_set<not_null<ViewElement*>> &list);
void refreshItems(const base::flat_set<not_null<HistoryItem*>> &items);

void request(EmojiPtr emoji);
base::flat_set<EmojiPtr> _requested;

const not_null<Main::Session*> _session;
#if 0 // mtp
base::flat_map<EmojiPtr, not_null<DocumentData*>> _map;
#endif
base::flat_map<
IsolatedEmoji,
base::flat_set<not_null<HistoryView::Element*>>> _items;
Expand Down
28 changes: 24 additions & 4 deletions Telegram/SourceFiles/chat_helpers/stickers_gift_box_pack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,19 @@ For license and copyright information please follow this link:
*/
#include "chat_helpers/stickers_gift_box_pack.h"

#if 0 // mtp

#include "apiwrap.h"
#include "data/data_document.h"
#include "data/data_file_origin.h"
#include "data/data_session.h"
#include "main/main_session.h"

#include "tdb/tdb_tl_scheme.h"
#include "tdb/tdb_sender.h"

namespace Stickers {

using namespace Tdb;

GiftBoxPack::GiftBoxPack(not_null<Main::Session*> session)
: _session(session)
, _localMonths({ 1, 3, 6, 12, 24 }) {
Expand All @@ -39,6 +42,7 @@ int GiftBoxPack::monthsForStars(int stars) const {
}

DocumentData *GiftBoxPack::lookup(int months) const {
#if 0 // mtp
const auto it = ranges::lower_bound(_localMonths, months);
const auto fallback = _documents.empty() ? nullptr : _documents[0];
if (it == begin(_localMonths)) {
Expand All @@ -53,12 +57,29 @@ DocumentData *GiftBoxPack::lookup(int months) const {
: 0;
const auto index = int(std::distance(begin(_localMonths), it - shift));
return (index >= _documents.size()) ? fallback : _documents[index];
#endif
const auto i = _months.find(months);
if (i == end(_months)) {
_months.emplace(months, nullptr);
_session->sender().request(TLgetPremiumInfoSticker(
tl_int32(months)
)).done([=](const TLsticker &result) {
const auto document = _session->data().processDocument(result);
if (document->sticker()) {
_months[months] = document;
_updated.fire({});
}
}).send();
return nullptr;
}
return i->second;
}

Data::FileOrigin GiftBoxPack::origin() const {
return Data::FileOriginStickerSet(_setId, _accessHash);
}

#if 0 // mtp
void GiftBoxPack::load() {
if (_requestId || !_documents.empty()) {
return;
Expand Down Expand Up @@ -120,7 +141,6 @@ void GiftBoxPack::applySet(const MTPDmessages_stickerSet &data) {
}
_updated.fire({});
}
#endif

} // namespace Stickers

#endif
10 changes: 6 additions & 4 deletions Telegram/SourceFiles/chat_helpers/stickers_gift_box_pack.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ For license and copyright information please follow this link:
*/
#pragma once

#if 0 // mtp

class DocumentData;

namespace Data {
Expand All @@ -26,15 +24,21 @@ class GiftBoxPack final {
explicit GiftBoxPack(not_null<Main::Session*> session);
~GiftBoxPack();

#if 0 // mtp
void load();
#endif
[[nodiscard]] int monthsForStars(int stars) const;
[[nodiscard]] DocumentData *lookup(int months) const;
[[nodiscard]] Data::FileOrigin origin() const;
[[nodiscard]] rpl::producer<> updated() const;

private:
using SetId = uint64;
#if 0 // mtp
void applySet(const MTPDmessages_stickerSet &data);
#endif

mutable base::flat_map<int, DocumentData*> _months;

const not_null<Main::Session*> _session;
const std::vector<int> _localMonths;
Expand All @@ -48,5 +52,3 @@ class GiftBoxPack final {
};

} // namespace Stickers

#endif
2 changes: 1 addition & 1 deletion Telegram/SourceFiles/chat_helpers/stickers_lottie.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ not_null<DocumentData*> GenerateLocalTgsSticker(
"WEBP",
result->thumbbytes));
#endif
const auto document = _session->data().processDocument(result->document);
const auto document = session->data().processDocument(result->document);
document->setLocation(Core::FileLocation(path));

Ensures(document->sticker());
Expand Down
48 changes: 42 additions & 6 deletions Telegram/SourceFiles/core/local_url_handlers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1728,15 +1728,15 @@ bool HandleLocalUrl(
.openWebAppUrl = openWebAppUrl,
}));
});
}, [&](const TLDinternalLinkTypeSideMenuBot &data) {
}, [&](const TLDinternalLinkTypeMainWebApp &data) {
if (!controller) {
return false;
}
// todo
controller->showPeerByLink(Window::PeerByLinkInfo{
.usernameOrId = data.vbot_username().v,
.attachBotToggleCommand = data.vurl().v,
//.attachBotMenuOpen = true,
.attachBotToggleCommand = data.vstart_parameter().v,
.attachBotMainOpen = true,
.attachBotMainCompact = data.vis_compact().v,
.clickFromMessageId = my.itemId,
});
controller->window().activate();
Expand Down Expand Up @@ -2145,10 +2145,46 @@ bool HandleLocalUrl(
if (!controller) {
return false;
}
const auto ref = data.vreferrer().v;
controller->showGiftPremiumsBox(ref.isEmpty() ? u"gift_url"_q : ref);
Ui::ChooseStarGiftRecipient(controller);
controller->window().activate();
return true;
}, [&](const TLDinternalLinkTypeBuyStars &data) {
if (!controller) {
return false;
}
const auto amount = std::clamp(
data.vstar_count().v,
int64(1),
int64(1'000'000));
const auto purpose = data.vpurpose().v;
const auto weak = base::make_weak(controller);
const auto done = [=](::Settings::SmallBalanceResult result) {
if (result == ::Settings::SmallBalanceResult::Already) {
if (const auto strong = weak.get()) {
const auto filter = [=](const auto &...) {
strong->showSettings(::Settings::CreditsId());
return false;
};
strong->showToast(Ui::Toast::Config{
.text = tr::lng_credits_enough(
tr::now,
lt_link,
Ui::Text::Link(
Ui::Text::Bold(
tr::lng_credits_enough_link(tr::now))),
Ui::Text::RichLangValue),
.filter = filter,
.duration = 4 * crl::time(1000),
});
}
}
};
::Settings::MaybeRequestBalanceIncrease(
controller->uiShow(),
amount,
::Settings::SmallBalanceDeepLink{ .purpose = purpose },
done);
return true;
});
}

Expand Down
7 changes: 7 additions & 0 deletions Telegram/SourceFiles/data/components/credits.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ For license and copyright information please follow this link:
#include "main/main_app_config.h"
#include "main/main_session.h"

#include "tdb/tdb_tl_scheme.h"

namespace Data {
namespace {

Expand All @@ -26,9 +28,14 @@ Credits::Credits(not_null<Main::Session*> session)

Credits::~Credits() = default;

#if 0 // mtp
void Credits::apply(const MTPDupdateStarsBalance &data) {
apply(data.vbalance().v);
}
#endif
void Credits::apply(const Tdb::TLDupdateOwnedStarCount &data) {
apply(data.vstar_count().v);
}

rpl::producer<float64> Credits::rateValue(
not_null<PeerData*> ownedBotOrChannel) {
Expand Down
7 changes: 7 additions & 0 deletions Telegram/SourceFiles/data/components/credits.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ namespace Main {
class Session;
} // namespace Main

namespace Tdb {
class TLDupdateOwnedStarCount;
} // namespace Tdb

namespace Data {

class Credits final {
Expand All @@ -40,7 +44,10 @@ class Credits final {
void withdrawLocked(int count);
void invalidate();

#if 0 // mtp
void apply(const MTPDupdateStarsBalance &data);
#endif
void apply(const Tdb::TLDupdateOwnedStarCount &data);

private:
void updateNonLockedValue();
Expand Down
4 changes: 3 additions & 1 deletion Telegram/SourceFiles/data/components/sponsored_messages.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -593,7 +593,9 @@ void SponsoredMessages::clicked(
const auto id = DeserializeRandomId(entryPtr->sponsored.randomId);
_session->sender().request(TLclickChatSponsoredMessage(
peerToTdbChat(id.peer),
tl_int53(id.msg.bare)
tl_int53(id.msg.bare),
tl_bool(isMedia),
tl_bool(isFullscreen)
)).send();
#if 0 // mtp
const auto randomId = entryPtr->sponsored.randomId;
Expand Down
15 changes: 7 additions & 8 deletions Telegram/SourceFiles/data/data_media_preload.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,14 @@ For license and copyright information please follow this link:
#include "media/streaming/media_streaming_reader.h"
#include "storage/file_download.h" // kMaxFileInMemory.

#include "tdb/tdb_account.h"
#include "tdb/tdb_tl_scheme.h"

namespace Data {
namespace {

using namespace Tdb;

constexpr auto kDefaultPreloadPrefix = 4 * 1024 * 1024;

[[nodiscard]] int64 ChoosePreloadPrefix(not_null<DocumentData*> video) {
Expand Down Expand Up @@ -208,13 +213,6 @@ bool VideoPreload::setWebFileSizeHook(int64 size) {
}
#endif

[[nodiscard]] int ChoosePreloadPrefix(not_null<DocumentData*> document) {
const auto prefix = document->videoPreloadPrefix();
const auto part = Storage::kDownloadPartSize;
const auto parts = (prefix + part - 1) / part;
return std::min(int64(parts) * part, document->size);
}

[[nodiscard]] QByteArray PackPreload(const QByteArray &bytes, int64 full) {
if (bytes.isEmpty()) {
return {};
Expand Down Expand Up @@ -244,6 +242,7 @@ VideoPreload::VideoPreload(
not_null<DocumentData*> video,
Fn<void()> done)
: MediaPreload(std::move(done))
, _video(video)
, _session(&video->session())
, _sender(&_session->sender())
, _full(video->size)
Expand Down Expand Up @@ -334,7 +333,7 @@ void VideoPreload::startWith(const TLDlocalFile &data) {
});
}
}).fail([=] {
done();
done({});
}).send();
}
}
Expand Down
Loading

0 comments on commit 26e97c7

Please sign in to comment.