2
0
mirror of https://github.com/kotatogram/kotatogram-desktop synced 2025-08-30 22:25:12 +00:00

Simplified saving self bio.

This commit is contained in:
23rd
2021-10-18 16:05:43 +03:00
parent b776308fd7
commit 94d5d20281
4 changed files with 22 additions and 54 deletions

View File

@@ -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);
}