mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-05 06:33:57 +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;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
searchById(userId,
|
searchById(
|
||||||
&controller->session(),
|
userId,
|
||||||
[=](const QString &title, UserData *data)
|
&controller->session(),
|
||||||
{
|
[=](const QString &title, UserData *data)
|
||||||
if (data) {
|
{
|
||||||
controller->showPeerInfo(data);
|
if (data) {
|
||||||
return;
|
controller->showPeerInfo(data);
|
||||||
}
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
Core::App().hideMediaView();
|
Core::App().hideMediaView();
|
||||||
Ui::show(Ui::MakeInformBox(tr::ayu_UserNotFoundMessage()));
|
Ui::show(Ui::MakeInformBox(tr::ayu_UserNotFoundMessage()));
|
||||||
});
|
}
|
||||||
|
);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -218,59 +218,73 @@ ActionStickerPackAuthor::ActionStickerPackAuthor(not_null<Menu::Menu*> menu,
|
||||||
}
|
}
|
||||||
|
|
||||||
void ActionStickerPackAuthor::searchAuthor(ID authorId) {
|
void ActionStickerPackAuthor::searchAuthor(ID authorId) {
|
||||||
const auto pointer = Ui::MakeWeak(this);
|
const auto session = _session;
|
||||||
searchById(authorId,
|
const auto weak = Ui::MakeWeak(this);
|
||||||
_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));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
crl::on_main(
|
searchById(
|
||||||
[=]
|
authorId,
|
||||||
{
|
session,
|
||||||
update();
|
[session, weak, authorId](const QString &username, UserData *user)
|
||||||
});
|
{
|
||||||
return;
|
if (!weak) {
|
||||||
}
|
LOG(("ContextActionStickerAuthor: searchById callback after destruction"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const auto title = username.isEmpty() ? user ? user->name() : QString() : username;
|
const auto strong = weak.data();
|
||||||
const auto callback = [=]
|
if (!strong) {
|
||||||
{
|
LOG(("ContextActionStickerAuthor: weak.data() returned null"));
|
||||||
if (user) {
|
return;
|
||||||
if (const auto window = _session->tryResolveWindow()) {
|
}
|
||||||
if (const auto mainWidget = window->widget()->sessionController()) {
|
|
||||||
mainWidget->showPeer(user);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
QGuiApplication::clipboard()->setText(title);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
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(
|
||||||
crl::on_main(
|
[weak]
|
||||||
[=]
|
{
|
||||||
{
|
if (const auto strongInner = weak.data()) {
|
||||||
update();
|
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
|
} // namespace
|
||||||
|
|
|
@ -771,30 +771,43 @@ void StickerSetBox::updateButtons() {
|
||||||
const auto addPackOwner = [=](const std::shared_ptr<base::unique_qptr<Ui::PopupMenu>> &menu)
|
const auto addPackOwner = [=](const std::shared_ptr<base::unique_qptr<Ui::PopupMenu>> &menu)
|
||||||
{
|
{
|
||||||
if (type == Data::StickersType::Stickers || type == Data::StickersType::Emoji) {
|
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(
|
(*menu)->addAction(
|
||||||
tr::ayu_MessageDetailsPackOwnerPC(tr::now),
|
tr::ayu_MessageDetailsPackOwnerPC(tr::now),
|
||||||
[=]
|
[weak, session, innerId]
|
||||||
{
|
{
|
||||||
if (!pointer) {
|
if (!weak) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const auto strong = weak.data();
|
||||||
|
if (!strong) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
searchById(
|
searchById(
|
||||||
_inner->setId() >> 32,
|
innerId,
|
||||||
_session,
|
session,
|
||||||
[=](const QString &username, UserData *user)
|
[session, weak](const QString &username, UserData *user)
|
||||||
{
|
{
|
||||||
if (!pointer) {
|
if (!weak) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const auto strongInner = weak.data();
|
||||||
|
if (!strongInner) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!user) {
|
if (!user) {
|
||||||
showToast(tr::ayu_UserNotFoundMessage(tr::now));
|
strongInner->showToast(tr::ayu_UserNotFoundMessage(tr::now));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (const auto window = _session->tryResolveWindow()) {
|
if (const auto window = session->tryResolveWindow()) {
|
||||||
if (const auto mainWidget = window->widget()->sessionController()) {
|
if (const auto mainWidget = window->widget()->sessionController()) {
|
||||||
mainWidget->showPeer(user);
|
mainWidget->showPeer(user);
|
||||||
}
|
}
|
||||||
|
|
|
@ -127,16 +127,30 @@ ResolvePhoneAction::ResolvePhoneAction(
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
searchById(possibleId,
|
const auto weak = Ui::MakeWeak(this);
|
||||||
&controller->session(),
|
const auto session = &controller->session();
|
||||||
[=](const QString &username, UserData *user)
|
|
||||||
{
|
|
||||||
if (user) {
|
|
||||||
_peer = user;
|
|
||||||
}
|
|
||||||
|
|
||||||
_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();
|
}).send();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue