mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2026-07-25 06:54:43 +00:00
Added ability to suggest birthday from edit contact box.
This commit is contained in:
@@ -777,6 +777,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||
"lng_settings_birthday_contacts" = "Only your contacts can see your birthday. {link}";
|
||||
"lng_settings_birthday_contacts_link" = "Change >";
|
||||
"lng_settings_birthday_saved" = "Your date of birth was updated.";
|
||||
"lng_settings_birthday_suggested" = "Date of birth was suggested to {user}";
|
||||
"lng_settings_birthday_reset" = "Remove";
|
||||
"lng_settings_channel_label" = "Personal channel";
|
||||
"lng_settings_channel_add" = "Add";
|
||||
@@ -4802,6 +4803,9 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||
"lng_contact_add_notes" = "Note";
|
||||
"lng_contact_add_notes_about" = "Notes are only visible to you.";
|
||||
"lng_suggest_photo_for" = "Suggest Photo for {user}";
|
||||
"lng_suggest_birthday" = "Suggest Date of Birth";
|
||||
"lng_suggest_birthday_box_title" = "{user}'s Date of Birth";
|
||||
"lng_suggest_birthday_box_confirm" = "Suggest";
|
||||
"lng_set_photo_for_user" = "Set Photo for {user}";
|
||||
"lng_contact_photo_replace_info" = "You can replace {user}'s photo with another photo that only you will see.";
|
||||
"lng_edit_contact_title" = "Edit contact";
|
||||
|
||||
@@ -14,6 +14,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||
#include "boxes/premium_preview_box.h"
|
||||
#include "chat_helpers/tabbed_panel.h"
|
||||
#include "chat_helpers/tabbed_selector.h"
|
||||
#include "core/application.h"
|
||||
#include "core/click_handler_types.h"
|
||||
#include "core/ui_integration.h"
|
||||
#include "data/data_changes.h"
|
||||
#include "data/data_document.h"
|
||||
@@ -450,6 +452,20 @@ void Controller::setupPhotoButtons() {
|
||||
const auto inner = _box->verticalLayout();
|
||||
Ui::AddSkip(inner);
|
||||
|
||||
const auto suggestBirthdayButton = Settings::AddButtonWithIcon(
|
||||
inner,
|
||||
tr::lng_suggest_birthday(),
|
||||
st::settingsButtonLightNoIcon);
|
||||
suggestBirthdayButton->setClickedCallback([=] {
|
||||
Core::App().openInternalUrl(
|
||||
u"internal:edit_birthday:suggest:%1"_q.arg(
|
||||
peerToUser(_user->id).bare),
|
||||
QVariant::fromValue(ClickHandlerContext{
|
||||
.sessionWindow = base::make_weak(_window),
|
||||
}));
|
||||
});
|
||||
suggestBirthdayButton->setVisible(!_user->birthday().valid());
|
||||
|
||||
const auto suggestButton = Settings::AddButtonWithIcon(
|
||||
inner,
|
||||
tr::lng_suggest_photo_for(lt_user, rpl::duplicate(nameValue)),
|
||||
|
||||
@@ -72,6 +72,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||
#include "main/main_session_settings.h"
|
||||
#include "info/info_controller.h"
|
||||
#include "info/info_memento.h"
|
||||
#include "info/profile/info_profile_values.h"
|
||||
#include "inline_bots/bot_attach_web_view.h"
|
||||
#include "history/history.h"
|
||||
#include "history/history_item.h"
|
||||
@@ -928,6 +929,53 @@ bool ShowEditBirthday(
|
||||
} else if (controller->showFrozenError()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
const auto captured = match->captured(1);
|
||||
if (captured.startsWith(u":suggest:"_q)) {
|
||||
const auto userIdStr = captured.mid(9); // Skip ":suggest:"
|
||||
const auto userId = UserId(userIdStr.toULongLong());
|
||||
if (!userId) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const auto targetUser
|
||||
= controller->session().data().userLoaded(userId);
|
||||
if (!targetUser) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const auto save = [=](Data::Birthday result) {
|
||||
using BFlag = MTPDbirthday::Flag;
|
||||
controller->session().api().request(MTPusers_SuggestBirthday(
|
||||
targetUser->inputUser,
|
||||
MTP_birthday(
|
||||
MTP_flags(result.year() ? BFlag::f_year : BFlag()),
|
||||
MTP_int(result.day()),
|
||||
MTP_int(result.month()),
|
||||
MTP_int(result.year()))
|
||||
)).done(crl::guard(controller, [=] {
|
||||
controller->showToast(
|
||||
tr::lng_settings_birthday_suggested(
|
||||
tr::now,
|
||||
lt_user,
|
||||
targetUser->name()));
|
||||
})).fail(crl::guard(controller, [=](const MTP::Error &error) {
|
||||
const auto type = error.type();
|
||||
controller->showToast(type.startsWith(u"FLOOD_WAIT_"_q)
|
||||
? tr::lng_flood_error(tr::now)
|
||||
: (u"Error: "_q + error.type()));
|
||||
})).handleFloodErrors().send();
|
||||
};
|
||||
|
||||
controller->show(Box([=](not_null<Ui::GenericBox*> box) {
|
||||
box->setTitle(tr::lng_suggest_birthday_box_title(
|
||||
lt_user,
|
||||
Info::Profile::NameValue(targetUser)));
|
||||
Ui::EditBirthdayBox(box, Data::Birthday(), save, true);
|
||||
}));
|
||||
return true;
|
||||
}
|
||||
|
||||
const auto user = controller->session().user();
|
||||
const auto save = [=](Data::Birthday result) {
|
||||
user->setBirthday(result);
|
||||
@@ -950,8 +998,8 @@ bool ShowEditBirthday(
|
||||
: (u"Error: "_q + error.type()));
|
||||
})).handleFloodErrors().send();
|
||||
};
|
||||
if (match->captured(1).isEmpty()) {
|
||||
controller->show(Box(Ui::EditBirthdayBox, user->birthday(), save));
|
||||
if (captured.isEmpty()) {
|
||||
controller->show(Box(Ui::EditBirthdayBox, user->birthday(), save, 0));
|
||||
} else {
|
||||
controller->show(Box([=](not_null<Ui::GenericBox*> box) {
|
||||
Ui::EditBirthdayBox(box, user->birthday(), save);
|
||||
|
||||
@@ -25,7 +25,8 @@ class GenericBox;
|
||||
void EditBirthdayBox(
|
||||
not_null<Ui::GenericBox*> box,
|
||||
Data::Birthday current,
|
||||
Fn<void(Data::Birthday)> save) {
|
||||
Fn<void(Data::Birthday)> save,
|
||||
bool useSuggestText) {
|
||||
box->setWidth(st::boxWideWidth);
|
||||
const auto content = box->addRow(object_ptr<Ui::FixedHeightWidget>(
|
||||
box,
|
||||
@@ -209,7 +210,10 @@ void EditBirthdayBox(
|
||||
return base::EventFilterResult::Continue;
|
||||
});
|
||||
|
||||
box->addButton(tr::lng_settings_save(), [=] {
|
||||
auto confirmText = useSuggestText
|
||||
? tr::lng_suggest_birthday_box_confirm()
|
||||
: tr::lng_settings_save();
|
||||
box->addButton(std::move(confirmText), [=] {
|
||||
const auto result = Data::Birthday(
|
||||
state->days.current()->index() + 1,
|
||||
state->months.current()->index() + 1,
|
||||
|
||||
@@ -18,6 +18,7 @@ class GenericBox;
|
||||
void EditBirthdayBox(
|
||||
not_null<Ui::GenericBox*> box,
|
||||
Data::Birthday current,
|
||||
Fn<void(Data::Birthday)> save);
|
||||
Fn<void(Data::Birthday)> save,
|
||||
bool useConfirmText = false);
|
||||
|
||||
} // namespace Ui
|
||||
|
||||
Reference in New Issue
Block a user