Added ability to suggest birthday from edit contact box.
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user