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
|
2015-10-03 13:16:42 +00:00
|
|
|
Copyright (c) 2014-2015 John Preston, https://desktop.telegram.org
|
2014-05-30 08:53:19 +00:00
|
|
|
*/
|
|
|
|
#include "stdafx.h"
|
|
|
|
#include "style.h"
|
|
|
|
#include "lang.h"
|
|
|
|
|
2015-10-15 10:18:24 +00:00
|
|
|
#include "application.h"
|
2014-05-30 08:53:19 +00:00
|
|
|
#include "window.h"
|
|
|
|
#include "dialogswidget.h"
|
|
|
|
#include "mainwidget.h"
|
|
|
|
#include "boxes/addcontactbox.h"
|
2015-04-02 10:33:19 +00:00
|
|
|
#include "boxes/contactsbox.h"
|
2014-05-30 08:53:19 +00:00
|
|
|
|
2015-03-24 10:00:27 +00:00
|
|
|
#include "localstorage.h"
|
|
|
|
|
2015-11-18 13:11:56 +00:00
|
|
|
DialogsInner::DialogsInner(QWidget *parent, MainWidget *main) : SplittedWidget(parent)
|
|
|
|
, dialogs(DialogsSortByDate)
|
|
|
|
, contactsNoDialogs(DialogsSortByName)
|
|
|
|
, contacts(DialogsSortByName)
|
|
|
|
, sel(0)
|
|
|
|
, contactSel(false)
|
|
|
|
, selByMouse(false)
|
|
|
|
, _hashtagSel(-1)
|
|
|
|
, _filteredSel(-1)
|
|
|
|
, _searchedCount(0)
|
|
|
|
, _searchedMigratedCount(0)
|
|
|
|
, _searchedSel(-1)
|
|
|
|
, _peopleSel(-1)
|
|
|
|
, _lastSearchDate(0)
|
|
|
|
, _lastSearchPeer(0)
|
|
|
|
, _lastSearchId(0)
|
|
|
|
, _lastSearchMigratedId(0)
|
|
|
|
, _state(DefaultState)
|
|
|
|
, _addContactLnk(this, lang(lng_add_contact_button))
|
|
|
|
, _cancelSearchInPeer(this, st::btnCancelSearch)
|
|
|
|
, _overDelete(false)
|
|
|
|
, _searchInPeer(0)
|
|
|
|
, _searchInMigrated(0) {
|
2015-10-11 08:37:24 +00:00
|
|
|
connect(App::wnd(), SIGNAL(imageLoaded()), this, SLOT(update()));
|
|
|
|
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*)));
|
|
|
|
connect(main, SIGNAL(dialogRowReplaced(DialogRow*,DialogRow*)), this, SLOT(onDialogRowReplaced(DialogRow*,DialogRow*)));
|
|
|
|
connect(&_addContactLnk, SIGNAL(clicked()), App::wnd(), SLOT(onShowAddContact()));
|
2015-08-04 15:01:47 +00:00
|
|
|
connect(&_cancelSearchInPeer, SIGNAL(clicked()), this, SIGNAL(cancelSearchInPeer()));
|
|
|
|
_cancelSearchInPeer.hide();
|
2014-11-25 12:15:29 +00:00
|
|
|
refresh(false);
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
|
2015-09-29 13:24:39 +00:00
|
|
|
int32 DialogsInner::filteredOffset() const {
|
2015-11-18 13:11:56 +00:00
|
|
|
return _hashtagResults.size() * st::mentionHeight;
|
2015-03-24 10:00:27 +00:00
|
|
|
}
|
|
|
|
|
2015-09-29 13:24:39 +00:00
|
|
|
int32 DialogsInner::peopleOffset() const {
|
2015-11-18 13:11:56 +00:00
|
|
|
return filteredOffset() + (_filterResults.size() * st::dlgHeight) + st::searchedBarHeight;
|
2015-03-24 10:00:27 +00:00
|
|
|
}
|
|
|
|
|
2015-09-29 13:24:39 +00:00
|
|
|
int32 DialogsInner::searchedOffset() const {
|
2015-11-18 13:11:56 +00:00
|
|
|
int32 result = peopleOffset() + (_peopleResults.isEmpty() ? 0 : ((_peopleResults.size() * st::dlgHeight) + st::searchedBarHeight));
|
2015-08-04 15:01:47 +00:00
|
|
|
if (_searchInPeer) result += st::dlgHeight;
|
|
|
|
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;
|
|
|
|
|
2015-09-29 13:24:39 +00:00
|
|
|
QRect r(region.boundingRect());
|
2015-10-01 14:05:05 +00:00
|
|
|
if (!paintingOther) {
|
|
|
|
p.setClipRect(r);
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
2015-09-29 13:24:39 +00:00
|
|
|
|
2014-07-04 11:12:54 +00:00
|
|
|
if (_state == DefaultState) {
|
2014-05-30 08:53:19 +00:00
|
|
|
int32 otherStart = dialogs.list.count * st::dlgHeight;
|
|
|
|
PeerData *active = App::main()->activePeer(), *selected = sel ? sel->history->peer : 0;
|
|
|
|
if (otherStart) {
|
2015-09-29 13:24:39 +00:00
|
|
|
dialogs.list.paint(p, fullWidth(), r.top(), r.top() + r.height(), active, selected, paintingOther);
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
2015-08-07 12:11:50 +00:00
|
|
|
if (contactsNoDialogs.list.count && false) {
|
2015-09-29 13:24:39 +00:00
|
|
|
contactsNoDialogs.list.paint(p, fullWidth(), r.top() - otherStart, r.top() + r.height() - otherStart, active, selected, paintingOther);
|
2014-05-30 08:53:19 +00:00
|
|
|
} else if (!otherStart) {
|
2015-09-29 13:24:39 +00:00
|
|
|
p.fillRect(r, st::white->b);
|
|
|
|
if (!paintingOther) {
|
|
|
|
p.setFont(st::noContactsFont->f);
|
|
|
|
p.setPen(st::noContactsColor->p);
|
|
|
|
p.drawText(QRect(0, 0, fullWidth(), st::noContactsHeight - (cContactsReceived() ? st::noContactsFont->height : 0)), lang(cContactsReceived() ? lng_no_chats : lng_contacts_loading), style::al_center);
|
|
|
|
}
|
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()) {
|
2015-10-01 14:05:05 +00:00
|
|
|
int32 w = fullWidth(), htagwidth = w - st::dlgPaddingHor * 2;
|
|
|
|
|
2015-03-24 10:00:27 +00:00
|
|
|
p.setFont(st::mentionFont->f);
|
|
|
|
p.setPen(st::black->p);
|
|
|
|
for (; from < to; ++from) {
|
2015-11-18 13:11:56 +00:00
|
|
|
bool selected = (from == _hashtagSel);
|
2015-09-29 13:24:39 +00:00
|
|
|
p.fillRect(0, 0, w, st::mentionHeight, (selected ? st::mentionBgOver : st::white)->b);
|
|
|
|
if (!paintingOther) {
|
|
|
|
if (selected) {
|
|
|
|
int skip = (st::mentionHeight - st::notifyClose.icon.pxHeight()) / 2;
|
|
|
|
p.drawPixmap(QPoint(w - st::notifyClose.icon.pxWidth() - skip, skip), App::sprite(), st::notifyClose.icon);
|
2015-06-15 17:19:24 +00:00
|
|
|
|
|
|
|
}
|
2015-11-18 13:11:56 +00:00
|
|
|
QString first = (_hashtagFilter.size() < 2) ? QString() : ('#' + _hashtagResults.at(from).mid(0, _hashtagFilter.size() - 1)), second = (_hashtagFilter.size() < 2) ? ('#' + _hashtagResults.at(from)) : _hashtagResults.at(from).mid(_hashtagFilter.size() - 1);
|
2015-10-03 10:09:09 +00:00
|
|
|
int32 firstwidth = st::mentionFont->width(first), 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
|
|
|
|
2015-09-29 13:24:39 +00:00
|
|
|
p.setFont(st::mentionFont->f);
|
|
|
|
if (!first.isEmpty()) {
|
|
|
|
p.setPen((selected ? st::mentionFgOverActive : st::mentionFgActive)->p);
|
|
|
|
p.drawText(st::dlgPaddingHor, st::mentionTop + st::mentionFont->ascent, first);
|
|
|
|
}
|
|
|
|
if (!second.isEmpty()) {
|
|
|
|
p.setPen((selected ? st::mentionFgOver : st::mentionFg)->p);
|
|
|
|
p.drawText(st::dlgPaddingHor + firstwidth, st::mentionTop + st::mentionFont->ascent, second);
|
|
|
|
}
|
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()) {
|
2015-03-24 10:00:27 +00:00
|
|
|
int32 skip = filteredOffset();
|
2015-11-18 13:11:56 +00:00
|
|
|
int32 from = floorclamp(r.y() - skip, st::dlgHeight, 0, _filterResults.size());
|
|
|
|
int32 to = ceilclamp(r.y() + r.height() - skip, st::dlgHeight, 0, _filterResults.size());
|
2014-07-13 09:50:38 +00:00
|
|
|
p.translate(0, from * st::dlgHeight);
|
2015-11-18 13:11:56 +00:00
|
|
|
if (from < _filterResults.size()) {
|
2015-10-01 14:05:05 +00:00
|
|
|
int32 w = fullWidth();
|
2015-11-18 13:11:56 +00:00
|
|
|
PeerData *act = App::main()->activePeer();
|
|
|
|
MsgId actId = App::main()->activeMsgId();
|
2014-05-30 08:53:19 +00:00
|
|
|
for (; from < to; ++from) {
|
2015-11-18 13:11:56 +00:00
|
|
|
bool active = ((_filterResults[from]->history->peer == act) || (_filterResults[from]->history->peer->migrateTo() && _filterResults[from]->history->peer->migrateTo() == act)) && !actId;
|
|
|
|
bool selected = (from == _filteredSel);
|
|
|
|
_filterResults[from]->paint(p, w, active, selected, paintingOther);
|
2014-07-04 11:12:54 +00:00
|
|
|
p.translate(0, st::dlgHeight);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-07-13 09:50:38 +00:00
|
|
|
|
2015-11-18 13:11:56 +00:00
|
|
|
if (!_peopleResults.isEmpty()) {
|
2015-09-29 13:24:39 +00:00
|
|
|
p.fillRect(0, 0, fullWidth(), st::searchedBarHeight, st::searchedBarBG->b);
|
|
|
|
if (!paintingOther) {
|
|
|
|
p.setFont(st::searchedBarFont->f);
|
|
|
|
p.setPen(st::searchedBarColor->p);
|
|
|
|
p.drawText(QRect(0, 0, fullWidth(), st::searchedBarHeight), lang(lng_search_global_results), style::al_center);
|
|
|
|
}
|
2014-10-22 18:39:03 +00:00
|
|
|
p.translate(0, st::searchedBarHeight);
|
2015-09-29 13:24:39 +00:00
|
|
|
|
2015-03-24 10:00:27 +00:00
|
|
|
int32 skip = peopleOffset();
|
2015-11-18 13:11:56 +00:00
|
|
|
int32 from = floorclamp(r.y() - skip, st::dlgHeight, 0, _peopleResults.size());
|
|
|
|
int32 to = ceilclamp(r.y() + r.height() - skip, st::dlgHeight, 0, _peopleResults.size());
|
2014-10-22 18:39:03 +00:00
|
|
|
p.translate(0, from * st::dlgHeight);
|
2015-11-18 13:11:56 +00:00
|
|
|
if (from < _peopleResults.size()) {
|
2015-10-01 14:05:05 +00:00
|
|
|
int32 w = fullWidth();
|
2015-11-18 13:11:56 +00:00
|
|
|
PeerData *act = App::main()->activePeer();
|
|
|
|
MsgId actId = App::main()->activeMsgId();
|
2014-10-22 18:39:03 +00:00
|
|
|
for (; from < to; ++from) {
|
2015-11-18 13:11:56 +00:00
|
|
|
bool active = ((_peopleResults[from] == act) || (_peopleResults[from]->migrateTo() && _peopleResults[from]->migrateTo() == act)) && !actId;
|
|
|
|
bool selected = (from == _peopleSel);
|
|
|
|
peopleResultPaint(_peopleResults[from], p, w, active, selected, paintingOther);
|
2014-10-22 18:39:03 +00:00
|
|
|
p.translate(0, st::dlgHeight);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-08-04 15:01:47 +00:00
|
|
|
if (_searchInPeer) {
|
2015-09-29 13:24:39 +00:00
|
|
|
searchInPeerPaint(p, fullWidth(), paintingOther);
|
2015-08-04 15:01:47 +00:00
|
|
|
p.translate(0, st::dlgHeight);
|
2015-11-18 13:11:56 +00:00
|
|
|
if (_state == FilteredState && _searchResults.isEmpty()) {
|
2015-09-29 13:24:39 +00:00
|
|
|
p.fillRect(0, 0, fullWidth(), st::searchedBarHeight, st::searchedBarBG->b);
|
|
|
|
if (!paintingOther) {
|
|
|
|
p.setFont(st::searchedBarFont->f);
|
|
|
|
p.setPen(st::searchedBarColor->p);
|
|
|
|
p.drawText(QRect(0, 0, fullWidth(), st::searchedBarHeight), lang(lng_dlg_search_for_messages), style::al_center);
|
|
|
|
}
|
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));
|
2015-09-29 13:24:39 +00:00
|
|
|
p.fillRect(0, 0, fullWidth(), st::searchedBarHeight, st::searchedBarBG->b);
|
|
|
|
if (!paintingOther) {
|
|
|
|
p.setFont(st::searchedBarFont->f);
|
|
|
|
p.setPen(st::searchedBarColor->p);
|
|
|
|
p.drawText(QRect(0, 0, fullWidth(), st::searchedBarHeight), text, style::al_center);
|
|
|
|
}
|
2014-07-13 09:50:38 +00:00
|
|
|
p.translate(0, st::searchedBarHeight);
|
|
|
|
|
2015-03-24 10:00:27 +00:00
|
|
|
int32 skip = searchedOffset();
|
2015-11-18 13:11:56 +00:00
|
|
|
int32 from = floorclamp(r.y() - skip, st::dlgHeight, 0, _searchResults.size());
|
|
|
|
int32 to = ceilclamp(r.y() + r.height() - skip, st::dlgHeight, 0, _searchResults.size());
|
2014-10-22 18:39:03 +00:00
|
|
|
p.translate(0, from * st::dlgHeight);
|
2015-11-18 13:11:56 +00:00
|
|
|
if (from < _searchResults.size()) {
|
2015-10-01 14:05:05 +00:00
|
|
|
int32 w = fullWidth();
|
2015-11-18 13:11:56 +00:00
|
|
|
PeerData *act = App::main()->activePeer();
|
|
|
|
MsgId actId = App::main()->activeMsgId();
|
2014-07-04 11:12:54 +00:00
|
|
|
for (; from < to; ++from) {
|
2015-11-18 13:11:56 +00:00
|
|
|
bool active = (_searchResults[from]->_item->history()->peer == act && _searchResults[from]->_item->id == actId) || (_searchResults[from]->_item->history()->peer->migrateTo() && _searchResults[from]->_item->history()->peer->migrateTo() == act && _searchResults[from]->_item->id == -actId);
|
|
|
|
bool selected = (from == _searchedSel);
|
|
|
|
_searchResults[from]->paint(p, w, active, selected, paintingOther);
|
2014-05-30 08:53:19 +00:00
|
|
|
p.translate(0, st::dlgHeight);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-09-29 13:24:39 +00:00
|
|
|
void DialogsInner::peopleResultPaint(PeerData *peer, Painter &p, int32 w, bool act, bool sel, bool onlyBackground) const {
|
2014-10-22 18:39:03 +00:00
|
|
|
QRect fullRect(0, 0, w, st::dlgHeight);
|
|
|
|
p.fillRect(fullRect, (act ? st::dlgActiveBG : (sel ? st::dlgHoverBG : st::dlgBG))->b);
|
2015-09-29 13:24:39 +00:00
|
|
|
if (onlyBackground) return;
|
2014-10-22 18:39:03 +00:00
|
|
|
|
2015-09-06 10:17:09 +00:00
|
|
|
History *history = App::history(peer->id);
|
2014-10-22 18:39:03 +00:00
|
|
|
|
2015-11-18 13:11:56 +00:00
|
|
|
if (peer->migrateTo()) {
|
|
|
|
p.drawPixmap(st::dlgPaddingHor, st::dlgPaddingVer, peer->migrateTo()->photo->pix(st::dlgPhotoSize));
|
|
|
|
} else {
|
|
|
|
p.drawPixmap(st::dlgPaddingHor, st::dlgPaddingVer, peer->photo->pix(st::dlgPhotoSize));
|
|
|
|
}
|
2014-10-22 18:39:03 +00:00
|
|
|
|
|
|
|
int32 nameleft = st::dlgPaddingHor + st::dlgPhotoSize + st::dlgPhotoPadding;
|
|
|
|
int32 namewidth = w - nameleft - st::dlgPaddingHor;
|
|
|
|
QRect rectForName(nameleft, st::dlgPaddingVer + st::dlgNameTop, namewidth, st::msgNameFont->height);
|
|
|
|
|
|
|
|
// draw chat icon
|
2015-09-23 17:43:08 +00:00
|
|
|
if (peer->isChat()) {
|
2015-09-15 08:50:54 +00:00
|
|
|
p.drawPixmap(QPoint(rectForName.left() + st::dlgChatImgPos.x(), rectForName.top() + st::dlgChatImgPos.y()), App::sprite(), (act ? st::dlgActiveChatImg : st::dlgChatImg));
|
|
|
|
rectForName.setLeft(rectForName.left() + st::dlgImgSkip);
|
2015-09-23 17:43:08 +00:00
|
|
|
} else if (peer->isChannel()) {
|
2015-09-15 08:50:54 +00:00
|
|
|
p.drawPixmap(QPoint(rectForName.left() + st::dlgChannelImgPos.x(), rectForName.top() + st::dlgChannelImgPos.y()), App::sprite(), (act ? st::dlgActiveChannelImg : st::dlgChannelImg));
|
|
|
|
rectForName.setLeft(rectForName.left() + st::dlgImgSkip);
|
2014-10-22 18:39:03 +00:00
|
|
|
}
|
2015-10-29 15:52:39 +00:00
|
|
|
if (peer->isVerified()) {
|
|
|
|
rectForName.setWidth(rectForName.width() - st::verifiedCheck.pxWidth() - st::verifiedCheckPos.x());
|
|
|
|
p.drawSprite(rectForName.topLeft() + QPoint(qMin(peer->dialogName().maxWidth(), rectForName.width()), 0) + st::verifiedCheckPos, (act ? st::verifiedCheckInv : st::verifiedCheck));
|
|
|
|
}
|
|
|
|
|
2014-10-22 18:39:03 +00:00
|
|
|
QRect tr(nameleft, st::dlgPaddingVer + st::dlgFont->height + st::dlgSep, namewidth, st::dlgFont->height);
|
|
|
|
p.setFont(st::dlgHistFont->f);
|
2015-09-06 10:17:09 +00:00
|
|
|
QString username = peer->userName();
|
2015-11-18 13:11:56 +00:00
|
|
|
if (!act && username.toLower().startsWith(_peopleQuery)) {
|
|
|
|
QString first = '@' + username.mid(0, _peopleQuery.size()), second = username.mid(_peopleQuery.size());
|
2015-10-03 10:09:09 +00:00
|
|
|
int32 w = st::dlgHistFont->width(first);
|
2014-10-23 16:05:33 +00:00
|
|
|
if (w >= tr.width()) {
|
|
|
|
p.setPen(st::dlgSystemColor->p);
|
2015-10-03 10:09:09 +00:00
|
|
|
p.drawText(tr.left(), tr.top() + st::dlgHistFont->ascent, st::dlgHistFont->elided(first, tr.width()));
|
2014-10-23 16:05:33 +00:00
|
|
|
} else {
|
|
|
|
p.setPen(st::dlgSystemColor->p);
|
|
|
|
p.drawText(tr.left(), tr.top() + st::dlgHistFont->ascent, first);
|
|
|
|
p.setPen(st::dlgTextColor->p);
|
2015-10-03 10:09:09 +00:00
|
|
|
p.drawText(tr.left() + w, tr.top() + st::dlgHistFont->ascent, st::dlgHistFont->elided(second, tr.width() - w));
|
2014-10-23 16:05:33 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
p.setPen((act ? st::dlgActiveColor : st::dlgSystemColor)->p);
|
2015-10-03 10:09:09 +00:00
|
|
|
p.drawText(tr.left(), tr.top() + st::dlgHistFont->ascent, st::dlgHistFont->elided('@' + username, tr.width()));
|
2014-10-23 16:05:33 +00:00
|
|
|
}
|
2014-10-22 18:39:03 +00:00
|
|
|
|
|
|
|
p.setPen((act ? st::dlgActiveColor : st::dlgNameColor)->p);
|
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
|
|
|
}
|
|
|
|
|
2015-09-29 13:24:39 +00:00
|
|
|
void DialogsInner::searchInPeerPaint(Painter &p, int32 w, bool onlyBackground) const {
|
2015-08-04 15:01:47 +00:00
|
|
|
QRect fullRect(0, 0, w, st::dlgHeight);
|
|
|
|
p.fillRect(fullRect, st::dlgBG->b);
|
2015-09-29 13:24:39 +00:00
|
|
|
if (onlyBackground) return;
|
2015-08-04 15:01:47 +00:00
|
|
|
|
|
|
|
p.drawPixmap(st::dlgPaddingHor, st::dlgPaddingVer, _searchInPeer->photo->pix(st::dlgPhotoSize));
|
|
|
|
|
|
|
|
int32 nameleft = st::dlgPaddingHor + st::dlgPhotoSize + st::dlgPhotoPadding;
|
|
|
|
int32 namewidth = w - nameleft - st::dlgPaddingHor * 2 - st::btnCancelSearch.width;
|
|
|
|
QRect rectForName(nameleft, st::dlgPaddingVer + st::dlgNameTop, namewidth, st::msgNameFont->height);
|
|
|
|
|
|
|
|
// draw chat icon
|
2015-09-15 08:50:54 +00:00
|
|
|
if (_searchInPeer->isChat()) {
|
|
|
|
p.drawPixmap(QPoint(rectForName.left() + st::dlgChatImgPos.x(), rectForName.top() + st::dlgChatImgPos.y()), App::sprite(), st::dlgChatImg);
|
|
|
|
rectForName.setLeft(rectForName.left() + st::dlgImgSkip);
|
|
|
|
} else if (_searchInPeer->isChannel()) {
|
|
|
|
p.drawPixmap(QPoint(rectForName.left() + st::dlgChannelImgPos.x(), rectForName.top() + st::dlgChannelImgPos.y()), App::sprite(), st::dlgChannelImg);
|
|
|
|
rectForName.setLeft(rectForName.left() + st::dlgImgSkip);
|
2015-08-04 15:01:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
QRect tr(nameleft, st::dlgPaddingVer + st::dlgFont->height + st::dlgSep, namewidth, st::dlgFont->height);
|
|
|
|
p.setFont(st::dlgHistFont->f);
|
|
|
|
p.setPen(st::dlgTextColor->p);
|
2015-11-19 11:28:17 +00:00
|
|
|
p.drawText(tr.left(), tr.top() + st::dlgHistFont->ascent, st::dlgHistFont->elided(lang((_searchInPeer->isChannel() && !_searchInPeer->isMegagroup()) ? lng_dlg_search_channel : lng_dlg_search_chat), tr.width()));
|
2015-08-04 15:01:47 +00:00
|
|
|
|
|
|
|
p.setPen(st::dlgNameColor->p);
|
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) {
|
2014-05-30 08:53:19 +00:00
|
|
|
lastMousePos = mapToGlobal(e->pos());
|
|
|
|
selByMouse = true;
|
|
|
|
onUpdateSelected(true);
|
|
|
|
}
|
|
|
|
|
2015-09-29 13:24:39 +00:00
|
|
|
void DialogsInner::onUpdateSelected(bool force) {
|
2014-05-30 08:53:19 +00:00
|
|
|
QPoint mouse(mapFromGlobal(lastMousePos));
|
2014-06-16 09:31:10 +00:00
|
|
|
if ((!force && !rect().contains(mouse)) || !selByMouse) return;
|
2014-05-30 08:53:19 +00:00
|
|
|
|
|
|
|
int w = width(), mouseY = mouse.y();
|
2015-03-24 15:18:20 +00:00
|
|
|
_overDelete = false;
|
2014-07-04 11:12:54 +00:00
|
|
|
if (_state == DefaultState) {
|
2014-05-30 08:53:19 +00:00
|
|
|
DialogRow *newSel = dialogs.list.rowAtY(mouseY, st::dlgHeight);
|
|
|
|
int32 otherStart = dialogs.list.count * st::dlgHeight;
|
|
|
|
if (newSel) {
|
|
|
|
contactSel = false;
|
|
|
|
} else {
|
2015-08-07 12:11:50 +00:00
|
|
|
newSel = 0;// contactsNoDialogs.list.rowAtY(mouseY - otherStart, st::dlgHeight);
|
2014-05-30 08:53:19 +00:00
|
|
|
contactSel = true;
|
|
|
|
}
|
|
|
|
if (newSel != sel) {
|
2015-09-29 13:24:39 +00:00
|
|
|
updateSelectedRow();
|
2014-05-30 08:53:19 +00:00
|
|
|
sel = newSel;
|
2015-09-29 13:24:39 +00:00
|
|
|
updateSelectedRow();
|
2014-05-30 08:53:19 +00:00
|
|
|
setCursor(sel ? style::cur_pointer : style::cur_default);
|
|
|
|
}
|
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()) {
|
2015-09-29 13:24:39 +00:00
|
|
|
int32 skip = 0, newHashtagSel = (mouseY >= skip) ? ((mouseY - skip) / int32(st::mentionHeight)) : -1;
|
2015-11-18 13:11:56 +00:00
|
|
|
if (newHashtagSel < 0 || newHashtagSel >= _hashtagResults.size()) {
|
2015-03-24 10:00:27 +00:00
|
|
|
newHashtagSel = -1;
|
|
|
|
}
|
2015-11-18 13:11:56 +00:00
|
|
|
if (newHashtagSel != _hashtagSel) {
|
2015-09-29 13:24:39 +00:00
|
|
|
updateSelectedRow();
|
2015-11-18 13:11:56 +00:00
|
|
|
_hashtagSel = newHashtagSel;
|
2015-09-29 13:24:39 +00:00
|
|
|
updateSelectedRow();
|
2015-11-18 13:11:56 +00:00
|
|
|
setCursor((_hashtagSel >= 0) ? style::cur_pointer : style::cur_default);
|
2015-03-24 10:00:27 +00:00
|
|
|
}
|
2015-11-18 13:11:56 +00:00
|
|
|
if (_hashtagSel >= 0) {
|
2015-03-24 15:18:20 +00:00
|
|
|
_overDelete = (mouse.x() >= w - st::mentionHeight);
|
|
|
|
}
|
2015-03-24 10:00:27 +00:00
|
|
|
}
|
2015-11-18 13:11:56 +00:00
|
|
|
if (!_filterResults.isEmpty()) {
|
2015-09-29 13:24:39 +00:00
|
|
|
int32 skip = filteredOffset(), newFilteredSel = (mouseY >= skip) ? ((mouseY - skip) / int32(st::dlgHeight)) : -1;
|
2015-11-18 13:11:56 +00:00
|
|
|
if (newFilteredSel < 0 || newFilteredSel >= _filterResults.size()) {
|
2014-05-30 08:53:19 +00:00
|
|
|
newFilteredSel = -1;
|
|
|
|
}
|
2015-11-18 13:11:56 +00:00
|
|
|
if (newFilteredSel != _filteredSel) {
|
2015-09-29 13:24:39 +00:00
|
|
|
updateSelectedRow();
|
2015-11-18 13:11:56 +00:00
|
|
|
_filteredSel = newFilteredSel;
|
2015-09-29 13:24:39 +00:00
|
|
|
updateSelectedRow();
|
2015-11-18 13:11:56 +00:00
|
|
|
setCursor((_filteredSel >= 0) ? style::cur_pointer : style::cur_default);
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
}
|
2015-11-18 13:11:56 +00:00
|
|
|
if (!_peopleResults.isEmpty()) {
|
2015-09-29 13:24:39 +00:00
|
|
|
int32 skip = peopleOffset(), newPeopleSel = (mouseY >= skip) ? ((mouseY - skip) / int32(st::dlgHeight)) : -1;
|
2015-11-18 13:11:56 +00:00
|
|
|
if (newPeopleSel < 0 || newPeopleSel >= _peopleResults.size()) {
|
2014-10-22 18:39:03 +00:00
|
|
|
newPeopleSel = -1;
|
|
|
|
}
|
2015-11-18 13:11:56 +00:00
|
|
|
if (newPeopleSel != _peopleSel) {
|
2015-09-29 13:24:39 +00:00
|
|
|
updateSelectedRow();
|
2015-11-18 13:11:56 +00:00
|
|
|
_peopleSel = newPeopleSel;
|
2015-09-29 13:24:39 +00:00
|
|
|
updateSelectedRow();
|
2015-11-18 13:11:56 +00:00
|
|
|
setCursor((_peopleSel >= 0) ? style::cur_pointer : style::cur_default);
|
2014-10-22 18:39:03 +00:00
|
|
|
}
|
|
|
|
}
|
2015-11-18 13:11:56 +00:00
|
|
|
if (_state == SearchedState && !_searchResults.isEmpty()) {
|
2015-09-29 13:24:39 +00:00
|
|
|
int32 skip = searchedOffset(), newSearchedSel = (mouseY >= skip) ? ((mouseY - skip) / int32(st::dlgHeight)) : -1;
|
2015-11-18 13:11:56 +00:00
|
|
|
if (newSearchedSel < 0 || newSearchedSel >= _searchResults.size()) {
|
2014-07-04 11:12:54 +00:00
|
|
|
newSearchedSel = -1;
|
|
|
|
}
|
2015-11-18 13:11:56 +00:00
|
|
|
if (newSearchedSel != _searchedSel) {
|
2015-09-29 13:24:39 +00:00
|
|
|
updateSelectedRow();
|
2015-11-18 13:11:56 +00:00
|
|
|
_searchedSel = newSearchedSel;
|
2015-09-29 13:24:39 +00:00
|
|
|
updateSelectedRow();
|
2015-11-18 13:11:56 +00:00
|
|
|
setCursor((_searchedSel >= 0) ? style::cur_pointer : style::cur_default);
|
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::mousePressEvent(QMouseEvent *e) {
|
2014-05-30 08:53:19 +00:00
|
|
|
lastMousePos = mapToGlobal(e->pos());
|
|
|
|
selByMouse = true;
|
|
|
|
onUpdateSelected(true);
|
|
|
|
if (e->button() == Qt::LeftButton) {
|
|
|
|
choosePeer();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-09-29 13:24:39 +00:00
|
|
|
void DialogsInner::resizeEvent(QResizeEvent *e) {
|
2014-11-25 12:15:29 +00:00
|
|
|
_addContactLnk.move((width() - _addContactLnk.width()) / 2, (st::noContactsHeight + st::noContactsFont->height) / 2);
|
2015-08-04 15:01:47 +00:00
|
|
|
_cancelSearchInPeer.move(width() - st::dlgPaddingHor - st::btnCancelSearch.width, (st::dlgHeight - st::btnCancelSearch.height) / 2);
|
2014-11-25 12:15:29 +00:00
|
|
|
}
|
|
|
|
|
2015-09-29 13:24:39 +00:00
|
|
|
void DialogsInner::onDialogRowReplaced(DialogRow *oldRow, DialogRow *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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (sel == oldRow) {
|
|
|
|
sel = newRow;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-09-29 13:24:39 +00:00
|
|
|
void DialogsInner::createDialog(History *history) {
|
2015-09-24 16:05:06 +00:00
|
|
|
bool creating = history->dialogs.isEmpty();
|
|
|
|
if (creating) {
|
|
|
|
history->dialogs = dialogs.addToEnd(history);
|
|
|
|
contactsNoDialogs.del(history->peer, history->dialogs[0]);
|
|
|
|
}
|
2014-05-30 08:53:19 +00:00
|
|
|
|
2015-09-24 16:05:06 +00:00
|
|
|
History::DialogLinks links = history->dialogs;
|
|
|
|
int32 movedFrom = links[0]->pos * st::dlgHeight;
|
|
|
|
dialogs.adjustByPos(links);
|
|
|
|
int32 movedTo = links[0]->pos * st::dlgHeight;
|
2014-05-30 08:53:19 +00:00
|
|
|
|
2015-09-24 16:05:06 +00:00
|
|
|
emit dialogMoved(movedFrom, movedTo);
|
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();
|
2015-09-29 13:24:39 +00:00
|
|
|
} else if (_state == DefaultState && movedFrom != movedTo) {
|
2015-10-23 16:06:56 +00:00
|
|
|
update(0, qMin(movedFrom, movedTo), fullWidth(), qAbs(movedFrom - movedTo) + st::dlgHeight);
|
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;
|
|
|
|
if (sel && sel->history == history) {
|
2014-05-30 08:53:19 +00:00
|
|
|
sel = 0;
|
|
|
|
}
|
2015-11-13 15:14:33 +00:00
|
|
|
dialogs.del(history->peer);
|
2014-05-30 08:53:19 +00:00
|
|
|
history->dialogs = History::DialogLinks();
|
2015-09-23 17:43:08 +00:00
|
|
|
history->clearNotifications();
|
|
|
|
if (App::wnd()) App::wnd()->notifyClear(history);
|
2015-11-13 15:14:33 +00:00
|
|
|
if (contacts.list.rowByPeer.constFind(history->peer->id) != contacts.list.rowByPeer.cend()) {
|
|
|
|
if (contactsNoDialogs.list.rowByPeer.constFind(history->peer->id) == contactsNoDialogs.list.rowByPeer.cend()) {
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
2015-09-29 13:24:39 +00:00
|
|
|
void DialogsInner::removeContact(UserData *user) {
|
2014-05-30 08:53:19 +00:00
|
|
|
if (sel && sel->history->peer == user) {
|
|
|
|
sel = 0;
|
|
|
|
}
|
|
|
|
contactsNoDialogs.del(user);
|
|
|
|
contacts.del(user);
|
|
|
|
|
|
|
|
refresh();
|
|
|
|
}
|
|
|
|
|
2015-09-29 13:24:39 +00:00
|
|
|
void DialogsInner::dlgUpdated(DialogRow *row) {
|
2014-07-04 11:12:54 +00:00
|
|
|
if (_state == DefaultState) {
|
2015-09-29 13:24:39 +00:00
|
|
|
update(0, row->pos * st::dlgHeight, fullWidth(), st::dlgHeight);
|
2014-07-13 09:50:38 +00:00
|
|
|
} else if (_state == FilteredState || _state == SearchedState) {
|
2015-11-18 13:11:56 +00:00
|
|
|
for (int32 i = 0, l = _filterResults.size(); i < l; ++i) {
|
|
|
|
if (_filterResults.at(i)->history == row->history) {
|
2015-09-29 13:24:39 +00:00
|
|
|
update(0, i * st::dlgHeight, fullWidth(), st::dlgHeight);
|
2014-05-30 08:53:19 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-03 10:09:09 +00:00
|
|
|
void DialogsInner::dlgUpdated(History *history, MsgId msgId) {
|
2014-07-04 11:12:54 +00:00
|
|
|
if (_state == DefaultState) {
|
2014-05-30 08:53:19 +00:00
|
|
|
DialogRow *row = 0;
|
|
|
|
DialogsList::RowByPeer::iterator i = dialogs.list.rowByPeer.find(history->peer->id);
|
|
|
|
if (i != dialogs.list.rowByPeer.cend()) {
|
2015-09-29 13:24:39 +00:00
|
|
|
update(0, i.value()->pos * st::dlgHeight, fullWidth(), st::dlgHeight);
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
2014-07-13 09:50:38 +00:00
|
|
|
} else if (_state == FilteredState || _state == SearchedState) {
|
2015-03-24 10:00:27 +00:00
|
|
|
int32 cnt = 0, add = filteredOffset();
|
2015-11-18 13:11:56 +00:00
|
|
|
for (FilteredDialogs::const_iterator i = _filterResults.cbegin(), e = _filterResults.cend(); i != e; ++i) {
|
2014-05-30 08:53:19 +00:00
|
|
|
if ((*i)->history == history) {
|
2015-10-23 16:06:56 +00:00
|
|
|
update(0, add + cnt * st::dlgHeight, fullWidth(), st::dlgHeight);
|
2014-05-30 08:53:19 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
++cnt;
|
|
|
|
}
|
2015-11-18 13:11:56 +00:00
|
|
|
if (!_peopleResults.isEmpty()) {
|
2015-03-24 10:00:27 +00:00
|
|
|
int32 cnt = 0, add = peopleOffset();
|
2015-11-18 13:11:56 +00:00
|
|
|
for (PeopleResults::const_iterator i = _peopleResults.cbegin(), e = _peopleResults.cend(); i != e; ++i) {
|
2014-10-22 18:39:03 +00:00
|
|
|
if ((*i) == history->peer) {
|
2015-09-29 13:24:39 +00:00
|
|
|
update(0, add + cnt * st::dlgHeight, fullWidth(), st::dlgHeight);
|
2014-10-22 18:39:03 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
++cnt;
|
|
|
|
}
|
|
|
|
}
|
2015-11-18 13:11:56 +00:00
|
|
|
if (!_searchResults.isEmpty()) {
|
2015-03-24 10:00:27 +00:00
|
|
|
int32 cnt = 0, add = searchedOffset();
|
2015-11-18 13:11:56 +00:00
|
|
|
for (SearchResults::const_iterator i = _searchResults.cbegin(), e = _searchResults.cend(); i != e; ++i) {
|
2015-10-03 10:09:09 +00:00
|
|
|
if ((*i)->_item->history() == history && (*i)->_item->id == msgId) {
|
2015-09-29 13:24:39 +00:00
|
|
|
update(0, add + cnt * st::dlgHeight, fullWidth(), st::dlgHeight);
|
2014-07-13 09:50:38 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
++cnt;
|
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);
|
|
|
|
lastMousePos = QCursor::pos();
|
|
|
|
onUpdateSelected(true);
|
|
|
|
}
|
|
|
|
|
2015-09-29 13:24:39 +00:00
|
|
|
void DialogsInner::updateSelectedRow() {
|
|
|
|
if (_state == DefaultState) {
|
|
|
|
if (sel) {
|
|
|
|
update(0, sel->pos * st::dlgHeight, fullWidth(), st::dlgHeight);
|
|
|
|
}
|
|
|
|
} else if (_state == FilteredState || _state == SearchedState) {
|
2015-11-18 13:11:56 +00:00
|
|
|
if (_hashtagSel >= 0) {
|
|
|
|
update(0, _hashtagSel * st::mentionHeight, fullWidth(), st::mentionHeight);
|
|
|
|
} else if (_filteredSel >= 0) {
|
|
|
|
update(0, filteredOffset() + _filteredSel * st::dlgHeight, fullWidth(), st::dlgHeight);
|
|
|
|
} else if (_peopleSel >= 0) {
|
|
|
|
update(0, peopleOffset() + _peopleSel * st::dlgHeight, fullWidth(), st::dlgHeight);
|
|
|
|
} else if (_searchedSel >= 0) {
|
|
|
|
update(0, searchedOffset() + _searchedSel * st::dlgHeight, fullWidth(), st::dlgHeight);
|
2015-09-29 13:24:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void DialogsInner::leaveEvent(QEvent *e) {
|
2014-05-30 08:53:19 +00:00
|
|
|
setMouseTracking(false);
|
2015-04-04 20:01:34 +00:00
|
|
|
selByMouse = false;
|
2015-11-18 13:11:56 +00:00
|
|
|
if (sel || _filteredSel >= 0 || _hashtagSel >= 0 || _searchedSel >= 0 || _peopleSel >= 0) {
|
2015-09-29 13:24:39 +00:00
|
|
|
updateSelectedRow();
|
2014-05-30 08:53:19 +00:00
|
|
|
sel = 0;
|
2015-11-18 13:11:56 +00:00
|
|
|
_filteredSel = _searchedSel = _peopleSel = _hashtagSel = -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::onParentGeometryChanged() {
|
2014-05-30 08:53:19 +00:00
|
|
|
lastMousePos = QCursor::pos();
|
|
|
|
if (rect().contains(mapFromGlobal(lastMousePos))) {
|
|
|
|
setMouseTracking(true);
|
|
|
|
onUpdateSelected(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-09-29 13:24:39 +00:00
|
|
|
void DialogsInner::onPeerNameChanged(PeerData *peer, const PeerData::Names &oldNames, const PeerData::NameFirstChars &oldChars) {
|
2014-05-30 08:53:19 +00:00
|
|
|
dialogs.peerNameChanged(peer, oldNames, oldChars);
|
|
|
|
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();
|
|
|
|
_peopleResults.clear();
|
|
|
|
_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()) {
|
2014-05-30 08:53:19 +00:00
|
|
|
DialogsList *dialogsToFilter = 0, *contactsNoDialogsToFilter = 0;
|
|
|
|
if (dialogs.list.count) {
|
|
|
|
for (fi = fb; fi != fe; ++fi) {
|
|
|
|
DialogsIndexed::DialogsIndex::iterator i = dialogs.index.find(fi->at(0));
|
|
|
|
if (i == dialogs.index.cend()) {
|
|
|
|
dialogsToFilter = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (!dialogsToFilter || dialogsToFilter->count > i.value()->count) {
|
|
|
|
dialogsToFilter = i.value();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (contactsNoDialogs.list.count) {
|
|
|
|
for (fi = fb; fi != fe; ++fi) {
|
|
|
|
DialogsIndexed::DialogsIndex::iterator i = contactsNoDialogs.index.find(fi->at(0));
|
|
|
|
if (i == contactsNoDialogs.index.cend()) {
|
|
|
|
contactsNoDialogsToFilter = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (!contactsNoDialogsToFilter || contactsNoDialogsToFilter->count > i.value()->count) {
|
|
|
|
contactsNoDialogsToFilter = i.value();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-11-18 13:11:56 +00:00
|
|
|
_filterResults.reserve((dialogsToFilter ? dialogsToFilter->count : 0) + (contactsNoDialogsToFilter ? contactsNoDialogsToFilter->count : 0));
|
2014-05-30 08:53:19 +00:00
|
|
|
if (dialogsToFilter && dialogsToFilter->count) {
|
|
|
|
for (DialogRow *i = dialogsToFilter->begin, *e = dialogsToFilter->end; i != e; i = i->next) {
|
|
|
|
const PeerData::Names &names(i->history->peer->names);
|
|
|
|
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) {
|
2015-11-18 13:11:56 +00:00
|
|
|
_filterResults.push_back(i);
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (contactsNoDialogsToFilter && contactsNoDialogsToFilter->count) {
|
|
|
|
for (DialogRow *i = contactsNoDialogsToFilter->begin, *e = contactsNoDialogsToFilter->end; i != e; i = i->next) {
|
|
|
|
const PeerData::Names &names(i->history->peer->names);
|
|
|
|
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) {
|
2015-11-18 13:11:56 +00:00
|
|
|
_filterResults.push_back(i);
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
refresh(true);
|
|
|
|
setMouseSel(false, true);
|
|
|
|
}
|
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);
|
|
|
|
setMouseSel(false, true);
|
|
|
|
}
|
|
|
|
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()) {
|
|
|
|
Local::readRecentHashtags();
|
|
|
|
}
|
|
|
|
const RecentHashtagPack &recent(cRecentSearchHashtags());
|
2015-11-18 13:11:56 +00:00
|
|
|
_hashtagResults.clear();
|
2015-03-24 10:00:27 +00:00
|
|
|
if (!recent.isEmpty()) {
|
2015-11-18 13:11:56 +00:00
|
|
|
_hashtagResults.reserve(qMin(recent.size(), 5));
|
2015-03-24 10:00:27 +00:00
|
|
|
for (RecentHashtagPack::const_iterator 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()) {
|
2015-11-18 13:11:56 +00:00
|
|
|
_hashtagResults.push_back(i->first);
|
|
|
|
if (_hashtagResults.size() == 5) break;
|
2015-03-24 10:00:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
refresh(true);
|
|
|
|
setMouseSel(false, true);
|
|
|
|
}
|
|
|
|
|
2015-09-29 13:24:39 +00:00
|
|
|
DialogsInner::~DialogsInner() {
|
2014-07-04 11:12:54 +00:00
|
|
|
clearSearchResults();
|
|
|
|
}
|
|
|
|
|
2015-09-29 13:24:39 +00:00
|
|
|
void DialogsInner::clearSearchResults(bool clearPeople) {
|
2015-11-18 13:11:56 +00:00
|
|
|
if (clearPeople) _peopleResults.clear();
|
|
|
|
if (!_searchResults.isEmpty()) {
|
|
|
|
for (SearchResults::const_iterator i = _searchResults.cbegin(), e = _searchResults.cend(); i != e; ++i) {
|
2014-07-04 11:12:54 +00:00
|
|
|
delete *i;
|
|
|
|
}
|
2015-11-18 13:11:56 +00:00
|
|
|
_searchResults.clear();
|
2014-07-04 11:12:54 +00:00
|
|
|
}
|
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
|
|
|
void DialogsInner::itemReplaced(HistoryItem *oldItem, HistoryItem *newItem) {
|
2015-11-18 13:11:56 +00:00
|
|
|
for (int i = 0; i < _searchResults.size(); ++i) {
|
|
|
|
if (_searchResults[i]->_item == oldItem) {
|
|
|
|
_searchResults[i]->_item = newItem;
|
2014-07-04 11:12:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-09-29 13:24:39 +00:00
|
|
|
PeerData *DialogsInner::updateFromParentDrag(QPoint globalPos) {
|
2015-06-24 17:24:48 +00:00
|
|
|
lastMousePos = globalPos;
|
|
|
|
selByMouse = true;
|
|
|
|
onUpdateSelected(true);
|
|
|
|
if (_state == DefaultState) {
|
|
|
|
if (sel) return sel->history->peer;
|
|
|
|
} else if (_state == FilteredState || _state == SearchedState) {
|
2015-11-18 13:11:56 +00:00
|
|
|
if (_filteredSel >= 0 && _filteredSel < _filterResults.size()) {
|
|
|
|
return _filterResults[_filteredSel]->history->peer;
|
|
|
|
} else if (_peopleSel >= 0 && _peopleSel < _peopleResults.size()) {
|
|
|
|
return _peopleResults[_peopleSel];
|
|
|
|
} else if (_searchedSel >= 0 && _searchedSel < _searchResults.size()) {
|
|
|
|
return _searchResults[_searchedSel]->_item->history()->peer;
|
2015-06-24 17:24:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
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();
|
|
|
|
for (int i = 0; i < _searchResults.size();) {
|
|
|
|
if (_searchResults[i]->_item == item) {
|
|
|
|
_searchResults.remove(i);
|
|
|
|
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) {
|
2014-05-30 08:53:19 +00:00
|
|
|
for (QVector<MTPDialog>::const_iterator i = added.cbegin(), e = added.cend(); i != e; ++i) {
|
2015-09-07 07:52:37 +00:00
|
|
|
History *history = 0;
|
2015-09-04 13:01:31 +00:00
|
|
|
switch (i->type()) {
|
2015-09-07 07:52:37 +00:00
|
|
|
case mtpc_dialog: {
|
|
|
|
const MTPDdialog &d(i->c_dialog());
|
|
|
|
history = App::historyFromDialog(peerFromMTP(d.vpeer), d.vunread_count.v, d.vread_inbox_max_id.v);
|
|
|
|
App::main()->applyNotifySetting(MTP_notifyPeer(d.vpeer), d.vnotify_settings, history);
|
|
|
|
} break;
|
|
|
|
|
|
|
|
case mtpc_dialogChannel: {
|
|
|
|
const MTPDdialogChannel &d(i->c_dialogChannel());
|
2015-11-02 22:33:57 +00:00
|
|
|
PeerData *peer = App::peerLoaded(peerFromMTP(d.vpeer));
|
|
|
|
int32 unreadCount = (peer && peer->isMegagroup()) ? d.vunread_count.v : d.vunread_important_count.v;
|
|
|
|
History *history = App::historyFromDialog(peerFromMTP(d.vpeer), unreadCount, d.vread_inbox_max_id.v);
|
2015-09-13 08:41:27 +00:00
|
|
|
if (history->peer->isChannel()) {
|
2015-09-19 09:13:21 +00:00
|
|
|
history->asChannelHistory()->unreadCountAll = d.vunread_count.v;
|
2015-09-13 08:41:27 +00:00
|
|
|
history->peer->asChannel()->ptsReceived(d.vpts.v);
|
2015-09-21 20:57:42 +00:00
|
|
|
if (!history->peer->asChannel()->amCreator()) {
|
2015-11-02 22:33:57 +00:00
|
|
|
MsgId topMsg = history->isMegagroup() ? d.vtop_message.v : d.vtop_important_message.v;
|
|
|
|
if (HistoryItem *top = App::histItemById(history->channelId(), topMsg)) {
|
2015-10-03 11:33:51 +00:00
|
|
|
if (top->date <= date(history->peer->asChannel()->date) && App::api()) {
|
2015-09-21 20:57:42 +00:00
|
|
|
App::api()->requestSelfParticipant(history->peer->asChannel());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-09-13 08:41:27 +00:00
|
|
|
}
|
2015-11-02 22:33:57 +00:00
|
|
|
if (!history->isMegagroup() && d.vtop_message.v > d.vtop_important_message.v) {
|
2015-09-20 08:55:41 +00:00
|
|
|
history->setNotLoadedAtBottom();
|
|
|
|
}
|
2015-09-07 07:52:37 +00:00
|
|
|
App::main()->applyNotifySetting(MTP_notifyPeer(d.vpeer), d.vnotify_settings, history);
|
|
|
|
} break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (history) {
|
2015-11-13 15:14:33 +00:00
|
|
|
if (!history->lastMsgDate.isNull()) {
|
|
|
|
addSavedPeersAfter(history->lastMsgDate);
|
|
|
|
}
|
2015-09-07 07:52:37 +00:00
|
|
|
contactsNoDialogs.del(history->peer);
|
2015-11-13 15:14:33 +00:00
|
|
|
if (history->peer->migrateFrom()) {
|
|
|
|
removeDialog(App::historyLoaded(history->peer->migrateFrom()->id));
|
|
|
|
} else if (history->peer->migrateTo() && history->peer->migrateTo()->amIn()) {
|
|
|
|
removeDialog(history);
|
|
|
|
}
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
}
|
2015-09-07 07:52:37 +00:00
|
|
|
|
2014-12-15 15:55:45 +00:00
|
|
|
if (App::wnd()) App::wnd()->updateCounter();
|
2014-05-30 08:53:19 +00:00
|
|
|
if (!sel && dialogs.list.count) {
|
|
|
|
sel = dialogs.list.begin;
|
|
|
|
contactSel = false;
|
|
|
|
}
|
|
|
|
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);
|
2015-09-06 10:17:09 +00:00
|
|
|
history->setPosInDialogsDate(saved.lastKey());
|
2015-08-07 12:11:50 +00:00
|
|
|
contactsNoDialogs.del(history->peer);
|
|
|
|
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
|
|
|
}
|
2015-11-18 13:11:56 +00:00
|
|
|
int32 lastDateFound = 0;
|
2014-07-04 11:12:54 +00:00
|
|
|
for (QVector<MTPMessage>::const_iterator i = messages.cbegin(), e = messages.cend(); i != e; ++i) {
|
2015-09-20 08:55:41 +00:00
|
|
|
HistoryItem *item = App::histories().addNewMessage(*i, NewMessageExisting);
|
2015-11-18 13:11:56 +00:00
|
|
|
int32 lastDate = dateFromMessage(*i);
|
|
|
|
if (lastDate) {
|
|
|
|
_searchResults.push_back(new FakeDialogRow(item));
|
|
|
|
lastDateFound = lastDate;
|
|
|
|
if (type == DialogsSearchFromStart || type == DialogsSearchFromOffset) {
|
|
|
|
_lastSearchDate = lastDateFound;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (type == DialogsSearchFromStart || type == DialogsSearchFromOffset) {
|
|
|
|
_lastSearchPeer = item->history()->peer;
|
|
|
|
}
|
|
|
|
if (type == DialogsSearchMigratedFromStart || type == DialogsSearchMigratedFromOffset) {
|
|
|
|
_lastSearchMigratedId = item->id;
|
|
|
|
} else {
|
|
|
|
_lastSearchId = item->id;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (type == DialogsSearchMigratedFromStart || type == DialogsSearchMigratedFromOffset) {
|
|
|
|
_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
|
|
|
}
|
|
|
|
|
2015-09-29 13:24:39 +00:00
|
|
|
void DialogsInner::peopleReceived(const QString &query, const QVector<MTPPeer> &people) {
|
2015-11-18 13:11:56 +00:00
|
|
|
_peopleQuery = query.toLower().trimmed();
|
|
|
|
_peopleResults.clear();
|
|
|
|
_peopleResults.reserve(people.size());
|
2015-09-06 10:17:09 +00:00
|
|
|
for (QVector<MTPPeer>::const_iterator i = people.cbegin(), e = people.cend(); i != e; ++i) {
|
|
|
|
PeerId peerId = peerFromMTP(*i);
|
|
|
|
History *h = App::historyLoaded(peerId);
|
2015-09-13 19:15:45 +00:00
|
|
|
if (h && !h->dialogs.isEmpty()) continue; // skip dialogs
|
2014-10-22 18:39:03 +00:00
|
|
|
|
2015-11-18 13:11:56 +00:00
|
|
|
_peopleResults.push_back(App::peer(peerId));
|
2014-10-22 18:39:03 +00:00
|
|
|
}
|
|
|
|
refresh();
|
|
|
|
}
|
|
|
|
|
2015-09-29 13:24:39 +00:00
|
|
|
void DialogsInner::contactsReceived(const QVector<MTPContact> &contacts) {
|
2014-05-30 08:53:19 +00:00
|
|
|
for (QVector<MTPContact>::const_iterator i = contacts.cbegin(), e = contacts.cend(); i != e; ++i) {
|
2015-04-02 10:33:19 +00:00
|
|
|
int32 uid = i->c_contact().vuser_id.v;
|
|
|
|
addNewContact(uid);
|
|
|
|
if (uid == MTP::authedId() && App::self()) {
|
|
|
|
App::self()->contact = 1;
|
|
|
|
}
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
2015-08-07 12:11:50 +00:00
|
|
|
if (!sel && contactsNoDialogs.list.count && false) {
|
2014-05-30 08:53:19 +00:00
|
|
|
sel = contactsNoDialogs.list.begin;
|
|
|
|
contactSel = true;
|
|
|
|
}
|
|
|
|
refresh();
|
|
|
|
}
|
|
|
|
|
2015-09-29 13:24:39 +00:00
|
|
|
int32 DialogsInner::addNewContact(int32 uid, bool select) { // -2 - err, -1 - don't scroll, >= 0 - scroll
|
2015-09-03 10:48:40 +00:00
|
|
|
PeerId peer = peerFromUser(uid);
|
2015-09-02 10:20:33 +00:00
|
|
|
if (!App::peerLoaded(peer)) return -2;
|
2014-05-30 08:53:19 +00:00
|
|
|
|
|
|
|
History *history = App::history(peer);
|
|
|
|
contacts.addByName(history);
|
|
|
|
DialogsList::RowByPeer::const_iterator i = dialogs.list.rowByPeer.constFind(peer);
|
|
|
|
if (i == dialogs.list.rowByPeer.cend()) {
|
|
|
|
DialogRow *added = contactsNoDialogs.addByName(history);
|
2015-09-02 10:20:33 +00:00
|
|
|
if (!added) return -2;
|
|
|
|
return -1;
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
if (select) {
|
|
|
|
sel = i.value();
|
|
|
|
contactSel = false;
|
|
|
|
}
|
|
|
|
return i.value()->pos * st::dlgHeight;
|
|
|
|
}
|
|
|
|
|
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) {
|
2015-08-07 12:11:50 +00:00
|
|
|
h = (dialogs.list.count/* + contactsNoDialogs.list.count*/) * st::dlgHeight;
|
2014-11-25 12:15:29 +00:00
|
|
|
if (h) {
|
|
|
|
if (!_addContactLnk.isHidden()) _addContactLnk.hide();
|
|
|
|
} else {
|
|
|
|
h = st::noContactsHeight;
|
|
|
|
if (cContactsReceived()) {
|
|
|
|
if (_addContactLnk.isHidden()) _addContactLnk.show();
|
|
|
|
} else {
|
|
|
|
if (!_addContactLnk.isHidden()) _addContactLnk.hide();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (!_addContactLnk.isHidden()) _addContactLnk.hide();
|
|
|
|
if (_state == FilteredState) {
|
2015-11-18 13:11:56 +00:00
|
|
|
h = searchedOffset() + (_searchResults.count() * st::dlgHeight) + ((_searchResults.isEmpty() && !_searchInPeer) ? -st::searchedBarHeight : 0);
|
2014-11-25 12:15:29 +00:00
|
|
|
} else if (_state == SearchedState) {
|
2015-11-18 13:11:56 +00:00
|
|
|
h = searchedOffset() + (_searchResults.count() * st::dlgHeight);
|
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);
|
|
|
|
}
|
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::setMouseSel(bool msel, bool toTop) {
|
2014-05-30 08:53:19 +00:00
|
|
|
selByMouse = msel;
|
|
|
|
if (!selByMouse && toTop) {
|
2014-07-04 11:12:54 +00:00
|
|
|
if (_state == DefaultState) {
|
2014-05-30 08:53:19 +00:00
|
|
|
sel = (dialogs.list.count ? dialogs.list.begin : (contactsNoDialogs.list.count ? contactsNoDialogs.list.begin : 0));
|
|
|
|
contactSel = !dialogs.list.count && contactsNoDialogs.list.count;
|
2014-07-13 09:50:38 +00:00
|
|
|
} else if (_state == FilteredState || _state == SearchedState) { // don't select first elem in search
|
2015-11-18 13:11:56 +00:00
|
|
|
_filteredSel = _peopleSel = _searchedSel = _hashtagSel = -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;
|
2014-07-13 09:50:38 +00:00
|
|
|
if (_state == DefaultState) {
|
2014-07-04 11:12:54 +00:00
|
|
|
clearSearchResults();
|
2015-11-18 13:11:56 +00:00
|
|
|
_searchedSel = _peopleSel = _filteredSel = _hashtagSel = -1;
|
2014-07-04 11:12:54 +00:00
|
|
|
} else if (_state == DefaultState || _state == SearchedState) {
|
2015-11-18 13:11:56 +00:00
|
|
|
_hashtagResults.clear();
|
|
|
|
_hashtagSel = -1;
|
|
|
|
_filterResults.clear();
|
|
|
|
_filteredSel = -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
|
|
|
refresh(true);
|
|
|
|
}
|
|
|
|
|
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) {
|
2015-11-18 13:11:56 +00:00
|
|
|
_searchInPeer = peer ? (peer->migrateTo() ? peer->migrateTo() : peer) : 0;
|
|
|
|
_searchInMigrated = _searchInPeer ? _searchInPeer->migrateFrom() : 0;
|
2015-08-04 15:01:47 +00:00
|
|
|
if (_searchInPeer) {
|
|
|
|
onHashtagFilterUpdate(QStringRef());
|
|
|
|
_cancelSearchInPeer.show();
|
|
|
|
} else {
|
|
|
|
_cancelSearchInPeer.hide();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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();
|
|
|
|
_peopleResults.clear();
|
|
|
|
_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) {
|
2014-05-30 08:53:19 +00:00
|
|
|
if (!sel) {
|
|
|
|
if (dialogs.list.count && direction > 0) {
|
|
|
|
sel = dialogs.list.begin;
|
2015-08-16 16:37:56 +00:00
|
|
|
} else if (false && contactsNoDialogs.list.count && direction > 0) {
|
2014-05-30 08:53:19 +00:00
|
|
|
sel = contactsNoDialogs.list.begin;
|
|
|
|
} else {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
} else if (direction > 0) {
|
|
|
|
if (sel->next->next) {
|
|
|
|
sel = sel->next;
|
2015-08-16 16:37:56 +00:00
|
|
|
} else if (false && sel->next == dialogs.list.end && contactsNoDialogs.list.count) {
|
2014-05-30 08:53:19 +00:00
|
|
|
sel = contactsNoDialogs.list.begin;
|
|
|
|
contactSel = true;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (sel->prev) {
|
|
|
|
sel = sel->prev;
|
2015-08-16 16:37:56 +00:00
|
|
|
} else if (false && sel == contactsNoDialogs.list.begin && dialogs.list.count) {
|
2014-05-30 08:53:19 +00:00
|
|
|
sel = dialogs.list.end->prev;
|
|
|
|
contactSel = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
int32 fromY = (sel->pos + (contactSel ? dialogs.list.count : 0)) * st::dlgHeight;
|
|
|
|
emit mustScrollTo(fromY, fromY + st::dlgHeight);
|
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() && _filterResults.isEmpty() && _peopleResults.isEmpty() && _searchResults.isEmpty()) return;
|
|
|
|
if ((_hashtagSel < 0 || _hashtagSel >= _hashtagResults.size()) &&
|
|
|
|
(_filteredSel < 0 || _filteredSel >= _filterResults.size()) &&
|
|
|
|
(_peopleSel < 0 || _peopleSel >= _peopleResults.size()) &&
|
|
|
|
(_searchedSel < 0 || _searchedSel >= _searchResults.size())) {
|
|
|
|
if (_hashtagResults.isEmpty() && _filterResults.isEmpty() && _peopleResults.isEmpty()) {
|
|
|
|
_searchedSel = 0;
|
|
|
|
} else if (_hashtagResults.isEmpty() && _filterResults.isEmpty()) {
|
|
|
|
_peopleSel = 0;
|
|
|
|
} else if (_hashtagResults.isEmpty()) {
|
|
|
|
_filteredSel = 0;
|
2015-03-24 10:00:27 +00:00
|
|
|
} else {
|
2015-11-18 13:11:56 +00:00
|
|
|
_hashtagSel = 0;
|
2014-07-13 09:50:38 +00:00
|
|
|
}
|
|
|
|
} else {
|
2015-11-18 13:11:56 +00:00
|
|
|
int32 cur = (_hashtagSel >= 0 && _hashtagSel < _hashtagResults.size()) ? _hashtagSel : ((_filteredSel >= 0 && _filteredSel < _filterResults.size()) ? (_hashtagResults.size() + _filteredSel) : ((_peopleSel >= 0 && _peopleSel < _peopleResults.size()) ? (_peopleSel + _filterResults.size() + _hashtagResults.size()) : (_searchedSel + _peopleResults.size() + _filterResults.size() + _hashtagResults.size())));
|
|
|
|
cur = snap(cur + direction, 0, _hashtagResults.size() + _filterResults.size() + _peopleResults.size() + _searchResults.size() - 1);
|
|
|
|
if (cur < _hashtagResults.size()) {
|
|
|
|
_hashtagSel = cur;
|
|
|
|
_filteredSel = _peopleSel = _searchedSel = -1;
|
|
|
|
} else if (cur < _hashtagResults.size() + _filterResults.size()) {
|
|
|
|
_filteredSel = cur - _hashtagResults.size();
|
|
|
|
_hashtagSel = _peopleSel = _searchedSel = -1;
|
|
|
|
} else if (cur < _hashtagResults.size() + _filterResults.size() + _peopleResults.size()) {
|
|
|
|
_peopleSel = cur - _hashtagResults.size() - _filterResults.size();
|
|
|
|
_hashtagSel = _filteredSel = _searchedSel = -1;
|
2014-10-22 18:39:03 +00:00
|
|
|
} else {
|
2015-11-18 13:11:56 +00:00
|
|
|
_hashtagSel = _filteredSel = _peopleSel = -1;
|
|
|
|
_searchedSel = cur - _hashtagResults.size() - _filterResults.size() - _peopleResults.size();
|
2014-07-13 09:50:38 +00:00
|
|
|
}
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
2015-11-18 13:11:56 +00:00
|
|
|
if (_hashtagSel >= 0 && _hashtagSel < _hashtagResults.size()) {
|
|
|
|
emit mustScrollTo(_hashtagSel * st::mentionHeight, (_hashtagSel + 1) * st::mentionHeight);
|
|
|
|
} else if (_filteredSel >= 0 && _filteredSel < _filterResults.size()) {
|
|
|
|
emit mustScrollTo(filteredOffset() + _filteredSel * st::dlgHeight, filteredOffset() + (_filteredSel + 1) * st::dlgHeight);
|
|
|
|
} else if (_peopleSel >= 0 && _peopleSel < _peopleResults.size()) {
|
|
|
|
emit mustScrollTo(peopleOffset() + _peopleSel * st::dlgHeight + (_peopleSel ? 0 : -st::searchedBarHeight), peopleOffset() + (_peopleSel + 1) * st::dlgHeight);
|
2014-07-13 09:50:38 +00:00
|
|
|
} else {
|
2015-11-18 13:11:56 +00:00
|
|
|
emit mustScrollTo(searchedOffset() + _searchedSel * st::dlgHeight + (_searchedSel ? 0 : -st::searchedBarHeight), searchedOffset() + (_searchedSel + 1) * st::dlgHeight);
|
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) {
|
2014-05-30 08:53:19 +00:00
|
|
|
DialogsList::RowByPeer::const_iterator i = dialogs.list.rowByPeer.constFind(peer);
|
|
|
|
if (i != dialogs.list.rowByPeer.cend()) {
|
|
|
|
fromY = i.value()->pos * st::dlgHeight;
|
2015-08-16 16:37:56 +00:00
|
|
|
} else if (false) {
|
2014-05-30 08:53:19 +00:00
|
|
|
i = contactsNoDialogs.list.rowByPeer.constFind(peer);
|
|
|
|
if (i != contactsNoDialogs.list.rowByPeer.cend()) {
|
|
|
|
fromY = (i.value()->pos + dialogs.list.count) * st::dlgHeight;
|
|
|
|
}
|
|
|
|
}
|
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) {
|
|
|
|
if (_searchResults[i]->_item->history()->peer->id == peer && _searchResults[i]->_item->id == msgId) {
|
2015-03-24 10:00:27 +00:00
|
|
|
fromY = searchedOffset() + i * st::dlgHeight;
|
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) {
|
|
|
|
if (_filterResults[i]->history->peer->id == peer) {
|
2015-03-24 10:00:27 +00:00
|
|
|
fromY = filteredOffset() + (i * st::dlgHeight);
|
2014-08-22 07:41:39 +00:00
|
|
|
break;
|
|
|
|
}
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (fromY >= 0) {
|
|
|
|
emit mustScrollTo(fromY, fromY + st::dlgHeight);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-09-29 13:24:39 +00:00
|
|
|
void DialogsInner::selectSkipPage(int32 pixels, int32 direction) {
|
2014-05-30 08:53:19 +00:00
|
|
|
int32 toSkip = pixels / int32(st::dlgHeight);
|
2014-07-04 11:12:54 +00:00
|
|
|
if (_state == DefaultState) {
|
2014-05-30 08:53:19 +00:00
|
|
|
if (!sel) {
|
|
|
|
if (direction > 0 && dialogs.list.count) {
|
|
|
|
sel = dialogs.list.begin;
|
2015-08-16 16:37:56 +00:00
|
|
|
} else if (false && direction > 0 && contactsNoDialogs.list.count) {
|
2014-05-30 08:53:19 +00:00
|
|
|
sel = contactsNoDialogs.list.begin;
|
|
|
|
} else {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (direction > 0) {
|
|
|
|
while (toSkip-- && sel->next->next) {
|
|
|
|
sel = sel->next;
|
|
|
|
}
|
2015-08-16 16:37:56 +00:00
|
|
|
if (false && toSkip >= 0 && sel->next == dialogs.list.end && contactsNoDialogs.list.count) {
|
2014-05-30 08:53:19 +00:00
|
|
|
sel = contactsNoDialogs.list.begin;
|
|
|
|
while (toSkip-- && sel->next->next) {
|
|
|
|
sel = sel->next;
|
|
|
|
}
|
|
|
|
contactSel = true;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
while (toSkip-- && sel->prev) {
|
|
|
|
sel = sel->prev;
|
|
|
|
}
|
|
|
|
if (toSkip >= 0 && sel == contactsNoDialogs.list.begin && dialogs.list.count) {
|
|
|
|
sel = dialogs.list.end->prev;
|
|
|
|
while (toSkip-- && sel->prev) {
|
|
|
|
sel = sel->prev;
|
|
|
|
}
|
|
|
|
contactSel = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
int32 fromY = (sel->pos + (contactSel ? dialogs.list.count : 0)) * st::dlgHeight;
|
|
|
|
emit mustScrollTo(fromY, fromY + st::dlgHeight);
|
|
|
|
} else {
|
|
|
|
return selectSkip(direction * toSkip);
|
|
|
|
}
|
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::loadPeerPhotos(int32 yFrom) {
|
2014-05-30 08:53:19 +00:00
|
|
|
int32 yTo = yFrom + parentWidget()->height() * 5;
|
|
|
|
MTP::clearLoaderPriorities();
|
2014-07-04 11:12:54 +00:00
|
|
|
if (_state == DefaultState) {
|
2014-05-30 08:53:19 +00:00
|
|
|
int32 otherStart = dialogs.list.count * st::dlgHeight;
|
|
|
|
if (yFrom < otherStart) {
|
|
|
|
dialogs.list.adjustCurrent(yFrom, st::dlgHeight);
|
|
|
|
for (DialogRow *row = dialogs.list.current; row != dialogs.list.end && (row->pos * st::dlgHeight) < yTo; row = row->next) {
|
|
|
|
row->history->peer->photo->load();
|
|
|
|
}
|
|
|
|
yFrom = 0;
|
|
|
|
} else {
|
|
|
|
yFrom -= otherStart;
|
|
|
|
}
|
|
|
|
yTo -= otherStart;
|
|
|
|
if (yTo > 0) {
|
|
|
|
contactsNoDialogs.list.adjustCurrent(yFrom, st::dlgHeight);
|
|
|
|
for (DialogRow *row = contactsNoDialogs.list.current; row != contactsNoDialogs.list.end && (row->pos * st::dlgHeight) < yTo; row = row->next) {
|
|
|
|
row->history->peer->photo->load();
|
|
|
|
}
|
|
|
|
}
|
2014-07-13 09:50:38 +00:00
|
|
|
} else if (_state == FilteredState || _state == SearchedState) {
|
2015-03-24 10:00:27 +00:00
|
|
|
int32 from = (yFrom - filteredOffset()) / st::dlgHeight;
|
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()) {
|
2014-05-30 08:53:19 +00:00
|
|
|
int32 to = (yTo / int32(st::dlgHeight)) + 1, w = width();
|
2015-11-18 13:11:56 +00:00
|
|
|
if (to > _filterResults.size()) to = _filterResults.size();
|
2014-05-30 08:53:19 +00:00
|
|
|
|
|
|
|
for (; from < to; ++from) {
|
2015-11-18 13:11:56 +00:00
|
|
|
_filterResults[from]->history->peer->photo->load();
|
2014-07-04 11:12:54 +00:00
|
|
|
}
|
|
|
|
}
|
2014-07-13 09:50:38 +00:00
|
|
|
|
2015-11-18 13:11:56 +00:00
|
|
|
from = (yFrom > filteredOffset() + st::searchedBarHeight ? ((yFrom - filteredOffset() - st::searchedBarHeight) / int32(st::dlgHeight)) : 0) - _filterResults.size();
|
2014-07-04 11:12:54 +00:00
|
|
|
if (from < 0) from = 0;
|
2015-11-18 13:11:56 +00:00
|
|
|
if (from < _peopleResults.size()) {
|
|
|
|
int32 to = (yTo > filteredOffset() + st::searchedBarHeight ? ((yTo - filteredOffset() - st::searchedBarHeight) / int32(st::dlgHeight)) : 0) - _filterResults.size() + 1, w = width();
|
|
|
|
if (to > _peopleResults.size()) to = _peopleResults.size();
|
2014-10-22 18:39:03 +00:00
|
|
|
|
|
|
|
for (; from < to; ++from) {
|
2015-11-18 13:11:56 +00:00
|
|
|
_peopleResults[from]->photo->load();
|
2014-10-22 18:39:03 +00:00
|
|
|
}
|
|
|
|
}
|
2015-11-18 13:11:56 +00:00
|
|
|
from = (yFrom > filteredOffset() + ((_peopleResults.isEmpty() ? 0 : st::searchedBarHeight) + st::searchedBarHeight) ? ((yFrom - filteredOffset() - (_peopleResults.isEmpty() ? 0 : st::searchedBarHeight) - st::searchedBarHeight) / int32(st::dlgHeight)) : 0) - _filterResults.size() - _peopleResults.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()) {
|
|
|
|
int32 to = (yTo > filteredOffset() + (_peopleResults.isEmpty() ? 0 : st::searchedBarHeight) + st::searchedBarHeight ? ((yTo - filteredOffset() - (_peopleResults.isEmpty() ? 0 : st::searchedBarHeight) - st::searchedBarHeight) / int32(st::dlgHeight)) : 0) - _filterResults.size() - _peopleResults.size() + 1, w = width();
|
|
|
|
if (to > _searchResults.size()) to = _searchResults.size();
|
2014-07-04 11:12:54 +00:00
|
|
|
|
|
|
|
for (; from < to; ++from) {
|
2015-11-18 13:11:56 +00:00
|
|
|
_searchResults[from]->_item->history()->peer->photo->load();
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-09-29 13:24:39 +00:00
|
|
|
bool DialogsInner::choosePeer() {
|
2014-07-04 11:12:54 +00:00
|
|
|
History *history = 0;
|
2015-07-17 19:17:37 +00:00
|
|
|
MsgId msgId = ShowAtUnreadMsgId;
|
2014-07-04 11:12:54 +00:00
|
|
|
if (_state == DefaultState) {
|
|
|
|
if (sel) history = sel->history;
|
2014-07-13 09:50:38 +00:00
|
|
|
} else if (_state == FilteredState || _state == SearchedState) {
|
2015-11-18 13:11:56 +00:00
|
|
|
if (_hashtagSel >= 0 && _hashtagSel < _hashtagResults.size()) {
|
|
|
|
QString hashtag = _hashtagResults.at(_hashtagSel);
|
2015-03-24 15:18:20 +00:00
|
|
|
if (_overDelete) {
|
|
|
|
lastMousePos = QCursor::pos();
|
|
|
|
|
|
|
|
RecentHashtagPack recent(cRecentSearchHashtags());
|
|
|
|
for (RecentHashtagPack::iterator i = recent.begin(); i != recent.cend();) {
|
|
|
|
if (i->first == hashtag) {
|
|
|
|
i = recent.erase(i);
|
|
|
|
} else {
|
|
|
|
++i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
cSetRecentSearchHashtags(recent);
|
|
|
|
Local::writeRecentHashtags();
|
|
|
|
emit refreshHashtags();
|
|
|
|
|
|
|
|
selByMouse = true;
|
|
|
|
onUpdateSelected(true);
|
|
|
|
} else {
|
|
|
|
saveRecentHashtags('#' + hashtag);
|
|
|
|
emit completeHashtag(hashtag);
|
|
|
|
}
|
2015-03-24 10:00:27 +00:00
|
|
|
return true;
|
|
|
|
}
|
2015-11-18 13:11:56 +00:00
|
|
|
if (_filteredSel >= 0 && _filteredSel < _filterResults.size()) {
|
|
|
|
history = _filterResults[_filteredSel]->history;
|
|
|
|
} else if (_peopleSel >= 0 && _peopleSel < _peopleResults.size()) {
|
|
|
|
history = App::history(_peopleResults[_peopleSel]->id);
|
|
|
|
} else if (_searchedSel >= 0 && _searchedSel < _searchResults.size()) {
|
|
|
|
history = _searchResults[_searchedSel]->_item->history();
|
|
|
|
msgId = _searchResults[_searchedSel]->_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
|
|
|
}
|
2015-11-18 13:11:56 +00:00
|
|
|
bool chosen = (!App::main()->selectingPeer(true) && (_state == FilteredState || _state == SearchedState) && _filteredSel >= 0 && _filteredSel < _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();
|
2014-05-30 08:53:19 +00:00
|
|
|
sel = 0;
|
2015-11-18 13:11:56 +00:00
|
|
|
_filteredSel = _peopleSel = _searchedSel = _hashtagSel = -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()) {
|
2015-05-19 15:46:45 +00:00
|
|
|
Local::readRecentHashtags();
|
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);
|
|
|
|
Local::writeRecentHashtags();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-09-29 13:24:39 +00:00
|
|
|
void DialogsInner::destroyData() {
|
2014-05-30 08:53:19 +00:00
|
|
|
sel = 0;
|
|
|
|
contactSel = false;
|
2015-11-18 13:11:56 +00:00
|
|
|
_hashtagSel = -1;
|
|
|
|
_hashtagResults.clear();
|
|
|
|
_filteredSel = -1;
|
|
|
|
_filterResults.clear();
|
|
|
|
_filter.clear();
|
|
|
|
_searchedSel = _peopleSel = -1;
|
2014-07-04 11:12:54 +00:00
|
|
|
clearSearchResults();
|
2014-05-30 08:53:19 +00:00
|
|
|
contacts.clear();
|
|
|
|
contactsNoDialogs.clear();
|
|
|
|
dialogs.clear();
|
|
|
|
}
|
|
|
|
|
2015-09-29 13:24:39 +00:00
|
|
|
void DialogsInner::peerBefore(const PeerData *inPeer, MsgId inMsg, PeerData *&outPeer, MsgId &outMsg) const {
|
2014-07-04 11:12:54 +00:00
|
|
|
if (_state == DefaultState) {
|
2014-08-22 07:41:39 +00:00
|
|
|
DialogsList::RowByPeer::const_iterator i = dialogs.list.rowByPeer.constFind(inPeer->id);
|
2014-07-04 11:12:54 +00:00
|
|
|
if (i == dialogs.list.rowByPeer.constEnd()) {
|
2014-08-22 07:41:39 +00:00
|
|
|
i = contactsNoDialogs.list.rowByPeer.constFind(inPeer->id);
|
2014-07-04 11:12:54 +00:00
|
|
|
if (i == contactsNoDialogs.list.rowByPeer.cend()) {
|
2014-08-22 07:41:39 +00:00
|
|
|
outPeer = 0;
|
|
|
|
outMsg = 0;
|
|
|
|
return;
|
2014-07-04 11:12:54 +00:00
|
|
|
}
|
|
|
|
if (i.value()->prev) {
|
2014-08-22 07:41:39 +00:00
|
|
|
outPeer = i.value()->prev->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
|
|
|
} else if (dialogs.list.count) {
|
2014-08-22 07:41:39 +00:00
|
|
|
outPeer = dialogs.list.end->prev->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
|
|
|
}
|
2014-08-22 07:41:39 +00:00
|
|
|
outPeer = 0;
|
|
|
|
outMsg = 0;
|
|
|
|
return;
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
if (i.value()->prev) {
|
2014-08-22 07:41:39 +00:00
|
|
|
outPeer = i.value()->prev->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
|
|
|
}
|
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()) {
|
|
|
|
for (SearchResults::const_iterator b = _searchResults.cbegin(), i = b + 1, e = _searchResults.cend(); i != e; ++i) {
|
2014-08-22 07:41:39 +00:00
|
|
|
if ((*i)->_item->history()->peer == inPeer && (*i)->_item->id == inMsg) {
|
|
|
|
SearchResults::const_iterator j = i - 1;
|
|
|
|
outPeer = (*j)->_item->history()->peer;
|
|
|
|
outMsg = (*j)->_item->id;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2015-11-18 13:11:56 +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;
|
2015-11-18 13:11:56 +00:00
|
|
|
if (_peopleResults.isEmpty()) {
|
|
|
|
if (_filterResults.isEmpty()) {
|
2014-10-22 18:39:03 +00:00
|
|
|
outPeer = 0;
|
|
|
|
} else {
|
2015-11-18 13:11:56 +00:00
|
|
|
outPeer = _filterResults.back()->history->peer;
|
2014-10-22 18:39:03 +00:00
|
|
|
}
|
|
|
|
} else {
|
2015-11-18 13:11:56 +00:00
|
|
|
outPeer = _peopleResults.back();
|
2014-10-22 18:39:03 +00:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2015-11-18 13:11:56 +00:00
|
|
|
if (!_peopleResults.isEmpty() && _peopleResults.at(0) == inPeer) {
|
|
|
|
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;
|
|
|
|
}
|
2015-11-18 13:11:56 +00:00
|
|
|
if (!_peopleResults.isEmpty()) {
|
|
|
|
for (PeopleResults::const_iterator b = _peopleResults.cbegin(), i = b + 1, e = _peopleResults.cend(); i != e; ++i) {
|
2014-10-22 18:39:03 +00:00
|
|
|
if ((*i) == inPeer) {
|
|
|
|
outPeer = (*(i - 1));
|
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
|
|
|
}
|
2015-11-18 13:11:56 +00:00
|
|
|
if (_filterResults.isEmpty() || _filterResults.at(0)->history->peer == inPeer) {
|
2014-08-22 07:41:39 +00:00
|
|
|
outPeer = 0;
|
|
|
|
outMsg = 0;
|
|
|
|
return;
|
|
|
|
}
|
2014-07-04 11:12:54 +00:00
|
|
|
|
2015-11-18 13:11:56 +00:00
|
|
|
for (FilteredDialogs::const_iterator b = _filterResults.cbegin(), i = b + 1, e = _filterResults.cend(); i != e; ++i) {
|
2014-08-22 07:41:39 +00:00
|
|
|
if ((*i)->history->peer == inPeer) {
|
2014-10-22 18:39:03 +00:00
|
|
|
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
|
|
|
}
|
2014-08-22 07:41:39 +00:00
|
|
|
outPeer = 0;
|
|
|
|
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 {
|
2014-07-04 11:12:54 +00:00
|
|
|
if (_state == DefaultState) {
|
2014-08-22 07:41:39 +00:00
|
|
|
DialogsList::RowByPeer::const_iterator i = dialogs.list.rowByPeer.constFind(inPeer->id);
|
2014-07-04 11:12:54 +00:00
|
|
|
if (i == dialogs.list.rowByPeer.constEnd()) {
|
2015-08-16 16:37:56 +00:00
|
|
|
//i = contactsNoDialogs.list.rowByPeer.constFind(inPeer->id);
|
|
|
|
//if (i == contactsNoDialogs.list.rowByPeer.cend()) {
|
|
|
|
// outPeer = 0;
|
|
|
|
// outMsg = 0;
|
|
|
|
// return;
|
|
|
|
//}
|
|
|
|
//if (i.value()->next != contactsNoDialogs.list.end) {
|
|
|
|
// outPeer = i.value()->next->history->peer;
|
|
|
|
// outMsg = ShowAtUnreadMsgId;
|
|
|
|
// return;
|
|
|
|
//}
|
2014-08-22 07:41:39 +00:00
|
|
|
outPeer = 0;
|
|
|
|
outMsg = 0;
|
|
|
|
return;
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
2014-07-04 11:12:54 +00:00
|
|
|
|
|
|
|
if (i.value()->next != dialogs.list.end) {
|
2014-08-22 07:41:39 +00:00
|
|
|
outPeer = i.value()->next->history->peer;
|
2015-07-17 19:17:37 +00:00
|
|
|
outMsg = ShowAtUnreadMsgId;
|
2014-08-22 07:41:39 +00:00
|
|
|
return;
|
2015-08-16 16:37:56 +00:00
|
|
|
} else if (false && contactsNoDialogs.list.count) {
|
2014-08-22 07:41:39 +00:00
|
|
|
outPeer = contactsNoDialogs.list.begin->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-07-13 09:50:38 +00:00
|
|
|
} else if (_state == FilteredState || _state == SearchedState) {
|
2014-08-22 07:41:39 +00:00
|
|
|
if (inMsg) {
|
2015-11-18 13:11:56 +00:00
|
|
|
for (SearchResults::const_iterator i = _searchResults.cbegin(), e = _searchResults.cend(); i != e; ++i) {
|
2014-08-22 07:41:39 +00:00
|
|
|
if ((*i)->_item->history()->peer == inPeer && (*i)->_item->id == inMsg) {
|
|
|
|
++i;
|
|
|
|
outPeer = (i == e) ? 0 : (*i)->_item->history()->peer;
|
|
|
|
outMsg = (i == e) ? 0 : (*i)->_item->id;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-11-18 13:11:56 +00:00
|
|
|
for (PeopleResults::const_iterator i = _peopleResults.cbegin(), e = _peopleResults.cend(); i != e; ++i) {
|
2014-10-22 18:39:03 +00:00
|
|
|
if ((*i) == inPeer) {
|
|
|
|
++i;
|
2015-11-18 13:11:56 +00:00
|
|
|
if (i == e && !_searchResults.isEmpty()) {
|
|
|
|
outPeer = _searchResults.front()->_item->history()->peer;
|
|
|
|
outMsg = _searchResults.front()->_item->id;
|
2014-10-22 18:39:03 +00:00
|
|
|
} else {
|
|
|
|
outPeer = (i == e) ? 0 : (*i);
|
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) {
|
2014-08-22 07:41:39 +00:00
|
|
|
if ((*i)->history->peer == inPeer) {
|
2014-07-04 11:12:54 +00:00
|
|
|
++i;
|
2015-11-18 13:11:56 +00:00
|
|
|
if (i == e && !_peopleResults.isEmpty()) {
|
|
|
|
outPeer = _peopleResults.front();
|
2015-07-17 19:17:37 +00:00
|
|
|
outMsg = ShowAtUnreadMsgId;
|
2015-11-18 13:11:56 +00:00
|
|
|
} else if (i == e && !_searchResults.isEmpty()) {
|
|
|
|
outPeer = _searchResults.front()->_item->history()->peer;
|
|
|
|
outMsg = _searchResults.front()->_item->id;
|
2014-10-22 18:39:03 +00:00
|
|
|
} else {
|
|
|
|
outPeer = (i == e) ? 0 : (*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
|
|
|
}
|
|
|
|
}
|
2014-08-22 07:41:39 +00:00
|
|
|
outPeer = 0;
|
|
|
|
outMsg = 0;
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
|
2015-09-29 13:24:39 +00:00
|
|
|
DialogsIndexed &DialogsInner::contactsList() {
|
2014-05-30 08:53:19 +00:00
|
|
|
return contacts;
|
|
|
|
}
|
|
|
|
|
2015-09-29 13:24:39 +00:00
|
|
|
DialogsIndexed &DialogsInner::dialogsList() {
|
2014-05-30 08:53:19 +00:00
|
|
|
return dialogs;
|
|
|
|
}
|
|
|
|
|
2015-09-29 13:24:39 +00:00
|
|
|
DialogsInner::FilteredDialogs &DialogsInner::filteredList() {
|
2015-11-18 13:11:56 +00:00
|
|
|
return _filterResults;
|
2014-10-22 18:39:03 +00:00
|
|
|
}
|
|
|
|
|
2015-09-29 13:24:39 +00:00
|
|
|
DialogsInner::PeopleResults &DialogsInner::peopleList() {
|
2015-11-18 13:11:56 +00:00
|
|
|
return _peopleResults;
|
2014-10-22 18:39:03 +00:00
|
|
|
}
|
|
|
|
|
2015-09-29 13:24:39 +00:00
|
|
|
DialogsInner::SearchResults &DialogsInner::searchList() {
|
2015-11-18 13:11:56 +00:00
|
|
|
return _searchResults;
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2015-10-17 08:31:48 +00:00
|
|
|
DialogsWidget::DialogsWidget(MainWidget *parent) : TWidget(parent)
|
2015-06-24 17:24:48 +00:00
|
|
|
, _dragInScroll(false)
|
|
|
|
, _dragForward(false)
|
2015-11-18 14:59:17 +00:00
|
|
|
, _dialogsFull(false)
|
|
|
|
, _dialogsOffsetDate(0)
|
|
|
|
, _dialogsOffsetId(0)
|
|
|
|
, _dialogsOffsetPeer(0)
|
2015-09-03 10:48:40 +00:00
|
|
|
, _dialogsRequest(0)
|
|
|
|
, _contactsRequest(0)
|
2014-06-16 09:31:10 +00:00
|
|
|
, _filter(this, st::dlgFilter, lang(lng_dlg_filter))
|
|
|
|
, _newGroup(this, st::btnNewGroup)
|
|
|
|
, _addContact(this, st::btnAddContact)
|
2014-07-04 11:12:54 +00:00
|
|
|
, _cancelSearch(this, st::btnCancelSearch)
|
2015-09-29 13:24:39 +00:00
|
|
|
, _scroll(this, st::dlgScroll)
|
|
|
|
, _inner(&_scroll, parent)
|
2015-10-17 14:52:26 +00:00
|
|
|
, _a_show(animFunc(this, &DialogsWidget::animStep_show))
|
2015-08-04 15:01:47 +00:00
|
|
|
, _searchInPeer(0)
|
2015-11-18 13:11:56 +00:00
|
|
|
, _searchInMigrated(0)
|
2014-07-04 11:12:54 +00:00
|
|
|
, _searchFull(false)
|
2015-11-18 13:11:56 +00:00
|
|
|
, _searchFullMigrated(false)
|
2014-10-22 18:39:03 +00:00
|
|
|
, _peopleFull(false)
|
2014-06-16 09:31:10 +00:00
|
|
|
{
|
2015-09-29 13:24:39 +00:00
|
|
|
_scroll.setWidget(&_inner);
|
|
|
|
_scroll.setFocusPolicy(Qt::NoFocus);
|
|
|
|
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()), &_inner, SLOT(onUpdateSelected()));
|
|
|
|
connect(&_scroll, SIGNAL(scrolled()), this, SLOT(onListScroll()));
|
2014-05-30 08:53:19 +00:00
|
|
|
connect(&_filter, SIGNAL(cancelled()), this, SLOT(onCancel()));
|
|
|
|
connect(&_filter, SIGNAL(changed()), this, SLOT(onFilterUpdate()));
|
2015-03-24 10:00:27 +00:00
|
|
|
connect(&_filter, SIGNAL(cursorPositionChanged(int,int)), this, SLOT(onFilterCursorMoved(int,int)));
|
2014-05-30 08:53:19 +00:00
|
|
|
connect(parent, SIGNAL(dialogsUpdated()), this, SLOT(onListScroll()));
|
|
|
|
connect(&_addContact, SIGNAL(clicked()), this, SLOT(onAddContact()));
|
|
|
|
connect(&_newGroup, SIGNAL(clicked()), this, SLOT(onNewGroup()));
|
2014-07-04 11:12:54 +00:00
|
|
|
connect(&_cancelSearch, SIGNAL(clicked()), this, SLOT(onCancelSearch()));
|
|
|
|
|
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
|
|
|
|
2015-09-29 13:24:39 +00:00
|
|
|
_scroll.show();
|
2014-05-30 08:53:19 +00:00
|
|
|
_filter.show();
|
|
|
|
_filter.move(st::dlgPaddingHor, st::dlgFilterPadding);
|
|
|
|
_filter.setFocusPolicy(Qt::StrongFocus);
|
2014-06-20 07:06:21 +00:00
|
|
|
_filter.customUpDown(true);
|
2014-05-30 08:53:19 +00:00
|
|
|
_addContact.hide();
|
|
|
|
_newGroup.show();
|
2014-07-04 11:12:54 +00:00
|
|
|
_cancelSearch.hide();
|
2014-05-30 08:53:19 +00:00
|
|
|
_newGroup.move(width() - _newGroup.width() - st::dlgPaddingHor, 0);
|
|
|
|
_addContact.move(width() - _addContact.width() - st::dlgPaddingHor, 0);
|
2014-07-04 11:12:54 +00:00
|
|
|
_cancelSearch.move(width() - _cancelSearch.width() - st::dlgPaddingHor, 0);
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void DialogsWidget::activate() {
|
|
|
|
_filter.setFocus();
|
2015-09-29 13:24:39 +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) {
|
2015-11-13 15:14:33 +00:00
|
|
|
bool creating = history->dialogs.isEmpty();
|
2015-09-29 13:24:39 +00:00
|
|
|
_inner.createDialog(history);
|
2015-11-13 15:14:33 +00:00
|
|
|
if (creating && history->peer->migrateFrom()) {
|
|
|
|
if (History *h = App::historyLoaded(history->peer->migrateFrom()->id)) {
|
|
|
|
if (!h->dialogs.isEmpty()) {
|
|
|
|
removeDialog(h);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void DialogsWidget::dlgUpdated(DialogRow *row) {
|
2015-09-29 13:24:39 +00:00
|
|
|
_inner.dlgUpdated(row);
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
|
2015-10-03 10:09:09 +00:00
|
|
|
void DialogsWidget::dlgUpdated(History *row, MsgId msgId) {
|
|
|
|
_inner.dlgUpdated(row, msgId);
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void DialogsWidget::dialogsToUp() {
|
2015-08-18 16:10:01 +00:00
|
|
|
if (_filter.getLastText().trimmed().isEmpty()) {
|
2015-09-29 13:24:39 +00:00
|
|
|
_scroll.scrollToY(0);
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-12-12 16:27:03 +00:00
|
|
|
void DialogsWidget::animShow(const QPixmap &bgAnimCache) {
|
2015-10-15 11:51:10 +00:00
|
|
|
if (App::app()) App::app()->mtpPause();
|
2015-10-15 10:18:24 +00:00
|
|
|
|
2015-10-17 14:52:26 +00:00
|
|
|
bool back = true;
|
|
|
|
(back ? _cacheOver : _cacheUnder) = bgAnimCache;
|
|
|
|
|
|
|
|
_a_show.stop();
|
|
|
|
|
|
|
|
(back ? _cacheUnder : _cacheOver) = myGrab(this);
|
|
|
|
|
2015-09-29 13:24:39 +00:00
|
|
|
_scroll.hide();
|
2014-12-12 16:27:03 +00:00
|
|
|
_filter.hide();
|
|
|
|
_cancelSearch.hide();
|
|
|
|
_newGroup.hide();
|
2015-10-17 14:52:26 +00:00
|
|
|
|
|
|
|
a_coordUnder = back ? anim::ivalue(-qFloor(st::slideShift * width()), 0) : anim::ivalue(0, -qFloor(st::slideShift * width()));
|
|
|
|
a_coordOver = back ? anim::ivalue(0, width()) : anim::ivalue(width(), 0);
|
|
|
|
a_shadow = back ? anim::fvalue(1, 0) : anim::fvalue(0, 1);
|
|
|
|
_a_show.start();
|
|
|
|
|
|
|
|
show();
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
|
2015-10-17 14:52:26 +00:00
|
|
|
bool DialogsWidget::animStep_show(float64 ms) {
|
|
|
|
float64 dt = ms / st::slideDuration;
|
2014-12-12 16:27:03 +00:00
|
|
|
bool res = true;
|
2015-10-17 14:52:26 +00:00
|
|
|
if (dt >= 1) {
|
|
|
|
_a_show.stop();
|
|
|
|
|
2014-12-12 16:27:03 +00:00
|
|
|
res = false;
|
2015-10-17 14:52:26 +00:00
|
|
|
a_coordUnder.finish();
|
|
|
|
a_coordOver.finish();
|
|
|
|
a_shadow.finish();
|
|
|
|
|
|
|
|
_cacheUnder = _cacheOver = QPixmap();
|
|
|
|
|
2015-09-29 13:24:39 +00:00
|
|
|
_scroll.show();
|
2014-12-12 16:27:03 +00:00
|
|
|
_filter.show();
|
|
|
|
onFilterUpdate(true);
|
|
|
|
activate();
|
2015-10-15 10:18:24 +00:00
|
|
|
|
|
|
|
if (App::app()) App::app()->mtpUnpause();
|
2014-12-12 16:27:03 +00:00
|
|
|
} else {
|
2015-10-17 14:52:26 +00:00
|
|
|
a_coordUnder.update(dt, st::slideFunction);
|
|
|
|
a_coordOver.update(dt, st::slideFunction);
|
|
|
|
a_shadow.update(dt, st::slideFunction);
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
2014-12-12 16:27:03 +00:00
|
|
|
update();
|
|
|
|
return res;
|
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
|
|
|
}
|
|
|
|
|
2014-10-10 12:46:20 +00:00
|
|
|
void DialogsWidget::itemRemoved(HistoryItem *item) {
|
2015-09-29 13:24:39 +00:00
|
|
|
_inner.itemRemoved(item);
|
2014-10-10 12:46:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void DialogsWidget::itemReplaced(HistoryItem *oldItem, HistoryItem *newItem) {
|
2015-09-29 13:24:39 +00:00
|
|
|
_inner.itemReplaced(oldItem, newItem);
|
2014-10-10 12:46:20 +00:00
|
|
|
}
|
|
|
|
|
2014-05-30 08:53:19 +00:00
|
|
|
void DialogsWidget::unreadCountsReceived(const QVector<MTPDialog> &dialogs) {
|
|
|
|
for (QVector<MTPDialog>::const_iterator i = dialogs.cbegin(), e = dialogs.cend(); i != e; ++i) {
|
2015-09-04 13:01:31 +00:00
|
|
|
switch (i->type()) {
|
|
|
|
case mtpc_dialog: {
|
|
|
|
const MTPDdialog &d(i->c_dialog());
|
2015-09-19 09:13:21 +00:00
|
|
|
if (History *h = App::historyLoaded(peerFromMTP(d.vpeer))) {
|
|
|
|
App::main()->applyNotifySetting(MTP_notifyPeer(d.vpeer), d.vnotify_settings, h);
|
|
|
|
if (d.vunread_count.v >= h->unreadCount) {
|
|
|
|
h->setUnreadCount(d.vunread_count.v, false);
|
|
|
|
h->inboxReadBefore = d.vread_inbox_max_id.v + 1;
|
2015-09-04 13:01:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} break;
|
|
|
|
case mtpc_dialogChannel: {
|
|
|
|
const MTPDdialogChannel &d(i->c_dialogChannel());
|
2015-09-19 09:13:21 +00:00
|
|
|
if (History *h = App::historyLoaded(peerFromMTP(d.vpeer))) {
|
|
|
|
if (h->peer->isChannel()) {
|
|
|
|
h->peer->asChannel()->ptsReceived(d.vpts.v);
|
|
|
|
if (d.vunread_count.v >= h->asChannelHistory()->unreadCountAll) {
|
|
|
|
h->asChannelHistory()->unreadCountAll = d.vunread_count.v;
|
|
|
|
h->inboxReadBefore = d.vread_inbox_max_id.v + 1;
|
|
|
|
}
|
2015-09-13 08:41:27 +00:00
|
|
|
}
|
2015-09-19 09:13:21 +00:00
|
|
|
App::main()->applyNotifySetting(MTP_notifyPeer(d.vpeer), d.vnotify_settings, h);
|
2015-11-02 22:33:57 +00:00
|
|
|
int32 unreadCount = h->isMegagroup() ? d.vunread_count.v : d.vunread_important_count.v;
|
|
|
|
if (unreadCount >= h->unreadCount) {
|
|
|
|
h->setUnreadCount(unreadCount, false);
|
2015-09-19 09:13:21 +00:00
|
|
|
h->inboxReadBefore = d.vread_inbox_max_id.v + 1;
|
2015-09-04 13:01:31 +00:00
|
|
|
}
|
2014-12-12 16:27:03 +00:00
|
|
|
}
|
2015-09-04 13:01:31 +00:00
|
|
|
} break;
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
}
|
2014-12-15 15:55:45 +00:00
|
|
|
if (App::wnd()) App::wnd()->updateCounter();
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
|
2015-09-03 13:15:07 +00:00
|
|
|
void DialogsWidget::dialogsReceived(const MTPmessages_Dialogs &dialogs, mtpRequestId req) {
|
2015-11-18 14:59:17 +00:00
|
|
|
if (_dialogsRequest != req) return;
|
|
|
|
|
|
|
|
const QVector<MTPDialog> *v = 0;
|
|
|
|
const QVector<MTPMessage> *m = 0;
|
2014-05-30 08:53:19 +00:00
|
|
|
switch (dialogs.type()) {
|
|
|
|
case mtpc_messages_dialogs: {
|
|
|
|
const MTPDmessages_dialogs &data(dialogs.c_messages_dialogs());
|
|
|
|
App::feedUsers(data.vusers);
|
|
|
|
App::feedChats(data.vchats);
|
2015-11-18 14:59:17 +00:00
|
|
|
m = &data.vmessages.c_vector().v;
|
|
|
|
v = &data.vdialogs.c_vector().v;
|
2014-05-30 08:53:19 +00:00
|
|
|
} break;
|
|
|
|
case mtpc_messages_dialogsSlice: {
|
|
|
|
const MTPDmessages_dialogsSlice &data(dialogs.c_messages_dialogsSlice());
|
|
|
|
App::feedUsers(data.vusers);
|
|
|
|
App::feedChats(data.vchats);
|
2015-11-18 14:59:17 +00:00
|
|
|
m = &data.vmessages.c_vector().v;
|
|
|
|
v = &data.vdialogs.c_vector().v;
|
2014-05-30 08:53:19 +00:00
|
|
|
} break;
|
|
|
|
}
|
|
|
|
|
2015-09-03 10:48:40 +00:00
|
|
|
if (!_contactsRequest) {
|
|
|
|
_contactsRequest = MTP::send(MTPcontacts_GetContacts(MTP_string("")), rpcDone(&DialogsWidget::contactsReceived), rpcFail(&DialogsWidget::contactsFailed));
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
|
2015-11-18 14:59:17 +00:00
|
|
|
if (m) {
|
|
|
|
App::feedMsgs(*m, NewMessageLast);
|
|
|
|
}
|
|
|
|
if (v) {
|
|
|
|
unreadCountsReceived(*v);
|
|
|
|
_inner.dialogsReceived(*v);
|
|
|
|
onListScroll();
|
|
|
|
|
|
|
|
int32 lastDate = 0;
|
|
|
|
PeerId lastPeer = 0;
|
|
|
|
MsgId lastMsgId = 0;
|
|
|
|
for (int32 i = v->size(); i > 0;) {
|
|
|
|
PeerId peer = 0;
|
|
|
|
MsgId msgId = 0;
|
|
|
|
const MTPDialog &d(v->at(--i));
|
|
|
|
switch (d.type()) {
|
|
|
|
case mtpc_dialog:
|
|
|
|
msgId = d.c_dialog().vtop_message.v;
|
|
|
|
peer = peerFromMTP(d.c_dialog().vpeer);
|
|
|
|
break;
|
|
|
|
case mtpc_dialogChannel:
|
2015-11-19 15:56:29 +00:00
|
|
|
//msgId = d.c_dialogChannel().vtop_important_message.v;
|
|
|
|
//if (!msgId) msgId = d.c_dialogChannel().vtop_message.v;
|
|
|
|
msgId = d.c_dialogChannel().vtop_message.v;
|
2015-11-18 14:59:17 +00:00
|
|
|
peer = peerFromMTP(d.c_dialogChannel().vpeer);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (peer) {
|
|
|
|
if (!lastPeer) lastPeer = peer;
|
|
|
|
if (msgId) {
|
|
|
|
if (!lastMsgId) lastMsgId = msgId;
|
|
|
|
for (int32 j = m->size(); j > 0;) {
|
|
|
|
const MTPMessage &d(m->at(--j));
|
2015-11-19 15:56:29 +00:00
|
|
|
if (idFromMessage(d) == msgId && peerFromMessage(d) == peer) {
|
2015-11-18 14:59:17 +00:00
|
|
|
int32 date = dateFromMessage(d);
|
|
|
|
if (date) lastDate = date;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (lastDate) break;
|
|
|
|
}
|
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
|
|
|
}
|
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
|
|
|
|
|
|
|
_dialogsRequest = 0;
|
|
|
|
loadDialogs();
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
|
2015-09-03 13:15:07 +00:00
|
|
|
bool DialogsWidget::dialogsFailed(const RPCError &error, mtpRequestId req) {
|
2015-10-06 19:49:23 +00:00
|
|
|
if (mtpIsFlood(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()));
|
2015-09-03 13:15:07 +00:00
|
|
|
if (_dialogsRequest == req) {
|
|
|
|
_dialogsRequest = 0;
|
|
|
|
}
|
2014-05-30 08:53:19 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-07-13 09:50:38 +00:00
|
|
|
bool DialogsWidget::onSearchMessages(bool searchCache) {
|
2015-08-18 16:10:01 +00:00
|
|
|
QString q = _filter.getLastText().trimmed();
|
2014-07-04 11:12:54 +00:00
|
|
|
if (q.isEmpty()) {
|
|
|
|
if (_searchRequest) {
|
2015-09-13 08:41:27 +00:00
|
|
|
MTP::cancel(_searchRequest);
|
2014-07-04 11:12:54 +00:00
|
|
|
_searchRequest = 0;
|
|
|
|
}
|
2014-10-22 18:39:03 +00:00
|
|
|
if (_peopleRequest) {
|
2015-09-13 08:41:27 +00:00
|
|
|
MTP::cancel(_peopleRequest);
|
2014-10-22 18:39:03 +00:00
|
|
|
_peopleRequest = 0;
|
|
|
|
}
|
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;
|
2015-09-13 08:41:27 +00:00
|
|
|
if (_searchRequest) {
|
|
|
|
MTP::cancel(_searchRequest);
|
|
|
|
_searchRequest = 0;
|
|
|
|
}
|
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;
|
2015-09-13 08:41:27 +00:00
|
|
|
if (_searchRequest) {
|
|
|
|
MTP::cancel(_searchRequest);
|
|
|
|
}
|
2015-11-18 13:11:56 +00:00
|
|
|
if (_searchInPeer) {
|
|
|
|
int32 flags = (_searchInPeer->isChannel() && !_searchInPeer->isMegagroup()) ? MTPmessages_Search::flag_important_only : 0;
|
|
|
|
_searchRequest = MTP::send(MTPmessages_Search(MTP_int(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));
|
|
|
|
} 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) {
|
|
|
|
PeopleCache::const_iterator i = _peopleCache.constFind(q);
|
|
|
|
if (i != _peopleCache.cend()) {
|
|
|
|
_peopleQuery = q;
|
|
|
|
_peopleRequest = 0;
|
|
|
|
peopleReceived(i.value(), 0);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
} else if (_peopleQuery != q) {
|
|
|
|
_peopleQuery = q;
|
|
|
|
_peopleFull = false;
|
|
|
|
_peopleRequest = MTP::send(MTPcontacts_Search(MTP_string(_peopleQuery), MTP_int(SearchPeopleLimit)), rpcDone(&DialogsWidget::peopleReceived), rpcFail(&DialogsWidget::peopleFailed));
|
|
|
|
_peopleQueries.insert(_peopleRequest, _peopleQuery);
|
|
|
|
}
|
|
|
|
}
|
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() {
|
2015-09-29 13:24:39 +00:00
|
|
|
_inner.choosePeer();
|
2015-06-26 09:07:59 +00:00
|
|
|
}
|
|
|
|
|
2015-09-21 20:57:42 +00:00
|
|
|
void DialogsWidget::searchMessages(const QString &query, PeerData *inPeer) {
|
2015-11-18 13:11:56 +00:00
|
|
|
if ((_filter.getLastText() != query) || (inPeer && inPeer != _searchInPeer && inPeer->migrateTo() != _searchInPeer)) {
|
2015-09-21 20:57:42 +00:00
|
|
|
if (inPeer) {
|
2015-11-18 13:11:56 +00:00
|
|
|
_searchInPeer = inPeer->migrateTo() ? inPeer->migrateTo() : inPeer;
|
|
|
|
_searchInMigrated = _searchInPeer ? _searchInPeer->migrateFrom() : 0;
|
|
|
|
_inner.searchInPeer(_searchInPeer);
|
2015-09-21 20:57:42 +00:00
|
|
|
}
|
2014-07-16 06:58:36 +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
|
|
|
|
2015-09-29 13:24:39 +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) {
|
|
|
|
int32 offsetDate = _inner.lastSearchDate();
|
|
|
|
PeerData *offsetPeer = _inner.lastSearchPeer();
|
|
|
|
MsgId offsetId = _inner.lastSearchId();
|
|
|
|
if (_searchInPeer) {
|
|
|
|
int32 flags = (_searchInPeer->isChannel() && !_searchInPeer->isMegagroup()) ? MTPmessages_Search::flag_important_only : 0;
|
|
|
|
_searchRequest = MTP::send(MTPmessages_Search(MTP_int(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));
|
|
|
|
} 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) {
|
|
|
|
MsgId offsetMigratedId = _inner.lastSearchMigratedId();
|
|
|
|
int32 flags = (_searchInMigrated->isChannel() && !_searchInMigrated->isMegagroup()) ? MTPmessages_Search::flag_important_only : 0;
|
|
|
|
_searchRequest = MTP::send(MTPmessages_Search(MTP_int(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() {
|
2015-09-03 10:48:40 +00:00
|
|
|
if (_dialogsRequest) return;
|
2015-11-18 14:59:17 +00:00
|
|
|
if (_dialogsFull) {
|
2015-09-29 13:24:39 +00:00
|
|
|
_inner.addAllSavedPeers();
|
2015-06-15 17:19:24 +00:00
|
|
|
cSetDialogsReceived(true);
|
|
|
|
return;
|
|
|
|
}
|
2014-05-30 08:53:19 +00:00
|
|
|
|
2015-11-20 13:34:37 +00:00
|
|
|
int32 loadCount = (!cTestMode() || _dialogsOffsetDate) ? DialogsPerPage : DialogsFirstLoad;
|
|
|
|
if (!cTestMode() && _dialogsOffsetDate) return;
|
2015-11-18 14:59:17 +00:00
|
|
|
_dialogsRequest = MTP::send(MTPmessages_GetDialogs(MTP_int(_dialogsOffsetDate), MTP_int(_dialogsOffsetId), _dialogsOffsetPeer ? _dialogsOffsetPeer->input : MTP_inputPeerEmpty(), MTP_int(loadCount)), rpcDone(&DialogsWidget::dialogsReceived), rpcFail(&DialogsWidget::dialogsFailed));
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void DialogsWidget::contactsReceived(const MTPcontacts_Contacts &contacts) {
|
2015-09-07 15:53:46 +00:00
|
|
|
cSetContactsReceived(true);
|
2014-05-30 08:53:19 +00:00
|
|
|
if (contacts.type() == mtpc_contacts_contacts) {
|
|
|
|
const MTPDcontacts_contacts &d(contacts.c_contacts_contacts());
|
|
|
|
App::feedUsers(d.vusers);
|
2015-09-29 13:24:39 +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) {
|
2015-10-06 19:49:23 +00:00
|
|
|
if (mtpIsFlood(error)) return false;
|
2015-04-04 20:01:34 +00:00
|
|
|
|
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) {
|
|
|
|
if (_inner.state() == DialogsInner::FilteredState || _inner.state() == DialogsInner::SearchedState) {
|
|
|
|
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: {
|
2015-09-04 13:01:31 +00:00
|
|
|
const MTPDmessages_messages &d(result.c_messages_messages());
|
|
|
|
App::feedUsers(d.vusers);
|
|
|
|
App::feedChats(d.vchats);
|
|
|
|
const QVector<MTPMessage> &msgs(d.vmessages.c_vector().v);
|
2015-11-18 13:11:56 +00:00
|
|
|
if (!_inner.searchReceived(msgs, type, msgs.size())) {
|
|
|
|
if (type == DialogsSearchMigratedFromStart || type == DialogsSearchMigratedFromOffset) {
|
|
|
|
_searchFullMigrated = true;
|
|
|
|
} else {
|
|
|
|
_searchFull = true;
|
|
|
|
}
|
2014-07-04 11:12:54 +00:00
|
|
|
}
|
|
|
|
} break;
|
|
|
|
|
|
|
|
case mtpc_messages_messagesSlice: {
|
2015-09-04 13:01:31 +00:00
|
|
|
const MTPDmessages_messagesSlice &d(result.c_messages_messagesSlice());
|
|
|
|
App::feedUsers(d.vusers);
|
|
|
|
App::feedChats(d.vchats);
|
|
|
|
const QVector<MTPMessage> &msgs(d.vmessages.c_vector().v);
|
2015-11-18 13:11:56 +00:00
|
|
|
if (!_inner.searchReceived(msgs, type, d.vcount.v)) {
|
|
|
|
if (type == DialogsSearchMigratedFromStart || type == DialogsSearchMigratedFromOffset) {
|
|
|
|
_searchFullMigrated = true;
|
|
|
|
} else {
|
|
|
|
_searchFull = true;
|
|
|
|
}
|
2015-09-04 13:01:31 +00:00
|
|
|
}
|
|
|
|
} break;
|
|
|
|
|
|
|
|
case mtpc_messages_channelMessages: {
|
|
|
|
const MTPDmessages_channelMessages &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)"));
|
|
|
|
}
|
|
|
|
if (d.has_collapsed()) { // should not be returned
|
|
|
|
LOG(("API Error: channels.getMessages and messages.getMessages should not return collapsed groups! (DialogsWidget::searchReceived)"));
|
2015-09-13 08:41:27 +00:00
|
|
|
}
|
|
|
|
|
2015-09-04 13:01:31 +00:00
|
|
|
App::feedUsers(d.vusers);
|
|
|
|
App::feedChats(d.vchats);
|
|
|
|
const QVector<MTPMessage> &msgs(d.vmessages.c_vector().v);
|
2015-11-18 13:11:56 +00:00
|
|
|
if (!_inner.searchReceived(msgs, type, d.vcount.v)) {
|
|
|
|
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();
|
2014-07-04 11:12:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-10-22 18:39:03 +00:00
|
|
|
void DialogsWidget::peopleReceived(const MTPcontacts_Found &result, mtpRequestId req) {
|
2014-10-23 16:05:33 +00:00
|
|
|
QString q = _peopleQuery;
|
2015-09-29 13:24:39 +00:00
|
|
|
if (_inner.state() == DialogsInner::FilteredState || _inner.state() == DialogsInner::SearchedState) {
|
2014-10-22 18:39:03 +00:00
|
|
|
PeopleQueries::iterator i = _peopleQueries.find(req);
|
|
|
|
if (i != _peopleQueries.cend()) {
|
2014-10-23 16:05:33 +00:00
|
|
|
q = i.value();
|
|
|
|
_peopleCache[q] = result;
|
2014-10-22 18:39:03 +00:00
|
|
|
_peopleQueries.erase(i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (_peopleRequest == req) {
|
|
|
|
switch (result.type()) {
|
|
|
|
case mtpc_contacts_found: {
|
|
|
|
App::feedUsers(result.c_contacts_found().vusers);
|
2015-09-21 20:57:42 +00:00
|
|
|
App::feedChats(result.c_contacts_found().vchats);
|
2015-09-29 13:24:39 +00:00
|
|
|
_inner.peopleReceived(q, result.c_contacts_found().vresults.c_vector().v);
|
2014-10-22 18:39:03 +00:00
|
|
|
} break;
|
|
|
|
}
|
|
|
|
|
|
|
|
_peopleRequest = 0;
|
|
|
|
onListScroll();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-11-18 13:11:56 +00:00
|
|
|
bool DialogsWidget::searchFailed(DialogsSearchRequestType type, const RPCError &error, mtpRequestId req) {
|
2015-10-06 19:49:23 +00:00
|
|
|
if (mtpIsFlood(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) {
|
2015-10-06 19:49:23 +00:00
|
|
|
if (mtpIsFlood(error)) return false;
|
2015-04-04 20:01:34 +00:00
|
|
|
|
2014-10-22 18:39:03 +00:00
|
|
|
if (_peopleRequest == req) {
|
|
|
|
_peopleRequest = 0;
|
|
|
|
_peopleFull = true;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-05-30 08:53:19 +00:00
|
|
|
bool DialogsWidget::addNewContact(int32 uid, bool show) {
|
|
|
|
_filter.setText(QString());
|
2015-09-22 09:58:40 +00:00
|
|
|
_filter.updatePlaceholder();
|
2014-05-30 08:53:19 +00:00
|
|
|
onFilterUpdate();
|
2015-09-29 13:24:39 +00:00
|
|
|
int32 to = _inner.addNewContact(uid, true);
|
2015-09-02 10:20:33 +00:00
|
|
|
if (to < -1 || !show) return false;
|
2015-09-29 13:24:39 +00:00
|
|
|
_inner.refresh();
|
|
|
|
if (to >= 0) _scroll.scrollToY(to);
|
2014-05-30 08:53:19 +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"));
|
|
|
|
if (_dragForward && !cWideMode()) _dragForward = false;
|
2015-06-24 17:24:48 +00:00
|
|
|
if (_dragForward) {
|
|
|
|
e->setDropAction(Qt::CopyAction);
|
|
|
|
e->accept();
|
2015-09-29 13:24:39 +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) {
|
2015-09-29 13:24:39 +00:00
|
|
|
if (_scroll.geometry().contains(e->pos())) {
|
2015-06-26 09:07:59 +00:00
|
|
|
if (_dragForward) {
|
|
|
|
updateDragInScroll(true);
|
|
|
|
} else {
|
|
|
|
_chooseByDragTimer.start(ChoosePeerByDragTimeout);
|
|
|
|
}
|
2015-09-29 13:24:39 +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);
|
2015-09-29 13:24:39 +00:00
|
|
|
_inner.leaveEvent(0);
|
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();
|
|
|
|
}
|
2015-09-29 13:24:39 +00:00
|
|
|
_inner.leaveEvent(0);
|
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();
|
2015-09-29 13:24:39 +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() {
|
2015-03-02 12:34:16 +00:00
|
|
|
// if (!App::self()) return;
|
|
|
|
|
2015-09-29 13:24:39 +00:00
|
|
|
_inner.loadPeerPhotos(_scroll.scrollTop());
|
2015-11-18 13:11:56 +00:00
|
|
|
if (_inner.state() == DialogsInner::SearchedState || (_inner.state() == DialogsInner::FilteredState && _searchInMigrated && _searchFull && !_searchFullMigrated)) {
|
2015-09-29 13:24:39 +00:00
|
|
|
if (_scroll.scrollTop() > (_inner.searchList().size() + _inner.filteredList().size() + _inner.peopleList().size()) * st::dlgHeight - PreloadHeightsCount * _scroll.height()) {
|
2015-11-18 13:11:56 +00:00
|
|
|
onSearchMore();
|
2014-07-04 11:12:54 +00:00
|
|
|
}
|
2015-09-29 13:24:39 +00:00
|
|
|
} else if (_scroll.scrollTop() > _inner.dialogsList().list.count * st::dlgHeight - PreloadHeightsCount * _scroll.height()) {
|
2014-05-30 08:53:19 +00:00
|
|
|
loadDialogs();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2015-08-18 16:10:01 +00:00
|
|
|
QString filterText = _filter.getLastText();
|
2015-11-13 15:14:33 +00:00
|
|
|
_inner.onFilterUpdate(filterText, force);
|
2014-07-13 09:50:38 +00:00
|
|
|
if (filterText.isEmpty()) {
|
|
|
|
_searchCache.clear();
|
|
|
|
_searchQueries.clear();
|
|
|
|
_searchQuery = QString();
|
2014-12-12 16:27:03 +00:00
|
|
|
_cancelSearch.hide();
|
|
|
|
_newGroup.show();
|
2014-07-13 09:50:38 +00:00
|
|
|
} else if (_cancelSearch.isHidden()) {
|
2014-07-04 11:12:54 +00:00
|
|
|
_cancelSearch.show();
|
|
|
|
_newGroup.hide();
|
|
|
|
}
|
2014-10-22 18:39:03 +00:00
|
|
|
if (filterText.size() < MinUsernameLength) {
|
|
|
|
_peopleCache.clear();
|
|
|
|
_peopleQueries.clear();
|
|
|
|
_peopleQuery = QString();
|
|
|
|
}
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
|
2015-08-04 15:01:47 +00:00
|
|
|
void DialogsWidget::searchInPeer(PeerData *peer) {
|
|
|
|
onCancelSearch();
|
2015-11-18 13:11:56 +00:00
|
|
|
_searchInPeer = peer ? (peer->migrateTo() ? peer->migrateTo() : peer) : 0;
|
|
|
|
_searchInMigrated = _searchInPeer ? _searchInPeer->migrateFrom() : 0;
|
|
|
|
_inner.searchInPeer(_searchInPeer);
|
2015-08-04 15:01:47 +00:00
|
|
|
onFilterUpdate(true);
|
|
|
|
}
|
|
|
|
|
2015-03-24 10:00:27 +00:00
|
|
|
void DialogsWidget::onFilterCursorMoved(int from, int to) {
|
2015-03-24 15:18:20 +00:00
|
|
|
if (to < 0) to = _filter.cursorPosition();
|
2015-08-18 16:10:01 +00:00
|
|
|
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;
|
|
|
|
}
|
2015-09-29 13:24:39 +00:00
|
|
|
_inner.onHashtagFilterUpdate(r);
|
2015-03-24 10:00:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void DialogsWidget::onCompleteHashtag(QString tag) {
|
2015-08-18 16:10:01 +00:00
|
|
|
QString t = _filter.getLastText(), r;
|
2015-03-24 10:00:27 +00:00
|
|
|
int cur = _filter.cursorPosition();
|
|
|
|
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);
|
|
|
|
_filter.setText(r);
|
|
|
|
_filter.setCursorPosition(start + 1 + tag.size() + 1);
|
|
|
|
onFilterUpdate(true);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (!t.at(start).isLetterOrNumber() && t.at(start) != '_') break;
|
|
|
|
}
|
|
|
|
_filter.setText(t.mid(0, cur) + '#' + tag + ' ' + t.mid(cur));
|
|
|
|
_filter.setCursorPosition(cur + 1 + tag.size() + 1);
|
|
|
|
onFilterUpdate(true);
|
|
|
|
}
|
|
|
|
|
2014-05-30 08:53:19 +00:00
|
|
|
void DialogsWidget::resizeEvent(QResizeEvent *e) {
|
2015-10-17 08:31:48 +00:00
|
|
|
int32 w = width();
|
2014-05-30 08:53:19 +00:00
|
|
|
_filter.setGeometry(st::dlgPaddingHor, st::dlgFilterPadding, w - 2 * st::dlgPaddingHor, _filter.height());
|
|
|
|
_newGroup.move(w - _newGroup.width() - st::dlgPaddingHor, _filter.y());
|
|
|
|
_addContact.move(w - _addContact.width() - st::dlgPaddingHor, _filter.y());
|
2014-07-04 11:12:54 +00:00
|
|
|
_cancelSearch.move(w - _cancelSearch.width() - st::dlgPaddingHor, _filter.y());
|
2015-09-29 13:24:39 +00:00
|
|
|
_scroll.move(0, _filter.height() + 2 * st::dlgFilterPadding);
|
2015-07-03 08:47:16 +00:00
|
|
|
|
|
|
|
int32 addToY = App::main() ? App::main()->contentScrollAddToY() : 0;
|
2015-09-29 13:24:39 +00:00
|
|
|
int32 newScrollY = _scroll.scrollTop() + addToY;
|
|
|
|
_scroll.resize(w, height() - _filter.y() - _filter.height() - st::dlgFilterPadding - st::dlgPaddingVer);
|
2015-07-03 08:47:16 +00:00
|
|
|
if (addToY) {
|
2015-09-29 13:24:39 +00:00
|
|
|
_scroll.scrollToY(newScrollY);
|
2015-07-03 08:47:16 +00:00
|
|
|
} else {
|
|
|
|
onListScroll();
|
|
|
|
}
|
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) {
|
2015-09-29 13:24:39 +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) {
|
2015-09-29 13:24:39 +00:00
|
|
|
_inner.setMouseSel(false);
|
|
|
|
_inner.selectSkip(1);
|
2014-05-30 08:53:19 +00:00
|
|
|
} else if (e->key() == Qt::Key_Up) {
|
2015-09-29 13:24:39 +00:00
|
|
|
_inner.setMouseSel(false);
|
|
|
|
_inner.selectSkip(-1);
|
2014-05-30 08:53:19 +00:00
|
|
|
} else if (e->key() == Qt::Key_PageDown) {
|
2015-09-29 13:24:39 +00:00
|
|
|
_inner.setMouseSel(false);
|
|
|
|
_inner.selectSkipPage(_scroll.height(), 1);
|
2014-05-30 08:53:19 +00:00
|
|
|
} else if (e->key() == Qt::Key_PageUp) {
|
2015-09-29 13:24:39 +00:00
|
|
|
_inner.setMouseSel(false);
|
|
|
|
_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;
|
|
|
|
|
2014-05-30 08:53:19 +00:00
|
|
|
QPainter p(this);
|
2014-12-12 16:27:03 +00:00
|
|
|
QRect r(e->rect());
|
|
|
|
if (r != rect()) {
|
|
|
|
p.setClipRect(r);
|
|
|
|
}
|
2015-10-17 14:52:26 +00:00
|
|
|
if (_a_show.animating()) {
|
|
|
|
if (a_coordOver.current() > 0) {
|
2015-10-18 23:01:18 +00:00
|
|
|
p.drawPixmap(QRect(0, 0, a_coordOver.current(), height()), _cacheUnder, QRect(-a_coordUnder.current() * cRetinaFactor(), 0, a_coordOver.current() * cRetinaFactor(), height() * cRetinaFactor()));
|
2015-10-17 14:52:26 +00:00
|
|
|
p.setOpacity(a_shadow.current() * st::slideFadeOut);
|
|
|
|
p.fillRect(0, 0, a_coordOver.current(), height(), st::black->b);
|
|
|
|
p.setOpacity(1);
|
|
|
|
}
|
|
|
|
p.drawPixmap(a_coordOver.current(), 0, _cacheOver);
|
|
|
|
p.setOpacity(a_shadow.current());
|
|
|
|
p.drawPixmap(QRect(a_coordOver.current() - st::slideShadow.pxWidth(), 0, st::slideShadow.pxWidth(), height()), App::sprite(), st::slideShadow);
|
2014-12-12 16:27:03 +00:00
|
|
|
return;
|
|
|
|
}
|
2015-10-17 08:31:48 +00:00
|
|
|
QRect above(0, 0, width(), _scroll.y());
|
2015-09-29 13:24:39 +00:00
|
|
|
if (above.intersects(r)) {
|
|
|
|
p.fillRect(above.intersected(r), st::white->b);
|
|
|
|
}
|
2015-10-17 08:31:48 +00:00
|
|
|
QRect below(0, _scroll.y() + qMin(_scroll.height(), _inner.height()), width(), height());
|
2015-09-29 13:24:39 +00:00
|
|
|
if (below.intersects(r)) {
|
|
|
|
p.fillRect(below.intersected(r), st::white->b);
|
|
|
|
}
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void DialogsWidget::destroyData() {
|
2015-09-29 13:24:39 +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 {
|
2015-09-29 13:24:39 +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 {
|
2015-09-29 13:24:39 +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) {
|
2015-09-29 13:24:39 +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) {
|
|
|
|
_inner.removeDialog(history);
|
2014-05-30 08:53:19 +00:00
|
|
|
onFilterUpdate();
|
|
|
|
}
|
|
|
|
|
|
|
|
void DialogsWidget::removeContact(UserData *user) {
|
|
|
|
_filter.setText(QString());
|
2015-09-22 09:58:40 +00:00
|
|
|
_filter.updatePlaceholder();
|
2014-05-30 08:53:19 +00:00
|
|
|
onFilterUpdate();
|
2015-09-29 13:24:39 +00:00
|
|
|
_inner.removeContact(user);
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
DialogsIndexed &DialogsWidget::contactsList() {
|
2015-09-29 13:24:39 +00:00
|
|
|
return _inner.contactsList();
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
|
2015-06-15 17:19:24 +00:00
|
|
|
DialogsIndexed &DialogsWidget::dialogsList() {
|
2015-09-29 13:24:39 +00:00
|
|
|
return _inner.dialogsList();
|
2015-06-15 17:19:24 +00:00
|
|
|
}
|
|
|
|
|
2014-05-30 08:53:19 +00:00
|
|
|
void DialogsWidget::onAddContact() {
|
2014-11-25 12:15:29 +00:00
|
|
|
App::wnd()->replaceLayer(new AddContactBox());
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void DialogsWidget::onNewGroup() {
|
2015-09-16 13:04:08 +00:00
|
|
|
App::wnd()->showLayer(new NewGroupBox());
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
|
2014-12-12 16:27:03 +00:00
|
|
|
bool DialogsWidget::onCancelSearch() {
|
2015-08-18 16:10:01 +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) {
|
|
|
|
if (!cWideMode()) {
|
|
|
|
App::main()->showPeerHistory(_searchInPeer->id, ShowAtUnreadMsgId);
|
|
|
|
}
|
2015-11-18 13:11:56 +00:00
|
|
|
_searchInPeer = _searchInMigrated = 0;
|
2015-09-29 13:24:39 +00:00
|
|
|
_inner.searchInPeer(0);
|
2015-08-04 15:01:47 +00:00
|
|
|
clearing = true;
|
|
|
|
}
|
2015-09-29 13:24:39 +00:00
|
|
|
_inner.clearFilter();
|
2014-07-04 11:12:54 +00:00
|
|
|
_filter.clear();
|
|
|
|
_filter.updatePlaceholder();
|
|
|
|
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) {
|
2015-10-18 12:49:34 +00:00
|
|
|
if (!cWideMode() && !App::main()->selectingPeer()) {
|
2015-08-04 15:01:47 +00:00
|
|
|
App::main()->showPeerHistory(_searchInPeer->id, ShowAtUnreadMsgId);
|
|
|
|
}
|
2015-11-18 13:11:56 +00:00
|
|
|
_searchInPeer = _searchInMigrated = 0;
|
2015-09-29 13:24:39 +00:00
|
|
|
_inner.searchInPeer(0);
|
2015-08-04 15:01:47 +00:00
|
|
|
}
|
2015-09-29 13:24:39 +00:00
|
|
|
_inner.clearFilter();
|
2015-08-04 15:01:47 +00:00
|
|
|
_filter.clear();
|
|
|
|
_filter.updatePlaceholder();
|
|
|
|
onFilterUpdate();
|
2015-10-18 12:49:34 +00:00
|
|
|
if (cWideMode() && !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) {
|
2015-09-29 13:24:39 +00:00
|
|
|
int32 st = _scroll.scrollTop();
|
2015-09-24 16:05:06 +00:00
|
|
|
if (st > movedTo && st < movedFrom) {
|
2015-09-29 13:24:39 +00:00
|
|
|
_scroll.scrollToY(st + st::dlgHeight);
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
}
|