mirror of
https://github.com/kotatogram/kotatogram-desktop
synced 2025-08-31 14:45:14 +00:00
Add a comment field to ShareBox.
This commit is contained in:
@@ -8,8 +8,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||
#include "boxes/share_box.h"
|
||||
|
||||
#include "dialogs/dialogs_indexed_list.h"
|
||||
#include "styles/style_boxes.h"
|
||||
#include "styles/style_history.h"
|
||||
#include "observer_peer.h"
|
||||
#include "lang/lang_keys.h"
|
||||
#include "mainwindow.h"
|
||||
@@ -22,7 +20,10 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||
#include "ui/widgets/multi_select.h"
|
||||
#include "ui/widgets/buttons.h"
|
||||
#include "ui/widgets/scroll_area.h"
|
||||
#include "ui/widgets/input_fields.h"
|
||||
#include "ui/wrap/slide_wrap.h"
|
||||
#include "ui/text_options.h"
|
||||
#include "chat_helpers/message_field.h"
|
||||
#include "history/history.h"
|
||||
#include "history/history_media_types.h"
|
||||
#include "history/history_message.h"
|
||||
@@ -30,69 +31,248 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||
#include "boxes/peer_list_box.h"
|
||||
#include "auth_session.h"
|
||||
#include "messenger.h"
|
||||
#include "styles/style_boxes.h"
|
||||
#include "styles/style_history.h"
|
||||
|
||||
ShareBox::ShareBox(QWidget*, CopyCallback &©Callback, SubmitCallback &&submitCallback, FilterCallback &&filterCallback)
|
||||
|
||||
class ShareBox::Inner
|
||||
: public Ui::RpWidget
|
||||
, public RPCSender
|
||||
, private base::Subscriber {
|
||||
public:
|
||||
Inner(QWidget *parent, ShareBox::FilterCallback &&filterCallback);
|
||||
|
||||
void setPeerSelectedChangedCallback(
|
||||
Fn<void(PeerData *peer, bool selected)> callback);
|
||||
void peerUnselected(not_null<PeerData*> peer);
|
||||
|
||||
QVector<PeerData*> selected() const;
|
||||
bool hasSelected() const;
|
||||
|
||||
void peopleReceived(
|
||||
const QString &query,
|
||||
const QVector<MTPPeer> &my,
|
||||
const QVector<MTPPeer> &people);
|
||||
|
||||
void activateSkipRow(int direction);
|
||||
void activateSkipColumn(int direction);
|
||||
void activateSkipPage(int pageHeight, int direction);
|
||||
void updateFilter(QString filter = QString());
|
||||
void selectActive();
|
||||
|
||||
rpl::producer<Ui::ScrollToRequest> scrollToRequests() const;
|
||||
rpl::producer<> searchRequests() const;
|
||||
|
||||
protected:
|
||||
void visibleTopBottomUpdated(
|
||||
int visibleTop,
|
||||
int visibleBottom) override;
|
||||
|
||||
void paintEvent(QPaintEvent *e) override;
|
||||
void enterEventHook(QEvent *e) override;
|
||||
void leaveEventHook(QEvent *e) override;
|
||||
void mouseMoveEvent(QMouseEvent *e) override;
|
||||
void mousePressEvent(QMouseEvent *e) override;
|
||||
void resizeEvent(QResizeEvent *e) override;
|
||||
|
||||
private:
|
||||
struct Chat {
|
||||
Chat(PeerData *peer, Fn<void()> updateCallback);
|
||||
|
||||
PeerData *peer;
|
||||
Ui::RoundImageCheckbox checkbox;
|
||||
Text name;
|
||||
Animation nameActive;
|
||||
};
|
||||
|
||||
void notifyPeerUpdated(const Notify::PeerUpdate &update);
|
||||
void invalidateCache();
|
||||
|
||||
int displayedChatsCount() const;
|
||||
|
||||
void paintChat(Painter &p, TimeMs ms, not_null<Chat*> chat, int index);
|
||||
void updateChat(not_null<PeerData*> peer);
|
||||
void updateChatName(not_null<Chat*> chat, not_null<PeerData*> peer);
|
||||
void repaintChat(not_null<PeerData*> peer);
|
||||
int chatIndex(not_null<PeerData*> peer) const;
|
||||
void repaintChatAtIndex(int index);
|
||||
Chat *getChatAtIndex(int index);
|
||||
|
||||
void loadProfilePhotos(int yFrom);
|
||||
void changeCheckState(Chat *chat);
|
||||
enum class ChangeStateWay {
|
||||
Default,
|
||||
SkipCallback,
|
||||
};
|
||||
void changePeerCheckState(
|
||||
not_null<Chat*> chat,
|
||||
bool checked,
|
||||
ChangeStateWay useCallback = ChangeStateWay::Default);
|
||||
|
||||
not_null<Chat*> getChat(not_null<Dialogs::Row*> row);
|
||||
void setActive(int active);
|
||||
void updateUpon(const QPoint &pos);
|
||||
|
||||
void refresh();
|
||||
|
||||
float64 _columnSkip = 0.;
|
||||
float64 _rowWidthReal = 0.;
|
||||
int _rowsLeft = 0;
|
||||
int _rowsTop = 0;
|
||||
int _rowWidth = 0;
|
||||
int _rowHeight = 0;
|
||||
int _columnCount = 4;
|
||||
int _active = -1;
|
||||
int _upon = -1;
|
||||
|
||||
ShareBox::FilterCallback _filterCallback;
|
||||
std::unique_ptr<Dialogs::IndexedList> _chatsIndexed;
|
||||
QString _filter;
|
||||
std::vector<Dialogs::Row*> _filtered;
|
||||
|
||||
std::map<not_null<PeerData*>, std::unique_ptr<Chat>> _dataMap;
|
||||
base::flat_set<not_null<PeerData*>> _selected;
|
||||
|
||||
Fn<void(PeerData *peer, bool selected)> _peerSelectedChangedCallback;
|
||||
|
||||
bool _searching = false;
|
||||
QString _lastQuery;
|
||||
std::vector<PeerData*> _byUsernameFiltered;
|
||||
std::vector<std::unique_ptr<Chat>> d_byUsernameFiltered;
|
||||
|
||||
rpl::event_stream<Ui::ScrollToRequest> _scrollToRequests;
|
||||
rpl::event_stream<> _searchRequests;
|
||||
|
||||
};
|
||||
|
||||
ShareBox::ShareBox(
|
||||
QWidget*,
|
||||
CopyCallback &©Callback,
|
||||
SubmitCallback &&submitCallback,
|
||||
FilterCallback &&filterCallback)
|
||||
: _copyCallback(std::move(copyCallback))
|
||||
, _submitCallback(std::move(submitCallback))
|
||||
, _filterCallback(std::move(filterCallback))
|
||||
, _select(this, st::contactsMultiSelect, langFactory(lng_participant_filter))
|
||||
, _searchTimer(this) {
|
||||
, _select(
|
||||
this,
|
||||
st::contactsMultiSelect,
|
||||
langFactory(lng_participant_filter))
|
||||
, _comment(
|
||||
this,
|
||||
object_ptr<Ui::InputField>(
|
||||
this,
|
||||
st::shareComment,
|
||||
Ui::InputField::Mode::MultiLine,
|
||||
langFactory(lng_photos_comment)),
|
||||
st::shareCommentPadding)
|
||||
, _searchTimer([=] { searchByUsername(); }) {
|
||||
}
|
||||
|
||||
void ShareBox::prepareCommentField() {
|
||||
using namespace rpl::mappers;
|
||||
|
||||
_comment->hide(anim::type::instant);
|
||||
|
||||
rpl::combine(
|
||||
heightValue(),
|
||||
_comment->heightValue(),
|
||||
_1 - _2
|
||||
) | rpl::start_with_next([=](int top) {
|
||||
_comment->moveToLeft(0, top);
|
||||
}, _comment->lifetime());
|
||||
|
||||
const auto field = _comment->entity();
|
||||
|
||||
connect(field, &Ui::InputField::submitted, [=] {
|
||||
submit();
|
||||
});
|
||||
|
||||
field->setInstantReplaces(Ui::InstantReplaces::Default());
|
||||
field->setInstantReplacesEnabled(Global::ReplaceEmojiValue());
|
||||
field->setMarkdownReplacesEnabled(rpl::single(true));
|
||||
field->setEditLinkCallback(DefaultEditLinkCallback(field));
|
||||
|
||||
Ui::SendPendingMoveResizeEvents(_comment);
|
||||
}
|
||||
|
||||
void ShareBox::prepare() {
|
||||
prepareCommentField();
|
||||
|
||||
_select->resizeToWidth(st::boxWideWidth);
|
||||
Ui::SendPendingMoveResizeEvents(_select);
|
||||
|
||||
setTitle(langFactory(lng_share_title));
|
||||
|
||||
_inner = setInnerWidget(object_ptr<Inner>(this, std::move(_filterCallback)), getTopScrollSkip());
|
||||
connect(_inner, SIGNAL(mustScrollTo(int,int)), this, SLOT(onMustScrollTo(int,int)));
|
||||
_inner = setInnerWidget(
|
||||
object_ptr<Inner>(
|
||||
this,
|
||||
std::move(_filterCallback)),
|
||||
getTopScrollSkip(),
|
||||
getBottomScrollSkip());
|
||||
|
||||
createButtons();
|
||||
|
||||
setDimensions(st::boxWideWidth, st::boxMaxListHeight);
|
||||
|
||||
_select->setQueryChangedCallback([this](const QString &query) { onFilterUpdate(query); });
|
||||
_select->setItemRemovedCallback([this](uint64 itemId) {
|
||||
if (auto peer = App::peerLoaded(itemId)) {
|
||||
_select->setQueryChangedCallback([=](const QString &query) {
|
||||
onFilterUpdate(query);
|
||||
});
|
||||
_select->setItemRemovedCallback([=](uint64 itemId) {
|
||||
if (const auto peer = App::peerLoaded(itemId)) {
|
||||
_inner->peerUnselected(peer);
|
||||
onSelectedChanged();
|
||||
selectedChanged();
|
||||
update();
|
||||
}
|
||||
});
|
||||
_select->setResizedCallback([this] { updateScrollSkips(); });
|
||||
_select->setSubmittedCallback([this](Qt::KeyboardModifiers modifiers) {
|
||||
_select->setResizedCallback([=] { updateScrollSkips(); });
|
||||
_select->setSubmittedCallback([=](Qt::KeyboardModifiers modifiers) {
|
||||
if (modifiers.testFlag(Qt::ControlModifier)
|
||||
|| modifiers.testFlag(Qt::MetaModifier)) {
|
||||
onSubmit();
|
||||
submit();
|
||||
} else {
|
||||
_inner->onSelectActive();
|
||||
_inner->selectActive();
|
||||
}
|
||||
});
|
||||
connect(_inner, SIGNAL(searchByUsername()), this, SLOT(onNeedSearchByUsername()));
|
||||
_inner->setPeerSelectedChangedCallback([this](PeerData *peer, bool checked) {
|
||||
onPeerSelectedChanged(peer, checked);
|
||||
});
|
||||
_comment->heightValue(
|
||||
) | rpl::start_with_next([=] {
|
||||
updateScrollSkips();
|
||||
}, _comment->lifetime());
|
||||
|
||||
_searchTimer->setSingleShot(true);
|
||||
connect(_searchTimer, SIGNAL(timeout()), this, SLOT(onSearchByUsername()));
|
||||
_inner->searchRequests(
|
||||
) | rpl::start_with_next([=] {
|
||||
needSearchByUsername();
|
||||
}, _inner->lifetime());
|
||||
|
||||
_inner->scrollToRequests(
|
||||
) | rpl::start_with_next([=](const Ui::ScrollToRequest &request) {
|
||||
scrollTo(request);
|
||||
}, _inner->lifetime());
|
||||
|
||||
_inner->setPeerSelectedChangedCallback([=](PeerData *peer, bool checked) {
|
||||
innerSelectedChanged(peer, checked);
|
||||
});
|
||||
|
||||
_select->raise();
|
||||
}
|
||||
|
||||
int ShareBox::getTopScrollSkip() const {
|
||||
auto result = 0;
|
||||
if (!_select->isHidden()) {
|
||||
result += _select->height();
|
||||
}
|
||||
return result;
|
||||
return _select->isHidden() ? 0 : _select->height();
|
||||
}
|
||||
|
||||
int ShareBox::getBottomScrollSkip() const {
|
||||
return _comment->isHidden() ? 0 : _comment->height();
|
||||
}
|
||||
|
||||
int ShareBox::contentHeight() const {
|
||||
return height() - getTopScrollSkip() - getBottomScrollSkip();
|
||||
}
|
||||
|
||||
void ShareBox::updateScrollSkips() {
|
||||
setInnerTopSkip(getTopScrollSkip(), true);
|
||||
setInnerBottomSkip(getBottomScrollSkip());
|
||||
}
|
||||
|
||||
bool ShareBox::onSearchByUsername(bool searchCache) {
|
||||
bool ShareBox::searchByUsername(bool searchCache) {
|
||||
auto query = _select->getQuery();
|
||||
if (query.isEmpty()) {
|
||||
if (_peopleRequest) {
|
||||
@@ -124,9 +304,9 @@ bool ShareBox::onSearchByUsername(bool searchCache) {
|
||||
return false;
|
||||
}
|
||||
|
||||
void ShareBox::onNeedSearchByUsername() {
|
||||
if (!onSearchByUsername(true)) {
|
||||
_searchTimer->start(AutoSearchTimeout);
|
||||
void ShareBox::needSearchByUsername() {
|
||||
if (!searchByUsername(true)) {
|
||||
_searchTimer.callOnce(AutoSearchTimeout);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -172,7 +352,11 @@ bool ShareBox::peopleFailed(const RPCError &error, mtpRequestId requestId) {
|
||||
}
|
||||
|
||||
void ShareBox::setInnerFocus() {
|
||||
_select->setInnerFocus();
|
||||
if (_comment->isHidden()) {
|
||||
_select->setInnerFocus();
|
||||
} else {
|
||||
_comment->entity()->setFocusFast();
|
||||
}
|
||||
}
|
||||
|
||||
void ShareBox::resizeEvent(QResizeEvent *e) {
|
||||
@@ -194,9 +378,9 @@ void ShareBox::keyPressEvent(QKeyEvent *e) {
|
||||
} else if (e->key() == Qt::Key_Down) {
|
||||
_inner->activateSkipColumn(1);
|
||||
} else if (e->key() == Qt::Key_PageUp) {
|
||||
_inner->activateSkipPage(height() - getTopScrollSkip(), -1);
|
||||
_inner->activateSkipPage(contentHeight(), -1);
|
||||
} else if (e->key() == Qt::Key_PageDown) {
|
||||
_inner->activateSkipPage(height() - getTopScrollSkip(), 1);
|
||||
_inner->activateSkipPage(contentHeight(), 1);
|
||||
} else {
|
||||
BoxContent::keyPressEvent(e);
|
||||
}
|
||||
@@ -205,22 +389,14 @@ void ShareBox::keyPressEvent(QKeyEvent *e) {
|
||||
}
|
||||
}
|
||||
|
||||
void ShareBox::updateButtons() {
|
||||
auto hasSelected = _inner->hasSelected();
|
||||
if (_hasSelected != hasSelected) {
|
||||
_hasSelected = hasSelected;
|
||||
createButtons();
|
||||
}
|
||||
}
|
||||
|
||||
void ShareBox::createButtons() {
|
||||
clearButtons();
|
||||
if (_hasSelected) {
|
||||
addButton(langFactory(lng_share_confirm), [this] { onSubmit(); });
|
||||
addButton(langFactory(lng_share_confirm), [=] { submit(); });
|
||||
} else if (_copyCallback) {
|
||||
addButton(langFactory(lng_share_copy_link), [this] { onCopyLink(); });
|
||||
addButton(langFactory(lng_share_copy_link), [=] { copyLink(); });
|
||||
}
|
||||
addButton(langFactory(lng_cancel), [this] { closeBox(); });
|
||||
addButton(langFactory(lng_cancel), [=] { closeBox(); });
|
||||
}
|
||||
|
||||
void ShareBox::onFilterUpdate(const QString &query) {
|
||||
@@ -239,36 +415,44 @@ void ShareBox::addPeerToMultiSelect(PeerData *peer, bool skipAnimation) {
|
||||
addItemWay);
|
||||
}
|
||||
|
||||
void ShareBox::onPeerSelectedChanged(PeerData *peer, bool checked) {
|
||||
void ShareBox::innerSelectedChanged(PeerData *peer, bool checked) {
|
||||
if (checked) {
|
||||
addPeerToMultiSelect(peer);
|
||||
_select->clearQuery();
|
||||
} else {
|
||||
_select->removeItem(peer->id);
|
||||
}
|
||||
onSelectedChanged();
|
||||
selectedChanged();
|
||||
update();
|
||||
}
|
||||
|
||||
void ShareBox::onSubmit() {
|
||||
void ShareBox::submit() {
|
||||
if (_submitCallback) {
|
||||
_submitCallback(_inner->selected());
|
||||
_submitCallback(
|
||||
_inner->selected(),
|
||||
_comment->entity()->getTextWithAppliedMarkdown());
|
||||
}
|
||||
}
|
||||
|
||||
void ShareBox::onCopyLink() {
|
||||
void ShareBox::copyLink() {
|
||||
if (_copyCallback) {
|
||||
_copyCallback();
|
||||
}
|
||||
}
|
||||
|
||||
void ShareBox::onSelectedChanged() {
|
||||
updateButtons();
|
||||
void ShareBox::selectedChanged() {
|
||||
auto hasSelected = _inner->hasSelected();
|
||||
if (_hasSelected != hasSelected) {
|
||||
_hasSelected = hasSelected;
|
||||
createButtons();
|
||||
_comment->toggle(_hasSelected, anim::type::normal);
|
||||
_comment->resizeToWidth(st::boxWideWidth);
|
||||
}
|
||||
update();
|
||||
}
|
||||
|
||||
void ShareBox::onMustScrollTo(int top, int bottom) {
|
||||
onScrollToY(top, bottom);
|
||||
void ShareBox::scrollTo(Ui::ScrollToRequest request) {
|
||||
onScrollToY(request.ymin, request.ymax);
|
||||
//auto scrollTop = scrollArea()->scrollTop(), scrollBottom = scrollTop + scrollArea()->height();
|
||||
//auto from = scrollTop, to = scrollTop;
|
||||
//if (scrollTop > top) {
|
||||
@@ -286,9 +470,14 @@ void ShareBox::scrollAnimationCallback() {
|
||||
//scrollArea()->scrollToY(scrollTop);
|
||||
}
|
||||
|
||||
ShareBox::Inner::Inner(QWidget *parent, ShareBox::FilterCallback &&filterCallback) : TWidget(parent)
|
||||
ShareBox::Inner::Inner(
|
||||
QWidget *parent,
|
||||
ShareBox::FilterCallback &&filterCallback)
|
||||
: RpWidget(parent)
|
||||
, _filterCallback(std::move(filterCallback))
|
||||
, _chatsIndexed(std::make_unique<Dialogs::IndexedList>(Dialogs::SortMode::Add)) {
|
||||
, _chatsIndexed(
|
||||
std::make_unique<Dialogs::IndexedList>(
|
||||
Dialogs::SortMode::Add)) {
|
||||
_rowsTop = st::shareRowsTop;
|
||||
_rowHeight = st::shareRowHeight;
|
||||
setAttribute(Qt::WA_OpaquePaintEvent);
|
||||
@@ -325,7 +514,7 @@ ShareBox::Inner::Inner(QWidget *parent, ShareBox::FilterCallback &&filterCallbac
|
||||
}
|
||||
|
||||
void ShareBox::Inner::invalidateCache() {
|
||||
for_const (auto data, _dataMap) {
|
||||
for (const auto &[peer, data] : _dataMap) {
|
||||
data->checkbox.invalidateCache();
|
||||
}
|
||||
}
|
||||
@@ -377,9 +566,8 @@ void ShareBox::Inner::notifyPeerUpdated(const Notify::PeerUpdate &update) {
|
||||
}
|
||||
|
||||
void ShareBox::Inner::updateChat(not_null<PeerData*> peer) {
|
||||
auto i = _dataMap.find(peer);
|
||||
if (i != _dataMap.cend()) {
|
||||
updateChatName(i.value(), peer);
|
||||
if (const auto i = _dataMap.find(peer); i != end(_dataMap)) {
|
||||
updateChatName(i->second.get(), peer);
|
||||
repaintChat(peer);
|
||||
}
|
||||
}
|
||||
@@ -400,11 +588,17 @@ void ShareBox::Inner::repaintChatAtIndex(int index) {
|
||||
}
|
||||
|
||||
ShareBox::Inner::Chat *ShareBox::Inner::getChatAtIndex(int index) {
|
||||
if (index < 0) return nullptr;
|
||||
auto row = ([this, index]() -> Dialogs::Row* {
|
||||
if (_filter.isEmpty()) return _chatsIndexed->rowAtY(index, 1);
|
||||
return (index < _filtered.size()) ? _filtered[index] : nullptr;
|
||||
})();
|
||||
if (index < 0) {
|
||||
return nullptr;
|
||||
}
|
||||
const auto row = [=] {
|
||||
if (_filter.isEmpty()) {
|
||||
return _chatsIndexed->rowAtY(index, 1);
|
||||
}
|
||||
return (index < _filtered.size())
|
||||
? _filtered[index]
|
||||
: nullptr;
|
||||
}();
|
||||
if (row) {
|
||||
return static_cast<Chat*>(row->attached);
|
||||
}
|
||||
@@ -412,7 +606,7 @@ ShareBox::Inner::Chat *ShareBox::Inner::getChatAtIndex(int index) {
|
||||
if (!_filter.isEmpty()) {
|
||||
index -= _filtered.size();
|
||||
if (index >= 0 && index < d_byUsernameFiltered.size()) {
|
||||
return d_byUsernameFiltered[index];
|
||||
return d_byUsernameFiltered[index].get();
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
@@ -442,7 +636,7 @@ int ShareBox::Inner::chatIndex(not_null<PeerData*> peer) const {
|
||||
}
|
||||
++index;
|
||||
}
|
||||
for (const auto row : d_byUsernameFiltered) {
|
||||
for (const auto &row : d_byUsernameFiltered) {
|
||||
if (row->peer == peer) {
|
||||
return index;
|
||||
}
|
||||
@@ -478,7 +672,7 @@ void ShareBox::Inner::loadProfilePhotos(int yFrom) {
|
||||
(*i)->entry()->loadUserpic();
|
||||
}
|
||||
}
|
||||
} else if (!_filtered.isEmpty()) {
|
||||
} else if (!_filtered.empty()) {
|
||||
int from = yFrom / _rowHeight;
|
||||
if (from < 0) from = 0;
|
||||
if (from < _filtered.size()) {
|
||||
@@ -492,23 +686,24 @@ void ShareBox::Inner::loadProfilePhotos(int yFrom) {
|
||||
}
|
||||
}
|
||||
|
||||
ShareBox::Inner::Chat *ShareBox::Inner::getChat(Dialogs::Row *row) {
|
||||
auto ShareBox::Inner::getChat(not_null<Dialogs::Row*> row)
|
||||
-> not_null<Chat*> {
|
||||
Expects(row->history() != nullptr);
|
||||
|
||||
auto data = static_cast<Chat*>(row->attached);
|
||||
if (!data) {
|
||||
auto peer = row->history()->peer;
|
||||
auto i = _dataMap.constFind(peer);
|
||||
if (i == _dataMap.cend()) {
|
||||
data = new Chat(peer, [this, peer] { repaintChat(peer); });
|
||||
_dataMap.insert(peer, data);
|
||||
updateChatName(data, peer);
|
||||
} else {
|
||||
data = i.value();
|
||||
}
|
||||
row->attached = data;
|
||||
if (const auto data = static_cast<Chat*>(row->attached)) {
|
||||
return data;
|
||||
}
|
||||
return data;
|
||||
const auto peer = row->history()->peer;
|
||||
if (const auto i = _dataMap.find(peer); i != end(_dataMap)) {
|
||||
row->attached = i->second.get();
|
||||
return i->second.get();
|
||||
}
|
||||
const auto [i, ok] = _dataMap.emplace(
|
||||
peer,
|
||||
std::make_unique<Chat>(peer, [=] { repaintChat(peer); }));
|
||||
updateChatName(i->second.get(), peer);
|
||||
row->attached = i->second.get();
|
||||
return i->second.get();
|
||||
}
|
||||
|
||||
void ShareBox::Inner::setActive(int active) {
|
||||
@@ -525,7 +720,7 @@ void ShareBox::Inner::setActive(int active) {
|
||||
changeNameFg(_active, 0., 1.);
|
||||
}
|
||||
auto y = (_active < _columnCount) ? 0 : (_rowsTop + ((_active / _columnCount) * _rowHeight));
|
||||
emit mustScrollTo(y, y + _rowHeight);
|
||||
_scrollToRequests.fire({ y, y + _rowHeight });
|
||||
}
|
||||
|
||||
void ShareBox::Inner::paintChat(
|
||||
@@ -587,7 +782,7 @@ void ShareBox::Inner::paintEvent(QPaintEvent *e) {
|
||||
style::al_center);
|
||||
}
|
||||
} else {
|
||||
if (_filtered.isEmpty()
|
||||
if (_filtered.empty()
|
||||
&& _byUsernameFiltered.empty()
|
||||
&& !_searching) {
|
||||
p.setFont(st::noContactsFont);
|
||||
@@ -616,7 +811,11 @@ void ShareBox::Inner::paintEvent(QPaintEvent *e) {
|
||||
if (indexFrom >= d_byUsernameFiltered.size()) {
|
||||
break;
|
||||
}
|
||||
paintChat(p, ms, d_byUsernameFiltered[indexFrom], filteredSize + indexFrom);
|
||||
paintChat(
|
||||
p,
|
||||
ms,
|
||||
d_byUsernameFiltered[indexFrom].get(),
|
||||
filteredSize + indexFrom);
|
||||
++indexFrom;
|
||||
}
|
||||
}
|
||||
@@ -659,7 +858,7 @@ void ShareBox::Inner::mousePressEvent(QMouseEvent *e) {
|
||||
}
|
||||
}
|
||||
|
||||
void ShareBox::Inner::onSelectActive() {
|
||||
void ShareBox::Inner::selectActive() {
|
||||
changeCheckState(getChatAtIndex(_active > 0 ? _active : 0));
|
||||
}
|
||||
|
||||
@@ -693,12 +892,16 @@ void ShareBox::Inner::changeCheckState(Chat *chat) {
|
||||
}
|
||||
|
||||
void ShareBox::Inner::peerUnselected(not_null<PeerData*> peer) {
|
||||
if (auto chat = _dataMap.value(peer, nullptr)) {
|
||||
changePeerCheckState(chat, false, ChangeStateWay::SkipCallback);
|
||||
if (const auto i = _dataMap.find(peer); i != end(_dataMap)) {
|
||||
changePeerCheckState(
|
||||
i->second.get(),
|
||||
false,
|
||||
ChangeStateWay::SkipCallback);
|
||||
}
|
||||
}
|
||||
|
||||
void ShareBox::Inner::setPeerSelectedChangedCallback(Fn<void(PeerData *peer, bool selected)> callback) {
|
||||
void ShareBox::Inner::setPeerSelectedChangedCallback(
|
||||
Fn<void(PeerData *peer, bool selected)> callback) {
|
||||
_peerSelectedChangedCallback = std::move(callback);
|
||||
}
|
||||
|
||||
@@ -732,9 +935,6 @@ void ShareBox::Inner::updateFilter(QString filter) {
|
||||
_filter = filter;
|
||||
|
||||
_byUsernameFiltered.clear();
|
||||
for (int i = 0, l = d_byUsernameFiltered.size(); i < l; ++i) {
|
||||
delete d_byUsernameFiltered[i];
|
||||
}
|
||||
d_byUsernameFiltered.clear();
|
||||
|
||||
if (_filter.isEmpty()) {
|
||||
@@ -782,7 +982,7 @@ void ShareBox::Inner::updateFilter(QString filter) {
|
||||
refresh();
|
||||
|
||||
_searching = true;
|
||||
emit searchByUsername();
|
||||
_searchRequests.fire({});
|
||||
}
|
||||
setActive(-1);
|
||||
update();
|
||||
@@ -790,6 +990,14 @@ void ShareBox::Inner::updateFilter(QString filter) {
|
||||
}
|
||||
}
|
||||
|
||||
rpl::producer<Ui::ScrollToRequest> ShareBox::Inner::scrollToRequests() const {
|
||||
return _scrollToRequests.events();
|
||||
}
|
||||
|
||||
rpl::producer<> ShareBox::Inner::searchRequests() const {
|
||||
return _searchRequests.events();
|
||||
}
|
||||
|
||||
void ShareBox::Inner::peopleReceived(
|
||||
const QString &query,
|
||||
const QVector<MTPPeer> &my,
|
||||
@@ -802,8 +1010,8 @@ void ShareBox::Inner::peopleReceived(
|
||||
_byUsernameFiltered.reserve(already + my.size() + people.size());
|
||||
d_byUsernameFiltered.reserve(already + my.size() + people.size());
|
||||
const auto feedList = [&](const QVector<MTPPeer> &list) {
|
||||
for (const auto &mtpPeer : list) {
|
||||
if (const auto peer = App::peerLoaded(peerFromMTP(mtpPeer))) {
|
||||
for (const auto &data : list) {
|
||||
if (const auto peer = App::peerLoaded(peerFromMTP(data))) {
|
||||
const auto history = App::historyLoaded(peer);
|
||||
if (!_filterCallback(peer)) {
|
||||
continue;
|
||||
@@ -812,10 +1020,11 @@ void ShareBox::Inner::peopleReceived(
|
||||
} else if (base::contains(_byUsernameFiltered, peer)) {
|
||||
continue;
|
||||
}
|
||||
auto chat = new Chat(peer, [=] { repaintChat(peer); });
|
||||
updateChatName(chat, peer);
|
||||
_byUsernameFiltered.push_back(peer);
|
||||
d_byUsernameFiltered.push_back(chat);
|
||||
d_byUsernameFiltered.push_back(std::make_unique<Chat>(
|
||||
peer,
|
||||
[=] { repaintChat(peer); }));
|
||||
updateChatName(d_byUsernameFiltered.back().get(), peer);
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -837,18 +1046,12 @@ void ShareBox::Inner::refresh() {
|
||||
update();
|
||||
}
|
||||
|
||||
ShareBox::Inner::~Inner() {
|
||||
for_const (auto chat, _dataMap) {
|
||||
delete chat;
|
||||
}
|
||||
}
|
||||
|
||||
QVector<PeerData*> ShareBox::Inner::selected() const {
|
||||
QVector<PeerData*> result;
|
||||
auto result = QVector<PeerData*>();
|
||||
result.reserve(_dataMap.size());
|
||||
for_const (auto chat, _dataMap) {
|
||||
for (const auto &[peer, chat] : _dataMap) {
|
||||
if (chat->checkbox.checked()) {
|
||||
result.push_back(chat->peer);
|
||||
result.push_back(peer);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
|
Reference in New Issue
Block a user