Skip to content

Commit

Permalink
wip4
Browse files Browse the repository at this point in the history
  • Loading branch information
john-preston committed Oct 9, 2024
1 parent cea3d40 commit bdc3648
Show file tree
Hide file tree
Showing 7 changed files with 141 additions and 13 deletions.
4 changes: 3 additions & 1 deletion Telegram/SourceFiles/data/data_web_page.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<Iv::Data>(data, iv),
(ignore
? nullptr
: std::make_unique<Iv::Data>(data.data().vurl().v, iv)),
ExtractCollage(owner, iv.data()));
}).fail([finish] {
finish(nullptr, {});
Expand Down
58 changes: 53 additions & 5 deletions Telegram/SourceFiles/history/admin_log/history_admin_log_item.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand All @@ -1498,7 +1503,10 @@ void GenerateItems(
controller->show(
Box<StickerSetBox>(
controller->uiShow(),
#if 0 // mtp
Data::FromInputSet(set),
#endif
StickerSetIdentifier{ .id = uint64(set) },
Data::StickersType::Emoji),
Ui::LayerOption::CloseOther);
}
Expand Down Expand Up @@ -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<MTPint> 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,
Expand All @@ -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(
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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) {
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion Telegram/SourceFiles/history/history.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<HistoryItem*> createItem(
BusinessShortcutId shortcutId,
Expand Down
9 changes: 4 additions & 5 deletions Telegram/SourceFiles/iv/iv_data.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down Expand Up @@ -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>(Source{
.pageId = IdFromTdb(link),
.pageId = IdFromTdb(url),
.page = data,
.url = link.data().vurl().v,
.url = url,
})) {

}
Expand Down
2 changes: 1 addition & 1 deletion Telegram/SourceFiles/iv/iv_data.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
58 changes: 58 additions & 0 deletions Telegram/SourceFiles/iv/iv_instance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 <QtGui/QGuiApplication>
#include <QtGui/QWindow>

namespace Iv {
namespace {

using namespace Tdb;

constexpr auto kGeoPointScale = 1;
constexpr auto kGeoPointZoomMin = 13;
constexpr auto kMaxLoadParts = 5;
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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('#');
Expand Down Expand Up @@ -904,7 +922,10 @@ void Instance::trackSession(not_null<Main::Session*> 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;
Expand Down Expand Up @@ -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<ClickHandlerContext>();
if (const auto window = my.sessionWindow.get()) {
Expand All @@ -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);
Expand All @@ -1003,20 +1041,39 @@ 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());
}
}).send();
}

#if 0 // mtp
WebPageData *Instance::processReceivedPage(
#endif
Instance::PageIv *Instance::processReceivedPage(
not_null<Main::Session*> session,
const QString &url,
const TLwebPageInstantView &result) {
auto owned = std::make_unique<PageIv>(PageIv{
.iv = std::make_unique<Data>(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();
Expand All @@ -1038,6 +1095,7 @@ WebPageData *Instance::processReceivedPage(
requested.page = owner->processWebpage(mtp).get();
});
return requested.page;
#endif
}

void Instance::processOpenChannel(const QString &context) {
Expand Down
Loading

0 comments on commit bdc3648

Please sign in to comment.