mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-05 06:33:57 +02:00
Delete filter links, edit filter link names.
This commit is contained in:
parent
8a9d13c6e4
commit
fb16375a19
5 changed files with 117 additions and 39 deletions
|
@ -692,6 +692,7 @@ void EditFilterBox(
|
||||||
rules.never());
|
rules.never());
|
||||||
if (title.isEmpty()) {
|
if (title.isEmpty()) {
|
||||||
name->showError();
|
name->showError();
|
||||||
|
box->scrollToY(0);
|
||||||
return {};
|
return {};
|
||||||
} else if (!(rules.flags() & kTypes) && rules.always().empty()) {
|
} else if (!(rules.flags() & kTypes) && rules.always().empty()) {
|
||||||
window->window().showToast(tr::lng_filters_empty(tr::now));
|
window->window().showToast(tr::lng_filters_empty(tr::now));
|
||||||
|
|
|
@ -87,6 +87,7 @@ void ShowEmptyLinkError(not_null<Window::SessionController*> window) {
|
||||||
|
|
||||||
void ChatFilterLinkBox(
|
void ChatFilterLinkBox(
|
||||||
not_null<Ui::GenericBox*> box,
|
not_null<Ui::GenericBox*> box,
|
||||||
|
not_null<Main::Session*> session,
|
||||||
Data::ChatFilterLink data) {
|
Data::ChatFilterLink data) {
|
||||||
using namespace rpl::mappers;
|
using namespace rpl::mappers;
|
||||||
|
|
||||||
|
@ -139,10 +140,20 @@ void ChatFilterLinkBox(
|
||||||
labelField->setMaxLength(kMaxLinkTitleLength);
|
labelField->setMaxLength(kMaxLinkTitleLength);
|
||||||
Settings::AddDivider(container);
|
Settings::AddDivider(container);
|
||||||
|
|
||||||
|
box->setFocusCallback([=] {
|
||||||
|
labelField->setFocusFast();
|
||||||
|
});
|
||||||
|
|
||||||
const auto &saveLabel = link.isEmpty()
|
const auto &saveLabel = link.isEmpty()
|
||||||
? tr::lng_formatting_link_create
|
? tr::lng_formatting_link_create
|
||||||
: tr::lng_settings_save;
|
: tr::lng_settings_save;
|
||||||
box->addButton(saveLabel(), [=] {});
|
box->addButton(saveLabel(), [=] {
|
||||||
|
session->data().chatsFilters().edit(
|
||||||
|
data.id,
|
||||||
|
data.url,
|
||||||
|
labelField->getLastText().trimmed());
|
||||||
|
box->closeBox();
|
||||||
|
});
|
||||||
box->addButton(tr::lng_cancel(), [=] { box->closeBox(); });
|
box->addButton(tr::lng_cancel(), [=] { box->closeBox(); });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -420,6 +431,19 @@ void LinkController::addHeader(not_null<Ui::VerticalLayout*> container) {
|
||||||
}, divider->lifetime());
|
}, divider->lifetime());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
object_ptr<Ui::BoxContent> DeleteLinkBox(
|
||||||
|
not_null<Window::SessionController*> window,
|
||||||
|
const InviteLinkData &link) {
|
||||||
|
const auto sure = [=](Fn<void()> &&close) {
|
||||||
|
window->session().data().chatsFilters().destroy(link.id, link.url);
|
||||||
|
close();
|
||||||
|
};
|
||||||
|
return Ui::MakeConfirmBox({
|
||||||
|
u"Are you sure you want to delete this link?"_q, // langs
|
||||||
|
sure,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
void LinkController::addLinkBlock(not_null<Ui::VerticalLayout*> container) {
|
void LinkController::addLinkBlock(not_null<Ui::VerticalLayout*> container) {
|
||||||
using namespace Settings;
|
using namespace Settings;
|
||||||
|
|
||||||
|
@ -439,14 +463,14 @@ void LinkController::addLinkBlock(not_null<Ui::VerticalLayout*> container) {
|
||||||
Ui::LayerOption::KeepOther);
|
Ui::LayerOption::KeepOther);
|
||||||
});
|
});
|
||||||
const auto editLink = crl::guard(weak, [=] {
|
const auto editLink = crl::guard(weak, [=] {
|
||||||
//delegate()->peerListShowBox(
|
delegate()->peerListShowBox(
|
||||||
// EditLinkBox(_window, _data.current()),
|
Box(ChatFilterLinkBox, &_window->session(), _data),
|
||||||
// Ui::LayerOption::KeepOther);
|
Ui::LayerOption::KeepOther);
|
||||||
});
|
});
|
||||||
const auto deleteLink = crl::guard(weak, [=] {
|
const auto deleteLink = crl::guard(weak, [=] {
|
||||||
//delegate()->peerListShowBox(
|
delegate()->peerListShowBox(
|
||||||
// DeleteLinkBox(_window, _data.current()),
|
DeleteLinkBox(_window, _data),
|
||||||
// Ui::LayerOption::KeepOther);
|
Ui::LayerOption::KeepOther);
|
||||||
});
|
});
|
||||||
|
|
||||||
const auto createMenu = [=] {
|
const auto createMenu = [=] {
|
||||||
|
@ -466,7 +490,7 @@ void LinkController::addLinkBlock(not_null<Ui::VerticalLayout*> container) {
|
||||||
getLinkQr,
|
getLinkQr,
|
||||||
&st::menuIconQrCode);
|
&st::menuIconQrCode);
|
||||||
result->addAction(
|
result->addAction(
|
||||||
tr::lng_group_invite_context_edit(tr::now),
|
u"Name Link"_q, // langs
|
||||||
editLink,
|
editLink,
|
||||||
&st::menuIconEdit);
|
&st::menuIconEdit);
|
||||||
result->addAction(
|
result->addAction(
|
||||||
|
@ -502,6 +526,8 @@ void LinkController::addLinkBlock(not_null<Ui::VerticalLayout*> container) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void LinkController::prepare() {
|
void LinkController::prepare() {
|
||||||
|
Expects(!_data.url.isEmpty() || _data.chats.empty());
|
||||||
|
|
||||||
setupAboveWidget();
|
setupAboveWidget();
|
||||||
for (const auto &history : _data.chats) {
|
for (const auto &history : _data.chats) {
|
||||||
const auto peer = history->peer;
|
const auto peer = history->peer;
|
||||||
|
@ -522,7 +548,7 @@ void LinkController::prepare() {
|
||||||
delegate()->peerListAppendRow(std::move(row));
|
delegate()->peerListAppendRow(std::move(row));
|
||||||
if (const auto error = ErrorForSharing(history)) {
|
if (const auto error = ErrorForSharing(history)) {
|
||||||
raw->setCustomStatus(*error);
|
raw->setCustomStatus(*error);
|
||||||
} else {
|
} else if (!_data.url.isEmpty()) {
|
||||||
_allowed.emplace(peer);
|
_allowed.emplace(peer);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -663,32 +689,52 @@ base::unique_qptr<Ui::PopupMenu> LinksController::createRowContextMenu(
|
||||||
const auto real = static_cast<Row*>(row.get());
|
const auto real = static_cast<Row*>(row.get());
|
||||||
const auto data = real->data();
|
const auto data = real->data();
|
||||||
const auto link = data.url;
|
const auto link = data.url;
|
||||||
|
const auto copyLink = [=] {
|
||||||
|
CopyInviteLink(delegate()->peerListToastParent(), link);
|
||||||
|
};
|
||||||
|
const auto shareLink = [=] {
|
||||||
|
delegate()->peerListShowBox(
|
||||||
|
ShareInviteLinkBox(&_window->session(), link),
|
||||||
|
Ui::LayerOption::KeepOther);
|
||||||
|
};
|
||||||
|
const auto getLinkQr = [=] {
|
||||||
|
delegate()->peerListShowBox(
|
||||||
|
InviteLinkQrBox(link),
|
||||||
|
Ui::LayerOption::KeepOther);
|
||||||
|
};
|
||||||
|
const auto editLink = [=] {
|
||||||
|
delegate()->peerListShowBox(
|
||||||
|
Box(ChatFilterLinkBox, &_window->session(), data),
|
||||||
|
Ui::LayerOption::KeepOther);
|
||||||
|
};
|
||||||
|
const auto deleteLink = [=] {
|
||||||
|
delegate()->peerListShowBox(
|
||||||
|
DeleteLinkBox(_window, data),
|
||||||
|
Ui::LayerOption::KeepOther);
|
||||||
|
};
|
||||||
auto result = base::make_unique_q<Ui::PopupMenu>(
|
auto result = base::make_unique_q<Ui::PopupMenu>(
|
||||||
parent,
|
parent,
|
||||||
st::popupMenuWithIcons);
|
st::popupMenuWithIcons);
|
||||||
result->addAction(tr::lng_group_invite_context_copy(tr::now), [=] {
|
result->addAction(
|
||||||
//CopyInviteLink(delegate()->peerListToastParent(), link);
|
tr::lng_group_invite_context_copy(tr::now),
|
||||||
}, &st::menuIconCopy);
|
copyLink,
|
||||||
result->addAction(tr::lng_group_invite_context_share(tr::now), [=] {
|
&st::menuIconCopy);
|
||||||
//delegate()->peerListShowBox(
|
result->addAction(
|
||||||
// ShareInviteLinkBox(_peer, link),
|
tr::lng_group_invite_context_share(tr::now),
|
||||||
// Ui::LayerOption::KeepOther);
|
shareLink,
|
||||||
}, &st::menuIconShare);
|
&st::menuIconShare);
|
||||||
result->addAction(tr::lng_group_invite_context_qr(tr::now), [=] {
|
result->addAction(
|
||||||
//delegate()->peerListShowBox(
|
tr::lng_group_invite_context_qr(tr::now),
|
||||||
// InviteLinkQrBox(link),
|
getLinkQr,
|
||||||
// Ui::LayerOption::KeepOther);
|
&st::menuIconQrCode);
|
||||||
}, &st::menuIconQrCode);
|
result->addAction(
|
||||||
result->addAction(tr::lng_group_invite_context_edit(tr::now), [=] {
|
u"Name Link"_q, // langs
|
||||||
//delegate()->peerListShowBox(
|
editLink,
|
||||||
// EditLinkBox(_peer, data),
|
&st::menuIconEdit);
|
||||||
// Ui::LayerOption::KeepOther);
|
result->addAction(
|
||||||
}, &st::menuIconEdit);
|
tr::lng_group_invite_context_delete(tr::now),
|
||||||
result->addAction(tr::lng_group_invite_context_delete(tr::now), [=] {
|
deleteLink,
|
||||||
//delegate()->peerListShowBox(
|
&st::menuIconDelete);
|
||||||
// DeleteLinkBox(_peer, _admin, link),
|
|
||||||
// Ui::LayerOption::KeepOther);
|
|
||||||
}, &st::menuIconDelete);
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -454,15 +454,36 @@ void ChatFilters::edit(
|
||||||
if (i != end(links)) {
|
if (i != end(links)) {
|
||||||
i->title = title;
|
i->title = title;
|
||||||
_communityLinksUpdated.fire_copy(id);
|
_communityLinksUpdated.fire_copy(id);
|
||||||
|
|
||||||
|
_owner->session().api().request(MTPcommunities_EditExportedInvite(
|
||||||
|
MTP_flags(MTPcommunities_EditExportedInvite::Flag::f_title),
|
||||||
|
MTP_inputCommunityDialogFilter(MTP_int(id)),
|
||||||
|
MTP_string(url),
|
||||||
|
MTP_string(title),
|
||||||
|
MTPVector<MTPInputPeer>() // peers
|
||||||
|
)).done([=](const MTPExportedCommunityInvite &result) {
|
||||||
|
//const auto &data = result.data();
|
||||||
|
//const auto link = _owner->chatsFilters().add(id, result);
|
||||||
|
//done(link);
|
||||||
|
}).fail([=](const MTP::Error &error) {
|
||||||
|
//done({ .id = id });
|
||||||
|
}).send();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ChatFilters::remove(FilterId id, const QString &url) {
|
void ChatFilters::destroy(FilterId id, const QString &url) {
|
||||||
auto &links = _communityLinks[id];
|
auto &links = _communityLinks[id];
|
||||||
const auto i = ranges::find(links, url, &ChatFilterLink::url);
|
const auto i = ranges::find(links, url, &ChatFilterLink::url);
|
||||||
if (i != end(links)) {
|
if (i != end(links)) {
|
||||||
links.erase(i);
|
links.erase(i);
|
||||||
_communityLinksUpdated.fire_copy(id);
|
_communityLinksUpdated.fire_copy(id);
|
||||||
|
|
||||||
|
const auto api = &_owner->session().api();
|
||||||
|
api->request(_linksRequestId).cancel();
|
||||||
|
_linksRequestId = api->request(MTPcommunities_DeleteExportedInvite(
|
||||||
|
MTP_inputCommunityDialogFilter(MTP_int(id)),
|
||||||
|
MTP_string(url)
|
||||||
|
)).send();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -154,7 +154,7 @@ public:
|
||||||
FilterId id,
|
FilterId id,
|
||||||
const QString &url,
|
const QString &url,
|
||||||
const QString &title);
|
const QString &title);
|
||||||
void remove(FilterId id, const QString &url);
|
void destroy(FilterId id, const QString &url);
|
||||||
rpl::producer<std::vector<ChatFilterLink>> communityLinks(
|
rpl::producer<std::vector<ChatFilterLink>> communityLinks(
|
||||||
FilterId id) const;
|
FilterId id) const;
|
||||||
void reloadCommunityLinks(FilterId id);
|
void reloadCommunityLinks(FilterId id);
|
||||||
|
|
|
@ -629,6 +629,15 @@ void FilterRowButton::paintEvent(QPaintEvent *e) {
|
||||||
] {
|
] {
|
||||||
const auto api = &session->api();
|
const auto api = &session->api();
|
||||||
const auto filters = &session->data().chatsFilters();
|
const auto filters = &session->data().chatsFilters();
|
||||||
|
const auto ids = std::make_shared<
|
||||||
|
base::flat_set<mtpRequestId>
|
||||||
|
>();
|
||||||
|
const auto checkFinished = [=] {
|
||||||
|
if (ids->empty() && next) {
|
||||||
|
Assert(updated.id() != 0);
|
||||||
|
next(updated);
|
||||||
|
}
|
||||||
|
};
|
||||||
for (const auto &update : updates) {
|
for (const auto &update : updates) {
|
||||||
filters->apply(update);
|
filters->apply(update);
|
||||||
}
|
}
|
||||||
|
@ -639,15 +648,16 @@ void FilterRowButton::paintEvent(QPaintEvent *e) {
|
||||||
for (auto &request : requests) {
|
for (auto &request : requests) {
|
||||||
previousId = api->request(
|
previousId = api->request(
|
||||||
std::move(request)
|
std::move(request)
|
||||||
).afterRequest(previousId).send();
|
).done([=](const auto &, mtpRequestId id) {
|
||||||
|
ids->remove(id);
|
||||||
|
checkFinished();
|
||||||
|
}).afterRequest(previousId).send();
|
||||||
|
ids->emplace(previousId);
|
||||||
}
|
}
|
||||||
if (!order.empty() && !addRequests.empty()) {
|
if (!order.empty() && !addRequests.empty()) {
|
||||||
filters->saveOrder(order, previousId);
|
filters->saveOrder(order, previousId);
|
||||||
}
|
}
|
||||||
if (next) {
|
checkFinished();
|
||||||
Assert(updated.id() != 0);
|
|
||||||
next(updated);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
return [copy = state->save] {
|
return [copy = state->save] {
|
||||||
|
|
Loading…
Add table
Reference in a new issue