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 3124b27 commit 38e09c2
Show file tree
Hide file tree
Showing 51 changed files with 721 additions and 200 deletions.
2 changes: 1 addition & 1 deletion Telegram/SourceFiles/boxes/peers/edit_participants_box.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ void RemoveAdmin(
peer->session().sender().request(TLsetChatMemberStatus(
peerToTdbChat(peer->id),
peerToSender(user->id),
tl_chatMemberStatusMember()
tl_chatMemberStatusMember(tl_int32(0)) // member_until_date
)).done([=] {
if (const auto channel = peer->asChannel()) {
channel->applyEditAdmin(user, oldRights, {}, {});
Expand Down
3 changes: 2 additions & 1 deletion Telegram/SourceFiles/boxes/peers/edit_peer_info_box.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2461,7 +2461,8 @@ void Controller::saveSignatures() {
#endif
_api.request(TLtoggleSupergroupSignMessages(
tl_int53(peerToChannel(channel->id).bare),
tl_bool(*_savingData.signatures)
tl_bool(*_savingData.signatures),
tl_bool(*_savingData.signatureProfiles)
)).done([=] {
// CHAT_NOT_MODIFIED is processed as TLok.
continueSave();
Expand Down
1 change: 1 addition & 0 deletions Telegram/SourceFiles/boxes/peers/edit_peer_invite_link.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -946,6 +946,7 @@ void Controller::loadMoreRows() {
_requestId = _api.request(TLgetChatInviteLinkMembers(
peerToTdbChat(_peer->id),
tl_string(_link),
tl_bool(false), // only_with_expired_subscription
tl_chatInviteLinkMember( // Offset.
tl_int53(_lastUser
? peerToUser(_lastUser->user->id).bare
Expand Down
14 changes: 14 additions & 0 deletions Telegram/SourceFiles/boxes/send_credits_box.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ For license and copyright information please follow this link:

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

namespace Ui {
namespace {
Expand Down Expand Up @@ -470,6 +471,7 @@ void SendStarGift(
not_null<Main::Session*> session,
std::shared_ptr<Payments::CreditsFormData> data,
Fn<void(std::optional<QString>)> done) {
#if 0 // mtp
session->api().request(MTPpayments_SendStarsForm(
MTP_long(data->formId),
data->inputInvoice
Expand All @@ -482,6 +484,18 @@ void SendStarGift(
}).fail([=](const MTP::Error &error) {
done(error.type());
}).send();
#endif
const auto &gift = v::get<Payments::InvoiceStarGift>(data->id.value);
session->sender().request(TLsendGift(
tl_int64(gift.giftId),
tl_int53(peerToUser(gift.user->id).bare),
Api::FormattedTextToTdb(gift.message),
tl_bool(gift.anonymous)
)).done([=] {
done(std::nullopt);
}).fail([=](const Error &error) {
done(error.message);
}).send();
}

} // namespace Ui
93 changes: 88 additions & 5 deletions Telegram/SourceFiles/boxes/sticker_set_box.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,10 @@ constexpr auto kStickerMoveDuration = crl::time(200);
using Data::StickersSet;
using Data::StickersPack;
using SetFlag = Data::StickersSetFlag;
#if 0 // mtp
using TLStickerSet = MTPmessages_StickerSet;
#endif
using TLStickerSet = TLstickerSet;

[[nodiscard]] std::optional<QColor> ComputeImageColor(
const style::icon &lockIcon,
Expand Down Expand Up @@ -389,7 +392,6 @@ class StickerSetBox::Inner final : public Ui::RpWidget {
#if 0 // mtp
void installDone(const MTPmessages_StickerSetInstallResult &result);
#endif
void gotSet(const TLstickerSet &set);
void installDone();

void requestReorder(not_null<DocumentData*> document, int index);
Expand Down Expand Up @@ -684,6 +686,7 @@ void ChangeSetNameBox(
const auto buttonWidth = state->saveButton
? state->saveButton->width()
: 0;
#if 0 // mtp
state->requestId = data->session().api().request(
MTPstickers_RenameStickerSet(
Data::InputStickerSet(input),
Expand All @@ -700,6 +703,31 @@ void ChangeSetNameBox(
show->showToast(error.type());
close();
}).send();
#endif
const auto &sets = data->stickers().sets();
const auto it = sets.find(input.id);
if (it == sets.end()) {
show->showToast(u"Set not found!"_q);
return;
}
state->requestId = data->session().sender().request(
TLsetStickerSetTitle(
tl_string(it->second->shortName),
tl_string(text))
).done([=] {
state->requestId = data->session().sender().request(
TLgetStickerSet(tl_int64(input.id))
).done([=](const TLstickerSet &result) {
done(result);
close();
}).fail([=](const Error &error) {
show->showToast(error.message);
close();
}).send();
}).fail([=](const Error &error) {
show->showToast(error.message);
close();
}).send();
if (state->saveButton) {
state->saveButton->resizeToWidth(buttonWidth);
}
Expand All @@ -722,7 +750,11 @@ void ChangeSetNameBox(
state->requestId.value() | rpl::map(rpl::mappers::_1 > 0));
}
box->addButton(tr::lng_cancel(), [=] {
#if 0 // mtp
data->session().api().request(state->requestId.current()).cancel();
#endif
data->session().sender().request(
state->requestId.current()).cancel();
close();
});
}
Expand Down Expand Up @@ -927,16 +959,17 @@ StickerSetBox::Inner::Inner(
_api.request(TLgetStickerSet(
tl_int64(_input.id)
)).done([=](const TLstickerSet &result) {
gotSet(result);
applySet(result);
}).fail([=] {
_loaded = true;
_errors.fire(Error::NotFound);
}).send();
} else {
_api.request(TLsearchStickerSet(
tl_string(_input.shortName)
tl_string(_input.shortName),
tl_bool(true)
)).done([=](const TLstickerSet &result) {
gotSet(result);
applySet(result);
}).fail([=] {
_loaded = true;
_errors.fire(Error::NotFound);
Expand Down Expand Up @@ -1091,8 +1124,8 @@ void StickerSetBox::Inner::applySet(const TLStickerSet &set) {
set->emoji = _emoji;
set->setThumbnail(_setThumbnail, _setThumbnailType);
}
};
#if 0 // mtp
};
}, [&](const MTPDmessages_stickerSetNotModified &data) {
LOG(("API Error: Unexpected messages.stickerSetNotModified."));
#endif
Expand Down Expand Up @@ -1362,6 +1395,11 @@ void StickerSetBox::Inner::requestReorder(
_apiReorder.emplace(&_session->mtp());
}
_reorderRequests.emplace_back([document, index, this] {
_apiReorder->request(TLsetStickerPositionInSet(
tl_inputFileId(tl_int32(document->tdbFileId())),
tl_int32(index)
)).done([this, document] {
#if 0 // mtp
_apiReorder->request(
MTPstickers_ChangeStickerPosition(
document->mtpInput(),
Expand All @@ -1373,16 +1411,30 @@ void StickerSetBox::Inner::requestReorder(
Data::StickersType::Stickers);
}, [](const auto &) {
});
#endif
if (!_reorderRequests.empty()) {
_reorderRequests.pop_front();
}
if (_reorderRequests.empty()) {
_apiReorder->request(TLgetStickerSet(
tl_int64(_setId)
)).done([this, document](const TLstickerSet &result) {
document->owner().stickers().feedSetFull(result);
document->owner().stickers().notifyUpdated(
Data::StickersType::Stickers);
}).fail([show = _show](const Tdb::Error &error) {
show->showToast(error.message);
}).send();
// applySet(result); // Causes stickers blink.
} else {
_reorderRequests.front()();
}
#if 0 // mtp
}).fail([show = _show](const MTP::Error &error) {
show->showToast(error.type());
#endif
}).fail([show = _show](const Tdb::Error &error) {
show->showToast(error.message);
}).send();
});
if (_reorderRequests.size() == 1) {
Expand Down Expand Up @@ -1644,6 +1696,7 @@ void StickerSetBox::Inner::fillDeleteStickerBox(
const auto buttonWidth = state->saveButton
? state->saveButton->width()
: 0;
#if 0 // mtp
state->requestId = document->owner().session().api().request(
MTPstickers_RemoveStickerFromSet(document->mtpInput()
)).done([=](const TLStickerSet &result) {
Expand All @@ -1664,6 +1717,33 @@ void StickerSetBox::Inner::fillDeleteStickerBox(
strongBox->uiShow()->showToast(error.type());
}
}).send();
#endif
state->requestId = document->owner().session().sender().request(
TLremoveStickerFromSet(
tl_inputFileId(tl_int32(document->tdbFileId())))
).done([=] {
document->owner().session().sender().request(TLgetStickerSet(
tl_int64(_setId)
)).done([=](const TLstickerSet &result) {
document->owner().stickers().feedSetFull(result);
document->owner().stickers().notifyUpdated(
Data::StickersType::Stickers);
if (const auto strong = weak.data()) {
applySet(result);
}
if (const auto strongBox = weakBox.data()) {
strongBox->closeBox();
}
}).fail([=](const Tdb::Error &error) {
if (const auto strongBox = weakBox.data()) {
strongBox->uiShow()->showToast(error.message);
}
}).send();
}).fail([=](const Tdb::Error &error) {
if (const auto strongBox = weakBox.data()) {
strongBox->uiShow()->showToast(error.message);
}
}).send();
if (state->saveButton) {
state->saveButton->resizeToWidth(buttonWidth);
}
Expand All @@ -1686,7 +1766,10 @@ void StickerSetBox::Inner::fillDeleteStickerBox(
state->requestId.value() | rpl::map(rpl::mappers::_1 > 0));
}
box->addButton(tr::lng_close(), [=] {
#if 0 // mtp
document->owner().session().api().request(
#endif
document->owner().session().sender().request(
state->requestId.current()).cancel();
box->closeBox();
});
Expand Down
3 changes: 2 additions & 1 deletion Telegram/SourceFiles/boxes/stickers_box.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2282,7 +2282,8 @@ void StickersBox::Inner::handleMegagroupSetAddressChange() {
}
} else if (!_megagroupSetRequestId) {
_megagroupSetRequestId = _api.request(TLsearchStickerSet(
tl_string(text)
tl_string(text),
tl_bool(true)
)).done([=](const TLstickerSet &result) {
_megagroupSetRequestId = 0;
const auto set = session().data().stickers().feedSetFull(result);
Expand Down
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
Loading

0 comments on commit 38e09c2

Please sign in to comment.