mirror of
https://github.com/Qz3rK/tdesktop.git
synced 2026-06-02 03:53:42 +02:00
Added frequent contacts and search placeholder to gift picker.
This commit is contained in:
@@ -4008,6 +4008,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||
"lng_gift_availability" = "Availability";
|
||||
"lng_gift_from_hidden" = "Hidden User";
|
||||
"lng_gift_subtitle_birthdays" = "Birthdays";
|
||||
"lng_gift_recipient_search" = "Search people to send a gift to...";
|
||||
"lng_gift_list_birthday_status_today" = "{emoji} Birthday today";
|
||||
"lng_gift_list_birthday_status_yesterday" = "Birthday yesterday";
|
||||
"lng_gift_list_birthday_status_tomorrow" = "Birthday tomorrow";
|
||||
|
||||
@@ -41,6 +41,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||
#include "core/ui_integration.h"
|
||||
#include "data/components/gift_auctions.h"
|
||||
#include "data/components/promo_suggestions.h"
|
||||
#include "data/components/top_peers.h"
|
||||
#include "data/data_birthday.h"
|
||||
#include "data/data_changes.h"
|
||||
#include "data/data_channel.h"
|
||||
@@ -1929,6 +1930,8 @@ public:
|
||||
int fromIndex,
|
||||
int toIndex) override final;
|
||||
|
||||
[[nodiscard]] rpl::producer<QString> searchPlaceholder() const override;
|
||||
|
||||
void rowRightActionClicked(not_null<PeerListRow*> row) override final;
|
||||
base::unique_qptr<Ui::PopupMenu> rowContextMenu(
|
||||
QWidget *parent,
|
||||
@@ -1943,8 +1946,10 @@ private:
|
||||
|
||||
const PickCallback _pick;
|
||||
const std::vector<UserId> _contactBirthdays;
|
||||
const std::vector<not_null<UserData*>> _frequentUsers;
|
||||
CustomList _selfOption;
|
||||
CustomList _birthdayOptions;
|
||||
CustomList _frequentOptions;
|
||||
|
||||
base::unique_qptr<Ui::PopupMenu> _menu;
|
||||
|
||||
@@ -1952,6 +1957,27 @@ private:
|
||||
|
||||
};
|
||||
|
||||
[[nodiscard]] std::vector<not_null<UserData*>> CollectFrequentUsers(
|
||||
not_null<Main::Session*> session,
|
||||
const std::vector<UserId> &birthdays) {
|
||||
auto result = std::vector<not_null<UserData*>>();
|
||||
for (const auto &peer : session->topPeers().list()) {
|
||||
const auto user = peer->asUser();
|
||||
if (!user
|
||||
|| user->isSelf()
|
||||
|| user->isBot()
|
||||
|| user->isServiceUser()
|
||||
|| user->isInaccessible()) {
|
||||
continue;
|
||||
}
|
||||
if (ranges::contains(birthdays, peerToUser(user->id))) {
|
||||
continue;
|
||||
}
|
||||
result.push_back(user);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
[[nodiscard]] CustomList MakeCustomList(
|
||||
not_null<Main::Session*> session,
|
||||
Fn<void(not_null<PeerListController*>)> fill,
|
||||
@@ -2085,6 +2111,7 @@ Controller::Controller(not_null<Main::Session*> session, PickCallback pick)
|
||||
, _contactBirthdays(
|
||||
session->promoSuggestions().knownContactBirthdays().value_or(
|
||||
std::vector<UserId>{}))
|
||||
, _frequentUsers(CollectFrequentUsers(session, _contactBirthdays))
|
||||
, _selfOption(
|
||||
MakeCustomList(
|
||||
session,
|
||||
@@ -2095,9 +2122,11 @@ Controller::Controller(not_null<Main::Session*> session, PickCallback pick)
|
||||
controller->delegate()->peerListRefreshRows();
|
||||
},
|
||||
_pick,
|
||||
_contactBirthdays.empty()
|
||||
? tr::lng_contacts_header()
|
||||
: tr::lng_gift_subtitle_birthdays()))
|
||||
!_contactBirthdays.empty()
|
||||
? tr::lng_gift_subtitle_birthdays()
|
||||
: !_frequentUsers.empty()
|
||||
? tr::lng_settings_top_peers_title()
|
||||
: tr::lng_contacts_header()))
|
||||
, _birthdayOptions(
|
||||
MakeCustomList(
|
||||
session,
|
||||
@@ -2155,6 +2184,22 @@ Controller::Controller(not_null<Main::Session*> session, PickCallback pick)
|
||||
},
|
||||
_pick,
|
||||
_contactBirthdays.empty()
|
||||
? rpl::producer<QString>(nullptr)
|
||||
: !_frequentUsers.empty()
|
||||
? tr::lng_settings_top_peers_title()
|
||||
: tr::lng_contacts_header()))
|
||||
, _frequentOptions(
|
||||
MakeCustomList(
|
||||
session,
|
||||
[=](not_null<PeerListController*> controller) {
|
||||
for (const auto &user : _frequentUsers) {
|
||||
controller->delegate()->peerListAppendRow(
|
||||
std::make_unique<PeerRow>(user));
|
||||
}
|
||||
controller->delegate()->peerListRefreshRows();
|
||||
},
|
||||
_pick,
|
||||
_frequentUsers.empty()
|
||||
? rpl::producer<QString>(nullptr)
|
||||
: tr::lng_contacts_header())) {
|
||||
setStyleOverrides(&st::peerListSmallSkips);
|
||||
@@ -2182,11 +2227,14 @@ base::unique_qptr<Ui::PopupMenu> Controller::rowContextMenu(
|
||||
}
|
||||
|
||||
void Controller::noSearchSubmit() {
|
||||
if (const auto onstack = _selfOption.activate) {
|
||||
onstack();
|
||||
}
|
||||
if (const auto onstack = _birthdayOptions.activate) {
|
||||
onstack();
|
||||
for (const auto section : {
|
||||
&_selfOption,
|
||||
&_birthdayOptions,
|
||||
&_frequentOptions
|
||||
}) {
|
||||
if (const auto onstack = section->activate) {
|
||||
onstack();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2198,38 +2246,46 @@ bool Controller::overrideKeyboardNavigation(
|
||||
return true;
|
||||
}
|
||||
_skipUpDirectionSelect = false;
|
||||
const auto sections = std::array<CustomList*, 3>{
|
||||
&_selfOption,
|
||||
&_birthdayOptions,
|
||||
&_frequentOptions,
|
||||
};
|
||||
const auto count = int(sections.size());
|
||||
const auto selected = [&] {
|
||||
for (auto i = 0; i != count; ++i) {
|
||||
if (sections[i]->hasSelection && sections[i]->hasSelection()) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}();
|
||||
if (direction > 0) {
|
||||
if (!_selfOption.hasSelection() && !_birthdayOptions.hasSelection()) {
|
||||
return _selfOption.overrideKey(direction, from, to);
|
||||
if (selected < 0) {
|
||||
return sections.front()->overrideKey(direction, from, to);
|
||||
}
|
||||
if (_selfOption.hasSelection() && !_birthdayOptions.hasSelection()) {
|
||||
if (_selfOption.overrideKey(direction, from, to)) {
|
||||
return true;
|
||||
} else {
|
||||
return _birthdayOptions.overrideKey(direction, from, to);
|
||||
}
|
||||
if (sections[selected]->overrideKey(direction, from, to)) {
|
||||
return true;
|
||||
}
|
||||
if (!_selfOption.hasSelection() && _birthdayOptions.hasSelection()) {
|
||||
if (_birthdayOptions.overrideKey(direction, from, to)) {
|
||||
for (auto i = selected + 1; i != count; ++i) {
|
||||
if (sections[i]->overrideKey(direction, from, to)
|
||||
&& sections[i]->hasSelection()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
} else if (direction < 0) {
|
||||
if (!_selfOption.hasSelection() && !_birthdayOptions.hasSelection()) {
|
||||
return _birthdayOptions.overrideKey(direction, from, to);
|
||||
if (selected < 0) {
|
||||
return sections.back()->overrideKey(direction, from, to);
|
||||
}
|
||||
if (!_selfOption.hasSelection() && _birthdayOptions.hasSelection()) {
|
||||
if (_birthdayOptions.overrideKey(direction, from, to)) {
|
||||
return true;
|
||||
} else if (!_birthdayOptions.hasSelection()) {
|
||||
const auto res = _selfOption.overrideKey(direction, from, to);
|
||||
_skipUpDirectionSelect = _selfOption.hasSelection();
|
||||
return res;
|
||||
}
|
||||
if (sections[selected]->overrideKey(direction, from, to)) {
|
||||
_skipUpDirectionSelect = sections[selected]->hasSelection();
|
||||
return true;
|
||||
}
|
||||
if (_selfOption.hasSelection() && !_birthdayOptions.hasSelection()) {
|
||||
if (_selfOption.overrideKey(direction, from, to)) {
|
||||
_skipUpDirectionSelect = _selfOption.hasSelection();
|
||||
for (auto i = selected - 1; i >= 0; --i) {
|
||||
sections[i]->overrideKey(direction, from, to);
|
||||
if (sections[i]->hasSelection()) {
|
||||
_skipUpDirectionSelect = true;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -2245,6 +2301,9 @@ std::unique_ptr<PeerListRow> Controller::createRow(
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
if (ranges::contains(_frequentUsers, user)) {
|
||||
return nullptr;
|
||||
}
|
||||
if (user->isSelf()
|
||||
|| user->isBot()
|
||||
|| user->isServiceUser()
|
||||
@@ -2258,9 +2317,14 @@ void Controller::prepareViewHook() {
|
||||
auto list = object_ptr<Ui::VerticalLayout>((QWidget*)nullptr);
|
||||
list->add(std::move(_selfOption.content));
|
||||
list->add(std::move(_birthdayOptions.content));
|
||||
list->add(std::move(_frequentOptions.content));
|
||||
delegate()->peerListSetAboveWidget(std::move(list));
|
||||
}
|
||||
|
||||
rpl::producer<QString> Controller::searchPlaceholder() const {
|
||||
return tr::lng_gift_recipient_search();
|
||||
}
|
||||
|
||||
void Controller::rowClicked(not_null<PeerListRow*> row) {
|
||||
_pick(row->peer(), PickType::Activate);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user