mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-08 08:04:08 +02:00
Moved text changes of QAction in peer menu to single place.
This commit is contained in:
parent
ce3279143d
commit
622c1a910b
1 changed files with 34 additions and 36 deletions
|
@ -67,6 +67,15 @@ namespace {
|
||||||
constexpr auto kArchivedToastDuration = crl::time(5000);
|
constexpr auto kArchivedToastDuration = crl::time(5000);
|
||||||
constexpr auto kMaxUnreadWithoutConfirmation = 10000;
|
constexpr auto kMaxUnreadWithoutConfirmation = 10000;
|
||||||
|
|
||||||
|
void SetActionText(not_null<QAction*> action, rpl::producer<QString> &&text) {
|
||||||
|
const auto lifetime = Ui::CreateChild<rpl::lifetime>(action.get());
|
||||||
|
std::move(
|
||||||
|
text
|
||||||
|
) | rpl::start_with_next([=](const QString &actionText) {
|
||||||
|
action->setText(actionText);
|
||||||
|
}, *lifetime);
|
||||||
|
}
|
||||||
|
|
||||||
[[nodiscard]] bool IsUnreadHistory(not_null<History*> history) {
|
[[nodiscard]] bool IsUnreadHistory(not_null<History*> history) {
|
||||||
return (history->chatListUnreadCount() > 0)
|
return (history->chatListUnreadCount() > 0)
|
||||||
|| (history->chatListUnreadMark());
|
|| (history->chatListUnreadMark());
|
||||||
|
@ -353,13 +362,11 @@ void Filler::addTogglePin() {
|
||||||
};
|
};
|
||||||
const auto pinAction = _addAction(pinText(), pinToggle);
|
const auto pinAction = _addAction(pinText(), pinToggle);
|
||||||
|
|
||||||
const auto lifetime = Ui::CreateChild<rpl::lifetime>(pinAction);
|
auto actionText = history->session().changes().historyUpdates(
|
||||||
history->session().changes().historyUpdates(
|
|
||||||
history,
|
history,
|
||||||
Data::HistoryUpdate::Flag::IsPinned
|
Data::HistoryUpdate::Flag::IsPinned
|
||||||
) | rpl::start_with_next([=] {
|
) | rpl::map(pinText);
|
||||||
pinAction->setText(pinText());
|
SetActionText(pinAction, std::move(actionText));
|
||||||
}, *lifetime);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Filler::addInfo() {
|
void Filler::addInfo() {
|
||||||
|
@ -402,13 +409,11 @@ void Filler::addToggleUnreadMark() {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
const auto lifetime = Ui::CreateChild<rpl::lifetime>(action);
|
auto actionText = history->session().changes().historyUpdates(
|
||||||
history->session().changes().historyUpdates(
|
|
||||||
history,
|
history,
|
||||||
Data::HistoryUpdate::Flag::UnreadView
|
Data::HistoryUpdate::Flag::UnreadView
|
||||||
) | rpl::start_with_next([=] {
|
) | rpl::map(label);
|
||||||
action->setText(label());
|
SetActionText(action, std::move(actionText));
|
||||||
}, *lifetime);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Filler::addToggleArchive() {
|
void Filler::addToggleArchive() {
|
||||||
|
@ -417,24 +422,21 @@ void Filler::addToggleArchive() {
|
||||||
const auto isArchived = [=] {
|
const auto isArchived = [=] {
|
||||||
return (history->folder() != nullptr);
|
return (history->folder() != nullptr);
|
||||||
};
|
};
|
||||||
|
const auto label = [=] {
|
||||||
|
return isArchived()
|
||||||
|
? tr::lng_archived_remove(tr::now)
|
||||||
|
: tr::lng_archived_add(tr::now);
|
||||||
|
};
|
||||||
const auto toggle = [=] {
|
const auto toggle = [=] {
|
||||||
ToggleHistoryArchived(history, !isArchived());
|
ToggleHistoryArchived(history, !isArchived());
|
||||||
};
|
};
|
||||||
const auto archiveAction = _addAction(
|
const auto archiveAction = _addAction(label(), toggle);
|
||||||
(isArchived()
|
|
||||||
? tr::lng_archived_remove(tr::now)
|
|
||||||
: tr::lng_archived_add(tr::now)),
|
|
||||||
toggle);
|
|
||||||
|
|
||||||
const auto lifetime = Ui::CreateChild<rpl::lifetime>(archiveAction);
|
auto actionText = history->session().changes().historyUpdates(
|
||||||
history->session().changes().historyUpdates(
|
|
||||||
history,
|
history,
|
||||||
Data::HistoryUpdate::Flag::Folder
|
Data::HistoryUpdate::Flag::Folder
|
||||||
) | rpl::start_with_next([=] {
|
) | rpl::map(label);
|
||||||
archiveAction->setText(isArchived()
|
SetActionText(archiveAction, std::move(actionText));
|
||||||
? tr::lng_archived_remove(tr::now)
|
|
||||||
: tr::lng_archived_add(tr::now));
|
|
||||||
}, *lifetime);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Filler::addBlockUser(not_null<UserData*> user) {
|
void Filler::addBlockUser(not_null<UserData*> user) {
|
||||||
|
@ -463,13 +465,11 @@ void Filler::addBlockUser(not_null<UserData*> user) {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
const auto lifetime = Ui::CreateChild<rpl::lifetime>(blockAction);
|
auto actionText = _peer->session().changes().peerUpdates(
|
||||||
_peer->session().changes().peerUpdates(
|
|
||||||
_peer,
|
_peer,
|
||||||
Data::PeerUpdate::Flag::IsBlocked
|
Data::PeerUpdate::Flag::IsBlocked
|
||||||
) | rpl::start_with_next([=] {
|
) | rpl::map([=] { return blockText(user); });
|
||||||
blockAction->setText(blockText(user));
|
SetActionText(blockAction, std::move(actionText));
|
||||||
}, *lifetime);
|
|
||||||
|
|
||||||
if (user->blockStatus() == UserData::BlockStatus::Unknown) {
|
if (user->blockStatus() == UserData::BlockStatus::Unknown) {
|
||||||
user->session().api().requestFullPeer(user);
|
user->session().api().requestFullPeer(user);
|
||||||
|
@ -1128,10 +1128,10 @@ void PeerMenuAddMuteAction(
|
||||||
not_null<PeerData*> peer,
|
not_null<PeerData*> peer,
|
||||||
const PeerMenuCallback &addAction) {
|
const PeerMenuCallback &addAction) {
|
||||||
peer->owner().requestNotifySettings(peer);
|
peer->owner().requestNotifySettings(peer);
|
||||||
const auto muteText = [](bool isMuted) {
|
const auto muteText = [](bool isUnmuted) {
|
||||||
return isMuted
|
return isUnmuted
|
||||||
? tr::lng_enable_notifications_from_tray(tr::now)
|
? tr::lng_disable_notifications_from_tray(tr::now)
|
||||||
: tr::lng_disable_notifications_from_tray(tr::now);
|
: tr::lng_enable_notifications_from_tray(tr::now);
|
||||||
};
|
};
|
||||||
const auto muteAction = addAction(QString("-"), [=] {
|
const auto muteAction = addAction(QString("-"), [=] {
|
||||||
if (!peer->owner().notifyIsMuted(peer)) {
|
if (!peer->owner().notifyIsMuted(peer)) {
|
||||||
|
@ -1141,12 +1141,10 @@ void PeerMenuAddMuteAction(
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
const auto lifetime = Ui::CreateChild<rpl::lifetime>(muteAction);
|
auto actionText = Info::Profile::NotificationsEnabledValue(
|
||||||
Info::Profile::NotificationsEnabledValue(
|
|
||||||
peer
|
peer
|
||||||
) | rpl::start_with_next([=](bool enabled) {
|
) | rpl::map(muteText);
|
||||||
muteAction->setText(muteText(!enabled));
|
SetActionText(muteAction, std::move(actionText));
|
||||||
}, *lifetime);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void MenuAddMarkAsReadAllChatsAction(
|
void MenuAddMarkAsReadAllChatsAction(
|
||||||
|
|
Loading…
Add table
Reference in a new issue