2014-05-30 08:53:19 +00:00
|
|
|
/*
|
|
|
|
This file is part of Telegram Desktop,
|
2014-12-01 10:47:38 +00:00
|
|
|
the official desktop version of Telegram messaging app, see https://telegram.org
|
2014-05-30 08:53:19 +00:00
|
|
|
|
|
|
|
Telegram Desktop is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
It is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
2015-10-03 13:16:42 +00:00
|
|
|
In addition, as a special exception, the copyright holders give permission
|
|
|
|
to link the code of portions of this program with the OpenSSL library.
|
|
|
|
|
2014-05-30 08:53:19 +00:00
|
|
|
Full license: https://github.com/telegramdesktop/tdesktop/blob/master/LICENSE
|
2017-01-11 18:31:31 +00:00
|
|
|
Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org
|
2014-05-30 08:53:19 +00:00
|
|
|
*/
|
|
|
|
#include "stdafx.h"
|
2016-04-09 18:45:55 +00:00
|
|
|
#include "dialogswidget.h"
|
|
|
|
|
|
|
|
#include "dialogs/dialogs_indexed_list.h"
|
|
|
|
#include "dialogs/dialogs_layout.h"
|
2016-06-07 19:59:39 +00:00
|
|
|
#include "styles/style_dialogs.h"
|
2016-10-27 21:19:38 +00:00
|
|
|
#include "styles/style_stickers.h"
|
2016-11-16 10:44:06 +00:00
|
|
|
#include "styles/style_history.h"
|
2016-11-11 13:46:04 +00:00
|
|
|
#include "ui/widgets/buttons.h"
|
2016-10-26 16:43:13 +00:00
|
|
|
#include "ui/widgets/popup_menu.h"
|
2016-06-09 11:51:24 +00:00
|
|
|
#include "data/data_drafts.h"
|
2014-05-30 08:53:19 +00:00
|
|
|
#include "lang.h"
|
2015-10-15 10:18:24 +00:00
|
|
|
#include "application.h"
|
2016-04-12 21:31:28 +00:00
|
|
|
#include "mainwindow.h"
|
2014-05-30 08:53:19 +00:00
|
|
|
#include "dialogswidget.h"
|
|
|
|
#include "mainwidget.h"
|
|
|
|
#include "boxes/addcontactbox.h"
|
2015-04-02 10:33:19 +00:00
|
|
|
#include "boxes/contactsbox.h"
|
2015-12-02 17:17:53 +00:00
|
|
|
#include "boxes/confirmbox.h"
|
2016-11-04 11:14:47 +00:00
|
|
|
#include "boxes/aboutbox.h"
|
2015-03-24 10:00:27 +00:00
|
|
|
#include "localstorage.h"
|
2016-04-12 21:31:28 +00:00
|
|
|
#include "apiwrap.h"
|
2016-11-04 11:14:47 +00:00
|
|
|
#include "ui/widgets/dropdown_menu.h"
|
2016-11-15 11:56:49 +00:00
|
|
|
#include "ui/widgets/input_fields.h"
|
2016-12-31 13:34:41 +00:00
|
|
|
#include "window/window_theme.h"
|
2016-11-05 08:36:24 +00:00
|
|
|
#include "autoupdater.h"
|
2015-03-24 10:00:27 +00:00
|
|
|
|
2016-12-05 11:01:08 +00:00
|
|
|
namespace {
|
|
|
|
|
|
|
|
constexpr auto kHashtagResultsLimit = 5;
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
struct DialogsInner::ImportantSwitch {
|
|
|
|
Dialogs::RippleRow row;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct DialogsInner::HashtagResult {
|
|
|
|
HashtagResult(const QString &tag) : tag(tag) {
|
|
|
|
}
|
|
|
|
QString tag;
|
|
|
|
Dialogs::RippleRow row;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct DialogsInner::PeerSearchResult {
|
|
|
|
PeerSearchResult(PeerData *peer) : peer(peer) {
|
|
|
|
}
|
|
|
|
PeerData *peer;
|
|
|
|
Dialogs::RippleRow row;
|
|
|
|
};
|
|
|
|
|
2016-11-04 11:14:47 +00:00
|
|
|
DialogsInner::DialogsInner(QWidget *parent, QWidget *main) : SplittedWidget(parent)
|
2016-12-05 11:01:08 +00:00
|
|
|
, _dialogs(std_::make_unique<Dialogs::IndexedList>(Dialogs::SortMode::Date))
|
|
|
|
, _contactsNoDialogs(std_::make_unique<Dialogs::IndexedList>(Dialogs::SortMode::Name))
|
|
|
|
, _contacts(std_::make_unique<Dialogs::IndexedList>(Dialogs::SortMode::Name))
|
2015-11-18 13:11:56 +00:00
|
|
|
, _addContactLnk(this, lang(lng_add_contact_button))
|
2016-11-15 11:56:49 +00:00
|
|
|
, _cancelSearchInPeer(this, st::dialogsCancelSearchInPeer) {
|
2016-04-11 10:59:01 +00:00
|
|
|
if (Global::DialogsModeEnabled()) {
|
2016-12-05 11:01:08 +00:00
|
|
|
_dialogsImportant = std_::make_unique<Dialogs::IndexedList>(Dialogs::SortMode::Date);
|
|
|
|
_importantSwitch = std_::make_unique<ImportantSwitch>();
|
2016-04-11 10:59:01 +00:00
|
|
|
}
|
2015-10-11 08:37:24 +00:00
|
|
|
connect(main, SIGNAL(peerNameChanged(PeerData*, const PeerData::Names&, const PeerData::NameFirstChars&)), this, SLOT(onPeerNameChanged(PeerData*, const PeerData::Names&, const PeerData::NameFirstChars&)));
|
2014-11-25 12:15:29 +00:00
|
|
|
connect(main, SIGNAL(peerPhotoChanged(PeerData*)), this, SLOT(onPeerPhotoChanged(PeerData*)));
|
2016-04-09 18:45:55 +00:00
|
|
|
connect(main, SIGNAL(dialogRowReplaced(Dialogs::Row*,Dialogs::Row*)), this, SLOT(onDialogRowReplaced(Dialogs::Row*,Dialogs::Row*)));
|
2016-11-11 13:46:04 +00:00
|
|
|
connect(_addContactLnk, SIGNAL(clicked()), App::wnd(), SLOT(onShowAddContact()));
|
2016-10-27 21:19:38 +00:00
|
|
|
connect(_cancelSearchInPeer, SIGNAL(clicked()), this, SIGNAL(cancelSearchInPeer()));
|
|
|
|
_cancelSearchInPeer->hide();
|
2016-09-26 13:57:08 +00:00
|
|
|
|
|
|
|
subscribe(FileDownload::ImageLoaded(), [this] { update(); });
|
2016-10-14 17:10:15 +00:00
|
|
|
subscribe(Global::RefItemRemoved(), [this](HistoryItem *item) {
|
|
|
|
itemRemoved(item);
|
|
|
|
});
|
2016-12-05 08:45:56 +00:00
|
|
|
subscribe(App::histories().sendActionAnimationUpdated(), [this](const Histories::SendActionAnimationUpdate &update) {
|
2016-12-05 11:01:08 +00:00
|
|
|
auto updateRect = Dialogs::Layout::RowPainter::sendActionAnimationRect(update.width, update.height, getFullWidth(), update.textUpdated);
|
|
|
|
updateDialogRow(update.history->peer, MsgId(0), updateRect, UpdateRowSection::Default | UpdateRowSection::Filtered);
|
2016-12-05 08:45:56 +00:00
|
|
|
});
|
2016-09-26 13:57:08 +00:00
|
|
|
|
2016-12-31 13:34:41 +00:00
|
|
|
subscribe(Window::Theme::Background(), [this](const Window::Theme::BackgroundUpdate &data) {
|
|
|
|
if (data.paletteChanged()) {
|
|
|
|
Dialogs::Layout::clearUnreadBadgesCache();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2015-12-06 15:50:02 +00:00
|
|
|
refresh();
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
|
2016-04-11 10:59:01 +00:00
|
|
|
int DialogsInner::dialogsOffset() const {
|
2016-12-05 11:01:08 +00:00
|
|
|
return _dialogsImportant ? st::dialogsImportantBarHeight : 0;
|
2016-04-11 10:59:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int DialogsInner::filteredOffset() const {
|
2015-11-18 13:11:56 +00:00
|
|
|
return _hashtagResults.size() * st::mentionHeight;
|
2015-03-24 10:00:27 +00:00
|
|
|
}
|
|
|
|
|
2016-12-05 11:01:08 +00:00
|
|
|
int DialogsInner::peerSearchOffset() const {
|
2016-06-07 19:59:39 +00:00
|
|
|
return filteredOffset() + (_filterResults.size() * st::dialogsRowHeight) + st::searchedBarHeight;
|
2015-03-24 10:00:27 +00:00
|
|
|
}
|
|
|
|
|
2016-04-11 10:59:01 +00:00
|
|
|
int DialogsInner::searchedOffset() const {
|
2016-12-05 11:01:08 +00:00
|
|
|
int result = peerSearchOffset() + (_peerSearchResults.isEmpty() ? 0 : ((_peerSearchResults.size() * st::dialogsRowHeight) + st::searchedBarHeight));
|
2016-06-07 19:59:39 +00:00
|
|
|
if (_searchInPeer) result += st::dialogsRowHeight;
|
2015-08-04 15:01:47 +00:00
|
|
|
return result;
|
2015-03-24 10:00:27 +00:00
|
|
|
}
|
|
|
|
|
2015-09-29 13:24:39 +00:00
|
|
|
void DialogsInner::paintRegion(Painter &p, const QRegion ®ion, bool paintingOther) {
|
2015-10-01 14:05:05 +00:00
|
|
|
QRegion original(rtl() ? region.translated(-otherWidth(), 0) : region);
|
|
|
|
if (App::wnd() && App::wnd()->contentOverlapped(this, original)) return;
|
|
|
|
|
2015-06-15 17:19:24 +00:00
|
|
|
if (!App::main()) return;
|
|
|
|
|
2016-12-05 11:01:08 +00:00
|
|
|
auto r = region.boundingRect();
|
2015-10-01 14:05:05 +00:00
|
|
|
if (!paintingOther) {
|
|
|
|
p.setClipRect(r);
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
2016-12-05 11:01:08 +00:00
|
|
|
auto fullWidth = getFullWidth();
|
|
|
|
auto ms = getms();
|
2014-07-04 11:12:54 +00:00
|
|
|
if (_state == DefaultState) {
|
2016-04-11 10:59:01 +00:00
|
|
|
QRect dialogsClip = r;
|
2016-12-05 11:01:08 +00:00
|
|
|
if (_dialogsImportant) {
|
|
|
|
auto selected = isPressed() ? _importantSwitchPressed : _importantSwitchSelected;
|
|
|
|
Dialogs::Layout::paintImportantSwitch(p, Global::DialogsMode(), fullWidth, selected, paintingOther);
|
2016-06-07 19:59:39 +00:00
|
|
|
dialogsClip.translate(0, -st::dialogsImportantBarHeight);
|
|
|
|
p.translate(0, st::dialogsImportantBarHeight);
|
2016-04-11 10:59:01 +00:00
|
|
|
}
|
2016-12-05 11:01:08 +00:00
|
|
|
auto otherStart = shownDialogs()->size() * st::dialogsRowHeight;
|
|
|
|
auto active = App::main()->activePeer();
|
|
|
|
auto selected = _menuPeer ? _menuPeer : (isPressed() ? (_pressed ? _pressed->history()->peer : nullptr) : (_selected ? _selected->history()->peer : nullptr));
|
2014-05-30 08:53:19 +00:00
|
|
|
if (otherStart) {
|
2016-12-05 11:01:08 +00:00
|
|
|
shownDialogs()->all().paint(p, fullWidth, dialogsClip.top(), dialogsClip.top() + dialogsClip.height(), active, selected, paintingOther, ms);
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
2016-04-09 18:45:55 +00:00
|
|
|
if (!otherStart) {
|
2016-10-31 12:29:26 +00:00
|
|
|
p.fillRect(dialogsClip, st::dialogsBg);
|
2015-09-29 13:24:39 +00:00
|
|
|
if (!paintingOther) {
|
2016-04-11 10:59:01 +00:00
|
|
|
p.setFont(st::noContactsFont);
|
|
|
|
p.setPen(st::noContactsColor);
|
2016-12-05 11:01:08 +00:00
|
|
|
p.drawText(QRect(0, 0, fullWidth, st::noContactsHeight - (cContactsReceived() ? st::noContactsFont->height : 0)), lang(cContactsReceived() ? lng_no_chats : lng_contacts_loading), style::al_center);
|
2015-09-29 13:24:39 +00:00
|
|
|
}
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
2014-07-13 09:50:38 +00:00
|
|
|
} else if (_state == FilteredState || _state == SearchedState) {
|
2015-11-18 13:11:56 +00:00
|
|
|
if (!_hashtagResults.isEmpty()) {
|
|
|
|
int32 from = floorclamp(r.y(), st::mentionHeight, 0, _hashtagResults.size());
|
|
|
|
int32 to = ceilclamp(r.y() + r.height(), st::mentionHeight, 0, _hashtagResults.size());
|
2015-03-24 10:00:27 +00:00
|
|
|
p.translate(0, from * st::mentionHeight);
|
2015-11-18 13:11:56 +00:00
|
|
|
if (from < _hashtagResults.size()) {
|
2016-12-05 11:01:08 +00:00
|
|
|
auto htagwidth = fullWidth - st::dialogsPadding.x() * 2;
|
2015-10-01 14:05:05 +00:00
|
|
|
|
2016-10-31 12:29:26 +00:00
|
|
|
p.setFont(st::mentionFont);
|
2015-03-24 10:00:27 +00:00
|
|
|
for (; from < to; ++from) {
|
2016-12-05 11:01:08 +00:00
|
|
|
auto &result = _hashtagResults[from];
|
|
|
|
bool selected = (from == (isPressed() ? _hashtagPressed : _hashtagSelected));
|
|
|
|
p.fillRect(0, 0, fullWidth, st::mentionHeight, selected ? st::mentionBgOver : st::dialogsBg);
|
|
|
|
result->row.paintRipple(p, 0, 0, fullWidth, ms);
|
2015-09-29 13:24:39 +00:00
|
|
|
if (!paintingOther) {
|
2016-12-05 11:01:08 +00:00
|
|
|
auto &tag = result->tag;
|
2015-09-29 13:24:39 +00:00
|
|
|
if (selected) {
|
2016-12-21 15:05:58 +00:00
|
|
|
int skip = (st::mentionHeight - st::smallCloseIconOver.height()) / 2;
|
|
|
|
st::smallCloseIconOver.paint(p, QPoint(fullWidth - st::smallCloseIconOver.width() - skip, skip), width());
|
2015-06-15 17:19:24 +00:00
|
|
|
}
|
2016-12-05 11:01:08 +00:00
|
|
|
auto first = (_hashtagFilter.size() < 2) ? QString() : ('#' + tag.mid(0, _hashtagFilter.size() - 1));
|
|
|
|
auto second = (_hashtagFilter.size() < 2) ? ('#' + tag) : tag.mid(_hashtagFilter.size() - 1);
|
|
|
|
auto firstwidth = st::mentionFont->width(first);
|
|
|
|
auto secondwidth = st::mentionFont->width(second);
|
2015-09-29 13:24:39 +00:00
|
|
|
if (htagwidth < firstwidth + secondwidth) {
|
|
|
|
if (htagwidth < firstwidth + st::mentionFont->elidew) {
|
2015-10-03 10:09:09 +00:00
|
|
|
first = st::mentionFont->elided(first + second, htagwidth);
|
2015-09-29 13:24:39 +00:00
|
|
|
second = QString();
|
|
|
|
} else {
|
2015-10-03 10:09:09 +00:00
|
|
|
second = st::mentionFont->elided(second, htagwidth - firstwidth);
|
2015-09-29 13:24:39 +00:00
|
|
|
}
|
|
|
|
}
|
2015-06-15 17:19:24 +00:00
|
|
|
|
2016-12-05 11:01:08 +00:00
|
|
|
p.setFont(st::mentionFont);
|
2015-09-29 13:24:39 +00:00
|
|
|
if (!first.isEmpty()) {
|
2016-12-05 11:01:08 +00:00
|
|
|
p.setPen(selected ? st::mentionFgOverActive : st::mentionFgActive);
|
2016-06-07 19:59:39 +00:00
|
|
|
p.drawText(st::dialogsPadding.x(), st::mentionTop + st::mentionFont->ascent, first);
|
2015-09-29 13:24:39 +00:00
|
|
|
}
|
|
|
|
if (!second.isEmpty()) {
|
2016-12-05 11:01:08 +00:00
|
|
|
p.setPen(selected ? st::mentionFgOver : st::mentionFg);
|
2016-06-07 19:59:39 +00:00
|
|
|
p.drawText(st::dialogsPadding.x() + firstwidth, st::mentionTop + st::mentionFont->ascent, second);
|
2015-09-29 13:24:39 +00:00
|
|
|
}
|
2015-06-15 17:19:24 +00:00
|
|
|
}
|
2015-03-24 10:00:27 +00:00
|
|
|
p.translate(0, st::mentionHeight);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-11-18 13:11:56 +00:00
|
|
|
if (!_filterResults.isEmpty()) {
|
2016-12-05 11:01:08 +00:00
|
|
|
auto skip = filteredOffset();
|
|
|
|
auto from = floorclamp(r.y() - skip, st::dialogsRowHeight, 0, _filterResults.size());
|
|
|
|
auto to = ceilclamp(r.y() + r.height() - skip, st::dialogsRowHeight, 0, _filterResults.size());
|
2016-06-07 19:59:39 +00:00
|
|
|
p.translate(0, from * st::dialogsRowHeight);
|
2015-11-18 13:11:56 +00:00
|
|
|
if (from < _filterResults.size()) {
|
2016-12-05 11:01:08 +00:00
|
|
|
auto activePeer = App::main()->activePeer();
|
|
|
|
auto activeMsgId = App::main()->activeMsgId();
|
2014-05-30 08:53:19 +00:00
|
|
|
for (; from < to; ++from) {
|
2016-12-05 11:01:08 +00:00
|
|
|
auto row = _filterResults[from];
|
|
|
|
auto peer = row->history()->peer;
|
|
|
|
auto active = ((peer == activePeer) || (peer->migrateTo() && peer->migrateTo() == activePeer)) && !activeMsgId;
|
|
|
|
auto selected = _menuPeer ? (peer == _menuPeer) : (from == (isPressed() ? _filteredPressed : _filteredSelected));
|
|
|
|
Dialogs::Layout::RowPainter::paint(p, _filterResults[from], fullWidth, active, selected, paintingOther, ms);
|
2016-06-07 19:59:39 +00:00
|
|
|
p.translate(0, st::dialogsRowHeight);
|
2014-07-04 11:12:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-07-13 09:50:38 +00:00
|
|
|
|
2016-12-05 11:01:08 +00:00
|
|
|
if (!_peerSearchResults.isEmpty()) {
|
|
|
|
p.fillRect(0, 0, fullWidth, st::searchedBarHeight, st::searchedBarBg);
|
2015-09-29 13:24:39 +00:00
|
|
|
if (!paintingOther) {
|
2016-12-03 12:10:35 +00:00
|
|
|
p.setFont(st::searchedBarFont);
|
|
|
|
p.setPen(st::searchedBarFg);
|
|
|
|
p.drawTextLeft(st::searchedBarPosition.x(), st::searchedBarPosition.y(), width(), lang(lng_search_global_results), style::al_center);
|
2015-09-29 13:24:39 +00:00
|
|
|
}
|
2014-10-22 18:39:03 +00:00
|
|
|
p.translate(0, st::searchedBarHeight);
|
2015-09-29 13:24:39 +00:00
|
|
|
|
2016-12-05 11:01:08 +00:00
|
|
|
auto skip = peerSearchOffset();
|
|
|
|
auto from = floorclamp(r.y() - skip, st::dialogsRowHeight, 0, _peerSearchResults.size());
|
|
|
|
auto to = ceilclamp(r.y() + r.height() - skip, st::dialogsRowHeight, 0, _peerSearchResults.size());
|
2016-06-07 19:59:39 +00:00
|
|
|
p.translate(0, from * st::dialogsRowHeight);
|
2016-12-05 11:01:08 +00:00
|
|
|
if (from < _peerSearchResults.size()) {
|
|
|
|
auto activePeer = App::main()->activePeer();
|
|
|
|
auto activeMsgId = App::main()->activeMsgId();
|
2014-10-22 18:39:03 +00:00
|
|
|
for (; from < to; ++from) {
|
2016-12-05 11:01:08 +00:00
|
|
|
auto &result = _peerSearchResults[from];
|
|
|
|
auto peer = result->peer;
|
|
|
|
auto active = ((peer == activePeer) || (peer->migrateTo() && peer->migrateTo() == activePeer)) && !activeMsgId;
|
|
|
|
auto selected = false ? (peer == _menuPeer) : (from == (isPressed() ? _peerSearchPressed : _peerSearchSelected));
|
|
|
|
paintPeerSearchResult(p, result.get(), fullWidth, active, selected, paintingOther, ms);
|
2016-06-07 19:59:39 +00:00
|
|
|
p.translate(0, st::dialogsRowHeight);
|
2014-10-22 18:39:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-08-04 15:01:47 +00:00
|
|
|
if (_searchInPeer) {
|
2016-12-05 11:01:08 +00:00
|
|
|
paintSearchInPeer(p, fullWidth, paintingOther);
|
2016-06-07 19:59:39 +00:00
|
|
|
p.translate(0, st::dialogsRowHeight);
|
2015-11-18 13:11:56 +00:00
|
|
|
if (_state == FilteredState && _searchResults.isEmpty()) {
|
2016-12-05 11:01:08 +00:00
|
|
|
p.fillRect(0, 0, fullWidth, st::searchedBarHeight, st::searchedBarBg);
|
2015-09-29 13:24:39 +00:00
|
|
|
if (!paintingOther) {
|
2016-12-03 12:10:35 +00:00
|
|
|
p.setFont(st::searchedBarFont);
|
|
|
|
p.setPen(st::searchedBarFg);
|
|
|
|
p.drawTextLeft(st::searchedBarPosition.x(), st::searchedBarPosition.y(), width(), lang(lng_dlg_search_for_messages), style::al_center);
|
2015-09-29 13:24:39 +00:00
|
|
|
}
|
2015-08-04 15:01:47 +00:00
|
|
|
p.translate(0, st::searchedBarHeight);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-11-18 13:11:56 +00:00
|
|
|
if (_state == SearchedState || !_searchResults.isEmpty()) {
|
|
|
|
QString text = lng_search_found_results(lt_count, _searchResults.isEmpty() ? 0 : (_searchedMigratedCount + _searchedCount));
|
2016-12-05 11:01:08 +00:00
|
|
|
p.fillRect(0, 0, fullWidth, st::searchedBarHeight, st::searchedBarBg);
|
2015-09-29 13:24:39 +00:00
|
|
|
if (!paintingOther) {
|
2016-12-03 12:10:35 +00:00
|
|
|
p.setFont(st::searchedBarFont);
|
|
|
|
p.setPen(st::searchedBarFg);
|
|
|
|
p.drawTextLeft(st::searchedBarPosition.x(), st::searchedBarPosition.y(), width(), text, style::al_center);
|
2015-09-29 13:24:39 +00:00
|
|
|
}
|
2014-07-13 09:50:38 +00:00
|
|
|
p.translate(0, st::searchedBarHeight);
|
|
|
|
|
2016-12-05 11:01:08 +00:00
|
|
|
auto skip = searchedOffset();
|
|
|
|
auto from = floorclamp(r.y() - skip, st::dialogsRowHeight, 0, _searchResults.size());
|
|
|
|
auto to = ceilclamp(r.y() + r.height() - skip, st::dialogsRowHeight, 0, _searchResults.size());
|
2016-06-07 19:59:39 +00:00
|
|
|
p.translate(0, from * st::dialogsRowHeight);
|
2015-11-18 13:11:56 +00:00
|
|
|
if (from < _searchResults.size()) {
|
2016-12-05 11:01:08 +00:00
|
|
|
auto activePeer = App::main()->activePeer();
|
|
|
|
auto activeMsgId = App::main()->activeMsgId();
|
2014-07-04 11:12:54 +00:00
|
|
|
for (; from < to; ++from) {
|
2016-12-05 11:01:08 +00:00
|
|
|
auto &result = _searchResults[from];
|
2016-04-09 18:45:55 +00:00
|
|
|
auto item = result->item();
|
2016-12-05 11:01:08 +00:00
|
|
|
auto peer = item->history()->peer;
|
|
|
|
auto active = (peer == activePeer && item->id == activeMsgId) || (peer->migrateTo() && peer->migrateTo() == activePeer && item->id == -activeMsgId);
|
|
|
|
auto selected = false ? (peer == _menuPeer) : (from == (isPressed() ? _searchedPressed : _searchedSelected));
|
|
|
|
Dialogs::Layout::RowPainter::paint(p, result.get(), fullWidth, active, selected, paintingOther, ms);
|
2016-06-07 19:59:39 +00:00
|
|
|
p.translate(0, st::dialogsRowHeight);
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-05 11:01:08 +00:00
|
|
|
void DialogsInner::paintPeerSearchResult(Painter &p, const PeerSearchResult *result, int fullWidth, bool active, bool selected, bool onlyBackground, TimeMs ms) const {
|
|
|
|
QRect fullRect(0, 0, fullWidth, st::dialogsRowHeight);
|
2016-06-07 19:59:39 +00:00
|
|
|
p.fillRect(fullRect, active ? st::dialogsBgActive : (selected ? st::dialogsBgOver : st::dialogsBg));
|
2016-12-05 11:01:08 +00:00
|
|
|
if (!active) {
|
|
|
|
result->row.paintRipple(p, 0, 0, fullWidth, ms);
|
|
|
|
}
|
2015-09-29 13:24:39 +00:00
|
|
|
if (onlyBackground) return;
|
2014-10-22 18:39:03 +00:00
|
|
|
|
2016-12-05 11:01:08 +00:00
|
|
|
auto peer = result->peer;
|
|
|
|
auto userpicPeer = (peer->migrateTo() ? peer->migrateTo() : peer);
|
2016-12-29 09:03:51 +00:00
|
|
|
userpicPeer->paintUserpicLeft(p, st::dialogsPadding.x(), st::dialogsPadding.y(), getFullWidth(), st::dialogsPhotoSize);
|
2014-10-22 18:39:03 +00:00
|
|
|
|
2016-12-05 11:01:08 +00:00
|
|
|
auto nameleft = st::dialogsPadding.x() + st::dialogsPhotoSize + st::dialogsPhotoPadding;
|
|
|
|
auto namewidth = fullWidth - nameleft - st::dialogsPadding.x();
|
2016-06-07 19:59:39 +00:00
|
|
|
QRect rectForName(nameleft, st::dialogsPadding.y() + st::dialogsNameTop, namewidth, st::msgNameFont->height);
|
2014-10-22 18:39:03 +00:00
|
|
|
|
|
|
|
// draw chat icon
|
2016-11-05 08:36:24 +00:00
|
|
|
if (auto chatTypeIcon = Dialogs::Layout::ChatTypeIcon(peer, active, selected)) {
|
2016-12-05 11:01:08 +00:00
|
|
|
chatTypeIcon->paint(p, rectForName.topLeft(), fullWidth);
|
2016-09-30 12:52:03 +00:00
|
|
|
rectForName.setLeft(rectForName.left() + st::dialogsChatTypeSkip);
|
2014-10-22 18:39:03 +00:00
|
|
|
}
|
2015-10-29 15:52:39 +00:00
|
|
|
if (peer->isVerified()) {
|
2016-11-05 08:36:24 +00:00
|
|
|
auto icon = &(active ? st::dialogsVerifiedIconActive : (selected ? st::dialogsVerifiedIconOver : st::dialogsVerifiedIcon));
|
2016-09-30 12:52:03 +00:00
|
|
|
rectForName.setWidth(rectForName.width() - icon->width());
|
2016-12-05 11:01:08 +00:00
|
|
|
icon->paint(p, rectForName.topLeft() + QPoint(qMin(peer->dialogName().maxWidth(), rectForName.width()), 0), fullWidth);
|
2015-10-29 15:52:39 +00:00
|
|
|
}
|
|
|
|
|
2016-06-07 19:59:39 +00:00
|
|
|
QRect tr(nameleft, st::dialogsPadding.y() + st::msgNameFont->height + st::dialogsSkip, namewidth, st::dialogsTextFont->height);
|
|
|
|
p.setFont(st::dialogsTextFont);
|
2015-09-06 10:17:09 +00:00
|
|
|
QString username = peer->userName();
|
2016-12-05 11:01:08 +00:00
|
|
|
if (!active && username.toLower().startsWith(_peerSearchQuery)) {
|
|
|
|
auto first = '@' + username.mid(0, _peerSearchQuery.size());
|
|
|
|
auto second = username.mid(_peerSearchQuery.size());
|
|
|
|
auto w = st::dialogsTextFont->width(first);
|
2014-10-23 16:05:33 +00:00
|
|
|
if (w >= tr.width()) {
|
2016-06-07 19:59:39 +00:00
|
|
|
p.setPen(st::dialogsTextFgService);
|
|
|
|
p.drawText(tr.left(), tr.top() + st::dialogsTextFont->ascent, st::dialogsTextFont->elided(first, tr.width()));
|
2014-10-23 16:05:33 +00:00
|
|
|
} else {
|
2016-06-07 19:59:39 +00:00
|
|
|
p.setPen(st::dialogsTextFgService);
|
|
|
|
p.drawText(tr.left(), tr.top() + st::dialogsTextFont->ascent, first);
|
|
|
|
p.setPen(st::dialogsTextFg);
|
|
|
|
p.drawText(tr.left() + w, tr.top() + st::dialogsTextFont->ascent, st::dialogsTextFont->elided(second, tr.width() - w));
|
2014-10-23 16:05:33 +00:00
|
|
|
}
|
|
|
|
} else {
|
2016-06-07 19:59:39 +00:00
|
|
|
p.setPen(active ? st::dialogsTextFgActive : st::dialogsTextFgService);
|
|
|
|
p.drawText(tr.left(), tr.top() + st::dialogsTextFont->ascent, st::dialogsTextFont->elided('@' + username, tr.width()));
|
2014-10-23 16:05:33 +00:00
|
|
|
}
|
2014-10-22 18:39:03 +00:00
|
|
|
|
2016-06-07 19:59:39 +00:00
|
|
|
p.setPen(active ? st::dialogsTextFgActive : st::dialogsNameFg);
|
2015-09-06 10:17:09 +00:00
|
|
|
peer->dialogName().drawElided(p, rectForName.left(), rectForName.top(), rectForName.width());
|
2014-10-22 18:39:03 +00:00
|
|
|
}
|
|
|
|
|
2016-12-05 11:01:08 +00:00
|
|
|
void DialogsInner::paintSearchInPeer(Painter &p, int fullWidth, bool onlyBackground) const {
|
|
|
|
QRect fullRect(0, 0, fullWidth, st::dialogsRowHeight);
|
2016-06-07 19:59:39 +00:00
|
|
|
p.fillRect(fullRect, st::dialogsBg);
|
2015-09-29 13:24:39 +00:00
|
|
|
if (onlyBackground) return;
|
2015-08-04 15:01:47 +00:00
|
|
|
|
2016-12-29 09:03:51 +00:00
|
|
|
_searchInPeer->paintUserpicLeft(p, st::dialogsPadding.x(), st::dialogsPadding.y(), getFullWidth(), st::dialogsPhotoSize);
|
2015-08-04 15:01:47 +00:00
|
|
|
|
2016-12-05 11:01:08 +00:00
|
|
|
auto nameleft = st::dialogsPadding.x() + st::dialogsPhotoSize + st::dialogsPhotoPadding;
|
|
|
|
auto namewidth = fullWidth - nameleft - st::dialogsPadding.x() * 2 - st::dialogsCancelSearch.width;
|
2016-06-07 19:59:39 +00:00
|
|
|
QRect rectForName(nameleft, st::dialogsPadding.y() + st::dialogsNameTop, namewidth, st::msgNameFont->height);
|
2015-08-04 15:01:47 +00:00
|
|
|
|
2016-11-05 08:36:24 +00:00
|
|
|
if (auto chatTypeIcon = Dialogs::Layout::ChatTypeIcon(_searchInPeer, false, false)) {
|
2016-12-05 11:01:08 +00:00
|
|
|
chatTypeIcon->paint(p, rectForName.topLeft(), fullWidth);
|
2016-09-30 12:52:03 +00:00
|
|
|
rectForName.setLeft(rectForName.left() + st::dialogsChatTypeSkip);
|
2015-08-04 15:01:47 +00:00
|
|
|
}
|
|
|
|
|
2016-06-07 19:59:39 +00:00
|
|
|
QRect tr(nameleft, st::dialogsPadding.y() + st::msgNameFont->height + st::dialogsSkip, namewidth, st::dialogsTextFont->height);
|
|
|
|
p.setFont(st::dialogsTextFont);
|
|
|
|
p.setPen(st::dialogsTextFg);
|
|
|
|
p.drawText(tr.left(), tr.top() + st::dialogsTextFont->ascent, st::dialogsTextFont->elided(lang((_searchInPeer->isChannel() && !_searchInPeer->isMegagroup()) ? lng_dlg_search_channel : lng_dlg_search_chat), tr.width()));
|
2015-08-04 15:01:47 +00:00
|
|
|
|
2016-06-07 19:59:39 +00:00
|
|
|
p.setPen(st::dialogsNameFg);
|
2015-09-04 13:01:31 +00:00
|
|
|
_searchInPeer->nameText.drawElided(p, rectForName.left(), rectForName.top(), rectForName.width());
|
2015-08-04 15:01:47 +00:00
|
|
|
}
|
|
|
|
|
2015-09-29 13:24:39 +00:00
|
|
|
void DialogsInner::activate() {
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
|
2015-09-29 13:24:39 +00:00
|
|
|
void DialogsInner::mouseMoveEvent(QMouseEvent *e) {
|
2016-12-05 11:01:08 +00:00
|
|
|
_mouseSelection = true;
|
|
|
|
updateSelected(e->pos());
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
|
2016-12-05 11:01:08 +00:00
|
|
|
void DialogsInner::clearIrrelevantState() {
|
|
|
|
if (_state == DefaultState) {
|
|
|
|
_hashtagSelected = -1;
|
|
|
|
setHashtagPressed(-1);
|
|
|
|
_hashtagDeleteSelected = _hashtagDeletePressed = false;
|
|
|
|
_filteredSelected = -1;
|
|
|
|
setFilteredPressed(-1);
|
|
|
|
_peerSearchSelected = -1;
|
|
|
|
setPeerSearchPressed(-1);
|
|
|
|
_searchedSelected = -1;
|
|
|
|
setSearchedPressed(-1);
|
|
|
|
} else if (_state == FilteredState || _state == SearchedState) {
|
|
|
|
_importantSwitchSelected = false;
|
|
|
|
setImportantSwitchPressed(false);
|
|
|
|
_selected = nullptr;
|
|
|
|
setPressed(nullptr);
|
|
|
|
}
|
|
|
|
}
|
2014-05-30 08:53:19 +00:00
|
|
|
|
2016-12-05 11:01:08 +00:00
|
|
|
void DialogsInner::updateSelected(QPoint localPos) {
|
|
|
|
if (!_mouseSelection) return;
|
|
|
|
|
|
|
|
int w = width(), mouseY = localPos.y();
|
|
|
|
clearIrrelevantState();
|
2014-07-04 11:12:54 +00:00
|
|
|
if (_state == DefaultState) {
|
2016-12-05 11:01:08 +00:00
|
|
|
auto importantSwitchSelected = (_dialogsImportant && mouseY >= 0 && mouseY < dialogsOffset());
|
2016-04-11 10:59:01 +00:00
|
|
|
mouseY -= dialogsOffset();
|
2016-12-05 11:01:08 +00:00
|
|
|
auto selected = importantSwitchSelected ? nullptr : shownDialogs()->rowAtY(mouseY, st::dialogsRowHeight);
|
|
|
|
if (_selected != selected || _importantSwitchSelected != importantSwitchSelected) {
|
2015-09-29 13:24:39 +00:00
|
|
|
updateSelectedRow();
|
2016-12-05 11:01:08 +00:00
|
|
|
_selected = selected;
|
|
|
|
_importantSwitchSelected = importantSwitchSelected;
|
2015-09-29 13:24:39 +00:00
|
|
|
updateSelectedRow();
|
2016-12-05 11:01:08 +00:00
|
|
|
setCursor((_selected || _importantSwitchSelected) ? style::cur_pointer : style::cur_default);
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
2014-07-13 09:50:38 +00:00
|
|
|
} else if (_state == FilteredState || _state == SearchedState) {
|
2016-12-05 11:01:08 +00:00
|
|
|
auto wasSelected = isSelected();
|
|
|
|
if (_hashtagResults.isEmpty()) {
|
|
|
|
_hashtagSelected = -1;
|
|
|
|
_hashtagDeleteSelected = false;
|
|
|
|
} else {
|
|
|
|
auto skip = 0;
|
|
|
|
auto hashtagSelected = (mouseY >= skip) ? ((mouseY - skip) / st::mentionHeight) : -1;
|
|
|
|
if (hashtagSelected < 0 || hashtagSelected >= _hashtagResults.size()) {
|
|
|
|
hashtagSelected = -1;
|
2015-03-24 10:00:27 +00:00
|
|
|
}
|
2016-12-05 11:01:08 +00:00
|
|
|
if (_hashtagSelected != hashtagSelected) {
|
2015-09-29 13:24:39 +00:00
|
|
|
updateSelectedRow();
|
2016-12-05 11:01:08 +00:00
|
|
|
_hashtagSelected = hashtagSelected;
|
2015-09-29 13:24:39 +00:00
|
|
|
updateSelectedRow();
|
2015-03-24 15:18:20 +00:00
|
|
|
}
|
2016-12-05 11:01:08 +00:00
|
|
|
_hashtagDeleteSelected = (_hashtagSelected >= 0) && (localPos.x() >= w - st::mentionHeight);
|
2015-03-24 10:00:27 +00:00
|
|
|
}
|
2015-11-18 13:11:56 +00:00
|
|
|
if (!_filterResults.isEmpty()) {
|
2016-12-05 11:01:08 +00:00
|
|
|
auto skip = filteredOffset();
|
|
|
|
auto filteredSelected = (mouseY >= skip) ? ((mouseY - skip) / st::dialogsRowHeight) : -1;
|
|
|
|
if (filteredSelected < 0 || filteredSelected >= _filterResults.size()) {
|
|
|
|
filteredSelected = -1;
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
2016-12-05 11:01:08 +00:00
|
|
|
if (_filteredSelected != filteredSelected) {
|
2015-09-29 13:24:39 +00:00
|
|
|
updateSelectedRow();
|
2016-12-05 11:01:08 +00:00
|
|
|
_filteredSelected = filteredSelected;
|
2015-09-29 13:24:39 +00:00
|
|
|
updateSelectedRow();
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
}
|
2016-12-05 11:01:08 +00:00
|
|
|
if (!_peerSearchResults.isEmpty()) {
|
|
|
|
auto skip = peerSearchOffset();
|
|
|
|
auto peerSearchSelected = (mouseY >= skip) ? ((mouseY - skip) / st::dialogsRowHeight) : -1;
|
|
|
|
if (peerSearchSelected < 0 || peerSearchSelected >= _peerSearchResults.size()) {
|
|
|
|
peerSearchSelected = -1;
|
2014-10-22 18:39:03 +00:00
|
|
|
}
|
2016-12-05 11:01:08 +00:00
|
|
|
if (_peerSearchSelected != peerSearchSelected) {
|
2015-09-29 13:24:39 +00:00
|
|
|
updateSelectedRow();
|
2016-12-05 11:01:08 +00:00
|
|
|
_peerSearchSelected = peerSearchSelected;
|
2015-09-29 13:24:39 +00:00
|
|
|
updateSelectedRow();
|
2014-10-22 18:39:03 +00:00
|
|
|
}
|
|
|
|
}
|
2015-11-18 13:11:56 +00:00
|
|
|
if (_state == SearchedState && !_searchResults.isEmpty()) {
|
2016-12-05 11:01:08 +00:00
|
|
|
auto skip = searchedOffset();
|
|
|
|
auto searchedSelected = (mouseY >= skip) ? ((mouseY - skip) / st::dialogsRowHeight) : -1;
|
|
|
|
if (searchedSelected < 0 || searchedSelected >= _searchResults.size()) {
|
|
|
|
searchedSelected = -1;
|
2014-07-04 11:12:54 +00:00
|
|
|
}
|
2016-12-05 11:01:08 +00:00
|
|
|
if (_searchedSelected != searchedSelected) {
|
2015-09-29 13:24:39 +00:00
|
|
|
updateSelectedRow();
|
2016-12-05 11:01:08 +00:00
|
|
|
_searchedSelected = searchedSelected;
|
2015-09-29 13:24:39 +00:00
|
|
|
updateSelectedRow();
|
2014-07-04 11:12:54 +00:00
|
|
|
}
|
|
|
|
}
|
2016-12-05 11:01:08 +00:00
|
|
|
if (wasSelected != isSelected()) {
|
|
|
|
setCursor(wasSelected ? style::cur_default : style::cur_pointer);
|
|
|
|
}
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-09-29 13:24:39 +00:00
|
|
|
void DialogsInner::mousePressEvent(QMouseEvent *e) {
|
2016-12-05 11:01:08 +00:00
|
|
|
_mouseSelection = true;
|
|
|
|
updateSelected(e->pos());
|
|
|
|
|
|
|
|
_pressButton = e->button();
|
|
|
|
setPressed(_selected);
|
|
|
|
setImportantSwitchPressed(_importantSwitchSelected);
|
|
|
|
setHashtagPressed(_hashtagSelected);
|
|
|
|
_hashtagDeletePressed = _hashtagDeleteSelected;
|
|
|
|
setFilteredPressed(_filteredSelected);
|
2016-12-07 13:32:25 +00:00
|
|
|
setPeerSearchPressed(_peerSearchSelected);
|
2016-12-05 11:01:08 +00:00
|
|
|
setSearchedPressed(_searchedSelected);
|
|
|
|
if (_importantSwitchPressed) {
|
|
|
|
_importantSwitch->row.addRipple(e->pos(), QSize(getFullWidth(), st::dialogsImportantBarHeight), [this] {
|
|
|
|
update(0, 0, getFullWidth(), st::dialogsImportantBarHeight);
|
|
|
|
});
|
|
|
|
} else if (_pressed) {
|
|
|
|
auto row = _pressed;
|
|
|
|
row->addRipple(e->pos() - QPoint(0, dialogsOffset() + _pressed->pos() * st::dialogsRowHeight), QSize(getFullWidth(), st::dialogsRowHeight), [row] {
|
|
|
|
row->history()->updateChatListEntry();
|
|
|
|
});
|
|
|
|
} else if (_hashtagPressed >= 0 && _hashtagPressed < _hashtagResults.size() && !_hashtagDeletePressed) {
|
|
|
|
auto row = &_hashtagResults[_hashtagPressed]->row;
|
|
|
|
row->addRipple(e->pos(), QSize(getFullWidth(), st::mentionHeight), [this, index = _hashtagPressed] {
|
|
|
|
update(0, index * st::mentionHeight, getFullWidth(), st::mentionHeight);
|
|
|
|
});
|
|
|
|
} else if (_filteredPressed >= 0 && _filteredPressed < _filterResults.size()) {
|
|
|
|
auto row = _filterResults[_filteredPressed];
|
|
|
|
row->addRipple(e->pos() - QPoint(0, filteredOffset() + _filteredPressed * st::dialogsRowHeight), QSize(getFullWidth(), st::dialogsRowHeight), [row] {
|
|
|
|
if (auto main = App::main()) {
|
|
|
|
main->dlgUpdated(row->history()->peer, 0);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
} else if (_peerSearchPressed >= 0 && _peerSearchPressed < _peerSearchResults.size()) {
|
|
|
|
auto &result = _peerSearchResults[_peerSearchPressed];
|
|
|
|
auto row = &result->row;
|
|
|
|
row->addRipple(e->pos() - QPoint(0, peerSearchOffset() + _peerSearchPressed * st::dialogsRowHeight), QSize(getFullWidth(), st::dialogsRowHeight), [peer = result->peer] {
|
|
|
|
if (auto main = App::main()) {
|
|
|
|
main->dlgUpdated(peer, 0);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
} else if (_searchedPressed >= 0 && _searchedPressed < _searchResults.size()) {
|
|
|
|
auto &row = _searchResults[_searchedPressed];
|
|
|
|
row->addRipple(e->pos() - QPoint(0, searchedOffset() + _searchedPressed * st::dialogsRowHeight), QSize(getFullWidth(), st::dialogsRowHeight), [this, index = _searchedPressed] {
|
|
|
|
rtlupdate(0, searchedOffset() + index * st::dialogsRowHeight, getFullWidth(), st::dialogsRowHeight);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void DialogsInner::mouseReleaseEvent(QMouseEvent *e) {
|
|
|
|
mousePressReleased(e->button());
|
|
|
|
}
|
|
|
|
|
|
|
|
void DialogsInner::mousePressReleased(Qt::MouseButton button) {
|
|
|
|
auto importantSwitchPressed = _importantSwitchPressed;
|
|
|
|
setImportantSwitchPressed(false);
|
|
|
|
auto pressed = _pressed;
|
|
|
|
setPressed(nullptr);
|
|
|
|
auto hashtagPressed = _hashtagPressed;
|
|
|
|
setHashtagPressed(-1);
|
|
|
|
auto hashtagDeletePressed = _hashtagDeletePressed;
|
|
|
|
_hashtagDeletePressed = false;
|
|
|
|
auto filteredPressed = _filteredPressed;
|
|
|
|
setFilteredPressed(-1);
|
|
|
|
auto peerSearchPressed = _peerSearchPressed;
|
|
|
|
setPeerSearchPressed(-1);
|
|
|
|
auto searchedPressed = _searchedPressed;
|
|
|
|
setSearchedPressed(-1);
|
|
|
|
updateSelectedRow();
|
|
|
|
if (button == Qt::LeftButton) {
|
|
|
|
if (importantSwitchPressed && importantSwitchPressed == _importantSwitchSelected) {
|
|
|
|
choosePeer();
|
|
|
|
} else if (pressed && pressed == _selected) {
|
|
|
|
choosePeer();
|
|
|
|
} else if (hashtagPressed >= 0 && hashtagPressed == _hashtagSelected && hashtagDeletePressed == _hashtagDeleteSelected) {
|
|
|
|
choosePeer();
|
|
|
|
} else if (filteredPressed >= 0 && filteredPressed == _filteredSelected) {
|
|
|
|
choosePeer();
|
|
|
|
} else if (peerSearchPressed >= 0 && peerSearchPressed == _peerSearchSelected) {
|
|
|
|
choosePeer();
|
|
|
|
} else if (searchedPressed >= 0 && searchedPressed == _searchedSelected) {
|
|
|
|
choosePeer();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void DialogsInner::setImportantSwitchPressed(bool pressed) {
|
|
|
|
if (_importantSwitchPressed != pressed) {
|
|
|
|
if (_importantSwitchPressed) {
|
|
|
|
_importantSwitch->row.stopLastRipple();
|
|
|
|
}
|
|
|
|
_importantSwitchPressed = pressed;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void DialogsInner::setPressed(Dialogs::Row *pressed) {
|
|
|
|
if (_pressed != pressed) {
|
|
|
|
if (_pressed) {
|
|
|
|
_pressed->stopLastRipple();
|
|
|
|
}
|
|
|
|
_pressed = pressed;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void DialogsInner::setHashtagPressed(int pressed) {
|
|
|
|
if (_hashtagPressed >= 0 && _hashtagPressed < _hashtagResults.size()) {
|
|
|
|
_hashtagResults[_hashtagPressed]->row.stopLastRipple();
|
|
|
|
}
|
|
|
|
_hashtagPressed = pressed;
|
|
|
|
}
|
|
|
|
|
|
|
|
void DialogsInner::setFilteredPressed(int pressed) {
|
|
|
|
if (_filteredPressed >= 0 && _filteredPressed < _filterResults.size()) {
|
|
|
|
_filterResults[_filteredPressed]->stopLastRipple();
|
|
|
|
}
|
|
|
|
_filteredPressed = pressed;
|
|
|
|
}
|
|
|
|
|
|
|
|
void DialogsInner::setPeerSearchPressed(int pressed) {
|
|
|
|
if (_peerSearchPressed >= 0 && _peerSearchPressed < _peerSearchResults.size()) {
|
|
|
|
_peerSearchResults[_peerSearchPressed]->row.stopLastRipple();
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
2016-12-05 11:01:08 +00:00
|
|
|
_peerSearchPressed = pressed;
|
|
|
|
}
|
|
|
|
|
|
|
|
void DialogsInner::setSearchedPressed(int pressed) {
|
|
|
|
if (_searchedPressed >= 0 && _searchedPressed < _searchResults.size()) {
|
|
|
|
_searchResults[_searchedPressed]->stopLastRipple();
|
|
|
|
}
|
|
|
|
_searchedPressed = pressed;
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
|
2015-09-29 13:24:39 +00:00
|
|
|
void DialogsInner::resizeEvent(QResizeEvent *e) {
|
2016-11-11 13:46:04 +00:00
|
|
|
_addContactLnk->move((width() - _addContactLnk->width()) / 2, (st::noContactsHeight + st::noContactsFont->height) / 2);
|
2017-01-14 18:50:16 +00:00
|
|
|
auto widthForCancelButton = qMax(width() + otherWidth(), st::dialogsWidthMin);
|
|
|
|
_cancelSearchInPeer->moveToLeft(widthForCancelButton - st::dialogsFilterSkip - st::dialogsFilterPadding.x() - _cancelSearchInPeer->width(), (st::dialogsRowHeight - st::dialogsCancelSearchInPeer.height) / 2);
|
2014-11-25 12:15:29 +00:00
|
|
|
}
|
|
|
|
|
2016-04-09 18:45:55 +00:00
|
|
|
void DialogsInner::onDialogRowReplaced(Dialogs::Row *oldRow, Dialogs::Row *newRow) {
|
2014-07-13 09:50:38 +00:00
|
|
|
if (_state == FilteredState || _state == SearchedState) {
|
2015-11-18 13:11:56 +00:00
|
|
|
for (FilteredDialogs::iterator i = _filterResults.begin(); i != _filterResults.end();) {
|
2014-05-30 08:53:19 +00:00
|
|
|
if (*i == oldRow) { // this row is shown in filtered and maybe is in contacts!
|
|
|
|
if (newRow) {
|
|
|
|
*i = newRow;
|
|
|
|
++i;
|
|
|
|
} else {
|
2015-11-18 13:11:56 +00:00
|
|
|
i = _filterResults.erase(i);
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
++i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-12-05 11:01:08 +00:00
|
|
|
if (_selected == oldRow) {
|
|
|
|
_selected = newRow;
|
|
|
|
}
|
|
|
|
if (_pressed == oldRow) {
|
|
|
|
setPressed(newRow);
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-09-29 13:24:39 +00:00
|
|
|
void DialogsInner::createDialog(History *history) {
|
2016-10-22 15:58:14 +00:00
|
|
|
if (history->peer->loadedStatus != PeerData::LoadedStatus::FullLoaded) {
|
|
|
|
LOG(("API Error: DialogsInner::createDialog() called for a non loaded peer!"));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-04-11 10:59:01 +00:00
|
|
|
bool creating = !history->inChatList(Dialogs::Mode::All);
|
2015-09-24 16:05:06 +00:00
|
|
|
if (creating) {
|
2016-12-05 11:01:08 +00:00
|
|
|
auto mainRow = history->addToChatList(Dialogs::Mode::All, _dialogs.get());
|
|
|
|
_contactsNoDialogs->del(history->peer, mainRow);
|
2015-09-24 16:05:06 +00:00
|
|
|
}
|
2016-12-05 11:01:08 +00:00
|
|
|
if (_dialogsImportant && !history->inChatList(Dialogs::Mode::Important) && !history->mute()) {
|
2016-04-11 10:59:01 +00:00
|
|
|
if (Global::DialogsMode() == Dialogs::Mode::Important) {
|
|
|
|
creating = true;
|
|
|
|
}
|
2016-12-05 11:01:08 +00:00
|
|
|
history->addToChatList(Dialogs::Mode::Important, _dialogsImportant.get());
|
2016-04-11 10:59:01 +00:00
|
|
|
}
|
|
|
|
|
2016-12-05 11:01:08 +00:00
|
|
|
auto changed = history->adjustByPosInChatList(Dialogs::Mode::All, _dialogs.get());
|
2016-04-11 10:59:01 +00:00
|
|
|
|
2016-12-05 11:01:08 +00:00
|
|
|
if (_dialogsImportant) {
|
2016-04-11 10:59:01 +00:00
|
|
|
if (history->mute()) {
|
|
|
|
if (Global::DialogsMode() == Dialogs::Mode::Important) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
} else {
|
2016-12-05 11:01:08 +00:00
|
|
|
auto importantChanged = history->adjustByPosInChatList(Dialogs::Mode::Important, _dialogsImportant.get());
|
2016-04-11 10:59:01 +00:00
|
|
|
if (Global::DialogsMode() == Dialogs::Mode::Important) {
|
|
|
|
changed = importantChanged;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-05-30 08:53:19 +00:00
|
|
|
|
2016-06-07 19:59:39 +00:00
|
|
|
int from = dialogsOffset() + changed.movedFrom * st::dialogsRowHeight;
|
|
|
|
int to = dialogsOffset() + changed.movedTo * st::dialogsRowHeight;
|
2016-04-11 11:14:54 +00:00
|
|
|
emit dialogMoved(from, to);
|
2014-05-30 08:53:19 +00:00
|
|
|
|
2015-09-24 16:05:06 +00:00
|
|
|
if (creating) {
|
2015-09-06 10:17:09 +00:00
|
|
|
refresh();
|
2016-04-11 11:14:54 +00:00
|
|
|
} else if (_state == DefaultState && changed.movedFrom != changed.movedTo) {
|
2016-12-05 11:01:08 +00:00
|
|
|
update(0, qMin(from, to), getFullWidth(), qAbs(from - to) + st::dialogsRowHeight);
|
2015-09-06 10:17:09 +00:00
|
|
|
}
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
|
2015-11-13 15:14:33 +00:00
|
|
|
void DialogsInner::removeDialog(History *history) {
|
|
|
|
if (!history) return;
|
2015-12-02 17:17:53 +00:00
|
|
|
if (history->peer == _menuPeer && _menu) {
|
|
|
|
_menu->deleteLater();
|
|
|
|
}
|
2016-12-05 11:01:08 +00:00
|
|
|
if (_selected && _selected->history() == history) {
|
|
|
|
_selected = nullptr;
|
2016-04-11 10:59:01 +00:00
|
|
|
}
|
2016-12-05 11:01:08 +00:00
|
|
|
if (_pressed && _pressed->history() == history) {
|
|
|
|
setPressed(nullptr);
|
|
|
|
}
|
|
|
|
history->removeFromChatList(Dialogs::Mode::All, _dialogs.get());
|
|
|
|
if (_dialogsImportant) {
|
|
|
|
history->removeFromChatList(Dialogs::Mode::Important, _dialogsImportant.get());
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
2015-09-23 17:43:08 +00:00
|
|
|
if (App::wnd()) App::wnd()->notifyClear(history);
|
2016-12-05 11:01:08 +00:00
|
|
|
if (_contacts->contains(history->peer->id)) {
|
|
|
|
if (!_contactsNoDialogs->contains(history->peer->id)) {
|
|
|
|
_contactsNoDialogs->addByName(history);
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-11-13 15:14:33 +00:00
|
|
|
Local::removeSavedPeer(history->peer);
|
2015-08-07 12:11:50 +00:00
|
|
|
|
2014-05-30 08:53:19 +00:00
|
|
|
emit App::main()->dialogsUpdated();
|
|
|
|
|
|
|
|
refresh();
|
|
|
|
}
|
|
|
|
|
2016-04-11 10:59:01 +00:00
|
|
|
void DialogsInner::dlgUpdated(Dialogs::Mode list, Dialogs::Row *row) {
|
2014-07-04 11:12:54 +00:00
|
|
|
if (_state == DefaultState) {
|
2016-04-11 10:59:01 +00:00
|
|
|
if (Global::DialogsMode() == list) {
|
2016-12-05 11:01:08 +00:00
|
|
|
update(0, dialogsOffset() + row->pos() * st::dialogsRowHeight, getFullWidth(), st::dialogsRowHeight);
|
2016-04-11 10:59:01 +00:00
|
|
|
}
|
2014-07-13 09:50:38 +00:00
|
|
|
} else if (_state == FilteredState || _state == SearchedState) {
|
2016-04-11 10:59:01 +00:00
|
|
|
if (list == Dialogs::Mode::All) {
|
|
|
|
for (int32 i = 0, l = _filterResults.size(); i < l; ++i) {
|
|
|
|
if (_filterResults.at(i)->history() == row->history()) {
|
2016-12-05 11:01:08 +00:00
|
|
|
update(0, filteredOffset() + i * st::dialogsRowHeight, getFullWidth(), st::dialogsRowHeight);
|
2016-04-11 10:59:01 +00:00
|
|
|
break;
|
|
|
|
}
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-05 11:01:08 +00:00
|
|
|
void DialogsInner::dlgUpdated(PeerData *peer, MsgId msgId) {
|
|
|
|
updateDialogRow(peer, msgId, QRect(0, 0, getFullWidth(), st::dialogsRowHeight));
|
2016-12-05 08:45:56 +00:00
|
|
|
}
|
|
|
|
|
2016-12-05 11:01:08 +00:00
|
|
|
void DialogsInner::updateDialogRow(PeerData *peer, MsgId msgId, QRect updateRect, UpdateRowSections sections) {
|
2016-12-05 08:45:56 +00:00
|
|
|
auto updateRow = [this, updateRect](int rowTop) {
|
|
|
|
rtlupdate(updateRect.x(), rowTop + updateRect.y(), updateRect.width(), updateRect.height());
|
|
|
|
};
|
2014-07-04 11:12:54 +00:00
|
|
|
if (_state == DefaultState) {
|
2016-12-05 08:45:56 +00:00
|
|
|
if (sections & UpdateRowSection::Default) {
|
2016-12-05 11:01:08 +00:00
|
|
|
if (auto row = shownDialogs()->getRow(peer->id)) {
|
2016-12-05 08:45:56 +00:00
|
|
|
updateRow(dialogsOffset() + row->pos() * st::dialogsRowHeight);
|
|
|
|
}
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
2014-07-13 09:50:38 +00:00
|
|
|
} else if (_state == FilteredState || _state == SearchedState) {
|
2016-12-05 08:45:56 +00:00
|
|
|
if ((sections & UpdateRowSection::Filtered) && !_filterResults.isEmpty()) {
|
|
|
|
auto index = 0, add = filteredOffset();
|
|
|
|
for_const (auto row, _filterResults) {
|
2016-12-05 11:01:08 +00:00
|
|
|
if (row->history()->peer == peer) {
|
2016-12-05 08:45:56 +00:00
|
|
|
updateRow(add + index * st::dialogsRowHeight);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
++index;
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
}
|
2016-12-05 11:01:08 +00:00
|
|
|
if ((sections & UpdateRowSection::PeerSearch) && !_peerSearchResults.isEmpty()) {
|
|
|
|
auto index = 0, add = peerSearchOffset();
|
|
|
|
for_const (auto &result, _peerSearchResults) {
|
|
|
|
if (result->peer == peer) {
|
2016-12-05 08:45:56 +00:00
|
|
|
updateRow(add + index * st::dialogsRowHeight);
|
2014-10-22 18:39:03 +00:00
|
|
|
break;
|
|
|
|
}
|
2016-12-05 08:45:56 +00:00
|
|
|
++index;
|
2014-10-22 18:39:03 +00:00
|
|
|
}
|
|
|
|
}
|
2016-12-05 08:45:56 +00:00
|
|
|
if ((sections & UpdateRowSection::MessageSearch) && !_searchResults.isEmpty()) {
|
|
|
|
auto index = 0, add = searchedOffset();
|
2016-12-05 11:01:08 +00:00
|
|
|
for_const (auto &result, _searchResults) {
|
|
|
|
auto item = result->item();
|
|
|
|
if (item->history()->peer == peer && item->id == msgId) {
|
2016-12-05 08:45:56 +00:00
|
|
|
updateRow(add + index * st::dialogsRowHeight);
|
2014-07-13 09:50:38 +00:00
|
|
|
break;
|
|
|
|
}
|
2016-12-05 08:45:56 +00:00
|
|
|
++index;
|
2014-07-04 11:12:54 +00:00
|
|
|
}
|
|
|
|
}
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-09-29 13:24:39 +00:00
|
|
|
void DialogsInner::enterEvent(QEvent *e) {
|
2014-05-30 08:53:19 +00:00
|
|
|
setMouseTracking(true);
|
2016-12-05 11:01:08 +00:00
|
|
|
updateSelected();
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
|
2015-12-02 17:17:53 +00:00
|
|
|
void DialogsInner::updateSelectedRow(PeerData *peer) {
|
2015-09-29 13:24:39 +00:00
|
|
|
if (_state == DefaultState) {
|
2015-12-02 17:17:53 +00:00
|
|
|
if (peer) {
|
|
|
|
if (History *h = App::historyLoaded(peer->id)) {
|
2016-04-11 10:59:01 +00:00
|
|
|
if (h->inChatList(Global::DialogsMode())) {
|
2016-12-05 11:01:08 +00:00
|
|
|
update(0, dialogsOffset() + h->posInChatList(Global::DialogsMode()) * st::dialogsRowHeight, getFullWidth(), st::dialogsRowHeight);
|
2015-12-02 17:17:53 +00:00
|
|
|
}
|
|
|
|
}
|
2016-12-05 11:01:08 +00:00
|
|
|
} else if (_selected) {
|
|
|
|
update(0, dialogsOffset() + _selected->pos() * st::dialogsRowHeight, getFullWidth(), st::dialogsRowHeight);
|
|
|
|
} else if (_importantSwitchSelected) {
|
|
|
|
update(0, 0, getFullWidth(), st::dialogsImportantBarHeight);
|
2015-09-29 13:24:39 +00:00
|
|
|
}
|
|
|
|
} else if (_state == FilteredState || _state == SearchedState) {
|
2015-12-02 17:17:53 +00:00
|
|
|
if (peer) {
|
|
|
|
for (int32 i = 0, l = _filterResults.size(); i != l; ++i) {
|
2016-04-09 18:45:55 +00:00
|
|
|
if (_filterResults.at(i)->history()->peer == peer) {
|
2016-12-05 11:01:08 +00:00
|
|
|
update(0, filteredOffset() + i * st::dialogsRowHeight, getFullWidth(), st::dialogsRowHeight);
|
2015-12-02 17:17:53 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2016-12-05 11:01:08 +00:00
|
|
|
} else if (_hashtagSelected >= 0) {
|
|
|
|
update(0, _hashtagSelected * st::mentionHeight, getFullWidth(), st::mentionHeight);
|
|
|
|
} else if (_filteredSelected >= 0) {
|
|
|
|
update(0, filteredOffset() + _filteredSelected * st::dialogsRowHeight, getFullWidth(), st::dialogsRowHeight);
|
|
|
|
} else if (_peerSearchSelected >= 0) {
|
|
|
|
update(0, peerSearchOffset() + _peerSearchSelected * st::dialogsRowHeight, getFullWidth(), st::dialogsRowHeight);
|
|
|
|
} else if (_searchedSelected >= 0) {
|
|
|
|
update(0, searchedOffset() + _searchedSelected * st::dialogsRowHeight, getFullWidth(), st::dialogsRowHeight);
|
2015-09-29 13:24:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void DialogsInner::leaveEvent(QEvent *e) {
|
2014-05-30 08:53:19 +00:00
|
|
|
setMouseTracking(false);
|
2016-04-11 10:59:01 +00:00
|
|
|
clearSelection();
|
|
|
|
}
|
|
|
|
|
2016-12-04 19:40:41 +00:00
|
|
|
void DialogsInner::dragLeft() {
|
|
|
|
setMouseTracking(false);
|
|
|
|
clearSelection();
|
|
|
|
}
|
|
|
|
|
2016-04-11 10:59:01 +00:00
|
|
|
void DialogsInner::clearSelection() {
|
2016-12-05 11:01:08 +00:00
|
|
|
_mouseSelection = false;
|
|
|
|
if (_importantSwitchSelected || _selected || _filteredSelected >= 0 || _hashtagSelected >= 0 || _peerSearchSelected >= 0 || _searchedSelected >= 0) {
|
2015-09-29 13:24:39 +00:00
|
|
|
updateSelectedRow();
|
2016-12-05 11:01:08 +00:00
|
|
|
_importantSwitchSelected = false;
|
|
|
|
_selected = nullptr;
|
|
|
|
_filteredSelected = _searchedSelected = _peerSearchSelected = _hashtagSelected = -1;
|
2015-08-03 10:22:05 +00:00
|
|
|
setCursor(style::cur_default);
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-12-02 17:17:53 +00:00
|
|
|
void DialogsInner::contextMenuEvent(QContextMenuEvent *e) {
|
|
|
|
if (_menu) {
|
|
|
|
_menu->deleteLater();
|
2016-11-05 08:36:24 +00:00
|
|
|
_menu = nullptr;
|
2015-12-02 17:17:53 +00:00
|
|
|
}
|
|
|
|
if (_menuPeer) {
|
|
|
|
updateSelectedRow(_menuPeer);
|
2016-11-05 08:36:24 +00:00
|
|
|
_menuPeer = nullptr;
|
2015-12-02 17:17:53 +00:00
|
|
|
}
|
2015-12-06 15:50:02 +00:00
|
|
|
|
2015-12-02 17:17:53 +00:00
|
|
|
if (e->reason() == QContextMenuEvent::Mouse) {
|
2016-12-05 11:01:08 +00:00
|
|
|
_mouseSelection = true;
|
|
|
|
updateSelected();
|
2015-12-02 17:17:53 +00:00
|
|
|
}
|
|
|
|
|
2016-11-05 08:36:24 +00:00
|
|
|
History *history = nullptr;
|
2015-12-02 17:17:53 +00:00
|
|
|
if (_state == DefaultState) {
|
2016-12-05 11:01:08 +00:00
|
|
|
if (_selected) history = _selected->history();
|
2015-12-02 17:17:53 +00:00
|
|
|
} else if (_state == FilteredState || _state == SearchedState) {
|
2016-12-05 11:01:08 +00:00
|
|
|
if (_filteredSelected >= 0 && _filteredSelected < _filterResults.size()) {
|
|
|
|
history = _filterResults[_filteredSelected]->history();
|
2015-12-02 17:17:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!history) return;
|
|
|
|
_menuPeer = history->peer;
|
|
|
|
|
2016-12-05 11:01:08 +00:00
|
|
|
if (_pressButton != Qt::LeftButton) {
|
|
|
|
mousePressReleased(_pressButton);
|
|
|
|
}
|
|
|
|
|
2017-01-11 05:30:51 +00:00
|
|
|
_menu = new Ui::PopupMenu(nullptr);
|
2016-11-20 12:54:07 +00:00
|
|
|
App::main()->fillPeerMenu(_menuPeer, [this](const QString &text, base::lambda<void()> &&callback) {
|
2016-11-05 08:36:24 +00:00
|
|
|
return _menu->addAction(text, std_::move(callback));
|
2016-12-20 13:03:51 +00:00
|
|
|
}, true);
|
2015-12-02 17:17:53 +00:00
|
|
|
connect(_menu, SIGNAL(destroyed(QObject*)), this, SLOT(onMenuDestroyed(QObject*)));
|
|
|
|
_menu->popup(e->globalPos());
|
|
|
|
e->accept();
|
|
|
|
}
|
|
|
|
|
|
|
|
void DialogsInner::onMenuDestroyed(QObject *obj) {
|
|
|
|
if (_menu == obj) {
|
2016-11-05 08:36:24 +00:00
|
|
|
_menu = nullptr;
|
2015-12-02 17:17:53 +00:00
|
|
|
if (_menuPeer) {
|
2016-11-05 08:36:24 +00:00
|
|
|
updateSelectedRow(base::take(_menuPeer));
|
2015-12-02 17:17:53 +00:00
|
|
|
}
|
2016-12-05 11:01:08 +00:00
|
|
|
auto localPos = mapFromGlobal(QCursor::pos());
|
|
|
|
if (rect().contains(localPos)) {
|
|
|
|
_mouseSelection = true;
|
2015-12-02 17:17:53 +00:00
|
|
|
setMouseTracking(true);
|
2016-12-05 11:01:08 +00:00
|
|
|
updateSelected(localPos);
|
2015-12-02 17:17:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-09-29 13:24:39 +00:00
|
|
|
void DialogsInner::onParentGeometryChanged() {
|
2016-12-05 11:01:08 +00:00
|
|
|
auto localPos = mapFromGlobal(QCursor::pos());
|
|
|
|
if (rect().contains(localPos)) {
|
2014-05-30 08:53:19 +00:00
|
|
|
setMouseTracking(true);
|
2016-12-05 11:01:08 +00:00
|
|
|
updateSelected(localPos);
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-09-29 13:24:39 +00:00
|
|
|
void DialogsInner::onPeerNameChanged(PeerData *peer, const PeerData::Names &oldNames, const PeerData::NameFirstChars &oldChars) {
|
2016-12-05 11:01:08 +00:00
|
|
|
_dialogs->peerNameChanged(Dialogs::Mode::All, peer, oldNames, oldChars);
|
|
|
|
if (_dialogsImportant) {
|
|
|
|
_dialogsImportant->peerNameChanged(Dialogs::Mode::Important, peer, oldNames, oldChars);
|
2016-04-11 10:59:01 +00:00
|
|
|
}
|
2016-12-05 11:01:08 +00:00
|
|
|
_contactsNoDialogs->peerNameChanged(peer, oldNames, oldChars);
|
|
|
|
_contacts->peerNameChanged(peer, oldNames, oldChars);
|
2015-09-29 13:24:39 +00:00
|
|
|
update();
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
|
2015-09-29 13:24:39 +00:00
|
|
|
void DialogsInner::onPeerPhotoChanged(PeerData *peer) {
|
|
|
|
update();
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
|
2015-09-29 13:24:39 +00:00
|
|
|
void DialogsInner::onFilterUpdate(QString newFilter, bool force) {
|
2014-10-07 17:57:57 +00:00
|
|
|
newFilter = textSearchKey(newFilter);
|
2015-11-18 13:11:56 +00:00
|
|
|
if (newFilter != _filter || force) {
|
2014-05-30 08:53:19 +00:00
|
|
|
QStringList f;
|
|
|
|
if (!newFilter.isEmpty()) {
|
|
|
|
QStringList filterList = newFilter.split(cWordSplit(), QString::SkipEmptyParts);
|
|
|
|
int l = filterList.size();
|
|
|
|
|
|
|
|
f.reserve(l);
|
|
|
|
for (int i = 0; i < l; ++i) {
|
|
|
|
QString filterName = filterList[i].trimmed();
|
|
|
|
if (filterName.isEmpty()) continue;
|
|
|
|
f.push_back(filterName);
|
|
|
|
}
|
|
|
|
newFilter = f.join(' ');
|
|
|
|
}
|
2015-11-18 13:11:56 +00:00
|
|
|
if (newFilter != _filter || force) {
|
|
|
|
_filter = newFilter;
|
|
|
|
if (!_searchInPeer && _filter.isEmpty()) {
|
2014-07-04 11:12:54 +00:00
|
|
|
_state = DefaultState;
|
2015-11-18 13:11:56 +00:00
|
|
|
_hashtagResults.clear();
|
|
|
|
_filterResults.clear();
|
2016-12-05 11:01:08 +00:00
|
|
|
_peerSearchResults.clear();
|
2015-11-18 13:11:56 +00:00
|
|
|
_searchResults.clear();
|
|
|
|
_lastSearchDate = 0;
|
|
|
|
_lastSearchPeer = 0;
|
|
|
|
_lastSearchId = _lastSearchMigratedId = 0;
|
2014-07-04 11:12:54 +00:00
|
|
|
} else {
|
2014-05-30 08:53:19 +00:00
|
|
|
QStringList::const_iterator fb = f.cbegin(), fe = f.cend(), fi;
|
|
|
|
|
2014-07-04 11:12:54 +00:00
|
|
|
_state = FilteredState;
|
2015-11-18 13:11:56 +00:00
|
|
|
_filterResults.clear();
|
2015-08-04 15:01:47 +00:00
|
|
|
if (!_searchInPeer && !f.isEmpty()) {
|
2016-04-09 18:45:55 +00:00
|
|
|
const Dialogs::List *toFilter = nullptr;
|
2016-12-05 11:01:08 +00:00
|
|
|
if (!_dialogs->isEmpty()) {
|
2014-05-30 08:53:19 +00:00
|
|
|
for (fi = fb; fi != fe; ++fi) {
|
2016-12-05 11:01:08 +00:00
|
|
|
auto found = _dialogs->filtered(fi->at(0));
|
2016-04-09 18:45:55 +00:00
|
|
|
if (found->isEmpty()) {
|
|
|
|
toFilter = nullptr;
|
2014-05-30 08:53:19 +00:00
|
|
|
break;
|
|
|
|
}
|
2016-04-09 18:45:55 +00:00
|
|
|
if (!toFilter || toFilter->size() > found->size()) {
|
|
|
|
toFilter = found;
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-04-09 18:45:55 +00:00
|
|
|
const Dialogs::List *toFilterContacts = nullptr;
|
2016-12-05 11:01:08 +00:00
|
|
|
if (!_contactsNoDialogs->isEmpty()) {
|
2014-05-30 08:53:19 +00:00
|
|
|
for (fi = fb; fi != fe; ++fi) {
|
2016-12-05 11:01:08 +00:00
|
|
|
auto found = _contactsNoDialogs->filtered(fi->at(0));
|
2016-04-09 18:45:55 +00:00
|
|
|
if (found->isEmpty()) {
|
|
|
|
toFilterContacts = nullptr;
|
2014-05-30 08:53:19 +00:00
|
|
|
break;
|
|
|
|
}
|
2016-04-09 18:45:55 +00:00
|
|
|
if (!toFilterContacts || toFilterContacts->size() > found->size()) {
|
|
|
|
toFilterContacts = found;
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-04-09 18:45:55 +00:00
|
|
|
_filterResults.reserve((toFilter ? toFilter->size() : 0) + (toFilterContacts ? toFilterContacts->size() : 0));
|
|
|
|
if (toFilter) {
|
|
|
|
for_const (auto row, *toFilter) {
|
|
|
|
const PeerData::Names &names(row->history()->peer->names);
|
2014-05-30 08:53:19 +00:00
|
|
|
PeerData::Names::const_iterator nb = names.cbegin(), ne = names.cend(), ni;
|
|
|
|
for (fi = fb; fi != fe; ++fi) {
|
|
|
|
QString filterName(*fi);
|
|
|
|
for (ni = nb; ni != ne; ++ni) {
|
2014-08-22 09:53:53 +00:00
|
|
|
if (ni->startsWith(*fi)) {
|
2014-05-30 08:53:19 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (ni == ne) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (fi == fe) {
|
2016-04-09 18:45:55 +00:00
|
|
|
_filterResults.push_back(row);
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-04-09 18:45:55 +00:00
|
|
|
if (toFilterContacts) {
|
|
|
|
for_const (auto row, *toFilterContacts) {
|
|
|
|
const PeerData::Names &names(row->history()->peer->names);
|
2014-05-30 08:53:19 +00:00
|
|
|
PeerData::Names::const_iterator nb = names.cbegin(), ne = names.cend(), ni;
|
|
|
|
for (fi = fb; fi != fe; ++fi) {
|
|
|
|
QString filterName(*fi);
|
|
|
|
for (ni = nb; ni != ne; ++ni) {
|
2014-08-22 09:53:53 +00:00
|
|
|
if (ni->startsWith(*fi)) {
|
2014-05-30 08:53:19 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (ni == ne) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (fi == fe) {
|
2016-04-09 18:45:55 +00:00
|
|
|
_filterResults.push_back(row);
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
refresh(true);
|
2016-12-05 11:01:08 +00:00
|
|
|
setMouseSelection(false, true);
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
2014-07-13 09:50:38 +00:00
|
|
|
if (_state != DefaultState) {
|
|
|
|
emit searchMessages();
|
|
|
|
}
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
|
2015-09-29 13:24:39 +00:00
|
|
|
void DialogsInner::onHashtagFilterUpdate(QStringRef newFilter) {
|
2015-08-04 15:01:47 +00:00
|
|
|
if (newFilter.isEmpty() || newFilter.at(0) != '#' || _searchInPeer) {
|
2015-06-15 17:19:24 +00:00
|
|
|
_hashtagFilter = QString();
|
2015-11-18 13:11:56 +00:00
|
|
|
if (!_hashtagResults.isEmpty()) {
|
|
|
|
_hashtagResults.clear();
|
2015-03-24 10:00:27 +00:00
|
|
|
refresh(true);
|
2016-12-05 11:01:08 +00:00
|
|
|
setMouseSelection(false, true);
|
2015-03-24 10:00:27 +00:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
2015-06-15 17:19:24 +00:00
|
|
|
_hashtagFilter = newFilter.toString();
|
2015-03-24 10:00:27 +00:00
|
|
|
if (cRecentSearchHashtags().isEmpty() && cRecentWriteHashtags().isEmpty()) {
|
2016-01-01 14:48:32 +00:00
|
|
|
Local::readRecentHashtagsAndBots();
|
2015-03-24 10:00:27 +00:00
|
|
|
}
|
2016-12-05 11:01:08 +00:00
|
|
|
auto &recent = cRecentSearchHashtags();
|
2015-11-18 13:11:56 +00:00
|
|
|
_hashtagResults.clear();
|
2015-03-24 10:00:27 +00:00
|
|
|
if (!recent.isEmpty()) {
|
2016-12-05 11:01:08 +00:00
|
|
|
_hashtagResults.reserve(qMin(recent.size(), kHashtagResultsLimit));
|
|
|
|
for (auto i = recent.cbegin(), e = recent.cend(); i != e; ++i) {
|
2015-06-15 17:19:24 +00:00
|
|
|
if (i->first.startsWith(_hashtagFilter.midRef(1), Qt::CaseInsensitive) && i->first.size() + 1 != newFilter.size()) {
|
2016-12-05 11:01:08 +00:00
|
|
|
_hashtagResults.push_back(std_::make_unique<HashtagResult>(i->first));
|
|
|
|
if (_hashtagResults.size() == kHashtagResultsLimit) break;
|
2015-03-24 10:00:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
refresh(true);
|
2016-12-05 11:01:08 +00:00
|
|
|
setMouseSelection(false, true);
|
2015-03-24 10:00:27 +00:00
|
|
|
}
|
|
|
|
|
2015-09-29 13:24:39 +00:00
|
|
|
DialogsInner::~DialogsInner() {
|
2014-07-04 11:12:54 +00:00
|
|
|
clearSearchResults();
|
|
|
|
}
|
|
|
|
|
2016-12-05 11:01:08 +00:00
|
|
|
void DialogsInner::clearSearchResults(bool clearPeerSearchResults) {
|
|
|
|
if (clearPeerSearchResults) _peerSearchResults.clear();
|
|
|
|
_searchResults.clear();
|
2015-11-18 13:11:56 +00:00
|
|
|
_searchedCount = _searchedMigratedCount = 0;
|
|
|
|
_lastSearchDate = 0;
|
|
|
|
_lastSearchPeer = 0;
|
|
|
|
_lastSearchId = _lastSearchMigratedId = 0;
|
2014-07-04 11:12:54 +00:00
|
|
|
}
|
|
|
|
|
2015-09-29 13:24:39 +00:00
|
|
|
PeerData *DialogsInner::updateFromParentDrag(QPoint globalPos) {
|
2016-12-05 11:01:08 +00:00
|
|
|
_mouseSelection = true;
|
|
|
|
updateSelected(mapFromGlobal(globalPos));
|
2015-06-24 17:24:48 +00:00
|
|
|
if (_state == DefaultState) {
|
2016-12-05 11:01:08 +00:00
|
|
|
if (_selected) return _selected->history()->peer;
|
2015-06-24 17:24:48 +00:00
|
|
|
} else if (_state == FilteredState || _state == SearchedState) {
|
2016-12-05 11:01:08 +00:00
|
|
|
if (_filteredSelected >= 0 && _filteredSelected < _filterResults.size()) {
|
|
|
|
return _filterResults[_filteredSelected]->history()->peer;
|
|
|
|
} else if (_peerSearchSelected >= 0 && _peerSearchSelected < _peerSearchResults.size()) {
|
|
|
|
return _peerSearchResults[_peerSearchSelected]->peer;
|
|
|
|
} else if (_searchedSelected >= 0 && _searchedSelected < _searchResults.size()) {
|
|
|
|
return _searchResults[_searchedSelected]->item()->history()->peer;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
void DialogsInner::setVisibleTopBottom(int visibleTop, int visibleBottom) {
|
|
|
|
_visibleAreaHeight = visibleBottom - visibleTop;
|
|
|
|
loadPeerPhotos(visibleTop);
|
|
|
|
if (visibleTop + PreloadHeightsCount * (visibleBottom - visibleTop) >= height()) {
|
|
|
|
if (_loadMoreCallback) {
|
|
|
|
_loadMoreCallback();
|
2015-06-24 17:24:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-09-29 13:24:39 +00:00
|
|
|
void DialogsInner::itemRemoved(HistoryItem *item) {
|
2015-11-18 13:11:56 +00:00
|
|
|
int wasCount = _searchResults.size();
|
2016-12-05 11:01:08 +00:00
|
|
|
for (auto i = _searchResults.begin(); i != _searchResults.end();) {
|
|
|
|
if ((*i)->item() == item) {
|
|
|
|
i = _searchResults.erase(i);
|
2015-11-18 13:11:56 +00:00
|
|
|
if (item->history()->peer == _searchInMigrated) {
|
|
|
|
if (_searchedMigratedCount > 0) --_searchedMigratedCount;
|
|
|
|
} else {
|
|
|
|
if (_searchedCount > 0) --_searchedCount;
|
|
|
|
}
|
2014-07-04 11:12:54 +00:00
|
|
|
} else {
|
|
|
|
++i;
|
|
|
|
}
|
|
|
|
}
|
2015-11-18 13:11:56 +00:00
|
|
|
if (wasCount != _searchResults.size()) {
|
2014-07-04 11:12:54 +00:00
|
|
|
refresh();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-09-29 13:24:39 +00:00
|
|
|
void DialogsInner::dialogsReceived(const QVector<MTPDialog> &added) {
|
2016-05-20 16:01:06 +00:00
|
|
|
for_const (auto &dialog, added) {
|
2016-05-31 09:46:31 +00:00
|
|
|
if (dialog.type() != mtpc_dialog) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto &d = dialog.c_dialog();
|
|
|
|
auto peerId = peerFromMTP(d.vpeer);
|
|
|
|
if (!peerId) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto history = App::historyFromDialog(peerId, d.vunread_count.v, d.vread_inbox_max_id.v, d.vread_outbox_max_id.v);
|
|
|
|
auto peer = history->peer;
|
|
|
|
if (auto channel = peer->asChannel()) {
|
|
|
|
if (d.has_pts()) {
|
|
|
|
channel->ptsReceived(d.vpts.v);
|
|
|
|
}
|
|
|
|
if (!channel->amCreator()) {
|
|
|
|
if (auto topMsg = App::histItemById(channel, d.vtop_message.v)) {
|
|
|
|
if (topMsg->date <= date(channel->date) && App::api()) {
|
|
|
|
App::api()->requestSelfParticipant(channel);
|
2015-09-21 20:57:42 +00:00
|
|
|
}
|
|
|
|
}
|
2015-09-13 08:41:27 +00:00
|
|
|
}
|
2015-09-07 07:52:37 +00:00
|
|
|
}
|
2016-05-31 09:46:31 +00:00
|
|
|
App::main()->applyNotifySetting(MTP_notifyPeer(d.vpeer), d.vnotify_settings, history);
|
2015-09-07 07:52:37 +00:00
|
|
|
|
2016-12-13 07:59:57 +00:00
|
|
|
if (!history->isPinnedDialog() && !history->lastMsgDate.isNull()) {
|
2016-05-31 09:46:31 +00:00
|
|
|
addSavedPeersAfter(history->lastMsgDate);
|
|
|
|
}
|
2016-12-05 11:01:08 +00:00
|
|
|
_contactsNoDialogs->del(peer);
|
2016-05-31 09:46:31 +00:00
|
|
|
if (peer->migrateFrom()) {
|
|
|
|
removeDialog(App::historyLoaded(peer->migrateFrom()->id));
|
|
|
|
} else if (peer->migrateTo() && peer->migrateTo()->amIn()) {
|
|
|
|
removeDialog(history);
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
2015-09-07 07:52:37 +00:00
|
|
|
|
2016-05-31 09:46:31 +00:00
|
|
|
if (d.has_draft() && d.vdraft.type() == mtpc_draftMessage) {
|
|
|
|
auto &draft = d.vdraft.c_draftMessage();
|
|
|
|
Data::applyPeerCloudDraft(peerId, draft);
|
|
|
|
}
|
|
|
|
}
|
2016-04-14 19:24:42 +00:00
|
|
|
Notify::unreadCounterUpdated();
|
2014-05-30 08:53:19 +00:00
|
|
|
refresh();
|
|
|
|
}
|
|
|
|
|
2015-09-29 13:24:39 +00:00
|
|
|
void DialogsInner::addSavedPeersAfter(const QDateTime &date) {
|
2015-08-07 12:11:50 +00:00
|
|
|
SavedPeersByTime &saved(cRefSavedPeersByTime());
|
2015-09-06 10:17:09 +00:00
|
|
|
while (!saved.isEmpty() && (date.isNull() || date < saved.lastKey())) {
|
2015-08-07 12:11:50 +00:00
|
|
|
History *history = App::history(saved.last()->id);
|
2016-02-28 11:58:30 +00:00
|
|
|
history->setChatsListDate(saved.lastKey());
|
2016-12-05 11:01:08 +00:00
|
|
|
_contactsNoDialogs->del(history->peer);
|
2015-08-07 12:11:50 +00:00
|
|
|
saved.remove(saved.lastKey(), saved.last());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-09-29 13:24:39 +00:00
|
|
|
void DialogsInner::addAllSavedPeers() {
|
2015-09-06 10:17:09 +00:00
|
|
|
addSavedPeersAfter(QDateTime());
|
|
|
|
}
|
|
|
|
|
2015-11-18 13:11:56 +00:00
|
|
|
bool DialogsInner::searchReceived(const QVector<MTPMessage> &messages, DialogsSearchRequestType type, int32 fullCount) {
|
|
|
|
if (type == DialogsSearchFromStart || type == DialogsSearchPeerFromStart) {
|
2014-10-22 18:39:03 +00:00
|
|
|
clearSearchResults(false);
|
2014-07-04 11:12:54 +00:00
|
|
|
}
|
2016-10-22 15:58:14 +00:00
|
|
|
auto isGlobalSearch = (type == DialogsSearchFromStart || type == DialogsSearchFromOffset);
|
|
|
|
auto isMigratedSearch = (type == DialogsSearchMigratedFromStart || type == DialogsSearchMigratedFromOffset);
|
|
|
|
|
|
|
|
TimeId lastDateFound = 0;
|
|
|
|
for_const (auto message, messages) {
|
|
|
|
if (auto msgId = idFromMessage(message)) {
|
|
|
|
auto peerId = peerFromMessage(message);
|
|
|
|
auto lastDate = dateFromMessage(message);
|
|
|
|
if (auto peer = App::peerLoaded(peerId)) {
|
|
|
|
if (lastDate) {
|
|
|
|
auto item = App::histories().addNewMessage(message, NewMessageExisting);
|
2016-12-05 11:01:08 +00:00
|
|
|
_searchResults.push_back(std_::make_unique<Dialogs::FakeRow>(item));
|
2016-10-22 15:58:14 +00:00
|
|
|
lastDateFound = lastDate;
|
|
|
|
if (isGlobalSearch) {
|
|
|
|
_lastSearchDate = lastDateFound;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (isGlobalSearch) {
|
|
|
|
_lastSearchPeer = peer;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
LOG(("API Error: a search results with not loaded peer %1").arg(peerId));
|
2015-11-18 13:11:56 +00:00
|
|
|
}
|
2016-10-22 15:58:14 +00:00
|
|
|
if (isMigratedSearch) {
|
|
|
|
_lastSearchMigratedId = msgId;
|
|
|
|
} else {
|
|
|
|
_lastSearchId = msgId;
|
2016-02-14 15:58:39 +00:00
|
|
|
}
|
2015-11-18 13:11:56 +00:00
|
|
|
} else {
|
2016-10-22 15:58:14 +00:00
|
|
|
LOG(("API Error: a search results with not message id"));
|
2015-11-18 13:11:56 +00:00
|
|
|
}
|
|
|
|
}
|
2016-10-22 15:58:14 +00:00
|
|
|
if (isMigratedSearch) {
|
2015-11-18 13:11:56 +00:00
|
|
|
_searchedMigratedCount = fullCount;
|
|
|
|
} else {
|
|
|
|
_searchedCount = fullCount;
|
2014-07-04 11:12:54 +00:00
|
|
|
}
|
2015-11-18 13:11:56 +00:00
|
|
|
if (_state == FilteredState && (!_searchResults.isEmpty() || !_searchInMigrated || type == DialogsSearchMigratedFromStart || type == DialogsSearchMigratedFromOffset)) {
|
2014-07-13 09:50:38 +00:00
|
|
|
_state = SearchedState;
|
|
|
|
}
|
2014-07-04 11:12:54 +00:00
|
|
|
refresh();
|
2015-11-18 13:11:56 +00:00
|
|
|
return lastDateFound != 0;
|
2014-07-04 11:12:54 +00:00
|
|
|
}
|
|
|
|
|
2016-12-05 11:01:08 +00:00
|
|
|
void DialogsInner::peerSearchReceived(const QString &query, const QVector<MTPPeer> &result) {
|
|
|
|
_peerSearchQuery = query.toLower().trimmed();
|
|
|
|
_peerSearchResults.clear();
|
|
|
|
_peerSearchResults.reserve(result.size());
|
|
|
|
for (auto i = result.cbegin(), e = result.cend(); i != e; ++i) {
|
2016-10-22 15:58:14 +00:00
|
|
|
auto peerId = peerFromMTP(*i);
|
|
|
|
if (auto history = App::historyLoaded(peerId)) {
|
|
|
|
if (history->inChatList(Dialogs::Mode::All)) {
|
2016-02-28 11:58:30 +00:00
|
|
|
continue; // skip existing chats
|
|
|
|
}
|
|
|
|
}
|
2016-10-22 15:58:14 +00:00
|
|
|
if (auto peer = App::peerLoaded(peerId)) {
|
2016-12-05 11:01:08 +00:00
|
|
|
_peerSearchResults.push_back(std_::make_unique<PeerSearchResult>(App::peer(peerId)));
|
2016-10-22 15:58:14 +00:00
|
|
|
} else {
|
|
|
|
LOG(("API Error: user %1 was not loaded in DialogsInner::peopleReceived()").arg(peerId));
|
|
|
|
}
|
2014-10-22 18:39:03 +00:00
|
|
|
}
|
|
|
|
refresh();
|
|
|
|
}
|
|
|
|
|
2016-12-05 11:01:08 +00:00
|
|
|
void DialogsInner::contactsReceived(const QVector<MTPContact> &result) {
|
|
|
|
for_const (auto contact, result) {
|
|
|
|
if (contact.type() != mtpc_contact) continue;
|
|
|
|
|
|
|
|
auto userId = contact.c_contact().vuser_id.v;
|
|
|
|
if (userId == MTP::authedId() && App::self()) {
|
2015-12-13 11:17:15 +00:00
|
|
|
if (App::self()->contact < 1) {
|
|
|
|
App::self()->contact = 1;
|
|
|
|
Notify::userIsContactChanged(App::self());
|
|
|
|
}
|
2015-04-02 10:33:19 +00:00
|
|
|
}
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
refresh();
|
|
|
|
}
|
|
|
|
|
2015-12-13 11:17:15 +00:00
|
|
|
void DialogsInner::notify_userIsContactChanged(UserData *user, bool fromThisApp) {
|
2016-10-22 15:58:14 +00:00
|
|
|
if (user->loadedStatus != PeerData::FullLoaded) {
|
|
|
|
LOG(("API Error: notify_userIsContactChanged() called for a not loaded user!"));
|
|
|
|
return;
|
|
|
|
}
|
2015-12-13 11:17:15 +00:00
|
|
|
if (user->contact > 0) {
|
2016-10-22 15:58:14 +00:00
|
|
|
auto history = App::history(user->id);
|
2016-12-05 11:01:08 +00:00
|
|
|
_contacts->addByName(history);
|
2016-04-11 10:59:01 +00:00
|
|
|
if (auto row = shownDialogs()->getRow(user->id)) {
|
2016-04-09 18:45:55 +00:00
|
|
|
if (fromThisApp) {
|
2016-12-05 11:01:08 +00:00
|
|
|
_selected = row;
|
|
|
|
_importantSwitchSelected = false;
|
2016-04-09 18:45:55 +00:00
|
|
|
}
|
2016-12-05 11:01:08 +00:00
|
|
|
} else if (!_dialogs->contains(user->id)) {
|
|
|
|
_contactsNoDialogs->addByName(history);
|
2015-12-13 11:17:15 +00:00
|
|
|
}
|
|
|
|
} else {
|
2016-12-05 11:01:08 +00:00
|
|
|
if (_selected && _selected->history()->peer == user) {
|
|
|
|
_selected = nullptr;
|
|
|
|
}
|
|
|
|
if (_pressed && _pressed->history()->peer == user) {
|
|
|
|
setPressed(nullptr);
|
2015-12-13 11:17:15 +00:00
|
|
|
}
|
2016-12-05 11:01:08 +00:00
|
|
|
_contactsNoDialogs->del(user);
|
|
|
|
_contacts->del(user);
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
2015-12-13 11:17:15 +00:00
|
|
|
refresh();
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
|
2016-04-11 10:59:01 +00:00
|
|
|
void DialogsInner::notify_historyMuteUpdated(History *history) {
|
2016-12-05 11:01:08 +00:00
|
|
|
if (!_dialogsImportant || !history->inChatList(Dialogs::Mode::All)) return;
|
2016-04-11 10:59:01 +00:00
|
|
|
|
|
|
|
if (history->mute()) {
|
2016-12-05 11:01:08 +00:00
|
|
|
if (Global::DialogsMode() == Dialogs::Mode::Important) {
|
|
|
|
if (_selected && _selected->history() == history) {
|
|
|
|
_selected = nullptr;
|
|
|
|
}
|
|
|
|
if (_pressed && _pressed->history() == history) {
|
|
|
|
setPressed(nullptr);
|
|
|
|
}
|
2016-04-11 10:59:01 +00:00
|
|
|
}
|
2016-12-05 11:01:08 +00:00
|
|
|
history->removeFromChatList(Dialogs::Mode::Important, _dialogsImportant.get());
|
2016-04-11 10:59:01 +00:00
|
|
|
if (Global::DialogsMode() != Dialogs::Mode::Important) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
refresh();
|
|
|
|
} else {
|
|
|
|
bool creating = !history->inChatList(Dialogs::Mode::Important);
|
|
|
|
if (creating) {
|
2016-12-05 11:01:08 +00:00
|
|
|
history->addToChatList(Dialogs::Mode::Important, _dialogsImportant.get());
|
2016-04-11 10:59:01 +00:00
|
|
|
}
|
|
|
|
|
2016-12-05 11:01:08 +00:00
|
|
|
auto changed = history->adjustByPosInChatList(Dialogs::Mode::All, _dialogs.get());
|
2016-04-11 10:59:01 +00:00
|
|
|
|
|
|
|
if (Global::DialogsMode() != Dialogs::Mode::Important) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-06-07 19:59:39 +00:00
|
|
|
int from = dialogsOffset() + changed.movedFrom * st::dialogsRowHeight;
|
|
|
|
int to = dialogsOffset() + changed.movedTo * st::dialogsRowHeight;
|
2016-04-11 11:14:54 +00:00
|
|
|
emit dialogMoved(from, to);
|
2016-04-11 10:59:01 +00:00
|
|
|
|
|
|
|
if (creating) {
|
|
|
|
refresh();
|
2016-04-11 11:14:54 +00:00
|
|
|
} else if (_state == DefaultState && changed.movedFrom != changed.movedTo) {
|
2016-12-05 11:01:08 +00:00
|
|
|
update(0, qMin(from, to), getFullWidth(), qAbs(from - to) + st::dialogsRowHeight);
|
2016-04-11 10:59:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-09-29 13:24:39 +00:00
|
|
|
void DialogsInner::refresh(bool toTop) {
|
2014-07-13 09:50:38 +00:00
|
|
|
int32 h = 0;
|
2014-07-04 11:12:54 +00:00
|
|
|
if (_state == DefaultState) {
|
2016-04-11 10:59:01 +00:00
|
|
|
if (shownDialogs()->isEmpty()) {
|
2014-11-25 12:15:29 +00:00
|
|
|
h = st::noContactsHeight;
|
|
|
|
if (cContactsReceived()) {
|
2016-11-11 13:46:04 +00:00
|
|
|
if (_addContactLnk->isHidden()) _addContactLnk->show();
|
2014-11-25 12:15:29 +00:00
|
|
|
} else {
|
2016-11-11 13:46:04 +00:00
|
|
|
if (!_addContactLnk->isHidden()) _addContactLnk->hide();
|
2014-11-25 12:15:29 +00:00
|
|
|
}
|
2016-04-11 10:59:01 +00:00
|
|
|
} else {
|
2016-06-07 19:59:39 +00:00
|
|
|
h = dialogsOffset() + shownDialogs()->size() * st::dialogsRowHeight;
|
2016-11-11 13:46:04 +00:00
|
|
|
if (!_addContactLnk->isHidden()) _addContactLnk->hide();
|
2014-11-25 12:15:29 +00:00
|
|
|
}
|
|
|
|
} else {
|
2016-11-11 13:46:04 +00:00
|
|
|
if (!_addContactLnk->isHidden()) _addContactLnk->hide();
|
2014-11-25 12:15:29 +00:00
|
|
|
if (_state == FilteredState) {
|
2016-12-05 11:01:08 +00:00
|
|
|
h = searchedOffset() + (_searchResults.size() * st::dialogsRowHeight) + ((_searchResults.isEmpty() && !_searchInPeer) ? -st::searchedBarHeight : 0);
|
2014-11-25 12:15:29 +00:00
|
|
|
} else if (_state == SearchedState) {
|
2016-12-05 11:01:08 +00:00
|
|
|
h = searchedOffset() + (_searchResults.size() * st::dialogsRowHeight);
|
2014-11-25 12:15:29 +00:00
|
|
|
}
|
2014-07-04 11:12:54 +00:00
|
|
|
}
|
2015-10-01 14:05:05 +00:00
|
|
|
setHeight(h);
|
2014-05-30 08:53:19 +00:00
|
|
|
if (toTop) {
|
|
|
|
emit mustScrollTo(0, 0);
|
|
|
|
loadPeerPhotos(0);
|
|
|
|
}
|
2017-01-14 18:50:16 +00:00
|
|
|
Global::RefDialogsListDisplayForced().set(_searchInPeer || !_filter.isEmpty(), true);
|
2015-09-29 13:24:39 +00:00
|
|
|
update();
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
|
2016-12-05 11:01:08 +00:00
|
|
|
void DialogsInner::setMouseSelection(bool mouseSelection, bool toTop) {
|
|
|
|
_mouseSelection = mouseSelection;
|
|
|
|
if (!_mouseSelection && toTop) {
|
2014-07-04 11:12:54 +00:00
|
|
|
if (_state == DefaultState) {
|
2016-12-05 11:01:08 +00:00
|
|
|
_selected = nullptr;
|
|
|
|
_importantSwitchSelected = false;
|
2014-07-13 09:50:38 +00:00
|
|
|
} else if (_state == FilteredState || _state == SearchedState) { // don't select first elem in search
|
2016-12-05 11:01:08 +00:00
|
|
|
_filteredSelected = _peerSearchSelected = _searchedSelected = _hashtagSelected = -1;
|
2015-08-03 10:22:05 +00:00
|
|
|
setCursor(style::cur_default);
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-09-29 13:24:39 +00:00
|
|
|
void DialogsInner::setState(State newState) {
|
2014-07-04 11:12:54 +00:00
|
|
|
_state = newState;
|
2016-12-05 11:01:08 +00:00
|
|
|
clearIrrelevantState();
|
2014-07-13 09:50:38 +00:00
|
|
|
if (_state == DefaultState) {
|
2014-07-04 11:12:54 +00:00
|
|
|
clearSearchResults();
|
2016-12-05 11:01:08 +00:00
|
|
|
} else if (_state == FilteredState || _state == SearchedState) {
|
2015-11-18 13:11:56 +00:00
|
|
|
_hashtagResults.clear();
|
2016-12-05 11:01:08 +00:00
|
|
|
_hashtagSelected = -1;
|
2015-11-18 13:11:56 +00:00
|
|
|
_filterResults.clear();
|
2016-12-05 11:01:08 +00:00
|
|
|
_filteredSelected = -1;
|
2014-07-04 11:12:54 +00:00
|
|
|
}
|
2015-11-18 13:11:56 +00:00
|
|
|
onFilterUpdate(_filter, true);
|
2014-07-04 11:12:54 +00:00
|
|
|
}
|
|
|
|
|
2015-09-29 13:24:39 +00:00
|
|
|
DialogsInner::State DialogsInner::state() const {
|
2014-07-04 11:12:54 +00:00
|
|
|
return _state;
|
|
|
|
}
|
|
|
|
|
2015-09-29 13:24:39 +00:00
|
|
|
bool DialogsInner::hasFilteredResults() const {
|
2015-11-18 13:11:56 +00:00
|
|
|
return !_filterResults.isEmpty() && _hashtagResults.isEmpty();
|
2015-02-09 23:19:48 +00:00
|
|
|
}
|
|
|
|
|
2015-09-29 13:24:39 +00:00
|
|
|
void DialogsInner::searchInPeer(PeerData *peer) {
|
2016-11-16 12:06:02 +00:00
|
|
|
_searchInPeer = peer ? (peer->migrateTo() ? peer->migrateTo() : peer) : nullptr;
|
|
|
|
_searchInMigrated = _searchInPeer ? _searchInPeer->migrateFrom() : nullptr;
|
2015-08-04 15:01:47 +00:00
|
|
|
if (_searchInPeer) {
|
|
|
|
onHashtagFilterUpdate(QStringRef());
|
2016-10-27 21:19:38 +00:00
|
|
|
_cancelSearchInPeer->show();
|
2015-08-04 15:01:47 +00:00
|
|
|
} else {
|
2016-10-27 21:19:38 +00:00
|
|
|
_cancelSearchInPeer->hide();
|
2015-08-04 15:01:47 +00:00
|
|
|
}
|
2017-01-14 18:50:16 +00:00
|
|
|
Global::RefDialogsListDisplayForced().set(_searchInPeer || !_filter.isEmpty(), true);
|
2015-08-04 15:01:47 +00:00
|
|
|
}
|
|
|
|
|
2015-09-29 13:24:39 +00:00
|
|
|
void DialogsInner::clearFilter() {
|
2014-07-13 09:50:38 +00:00
|
|
|
if (_state == FilteredState || _state == SearchedState) {
|
2015-08-04 15:01:47 +00:00
|
|
|
if (_searchInPeer) {
|
|
|
|
_state = FilteredState;
|
|
|
|
} else {
|
|
|
|
_state = DefaultState;
|
|
|
|
}
|
2015-11-18 13:11:56 +00:00
|
|
|
_hashtagResults.clear();
|
|
|
|
_filterResults.clear();
|
2016-12-05 11:01:08 +00:00
|
|
|
_peerSearchResults.clear();
|
2015-11-18 13:11:56 +00:00
|
|
|
_searchResults.clear();
|
|
|
|
_lastSearchDate = 0;
|
|
|
|
_lastSearchPeer = 0;
|
|
|
|
_lastSearchId = _lastSearchMigratedId = 0;
|
|
|
|
_filter = QString();
|
2014-05-30 08:53:19 +00:00
|
|
|
refresh(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-09-29 13:24:39 +00:00
|
|
|
void DialogsInner::selectSkip(int32 direction) {
|
2014-07-04 11:12:54 +00:00
|
|
|
if (_state == DefaultState) {
|
2016-12-05 11:01:08 +00:00
|
|
|
if (_importantSwitchSelected) {
|
2016-04-11 10:59:01 +00:00
|
|
|
if (!shownDialogs()->isEmpty() && direction > 0) {
|
2016-12-05 11:01:08 +00:00
|
|
|
_selected = *shownDialogs()->cbegin();
|
|
|
|
_importantSwitchSelected = false;
|
2016-04-11 10:59:01 +00:00
|
|
|
} else {
|
|
|
|
return;
|
|
|
|
}
|
2016-12-05 11:01:08 +00:00
|
|
|
} else if (!_selected) {
|
|
|
|
if (_dialogsImportant) {
|
|
|
|
_importantSwitchSelected = true;
|
2016-04-11 10:59:01 +00:00
|
|
|
} else if (!shownDialogs()->isEmpty() && direction > 0) {
|
2016-12-05 11:01:08 +00:00
|
|
|
_selected = *shownDialogs()->cbegin();
|
2014-05-30 08:53:19 +00:00
|
|
|
} else {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
} else if (direction > 0) {
|
2016-12-05 11:01:08 +00:00
|
|
|
auto next = shownDialogs()->cfind(_selected);
|
2016-04-11 10:59:01 +00:00
|
|
|
if (++next != shownDialogs()->cend()) {
|
2016-12-05 11:01:08 +00:00
|
|
|
_selected = *next;
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
} else {
|
2016-12-05 11:01:08 +00:00
|
|
|
auto prev = shownDialogs()->cfind(_selected);
|
2016-04-11 10:59:01 +00:00
|
|
|
if (prev != shownDialogs()->cbegin()) {
|
2016-12-05 11:01:08 +00:00
|
|
|
_selected = *(--prev);
|
|
|
|
} else if (_dialogsImportant) {
|
|
|
|
_importantSwitchSelected = true;
|
|
|
|
_selected = nullptr;
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
}
|
2016-12-05 11:01:08 +00:00
|
|
|
if (_importantSwitchSelected || _selected) {
|
|
|
|
int fromY = _importantSwitchSelected ? 0 : (dialogsOffset() + _selected->pos() * st::dialogsRowHeight);
|
2016-06-07 19:59:39 +00:00
|
|
|
emit mustScrollTo(fromY, fromY + st::dialogsRowHeight);
|
2016-04-11 10:59:01 +00:00
|
|
|
}
|
2014-07-13 09:50:38 +00:00
|
|
|
} else if (_state == FilteredState || _state == SearchedState) {
|
2016-12-05 11:01:08 +00:00
|
|
|
if (_hashtagResults.isEmpty() && _filterResults.isEmpty() && _peerSearchResults.isEmpty() && _searchResults.isEmpty()) return;
|
|
|
|
if ((_hashtagSelected < 0 || _hashtagSelected >= _hashtagResults.size()) &&
|
|
|
|
(_filteredSelected < 0 || _filteredSelected >= _filterResults.size()) &&
|
|
|
|
(_peerSearchSelected < 0 || _peerSearchSelected >= _peerSearchResults.size()) &&
|
|
|
|
(_searchedSelected < 0 || _searchedSelected >= _searchResults.size())) {
|
|
|
|
if (_hashtagResults.isEmpty() && _filterResults.isEmpty() && _peerSearchResults.isEmpty()) {
|
|
|
|
_searchedSelected = 0;
|
2015-11-18 13:11:56 +00:00
|
|
|
} else if (_hashtagResults.isEmpty() && _filterResults.isEmpty()) {
|
2016-12-05 11:01:08 +00:00
|
|
|
_peerSearchSelected = 0;
|
2015-11-18 13:11:56 +00:00
|
|
|
} else if (_hashtagResults.isEmpty()) {
|
2016-12-05 11:01:08 +00:00
|
|
|
_filteredSelected = 0;
|
2015-03-24 10:00:27 +00:00
|
|
|
} else {
|
2016-12-05 11:01:08 +00:00
|
|
|
_hashtagSelected = 0;
|
2014-07-13 09:50:38 +00:00
|
|
|
}
|
|
|
|
} else {
|
2016-12-05 11:01:08 +00:00
|
|
|
int32 cur = (_hashtagSelected >= 0 && _hashtagSelected < _hashtagResults.size()) ? _hashtagSelected : ((_filteredSelected >= 0 && _filteredSelected < _filterResults.size()) ? (_hashtagResults.size() + _filteredSelected) : ((_peerSearchSelected >= 0 && _peerSearchSelected < _peerSearchResults.size()) ? (_peerSearchSelected + _filterResults.size() + _hashtagResults.size()) : (_searchedSelected + _peerSearchResults.size() + _filterResults.size() + _hashtagResults.size())));
|
|
|
|
cur = snap(cur + direction, 0, _hashtagResults.size() + _filterResults.size() + _peerSearchResults.size() + _searchResults.size() - 1);
|
2015-11-18 13:11:56 +00:00
|
|
|
if (cur < _hashtagResults.size()) {
|
2016-12-05 11:01:08 +00:00
|
|
|
_hashtagSelected = cur;
|
|
|
|
_filteredSelected = _peerSearchSelected = _searchedSelected = -1;
|
2015-11-18 13:11:56 +00:00
|
|
|
} else if (cur < _hashtagResults.size() + _filterResults.size()) {
|
2016-12-05 11:01:08 +00:00
|
|
|
_filteredSelected = cur - _hashtagResults.size();
|
|
|
|
_hashtagSelected = _peerSearchSelected = _searchedSelected = -1;
|
|
|
|
} else if (cur < _hashtagResults.size() + _filterResults.size() + _peerSearchResults.size()) {
|
|
|
|
_peerSearchSelected = cur - _hashtagResults.size() - _filterResults.size();
|
|
|
|
_hashtagSelected = _filteredSelected = _searchedSelected = -1;
|
2014-10-22 18:39:03 +00:00
|
|
|
} else {
|
2016-12-05 11:01:08 +00:00
|
|
|
_hashtagSelected = _filteredSelected = _peerSearchSelected = -1;
|
|
|
|
_searchedSelected = cur - _hashtagResults.size() - _filterResults.size() - _peerSearchResults.size();
|
2014-07-13 09:50:38 +00:00
|
|
|
}
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
2016-12-05 11:01:08 +00:00
|
|
|
if (_hashtagSelected >= 0 && _hashtagSelected < _hashtagResults.size()) {
|
|
|
|
emit mustScrollTo(_hashtagSelected * st::mentionHeight, (_hashtagSelected + 1) * st::mentionHeight);
|
|
|
|
} else if (_filteredSelected >= 0 && _filteredSelected < _filterResults.size()) {
|
|
|
|
emit mustScrollTo(filteredOffset() + _filteredSelected * st::dialogsRowHeight, filteredOffset() + (_filteredSelected + 1) * st::dialogsRowHeight);
|
|
|
|
} else if (_peerSearchSelected >= 0 && _peerSearchSelected < _peerSearchResults.size()) {
|
|
|
|
emit mustScrollTo(peerSearchOffset() + _peerSearchSelected * st::dialogsRowHeight + (_peerSearchSelected ? 0 : -st::searchedBarHeight), peerSearchOffset() + (_peerSearchSelected + 1) * st::dialogsRowHeight);
|
2014-07-13 09:50:38 +00:00
|
|
|
} else {
|
2016-12-05 11:01:08 +00:00
|
|
|
emit mustScrollTo(searchedOffset() + _searchedSelected * st::dialogsRowHeight + (_searchedSelected ? 0 : -st::searchedBarHeight), searchedOffset() + (_searchedSelected + 1) * st::dialogsRowHeight);
|
2014-07-04 11:12:54 +00:00
|
|
|
}
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
2015-09-29 13:24:39 +00:00
|
|
|
update();
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
|
2015-09-29 13:24:39 +00:00
|
|
|
void DialogsInner::scrollToPeer(const PeerId &peer, MsgId msgId) {
|
2014-05-30 08:53:19 +00:00
|
|
|
int32 fromY = -1;
|
2014-07-04 11:12:54 +00:00
|
|
|
if (_state == DefaultState) {
|
2016-04-11 10:59:01 +00:00
|
|
|
if (auto row = shownDialogs()->getRow(peer)) {
|
2016-06-07 19:59:39 +00:00
|
|
|
fromY = dialogsOffset() + row->pos() * st::dialogsRowHeight;
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
2014-08-22 07:41:39 +00:00
|
|
|
} else if (_state == FilteredState || _state == SearchedState) {
|
|
|
|
if (msgId) {
|
2015-11-18 13:11:56 +00:00
|
|
|
for (int32 i = 0, c = _searchResults.size(); i < c; ++i) {
|
2016-04-09 18:45:55 +00:00
|
|
|
if (_searchResults[i]->item()->history()->peer->id == peer && _searchResults[i]->item()->id == msgId) {
|
2016-06-07 19:59:39 +00:00
|
|
|
fromY = searchedOffset() + i * st::dialogsRowHeight;
|
2014-08-22 07:41:39 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (fromY < 0) {
|
2015-11-18 13:11:56 +00:00
|
|
|
for (int32 i = 0, c = _filterResults.size(); i < c; ++i) {
|
2016-04-09 18:45:55 +00:00
|
|
|
if (_filterResults[i]->history()->peer->id == peer) {
|
2016-06-07 19:59:39 +00:00
|
|
|
fromY = filteredOffset() + (i * st::dialogsRowHeight);
|
2014-08-22 07:41:39 +00:00
|
|
|
break;
|
|
|
|
}
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (fromY >= 0) {
|
2016-06-07 19:59:39 +00:00
|
|
|
emit mustScrollTo(fromY, fromY + st::dialogsRowHeight);
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-09-29 13:24:39 +00:00
|
|
|
void DialogsInner::selectSkipPage(int32 pixels, int32 direction) {
|
2016-06-07 19:59:39 +00:00
|
|
|
int toSkip = pixels / int(st::dialogsRowHeight);
|
2014-07-04 11:12:54 +00:00
|
|
|
if (_state == DefaultState) {
|
2016-12-05 11:01:08 +00:00
|
|
|
if (!_selected) {
|
2016-04-11 10:59:01 +00:00
|
|
|
if (direction > 0 && !shownDialogs()->isEmpty()) {
|
2016-12-05 11:01:08 +00:00
|
|
|
_selected = *shownDialogs()->cbegin();
|
|
|
|
_importantSwitchSelected = false;
|
2014-05-30 08:53:19 +00:00
|
|
|
} else {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (direction > 0) {
|
2016-12-05 11:01:08 +00:00
|
|
|
for (auto i = shownDialogs()->cfind(_selected), end = shownDialogs()->cend(); i != end && (toSkip--); ++i) {
|
|
|
|
_selected = *i;
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
} else {
|
2016-12-05 11:01:08 +00:00
|
|
|
for (auto i = shownDialogs()->cfind(_selected), b = shownDialogs()->cbegin(); i != b && (toSkip--);) {
|
|
|
|
_selected = *(--i);
|
2016-04-11 10:59:01 +00:00
|
|
|
}
|
2016-12-05 11:01:08 +00:00
|
|
|
if (toSkip && _dialogsImportant) {
|
|
|
|
_importantSwitchSelected = true;
|
|
|
|
_selected = nullptr;
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
}
|
2016-12-05 11:01:08 +00:00
|
|
|
if (_importantSwitchSelected || _selected) {
|
|
|
|
int fromY = (_importantSwitchSelected ? 0 : (dialogsOffset() + _selected->pos() * st::dialogsRowHeight));
|
2016-06-07 19:59:39 +00:00
|
|
|
emit mustScrollTo(fromY, fromY + st::dialogsRowHeight);
|
2016-04-11 10:59:01 +00:00
|
|
|
}
|
2014-05-30 08:53:19 +00:00
|
|
|
} else {
|
|
|
|
return selectSkip(direction * toSkip);
|
|
|
|
}
|
2015-09-29 13:24:39 +00:00
|
|
|
update();
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
|
2016-12-05 11:01:08 +00:00
|
|
|
void DialogsInner::loadPeerPhotos(int visibleTop) {
|
2016-02-17 17:14:09 +00:00
|
|
|
if (!parentWidget()) return;
|
|
|
|
|
2016-12-05 11:01:08 +00:00
|
|
|
auto yFrom = visibleTop;
|
|
|
|
auto yTo = visibleTop + _visibleAreaHeight * (PreloadHeightsCount + 1);
|
2014-05-30 08:53:19 +00:00
|
|
|
MTP::clearLoaderPriorities();
|
2014-07-04 11:12:54 +00:00
|
|
|
if (_state == DefaultState) {
|
2016-12-05 11:01:08 +00:00
|
|
|
auto otherStart = shownDialogs()->size() * st::dialogsRowHeight;
|
2014-05-30 08:53:19 +00:00
|
|
|
if (yFrom < otherStart) {
|
2016-06-07 19:59:39 +00:00
|
|
|
for (auto i = shownDialogs()->cfind(yFrom, st::dialogsRowHeight), end = shownDialogs()->cend(); i != end; ++i) {
|
|
|
|
if (((*i)->pos() * st::dialogsRowHeight) >= yTo) {
|
2016-04-09 18:45:55 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
(*i)->history()->peer->loadUserpic();
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
yFrom = 0;
|
|
|
|
} else {
|
|
|
|
yFrom -= otherStart;
|
|
|
|
}
|
|
|
|
yTo -= otherStart;
|
2014-07-13 09:50:38 +00:00
|
|
|
} else if (_state == FilteredState || _state == SearchedState) {
|
2016-06-07 19:59:39 +00:00
|
|
|
int32 from = (yFrom - filteredOffset()) / st::dialogsRowHeight;
|
2014-05-30 08:53:19 +00:00
|
|
|
if (from < 0) from = 0;
|
2015-11-18 13:11:56 +00:00
|
|
|
if (from < _filterResults.size()) {
|
2016-06-07 19:59:39 +00:00
|
|
|
int32 to = (yTo / int32(st::dialogsRowHeight)) + 1, w = width();
|
2015-11-18 13:11:56 +00:00
|
|
|
if (to > _filterResults.size()) to = _filterResults.size();
|
2016-01-01 14:48:32 +00:00
|
|
|
|
2014-05-30 08:53:19 +00:00
|
|
|
for (; from < to; ++from) {
|
2016-04-09 18:45:55 +00:00
|
|
|
_filterResults[from]->history()->peer->loadUserpic();
|
2014-07-04 11:12:54 +00:00
|
|
|
}
|
|
|
|
}
|
2014-07-13 09:50:38 +00:00
|
|
|
|
2016-06-07 19:59:39 +00:00
|
|
|
from = (yFrom > filteredOffset() + st::searchedBarHeight ? ((yFrom - filteredOffset() - st::searchedBarHeight) / int32(st::dialogsRowHeight)) : 0) - _filterResults.size();
|
2014-07-04 11:12:54 +00:00
|
|
|
if (from < 0) from = 0;
|
2016-12-05 11:01:08 +00:00
|
|
|
if (from < _peerSearchResults.size()) {
|
2016-06-07 19:59:39 +00:00
|
|
|
int32 to = (yTo > filteredOffset() + st::searchedBarHeight ? ((yTo - filteredOffset() - st::searchedBarHeight) / int32(st::dialogsRowHeight)) : 0) - _filterResults.size() + 1, w = width();
|
2016-12-05 11:01:08 +00:00
|
|
|
if (to > _peerSearchResults.size()) to = _peerSearchResults.size();
|
2014-10-22 18:39:03 +00:00
|
|
|
|
|
|
|
for (; from < to; ++from) {
|
2016-12-05 11:01:08 +00:00
|
|
|
_peerSearchResults[from]->peer->loadUserpic();
|
2014-10-22 18:39:03 +00:00
|
|
|
}
|
|
|
|
}
|
2016-12-05 11:01:08 +00:00
|
|
|
from = (yFrom > filteredOffset() + ((_peerSearchResults.isEmpty() ? 0 : st::searchedBarHeight) + st::searchedBarHeight) ? ((yFrom - filteredOffset() - (_peerSearchResults.isEmpty() ? 0 : st::searchedBarHeight) - st::searchedBarHeight) / int32(st::dialogsRowHeight)) : 0) - _filterResults.size() - _peerSearchResults.size();
|
2014-10-22 18:39:03 +00:00
|
|
|
if (from < 0) from = 0;
|
2015-11-18 13:11:56 +00:00
|
|
|
if (from < _searchResults.size()) {
|
2016-12-05 11:01:08 +00:00
|
|
|
int32 to = (yTo > filteredOffset() + (_peerSearchResults.isEmpty() ? 0 : st::searchedBarHeight) + st::searchedBarHeight ? ((yTo - filteredOffset() - (_peerSearchResults.isEmpty() ? 0 : st::searchedBarHeight) - st::searchedBarHeight) / int32(st::dialogsRowHeight)) : 0) - _filterResults.size() - _peerSearchResults.size() + 1, w = width();
|
2015-11-18 13:11:56 +00:00
|
|
|
if (to > _searchResults.size()) to = _searchResults.size();
|
2014-07-04 11:12:54 +00:00
|
|
|
|
|
|
|
for (; from < to; ++from) {
|
2016-04-09 18:45:55 +00:00
|
|
|
_searchResults[from]->item()->history()->peer->loadUserpic();
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-09-29 13:24:39 +00:00
|
|
|
bool DialogsInner::choosePeer() {
|
2016-04-11 10:59:01 +00:00
|
|
|
History *history = nullptr;
|
2015-07-17 19:17:37 +00:00
|
|
|
MsgId msgId = ShowAtUnreadMsgId;
|
2014-07-04 11:12:54 +00:00
|
|
|
if (_state == DefaultState) {
|
2016-12-05 11:01:08 +00:00
|
|
|
if (_importantSwitchSelected && _dialogsImportant) {
|
2016-04-11 10:59:01 +00:00
|
|
|
clearSelection();
|
|
|
|
if (Global::DialogsMode() == Dialogs::Mode::All) {
|
|
|
|
Global::SetDialogsMode(Dialogs::Mode::Important);
|
|
|
|
} else {
|
|
|
|
Global::SetDialogsMode(Dialogs::Mode::All);
|
|
|
|
}
|
|
|
|
Local::writeUserSettings();
|
|
|
|
refresh();
|
2016-12-05 11:01:08 +00:00
|
|
|
_importantSwitchSelected = true;
|
2016-04-11 10:59:01 +00:00
|
|
|
return true;
|
2016-12-05 11:01:08 +00:00
|
|
|
} else if (_selected) {
|
|
|
|
history = _selected->history();
|
2016-04-11 10:59:01 +00:00
|
|
|
}
|
2014-07-13 09:50:38 +00:00
|
|
|
} else if (_state == FilteredState || _state == SearchedState) {
|
2016-12-05 11:01:08 +00:00
|
|
|
if (_hashtagSelected >= 0 && _hashtagSelected < _hashtagResults.size()) {
|
|
|
|
auto &hashtag = _hashtagResults[_hashtagSelected];
|
|
|
|
if (_hashtagDeleteSelected) {
|
2015-03-24 15:18:20 +00:00
|
|
|
RecentHashtagPack recent(cRecentSearchHashtags());
|
|
|
|
for (RecentHashtagPack::iterator i = recent.begin(); i != recent.cend();) {
|
2016-12-05 11:01:08 +00:00
|
|
|
if (i->first == hashtag->tag) {
|
2015-03-24 15:18:20 +00:00
|
|
|
i = recent.erase(i);
|
|
|
|
} else {
|
|
|
|
++i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
cSetRecentSearchHashtags(recent);
|
2016-01-01 14:48:32 +00:00
|
|
|
Local::writeRecentHashtagsAndBots();
|
2015-03-24 15:18:20 +00:00
|
|
|
emit refreshHashtags();
|
|
|
|
|
2016-12-05 11:01:08 +00:00
|
|
|
_mouseSelection = true;
|
|
|
|
updateSelected();
|
2015-03-24 15:18:20 +00:00
|
|
|
} else {
|
2016-12-05 11:01:08 +00:00
|
|
|
saveRecentHashtags('#' + hashtag->tag);
|
|
|
|
emit completeHashtag(hashtag->tag);
|
2015-03-24 15:18:20 +00:00
|
|
|
}
|
2015-03-24 10:00:27 +00:00
|
|
|
return true;
|
|
|
|
}
|
2016-12-05 11:01:08 +00:00
|
|
|
if (_filteredSelected >= 0 && _filteredSelected < _filterResults.size()) {
|
|
|
|
history = _filterResults[_filteredSelected]->history();
|
|
|
|
} else if (_peerSearchSelected >= 0 && _peerSearchSelected < _peerSearchResults.size()) {
|
|
|
|
history = App::history(_peerSearchResults[_peerSearchSelected]->peer->id);
|
|
|
|
} else if (_searchedSelected >= 0 && _searchedSelected < _searchResults.size()) {
|
|
|
|
history = _searchResults[_searchedSelected]->item()->history();
|
|
|
|
msgId = _searchResults[_searchedSelected]->item()->id;
|
2014-07-04 11:12:54 +00:00
|
|
|
}
|
|
|
|
}
|
2014-05-30 08:53:19 +00:00
|
|
|
if (history) {
|
2015-07-17 19:17:37 +00:00
|
|
|
if (msgId > 0) {
|
2015-11-18 13:11:56 +00:00
|
|
|
saveRecentHashtags(_filter);
|
2015-03-24 10:00:27 +00:00
|
|
|
}
|
2016-12-05 11:01:08 +00:00
|
|
|
bool chosen = (!App::main()->selectingPeer(true) && (_state == FilteredState || _state == SearchedState) && _filteredSelected >= 0 && _filteredSelected < _filterResults.size());
|
2015-07-17 19:17:37 +00:00
|
|
|
App::main()->choosePeer(history->peer->id, msgId);
|
2014-10-22 18:39:03 +00:00
|
|
|
if (chosen) {
|
|
|
|
emit searchResultChosen();
|
|
|
|
}
|
2015-09-29 13:24:39 +00:00
|
|
|
updateSelectedRow();
|
2016-12-05 11:01:08 +00:00
|
|
|
_selected = nullptr;
|
|
|
|
_hashtagSelected = _filteredSelected = _peerSearchSelected = _searchedSelected = -1;
|
2014-07-04 11:12:54 +00:00
|
|
|
return true;
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
2014-07-04 11:12:54 +00:00
|
|
|
return false;
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
|
2015-09-29 13:24:39 +00:00
|
|
|
void DialogsInner::saveRecentHashtags(const QString &text) {
|
2015-03-24 10:00:27 +00:00
|
|
|
bool found = false;
|
|
|
|
QRegularExpressionMatch m;
|
|
|
|
RecentHashtagPack recent(cRecentSearchHashtags());
|
|
|
|
for (int32 i = 0, next = 0; (m = reHashtag().match(text, i)).hasMatch(); i = next) {
|
|
|
|
i = m.capturedStart();
|
|
|
|
next = m.capturedEnd();
|
|
|
|
if (m.hasMatch()) {
|
|
|
|
if (!m.capturedRef(1).isEmpty()) {
|
|
|
|
++i;
|
|
|
|
}
|
|
|
|
if (!m.capturedRef(2).isEmpty()) {
|
|
|
|
--next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!found && cRecentWriteHashtags().isEmpty() && cRecentSearchHashtags().isEmpty()) {
|
2016-01-01 14:48:32 +00:00
|
|
|
Local::readRecentHashtagsAndBots();
|
2015-03-24 10:00:27 +00:00
|
|
|
recent = cRecentSearchHashtags();
|
|
|
|
}
|
|
|
|
found = true;
|
|
|
|
incrementRecentHashtag(recent, text.mid(i + 1, next - i - 1));
|
|
|
|
}
|
|
|
|
if (found) {
|
|
|
|
cSetRecentSearchHashtags(recent);
|
2016-01-01 14:48:32 +00:00
|
|
|
Local::writeRecentHashtagsAndBots();
|
2015-03-24 10:00:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-09-29 13:24:39 +00:00
|
|
|
void DialogsInner::destroyData() {
|
2016-12-05 11:01:08 +00:00
|
|
|
_selected = nullptr;
|
|
|
|
_hashtagSelected = -1;
|
2015-11-18 13:11:56 +00:00
|
|
|
_hashtagResults.clear();
|
2016-12-05 11:01:08 +00:00
|
|
|
_filteredSelected = -1;
|
2015-11-18 13:11:56 +00:00
|
|
|
_filterResults.clear();
|
|
|
|
_filter.clear();
|
2016-12-05 11:01:08 +00:00
|
|
|
_searchedSelected = _peerSearchSelected = -1;
|
2014-07-04 11:12:54 +00:00
|
|
|
clearSearchResults();
|
2016-12-05 11:01:08 +00:00
|
|
|
_contacts = nullptr;
|
|
|
|
_contactsNoDialogs = nullptr;
|
|
|
|
_dialogs = nullptr;
|
|
|
|
if (_dialogsImportant) {
|
|
|
|
_dialogsImportant = nullptr;
|
2016-04-11 10:59:01 +00:00
|
|
|
}
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
|
2015-09-29 13:24:39 +00:00
|
|
|
void DialogsInner::peerBefore(const PeerData *inPeer, MsgId inMsg, PeerData *&outPeer, MsgId &outMsg) const {
|
2016-02-29 11:34:44 +00:00
|
|
|
if (!inPeer) {
|
2016-04-09 18:45:55 +00:00
|
|
|
outPeer = nullptr;
|
2016-02-29 11:34:44 +00:00
|
|
|
outMsg = 0;
|
|
|
|
return;
|
|
|
|
}
|
2014-07-04 11:12:54 +00:00
|
|
|
if (_state == DefaultState) {
|
2016-04-11 10:59:01 +00:00
|
|
|
if (auto row = shownDialogs()->getRow(inPeer->id)) {
|
|
|
|
auto i = shownDialogs()->cfind(row);
|
|
|
|
if (i != shownDialogs()->cbegin()) {
|
2016-04-09 18:45:55 +00:00
|
|
|
outPeer = (*(--i))->history()->peer;
|
2015-07-17 19:17:37 +00:00
|
|
|
outMsg = ShowAtUnreadMsgId;
|
2014-08-22 07:41:39 +00:00
|
|
|
return;
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
}
|
2016-04-09 18:45:55 +00:00
|
|
|
outPeer = nullptr;
|
|
|
|
outMsg = 0;
|
|
|
|
return;
|
2014-07-13 09:50:38 +00:00
|
|
|
} else if (_state == FilteredState || _state == SearchedState) {
|
2015-11-18 13:11:56 +00:00
|
|
|
if (inMsg && !_searchResults.isEmpty()) {
|
2016-12-05 11:01:08 +00:00
|
|
|
for (auto b = _searchResults.cbegin(), i = b + 1, e = _searchResults.cend(); i != e; ++i) {
|
2016-04-09 18:45:55 +00:00
|
|
|
if ((*i)->item()->history()->peer == inPeer && (*i)->item()->id == inMsg) {
|
2016-12-05 11:01:08 +00:00
|
|
|
auto j = i - 1;
|
2016-04-09 18:45:55 +00:00
|
|
|
outPeer = (*j)->item()->history()->peer;
|
|
|
|
outMsg = (*j)->item()->id;
|
2014-08-22 07:41:39 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2016-04-09 18:45:55 +00:00
|
|
|
if (_searchResults.at(0)->item()->history()->peer == inPeer && _searchResults.at(0)->item()->id == inMsg) {
|
2015-07-17 19:17:37 +00:00
|
|
|
outMsg = ShowAtUnreadMsgId;
|
2016-12-05 11:01:08 +00:00
|
|
|
if (_peerSearchResults.isEmpty()) {
|
2015-11-18 13:11:56 +00:00
|
|
|
if (_filterResults.isEmpty()) {
|
2016-04-09 18:45:55 +00:00
|
|
|
outPeer = nullptr;
|
2014-10-22 18:39:03 +00:00
|
|
|
} else {
|
2016-04-09 18:45:55 +00:00
|
|
|
outPeer = _filterResults.back()->history()->peer;
|
2014-10-22 18:39:03 +00:00
|
|
|
}
|
|
|
|
} else {
|
2016-12-05 11:01:08 +00:00
|
|
|
outPeer = _peerSearchResults.back()->peer;
|
2014-10-22 18:39:03 +00:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2016-12-05 11:01:08 +00:00
|
|
|
if (!_peerSearchResults.isEmpty() && _peerSearchResults[0]->peer == inPeer) {
|
2016-04-09 18:45:55 +00:00
|
|
|
outPeer = _filterResults.isEmpty() ? 0 : _filterResults.back()->history()->peer;
|
2015-07-17 19:17:37 +00:00
|
|
|
outMsg = ShowAtUnreadMsgId;
|
2014-10-22 18:39:03 +00:00
|
|
|
return;
|
|
|
|
}
|
2016-12-05 11:01:08 +00:00
|
|
|
if (!_peerSearchResults.isEmpty()) {
|
|
|
|
for (auto b = _peerSearchResults.cbegin(), i = b + 1, e = _peerSearchResults.cend(); i != e; ++i) {
|
|
|
|
if ((*i)->peer == inPeer) {
|
|
|
|
outPeer = (*(i - 1))->peer;
|
2015-07-17 19:17:37 +00:00
|
|
|
outMsg = ShowAtUnreadMsgId;
|
2014-10-22 18:39:03 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2014-08-22 07:41:39 +00:00
|
|
|
}
|
2016-04-09 18:45:55 +00:00
|
|
|
if (_filterResults.isEmpty() || _filterResults.at(0)->history()->peer == inPeer) {
|
|
|
|
outPeer = nullptr;
|
2014-08-22 07:41:39 +00:00
|
|
|
outMsg = 0;
|
|
|
|
return;
|
|
|
|
}
|
2014-07-04 11:12:54 +00:00
|
|
|
|
2016-12-05 11:01:08 +00:00
|
|
|
for (auto b = _filterResults.cbegin(), i = b + 1, e = _filterResults.cend(); i != e; ++i) {
|
2016-04-09 18:45:55 +00:00
|
|
|
if ((*i)->history()->peer == inPeer) {
|
|
|
|
outPeer = (*(i - 1))->history()->peer;
|
2015-07-17 19:17:37 +00:00
|
|
|
outMsg = ShowAtUnreadMsgId;
|
2014-08-22 07:41:39 +00:00
|
|
|
return;
|
2014-07-04 11:12:54 +00:00
|
|
|
}
|
|
|
|
}
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
2016-04-09 18:45:55 +00:00
|
|
|
outPeer = nullptr;
|
2014-08-22 07:41:39 +00:00
|
|
|
outMsg = 0;
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
|
2015-09-29 13:24:39 +00:00
|
|
|
void DialogsInner::peerAfter(const PeerData *inPeer, MsgId inMsg, PeerData *&outPeer, MsgId &outMsg) const {
|
2016-02-29 11:34:44 +00:00
|
|
|
if (!inPeer) {
|
2016-04-09 18:45:55 +00:00
|
|
|
outPeer = nullptr;
|
2016-02-29 11:34:44 +00:00
|
|
|
outMsg = 0;
|
|
|
|
return;
|
|
|
|
}
|
2014-07-04 11:12:54 +00:00
|
|
|
if (_state == DefaultState) {
|
2016-04-11 10:59:01 +00:00
|
|
|
if (auto row = shownDialogs()->getRow(inPeer->id)) {
|
|
|
|
auto i = shownDialogs()->cfind(row) + 1;
|
|
|
|
if (i != shownDialogs()->cend()) {
|
2016-04-09 18:45:55 +00:00
|
|
|
outPeer = (*i)->history()->peer;
|
|
|
|
outMsg = ShowAtUnreadMsgId;
|
|
|
|
return;
|
|
|
|
}
|
2014-07-04 11:12:54 +00:00
|
|
|
}
|
2016-04-09 18:45:55 +00:00
|
|
|
outPeer = nullptr;
|
|
|
|
outMsg = 0;
|
|
|
|
return;
|
2014-07-13 09:50:38 +00:00
|
|
|
} else if (_state == FilteredState || _state == SearchedState) {
|
2014-08-22 07:41:39 +00:00
|
|
|
if (inMsg) {
|
2016-12-05 11:01:08 +00:00
|
|
|
for (auto i = _searchResults.cbegin(), e = _searchResults.cend(); i != e; ++i) {
|
2016-04-09 18:45:55 +00:00
|
|
|
if ((*i)->item()->history()->peer == inPeer && (*i)->item()->id == inMsg) {
|
2014-08-22 07:41:39 +00:00
|
|
|
++i;
|
2016-04-09 18:45:55 +00:00
|
|
|
outPeer = (i == e) ? nullptr : (*i)->item()->history()->peer;
|
|
|
|
outMsg = (i == e) ? 0 : (*i)->item()->id;
|
2014-08-22 07:41:39 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-12-05 11:01:08 +00:00
|
|
|
for (auto i = _peerSearchResults.cbegin(), e = _peerSearchResults.cend(); i != e; ++i) {
|
|
|
|
if ((*i)->peer == inPeer) {
|
2014-10-22 18:39:03 +00:00
|
|
|
++i;
|
2015-11-18 13:11:56 +00:00
|
|
|
if (i == e && !_searchResults.isEmpty()) {
|
2016-04-09 18:45:55 +00:00
|
|
|
outPeer = _searchResults.front()->item()->history()->peer;
|
|
|
|
outMsg = _searchResults.front()->item()->id;
|
2014-10-22 18:39:03 +00:00
|
|
|
} else {
|
2016-12-05 11:01:08 +00:00
|
|
|
outPeer = (i == e) ? nullptr : (*i)->peer;
|
2015-07-17 19:17:37 +00:00
|
|
|
outMsg = ShowAtUnreadMsgId;
|
2014-10-22 18:39:03 +00:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2015-11-18 13:11:56 +00:00
|
|
|
for (FilteredDialogs::const_iterator i = _filterResults.cbegin(), e = _filterResults.cend(); i != e; ++i) {
|
2016-04-09 18:45:55 +00:00
|
|
|
if ((*i)->history()->peer == inPeer) {
|
2014-07-04 11:12:54 +00:00
|
|
|
++i;
|
2016-12-05 11:01:08 +00:00
|
|
|
if (i == e && !_peerSearchResults.isEmpty()) {
|
|
|
|
outPeer = _peerSearchResults.front()->peer;
|
2015-07-17 19:17:37 +00:00
|
|
|
outMsg = ShowAtUnreadMsgId;
|
2015-11-18 13:11:56 +00:00
|
|
|
} else if (i == e && !_searchResults.isEmpty()) {
|
2016-04-09 18:45:55 +00:00
|
|
|
outPeer = _searchResults.front()->item()->history()->peer;
|
|
|
|
outMsg = _searchResults.front()->item()->id;
|
2014-10-22 18:39:03 +00:00
|
|
|
} else {
|
2016-04-09 18:45:55 +00:00
|
|
|
outPeer = (i == e) ? nullptr : (*i)->history()->peer;
|
2015-07-17 19:17:37 +00:00
|
|
|
outMsg = ShowAtUnreadMsgId;
|
2014-10-22 18:39:03 +00:00
|
|
|
}
|
2014-08-22 07:41:39 +00:00
|
|
|
return;
|
2014-07-04 11:12:54 +00:00
|
|
|
}
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
}
|
2016-04-09 18:45:55 +00:00
|
|
|
outPeer = nullptr;
|
2014-08-22 07:41:39 +00:00
|
|
|
outMsg = 0;
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
|
2016-04-09 18:45:55 +00:00
|
|
|
Dialogs::IndexedList *DialogsInner::contactsList() {
|
2016-12-05 11:01:08 +00:00
|
|
|
return _contacts.get();
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
|
2016-04-09 18:45:55 +00:00
|
|
|
Dialogs::IndexedList *DialogsInner::dialogsList() {
|
2016-12-05 11:01:08 +00:00
|
|
|
return _dialogs.get();
|
2015-11-18 13:11:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int32 DialogsInner::lastSearchDate() const {
|
|
|
|
return _lastSearchDate;
|
|
|
|
}
|
|
|
|
|
|
|
|
PeerData *DialogsInner::lastSearchPeer() const {
|
|
|
|
return _lastSearchPeer;
|
2014-07-04 11:12:54 +00:00
|
|
|
}
|
|
|
|
|
2015-09-29 13:24:39 +00:00
|
|
|
MsgId DialogsInner::lastSearchId() const {
|
2014-08-22 07:41:39 +00:00
|
|
|
return _lastSearchId;
|
|
|
|
}
|
|
|
|
|
2015-11-18 13:11:56 +00:00
|
|
|
MsgId DialogsInner::lastSearchMigratedId() const {
|
|
|
|
return _lastSearchMigratedId;
|
|
|
|
}
|
|
|
|
|
2017-01-14 18:50:16 +00:00
|
|
|
class DialogsWidget::UpdateButton : public Ui::RippleButton {
|
|
|
|
public:
|
|
|
|
UpdateButton(QWidget *parent);
|
|
|
|
|
|
|
|
protected:
|
|
|
|
void paintEvent(QPaintEvent *e) override;
|
|
|
|
|
|
|
|
void onStateChanged(State was, StateChangeSource source) override;
|
|
|
|
|
|
|
|
private:
|
|
|
|
QString _text;
|
|
|
|
const style::FlatButton &_st;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
DialogsWidget::UpdateButton::UpdateButton(QWidget *parent) : RippleButton(parent, st::dialogsUpdateButton.ripple)
|
|
|
|
, _text(lang(lng_update_telegram).toUpper())
|
|
|
|
, _st(st::dialogsUpdateButton) {
|
|
|
|
resize(st::dialogsWidthMin, _st.height);
|
|
|
|
}
|
|
|
|
|
|
|
|
void DialogsWidget::UpdateButton::onStateChanged(State was, StateChangeSource source) {
|
|
|
|
RippleButton::onStateChanged(was, source);
|
|
|
|
update();
|
|
|
|
}
|
|
|
|
|
|
|
|
void DialogsWidget::UpdateButton::paintEvent(QPaintEvent *e) {
|
|
|
|
QPainter p(this);
|
|
|
|
|
|
|
|
QRect r(0, height() - _st.height, width(), _st.height);
|
|
|
|
p.fillRect(r, isOver() ? _st.overBgColor : _st.bgColor);
|
|
|
|
|
|
|
|
paintRipple(p, 0, 0, getms());
|
|
|
|
|
|
|
|
p.setFont(isOver() ? _st.overFont : _st.font);
|
|
|
|
p.setRenderHint(QPainter::TextAntialiasing);
|
|
|
|
p.setPen(isOver() ? _st.overColor : _st.color);
|
|
|
|
|
|
|
|
if (width() >= st::dialogsWidthMin) {
|
|
|
|
r.setTop(_st.textTop);
|
|
|
|
p.drawText(r, _text, style::al_top);
|
|
|
|
} else {
|
|
|
|
(isOver() ? st::dialogsInstallUpdateOver : st::dialogsInstallUpdate).paintInCenter(p, r);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-04 11:14:47 +00:00
|
|
|
DialogsWidget::DialogsWidget(QWidget *parent) : TWidget(parent)
|
|
|
|
, _mainMenuToggle(this, st::dialogsMenuToggle)
|
|
|
|
, _filter(this, st::dialogsFilter, lang(lng_dlg_filter))
|
2016-10-27 21:19:38 +00:00
|
|
|
, _cancelSearch(this, st::dialogsCancelSearch)
|
2016-11-04 19:50:35 +00:00
|
|
|
, _lockUnlock(this, st::dialogsLock)
|
2016-12-13 17:07:56 +00:00
|
|
|
, _scroll(this, st::dialogsScroll) {
|
|
|
|
_inner = _scroll->setOwnedWidget(object_ptr<DialogsInner>(this, parent));
|
2016-11-05 08:36:24 +00:00
|
|
|
connect(_inner, SIGNAL(mustScrollTo(int,int)), _scroll, SLOT(scrollToY(int,int)));
|
|
|
|
connect(_inner, SIGNAL(dialogMoved(int,int)), this, SLOT(onDialogMoved(int,int)));
|
|
|
|
connect(_inner, SIGNAL(searchMessages()), this, SLOT(onNeedSearchMessages()));
|
|
|
|
connect(_inner, SIGNAL(searchResultChosen()), this, SLOT(onCancel()));
|
|
|
|
connect(_inner, SIGNAL(completeHashtag(QString)), this, SLOT(onCompleteHashtag(QString)));
|
|
|
|
connect(_inner, SIGNAL(refreshHashtags()), this, SLOT(onFilterCursorMoved()));
|
|
|
|
connect(_inner, SIGNAL(cancelSearchInPeer()), this, SLOT(onCancelSearchInPeer()));
|
|
|
|
connect(_scroll, SIGNAL(geometryChanged()), _inner, SLOT(onParentGeometryChanged()));
|
|
|
|
connect(_scroll, SIGNAL(scrolled()), this, SLOT(onListScroll()));
|
2016-11-04 11:14:47 +00:00
|
|
|
connect(_filter, SIGNAL(cancelled()), this, SLOT(onCancel()));
|
|
|
|
connect(_filter, SIGNAL(changed()), this, SLOT(onFilterUpdate()));
|
|
|
|
connect(_filter, SIGNAL(cursorPositionChanged(int,int)), this, SLOT(onFilterCursorMoved(int,int)));
|
2014-07-04 11:12:54 +00:00
|
|
|
|
2016-11-05 08:36:24 +00:00
|
|
|
#ifndef TDESKTOP_DISABLE_AUTOUPDATE
|
|
|
|
Sandbox::connect(SIGNAL(updateLatest()), this, SLOT(onCheckUpdateStatus()));
|
|
|
|
Sandbox::connect(SIGNAL(updateFailed()), this, SLOT(onCheckUpdateStatus()));
|
|
|
|
Sandbox::connect(SIGNAL(updateReady()), this, SLOT(onCheckUpdateStatus()));
|
|
|
|
onCheckUpdateStatus();
|
|
|
|
#endif // !TDESKTOP_DISABLE_AUTOUPDATE
|
|
|
|
|
2016-11-06 17:23:13 +00:00
|
|
|
subscribe(Adaptive::Changed(), [this] { updateForwardBar(); });
|
|
|
|
|
2016-11-04 19:50:35 +00:00
|
|
|
_cancelSearch->setClickedCallback([this] { onCancelSearch(); });
|
|
|
|
_lockUnlock->setVisible(Global::LocalPasscode());
|
|
|
|
subscribe(Global::RefLocalPasscodeChanged(), [this] { updateLockUnlockVisibility(); });
|
|
|
|
_lockUnlock->setClickedCallback([this] {
|
2016-12-05 11:01:08 +00:00
|
|
|
_lockUnlock->setIconOverride(&st::dialogsUnlockIcon, &st::dialogsUnlockIconOver);
|
2016-11-04 19:50:35 +00:00
|
|
|
App::wnd()->setupPasscode();
|
2016-12-05 11:01:08 +00:00
|
|
|
_lockUnlock->setIconOverride(nullptr);
|
2016-11-04 19:50:35 +00:00
|
|
|
});
|
2016-11-04 11:14:47 +00:00
|
|
|
_mainMenuToggle->setClickedCallback([this] { showMainMenu(); });
|
|
|
|
|
2015-06-26 09:07:59 +00:00
|
|
|
_chooseByDragTimer.setSingleShot(true);
|
|
|
|
connect(&_chooseByDragTimer, SIGNAL(timeout()), this, SLOT(onChooseByDrag()));
|
|
|
|
|
2015-06-24 17:24:48 +00:00
|
|
|
setAcceptDrops(true);
|
|
|
|
|
2014-07-13 09:50:38 +00:00
|
|
|
_searchTimer.setSingleShot(true);
|
|
|
|
connect(&_searchTimer, SIGNAL(timeout()), this, SLOT(onSearchMessages()));
|
2014-05-30 08:53:19 +00:00
|
|
|
|
2016-12-05 11:01:08 +00:00
|
|
|
_inner->setLoadMoreCallback([this] {
|
|
|
|
if (_inner->state() == DialogsInner::SearchedState || (_inner->state() == DialogsInner::FilteredState && _searchInMigrated && _searchFull && !_searchFullMigrated)) {
|
|
|
|
onSearchMore();
|
|
|
|
} else {
|
|
|
|
loadDialogs();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2016-11-04 11:14:47 +00:00
|
|
|
_filter->setFocusPolicy(Qt::StrongFocus);
|
|
|
|
_filter->customUpDown(true);
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
|
2016-11-05 08:36:24 +00:00
|
|
|
#ifndef TDESKTOP_DISABLE_AUTOUPDATE
|
|
|
|
void DialogsWidget::onCheckUpdateStatus() {
|
|
|
|
if (Sandbox::updatingState() == Application::UpdatingReady) {
|
|
|
|
if (_updateTelegram) return;
|
2017-01-14 18:50:16 +00:00
|
|
|
_updateTelegram.create(this);
|
2016-11-05 08:36:24 +00:00
|
|
|
_updateTelegram->show();
|
|
|
|
_updateTelegram->setClickedCallback([] {
|
|
|
|
checkReadyUpdate();
|
|
|
|
App::restart();
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
if (!_updateTelegram) return;
|
|
|
|
_updateTelegram.destroy();
|
|
|
|
}
|
|
|
|
updateControlsGeometry();
|
|
|
|
}
|
|
|
|
#endif // TDESKTOP_DISABLE_AUTOUPDATE
|
|
|
|
|
2014-05-30 08:53:19 +00:00
|
|
|
void DialogsWidget::activate() {
|
2016-11-04 11:14:47 +00:00
|
|
|
_filter->setFocus();
|
2016-11-05 08:36:24 +00:00
|
|
|
_inner->activate();
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
|
2015-09-21 20:57:42 +00:00
|
|
|
void DialogsWidget::createDialog(History *history) {
|
2016-11-05 08:36:24 +00:00
|
|
|
auto creating = !history->inChatList(Dialogs::Mode::All);
|
|
|
|
_inner->createDialog(history);
|
2015-11-13 15:14:33 +00:00
|
|
|
if (creating && history->peer->migrateFrom()) {
|
2016-11-05 08:36:24 +00:00
|
|
|
if (auto migrated = App::historyLoaded(history->peer->migrateFrom()->id)) {
|
|
|
|
if (migrated->inChatList(Dialogs::Mode::All)) {
|
|
|
|
removeDialog(migrated);
|
2015-11-13 15:14:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
|
2016-04-11 10:59:01 +00:00
|
|
|
void DialogsWidget::dlgUpdated(Dialogs::Mode list, Dialogs::Row *row) {
|
2016-11-05 08:36:24 +00:00
|
|
|
_inner->dlgUpdated(list, row);
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
|
2016-12-05 11:01:08 +00:00
|
|
|
void DialogsWidget::dlgUpdated(PeerData *peer, MsgId msgId) {
|
|
|
|
_inner->dlgUpdated(peer, msgId);
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void DialogsWidget::dialogsToUp() {
|
2016-11-04 11:14:47 +00:00
|
|
|
if (_filter->getLastText().trimmed().isEmpty()) {
|
2016-11-05 08:36:24 +00:00
|
|
|
_scroll->scrollToY(0);
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-01-14 18:50:16 +00:00
|
|
|
void DialogsWidget::startWidthAnimation() {
|
|
|
|
if (!_widthAnimationCache.isNull()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
auto scrollGeometry = _scroll->geometry();
|
|
|
|
auto grabGeometry = QRect(scrollGeometry.x(), scrollGeometry.y(), st::dialogsWidthMin, scrollGeometry.height());
|
|
|
|
_scroll->setGeometry(grabGeometry);
|
|
|
|
myEnsureResized(_scroll);
|
|
|
|
_widthAnimationCache = QPixmap(grabGeometry.size() * cIntRetinaFactor());
|
|
|
|
_widthAnimationCache.setDevicePixelRatio(cRetinaFactor());
|
|
|
|
_widthAnimationCache.fill(Qt::transparent);
|
|
|
|
_scroll->render(&_widthAnimationCache, QPoint(0, 0), QRect(QPoint(0, 0), grabGeometry.size()), QWidget::DrawChildren | QWidget::IgnoreMask);
|
|
|
|
_scroll->setGeometry(scrollGeometry);
|
|
|
|
_scroll->hide();
|
|
|
|
}
|
|
|
|
|
|
|
|
void DialogsWidget::stopWidthAnimation() {
|
|
|
|
_widthAnimationCache = QPixmap();
|
|
|
|
if (!_a_show.animating()) {
|
|
|
|
_scroll->show();
|
|
|
|
}
|
|
|
|
update();
|
|
|
|
}
|
|
|
|
|
2016-11-06 17:23:13 +00:00
|
|
|
void DialogsWidget::showFast() {
|
|
|
|
show();
|
|
|
|
updateForwardBar();
|
|
|
|
}
|
|
|
|
|
2016-05-19 12:03:51 +00:00
|
|
|
void DialogsWidget::showAnimated(Window::SlideDirection direction, const Window::SectionSlideParams ¶ms) {
|
2016-12-05 11:01:08 +00:00
|
|
|
_showDirection = direction;
|
|
|
|
|
|
|
|
_a_show.finish();
|
2015-10-15 10:18:24 +00:00
|
|
|
|
2016-05-19 12:03:51 +00:00
|
|
|
_cacheUnder = params.oldContentCache;
|
|
|
|
show();
|
2016-11-06 17:23:13 +00:00
|
|
|
updateForwardBar();
|
2016-05-19 12:03:51 +00:00
|
|
|
_cacheOver = App::main()->grabForShowAnimation(params);
|
2015-10-17 14:52:26 +00:00
|
|
|
|
2016-11-05 08:36:24 +00:00
|
|
|
_scroll->hide();
|
2016-11-04 19:50:35 +00:00
|
|
|
_mainMenuToggle->hide();
|
2016-11-06 17:23:13 +00:00
|
|
|
if (_forwardCancel) _forwardCancel->hide();
|
2016-11-04 11:14:47 +00:00
|
|
|
_filter->hide();
|
2016-11-21 17:46:29 +00:00
|
|
|
_cancelSearch->hideFast();
|
2016-11-04 19:50:35 +00:00
|
|
|
_lockUnlock->hide();
|
2015-10-17 14:52:26 +00:00
|
|
|
|
2016-05-19 12:03:51 +00:00
|
|
|
int delta = st::slideShift;
|
2016-12-05 11:01:08 +00:00
|
|
|
if (_showDirection == Window::SlideDirection::FromLeft) {
|
2016-05-19 12:38:09 +00:00
|
|
|
std::swap(_cacheUnder, _cacheOver);
|
2016-05-19 12:03:51 +00:00
|
|
|
}
|
2016-12-05 11:01:08 +00:00
|
|
|
_a_show.start([this] { animationCallback(); }, 0., 1., st::slideDuration, Window::SlideAnimation::transition());
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
|
2016-12-05 11:01:08 +00:00
|
|
|
void DialogsWidget::animationCallback() {
|
|
|
|
update();
|
|
|
|
if (!_a_show.animating()) {
|
2015-10-17 14:52:26 +00:00
|
|
|
_cacheUnder = _cacheOver = QPixmap();
|
|
|
|
|
2016-11-05 08:36:24 +00:00
|
|
|
_scroll->show();
|
2016-11-04 19:50:35 +00:00
|
|
|
_mainMenuToggle->show();
|
2016-11-06 17:23:13 +00:00
|
|
|
if (_forwardCancel) _forwardCancel->show();
|
2016-11-04 11:14:47 +00:00
|
|
|
_filter->show();
|
2016-11-04 19:50:35 +00:00
|
|
|
updateLockUnlockVisibility();
|
2015-12-06 15:50:02 +00:00
|
|
|
|
|
|
|
onFilterUpdate();
|
2016-10-17 10:55:17 +00:00
|
|
|
if (App::wnd()) App::wnd()->setInnerFocus();
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void DialogsWidget::onCancel() {
|
2015-08-04 15:01:47 +00:00
|
|
|
if (!onCancelSearch() || (!_searchInPeer && !App::main()->selectingPeer())) {
|
2014-12-12 16:27:03 +00:00
|
|
|
emit cancelled();
|
|
|
|
}
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
|
2015-12-13 11:17:15 +00:00
|
|
|
void DialogsWidget::notify_userIsContactChanged(UserData *user, bool fromThisApp) {
|
|
|
|
if (fromThisApp) {
|
2016-11-04 11:14:47 +00:00
|
|
|
_filter->setText(QString());
|
|
|
|
_filter->updatePlaceholder();
|
2015-12-13 11:17:15 +00:00
|
|
|
onFilterUpdate();
|
|
|
|
}
|
2016-11-05 08:36:24 +00:00
|
|
|
_inner->notify_userIsContactChanged(user, fromThisApp);
|
2015-12-13 11:17:15 +00:00
|
|
|
}
|
|
|
|
|
2016-04-11 10:59:01 +00:00
|
|
|
void DialogsWidget::notify_historyMuteUpdated(History *history) {
|
2016-11-05 08:36:24 +00:00
|
|
|
_inner->notify_historyMuteUpdated(history);
|
2016-04-11 10:59:01 +00:00
|
|
|
}
|
|
|
|
|
2014-05-30 08:53:19 +00:00
|
|
|
void DialogsWidget::unreadCountsReceived(const QVector<MTPDialog> &dialogs) {
|
|
|
|
}
|
|
|
|
|
2016-12-13 07:59:57 +00:00
|
|
|
void DialogsWidget::dialogsReceived(const MTPmessages_Dialogs &dialogs, mtpRequestId requestId) {
|
|
|
|
if (_dialogsRequestId != requestId) return;
|
2015-11-18 14:59:17 +00:00
|
|
|
|
2016-05-31 09:46:31 +00:00
|
|
|
const QVector<MTPDialog> *dialogsList = 0;
|
|
|
|
const QVector<MTPMessage> *messagesList = 0;
|
2014-05-30 08:53:19 +00:00
|
|
|
switch (dialogs.type()) {
|
|
|
|
case mtpc_messages_dialogs: {
|
2016-12-13 07:59:57 +00:00
|
|
|
auto &data = dialogs.c_messages_dialogs();
|
2014-05-30 08:53:19 +00:00
|
|
|
App::feedUsers(data.vusers);
|
|
|
|
App::feedChats(data.vchats);
|
2016-05-31 09:46:31 +00:00
|
|
|
messagesList = &data.vmessages.c_vector().v;
|
|
|
|
dialogsList = &data.vdialogs.c_vector().v;
|
2015-11-20 18:24:44 +00:00
|
|
|
_dialogsFull = true;
|
2014-05-30 08:53:19 +00:00
|
|
|
} break;
|
|
|
|
case mtpc_messages_dialogsSlice: {
|
2016-12-13 07:59:57 +00:00
|
|
|
auto &data = dialogs.c_messages_dialogsSlice();
|
2014-05-30 08:53:19 +00:00
|
|
|
App::feedUsers(data.vusers);
|
|
|
|
App::feedChats(data.vchats);
|
2016-05-31 09:46:31 +00:00
|
|
|
messagesList = &data.vmessages.c_vector().v;
|
|
|
|
dialogsList = &data.vdialogs.c_vector().v;
|
2014-05-30 08:53:19 +00:00
|
|
|
} break;
|
|
|
|
}
|
|
|
|
|
2016-12-13 07:59:57 +00:00
|
|
|
if (!cContactsReceived() && !_contactsRequestId) {
|
|
|
|
_contactsRequestId = MTP::send(MTPcontacts_GetContacts(MTP_string("")), rpcDone(&DialogsWidget::contactsReceived), rpcFail(&DialogsWidget::contactsFailed));
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
|
2016-05-31 09:46:31 +00:00
|
|
|
if (dialogsList) {
|
|
|
|
TimeId lastDate = 0;
|
2015-11-18 14:59:17 +00:00
|
|
|
PeerId lastPeer = 0;
|
|
|
|
MsgId lastMsgId = 0;
|
2016-05-31 09:46:31 +00:00
|
|
|
for (int i = dialogsList->size(); i > 0;) {
|
|
|
|
auto &dialog = dialogsList->at(--i);
|
|
|
|
if (dialog.type() != mtpc_dialog) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2016-12-13 07:59:57 +00:00
|
|
|
auto &dialogData = dialog.c_dialog();
|
|
|
|
if (auto peer = peerFromMTP(dialogData.vpeer)) {
|
|
|
|
auto history = App::history(peer);
|
|
|
|
history->setPinnedDialog(dialogData.is_pinned());
|
|
|
|
|
|
|
|
if (!lastDate) {
|
|
|
|
if (!lastPeer) lastPeer = peer;
|
|
|
|
if (auto msgId = dialogData.vtop_message.v) {
|
|
|
|
if (!lastMsgId) lastMsgId = msgId;
|
|
|
|
for (int j = messagesList->size(); j > 0;) {
|
|
|
|
auto &message = messagesList->at(--j);
|
|
|
|
if (idFromMessage(message) == msgId && peerFromMessage(message) == peer) {
|
|
|
|
if (auto date = dateFromMessage(message)) {
|
|
|
|
lastDate = date;
|
|
|
|
}
|
|
|
|
break;
|
2016-05-31 09:46:31 +00:00
|
|
|
}
|
2015-11-18 14:59:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-09-03 13:15:07 +00:00
|
|
|
}
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
2015-11-18 14:59:17 +00:00
|
|
|
if (lastDate) {
|
|
|
|
_dialogsOffsetDate = lastDate;
|
|
|
|
_dialogsOffsetId = lastMsgId;
|
|
|
|
_dialogsOffsetPeer = App::peer(lastPeer);
|
|
|
|
} else {
|
|
|
|
_dialogsFull = true;
|
2015-09-03 13:15:07 +00:00
|
|
|
}
|
2016-12-13 07:59:57 +00:00
|
|
|
|
|
|
|
t_assert(messagesList != nullptr);
|
|
|
|
App::feedMsgs(*messagesList, NewMessageLast);
|
|
|
|
|
|
|
|
unreadCountsReceived(*dialogsList);
|
|
|
|
_inner->dialogsReceived(*dialogsList);
|
|
|
|
onListScroll();
|
2015-11-18 14:59:17 +00:00
|
|
|
} else {
|
|
|
|
_dialogsFull = true;
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
2015-11-18 14:59:17 +00:00
|
|
|
|
2016-12-13 07:59:57 +00:00
|
|
|
_dialogsRequestId = 0;
|
2015-11-18 14:59:17 +00:00
|
|
|
loadDialogs();
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
|
2016-12-13 07:59:57 +00:00
|
|
|
void DialogsWidget::pinnedDialogsReceived(const MTPmessages_PeerDialogs &dialogs, mtpRequestId requestId) {
|
|
|
|
if (_pinnedDialogsRequestId != requestId) return;
|
|
|
|
|
|
|
|
if (dialogs.type() == mtpc_messages_peerDialogs) {
|
|
|
|
App::histories().clearPinned();
|
|
|
|
|
|
|
|
auto &dialogsData = dialogs.c_messages_peerDialogs();
|
|
|
|
App::feedUsers(dialogsData.vusers);
|
|
|
|
App::feedChats(dialogsData.vchats);
|
|
|
|
auto &list = dialogsData.vdialogs.c_vector().v;
|
|
|
|
for (auto i = list.size(); i > 0;) {
|
|
|
|
auto &dialog = list[--i];
|
|
|
|
if (dialog.type() != mtpc_dialog) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto &dialogData = dialog.c_dialog();
|
|
|
|
if (auto peer = peerFromMTP(dialogData.vpeer)) {
|
|
|
|
auto history = App::history(peer);
|
|
|
|
history->setPinnedDialog(dialogData.is_pinned());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
App::feedMsgs(dialogsData.vmessages, NewMessageLast);
|
|
|
|
unreadCountsReceived(list);
|
|
|
|
_inner->dialogsReceived(list);
|
|
|
|
onListScroll();
|
|
|
|
}
|
|
|
|
|
|
|
|
_pinnedDialogsRequestId = 0;
|
|
|
|
_pinnedDialogsReceived = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool DialogsWidget::dialogsFailed(const RPCError &error, mtpRequestId requestId) {
|
2016-04-08 10:44:35 +00:00
|
|
|
if (MTP::isDefaultHandledError(error)) return false;
|
2015-04-04 20:01:34 +00:00
|
|
|
|
|
|
|
LOG(("RPC Error: %1 %2: %3").arg(error.code()).arg(error.type()).arg(error.description()));
|
2016-12-13 07:59:57 +00:00
|
|
|
if (_dialogsRequestId == requestId) {
|
|
|
|
_dialogsRequestId = 0;
|
|
|
|
} else if (_pinnedDialogsRequestId == requestId) {
|
|
|
|
_pinnedDialogsRequestId = 0;
|
2015-09-03 13:15:07 +00:00
|
|
|
}
|
2014-05-30 08:53:19 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-07-13 09:50:38 +00:00
|
|
|
bool DialogsWidget::onSearchMessages(bool searchCache) {
|
2016-11-04 11:14:47 +00:00
|
|
|
QString q = _filter->getLastText().trimmed();
|
2014-07-04 11:12:54 +00:00
|
|
|
if (q.isEmpty()) {
|
2016-12-05 11:01:08 +00:00
|
|
|
MTP::cancel(base::take(_searchRequest));
|
|
|
|
MTP::cancel(base::take(_peerSearchRequest));
|
2014-07-13 09:50:38 +00:00
|
|
|
return true;
|
2014-07-04 11:12:54 +00:00
|
|
|
}
|
2014-07-13 09:50:38 +00:00
|
|
|
if (searchCache) {
|
|
|
|
SearchCache::const_iterator i = _searchCache.constFind(q);
|
|
|
|
if (i != _searchCache.cend()) {
|
|
|
|
_searchQuery = q;
|
2015-11-18 13:11:56 +00:00
|
|
|
_searchFull = _searchFullMigrated = false;
|
2016-12-05 11:01:08 +00:00
|
|
|
MTP::cancel(base::take(_searchRequest));
|
2015-11-18 13:11:56 +00:00
|
|
|
searchReceived(_searchInPeer ? DialogsSearchPeerFromStart : DialogsSearchFromStart, i.value(), 0);
|
2014-07-13 09:50:38 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
} else if (_searchQuery != q) {
|
2014-07-04 11:12:54 +00:00
|
|
|
_searchQuery = q;
|
2015-11-18 13:11:56 +00:00
|
|
|
_searchFull = _searchFullMigrated = false;
|
2016-12-05 11:01:08 +00:00
|
|
|
MTP::cancel(base::take(_searchRequest));
|
2015-11-18 13:11:56 +00:00
|
|
|
if (_searchInPeer) {
|
2016-03-19 16:55:15 +00:00
|
|
|
MTPmessages_Search::Flags flags = 0;
|
|
|
|
_searchRequest = MTP::send(MTPmessages_Search(MTP_flags(flags), _searchInPeer->input, MTP_string(_searchQuery), MTP_inputMessagesFilterEmpty(), MTP_int(0), MTP_int(0), MTP_int(0), MTP_int(0), MTP_int(SearchPerPage)), rpcDone(&DialogsWidget::searchReceived, DialogsSearchPeerFromStart), rpcFail(&DialogsWidget::searchFailed, DialogsSearchPeerFromStart));
|
2015-11-18 13:11:56 +00:00
|
|
|
} else {
|
|
|
|
_searchRequest = MTP::send(MTPmessages_SearchGlobal(MTP_string(_searchQuery), MTP_int(0), MTP_inputPeerEmpty(), MTP_int(0), MTP_int(SearchPerPage)), rpcDone(&DialogsWidget::searchReceived, DialogsSearchFromStart), rpcFail(&DialogsWidget::searchFailed, DialogsSearchFromStart));
|
|
|
|
}
|
2014-07-13 09:50:38 +00:00
|
|
|
_searchQueries.insert(_searchRequest, _searchQuery);
|
|
|
|
}
|
2015-08-04 15:01:47 +00:00
|
|
|
if (!_searchInPeer && q.size() >= MinUsernameLength) {
|
2014-10-22 18:39:03 +00:00
|
|
|
if (searchCache) {
|
2016-12-05 11:01:08 +00:00
|
|
|
auto i = _peerSearchCache.constFind(q);
|
|
|
|
if (i != _peerSearchCache.cend()) {
|
|
|
|
_peerSearchQuery = q;
|
|
|
|
_peerSearchRequest = 0;
|
|
|
|
peerSearchReceived(i.value(), 0);
|
2014-10-22 18:39:03 +00:00
|
|
|
return true;
|
|
|
|
}
|
2016-12-05 11:01:08 +00:00
|
|
|
} else if (_peerSearchQuery != q) {
|
|
|
|
_peerSearchQuery = q;
|
|
|
|
_peerSearchFull = false;
|
|
|
|
_peerSearchRequest = MTP::send(MTPcontacts_Search(MTP_string(_peerSearchQuery), MTP_int(SearchPeopleLimit)), rpcDone(&DialogsWidget::peerSearchReceived), rpcFail(&DialogsWidget::peopleFailed));
|
|
|
|
_peerSearchQueries.insert(_peerSearchRequest, _peerSearchQuery);
|
2014-10-22 18:39:03 +00:00
|
|
|
}
|
|
|
|
}
|
2014-07-13 09:50:38 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void DialogsWidget::onNeedSearchMessages() {
|
|
|
|
if (!onSearchMessages(true)) {
|
|
|
|
_searchTimer.start(AutoSearchTimeout);
|
2014-07-04 11:12:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-06-26 09:07:59 +00:00
|
|
|
void DialogsWidget::onChooseByDrag() {
|
2016-11-05 08:36:24 +00:00
|
|
|
_inner->choosePeer();
|
2015-06-26 09:07:59 +00:00
|
|
|
}
|
|
|
|
|
2016-11-04 11:14:47 +00:00
|
|
|
void DialogsWidget::showMainMenu() {
|
2016-11-11 19:51:59 +00:00
|
|
|
App::wnd()->showMainMenu();
|
2016-11-04 11:14:47 +00:00
|
|
|
}
|
|
|
|
|
2015-09-21 20:57:42 +00:00
|
|
|
void DialogsWidget::searchMessages(const QString &query, PeerData *inPeer) {
|
2016-11-04 11:14:47 +00:00
|
|
|
if ((_filter->getLastText() != query) || (inPeer && inPeer != _searchInPeer && inPeer->migrateTo() != _searchInPeer)) {
|
2015-09-21 20:57:42 +00:00
|
|
|
if (inPeer) {
|
2016-03-13 13:34:27 +00:00
|
|
|
onCancelSearch();
|
2016-11-16 12:06:02 +00:00
|
|
|
setSearchInPeer(inPeer);
|
2015-09-21 20:57:42 +00:00
|
|
|
}
|
2016-11-04 11:14:47 +00:00
|
|
|
_filter->setText(query);
|
|
|
|
_filter->updatePlaceholder();
|
2015-09-21 20:57:42 +00:00
|
|
|
onFilterUpdate(true);
|
2014-07-16 06:58:36 +00:00
|
|
|
_searchTimer.stop();
|
|
|
|
onSearchMessages();
|
2015-03-24 10:00:27 +00:00
|
|
|
|
2016-11-05 08:36:24 +00:00
|
|
|
_inner->saveRecentHashtags(query);
|
2014-07-16 06:58:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-11-18 13:11:56 +00:00
|
|
|
void DialogsWidget::onSearchMore() {
|
|
|
|
if (!_searchRequest) {
|
|
|
|
if (!_searchFull) {
|
2016-11-05 08:36:24 +00:00
|
|
|
int32 offsetDate = _inner->lastSearchDate();
|
|
|
|
PeerData *offsetPeer = _inner->lastSearchPeer();
|
|
|
|
MsgId offsetId = _inner->lastSearchId();
|
2015-11-18 13:11:56 +00:00
|
|
|
if (_searchInPeer) {
|
2016-03-19 16:55:15 +00:00
|
|
|
MTPmessages_Search::Flags flags = 0;
|
|
|
|
_searchRequest = MTP::send(MTPmessages_Search(MTP_flags(flags), _searchInPeer->input, MTP_string(_searchQuery), MTP_inputMessagesFilterEmpty(), MTP_int(0), MTP_int(0), MTP_int(0), MTP_int(offsetId), MTP_int(SearchPerPage)), rpcDone(&DialogsWidget::searchReceived, offsetId ? DialogsSearchPeerFromOffset : DialogsSearchPeerFromStart), rpcFail(&DialogsWidget::searchFailed, offsetId ? DialogsSearchPeerFromOffset : DialogsSearchPeerFromStart));
|
2015-11-18 13:11:56 +00:00
|
|
|
} else {
|
|
|
|
_searchRequest = MTP::send(MTPmessages_SearchGlobal(MTP_string(_searchQuery), MTP_int(offsetDate), offsetPeer ? offsetPeer->input : MTP_inputPeerEmpty(), MTP_int(offsetId), MTP_int(SearchPerPage)), rpcDone(&DialogsWidget::searchReceived, offsetId ? DialogsSearchFromOffset : DialogsSearchFromStart), rpcFail(&DialogsWidget::searchFailed, offsetId ? DialogsSearchFromOffset : DialogsSearchFromStart));
|
|
|
|
}
|
|
|
|
if (!offsetId) {
|
|
|
|
_searchQueries.insert(_searchRequest, _searchQuery);
|
|
|
|
}
|
|
|
|
} else if (_searchInMigrated && !_searchFullMigrated) {
|
2016-11-05 08:36:24 +00:00
|
|
|
MsgId offsetMigratedId = _inner->lastSearchMigratedId();
|
2016-03-19 16:55:15 +00:00
|
|
|
MTPmessages_Search::Flags flags = 0;
|
|
|
|
_searchRequest = MTP::send(MTPmessages_Search(MTP_flags(flags), _searchInMigrated->input, MTP_string(_searchQuery), MTP_inputMessagesFilterEmpty(), MTP_int(0), MTP_int(0), MTP_int(0), MTP_int(offsetMigratedId), MTP_int(SearchPerPage)), rpcDone(&DialogsWidget::searchReceived, offsetMigratedId ? DialogsSearchMigratedFromOffset : DialogsSearchMigratedFromStart), rpcFail(&DialogsWidget::searchFailed, offsetMigratedId ? DialogsSearchMigratedFromOffset : DialogsSearchMigratedFromStart));
|
2014-07-13 09:50:38 +00:00
|
|
|
}
|
2014-07-04 11:12:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-30 08:53:19 +00:00
|
|
|
void DialogsWidget::loadDialogs() {
|
2016-12-13 07:59:57 +00:00
|
|
|
if (_dialogsRequestId) return;
|
2015-11-18 14:59:17 +00:00
|
|
|
if (_dialogsFull) {
|
2016-11-05 08:36:24 +00:00
|
|
|
_inner->addAllSavedPeers();
|
2015-06-15 17:19:24 +00:00
|
|
|
cSetDialogsReceived(true);
|
|
|
|
return;
|
|
|
|
}
|
2014-05-30 08:53:19 +00:00
|
|
|
|
2016-12-13 07:59:57 +00:00
|
|
|
auto firstLoad = !_dialogsOffsetDate;
|
|
|
|
auto loadCount = firstLoad ? DialogsFirstLoad : DialogsPerPage;
|
|
|
|
auto flags = qFlags(MTPmessages_GetDialogs::Flag::f_exclude_pinned);
|
|
|
|
_dialogsRequestId = MTP::send(MTPmessages_GetDialogs(MTP_flags(flags), MTP_int(_dialogsOffsetDate), MTP_int(_dialogsOffsetId), _dialogsOffsetPeer ? _dialogsOffsetPeer->input : MTP_inputPeerEmpty(), MTP_int(loadCount)), rpcDone(&DialogsWidget::dialogsReceived), rpcFail(&DialogsWidget::dialogsFailed));
|
|
|
|
if (!_pinnedDialogsReceived) {
|
|
|
|
loadPinnedDialogs();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void DialogsWidget::loadPinnedDialogs() {
|
|
|
|
if (_pinnedDialogsRequestId) return;
|
|
|
|
|
|
|
|
_pinnedDialogsReceived = false;
|
|
|
|
_pinnedDialogsRequestId = MTP::send(MTPmessages_GetPinnedDialogs(), rpcDone(&DialogsWidget::pinnedDialogsReceived), rpcFail(&DialogsWidget::dialogsFailed));
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
|
2016-12-05 11:01:08 +00:00
|
|
|
void DialogsWidget::contactsReceived(const MTPcontacts_Contacts &result) {
|
2016-12-13 07:59:57 +00:00
|
|
|
_contactsRequestId = 0;
|
2015-09-07 15:53:46 +00:00
|
|
|
cSetContactsReceived(true);
|
2016-12-05 11:01:08 +00:00
|
|
|
if (result.type() == mtpc_contacts_contacts) {
|
|
|
|
auto &d = result.c_contacts_contacts();
|
2014-05-30 08:53:19 +00:00
|
|
|
App::feedUsers(d.vusers);
|
2016-11-05 08:36:24 +00:00
|
|
|
_inner->contactsReceived(d.vcontacts.c_vector().v);
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
2015-09-07 15:53:46 +00:00
|
|
|
if (App::main()) App::main()->contactsReceived();
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
|
2015-04-04 20:01:34 +00:00
|
|
|
bool DialogsWidget::contactsFailed(const RPCError &error) {
|
2016-04-08 10:44:35 +00:00
|
|
|
if (MTP::isDefaultHandledError(error)) return false;
|
2016-12-13 07:59:57 +00:00
|
|
|
_contactsRequestId = 0;
|
2014-05-30 08:53:19 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-11-18 13:11:56 +00:00
|
|
|
void DialogsWidget::searchReceived(DialogsSearchRequestType type, const MTPmessages_Messages &result, mtpRequestId req) {
|
2016-11-05 08:36:24 +00:00
|
|
|
if (_inner->state() == DialogsInner::FilteredState || _inner->state() == DialogsInner::SearchedState) {
|
2015-11-18 13:11:56 +00:00
|
|
|
if (type == DialogsSearchFromStart || type == DialogsSearchPeerFromStart) {
|
|
|
|
SearchQueries::iterator i = _searchQueries.find(req);
|
|
|
|
if (i != _searchQueries.cend()) {
|
|
|
|
_searchCache[i.value()] = result;
|
|
|
|
_searchQueries.erase(i);
|
|
|
|
}
|
2014-07-13 09:50:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-07-04 11:12:54 +00:00
|
|
|
if (_searchRequest == req) {
|
|
|
|
switch (result.type()) {
|
|
|
|
case mtpc_messages_messages: {
|
2016-05-27 16:47:46 +00:00
|
|
|
auto &d(result.c_messages_messages());
|
2015-09-04 13:01:31 +00:00
|
|
|
App::feedUsers(d.vusers);
|
|
|
|
App::feedChats(d.vchats);
|
2016-05-27 16:47:46 +00:00
|
|
|
auto &msgs(d.vmessages.c_vector().v);
|
2016-11-05 08:36:24 +00:00
|
|
|
if (!_inner->searchReceived(msgs, type, msgs.size())) {
|
2015-11-18 13:11:56 +00:00
|
|
|
if (type == DialogsSearchMigratedFromStart || type == DialogsSearchMigratedFromOffset) {
|
|
|
|
_searchFullMigrated = true;
|
|
|
|
} else {
|
|
|
|
_searchFull = true;
|
|
|
|
}
|
2014-07-04 11:12:54 +00:00
|
|
|
}
|
|
|
|
} break;
|
|
|
|
|
|
|
|
case mtpc_messages_messagesSlice: {
|
2016-05-27 16:47:46 +00:00
|
|
|
auto &d(result.c_messages_messagesSlice());
|
2015-09-04 13:01:31 +00:00
|
|
|
App::feedUsers(d.vusers);
|
|
|
|
App::feedChats(d.vchats);
|
2016-05-27 16:47:46 +00:00
|
|
|
auto &msgs(d.vmessages.c_vector().v);
|
2016-11-05 08:36:24 +00:00
|
|
|
if (!_inner->searchReceived(msgs, type, d.vcount.v)) {
|
2015-11-18 13:11:56 +00:00
|
|
|
if (type == DialogsSearchMigratedFromStart || type == DialogsSearchMigratedFromOffset) {
|
|
|
|
_searchFullMigrated = true;
|
|
|
|
} else {
|
|
|
|
_searchFull = true;
|
|
|
|
}
|
2015-09-04 13:01:31 +00:00
|
|
|
}
|
|
|
|
} break;
|
|
|
|
|
|
|
|
case mtpc_messages_channelMessages: {
|
2016-05-27 16:47:46 +00:00
|
|
|
auto &d(result.c_messages_channelMessages());
|
2015-09-13 08:41:27 +00:00
|
|
|
if (_searchInPeer && _searchInPeer->isChannel()) {
|
|
|
|
_searchInPeer->asChannel()->ptsReceived(d.vpts.v);
|
|
|
|
} else {
|
2015-09-19 09:13:21 +00:00
|
|
|
LOG(("API Error: received messages.channelMessages when no channel was passed! (DialogsWidget::searchReceived)"));
|
|
|
|
}
|
2015-09-04 13:01:31 +00:00
|
|
|
App::feedUsers(d.vusers);
|
|
|
|
App::feedChats(d.vchats);
|
2016-05-27 16:47:46 +00:00
|
|
|
auto &msgs(d.vmessages.c_vector().v);
|
2016-11-05 08:36:24 +00:00
|
|
|
if (!_inner->searchReceived(msgs, type, d.vcount.v)) {
|
2015-11-18 13:11:56 +00:00
|
|
|
if (type == DialogsSearchMigratedFromStart || type == DialogsSearchMigratedFromOffset) {
|
|
|
|
_searchFullMigrated = true;
|
|
|
|
} else {
|
|
|
|
_searchFull = true;
|
|
|
|
}
|
2014-07-04 11:12:54 +00:00
|
|
|
}
|
|
|
|
} break;
|
|
|
|
}
|
2014-07-13 09:50:38 +00:00
|
|
|
|
2014-07-04 11:12:54 +00:00
|
|
|
_searchRequest = 0;
|
2014-08-22 07:41:39 +00:00
|
|
|
onListScroll();
|
2016-08-03 18:18:23 +00:00
|
|
|
update();
|
2014-07-04 11:12:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-05 11:01:08 +00:00
|
|
|
void DialogsWidget::peerSearchReceived(const MTPcontacts_Found &result, mtpRequestId req) {
|
|
|
|
auto q = _peerSearchQuery;
|
2016-11-05 08:36:24 +00:00
|
|
|
if (_inner->state() == DialogsInner::FilteredState || _inner->state() == DialogsInner::SearchedState) {
|
2016-12-05 11:01:08 +00:00
|
|
|
auto i = _peerSearchQueries.find(req);
|
|
|
|
if (i != _peerSearchQueries.cend()) {
|
2014-10-23 16:05:33 +00:00
|
|
|
q = i.value();
|
2016-12-05 11:01:08 +00:00
|
|
|
_peerSearchCache[q] = result;
|
|
|
|
_peerSearchQueries.erase(i);
|
2014-10-22 18:39:03 +00:00
|
|
|
}
|
|
|
|
}
|
2016-12-05 11:01:08 +00:00
|
|
|
if (_peerSearchRequest == req) {
|
2014-10-22 18:39:03 +00:00
|
|
|
switch (result.type()) {
|
|
|
|
case mtpc_contacts_found: {
|
2016-10-22 15:58:14 +00:00
|
|
|
auto &d = result.c_contacts_found();
|
|
|
|
App::feedUsers(d.vusers);
|
|
|
|
App::feedChats(d.vchats);
|
2016-12-05 11:01:08 +00:00
|
|
|
_inner->peerSearchReceived(q, d.vresults.c_vector().v);
|
2014-10-22 18:39:03 +00:00
|
|
|
} break;
|
|
|
|
}
|
|
|
|
|
2016-12-05 11:01:08 +00:00
|
|
|
_peerSearchRequest = 0;
|
2014-10-22 18:39:03 +00:00
|
|
|
onListScroll();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-11-18 13:11:56 +00:00
|
|
|
bool DialogsWidget::searchFailed(DialogsSearchRequestType type, const RPCError &error, mtpRequestId req) {
|
2016-04-08 10:44:35 +00:00
|
|
|
if (MTP::isDefaultHandledError(error)) return false;
|
2015-04-04 20:01:34 +00:00
|
|
|
|
2014-07-04 11:12:54 +00:00
|
|
|
if (_searchRequest == req) {
|
|
|
|
_searchRequest = 0;
|
2015-11-18 13:11:56 +00:00
|
|
|
if (type == DialogsSearchMigratedFromStart || type == DialogsSearchMigratedFromOffset) {
|
|
|
|
_searchFullMigrated = true;
|
|
|
|
} else {
|
|
|
|
_searchFull = true;
|
|
|
|
}
|
2014-07-04 11:12:54 +00:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-10-22 18:39:03 +00:00
|
|
|
bool DialogsWidget::peopleFailed(const RPCError &error, mtpRequestId req) {
|
2016-04-08 10:44:35 +00:00
|
|
|
if (MTP::isDefaultHandledError(error)) return false;
|
2015-04-04 20:01:34 +00:00
|
|
|
|
2016-12-05 11:01:08 +00:00
|
|
|
if (_peerSearchRequest == req) {
|
|
|
|
_peerSearchRequest = 0;
|
|
|
|
_peerSearchFull = true;
|
2014-10-22 18:39:03 +00:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-06-24 17:24:48 +00:00
|
|
|
void DialogsWidget::dragEnterEvent(QDragEnterEvent *e) {
|
|
|
|
if (App::main()->selectingPeer()) return;
|
|
|
|
|
|
|
|
_dragInScroll = false;
|
2015-06-27 13:02:00 +00:00
|
|
|
_dragForward = e->mimeData()->hasFormat(qsl("application/x-td-forward-selected"));
|
|
|
|
if (!_dragForward) _dragForward = e->mimeData()->hasFormat(qsl("application/x-td-forward-pressed-link"));
|
|
|
|
if (!_dragForward) _dragForward = e->mimeData()->hasFormat(qsl("application/x-td-forward-pressed"));
|
2016-02-08 14:54:55 +00:00
|
|
|
if (_dragForward && Adaptive::OneColumn()) _dragForward = false;
|
2015-06-24 17:24:48 +00:00
|
|
|
if (_dragForward) {
|
|
|
|
e->setDropAction(Qt::CopyAction);
|
|
|
|
e->accept();
|
2016-11-05 08:36:24 +00:00
|
|
|
updateDragInScroll(_scroll->geometry().contains(e->pos()));
|
2015-06-26 09:07:59 +00:00
|
|
|
} else if (App::main() && App::main()->getDragState(e->mimeData()) != DragStateNone) {
|
2015-06-24 17:24:48 +00:00
|
|
|
e->setDropAction(Qt::CopyAction);
|
|
|
|
e->accept();
|
|
|
|
}
|
2015-06-26 09:07:59 +00:00
|
|
|
_chooseByDragTimer.stop();
|
2015-06-24 17:24:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void DialogsWidget::dragMoveEvent(QDragMoveEvent *e) {
|
2016-11-05 08:36:24 +00:00
|
|
|
if (_scroll->geometry().contains(e->pos())) {
|
2015-06-26 09:07:59 +00:00
|
|
|
if (_dragForward) {
|
|
|
|
updateDragInScroll(true);
|
|
|
|
} else {
|
|
|
|
_chooseByDragTimer.start(ChoosePeerByDragTimeout);
|
|
|
|
}
|
2016-11-05 08:36:24 +00:00
|
|
|
PeerData *p = _inner->updateFromParentDrag(mapToGlobal(e->pos()));
|
2015-06-24 17:24:48 +00:00
|
|
|
if (p) {
|
|
|
|
e->setDropAction(Qt::CopyAction);
|
|
|
|
} else {
|
|
|
|
e->setDropAction(Qt::IgnoreAction);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (_dragForward) updateDragInScroll(false);
|
2016-12-04 19:40:41 +00:00
|
|
|
_inner->dragLeft();
|
2015-06-24 17:24:48 +00:00
|
|
|
e->setDropAction(Qt::IgnoreAction);
|
|
|
|
}
|
|
|
|
e->accept();
|
|
|
|
}
|
|
|
|
|
|
|
|
void DialogsWidget::dragLeaveEvent(QDragLeaveEvent *e) {
|
2015-06-26 09:07:59 +00:00
|
|
|
if (_dragForward) {
|
|
|
|
updateDragInScroll(false);
|
|
|
|
} else {
|
|
|
|
_chooseByDragTimer.stop();
|
|
|
|
}
|
2016-12-04 19:40:41 +00:00
|
|
|
_inner->dragLeft();
|
2015-06-24 17:24:48 +00:00
|
|
|
e->accept();
|
|
|
|
}
|
|
|
|
|
|
|
|
void DialogsWidget::updateDragInScroll(bool inScroll) {
|
|
|
|
if (_dragInScroll != inScroll) {
|
|
|
|
_dragInScroll = inScroll;
|
|
|
|
if (_dragInScroll) {
|
|
|
|
App::main()->forwardLayer(1);
|
|
|
|
} else {
|
|
|
|
App::main()->dialogsCancelled();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void DialogsWidget::dropEvent(QDropEvent *e) {
|
2015-06-26 09:07:59 +00:00
|
|
|
_chooseByDragTimer.stop();
|
2016-11-05 08:36:24 +00:00
|
|
|
if (_scroll->geometry().contains(e->pos())) {
|
|
|
|
PeerData *p = _inner->updateFromParentDrag(mapToGlobal(e->pos()));
|
2015-06-24 17:24:48 +00:00
|
|
|
if (p) {
|
|
|
|
e->acceptProposedAction();
|
2015-06-27 13:02:00 +00:00
|
|
|
App::main()->onFilesOrForwardDrop(p->id, e->mimeData());
|
2015-06-24 17:24:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-30 08:53:19 +00:00
|
|
|
void DialogsWidget::onListScroll() {
|
2016-12-05 11:01:08 +00:00
|
|
|
auto scrollTop = _scroll->scrollTop();
|
|
|
|
_inner->setVisibleTopBottom(scrollTop, scrollTop + _scroll->height());
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
|
2014-12-12 16:27:03 +00:00
|
|
|
void DialogsWidget::onFilterUpdate(bool force) {
|
2015-10-17 14:52:26 +00:00
|
|
|
if (_a_show.animating() && !force) return;
|
2014-12-12 16:27:03 +00:00
|
|
|
|
2016-11-04 11:14:47 +00:00
|
|
|
QString filterText = _filter->getLastText();
|
2016-11-05 08:36:24 +00:00
|
|
|
_inner->onFilterUpdate(filterText, force);
|
2014-07-13 09:50:38 +00:00
|
|
|
if (filterText.isEmpty()) {
|
|
|
|
_searchCache.clear();
|
|
|
|
_searchQueries.clear();
|
|
|
|
_searchQuery = QString();
|
2016-11-21 17:46:29 +00:00
|
|
|
_cancelSearch->hideAnimated();
|
|
|
|
} else {
|
|
|
|
_cancelSearch->showAnimated();
|
2014-07-04 11:12:54 +00:00
|
|
|
}
|
2014-10-22 18:39:03 +00:00
|
|
|
if (filterText.size() < MinUsernameLength) {
|
2016-12-05 11:01:08 +00:00
|
|
|
_peerSearchCache.clear();
|
|
|
|
_peerSearchQueries.clear();
|
|
|
|
_peerSearchQuery = QString();
|
2014-10-22 18:39:03 +00:00
|
|
|
}
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
|
2015-08-04 15:01:47 +00:00
|
|
|
void DialogsWidget::searchInPeer(PeerData *peer) {
|
|
|
|
onCancelSearch();
|
2016-11-16 12:06:02 +00:00
|
|
|
setSearchInPeer(peer);
|
2015-08-04 15:01:47 +00:00
|
|
|
onFilterUpdate(true);
|
|
|
|
}
|
|
|
|
|
2016-11-16 12:06:02 +00:00
|
|
|
void DialogsWidget::setSearchInPeer(PeerData *peer) {
|
|
|
|
auto newSearchInPeer = peer ? (peer->migrateTo() ? peer->migrateTo() : peer) : nullptr;
|
|
|
|
_searchInMigrated = newSearchInPeer ? newSearchInPeer->migrateFrom() : nullptr;
|
|
|
|
if (newSearchInPeer != _searchInPeer) {
|
|
|
|
_searchInPeer = newSearchInPeer;
|
|
|
|
App::main()->searchInPeerChanged().notify(_searchInPeer, true);
|
|
|
|
}
|
|
|
|
_inner->searchInPeer(_searchInPeer);
|
|
|
|
}
|
|
|
|
|
2015-03-24 10:00:27 +00:00
|
|
|
void DialogsWidget::onFilterCursorMoved(int from, int to) {
|
2016-11-04 11:14:47 +00:00
|
|
|
if (to < 0) to = _filter->cursorPosition();
|
|
|
|
QString t = _filter->getLastText();
|
2015-06-15 17:19:24 +00:00
|
|
|
QStringRef r;
|
2015-03-24 10:00:27 +00:00
|
|
|
for (int start = to; start > 0;) {
|
|
|
|
--start;
|
|
|
|
if (t.size() <= start) break;
|
|
|
|
if (t.at(start) == '#') {
|
2015-06-15 17:19:24 +00:00
|
|
|
r = t.midRef(start, to - start);
|
2015-03-24 10:00:27 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (!t.at(start).isLetterOrNumber() && t.at(start) != '_') break;
|
|
|
|
}
|
2016-11-05 08:36:24 +00:00
|
|
|
_inner->onHashtagFilterUpdate(r);
|
2015-03-24 10:00:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void DialogsWidget::onCompleteHashtag(QString tag) {
|
2016-11-04 11:14:47 +00:00
|
|
|
QString t = _filter->getLastText(), r;
|
|
|
|
int cur = _filter->cursorPosition();
|
2015-03-24 10:00:27 +00:00
|
|
|
for (int start = cur; start > 0;) {
|
|
|
|
--start;
|
|
|
|
if (t.size() <= start) break;
|
|
|
|
if (t.at(start) == '#') {
|
|
|
|
if (cur == start + 1 || t.midRef(start + 1, cur - start - 1) == tag.midRef(0, cur - start - 1)) {
|
|
|
|
for (; cur < t.size() && cur - start - 1 < tag.size(); ++cur) {
|
|
|
|
if (t.at(cur) != tag.at(cur - start - 1)) break;
|
|
|
|
}
|
|
|
|
if (cur - start - 1 == tag.size() && cur < t.size() && t.at(cur) == ' ') ++cur;
|
|
|
|
r = t.mid(0, start + 1) + tag + ' ' + t.mid(cur);
|
2016-11-04 11:14:47 +00:00
|
|
|
_filter->setText(r);
|
|
|
|
_filter->setCursorPosition(start + 1 + tag.size() + 1);
|
2015-03-24 10:00:27 +00:00
|
|
|
onFilterUpdate(true);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (!t.at(start).isLetterOrNumber() && t.at(start) != '_') break;
|
|
|
|
}
|
2016-11-04 11:14:47 +00:00
|
|
|
_filter->setText(t.mid(0, cur) + '#' + tag + ' ' + t.mid(cur));
|
|
|
|
_filter->setCursorPosition(cur + 1 + tag.size() + 1);
|
2015-03-24 10:00:27 +00:00
|
|
|
onFilterUpdate(true);
|
|
|
|
}
|
|
|
|
|
2014-05-30 08:53:19 +00:00
|
|
|
void DialogsWidget::resizeEvent(QResizeEvent *e) {
|
2016-11-04 19:50:35 +00:00
|
|
|
updateControlsGeometry();
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
|
2016-11-04 19:50:35 +00:00
|
|
|
void DialogsWidget::updateLockUnlockVisibility() {
|
|
|
|
if (!_a_show.animating()) {
|
|
|
|
_lockUnlock->setVisible(Global::LocalPasscode());
|
|
|
|
}
|
|
|
|
updateControlsGeometry();
|
|
|
|
}
|
|
|
|
|
|
|
|
void DialogsWidget::updateControlsGeometry() {
|
2016-11-17 11:03:49 +00:00
|
|
|
auto filterAreaTop = 0;
|
2016-11-06 17:23:13 +00:00
|
|
|
if (_forwardCancel) {
|
2016-11-17 11:03:49 +00:00
|
|
|
_forwardCancel->moveToLeft(0, filterAreaTop);
|
|
|
|
filterAreaTop += st::dialogsForwardHeight;
|
2016-11-06 17:23:13 +00:00
|
|
|
}
|
2016-11-16 10:44:06 +00:00
|
|
|
auto filterLeft = st::dialogsFilterPadding.x() + _mainMenuToggle->width() + st::dialogsFilterPadding.x();
|
|
|
|
auto filterRight = (Global::LocalPasscode() ? (st::dialogsFilterPadding.x() + _lockUnlock->width()) : st::dialogsFilterSkip) + st::dialogsFilterPadding.x();
|
2017-01-14 18:50:16 +00:00
|
|
|
auto filterWidth = qMax(width(), st::dialogsWidthMin) - filterLeft - filterRight;
|
2016-11-17 11:03:49 +00:00
|
|
|
auto filterAreaHeight = st::dialogsFilterPadding.y() + _mainMenuToggle->height() + st::dialogsFilterPadding.y();
|
|
|
|
auto filterTop = filterAreaTop + (filterAreaHeight - _filter->height()) / 2;
|
2016-11-06 17:23:13 +00:00
|
|
|
_filter->setGeometryToLeft(filterLeft, filterTop, filterWidth, _filter->height());
|
2016-11-17 11:03:49 +00:00
|
|
|
_mainMenuToggle->moveToLeft(st::dialogsFilterPadding.x(), filterAreaTop + st::dialogsFilterPadding.y());
|
2017-01-14 18:50:16 +00:00
|
|
|
_lockUnlock->moveToLeft(filterLeft + filterWidth + st::dialogsFilterPadding.x(), filterAreaTop + st::dialogsFilterPadding.y());
|
2016-11-04 19:50:35 +00:00
|
|
|
_cancelSearch->moveToLeft(filterLeft + filterWidth - _cancelSearch->width(), _filter->y());
|
2016-11-05 08:36:24 +00:00
|
|
|
|
2016-11-17 11:03:49 +00:00
|
|
|
auto scrollTop = filterAreaTop + filterAreaHeight;
|
2016-11-05 08:36:24 +00:00
|
|
|
auto addToScroll = App::main() ? App::main()->contentScrollAddToY() : 0;
|
|
|
|
auto newScrollTop = _scroll->scrollTop() + addToScroll;
|
|
|
|
auto scrollHeight = height() - scrollTop;
|
|
|
|
if (_updateTelegram) {
|
|
|
|
auto updateHeight = _updateTelegram->height();
|
|
|
|
_updateTelegram->setGeometry(0, height() - updateHeight, width(), updateHeight);
|
|
|
|
scrollHeight -= updateHeight;
|
|
|
|
} else {
|
|
|
|
scrollHeight -= st::dialogsPadding.y();
|
|
|
|
}
|
|
|
|
_scroll->setGeometry(0, scrollTop, width(), scrollHeight);
|
|
|
|
if (addToScroll) {
|
|
|
|
_scroll->scrollToY(newScrollTop);
|
|
|
|
} else {
|
|
|
|
onListScroll();
|
|
|
|
}
|
2016-11-04 19:50:35 +00:00
|
|
|
}
|
|
|
|
|
2016-11-06 17:23:13 +00:00
|
|
|
void DialogsWidget::updateForwardBar() {
|
|
|
|
auto selecting = App::main()->selectingPeer();
|
|
|
|
auto oneColumnSelecting = (Adaptive::OneColumn() && selecting);
|
|
|
|
if (!oneColumnSelecting == !_forwardCancel) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (oneColumnSelecting) {
|
|
|
|
_forwardCancel.create(this, st::dialogsForwardCancel);
|
|
|
|
_forwardCancel->setClickedCallback([] { Global::RefPeerChooseCancel().notify(true); });
|
|
|
|
if (!_a_show.animating()) _forwardCancel->show();
|
|
|
|
} else {
|
|
|
|
_forwardCancel.destroyDelayed();
|
|
|
|
}
|
|
|
|
updateControlsGeometry();
|
|
|
|
update();
|
|
|
|
}
|
|
|
|
|
2014-05-30 08:53:19 +00:00
|
|
|
void DialogsWidget::keyPressEvent(QKeyEvent *e) {
|
|
|
|
if (e->key() == Qt::Key_Escape) {
|
|
|
|
e->ignore();
|
|
|
|
} else if (e->key() == Qt::Key_Return || e->key() == Qt::Key_Enter) {
|
2016-11-05 08:36:24 +00:00
|
|
|
if (!_inner->choosePeer()) {
|
|
|
|
if (_inner->state() == DialogsInner::DefaultState || _inner->state() == DialogsInner::SearchedState || (_inner->state() == DialogsInner::FilteredState && _inner->hasFilteredResults())) {
|
|
|
|
_inner->selectSkip(1);
|
|
|
|
_inner->choosePeer();
|
2015-02-09 23:19:48 +00:00
|
|
|
} else {
|
|
|
|
onSearchMessages();
|
|
|
|
}
|
2014-07-04 11:12:54 +00:00
|
|
|
}
|
2014-05-30 08:53:19 +00:00
|
|
|
} else if (e->key() == Qt::Key_Down) {
|
2016-12-05 11:01:08 +00:00
|
|
|
_inner->setMouseSelection(false);
|
2016-11-05 08:36:24 +00:00
|
|
|
_inner->selectSkip(1);
|
2014-05-30 08:53:19 +00:00
|
|
|
} else if (e->key() == Qt::Key_Up) {
|
2016-12-05 11:01:08 +00:00
|
|
|
_inner->setMouseSelection(false);
|
2016-11-05 08:36:24 +00:00
|
|
|
_inner->selectSkip(-1);
|
2014-05-30 08:53:19 +00:00
|
|
|
} else if (e->key() == Qt::Key_PageDown) {
|
2016-12-05 11:01:08 +00:00
|
|
|
_inner->setMouseSelection(false);
|
2016-11-05 08:36:24 +00:00
|
|
|
_inner->selectSkipPage(_scroll->height(), 1);
|
2014-05-30 08:53:19 +00:00
|
|
|
} else if (e->key() == Qt::Key_PageUp) {
|
2016-12-05 11:01:08 +00:00
|
|
|
_inner->setMouseSelection(false);
|
2016-11-05 08:36:24 +00:00
|
|
|
_inner->selectSkipPage(_scroll->height(), -1);
|
2014-05-30 08:53:19 +00:00
|
|
|
} else {
|
|
|
|
e->ignore();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void DialogsWidget::paintEvent(QPaintEvent *e) {
|
2015-10-01 14:05:05 +00:00
|
|
|
if (App::wnd() && App::wnd()->contentOverlapped(this, e)) return;
|
|
|
|
|
2016-04-21 17:57:29 +00:00
|
|
|
Painter p(this);
|
2014-12-12 16:27:03 +00:00
|
|
|
QRect r(e->rect());
|
|
|
|
if (r != rect()) {
|
|
|
|
p.setClipRect(r);
|
|
|
|
}
|
2016-12-05 11:01:08 +00:00
|
|
|
auto progress = _a_show.current(getms(), 1.);
|
2015-10-17 14:52:26 +00:00
|
|
|
if (_a_show.animating()) {
|
2016-12-05 11:01:08 +00:00
|
|
|
auto retina = cIntRetinaFactor();
|
|
|
|
auto fromLeft = (_showDirection == Window::SlideDirection::FromLeft);
|
|
|
|
auto coordUnder = fromLeft ? anim::interpolate(-st::slideShift, 0, progress) : anim::interpolate(0, -st::slideShift, progress);
|
|
|
|
auto coordOver = fromLeft ? anim::interpolate(0, width(), progress) : anim::interpolate(width(), 0, progress);
|
|
|
|
auto shadow = fromLeft ? (1. - progress) : progress;
|
|
|
|
if (coordOver > 0) {
|
|
|
|
p.drawPixmap(QRect(0, 0, coordOver, _cacheUnder.height() / retina), _cacheUnder, QRect(-coordUnder * retina, 0, coordOver * retina, _cacheUnder.height()));
|
|
|
|
p.setOpacity(shadow);
|
|
|
|
p.fillRect(0, 0, coordOver, _cacheUnder.height() / retina, st::slideFadeOutBg);
|
2015-10-17 14:52:26 +00:00
|
|
|
p.setOpacity(1);
|
|
|
|
}
|
2016-12-05 11:01:08 +00:00
|
|
|
p.drawPixmap(QRect(coordOver, 0, _cacheOver.width() / retina, _cacheOver.height() / retina), _cacheOver, QRect(0, 0, _cacheOver.width(), _cacheOver.height()));
|
|
|
|
p.setOpacity(shadow);
|
|
|
|
st::slideShadow.fill(p, QRect(coordOver - st::slideShadow.width(), 0, st::slideShadow.width(), _cacheOver.height() / retina));
|
2014-12-12 16:27:03 +00:00
|
|
|
return;
|
|
|
|
}
|
2016-11-06 17:23:13 +00:00
|
|
|
auto aboveTop = 0;
|
|
|
|
if (_forwardCancel) {
|
|
|
|
p.fillRect(0, aboveTop, width(), st::dialogsForwardHeight, st::dialogsForwardBg);
|
|
|
|
p.setPen(st::dialogsForwardFg);
|
|
|
|
p.setFont(st::dialogsForwardFont);
|
|
|
|
p.drawTextLeft(st::dialogsForwardTextLeft, st::dialogsForwardTextTop, width(), lang(lng_forward_choose));
|
|
|
|
aboveTop += st::dialogsForwardHeight;
|
|
|
|
}
|
2017-01-14 18:50:16 +00:00
|
|
|
auto above = QRect(0, aboveTop, width(), _scroll->y() - aboveTop);
|
2015-09-29 13:24:39 +00:00
|
|
|
if (above.intersects(r)) {
|
2016-10-31 12:29:26 +00:00
|
|
|
p.fillRect(above.intersected(r), st::dialogsBg);
|
2015-09-29 13:24:39 +00:00
|
|
|
}
|
2017-01-14 18:50:16 +00:00
|
|
|
|
|
|
|
auto belowTop = _scroll->y() + qMin(_scroll->height(), _inner->height());
|
|
|
|
if (!_widthAnimationCache.isNull()) {
|
|
|
|
p.drawPixmapLeft(0, _scroll->y(), width(), _widthAnimationCache);
|
|
|
|
belowTop = _scroll->y() + (_widthAnimationCache.height() / cIntRetinaFactor());
|
|
|
|
}
|
|
|
|
|
|
|
|
auto below = QRect(0, belowTop, width(), height() - belowTop);
|
2015-09-29 13:24:39 +00:00
|
|
|
if (below.intersects(r)) {
|
2016-10-31 12:29:26 +00:00
|
|
|
p.fillRect(below.intersected(r), st::dialogsBg);
|
2015-09-29 13:24:39 +00:00
|
|
|
}
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void DialogsWidget::destroyData() {
|
2016-11-05 08:36:24 +00:00
|
|
|
_inner->destroyData();
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
|
2014-08-22 07:41:39 +00:00
|
|
|
void DialogsWidget::peerBefore(const PeerData *inPeer, MsgId inMsg, PeerData *&outPeer, MsgId &outMsg) const {
|
2016-11-05 08:36:24 +00:00
|
|
|
return _inner->peerBefore(inPeer, inMsg, outPeer, outMsg);
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
|
2014-08-22 07:41:39 +00:00
|
|
|
void DialogsWidget::peerAfter(const PeerData *inPeer, MsgId inMsg, PeerData *&outPeer, MsgId &outMsg) const {
|
2016-11-05 08:36:24 +00:00
|
|
|
return _inner->peerAfter(inPeer, inMsg, outPeer, outMsg);
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
|
2014-08-22 07:41:39 +00:00
|
|
|
void DialogsWidget::scrollToPeer(const PeerId &peer, MsgId msgId) {
|
2016-11-05 08:36:24 +00:00
|
|
|
_inner->scrollToPeer(peer, msgId);
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
|
2015-11-13 15:14:33 +00:00
|
|
|
void DialogsWidget::removeDialog(History *history) {
|
2016-11-05 08:36:24 +00:00
|
|
|
_inner->removeDialog(history);
|
2014-05-30 08:53:19 +00:00
|
|
|
onFilterUpdate();
|
|
|
|
}
|
|
|
|
|
2016-04-09 18:45:55 +00:00
|
|
|
Dialogs::IndexedList *DialogsWidget::contactsList() {
|
2016-11-05 08:36:24 +00:00
|
|
|
return _inner->contactsList();
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
|
2016-04-09 18:45:55 +00:00
|
|
|
Dialogs::IndexedList *DialogsWidget::dialogsList() {
|
2016-11-05 08:36:24 +00:00
|
|
|
return _inner->dialogsList();
|
2015-06-15 17:19:24 +00:00
|
|
|
}
|
|
|
|
|
2014-12-12 16:27:03 +00:00
|
|
|
bool DialogsWidget::onCancelSearch() {
|
2016-11-04 11:14:47 +00:00
|
|
|
bool clearing = !_filter->getLastText().isEmpty();
|
2015-09-13 08:41:27 +00:00
|
|
|
if (_searchRequest) {
|
|
|
|
MTP::cancel(_searchRequest);
|
|
|
|
_searchRequest = 0;
|
|
|
|
}
|
2015-08-04 15:01:47 +00:00
|
|
|
if (_searchInPeer && !clearing) {
|
2016-02-08 14:54:55 +00:00
|
|
|
if (Adaptive::OneColumn()) {
|
2015-12-13 11:36:08 +00:00
|
|
|
Ui::showPeerHistory(_searchInPeer, ShowAtUnreadMsgId);
|
2015-08-04 15:01:47 +00:00
|
|
|
}
|
2016-11-16 12:06:02 +00:00
|
|
|
setSearchInPeer(nullptr);
|
2015-08-04 15:01:47 +00:00
|
|
|
clearing = true;
|
|
|
|
}
|
2016-11-05 08:36:24 +00:00
|
|
|
_inner->clearFilter();
|
2016-11-04 11:14:47 +00:00
|
|
|
_filter->clear();
|
|
|
|
_filter->updatePlaceholder();
|
2014-07-04 11:12:54 +00:00
|
|
|
onFilterUpdate();
|
2014-12-12 16:27:03 +00:00
|
|
|
return clearing;
|
2014-07-04 11:12:54 +00:00
|
|
|
}
|
|
|
|
|
2015-08-04 15:01:47 +00:00
|
|
|
void DialogsWidget::onCancelSearchInPeer() {
|
2015-09-13 08:41:27 +00:00
|
|
|
if (_searchRequest) {
|
|
|
|
MTP::cancel(_searchRequest);
|
|
|
|
_searchRequest = 0;
|
|
|
|
}
|
2015-08-04 15:01:47 +00:00
|
|
|
if (_searchInPeer) {
|
2016-02-08 14:54:55 +00:00
|
|
|
if (Adaptive::OneColumn() && !App::main()->selectingPeer()) {
|
2015-12-13 11:36:08 +00:00
|
|
|
Ui::showPeerHistory(_searchInPeer, ShowAtUnreadMsgId);
|
2015-08-04 15:01:47 +00:00
|
|
|
}
|
2016-11-16 12:06:02 +00:00
|
|
|
setSearchInPeer(nullptr);
|
2015-08-04 15:01:47 +00:00
|
|
|
}
|
2016-11-05 08:36:24 +00:00
|
|
|
_inner->clearFilter();
|
2016-11-04 11:14:47 +00:00
|
|
|
_filter->clear();
|
|
|
|
_filter->updatePlaceholder();
|
2015-08-04 15:01:47 +00:00
|
|
|
onFilterUpdate();
|
2016-02-08 14:54:55 +00:00
|
|
|
if (!Adaptive::OneColumn() && !App::main()->selectingPeer()) {
|
2015-08-04 15:01:47 +00:00
|
|
|
emit cancelled();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-09-24 16:05:06 +00:00
|
|
|
void DialogsWidget::onDialogMoved(int movedFrom, int movedTo) {
|
2016-11-05 08:36:24 +00:00
|
|
|
int32 st = _scroll->scrollTop();
|
2015-09-24 16:05:06 +00:00
|
|
|
if (st > movedTo && st < movedFrom) {
|
2016-11-05 08:36:24 +00:00
|
|
|
_scroll->scrollToY(st + st::dialogsRowHeight);
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
}
|