mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-05 22:54:01 +02:00
Moved out importChatInvite from ApiWrap.
This commit is contained in:
parent
0f7b0c4227
commit
4fff812910
3 changed files with 76 additions and 57 deletions
|
@ -19,12 +19,85 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
#include "data/data_user.h"
|
#include "data/data_user.h"
|
||||||
#include "data/data_file_origin.h"
|
#include "data/data_file_origin.h"
|
||||||
#include "ui/boxes/confirm_box.h"
|
#include "ui/boxes/confirm_box.h"
|
||||||
|
#include "ui/toasts/common_toasts.h"
|
||||||
#include "boxes/abstract_box.h"
|
#include "boxes/abstract_box.h"
|
||||||
#include "styles/style_boxes.h"
|
#include "styles/style_boxes.h"
|
||||||
#include "styles/style_layers.h"
|
#include "styles/style_layers.h"
|
||||||
|
|
||||||
namespace Api {
|
namespace Api {
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
|
||||||
|
void SubmitChatInvite(
|
||||||
|
base::weak_ptr<Window::SessionController> weak,
|
||||||
|
not_null<Main::Session*> session,
|
||||||
|
const QString &hash,
|
||||||
|
bool isGroup) {
|
||||||
|
session->api().request(MTPmessages_ImportChatInvite(
|
||||||
|
MTP_string(hash)
|
||||||
|
)).done([=](const MTPUpdates &result) {
|
||||||
|
session->api().applyUpdates(result);
|
||||||
|
const auto strongController = weak.get();
|
||||||
|
if (!strongController) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
strongController->hideLayer();
|
||||||
|
const auto handleChats = [&](const MTPVector<MTPChat> &chats) {
|
||||||
|
if (chats.v.isEmpty()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const auto peerId = chats.v[0].match([](const MTPDchat &data) {
|
||||||
|
return peerFromChat(data.vid().v);
|
||||||
|
}, [](const MTPDchannel &data) {
|
||||||
|
return peerFromChannel(data.vid().v);
|
||||||
|
}, [](auto&&) {
|
||||||
|
return PeerId(0);
|
||||||
|
});
|
||||||
|
if (const auto peer = session->data().peerLoaded(peerId)) {
|
||||||
|
// Shows in the primary window anyway.
|
||||||
|
strongController->showPeerHistory(
|
||||||
|
peer,
|
||||||
|
Window::SectionShow::Way::Forward);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
result.match([&](const MTPDupdates &data) {
|
||||||
|
handleChats(data.vchats());
|
||||||
|
}, [&](const MTPDupdatesCombined &data) {
|
||||||
|
handleChats(data.vchats());
|
||||||
|
}, [&](auto &&) {
|
||||||
|
LOG(("API Error: unexpected update cons %1 "
|
||||||
|
"(ApiWrap::importChatInvite)").arg(result.type()));
|
||||||
|
});
|
||||||
|
}).fail([=](const MTP::Error &error) {
|
||||||
|
const auto strongController = weak.get();
|
||||||
|
if (!strongController) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const auto &type = error.type();
|
||||||
|
strongController->hideLayer();
|
||||||
|
Ui::ShowMultilineToast({
|
||||||
|
.parentOverride = Window::Show(strongController).toastParent(),
|
||||||
|
.text = { [&] {
|
||||||
|
if (type == u"INVITE_REQUEST_SENT"_q) {
|
||||||
|
return isGroup
|
||||||
|
? tr::lng_group_request_sent(tr::now)
|
||||||
|
: tr::lng_group_request_sent_channel(tr::now);
|
||||||
|
} else if (type == u"CHANNELS_TOO_MUCH"_q) {
|
||||||
|
return tr::lng_join_channel_error(tr::now);
|
||||||
|
} else if (type == u"USERS_TOO_MUCH"_q) {
|
||||||
|
return tr::lng_group_invite_no_room(tr::now);
|
||||||
|
} else {
|
||||||
|
return tr::lng_group_invite_bad_link(tr::now);
|
||||||
|
}
|
||||||
|
}() },
|
||||||
|
.duration = ApiWrap::kJoinErrorDuration });
|
||||||
|
}).send();
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace
|
||||||
|
|
||||||
void CheckChatInvite(
|
void CheckChatInvite(
|
||||||
not_null<Window::SessionController*> controller,
|
not_null<Window::SessionController*> controller,
|
||||||
const QString &hash,
|
const QString &hash,
|
||||||
|
@ -43,7 +116,7 @@ void CheckChatInvite(
|
||||||
session,
|
session,
|
||||||
data,
|
data,
|
||||||
invitePeekChannel,
|
invitePeekChannel,
|
||||||
[=] { session->api().importChatInvite(hash, isGroup); }));
|
[=] { SubmitChatInvite(weak, session, hash, isGroup); }));
|
||||||
if (invitePeekChannel) {
|
if (invitePeekChannel) {
|
||||||
box->boxClosing(
|
box->boxClosing(
|
||||||
) | rpl::filter([=] {
|
) | rpl::filter([=] {
|
||||||
|
|
|
@ -104,7 +104,6 @@ constexpr auto kStickersByEmojiInvalidateTimeout = crl::time(6 * 1000);
|
||||||
constexpr auto kNotifySettingSaveTimeout = crl::time(1000);
|
constexpr auto kNotifySettingSaveTimeout = crl::time(1000);
|
||||||
constexpr auto kDialogsFirstLoad = 20;
|
constexpr auto kDialogsFirstLoad = 20;
|
||||||
constexpr auto kDialogsPerPage = 500;
|
constexpr auto kDialogsPerPage = 500;
|
||||||
constexpr auto kJoinErrorDuration = 5 * crl::time(1000);
|
|
||||||
|
|
||||||
using PhotoFileLocationId = Data::PhotoFileLocationId;
|
using PhotoFileLocationId = Data::PhotoFileLocationId;
|
||||||
using DocumentFileLocationId = Data::DocumentFileLocationId;
|
using DocumentFileLocationId = Data::DocumentFileLocationId;
|
||||||
|
@ -347,60 +346,6 @@ void ApiWrap::checkChatInvite(
|
||||||
)).done(std::move(done)).fail(std::move(fail)).send();
|
)).done(std::move(done)).fail(std::move(fail)).send();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ApiWrap::importChatInvite(const QString &hash, bool isGroup) {
|
|
||||||
request(MTPmessages_ImportChatInvite(
|
|
||||||
MTP_string(hash)
|
|
||||||
)).done([=](const MTPUpdates &result) {
|
|
||||||
applyUpdates(result);
|
|
||||||
|
|
||||||
Ui::hideLayer();
|
|
||||||
const auto handleChats = [&](const MTPVector<MTPChat> &chats) {
|
|
||||||
if (chats.v.isEmpty()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
const auto peerId = chats.v[0].match([](const MTPDchat &data) {
|
|
||||||
return peerFromChat(data.vid().v);
|
|
||||||
}, [](const MTPDchannel &data) {
|
|
||||||
return peerFromChannel(data.vid().v);
|
|
||||||
}, [](auto&&) {
|
|
||||||
return PeerId(0);
|
|
||||||
});
|
|
||||||
if (const auto peer = _session->data().peerLoaded(peerId)) {
|
|
||||||
const auto &windows = _session->windows();
|
|
||||||
if (!windows.empty()) {
|
|
||||||
windows.front()->showPeerHistory(
|
|
||||||
peer,
|
|
||||||
Window::SectionShow::Way::Forward);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
result.match([&](const MTPDupdates &data) {
|
|
||||||
handleChats(data.vchats());
|
|
||||||
}, [&](const MTPDupdatesCombined &data) {
|
|
||||||
handleChats(data.vchats());
|
|
||||||
}, [&](auto &&) {
|
|
||||||
LOG(("API Error: unexpected update cons %1 "
|
|
||||||
"(ApiWrap::importChatInvite)").arg(result.type()));
|
|
||||||
});
|
|
||||||
}).fail([=](const MTP::Error &error) {
|
|
||||||
const auto &type = error.type();
|
|
||||||
Ui::hideLayer();
|
|
||||||
Ui::ShowMultilineToast({ .text = { [&] {
|
|
||||||
if (type == qstr("INVITE_REQUEST_SENT")) {
|
|
||||||
return isGroup
|
|
||||||
? tr::lng_group_request_sent(tr::now)
|
|
||||||
: tr::lng_group_request_sent_channel(tr::now);
|
|
||||||
} else if (type == qstr("CHANNELS_TOO_MUCH")) {
|
|
||||||
return tr::lng_join_channel_error(tr::now);
|
|
||||||
} else if (type == qstr("USERS_TOO_MUCH")) {
|
|
||||||
return tr::lng_group_invite_no_room(tr::now);
|
|
||||||
} else {
|
|
||||||
return tr::lng_group_invite_bad_link(tr::now);
|
|
||||||
}
|
|
||||||
}() }, .duration = kJoinErrorDuration });
|
|
||||||
}).send();
|
|
||||||
}
|
|
||||||
|
|
||||||
void ApiWrap::savePinnedOrder(Data::Folder *folder) {
|
void ApiWrap::savePinnedOrder(Data::Folder *folder) {
|
||||||
const auto &order = _session->data().pinnedChatsOrder(
|
const auto &order = _session->data().pinnedChatsOrder(
|
||||||
folder,
|
folder,
|
||||||
|
|
|
@ -196,7 +196,6 @@ public:
|
||||||
const QString &hash,
|
const QString &hash,
|
||||||
FnMut<void(const MTPChatInvite &)> done,
|
FnMut<void(const MTPChatInvite &)> done,
|
||||||
Fn<void(const MTP::Error &)> fail);
|
Fn<void(const MTP::Error &)> fail);
|
||||||
void importChatInvite(const QString &hash, bool isGroup);
|
|
||||||
|
|
||||||
void processFullPeer(
|
void processFullPeer(
|
||||||
not_null<PeerData*> peer,
|
not_null<PeerData*> peer,
|
||||||
|
@ -358,6 +357,8 @@ public:
|
||||||
|
|
||||||
void updatePrivacyLastSeens();
|
void updatePrivacyLastSeens();
|
||||||
|
|
||||||
|
static constexpr auto kJoinErrorDuration = 5 * crl::time(1000);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
struct MessageDataRequest {
|
struct MessageDataRequest {
|
||||||
using Callbacks = std::vector<Fn<void()>>;
|
using Callbacks = std::vector<Fn<void()>>;
|
||||||
|
|
Loading…
Add table
Reference in a new issue