Support saved messages in filters edit.

This commit is contained in:
John Preston 2020-03-20 18:56:18 +04:00
parent 48f67d27f1
commit 0063edb14f
3 changed files with 92 additions and 24 deletions

View File

@ -234,6 +234,21 @@ void FilterChatsPreview::paintEvent(QPaintEvent *e) {
top += st.height;
}
for (const auto &[history, button] : _removePeer) {
const auto savedMessages = history->peer->isSelf();
if (savedMessages) {
Ui::EmptyUserpic::PaintSavedMessages(
p,
iconLeft,
top + iconTop,
width(),
st.photoSize);
p.setPen(st::contactsNameFg);
p.drawTextLeft(
nameLeft,
top + nameTop,
width(),
tr::lng_saved_messages(tr::now));
} else {
history->peer->paintUserpicLeft(
p,
iconLeft,
@ -247,6 +262,7 @@ void FilterChatsPreview::paintEvent(QPaintEvent *e) {
top + nameTop,
button->x() - nameLeft,
width());
}
top += st.height;
}
}

View File

@ -52,6 +52,16 @@ private:
};
class ExceptionRow final : public ChatsListBoxController::Row {
public:
explicit ExceptionRow(not_null<History*> history);
QString generateName() override;
QString generateShortName() override;
PaintRoundImageCallback generatePaintUserpicCallback() override;
};
class TypeDelegate final : public PeerListContentDelegate {
public:
void peerListSetTitle(rpl::producer<QString> title) override;
@ -151,6 +161,34 @@ Flag TypeRow::flag() const {
return static_cast<Flag>(id() & 0xFF);
}
ExceptionRow::ExceptionRow(not_null<History*> history) : Row(history) {
if (peer()->isSelf()) {
setCustomStatus(tr::lng_saved_forward_here(tr::now));
}
}
QString ExceptionRow::generateName() {
return peer()->isSelf()
? tr::lng_saved_messages(tr::now)
: Row::generateName();
}
QString ExceptionRow::generateShortName() {
return generateName();
}
PaintRoundImageCallback ExceptionRow::generatePaintUserpicCallback() {
const auto peer = this->peer();
const auto saved = peer->isSelf();
return [=](Painter &p, int x, int y, int outerWidth, int size) {
if (saved) {
Ui::EmptyUserpic::PaintSavedMessages(p, x, y, outerWidth, size);
} else {
peer->paintUserpicLeft(p, x, y, outerWidth, size);
}
};
}
void TypeDelegate::peerListSetTitle(rpl::producer<QString> title) {
}
@ -349,8 +387,19 @@ bool EditFilterChatsListController::handleDeselectForeignRow(
void EditFilterChatsListController::prepareViewHook() {
delegate()->peerListSetTitle(std::move(_title));
delegate()->peerListSetAboveWidget(prepareTypesList());
delegate()->peerListAddSelectedPeers(
_peers | ranges::view::transform(&History::peer));
const auto count = int(_peers.size());
const auto rows = std::make_unique<std::optional<ExceptionRow>[]>(count);
auto i = 0;
for (const auto history : _peers) {
rows[i++].emplace(history);
}
auto pointers = std::vector<ExceptionRow*>();
pointers.reserve(count);
for (auto i = 0; i != count; ++i) {
pointers.push_back(&*rows[i]);
}
delegate()->peerListAddSelectedRows(pointers);
updateTitle();
}
@ -416,7 +465,9 @@ object_ptr<Ui::RpWidget> EditFilterChatsListController::prepareTypesList() {
auto EditFilterChatsListController::createRow(not_null<History*> history)
-> std::unique_ptr<Row> {
return history->inChatList() ? std::make_unique<Row>(history) : nullptr;
return history->inChatList()
? std::make_unique<ExceptionRow>(history)
: nullptr;
}
void EditFilterChatsListController::updateTitle() {

View File

@ -87,14 +87,6 @@ private:
class ChatsListBoxController : public PeerListController {
public:
ChatsListBoxController(not_null<Window::SessionNavigation*> navigation);
ChatsListBoxController(
std::unique_ptr<PeerListSearchController> searchController);
void prepare() override final;
std::unique_ptr<PeerListRow> createSearchRow(not_null<PeerData*> peer) override final;
protected:
class Row : public PeerListRow {
public:
Row(not_null<History*> history);
@ -107,6 +99,15 @@ protected:
not_null<History*> _history;
};
ChatsListBoxController(not_null<Window::SessionNavigation*> navigation);
ChatsListBoxController(
std::unique_ptr<PeerListSearchController> searchController);
void prepare() override final;
std::unique_ptr<PeerListRow> createSearchRow(not_null<PeerData*> peer) override final;
protected:
virtual std::unique_ptr<Row> createRow(not_null<History*> history) = 0;
virtual void prepareViewHook() = 0;
virtual void updateRowHook(not_null<Row*> row) {