From bdc3648f0faff6b014e60d271791294983bc4411 Mon Sep 17 00:00:00 2001 From: John Preston Date: Wed, 9 Oct 2024 21:02:44 +0400 Subject: [PATCH] wip4 --- Telegram/SourceFiles/data/data_web_page.cpp | 4 +- .../admin_log/history_admin_log_item.cpp | 58 +++++++++++++++++-- Telegram/SourceFiles/history/history.h | 2 +- Telegram/SourceFiles/iv/iv_data.cpp | 9 ++- Telegram/SourceFiles/iv/iv_data.h | 2 +- Telegram/SourceFiles/iv/iv_instance.cpp | 58 +++++++++++++++++++ Telegram/SourceFiles/iv/iv_instance.h | 21 +++++++ 7 files changed, 141 insertions(+), 13 deletions(-) diff --git a/Telegram/SourceFiles/data/data_web_page.cpp b/Telegram/SourceFiles/data/data_web_page.cpp index ef0e3432be0f1c..cc74064bd8e45b 100644 --- a/Telegram/SourceFiles/data/data_web_page.cpp +++ b/Telegram/SourceFiles/data/data_web_page.cpp @@ -623,7 +623,9 @@ void WebPageData::setFromTdb(const TLlinkPreview &data) { tl_bool(false) // force_full ), requestId).done([=](const TLwebPageInstantView &iv) { finish( - ignore ? nullptr : std::make_unique(data, iv), + (ignore + ? nullptr + : std::make_unique(data.data().vurl().v, iv)), ExtractCollage(owner, iv.data())); }).fail([finish] { finish(nullptr, {}); diff --git a/Telegram/SourceFiles/history/admin_log/history_admin_log_item.cpp b/Telegram/SourceFiles/history/admin_log/history_admin_log_item.cpp index 679fa07dba1c3c..aaf033771199ee 100644 --- a/Telegram/SourceFiles/history/admin_log/history_admin_log_item.cpp +++ b/Telegram/SourceFiles/history/admin_log/history_admin_log_item.cpp @@ -987,6 +987,7 @@ void GenerateItems( using LogBan = TLDchatEventMemberRestricted; using LogPromote = TLDchatEventMemberPromoted; using LogSticker = TLDchatEventStickerSetChanged; + using LogEmoji = TLDchatEventCustomEmojiStickerSetChanged; using LogPreHistory = TLDchatEventIsAllHistoryAvailableToggled; using LogPermissions = TLDchatEventPermissionsChanged; using LogPoll = TLDchatEventPollStopped; @@ -1015,8 +1016,10 @@ void GenerateItems( using LogToggleAntiSpam = TLDchatEventHasAggressiveAntiSpamEnabledToggled; using LogToggleTopicClosed = TLDchatEventForumTopicToggleIsClosed; using LogToggleTopicHidden = TLDchatEventForumTopicToggleIsHidden; - using LogChangeColor = TLDchatEventAccentColorChanged; - using LogChangeBackgroundEmoji = TLDchatEventBackgroundCustomEmojiChanged; + using LogChangePeerColor = TLDchatEventAccentColorChanged; + using LogChangeProfilePeerColor = TLDchatEventProfileAccentColorChanged; + using LogChangeWallpaper = TLDchatEventBackgroundChanged; + using LogChangeEmojiStatus = TLDchatEventEmojiStatusChanged; const auto session = &history->session(); const auto id = event.vid().v; @@ -1224,13 +1227,11 @@ void GenerateItems( Ui::Text::WithEntities); addSimpleServiceMessage(text); - const auto detachExistingItem = false; addPart( history->createItem( history->nextNonHistoryEntryId(), PrepareLogMessage(message, date), - MessageFlag::AdminLogEntry, - detachExistingItem), + MessageFlag::AdminLogEntry), TimeId(message.data().vdate().v)); }; #if 0 // goodToRemove @@ -1472,8 +1473,12 @@ void GenerateItems( }; const auto createChangeEmojiSet = [&](const LogEmoji &action) { +#if 0 // mtp const auto set = action.vnew_stickerset(); const auto removed = (set.type() == mtpc_inputStickerSetEmpty); +#endif + const auto set = action.vnew_sticker_set_id().v; + const auto removed = !set; if (removed) { const auto text = tr::lng_admin_log_removed_emoji_group( tr::now, @@ -1498,7 +1503,10 @@ void GenerateItems( controller->show( Box( controller->uiShow(), +#if 0 // mtp Data::FromInputSet(set), +#endif + StickerSetIdentifier{ .id = uint64(set) }, Data::StickersType::Emoji), Ui::LayerOption::CloseOther); } @@ -2392,20 +2400,35 @@ void GenerateItems( }; const auto createColorChange = [&]( +#if 0 // mtp const MTPPeerColor &was, const MTPPeerColor &now, +#endif + int32 prevColor, + uint64 prevEmoji, + int32 nextColor, + uint64 nextEmoji, const auto &colorPhrase, const auto &setEmoji, const auto &removeEmoji, const auto &changeEmoji) { +#if 0 // mtp const auto prevColor = was.data().vcolor(); const auto nextColor = now.data().vcolor(); +#endif if (prevColor != nextColor) { +#if 0 // mtp const auto wrap = [&](tl::conditional value) { return value ? value->v : Data::DecideColorIndex(history->peer->id); }; +#endif + const auto wrap = [&](int32 value) { + return value + ? value + : Data::DecideColorIndex(history->peer->id); + }; const auto text = colorPhrase( tr::now, lt_from, @@ -2417,8 +2440,10 @@ void GenerateItems( Ui::Text::WithEntities); addSimpleServiceMessage(text); } +#if 0 // mtp const auto prevEmoji = was.data().vbackground_emoji_id().value_or_empty(); const auto nextEmoji = now.data().vbackground_emoji_id().value_or_empty(); +#endif if (prevEmoji != nextEmoji) { const auto text = !prevEmoji ? setEmoji( @@ -2455,8 +2480,14 @@ void GenerateItems( const auto createChangePeerColor = [&](const LogChangePeerColor &data) { createColorChange( +#if 0 // mtp data.vprev_value(), data.vnew_value(), +#endif + data.vold_accent_color_id().v, + data.vold_background_custom_emoji_id().v, + data.vnew_accent_color_id().v, + data.vnew_background_custom_emoji_id().v, tr::lng_admin_log_change_color, tr::lng_admin_log_set_background_emoji, tr::lng_admin_log_removed_background_emoji, @@ -2465,8 +2496,14 @@ void GenerateItems( const auto createChangeProfilePeerColor = [&](const LogChangeProfilePeerColor &data) { createColorChange( +#if 0 // mtp data.vprev_value(), data.vnew_value(), +#endif + data.vold_profile_accent_color_id().v, + data.vold_profile_background_custom_emoji_id().v, + data.vnew_profile_accent_color_id().v, + data.vnew_profile_background_custom_emoji_id().v, tr::lng_admin_log_change_profile_color, tr::lng_admin_log_set_profile_background_emoji, tr::lng_admin_log_removed_profile_background_emoji, @@ -2482,6 +2519,7 @@ void GenerateItems( }; const auto createChangeEmojiStatus = [&](const LogChangeEmojiStatus &data) { +#if 0 // mtp const auto parse = [](const MTPEmojiStatus &status) { return status.match([]( const MTPDemojiStatus &data) { @@ -2498,6 +2536,16 @@ void GenerateItems( const MTPDemojiStatusUntil &data) { return data.vuntil().v; }, [](const auto &) { return TimeId(); }); +#endif + const auto prevEmoji = data.vold_emoji_status() + ? data.vold_emoji_status()->data().vcustom_emoji_id().v + : DocumentId(); + const auto nextEmoji = data.vnew_emoji_status() + ? data.vnew_emoji_status()->data().vcustom_emoji_id().v + : DocumentId(); + const auto nextUntil = data.vnew_emoji_status() + ? data.vnew_emoji_status()->data().vexpiration_date().v + : TimeId(0); const auto text = !prevEmoji ? (nextUntil diff --git a/Telegram/SourceFiles/history/history.h b/Telegram/SourceFiles/history/history.h index 178b2b6e162c93..d6cb6c696c4348 100644 --- a/Telegram/SourceFiles/history/history.h +++ b/Telegram/SourceFiles/history/history.h @@ -231,7 +231,7 @@ class History final : public Data::Thread { MsgId id, const Tdb::TLmessage &message, MessageFlags localFlags, - bool detachExistingItem, + bool detachExistingItem = false, HistoryItem *replacing = nullptr); not_null createItem( BusinessShortcutId shortcutId, diff --git a/Telegram/SourceFiles/iv/iv_data.cpp b/Telegram/SourceFiles/iv/iv_data.cpp index 8a2ab2ad7e391a..54f3eda5ccca8e 100644 --- a/Telegram/SourceFiles/iv/iv_data.cpp +++ b/Telegram/SourceFiles/iv/iv_data.cpp @@ -21,8 +21,7 @@ namespace { bool FailureRecorded/* = false*/; -[[nodiscard]] uint64 IdFromTdb(const Tdb::TLlinkPreview &preview) { - const auto &url = preview.data().vurl().v; +[[nodiscard]] uint64 IdFromTdb(const QString &url) { return XXH64(url.data(), url.size() * sizeof(ushort), 0); } @@ -72,12 +71,12 @@ Data::Data(const MTPDwebPage &webpage, const MTPPage &page) #endif Data::Data( - const Tdb::TLlinkPreview &link, + const QString &url, const Tdb::TLwebPageInstantView &data) : _source(std::make_unique(Source{ - .pageId = IdFromTdb(link), + .pageId = IdFromTdb(url), .page = data, - .url = link.data().vurl().v, + .url = url, })) { } diff --git a/Telegram/SourceFiles/iv/iv_data.h b/Telegram/SourceFiles/iv/iv_data.h index eb38bc1abb3c89..fa84ebe39d4b86 100644 --- a/Telegram/SourceFiles/iv/iv_data.h +++ b/Telegram/SourceFiles/iv/iv_data.h @@ -48,7 +48,7 @@ class Data final { Data(const MTPDwebPage &webpage, const MTPPage &page); #endif Data( - const Tdb::TLlinkPreview &preview, + const QString &url, const Tdb::TLwebPageInstantView &data); ~Data(); diff --git a/Telegram/SourceFiles/iv/iv_instance.cpp b/Telegram/SourceFiles/iv/iv_instance.cpp index a49ba8887773e4..3e921d6b2890ae 100644 --- a/Telegram/SourceFiles/iv/iv_instance.cpp +++ b/Telegram/SourceFiles/iv/iv_instance.cpp @@ -49,12 +49,17 @@ For license and copyright information please follow this link: #include "window/window_session_controller.h" #include "window/window_session_controller_link_info.h" +#include "tdb/tdb_tl_scheme.h" +#include "tdb/tdb_sender.h" + #include #include namespace Iv { namespace { +using namespace Tdb; + constexpr auto kGeoPointScale = 1; constexpr auto kGeoPointZoomMin = 13; constexpr auto kMaxLoadParts = 5; @@ -206,12 +211,19 @@ void Shown::fillChannelJoinedValues(const Prepared &result) { const auto channelId = ChannelId(id.toLongLong()); const auto channel = _session->data().channel(channelId); if (!channel->isLoaded() && !channel->username().isEmpty()) { +#if 0 // mtp channel->session().api().request(MTPcontacts_ResolveUsername( MTP_string(channel->username()) )).done([=](const MTPcontacts_ResolvedPeer &result) { channel->owner().processUsers(result.data().vusers()); channel->owner().processChats(result.data().vchats()); }).send(); +#endif + channel->session().sender().request(TLsearchPublicChat( + tl_string(channel->username()) + )).done([=](const TLchat &result) { + channel->owner().processPeer(result); + }).send(); } _inChannelValues[id] = Info::Profile::AmInChannelValue(channel); } @@ -847,10 +859,16 @@ void Instance::show( const auto url = event.url; auto &requested = _fullRequested[session][url]; requested.lastRequestedAt = crl::now(); +#if 0 // mtp session->api().request(MTPmessages_GetWebPage( MTP_string(url), MTP_int(requested.hash) )).done([=](const MTPmessages_WebPage &result) { +#endif + session->sender().request(TLgetWebPageInstantView( + tl_string(url), + tl_bool(true) + )).done([=](const TLwebPageInstantView &result) { const auto page = processReceivedPage(session, url, result); if (page && page->iv) { const auto parts = event.url.split('#'); @@ -904,7 +922,10 @@ void Instance::trackSession(not_null session) { _fullRequested.remove(session); _ivCache.remove(session); if (_ivRequestSession == session) { +#if 0 // mtp session->api().request(_ivRequestId).cancel(); +#endif + session->sender().request(_ivRequestId).cancel(); _ivRequestSession = nullptr; _ivRequestUri = QString(); _ivRequestId = 0; @@ -950,7 +971,10 @@ void Instance::openWithIvPreferred( const auto url = parts[0]; auto &cache = _ivCache[session]; if (const auto i = cache.find(url); i != end(cache)) { +#if 0 // mtp const auto page = i->second; +#endif + const auto &page = i->second; if (page && page->iv) { auto my = context.value(); if (const auto window = my.sessionWindow.get()) { @@ -965,25 +989,39 @@ void Instance::openWithIvPreferred( } else if (_ivRequestSession == session.get() && _ivRequestUri == uri) { return; } else if (_ivRequestId) { +#if 0 // mtp _ivRequestSession->api().request(_ivRequestId).cancel(); +#endif + _ivRequestSession->sender().request(_ivRequestId).cancel(); } +#if 0 // mtp const auto finish = [=](WebPageData *page) { +#endif + const auto finish = [=](PageIv *page) { Expects(_ivRequestSession == session); _ivRequestId = 0; _ivRequestUri = QString(); _ivRequestSession = nullptr; +#if 0 // mtp _ivCache[session][url] = page; +#endif openWithIvPreferred(session, uri, context); }; _ivRequestSession = session; _ivRequestUri = uri; auto &requested = _fullRequested[session][url]; requested.lastRequestedAt = crl::now(); +#if 0 // mtp _ivRequestId = session->api().request(MTPmessages_GetWebPage( MTP_string(url), MTP_int(requested.hash) )).done([=](const MTPmessages_WebPage &result) { +#endif + _ivRequestId = session->sender().request(TLgetWebPageInstantView( + tl_string(url), + tl_bool(true) + )).done([=](const TLwebPageInstantView &result) { finish(processReceivedPage(session, url, result)); }).fail([=] { finish(nullptr); @@ -1003,10 +1041,16 @@ void Instance::requestFull( return; } requested.lastRequestedAt = now; +#if 0 // mtp session->api().request(MTPmessages_GetWebPage( MTP_string(id), MTP_int(requested.hash) )).done([=](const MTPmessages_WebPage &result) { +#endif + session->sender().request(TLgetWebPageInstantView( + tl_string(id), + tl_bool(true) + )).done([=](const TLwebPageInstantView &result) { const auto page = processReceivedPage(session, id, result); if (page && page->iv && _shown && _shownSession == session) { _shown->update(page->iv.get()); @@ -1014,9 +1058,22 @@ void Instance::requestFull( }).send(); } +#if 0 // mtp WebPageData *Instance::processReceivedPage( +#endif +Instance::PageIv *Instance::processReceivedPage( not_null session, const QString &url, + const TLwebPageInstantView &result) { + auto owned = std::make_unique(PageIv{ + .iv = std::make_unique(url, result), + }); + const auto raw = owned.get(); + _ivCache[session][url] = std::move(owned); + auto &requested = _fullRequested[session][url]; + requested.page = raw; + return raw; +#if 0 // mtp const MTPmessages_WebPage &result) { const auto &data = result.data(); const auto owner = &session->data(); @@ -1038,6 +1095,7 @@ WebPageData *Instance::processReceivedPage( requested.page = owner->processWebpage(mtp).get(); }); return requested.page; +#endif } void Instance::processOpenChannel(const QString &context) { diff --git a/Telegram/SourceFiles/iv/iv_instance.h b/Telegram/SourceFiles/iv/iv_instance.h index 9083734adf2fbf..056c63f7888776 100644 --- a/Telegram/SourceFiles/iv/iv_instance.h +++ b/Telegram/SourceFiles/iv/iv_instance.h @@ -9,6 +9,10 @@ For license and copyright information please follow this link: #include "iv/iv_delegate.h" +namespace Tdb { +class TLwebPageInstantView; +} // namespace Tdb + namespace Main { class Session; class SessionShow; @@ -61,9 +65,15 @@ class Instance final { [[nodiscard]] rpl::lifetime &lifetime(); private: + struct PageIv { + std::unique_ptr iv; + }; struct FullResult { crl::time lastRequestedAt = 0; +#if 0 // mtp WebPageData *page = nullptr; +#endif + PageIv *page = nullptr; int32 hash = 0; }; @@ -73,10 +83,16 @@ class Instance final { void trackSession(not_null session); +#if 0 // mtp WebPageData *processReceivedPage( not_null session, const QString &url, const MTPmessages_WebPage &result); +#endif + PageIv *processReceivedPage( + not_null session, + const QString &url, + const Tdb::TLwebPageInstantView &result); const not_null _delegate; @@ -90,9 +106,14 @@ class Instance final { not_null, base::flat_map> _fullRequested; +#if 0 // mtp base::flat_map< not_null, base::flat_map> _ivCache; +#endif + base::flat_map< + not_null, + base::flat_map>> _ivCache; Main::Session *_ivRequestSession = nullptr; QString _ivRequestUri; mtpRequestId _ivRequestId = 0;