Skip to content

Commit

Permalink
wip 1.8.18
Browse files Browse the repository at this point in the history
  • Loading branch information
john-preston committed Sep 15, 2023
1 parent a62706c commit a13a59b
Show file tree
Hide file tree
Showing 18 changed files with 463 additions and 275 deletions.
4 changes: 2 additions & 2 deletions Telegram/SourceFiles/api/api_authorizations.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ Authorizations::Entry ParseEntry(const Tdb::TLDsession &data) {
result.info = QString("%1%2").arg(
appName,
appVer.isEmpty() ? QString() : (' ' + appVer));
result.ip = data.vip().v;
result.ip = data.vip_address().v;
if (!result.hash) {
result.active = tr::lng_status_online(tr::now);
} else {
Expand All @@ -146,7 +146,7 @@ Authorizations::Entry ParseEntry(const Tdb::TLDsession &data) {
QLocale::ShortFormat);
}
}
result.location = data.vcountry().v;
result.location = data.vlocation().v;

return result;
}
Expand Down
25 changes: 13 additions & 12 deletions Telegram/SourceFiles/api/api_chat_invite.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,13 +156,11 @@ void CheckChatInvite(
Window::SectionShow::Way::Forward);
} else {
const auto isGroup = data.vtype().match([](
const TLDchatTypePrivate&) {
return false;
}, [](const TLDchatTypeBasicGroup&) {
const TLDinviteLinkChatTypeBasicGroup&) {
return true;
}, [&](const TLDinviteLinkChatTypeSupergroup&) {
return true;
}, [&](const TLDchatTypeSupergroup &data) {
return !data.vis_channel().v;
}, [](const TLDchatTypeSecret &) {
}, [](const TLDinviteLinkChatTypeChannel&) {
return false;
});
const auto box = strong->show(Box<ConfirmInviteBox>(
Expand Down Expand Up @@ -412,14 +410,17 @@ ConfirmInviteBox::ChatInvite ConfirmInviteBox::Parse(
.participants = std::move(participants),
.isPublic = data.vis_public().v,
.isRequestNeeded = data.vcreates_join_request().v,
.isFake = data.vis_fake().v,
.isScam = data.vis_scam().v,
.isVerified = data.vis_verified().v,
};
data.vtype().match([](const TLDchatTypePrivate&) {
}, [](const TLDchatTypeBasicGroup&) {
}, [&](const TLDchatTypeSupergroup &data) {
data.vtype().match([](const TLDinviteLinkChatTypeBasicGroup&) {
}, [&](const TLDinviteLinkChatTypeSupergroup&) {
result.isChannel = true;
result.isMegagroup = true;
}, [&](const TLDinviteLinkChatTypeChannel &data) {
result.isChannel = true;
result.isBroadcast = data.vis_channel().v;
result.isMegagroup = !result.isBroadcast;
}, [](const TLDchatTypeSecret &) {
result.isBroadcast = true;
});
return result;
}
Expand Down
8 changes: 4 additions & 4 deletions Telegram/SourceFiles/api/api_sending.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ void SendExistingMedia(
tl_int32(file->dimensions.width()),
tl_int32(file->dimensions.height()),
formatted,
tl_int32(0), // self_destruct_time
std::nullopt, // self_destruct_type
tl_bool(file->spoiler));
case PreparedFileType::Animation:
return tl_inputMessageAnimation(
Expand Down Expand Up @@ -271,7 +271,7 @@ void SendExistingMedia(
tl_int32(file->dimensions.height()),
tl_bool(file->supportsStreaming),
formatted,
tl_int32(0), // self_destruct_time
std::nullopt, // self_destruct_type
tl_bool(file->spoiler));
case PreparedFileType::VoiceNote:
return tl_inputMessageVoiceNote(
Expand Down Expand Up @@ -339,7 +339,7 @@ void SendExistingMedia(
tl_int32(document->dimensions.height()),
tl_bool(document->supportsStreaming()),
formatted,
tl_int32(0), // self_destruct_time
std::nullopt, // self_destruct_type
tl_bool(false)); // has_spoiler
} else if (const auto song = document->song()) {
return tl_inputMessageAudio(
Expand Down Expand Up @@ -385,7 +385,7 @@ void SendExistingMedia(
tl_int32(photo->width()),
tl_int32(photo->height()),
formatted,
tl_int32(0), // self_destruct_time
std::nullopt, // self_destruct_type
tl_bool(false)); // spoiler
}

Expand Down
2 changes: 2 additions & 0 deletions Telegram/SourceFiles/api/api_updates.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3081,6 +3081,8 @@ void Updates::applyUpdate(const TLupdate &update) {
data.vterms_of_service().data(),
data.vterms_of_service_id().v.toUtf8()));
}, [&](const TLDupdateUsersNearby &data) {
}, [&](const TLDupdateUnconfirmedSession &data) {
// later
}, [&](const TLDupdateAttachmentMenuBots &data) {
session().attachWebView().apply(data);
}, [&](const TLDupdateWebAppMessageSent &data) {
Expand Down
2 changes: 1 addition & 1 deletion Telegram/SourceFiles/api/api_websites.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ Websites::Entry ParseEntry(
.platform = data.vplatform().v,
.domain = data.vdomain_name().v,
.browser = data.vbrowser().v,
.ip = data.vip().v,
.ip = data.vip_address().v,
.location = data.vlocation().v,
};
result.activeTime = data.vlast_active_date().v
Expand Down
14 changes: 14 additions & 0 deletions Telegram/SourceFiles/core/local_url_handlers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1174,6 +1174,20 @@ bool HandleLocalUrl(
.openWebAppUrl = openWebAppUrl,
}));
});
}, [&](const TLDinternalLinkTypeSideMenuBot &data) {
if (!controller) {
return false;
}
const auto botUsername = data.vbot_username().v;
const auto openWebAppUrl = data.vurl().v;
controller->showPeerByLink(Navigation::PeerByLinkInfo{
.usernameOrId = botUsername,
.attachBotMenuOpen = true,
.clickFromMessageId = my.itemId,
.attachBotMenuUrl = openWebAppUrl,
});
controller->window().activate();
return true;
}, [&](const TLDinternalLinkTypeAuthenticationCode &data) {
const auto account = controller
? &controller->session().account()
Expand Down
2 changes: 1 addition & 1 deletion Telegram/SourceFiles/data/data_story.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -716,7 +716,7 @@ void Story::applyFields(
return StoryPrivacy::CloseFriends;
}, [](const TLDstoryPrivacySettingsContacts &) {
return StoryPrivacy::Contacts;
}, [](const TLDstoryPrivacySettingsSelectedContacts &) {
}, [](const TLDstoryPrivacySettingsSelectedUsers &) {
return StoryPrivacy::SelectedContacts;
});
const auto noForwards = !data.vcan_be_forwarded().v;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ Tdb::TLmessage PrepareLogMessage(
Tdb::tl_vector<Tdb::TLunreadReaction>(),
std::nullopt, // reply_to
Tdb::tl_int53(0), // message_thread_id
Tdb::tl_int32(0), // self_destruct_time
std::nullopt, // self_destruct_type
Tdb::tl_double(0), // self_destruct_in
Tdb::tl_double(0), // auto_delete_in
message.data().vvia_bot_user_id(),
Expand Down
25 changes: 24 additions & 1 deletion Telegram/SourceFiles/history/history_item.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4365,7 +4365,30 @@ void HistoryItem::setServiceMessageByContent(
Ui::Text::Link(name, 1), // Link 1.
Ui::Text::WithEntities);
}, [&](const TLDmessageBotWriteAccessAllowed &data) {
prepared.text = { tr::lng_action_attach_menu_bot_allowed(tr::now) };
if (data.vby_request().v) {
prepared.text = {
tr::lng_action_webapp_bot_allowed(tr::now)
};
} else if (const auto app = data.vweb_app()) {
const auto &data = app->data();
const auto bot = history()->peer->asUser();
const auto appName = data.vshort_name().v;
const auto url = (bot && !appName.isEmpty())
? history()->session().createInternalLinkFull(
bot->username() + '/' + appName)
: QString();
prepared.text = tr::lng_action_bot_allowed_from_app(
tr::now,
lt_app,
(url.isEmpty()
? TextWithEntities{ u"App"_q }
: Ui::Text::Link(data.vtitle().v, url)),
Ui::Text::WithEntities);
} else {
prepared.text = {
tr::lng_action_attach_menu_bot_allowed(tr::now),
};
}
}, [&](const TLDmessageUserShared &data) {
prepared = prepareServiceTextForSharedPeer(
peerFromUser(data.vuser_id()));
Expand Down
84 changes: 62 additions & 22 deletions Telegram/SourceFiles/inline_bots/bot_attach_web_view.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -194,10 +194,10 @@ constexpr auto kRefreshBotsTimeout = 60 * 60 * crl::time(1000);
.icon = ResolveIcon(session, data),
.name = data.vname().v,
.types = ResolvePeerTypes(data),
.inactive = !ranges::contains(
session->attachWebView().attachBots(),
not_null{ user },
&AttachWebViewBot::user),
.inactive = !data.vis_added().v,
.inMainMenu = data.vshow_in_side_menu().v,
.inAttachMenu = data.vshow_in_attachment_menu().v,
.disclaimerRequired = data.vshow_disclaimer_in_side_menu().v,
.hasSettings = data.vsupports_settings().v,
.requestWriteAccess = data.vrequest_write_access().v,
} : std::optional<AttachWebViewBot>();
Expand Down Expand Up @@ -513,8 +513,8 @@ void MenuBotIcon::validate() {
return;
}
auto icon = QSvgRenderer(_media->bytes());
if (_bot.media->bytes().isEmpty()) {
icon.load(_bot.media->owner()->filepath());
if (_media->bytes().isEmpty()) {
icon.load(_media->owner()->filepath());
}
_mask = QImage(wanted, QImage::Format_ARGB32_Premultiplied);
_mask.setDevicePixelRatio(style::DevicePixelRatio());
Expand Down Expand Up @@ -763,28 +763,35 @@ void AttachWebView::botSwitchInlineQuery(
}

void AttachWebView::botCheckWriteAccess(Fn<void(bool allowed)> callback) {
#if 0 // tdlib todo
_session->sender().request(TLcanBotSendMessages(
tl_int53(peerToUser(_bot->id).bare)
)).done([=] {
callback(true);
#if 0 // mtp
_session->api().request(MTPbots_CanSendMessage(
_bot->inputUser
)).done([=](const MTPBool &result) {
callback(mtpIsTrue(result));
#endif
}).fail([=] {
callback(false);
}).send();
#endif
}

void AttachWebView::botAllowWriteAccess(Fn<void(bool allowed)> callback) {
#if 0 // tdlib todo
_session->sender().request(TLallowBotToSendMessages(
tl_int53(peerToUser(_bot->id).bare)
)).done([=] {
#if 0 // mtp
_session->api().request(MTPbots_AllowSendMessage(
_bot->inputUser
)).done([=](const MTPUpdates &result) {
_session->api().applyUpdates(result);
#endif
callback(true);
}).fail([=] {
callback(false);
}).send();
#endif
}

void AttachWebView::botSharePhone(Fn<void(bool shared)> callback) {
Expand Down Expand Up @@ -814,8 +821,17 @@ void AttachWebView::botSharePhone(Fn<void(bool shared)> callback) {

void AttachWebView::botInvokeCustomMethod(
Ui::BotWebView::CustomMethodRequest request) {
#if 0 // tdlib todo
const auto callback = request.callback;
_bot->session().sender().request(TLsendWebAppCustomRequest(
tl_int53(peerToUser(_bot->id).bare),
tl_string(request.method),
tl_string(QString::fromUtf8(request.params))
)).done([=](const TLDcustomRequestResult &data) {
callback(data.vresult().v.toUtf8());
}).fail([=](const Error &error) {
callback(base::make_unexpected(error.message));
}).send();
#if 0 // mtp
_bot->session().api().request(MTPbots_InvokeWebViewCustomMethod(
_bot->inputUser,
MTP_string(request.method),
Expand Down Expand Up @@ -1050,7 +1066,13 @@ void AttachWebView::requestAddToMenu(
auto context = base::take(_addToMenuContext);
const auto open = base::take(_addToMenuOpen);
if (const auto openApp = std::get_if<AddToMenuOpenApp>(&open)) {
#if 0 // mtp
_app = openApp->app;
#endif
_app = std::make_unique<BotAppData>(
&_session->data(),
BotAppId());
_app->apply(_bot->id, *openApp->data);
_startCommand = openApp->startCommand;
_context = std::move(context);
if (_appConfirmationRequired) {
Expand Down Expand Up @@ -1103,7 +1125,13 @@ void AttachWebView::requestAddToMenu(
return false;
}
const auto &openApp = v::get<AddToMenuOpenApp>(open);
#if 0 // mtp
_app = openApp.app;
#endif
_app = std::make_unique<BotAppData>(
&_session->data(),
BotAppId());
_app->apply(_bot->id, *openApp.data);
_startCommand = openApp.startCommand;
_context = std::make_unique<Context>(*context);
requestAppView(true);
Expand All @@ -1115,7 +1143,14 @@ void AttachWebView::requestAddToMenu(
}
} else if (v::is<AddToMenuOpenMenu>(open)) {
_bot = bot;
const auto menu = v::get<AddToMenuOpenMenu>(open);
requestSimple(strong, bot, {
.url = menu.urlForGetWebAppUrl.toUtf8(),
.fromMainMenu = true,
});
#if 0 // mtp
requestSimple(strong, bot, { .fromMainMenu = true });
#endif
return true;
} else if (const auto useTypes = chooseTypes & types) {
const auto done = [=](not_null<Data::Thread*> thread) {
Expand Down Expand Up @@ -1274,18 +1309,20 @@ void AttachWebView::requestSimple(
}

void AttachWebView::requestSimple(const WebViewButton &button) {
_requestId = _session->sender().request(TLopenWebApp(
peerToTdbChat(_bot->id),
_requestId = _session->sender().request(TLgetWebAppUrl(
tl_int53(peerToUser(_bot->id).bare),
tl_string(button.url),
Window::Theme::WebViewTheme(),
tl_string("tdesktop"),
tl_int53(0), // message_thread_id
std::nullopt
)).done([=](const TLwebAppInfo &result) {
tl_string("tdesktop")
)).done([=](const TLDhttpUrl &data) {
_requestId = 0;
const auto &data = result.data();
show(data.vlaunch_id().v, data.vurl().v, button.text);
show(
uint64(),
data.vurl().v,
button.text,
false,
nullptr,
button.fromMainMenu);
}).fail([=](const Error &error) {
_requestId = 0;
}).send();
Expand Down Expand Up @@ -1424,22 +1461,25 @@ void AttachWebView::requestApp(
}
#endif
_requestId = _session->sender().request(TLsearchWebApp(
tl_int53(peerToUser(bot->id).bare),
tl_int53(peerToUser(_bot->id).bare),
tl_string(appName)
)).done([=](const TLDfoundWebApp &data) {
_app = std::make_unique<BotAppData>(&_session->data(), BotAppId());
_app->apply(bot->id, data.vweb_app());
_app->apply(_bot->id, data.vweb_app());
const auto firstTime = !data.vskip_confirmation().v;

// Check if this app can be added to main menu.
// On fail it'll still be opened.
_appConfirmationRequired = firstTime || forceConfirmation;
#if 0 // mtp
_appRequestWriteAccess = result.data().is_request_write_access();
requestAddToMenu(_bot, AddToMenuOpenApp{
.app = _app,
#endif
_app->hasSettings = data.vsupports_settings().v;
_appRequestWriteAccess = data.vrequest_write_access().v;
requestAddToMenu(_bot, AddToMenuOpenApp{
.app = _app,
.data = std::make_shared<TLwebApp>(data.vweb_app()),
.startCommand = _startCommand,
});
}).fail([=] {
Expand Down
5 changes: 5 additions & 0 deletions Telegram/SourceFiles/inline_bots/bot_attach_web_view.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ For license and copyright information please follow this link:

namespace Tdb {
class TLDupdateAttachmentMenuBots;
class TLwebApp;
} // namespace Tdb

namespace Api {
Expand Down Expand Up @@ -80,9 +81,13 @@ struct AddToMenuOpenAttach {
PeerTypes chooseTypes;
};
struct AddToMenuOpenMenu {
QString urlForGetWebAppUrl;
};
struct AddToMenuOpenApp {
#if 0 // mtp
not_null<BotAppData*> app;
#endif
std::shared_ptr<Tdb::TLwebApp> data;
QString startCommand;
};
using AddToMenuOpen = std::variant<
Expand Down
Loading

0 comments on commit a13a59b

Please sign in to comment.