mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-04-11 11:47:09 +02:00
fix: more checks for disposal
This commit is contained in:
parent
ce8650b4de
commit
9ca0c3c41d
4 changed files with 121 additions and 78 deletions
|
@ -43,18 +43,20 @@ bool ResolveUser(
|
|||
return true;
|
||||
}
|
||||
|
||||
searchById(userId,
|
||||
&controller->session(),
|
||||
[=](const QString &title, UserData *data)
|
||||
{
|
||||
if (data) {
|
||||
controller->showPeerInfo(data);
|
||||
return;
|
||||
}
|
||||
searchById(
|
||||
userId,
|
||||
&controller->session(),
|
||||
[=](const QString &title, UserData *data)
|
||||
{
|
||||
if (data) {
|
||||
controller->showPeerInfo(data);
|
||||
return;
|
||||
}
|
||||
|
||||
Core::App().hideMediaView();
|
||||
Ui::show(Ui::MakeInformBox(tr::ayu_UserNotFoundMessage()));
|
||||
});
|
||||
Core::App().hideMediaView();
|
||||
Ui::show(Ui::MakeInformBox(tr::ayu_UserNotFoundMessage()));
|
||||
}
|
||||
);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -218,59 +218,73 @@ ActionStickerPackAuthor::ActionStickerPackAuthor(not_null<Menu::Menu*> menu,
|
|||
}
|
||||
|
||||
void ActionStickerPackAuthor::searchAuthor(ID authorId) {
|
||||
const auto pointer = Ui::MakeWeak(this);
|
||||
searchById(authorId,
|
||||
_session,
|
||||
[=](const QString &username, UserData *user)
|
||||
{
|
||||
if (!pointer) {
|
||||
LOG(("ContextActionStickerAuthor: searchById callback after destruction"));
|
||||
return;
|
||||
}
|
||||
if (username.isEmpty() && !user) {
|
||||
_subText = QString(tr::ayu_MessageDetailsPackOwnerNotFoundPC(tr::now));
|
||||
setClickedCallback(
|
||||
[=]
|
||||
{
|
||||
QGuiApplication::clipboard()->setText(QString::number(authorId));
|
||||
if (const auto window = _session->tryResolveWindow()) {
|
||||
if (const auto mainWidget = window->widget()->sessionController()) {
|
||||
mainWidget->showToast(tr::ayu_IDCopiedToast(tr::now));
|
||||
}
|
||||
}
|
||||
});
|
||||
const auto session = _session;
|
||||
const auto weak = Ui::MakeWeak(this);
|
||||
|
||||
crl::on_main(
|
||||
[=]
|
||||
{
|
||||
update();
|
||||
});
|
||||
return;
|
||||
}
|
||||
searchById(
|
||||
authorId,
|
||||
session,
|
||||
[session, weak, authorId](const QString &username, UserData *user)
|
||||
{
|
||||
if (!weak) {
|
||||
LOG(("ContextActionStickerAuthor: searchById callback after destruction"));
|
||||
return;
|
||||
}
|
||||
|
||||
const auto title = username.isEmpty() ? user ? user->name() : QString() : username;
|
||||
const auto callback = [=]
|
||||
{
|
||||
if (user) {
|
||||
if (const auto window = _session->tryResolveWindow()) {
|
||||
if (const auto mainWidget = window->widget()->sessionController()) {
|
||||
mainWidget->showPeer(user);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
QGuiApplication::clipboard()->setText(title);
|
||||
}
|
||||
};
|
||||
const auto strong = weak.data();
|
||||
if (!strong) {
|
||||
LOG(("ContextActionStickerAuthor: weak.data() returned null"));
|
||||
return;
|
||||
}
|
||||
|
||||
setClickedCallback(callback);
|
||||
if (username.isEmpty() && !user) {
|
||||
strong->_subText = QString(tr::ayu_MessageDetailsPackOwnerNotFoundPC(tr::now));
|
||||
strong->setClickedCallback(
|
||||
[authorId, session]
|
||||
{
|
||||
QGuiApplication::clipboard()->setText(QString::number(authorId));
|
||||
if (const auto window = session->tryResolveWindow()) {
|
||||
if (const auto mainWidget = window->widget()->sessionController()) {
|
||||
mainWidget->showToast(tr::ayu_IDCopiedToast(tr::now));
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
_subText = QString(title);
|
||||
crl::on_main(
|
||||
[=]
|
||||
{
|
||||
update();
|
||||
});
|
||||
});
|
||||
crl::on_main(
|
||||
[weak]
|
||||
{
|
||||
if (const auto strongInner = weak.data()) {
|
||||
strongInner->update();
|
||||
}
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
const auto title = username.isEmpty() ? (user ? user->name() : QString()) : username;
|
||||
const auto callback = [user, title, session]
|
||||
{
|
||||
if (user) {
|
||||
if (const auto window = session->tryResolveWindow()) {
|
||||
if (const auto mainWidget = window->widget()->sessionController()) {
|
||||
mainWidget->showPeer(user);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
QGuiApplication::clipboard()->setText(title);
|
||||
}
|
||||
};
|
||||
|
||||
strong->setClickedCallback(callback);
|
||||
strong->_subText = QString(title);
|
||||
crl::on_main(
|
||||
[weak]
|
||||
{
|
||||
if (const auto strongInner = weak.data()) {
|
||||
strongInner->update();
|
||||
}
|
||||
});
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
|
|
@ -771,30 +771,43 @@ void StickerSetBox::updateButtons() {
|
|||
const auto addPackOwner = [=](const std::shared_ptr<base::unique_qptr<Ui::PopupMenu>> &menu)
|
||||
{
|
||||
if (type == Data::StickersType::Stickers || type == Data::StickersType::Emoji) {
|
||||
const auto pointer = Ui::MakeWeak(this);
|
||||
const auto weak = Ui::MakeWeak(this);
|
||||
const auto session = _session;
|
||||
const auto innerId = _inner->setId() >> 32;
|
||||
|
||||
(*menu)->addAction(
|
||||
tr::ayu_MessageDetailsPackOwnerPC(tr::now),
|
||||
[=]
|
||||
[weak, session, innerId]
|
||||
{
|
||||
if (!pointer) {
|
||||
if (!weak) {
|
||||
return;
|
||||
}
|
||||
|
||||
const auto strong = weak.data();
|
||||
if (!strong) {
|
||||
return;
|
||||
}
|
||||
|
||||
searchById(
|
||||
_inner->setId() >> 32,
|
||||
_session,
|
||||
[=](const QString &username, UserData *user)
|
||||
innerId,
|
||||
session,
|
||||
[session, weak](const QString &username, UserData *user)
|
||||
{
|
||||
if (!pointer) {
|
||||
if (!weak) {
|
||||
return;
|
||||
}
|
||||
|
||||
const auto strongInner = weak.data();
|
||||
if (!strongInner) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!user) {
|
||||
showToast(tr::ayu_UserNotFoundMessage(tr::now));
|
||||
strongInner->showToast(tr::ayu_UserNotFoundMessage(tr::now));
|
||||
return;
|
||||
}
|
||||
|
||||
if (const auto window = _session->tryResolveWindow()) {
|
||||
if (const auto window = session->tryResolveWindow()) {
|
||||
if (const auto mainWidget = window->widget()->sessionController()) {
|
||||
mainWidget->showPeer(user);
|
||||
}
|
||||
|
|
|
@ -127,16 +127,30 @@ ResolvePhoneAction::ResolvePhoneAction(
|
|||
return;
|
||||
}
|
||||
|
||||
searchById(possibleId,
|
||||
&controller->session(),
|
||||
[=](const QString &username, UserData *user)
|
||||
{
|
||||
if (user) {
|
||||
_peer = user;
|
||||
}
|
||||
const auto weak = Ui::MakeWeak(this);
|
||||
const auto session = &controller->session();
|
||||
|
||||
_loaded.force_assign(true);
|
||||
});
|
||||
searchById(
|
||||
possibleId,
|
||||
session,
|
||||
[session, weak, possibleId](const QString &username, UserData *user)
|
||||
{
|
||||
if (!weak) {
|
||||
return;
|
||||
}
|
||||
|
||||
const auto strong = weak.data();
|
||||
if (!strong) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (user) {
|
||||
strong->_peer = user;
|
||||
}
|
||||
|
||||
strong->_loaded.force_assign(true);
|
||||
}
|
||||
);
|
||||
}
|
||||
}).send();
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue