2
0
mirror of https://github.com/telegramdesktop/tdesktop synced 2025-09-01 06:55:58 +00:00

Pass SessionNavigation to some boxes.

This commit is contained in:
John Preston
2019-07-25 20:55:11 +02:00
parent 137fa0378c
commit bacaf805b5
54 changed files with 601 additions and 233 deletions

View File

@@ -27,6 +27,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "history/history.h"
#include "history/history_message.h"
#include "window/themes/window_theme.h"
#include "window/window_session_controller.h"
#include "boxes/peer_list_box.h"
#include "chat_helpers/emoji_suggestions_widget.h"
#include "data/data_channel.h"
@@ -43,7 +44,10 @@ class ShareBox::Inner
, public RPCSender
, private base::Subscriber {
public:
Inner(QWidget *parent, ShareBox::FilterCallback &&filterCallback);
Inner(
QWidget *parent,
not_null<Window::SessionNavigation*> navigation,
ShareBox::FilterCallback &&filterCallback);
void setPeerSelectedChangedCallback(
Fn<void(PeerData *peer, bool selected)> callback);
@@ -118,6 +122,8 @@ private:
void refresh();
const not_null<Window::SessionNavigation*> _navigation;
float64 _columnSkip = 0.;
float64 _rowWidthReal = 0.;
int _rowsLeft = 0;
@@ -150,10 +156,12 @@ private:
ShareBox::ShareBox(
QWidget*,
not_null<Window::SessionNavigation*> navigation,
CopyCallback &&copyCallback,
SubmitCallback &&submitCallback,
FilterCallback &&filterCallback)
: _copyCallback(std::move(copyCallback))
: _navigation(navigation)
, _copyCallback(std::move(copyCallback))
, _submitCallback(std::move(submitCallback))
, _filterCallback(std::move(filterCallback))
, _select(
@@ -209,6 +217,7 @@ void ShareBox::prepare() {
_inner = setInnerWidget(
object_ptr<Inner>(
this,
_navigation,
std::move(_filterCallback)),
getTopScrollSkip(),
getBottomScrollSkip());
@@ -221,7 +230,7 @@ void ShareBox::prepare() {
applyFilterUpdate(query);
});
_select->setItemRemovedCallback([=](uint64 itemId) {
if (const auto peer = Auth().data().peerLoaded(itemId)) {
if (const auto peer = _navigation->session().data().peerLoaded(itemId)) {
_inner->peerUnselected(peer);
selectedChanged();
update();
@@ -335,8 +344,8 @@ void ShareBox::peopleReceived(
switch (result.type()) {
case mtpc_contacts_found: {
auto &found = result.c_contacts_found();
Auth().data().processUsers(found.vusers());
Auth().data().processChats(found.vchats());
_navigation->session().data().processUsers(found.vusers());
_navigation->session().data().processChats(found.vchats());
_inner->peopleReceived(
query,
found.vmy_results().v,
@@ -479,8 +488,10 @@ void ShareBox::scrollAnimationCallback() {
ShareBox::Inner::Inner(
QWidget *parent,
not_null<Window::SessionNavigation*> navigation,
ShareBox::FilterCallback &&filterCallback)
: RpWidget(parent)
, _navigation(navigation)
, _filterCallback(std::move(filterCallback))
, _chatsIndexed(
std::make_unique<Dialogs::IndexedList>(
@@ -489,7 +500,7 @@ ShareBox::Inner::Inner(
_rowHeight = st::shareRowHeight;
setAttribute(Qt::WA_OpaquePaintEvent);
const auto self = Auth().user();
const auto self = _navigation->session().user();
if (_filterCallback(self)) {
_chatsIndexed->addToEnd(self->owner().history(self));
}
@@ -503,12 +514,12 @@ ShareBox::Inner::Inner(
}
}
};
addList(Auth().data().chatsList()->indexed());
addList(_navigation->session().data().chatsList()->indexed());
const auto id = Data::Folder::kId;
if (const auto folder = Auth().data().folderLoaded(id)) {
if (const auto folder = _navigation->session().data().folderLoaded(id)) {
addList(folder->chatsList()->indexed());
}
addList(Auth().data().contactsNoChatsList());
addList(_navigation->session().data().contactsNoChatsList());
_filter = qsl("a");
updateFilter();
@@ -518,7 +529,9 @@ ShareBox::Inner::Inner(
subscribe(Notify::PeerUpdated(), Notify::PeerUpdatedHandler(observeEvents, [this](const Notify::PeerUpdate &update) {
notifyPeerUpdated(update);
}));
subscribe(Auth().downloaderTaskFinished(), [this] { update(); });
subscribe(_navigation->session().downloaderTaskFinished(), [=] {
update();
});
subscribe(Window::Theme::Background(), [this](const Window::Theme::BackgroundUpdate &update) {
if (update.paletteChanged()) {
@@ -675,7 +688,7 @@ void ShareBox::Inner::loadProfilePhotos(int yFrom) {
yFrom *= _columnCount;
yTo *= _columnCount;
Auth().downloader().clearPriorities();
_navigation->session().downloader().clearPriorities();
if (_filter.isEmpty()) {
if (!_chatsIndexed->empty()) {
auto i = _chatsIndexed->cfind(yFrom, _rowHeight);
@@ -984,8 +997,8 @@ void ShareBox::Inner::peopleReceived(
d_byUsernameFiltered.reserve(already + my.size() + people.size());
const auto feedList = [&](const QVector<MTPPeer> &list) {
for (const auto &data : list) {
if (const auto peer = Auth().data().peerLoaded(peerFromMTP(data))) {
const auto history = Auth().data().historyLoaded(peer);
if (const auto peer = _navigation->session().data().peerLoaded(peerFromMTP(data))) {
const auto history = _navigation->session().data().historyLoaded(peer);
if (!_filterCallback(peer)) {
continue;
} else if (history && _chatsIndexed->getRow(history)) {
@@ -1030,15 +1043,18 @@ QVector<PeerData*> ShareBox::Inner::selected() const {
return result;
}
QString AppendShareGameScoreUrl(const QString &url, const FullMsgId &fullId) {
QString AppendShareGameScoreUrl(
not_null<Main::Session*> session,
const QString &url,
const FullMsgId &fullId) {
auto shareHashData = QByteArray(0x10, Qt::Uninitialized);
auto shareHashDataInts = reinterpret_cast<int32*>(shareHashData.data());
auto channel = fullId.channel
? Auth().data().channelLoaded(fullId.channel)
? session->data().channelLoaded(fullId.channel)
: static_cast<ChannelData*>(nullptr);
auto channelAccessHash = channel ? channel->access : 0ULL;
auto channelAccessHashInts = reinterpret_cast<int32*>(&channelAccessHash);
shareHashDataInts[0] = Auth().userId();
shareHashDataInts[0] = session->userId();
shareHashDataInts[1] = fullId.channel;
shareHashDataInts[2] = fullId.msg;
shareHashDataInts[3] = channelAccessHashInts[0];
@@ -1075,7 +1091,9 @@ QString AppendShareGameScoreUrl(const QString &url, const FullMsgId &fullId) {
return url + shareComponent;
}
void ShareGameScoreByHash(const QString &hash) {
void ShareGameScoreByHash(
not_null<Main::Session*> session,
const QString &hash) {
auto key128Size = 0x10;
auto hashEncrypted = QByteArray::fromBase64(hash.toLatin1(), QByteArray::Base64UrlEncoding | QByteArray::OmitTrailingEquals);
@@ -1105,7 +1123,7 @@ void ShareGameScoreByHash(const QString &hash) {
}
auto hashDataInts = reinterpret_cast<int32*>(hashData.data());
if (!Main::Session::Exists() || hashDataInts[0] != Auth().userId()) {
if (hashDataInts[0] != session->userId()) {
Ui::show(Box<InformBox>(tr::lng_share_wrong_user(tr::now)));
return;
}
@@ -1125,14 +1143,14 @@ void ShareGameScoreByHash(const QString &hash) {
return;
}
if (const auto item = Auth().data().message(channelId, msgId)) {
if (const auto item = session->data().message(channelId, msgId)) {
FastShareMessage(item);
} else {
auto resolveMessageAndShareScore = [=](ChannelData *channel) {
Auth().api().requestMessageData(channel, msgId, [](
session->api().requestMessageData(channel, msgId, [=](
ChannelData *channel,
MsgId msgId) {
if (const auto item = Auth().data().message(channel, msgId)) {
if (const auto item = session->data().message(channel, msgId)) {
FastShareMessage(item);
} else {
Ui::show(Box<InformBox>(tr::lng_edit_deleted(tr::now)));
@@ -1141,21 +1159,25 @@ void ShareGameScoreByHash(const QString &hash) {
};
const auto channel = channelId
? Auth().data().channelLoaded(channelId)
? session->data().channelLoaded(channelId)
: nullptr;
if (channel || !channelId) {
resolveMessageAndShareScore(channel);
} else {
auto requestChannelIds = MTP_vector<MTPInputChannel>(1, MTP_inputChannel(MTP_int(channelId), MTP_long(channelAccessHash)));
auto requestChannel = MTPchannels_GetChannels(requestChannelIds);
MTP::send(requestChannel, rpcDone([=](const MTPmessages_Chats &result) {
result.match([](const auto &data) {
Auth().data().processChats(data.vchats());
session->api().request(MTPchannels_GetChannels(
MTP_vector<MTPInputChannel>(
1,
MTP_inputChannel(
MTP_int(channelId),
MTP_long(channelAccessHash)))
)).done([=](const MTPmessages_Chats &result) {
result.match([&](const auto &data) {
session->data().processChats(data.vchats());
});
if (const auto channel = Auth().data().channelLoaded(channelId)) {
if (const auto channel = session->data().channelLoaded(channelId)) {
resolveMessageAndShareScore(channel);
}
}));
}).send();
}
}
}