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