2
0
mirror of https://github.com/telegramdesktop/tdesktop synced 2025-08-31 14:38:15 +00:00

Implement drag-n-drop to forum topics.

This commit is contained in:
John Preston
2022-11-01 11:18:56 +04:00
parent 6d215d3729
commit d5ea0149e8
23 changed files with 232 additions and 133 deletions

View File

@@ -497,20 +497,24 @@ void ChooseRecipientBoxController::rowClicked(not_null<PeerListRow*> row) {
(*weak)->closeBox();
}
};
const auto filter = [=](not_null<Data::ForumTopic*> topic) {
return guard && (!_filter || _filter(topic));
};
auto owned = Box<PeerListBox>(
std::make_unique<ChooseTopicBoxController>(
forum,
std::move(callback)),
std::move(callback),
filter),
[=](not_null<PeerListBox*> box) {
box->addButton(tr::lng_cancel(), [=] {
box->closeBox();
});
box->addButton(tr::lng_cancel(), [=] {
box->closeBox();
});
forum->destroyed(
) | rpl::start_with_next([=] {
box->closeBox();
}, box->lifetime());
});
forum->destroyed(
) | rpl::start_with_next([=] {
box->closeBox();
}, box->lifetime());
});
*weak = owned.data();
delegate()->peerListShowBox(std::move(owned));
return;
@@ -604,6 +608,49 @@ bool ChooseTopicSearchController::loadMoreRows() {
return !_allLoaded;
}
ChooseTopicBoxController::Row::Row(not_null<Data::ForumTopic*> topic)
: PeerListRow(topic->rootId().bare)
, _topic(topic) {
}
QString ChooseTopicBoxController::Row::generateName() {
return _topic->title();
}
QString ChooseTopicBoxController::Row::generateShortName() {
return _topic->title();
}
auto ChooseTopicBoxController::Row::generatePaintUserpicCallback()
-> PaintRoundImageCallback {
return [=](
Painter &p,
int x,
int y,
int outerWidth,
int size) {
auto view = std::shared_ptr<Data::CloudImageView>();
p.translate(x, y);
_topic->paintUserpic(p, view, {
.st = &st::forumTopicRow,
.now = crl::now(),
.width = outerWidth,
.paused = false,
});
p.translate(-x, -y);
};
}
auto ChooseTopicBoxController::Row::generateNameFirstLetters() const
-> const base::flat_set<QChar> & {
return _topic->chatListFirstLetters();
}
auto ChooseTopicBoxController::Row::generateNameWords() const
-> const base::flat_set<QString> & {
return _topic->chatListNameWords();
}
ChooseTopicBoxController::ChooseTopicBoxController(
not_null<Data::Forum*> forum,
FnMut<void(not_null<Data::ForumTopic*>)> callback,
@@ -656,8 +703,10 @@ void ChooseTopicBoxController::refreshRows(bool initial) {
const auto id = topic->rootId().bare;
auto already = delegate()->peerListFindRow(id);
if (initial || !already) {
delegate()->peerListAppendRow(createRow(topic));
added = true;
if (auto created = createRow(topic)) {
delegate()->peerListAppendRow(std::move(created));
added = true;
}
} else if (already->isSearchResult()) {
delegate()->peerListAppendFoundRow(already);
added = true;
@@ -681,49 +730,6 @@ std::unique_ptr<PeerListRow> ChooseTopicBoxController::createSearchRow(
return nullptr;
}
ChooseTopicBoxController::Row::Row(not_null<Data::ForumTopic*> topic)
: PeerListRow(topic->rootId().bare)
, _topic(topic) {
}
QString ChooseTopicBoxController::Row::generateName() {
return _topic->title();
}
QString ChooseTopicBoxController::Row::generateShortName() {
return _topic->title();
}
auto ChooseTopicBoxController::Row::generatePaintUserpicCallback()
-> PaintRoundImageCallback {
return [=](
Painter &p,
int x,
int y,
int outerWidth,
int size) {
auto view = std::shared_ptr<Data::CloudImageView>();
p.translate(x, y);
_topic->paintUserpic(p, view, {
.st = &st::forumTopicRow,
.now = crl::now(),
.width = outerWidth,
.paused = false,
});
p.translate(-x, -y);
};
}
auto ChooseTopicBoxController::Row::generateNameFirstLetters() const
-> const base::flat_set<QChar> & {
return _topic->chatListFirstLetters();
}
auto ChooseTopicBoxController::Row::generateNameWords() const
-> const base::flat_set<QString> & {
return _topic->chatListNameWords();
}
auto ChooseTopicBoxController::createRow(not_null<Data::ForumTopic*> topic)
-> std::unique_ptr<Row> {
const auto skip = _filter ? !_filter(topic) : !topic->canWrite();

View File

@@ -1204,7 +1204,7 @@ object_ptr<Ui::BoxContent> ShareInviteLinkBox(
auto object = Box<ShareBox>(ShareBox::Descriptor{
.session = &peer->session(),
.copyCallback = std::move(copyCallback),
.submitCallback = std::move(submitCallback), // #TODO forum forward
.submitCallback = std::move(submitCallback), // #TODO forum share
.filterCallback = [](auto peer) { return peer->canWrite(); },
});
*box = Ui::MakeWeak(object.data());

View File

@@ -1292,7 +1292,7 @@ void FastShareMessage(
}
const auto error = [&] {
for (const auto peer : result) { // #TODO forum forward
for (const auto peer : result) { // #TODO forum share
const auto error = GetErrorTextForSending(
peer,
{ .forward = &items, .text = &comment });
@@ -1398,7 +1398,7 @@ void FastShareMessage(
}
};
auto filterCallback = [isGame](PeerData *peer) {
if (peer->canWrite()) { // #TODO forum forward
if (peer->canWrite()) { // #TODO forum share
if (auto channel = peer->asChannel()) {
return isGame ? (!channel->isBroadcast()) : true;
}