Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
john-preston committed Oct 9, 2024
1 parent 578974b commit 1779604
Show file tree
Hide file tree
Showing 58 changed files with 2,084 additions and 268 deletions.
1 change: 1 addition & 0 deletions Telegram/SourceFiles/api/api_chat_filters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -722,6 +722,7 @@ void SaveNewFilterPinned(
filterId,
filter.title(),
filter.iconEmoji(),
filter.colorIndex(),
filter.flags(),
std::move(always),
std::move(pinned),
Expand Down
5 changes: 3 additions & 2 deletions Telegram/SourceFiles/api/api_credits.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -367,9 +367,10 @@ Data::CreditTopupOptions CreditsTopupOptions::options() const {
return _options;
}

#if 0 // mtp
rpl::producer<not_null<PeerData*>> PremiumPeerBot(
not_null<Main::Session*> session) {
return rpl::single(not_null<PeerData*>(session->user()));
#if 0 // mtp this won't be used so just workaround it for now
const auto username = session->appConfig().get<QString>(
u"premium_bot_username"_q,
QString());
Expand Down Expand Up @@ -399,8 +400,8 @@ rpl::producer<not_null<PeerData*>> PremiumPeerBot(

return lifetime;
};
}
#endif
}

CreditsEarnStatistics::CreditsEarnStatistics(not_null<PeerData*> peer)
: StatisticsRequestSender(peer)
Expand Down
2 changes: 0 additions & 2 deletions Telegram/SourceFiles/api/api_credits.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,7 @@ class CreditsEarnStatistics final : public StatisticsRequestSender {

};

#if 0 // mtp
[[nodiscard]] rpl::producer<not_null<PeerData*>> PremiumPeerBot(
not_null<Main::Session*> session);
#endif

} // namespace Api
23 changes: 23 additions & 0 deletions Telegram/SourceFiles/api/api_sending.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -789,6 +789,14 @@ bool SendDice(MessageToSend &message) {
}

void SendLocation(SendAction action, float64 lat, float64 lon) {
SendPreparedMessage(
action,
tl_inputMessageLocation(
tl_location(tl_double(lat), tl_double(lon), tl_double(0)),
tl_int32(0), // live_period
tl_int32(0), // heading
tl_int32(0))); // proximity_alert_radius
#if 0 // mtp
SendSimpleMedia(
action,
MTP_inputMediaGeoPoint(
Expand All @@ -797,9 +805,23 @@ void SendLocation(SendAction action, float64 lat, float64 lon) {
MTP_double(lat),
MTP_double(lon),
MTPint()))); // accuracy_radius
#endif
}

void SendVenue(SendAction action, Data::InputVenue venue) {
SendPreparedMessage(
action,
tl_inputMessageVenue(tl_venue(
tl_location(
tl_double(venue.lat),
tl_double(venue.lon),
tl_double(0)),
tl_string(venue.title),
tl_string(venue.address),
tl_string(venue.provider),
tl_string(venue.id),
tl_string(venue.venueType))));
#if 0 // mtp
SendSimpleMedia(
action,
MTP_inputMediaVenue(
Expand All @@ -813,6 +835,7 @@ void SendVenue(SendAction action, Data::InputVenue venue) {
MTP_string(venue.provider),
MTP_string(venue.id),
MTP_string(venue.venueType)));
#endif
}

void FillMessagePostFlags(
Expand Down
1 change: 1 addition & 0 deletions Telegram/SourceFiles/api/api_updates.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ For license and copyright information please follow this link:
#include "boxes/peers/add_participants_box.h"
#include "window/notifications_manager.h"
#include "data/components/factchecks.h"
#include "mainwidget.h"

namespace Api {
namespace {
Expand Down
6 changes: 5 additions & 1 deletion Telegram/SourceFiles/api/api_user_privacy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ TLInputRules RulesToTL(const UserPrivacy::Rule &rule) {
tl_userPrivacySettingRuleAllowChatMembers(
tl_vector<TLint53>(chats)));
}
using Option = UserPrivacy::Option;
if (rule.always.premiums && (rule.option != Option::Everyone)) {
result.push_back(tl_userPrivacySettingRuleAllowPremiumUsers());
}
Expand Down Expand Up @@ -407,6 +408,7 @@ TLuserPrivacySetting KeyToTL(UserPrivacy::Key key) {
case Key::Voices:
return tl_userPrivacySettingAllowPrivateVoiceAndVideoNoteMessages();
case Key::About: return tl_userPrivacySettingShowBio();
case Key::Birthday: return tl_userPrivacySettingShowBirthdate();
}
Unexpected("Key in Api::UserPrivacy::KetToTL.");
}
Expand All @@ -430,8 +432,10 @@ UserPrivacy::Key TLToKey(const TLuserPrivacySetting &setting) {
return UserPrivacy::Key::AddedByPhone;
}, [](TLDuserPrivacySettingAllowPrivateVoiceAndVideoNoteMessages) {
return UserPrivacy::Key::Voices;
}, [](const TLDuserPrivacySettingShowBio &data) {
}, [](const TLDuserPrivacySettingShowBio &) {
return UserPrivacy::Key::About;
}, [](const TLDuserPrivacySettingShowBirthdate &) {
return UserPrivacy::Key::Birthday;
});
}

Expand Down
47 changes: 44 additions & 3 deletions Telegram/SourceFiles/apiwrap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ For license and copyright information please follow this link:
#include "tdb/tdb_option.h"
#include "tdb/tdb_tl_scheme.h"
#include "data/data_secret_chat.h"
#include "data/data_saved_messages.h"

namespace {

Expand Down Expand Up @@ -566,6 +567,18 @@ void ApiWrap::savePinnedOrder(not_null<Data::Forum*> forum) {

void ApiWrap::savePinnedOrder(not_null<Data::SavedMessages*> saved) {
const auto &order = _session->data().pinnedChatsOrder(saved);
const auto input = [&](Dialogs::Key key) {
if (const auto sublist = key.sublist()) {
return tl_int53(saved->sublistId(sublist));
}
Unexpected("Key type in pinnedDialogsOrder().");
};
sender().request(TLsetPinnedSavedMessagesTopics(
tl_vector<TLint53>(order
| ranges::views::transform(input)
| ranges::to<QVector>)
)).send();
#if 0 // mtp
const auto input = [](Dialogs::Key key) {
if (const auto sublist = key.sublist()) {
return MTP_inputDialogPeer(sublist->peer()->input);
Expand All @@ -582,6 +595,7 @@ void ApiWrap::savePinnedOrder(not_null<Data::SavedMessages*> saved) {
MTP_flags(MTPmessages_ReorderPinnedSavedDialogs::Flag::f_force),
MTP_vector(peers)
)).send();
#endif
}

void ApiWrap::toggleHistoryArchived(
Expand Down Expand Up @@ -2450,7 +2464,9 @@ void ApiWrap::sendNotifySettingsUpdates() {
)).afterDelay(kSmallDelayMs).send();
#endif
}
#if 0 // mtp
session().mtp().sendAnything();
#endif
}

void ApiWrap::saveDraftToCloudDelayed(not_null<Data::Thread*> thread) {
Expand Down Expand Up @@ -2749,15 +2765,16 @@ void ApiWrap::saveDraftsToCloud() {
}
return tl_draftMessage(
Api::MessageReplyTo(history, cloudDraft->reply),
tl_int32(0), // Date.
tl_int32(0), // date
tl_inputMessageText(
Api::FormattedTextToTdb(TextWithEntities{
textWithTags.text,
TextUtilities::ConvertTextTagsToEntities(
textWithTags.tags)
}),
Data::LinkPreviewOptions(cloudDraft->webpage),
tl_bool(true)));
tl_bool(true)),
tl_int64(0)); // effect_id
}();

history->startSavingCloudDraft(topicRootId);
Expand Down Expand Up @@ -3290,10 +3307,16 @@ void ApiWrap::setGroupEmojiSet(
Expects(megagroup->mgInfo != nullptr);

megagroup->mgInfo->emojiSet = set;
sender().request(TLsetSupergroupCustomEmojiStickerSet(
tl_int53(peerToChannel(megagroup->id).bare),
tl_int64(set.id)
)).send();
#if 0 // mtp
request(MTPchannels_SetEmojiStickers(
megagroup->inputChannel,
Data::InputStickerSet(set)
)).send();
#endif
_session->changes().peerUpdated(
megagroup,
Data::PeerUpdate::Flag::EmojiSet);
Expand Down Expand Up @@ -3976,11 +3999,17 @@ void ApiWrap::requestHistory(
return;
}

auto prepared = Api::PrepareHistoryRequest(peer, messageId, slice);
#if 0 // mtp
const auto prepared = Api::PrepareHistoryRequest(peer, messageId, slice);
auto &histories = history->owner().histories();
const auto requestType = Data::Histories::RequestType::History;
histories.sendRequest(history, requestType, [=](Fn<void()> finish) {
return request(
#endif
{
const auto finish = [] {};
sender().request(
std::move(prepared)
).done([=](const Api::HistoryRequestResult &result) {
_historyRequests.remove(key);
Expand All @@ -3998,7 +4027,10 @@ void ApiWrap::requestHistory(
_historyRequests.remove(key);
finish();
}).send();
}
#if 0 // mtp
});
#endif
_historyRequests.emplace(key);
}

Expand Down Expand Up @@ -4234,6 +4266,7 @@ void ApiWrap::forwardMessages(
tl_bool(false), // from_background
tl_bool(false), // update_order_of_installed_stickers_sets
Api::ScheduledToTL(action.options.scheduled),
tl_int64(0), // effect_id
tl_int32(0), // sending_id
tl_bool(false)), // only_preview
tl_bool(draft.options != Data::ForwardOptions::PreserveInfo),
Expand Down Expand Up @@ -4612,6 +4645,13 @@ void ApiWrap::cancelLocalItem(not_null<HistoryItem*> item) {
void ApiWrap::sendShortcutMessages(
not_null<PeerData*> peer,
BusinessShortcutId id) {
sender().request(TLsendQuickReplyShortcutMessages(
peerToTdbChat(peer->id),
tl_int32(id),
tl_int32(0) // sending_id
)).fail([=](const Error &error) {
}).send();
#if 0 // mtp
auto ids = QVector<MTPint>();
auto randomIds = QVector<MTPlong>();
request(MTPmessages_SendQuickReplyMessages(
Expand All @@ -4623,6 +4663,7 @@ void ApiWrap::sendShortcutMessages(
applyUpdates(result);
}).fail([=](const MTP::Error &error) {
}).send();
#endif
}

void ApiWrap::sendMessage(MessageToSend &&message) {
Expand Down Expand Up @@ -4908,7 +4949,7 @@ void ApiWrap::sendBotStart(
tl_string(token)
)).fail([=](const Error &error) {
if (chat) {
ShowAddParticipantsError(error.message, chat, { 1, bot });
ShowAddParticipantsError(show, error.message, chat, bot);
}
}).send();
#if 0 // mtp
Expand Down
76 changes: 51 additions & 25 deletions Telegram/SourceFiles/chat_helpers/emoji_keywords.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -703,32 +703,58 @@ mtpRequestId EmojiKeywords::requestMine(
.normalizedQuery = normalized,
.callback = std::move(callback),
});
_api->sender().request(TLsearchEmojis(
tl_string(normalized),
tl_bool(exact),
tl_vector<TLstring>(std::move(langs))
), requestId).done([=](const TLemojis &result) {
const auto request = _requests.take(requestId);
if (!request) {
return;
}
const auto &list = result.data().vemojis().v;
auto cloud = std::vector<Result>();
cloud.reserve(list.size());
for (const auto &emoji : list) {
if (const auto found = Find(emoji.v)) {
cloud.push_back(Result{ found });
const auto send = [&](auto &&request, auto &&parse) {
using Response = std::decay_t<decltype(request)>::ResponseType;
_api->sender().request(
std::move(request),
requestId
).done([=](const Response &result) {
const auto request = _requests.take(requestId);
if (!request) {
return;
}
}
if (!exact) {
AppendLegacySuggestions(cloud, request->query);
}
request->callback(ApplyVariants(PrioritizeRecent(std::move(cloud))));
}).fail([=] {
if (const auto request = _requests.take(requestId)) {
request->callback({});
}
}).send();
auto cloud = parse(result);
if (!exact) {
AppendLegacySuggestions(cloud, request->query);
}
request->callback(ApplyVariants(PrioritizeRecent(std::move(cloud))));
}).fail([=] {
if (const auto request = _requests.take(requestId)) {
request->callback({});
}
}).send();
};
if (exact) {
send(TLgetKeywordEmojis(
tl_string(normalized),
tl_vector<TLstring>(std::move(langs))
), [](const TLemojis &result) {
const auto &list = result.data().vemojis().v;
auto cloud = std::vector<Result>();
cloud.reserve(list.size());
for (const auto &emoji : list) {
if (const auto found = Find(emoji.v)) {
cloud.push_back(Result{ found });
}
}
return cloud;
});
} else {
send(TLsearchEmojis(
tl_string(normalized),
tl_vector<TLstring>(std::move(langs))
), [](const TLemojiKeywords &result) {
const auto &list = result.data().vemoji_keywords().v;
auto cloud = std::vector<Result>();
cloud.reserve(list.size());
for (const auto &emoji : list) {
if (const auto found = Find(emoji.data().vemoji().v)) {
cloud.push_back(Result{ found });
}
}
return cloud;
});
}
return requestId;
}

Expand Down
1 change: 1 addition & 0 deletions Telegram/SourceFiles/chat_helpers/stickers_list_widget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -590,6 +590,7 @@ void StickersListWidget::sendSearchRequest() {
}

_searchRequestId = _api.request(TLsearchStickerSets(
tl_stickerTypeRegular(),
tl_string(_searchQuery)
)).done([=](const TLstickerSets &result) {
searchResultsDone(result);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ BusinessDetails FromTL(
result.location.point = LocationPoint(*point);
}
}
if (const auto intro = data.vintro()) {
if (const auto intro = data.vstart_page()) {
const auto &data = intro->data();
result.intro.title = data.vtitle().v;
result.intro.description = data.vmessage().v;
Expand Down
Loading

0 comments on commit 1779604

Please sign in to comment.