mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-04-16 14:17:12 +02:00
Simplified saving self bio.
This commit is contained in:
parent
b776308fd7
commit
94d5d20281
4 changed files with 22 additions and 54 deletions
|
@ -4639,34 +4639,27 @@ void ApiWrap::saveContactSignupSilent(bool silent) {
|
|||
_contactSignupSilentRequestId = requestId;
|
||||
}
|
||||
|
||||
void ApiWrap::saveSelfBio(const QString &text, FnMut<void()> done) {
|
||||
if (_saveBioRequestId) {
|
||||
if (text != _saveBioText) {
|
||||
request(_saveBioRequestId).cancel();
|
||||
void ApiWrap::saveSelfBio(const QString &text) {
|
||||
if (_bio.requestId) {
|
||||
if (text != _bio.requestedText) {
|
||||
request(_bio.requestId).cancel();
|
||||
} else {
|
||||
if (done) {
|
||||
_saveBioDone = std::move(done);
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
_saveBioText = text;
|
||||
_saveBioDone = std::move(done);
|
||||
_saveBioRequestId = request(MTPaccount_UpdateProfile(
|
||||
_bio.requestedText = text;
|
||||
_bio.requestId = request(MTPaccount_UpdateProfile(
|
||||
MTP_flags(MTPaccount_UpdateProfile::Flag::f_about),
|
||||
MTPstring(),
|
||||
MTPstring(),
|
||||
MTP_string(text)
|
||||
)).done([=](const MTPUser &result) {
|
||||
_saveBioRequestId = 0;
|
||||
_bio.requestId = 0;
|
||||
|
||||
_session->data().processUsers(MTP_vector<MTPUser>(1, result));
|
||||
_session->user()->setAbout(_saveBioText);
|
||||
if (_saveBioDone) {
|
||||
_saveBioDone();
|
||||
}
|
||||
_session->data().processUser(result);
|
||||
_session->user()->setAbout(_bio.requestedText);
|
||||
}).fail([=](const MTP::Error &error) {
|
||||
_saveBioRequestId = 0;
|
||||
_bio.requestId = 0;
|
||||
}).send();
|
||||
}
|
||||
|
||||
|
|
|
@ -390,7 +390,7 @@ public:
|
|||
std::optional<bool> contactSignupSilentCurrent() const;
|
||||
void saveContactSignupSilent(bool silent);
|
||||
|
||||
void saveSelfBio(const QString &text, FnMut<void()> done);
|
||||
void saveSelfBio(const QString &text);
|
||||
|
||||
[[nodiscard]] Api::Authorizations &authorizations();
|
||||
[[nodiscard]] Api::AttachedStickers &attachedStickers();
|
||||
|
@ -708,9 +708,10 @@ private:
|
|||
|
||||
base::flat_map<FullMsgId, not_null<PeerData*>> _peerPhotoUploads;
|
||||
|
||||
mtpRequestId _saveBioRequestId = 0;
|
||||
FnMut<void()> _saveBioDone;
|
||||
QString _saveBioText;
|
||||
struct {
|
||||
mtpRequestId requestId = 0;
|
||||
QString requestedText;
|
||||
} _bio;
|
||||
|
||||
const std::unique_ptr<Api::Authorizations> _authorizations;
|
||||
const std::unique_ptr<Api::AttachedStickers> _attachedStickers;
|
||||
|
|
|
@ -255,12 +255,7 @@ void SetupRows(
|
|||
AddSkip(container, st::settingsInfoAfterSkip);
|
||||
}
|
||||
|
||||
struct BioManager {
|
||||
rpl::producer<bool> canSave;
|
||||
Fn<void(FnMut<void()> done)> save;
|
||||
};
|
||||
|
||||
BioManager SetupBio(
|
||||
void SetupBio(
|
||||
not_null<Ui::VerticalLayout*> container,
|
||||
not_null<UserData*> self) {
|
||||
AddDivider(container);
|
||||
|
@ -268,8 +263,7 @@ BioManager SetupBio(
|
|||
|
||||
const auto bioStyle = [] {
|
||||
auto result = st::settingsBio;
|
||||
result.textMargins.setRight(
|
||||
st::boxTextFont->spacew
|
||||
result.textMargins.setRight(st::boxTextFont->spacew
|
||||
+ st::boxTextFont->width(QString::number(kMaxBioLength)));
|
||||
return result;
|
||||
};
|
||||
|
@ -317,10 +311,9 @@ BioManager SetupBio(
|
|||
const auto countLeft = qMax(kMaxBioLength - text.size(), 0);
|
||||
countdown->setText(QString::number(countLeft));
|
||||
};
|
||||
const auto save = [=](FnMut<void()> done) {
|
||||
const auto save = [=] {
|
||||
self->session().api().saveSelfBio(
|
||||
TextUtilities::PrepareForSending(bio->getLastText()),
|
||||
std::move(done));
|
||||
TextUtilities::PrepareForSending(bio->getLastText()));
|
||||
};
|
||||
|
||||
Info::Profile::AboutValue(
|
||||
|
@ -343,7 +336,7 @@ BioManager SetupBio(
|
|||
const auto saved = *generation = std::abs(*generation) + 1;
|
||||
base::call_delayed(kSaveBioTimeout, bio, [=] {
|
||||
if (*generation == saved) {
|
||||
save(nullptr);
|
||||
save();
|
||||
*generation = 0;
|
||||
}
|
||||
});
|
||||
|
@ -356,7 +349,7 @@ BioManager SetupBio(
|
|||
// to 'container' lifetime, not to the 'bio' lifetime.
|
||||
container->lifetime().add([=] {
|
||||
if (*generation > 0) {
|
||||
save(nullptr);
|
||||
save();
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -366,7 +359,7 @@ BioManager SetupBio(
|
|||
cursor.setPosition(bio->getLastText().size());
|
||||
bio->setTextCursor(cursor);
|
||||
QObject::connect(bio, &Ui::InputField::submitted, [=] {
|
||||
save(nullptr);
|
||||
save();
|
||||
});
|
||||
QObject::connect(bio, &Ui::InputField::changed, updated);
|
||||
bio->setInstantReplaces(Ui::InstantReplaces::Default());
|
||||
|
@ -386,11 +379,6 @@ BioManager SetupBio(
|
|||
st::settingsBioLabelPadding);
|
||||
|
||||
AddSkip(container);
|
||||
|
||||
return BioManager{
|
||||
changed->events() | rpl::distinct_until_changed(),
|
||||
save
|
||||
};
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
@ -402,14 +390,6 @@ Information::Information(
|
|||
setupContent(controller);
|
||||
}
|
||||
|
||||
//rpl::producer<bool> Information::sectionCanSaveChanges() {
|
||||
// return _canSaveChanges.value();
|
||||
//}
|
||||
//
|
||||
//void Information::sectionSaveChanges(FnMut<void()> done) {
|
||||
// _save(std::move(done));
|
||||
//}
|
||||
|
||||
void Information::setupContent(
|
||||
not_null<Window::SessionController*> controller) {
|
||||
const auto content = Ui::CreateChild<Ui::VerticalLayout>(this);
|
||||
|
@ -418,9 +398,6 @@ void Information::setupContent(
|
|||
SetupPhoto(content, controller, self);
|
||||
SetupRows(content, controller, self);
|
||||
SetupBio(content, self);
|
||||
//auto manager = SetupBio(content, self);
|
||||
//_canSaveChanges = std::move(manager.canSave);
|
||||
//_save = std::move(manager.save);
|
||||
|
||||
Ui::ResizeFitChild(this, content);
|
||||
}
|
||||
|
|
|
@ -20,9 +20,6 @@ public:
|
|||
private:
|
||||
void setupContent(not_null<Window::SessionController*> controller);
|
||||
|
||||
//rpl::variable<bool> _canSaveChanges;
|
||||
//Fn<void(FnMut<void()> done)> _save;
|
||||
|
||||
};
|
||||
|
||||
} // namespace Settings
|
||||
|
|
Loading…
Add table
Reference in a new issue