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.
|
|
|
|
|
|
|
|
Full license: https://github.com/telegramdesktop/tdesktop/blob/master/LICENSE
|
2014-12-01 10:47:38 +00:00
|
|
|
Copyright (c) 2014 John Preston, https://desktop.telegram.org
|
2014-05-30 08:53:19 +00:00
|
|
|
*/
|
|
|
|
#include "stdafx.h"
|
|
|
|
#include "style.h"
|
|
|
|
#include "lang.h"
|
|
|
|
|
|
|
|
#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"
|
|
|
|
|
2014-06-14 19:32:11 +00:00
|
|
|
DialogsListWidget::DialogsListWidget(QWidget *parent, MainWidget *main) : QWidget(parent),
|
2014-11-25 12:15:29 +00:00
|
|
|
dialogs(false),
|
|
|
|
contactsNoDialogs(true),
|
|
|
|
contacts(true),
|
|
|
|
sel(0),
|
|
|
|
contactSel(false),
|
|
|
|
selByMouse(false),
|
2015-03-24 10:00:27 +00:00
|
|
|
hashtagSel(-1),
|
2014-11-25 12:15:29 +00:00
|
|
|
filteredSel(-1),
|
|
|
|
searchedCount(0),
|
|
|
|
searchedSel(-1),
|
|
|
|
peopleSel(-1),
|
|
|
|
_lastSearchId(0),
|
|
|
|
_state(DefaultState),
|
2015-03-24 15:18:20 +00:00
|
|
|
_addContactLnk(this, lang(lng_add_contact_button)),
|
|
|
|
_overDelete(false) {
|
2014-11-25 12:15:29 +00:00
|
|
|
connect(main, SIGNAL(dialogToTop(const History::DialogLinks&)), this, SLOT(onDialogToTop(const History::DialogLinks&)));
|
|
|
|
connect(main, SIGNAL(peerNameChanged(PeerData*,const PeerData::Names&,const PeerData::NameFirstChars&)), this, SLOT(onPeerNameChanged(PeerData*,const PeerData::Names&,const PeerData::NameFirstChars&)));
|
|
|
|
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()));
|
|
|
|
refresh(false);
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
|
2015-03-24 10:00:27 +00:00
|
|
|
int32 DialogsListWidget::filteredOffset() const {
|
|
|
|
return hashtagResults.size() * st::mentionHeight;
|
|
|
|
}
|
|
|
|
|
|
|
|
int32 DialogsListWidget::peopleOffset() const {
|
|
|
|
return filteredOffset() + (filterResults.size() * st::dlgHeight) + st::searchedBarHeight;
|
|
|
|
}
|
|
|
|
|
|
|
|
int32 DialogsListWidget::searchedOffset() const {
|
|
|
|
return peopleOffset() + (peopleResults.isEmpty() ? 0 : ((peopleResults.size() * st::dlgHeight) + st::searchedBarHeight));
|
|
|
|
}
|
|
|
|
|
2014-05-30 08:53:19 +00:00
|
|
|
void DialogsListWidget::paintEvent(QPaintEvent *e) {
|
|
|
|
QRect r(e->rect());
|
|
|
|
bool trivial = (rect() == r);
|
|
|
|
|
2015-04-11 10:04:10 +00:00
|
|
|
Painter p(this);
|
2014-05-30 08:53:19 +00:00
|
|
|
if (!trivial) {
|
|
|
|
p.setClipRect(r);
|
|
|
|
}
|
2015-04-11 10:04:10 +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) {
|
|
|
|
dialogs.list.paint(p, width(), r.top(), r.bottom(), active, selected);
|
|
|
|
}
|
|
|
|
if (contactsNoDialogs.list.count) {
|
|
|
|
contactsNoDialogs.list.paint(p, width(), r.top() - otherStart, r.bottom() - otherStart, active, selected);
|
|
|
|
} else if (!otherStart) {
|
2014-11-25 12:15:29 +00:00
|
|
|
p.setFont(st::noContactsFont->f);
|
|
|
|
p.setPen(st::noContactsColor->p);
|
|
|
|
p.drawText(QRect(0, 0, width(), st::noContactsHeight - (cContactsReceived() ? st::noContactsFont->height : 0)), lang(cContactsReceived() ? lng_no_contacts : 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-03-24 10:00:27 +00:00
|
|
|
if (!hashtagResults.isEmpty()) {
|
|
|
|
int32 from = r.top() / int32(st::mentionHeight);
|
|
|
|
if (from < 0) {
|
|
|
|
from = 0;
|
|
|
|
} else if (from > hashtagResults.size()) {
|
|
|
|
from = hashtagResults.size();
|
|
|
|
}
|
|
|
|
p.translate(0, from * st::mentionHeight);
|
|
|
|
if (from < hashtagResults.size()) {
|
|
|
|
int32 to = (r.bottom() / int32(st::mentionHeight)) + 1, w = width();
|
|
|
|
if (to > hashtagResults.size()) to = hashtagResults.size();
|
|
|
|
p.setFont(st::mentionFont->f);
|
|
|
|
p.setPen(st::black->p);
|
|
|
|
for (; from < to; ++from) {
|
|
|
|
bool selected = (from == hashtagSel);
|
2015-03-24 15:18:20 +00:00
|
|
|
if (selected) {
|
|
|
|
p.fillRect(0, 0, w, st::mentionHeight, st::dlgHoverBG->b);
|
|
|
|
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-03-24 10:00:27 +00:00
|
|
|
QString tag = st::mentionFont->m.elidedText('#' + hashtagResults.at(from), Qt::ElideRight, w - st::dlgPaddingHor * 2);
|
|
|
|
p.drawText(st::dlgPaddingHor, st::mentionTop + st::mentionFont->ascent, tag);
|
|
|
|
p.translate(0, st::mentionHeight);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!filterResults.isEmpty()) {
|
|
|
|
int32 skip = filteredOffset();
|
|
|
|
int32 from = (r.top() - skip) / int32(st::dlgHeight);
|
2014-07-13 09:50:38 +00:00
|
|
|
if (from < 0) {
|
|
|
|
from = 0;
|
|
|
|
} else if (from > filterResults.size()) {
|
|
|
|
from = filterResults.size();
|
|
|
|
}
|
|
|
|
p.translate(0, from * st::dlgHeight);
|
2014-07-04 11:12:54 +00:00
|
|
|
if (from < filterResults.size()) {
|
2014-05-30 08:53:19 +00:00
|
|
|
int32 to = (r.bottom() / int32(st::dlgHeight)) + 1, w = width();
|
2014-07-04 11:12:54 +00:00
|
|
|
if (to > filterResults.size()) to = filterResults.size();
|
2014-05-30 08:53:19 +00:00
|
|
|
for (; from < to; ++from) {
|
2014-07-13 09:50:38 +00:00
|
|
|
bool active = (filterResults[from]->history->peer == App::main()->activePeer() && !App::main()->activeMsgId());
|
2014-05-30 08:53:19 +00:00
|
|
|
bool selected = (from == filteredSel);
|
2014-07-04 11:12:54 +00:00
|
|
|
filterResults[from]->paint(p, w, active, selected);
|
|
|
|
p.translate(0, st::dlgHeight);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-07-13 09:50:38 +00:00
|
|
|
|
2014-10-22 18:39:03 +00:00
|
|
|
if (!peopleResults.isEmpty()) {
|
|
|
|
p.fillRect(0, 0, width(), st::searchedBarHeight, st::searchedBarBG->b);
|
|
|
|
p.setFont(st::searchedBarFont->f);
|
|
|
|
p.setPen(st::searchedBarColor->p);
|
|
|
|
p.drawText(QRect(0, 0, width(), st::searchedBarHeight), lang(lng_search_global_results), style::al_center);
|
|
|
|
p.translate(0, st::searchedBarHeight);
|
|
|
|
|
2015-03-24 10:00:27 +00:00
|
|
|
int32 skip = peopleOffset();
|
2014-10-22 18:39:03 +00:00
|
|
|
int32 from = (r.top() - skip) / int32(st::dlgHeight);
|
|
|
|
if (from < 0) {
|
|
|
|
from = 0;
|
|
|
|
} else if (from > peopleResults.size()) {
|
|
|
|
from = peopleResults.size();
|
|
|
|
}
|
|
|
|
p.translate(0, from * st::dlgHeight);
|
|
|
|
if (from < peopleResults.size()) {
|
|
|
|
int32 to = ((r.bottom() - skip) / int32(st::dlgHeight)) + 1, w = width();
|
|
|
|
if (to > peopleResults.size()) to = peopleResults.size();
|
|
|
|
for (; from < to; ++from) {
|
|
|
|
bool active = (peopleResults[from] == App::main()->activePeer() && !App::main()->activeMsgId());
|
|
|
|
bool selected = (from == peopleSel);
|
|
|
|
peopleResultPaint(peopleResults[from], p, w, active, selected);
|
|
|
|
p.translate(0, st::dlgHeight);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-07-13 09:50:38 +00:00
|
|
|
if (_state == SearchedState || !searchResults.isEmpty()) {
|
2014-12-18 18:40:49 +00:00
|
|
|
QString text = lng_search_found_results(lt_count, searchResults.isEmpty() ? 0 : searchedCount);
|
2014-07-13 09:50:38 +00:00
|
|
|
p.fillRect(0, 0, width(), st::searchedBarHeight, st::searchedBarBG->b);
|
|
|
|
p.setFont(st::searchedBarFont->f);
|
|
|
|
p.setPen(st::searchedBarColor->p);
|
|
|
|
p.drawText(QRect(0, 0, width(), st::searchedBarHeight), text, style::al_center);
|
|
|
|
p.translate(0, st::searchedBarHeight);
|
|
|
|
|
2015-03-24 10:00:27 +00:00
|
|
|
int32 skip = searchedOffset();
|
2014-07-13 09:50:38 +00:00
|
|
|
int32 from = (r.top() - skip) / int32(st::dlgHeight);
|
2014-10-22 18:39:03 +00:00
|
|
|
if (from < 0) {
|
|
|
|
from = 0;
|
|
|
|
} else if (from > searchResults.size()) {
|
|
|
|
from = searchResults.size();
|
|
|
|
}
|
|
|
|
p.translate(0, from * st::dlgHeight);
|
2014-07-04 11:12:54 +00:00
|
|
|
if (from < searchResults.size()) {
|
2014-07-13 09:50:38 +00:00
|
|
|
int32 to = ((r.bottom() - skip) / int32(st::dlgHeight)) + 1, w = width();
|
2014-07-04 11:12:54 +00:00
|
|
|
if (to > searchResults.size()) to = searchResults.size();
|
|
|
|
for (; from < to; ++from) {
|
|
|
|
bool active = (searchResults[from]->_item->id == App::main()->activeMsgId());
|
|
|
|
bool selected = (from == searchedSel);
|
|
|
|
searchResults[from]->paint(p, w, active, selected);
|
2014-05-30 08:53:19 +00:00
|
|
|
p.translate(0, st::dlgHeight);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-10-22 18:39:03 +00:00
|
|
|
void DialogsListWidget::peopleResultPaint(UserData *user, QPainter &p, int32 w, bool act, bool sel) const {
|
|
|
|
QRect fullRect(0, 0, w, st::dlgHeight);
|
|
|
|
p.fillRect(fullRect, (act ? st::dlgActiveBG : (sel ? st::dlgHoverBG : st::dlgBG))->b);
|
|
|
|
|
|
|
|
History *history = App::history(user->id);
|
|
|
|
|
|
|
|
p.drawPixmap(st::dlgPaddingHor, st::dlgPaddingVer, history->peer->photo->pix(st::dlgPhotoSize));
|
|
|
|
|
|
|
|
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
|
|
|
|
if (history->peer->chat) {
|
|
|
|
p.drawPixmap(QPoint(rectForName.left() + st::dlgChatImgLeft, rectForName.top() + st::dlgChatImgTop), App::sprite(), (act ? st::dlgActiveChatImg : st::dlgChatImg));
|
|
|
|
rectForName.setLeft(rectForName.left() + st::dlgChatImgSkip);
|
|
|
|
}
|
2014-10-23 16:05:33 +00:00
|
|
|
|
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);
|
2014-10-23 16:05:33 +00:00
|
|
|
if (!act && user->username.toLower().startsWith(peopleQuery)) {
|
|
|
|
QString first = '@' + user->username.mid(0, peopleQuery.size()), second = user->username.mid(peopleQuery.size());
|
|
|
|
int32 w = st::dlgHistFont->m.width(first);
|
|
|
|
if (w >= tr.width()) {
|
|
|
|
p.setPen(st::dlgSystemColor->p);
|
|
|
|
p.drawText(tr.left(), tr.top() + st::dlgHistFont->ascent, st::dlgHistFont->m.elidedText(first, Qt::ElideRight, tr.width()));
|
|
|
|
} else {
|
|
|
|
p.setPen(st::dlgSystemColor->p);
|
|
|
|
p.drawText(tr.left(), tr.top() + st::dlgHistFont->ascent, first);
|
|
|
|
p.setPen(st::dlgTextColor->p);
|
2014-10-25 09:25:18 +00:00
|
|
|
p.drawText(tr.left() + w, tr.top() + st::dlgHistFont->ascent, st::dlgHistFont->m.elidedText(second, Qt::ElideRight, tr.width() - w));
|
2014-10-23 16:05:33 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
p.setPen((act ? st::dlgActiveColor : st::dlgSystemColor)->p);
|
|
|
|
p.drawText(tr.left(), tr.top() + st::dlgHistFont->ascent, st::dlgHistFont->m.elidedText('@' + user->username, Qt::ElideRight, tr.width()));
|
|
|
|
}
|
2014-10-22 18:39:03 +00:00
|
|
|
|
|
|
|
p.setPen((act ? st::dlgActiveColor : st::dlgNameColor)->p);
|
|
|
|
history->nameText.drawElided(p, rectForName.left(), rectForName.top(), rectForName.width());
|
|
|
|
}
|
|
|
|
|
2014-05-30 08:53:19 +00:00
|
|
|
void DialogsListWidget::activate() {
|
|
|
|
}
|
|
|
|
|
|
|
|
void DialogsListWidget::mouseMoveEvent(QMouseEvent *e) {
|
|
|
|
lastMousePos = mapToGlobal(e->pos());
|
|
|
|
selByMouse = true;
|
|
|
|
onUpdateSelected(true);
|
2014-08-20 05:32:50 +00:00
|
|
|
update();
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void DialogsListWidget::onUpdateSelected(bool force) {
|
|
|
|
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 {
|
|
|
|
newSel = contactsNoDialogs.list.rowAtY(mouseY - otherStart, st::dlgHeight);
|
|
|
|
contactSel = true;
|
|
|
|
}
|
|
|
|
if (newSel != sel) {
|
|
|
|
sel = newSel;
|
|
|
|
setCursor(sel ? style::cur_pointer : style::cur_default);
|
|
|
|
parentWidget()->update();
|
|
|
|
}
|
2014-07-13 09:50:38 +00:00
|
|
|
} else if (_state == FilteredState || _state == SearchedState) {
|
2015-03-24 10:00:27 +00:00
|
|
|
if (!hashtagResults.isEmpty()) {
|
|
|
|
int32 newHashtagSel = mouseY / int32(st::mentionHeight);
|
|
|
|
if (newHashtagSel < 0 || newHashtagSel >= hashtagResults.size()) {
|
|
|
|
newHashtagSel = -1;
|
|
|
|
}
|
|
|
|
if (newHashtagSel != hashtagSel) {
|
|
|
|
hashtagSel = newHashtagSel;
|
|
|
|
setCursor((hashtagSel >= 0) ? style::cur_pointer : style::cur_default);
|
|
|
|
parentWidget()->update();
|
|
|
|
}
|
2015-03-24 15:18:20 +00:00
|
|
|
if (hashtagSel >= 0) {
|
|
|
|
_overDelete = (mouse.x() >= w - st::mentionHeight);
|
|
|
|
}
|
2015-03-24 10:00:27 +00:00
|
|
|
mouseY -= filteredOffset();
|
|
|
|
}
|
2014-07-04 11:12:54 +00:00
|
|
|
if (!filterResults.isEmpty()) {
|
2015-03-24 10:00:27 +00:00
|
|
|
int32 newFilteredSel = (mouseY >= 0) ? (mouseY / int32(st::dlgHeight)) : -1;
|
2014-07-04 11:12:54 +00:00
|
|
|
if (newFilteredSel < 0 || newFilteredSel >= filterResults.size()) {
|
2014-05-30 08:53:19 +00:00
|
|
|
newFilteredSel = -1;
|
|
|
|
}
|
|
|
|
if (newFilteredSel != filteredSel) {
|
|
|
|
filteredSel = newFilteredSel;
|
|
|
|
setCursor((filteredSel >= 0) ? style::cur_pointer : style::cur_default);
|
|
|
|
parentWidget()->update();
|
|
|
|
}
|
|
|
|
}
|
2015-03-24 10:00:27 +00:00
|
|
|
mouseY -= peopleOffset() - filteredOffset();
|
2014-10-22 18:39:03 +00:00
|
|
|
if (!peopleResults.isEmpty()) {
|
|
|
|
int32 newPeopleSel = (mouseY >= 0) ? (mouseY / int32(st::dlgHeight)) : -1;
|
|
|
|
if (newPeopleSel < 0 || newPeopleSel >= peopleResults.size()) {
|
|
|
|
newPeopleSel = -1;
|
|
|
|
}
|
|
|
|
if (newPeopleSel != peopleSel) {
|
|
|
|
peopleSel = newPeopleSel;
|
|
|
|
setCursor((peopleSel >= 0) ? style::cur_pointer : style::cur_default);
|
|
|
|
parentWidget()->update();
|
|
|
|
}
|
|
|
|
}
|
2015-03-24 10:00:27 +00:00
|
|
|
mouseY -= searchedOffset() - peopleOffset();
|
2014-07-13 09:50:38 +00:00
|
|
|
if (_state == SearchedState && !searchResults.isEmpty()) {
|
2014-10-22 18:39:03 +00:00
|
|
|
int32 newSearchedSel = (mouseY >= 0) ? (mouseY / int32(st::dlgHeight)) : -1;
|
2014-07-04 11:12:54 +00:00
|
|
|
if (newSearchedSel < 0 || newSearchedSel >= searchResults.size()) {
|
|
|
|
newSearchedSel = -1;
|
|
|
|
}
|
|
|
|
if (newSearchedSel != searchedSel) {
|
|
|
|
searchedSel = newSearchedSel;
|
|
|
|
setCursor((searchedSel >= 0) ? style::cur_pointer : style::cur_default);
|
|
|
|
parentWidget()->update();
|
|
|
|
}
|
|
|
|
}
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void DialogsListWidget::mousePressEvent(QMouseEvent *e) {
|
|
|
|
lastMousePos = mapToGlobal(e->pos());
|
|
|
|
selByMouse = true;
|
|
|
|
onUpdateSelected(true);
|
|
|
|
if (e->button() == Qt::LeftButton) {
|
|
|
|
choosePeer();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-11-25 12:15:29 +00:00
|
|
|
void DialogsListWidget::resizeEvent(QResizeEvent *e) {
|
|
|
|
_addContactLnk.move((width() - _addContactLnk.width()) / 2, (st::noContactsHeight + st::noContactsFont->height) / 2);
|
|
|
|
}
|
|
|
|
|
2014-05-30 08:53:19 +00:00
|
|
|
void DialogsListWidget::onDialogRowReplaced(DialogRow *oldRow, DialogRow *newRow) {
|
2014-07-13 09:50:38 +00:00
|
|
|
if (_state == FilteredState || _state == SearchedState) {
|
2014-07-04 11:12:54 +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 {
|
2014-07-04 11:12:54 +00:00
|
|
|
i = filterResults.erase(i);
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
++i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (sel == oldRow) {
|
|
|
|
sel = newRow;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void DialogsListWidget::createDialogAtTop(History *history, int32 unreadCount) {
|
|
|
|
history->updateNameText();
|
|
|
|
|
|
|
|
History::DialogLinks links = dialogs.addToEnd(history);
|
|
|
|
int32 movedFrom = links[0]->pos * st::dlgHeight;
|
|
|
|
dialogs.bringToTop(links);
|
|
|
|
history->dialogs = links;
|
|
|
|
|
|
|
|
contactsNoDialogs.del(history->peer, links[0]);
|
|
|
|
|
|
|
|
emit dialogToTopFrom(movedFrom);
|
|
|
|
emit App::main()->dialogsUpdated();
|
|
|
|
|
|
|
|
refresh();
|
|
|
|
}
|
|
|
|
|
|
|
|
void DialogsListWidget::removePeer(PeerData *peer) {
|
|
|
|
if (sel && sel->history->peer == peer) {
|
|
|
|
sel = 0;
|
|
|
|
}
|
|
|
|
History *history = App::history(peer->id);
|
|
|
|
dialogs.del(peer);
|
|
|
|
history->dialogs = History::DialogLinks();
|
|
|
|
if (contacts.list.rowByPeer.constFind(peer->id) != contacts.list.rowByPeer.cend()) {
|
|
|
|
if (contactsNoDialogs.list.rowByPeer.constFind(peer->id) == contactsNoDialogs.list.rowByPeer.cend()) {
|
|
|
|
contactsNoDialogs.addByName(App::history(peer->id));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// contactsNoDialogs.del(peer);
|
|
|
|
// contacts.del(peer);
|
|
|
|
// App::deleteHistory(peer->id);
|
|
|
|
|
|
|
|
emit App::main()->dialogsUpdated();
|
|
|
|
|
|
|
|
refresh();
|
|
|
|
}
|
|
|
|
|
|
|
|
void DialogsListWidget::removeContact(UserData *user) {
|
|
|
|
if (sel && sel->history->peer == user) {
|
|
|
|
sel = 0;
|
|
|
|
}
|
|
|
|
contactsNoDialogs.del(user);
|
|
|
|
contacts.del(user);
|
|
|
|
|
|
|
|
emit App::main()->dialogsUpdated();
|
|
|
|
|
|
|
|
refresh();
|
|
|
|
}
|
|
|
|
|
|
|
|
void DialogsListWidget::dlgUpdated(DialogRow *row) {
|
2014-07-04 11:12:54 +00:00
|
|
|
if (_state == DefaultState) {
|
2014-05-30 08:53:19 +00:00
|
|
|
update(0, row->pos * st::dlgHeight, width(), st::dlgHeight);
|
2014-07-13 09:50:38 +00:00
|
|
|
} else if (_state == FilteredState || _state == SearchedState) {
|
2014-05-30 08:53:19 +00:00
|
|
|
int32 cnt = 0;
|
2014-07-04 11:12:54 +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 == row->history) {
|
|
|
|
update(0, cnt * st::dlgHeight, width(), st::dlgHeight);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
++cnt;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void DialogsListWidget::dlgUpdated(History *history) {
|
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()) {
|
|
|
|
update(0, i.value()->pos * st::dlgHeight, width(), st::dlgHeight);
|
|
|
|
} else {
|
|
|
|
i = contactsNoDialogs.list.rowByPeer.find(history->peer->id);
|
|
|
|
if (i != contactsNoDialogs.list.rowByPeer.cend()) {
|
|
|
|
update(0, (dialogs.list.count + i.value()->pos) * st::dlgHeight, width(), st::dlgHeight);
|
|
|
|
}
|
|
|
|
}
|
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();
|
2014-07-04 11:12:54 +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) {
|
|
|
|
update(0, cnt * st::dlgHeight, width(), st::dlgHeight);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
++cnt;
|
|
|
|
}
|
2014-10-22 18:39:03 +00:00
|
|
|
if (!peopleResults.isEmpty()) {
|
2015-03-24 10:00:27 +00:00
|
|
|
int32 cnt = 0, add = peopleOffset();
|
2014-10-22 18:39:03 +00:00
|
|
|
for (PeopleResults::const_iterator i = peopleResults.cbegin(), e = peopleResults.cend(); i != e; ++i) {
|
|
|
|
if ((*i) == history->peer) {
|
|
|
|
update(0, add + cnt * st::dlgHeight, width(), st::dlgHeight);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
++cnt;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!searchResults.isEmpty()) {
|
2015-03-24 10:00:27 +00:00
|
|
|
int32 cnt = 0, add = searchedOffset();
|
2014-07-13 09:50:38 +00:00
|
|
|
for (SearchResults::const_iterator i = searchResults.cbegin(), e = searchResults.cend(); i != e; ++i) {
|
|
|
|
if ((*i)->_item->history() == history) {
|
|
|
|
update(0, add + cnt * st::dlgHeight, width(), st::dlgHeight);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
++cnt;
|
2014-07-04 11:12:54 +00:00
|
|
|
}
|
|
|
|
}
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void DialogsListWidget::enterEvent(QEvent *e) {
|
|
|
|
setMouseTracking(true);
|
|
|
|
lastMousePos = QCursor::pos();
|
|
|
|
onUpdateSelected(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
void DialogsListWidget::leaveEvent(QEvent *e) {
|
|
|
|
setMouseTracking(false);
|
2015-04-04 20:01:34 +00:00
|
|
|
selByMouse = false;
|
2015-03-24 10:00:27 +00:00
|
|
|
if (sel || filteredSel >= 0 || hashtagSel >= 0 || searchedSel >= 0 || peopleSel >= 0) {
|
2014-05-30 08:53:19 +00:00
|
|
|
sel = 0;
|
2015-03-24 10:00:27 +00:00
|
|
|
filteredSel = searchedSel = peopleSel = hashtagSel = -1;
|
2014-05-30 08:53:19 +00:00
|
|
|
parentWidget()->update();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void DialogsListWidget::onParentGeometryChanged() {
|
|
|
|
lastMousePos = QCursor::pos();
|
|
|
|
if (rect().contains(mapFromGlobal(lastMousePos))) {
|
|
|
|
setMouseTracking(true);
|
|
|
|
onUpdateSelected(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void DialogsListWidget::onDialogToTop(const History::DialogLinks &links) {
|
|
|
|
int32 movedFrom = links[0]->pos * st::dlgHeight;
|
|
|
|
dialogs.bringToTop(links);
|
|
|
|
emit dialogToTopFrom(movedFrom);
|
|
|
|
emit App::main()->dialogsUpdated();
|
|
|
|
parentWidget()->update();
|
|
|
|
}
|
|
|
|
|
|
|
|
void DialogsListWidget::onPeerNameChanged(PeerData *peer, const PeerData::Names &oldNames, const PeerData::NameFirstChars &oldChars) {
|
|
|
|
dialogs.peerNameChanged(peer, oldNames, oldChars);
|
|
|
|
contactsNoDialogs.peerNameChanged(peer, oldNames, oldChars);
|
|
|
|
contacts.peerNameChanged(peer, oldNames, oldChars);
|
|
|
|
parentWidget()->update();
|
|
|
|
}
|
|
|
|
|
|
|
|
void DialogsListWidget::onPeerPhotoChanged(PeerData *peer) {
|
|
|
|
parentWidget()->update();
|
|
|
|
}
|
|
|
|
|
2014-07-04 11:12:54 +00:00
|
|
|
void DialogsListWidget::onFilterUpdate(QString newFilter, bool force) {
|
2014-10-07 17:57:57 +00:00
|
|
|
newFilter = textSearchKey(newFilter);
|
2014-07-04 11:12:54 +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(' ');
|
|
|
|
}
|
2014-07-04 11:12:54 +00:00
|
|
|
if (newFilter != filter || force) {
|
2014-05-30 08:53:19 +00:00
|
|
|
filter = newFilter;
|
2014-07-04 11:12:54 +00:00
|
|
|
if (filter.isEmpty()) {
|
|
|
|
_state = DefaultState;
|
2015-03-24 10:00:27 +00:00
|
|
|
hashtagResults.clear();
|
2014-07-04 11:12:54 +00:00
|
|
|
filterResults.clear();
|
2014-10-22 18:39:03 +00:00
|
|
|
peopleResults.clear();
|
2014-07-13 09:50:38 +00:00
|
|
|
searchResults.clear();
|
2014-08-22 07:41:39 +00:00
|
|
|
_lastSearchId = 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;
|
|
|
|
filterResults.clear();
|
2014-05-30 08:53:19 +00:00
|
|
|
if (!f.isEmpty()) {
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-07-04 11:12:54 +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) {
|
2014-07-04 11:12:54 +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) {
|
2014-07-04 11:12:54 +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-03-24 10:00:27 +00:00
|
|
|
void DialogsListWidget::onHashtagFilterUpdate(QString newFilter) {
|
|
|
|
if (newFilter.isEmpty() || newFilter.at(0) != '#') {
|
|
|
|
if (!hashtagResults.isEmpty()) {
|
|
|
|
hashtagResults.clear();
|
|
|
|
refresh(true);
|
|
|
|
setMouseSel(false, true);
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (cRecentSearchHashtags().isEmpty() && cRecentWriteHashtags().isEmpty()) {
|
|
|
|
Local::readRecentHashtags();
|
|
|
|
}
|
|
|
|
const RecentHashtagPack &recent(cRecentSearchHashtags());
|
|
|
|
hashtagResults.clear();
|
|
|
|
if (!recent.isEmpty()) {
|
|
|
|
hashtagResults.reserve(qMin(recent.size(), 5));
|
|
|
|
for (RecentHashtagPack::const_iterator i = recent.cbegin(), e = recent.cend(); i != e; ++i) {
|
|
|
|
if (i->first.startsWith(newFilter.midRef(1), Qt::CaseInsensitive) && i->first.size() + 1 != newFilter.size()) {
|
|
|
|
hashtagResults.push_back(i->first);
|
|
|
|
if (hashtagResults.size() == 5) break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
refresh(true);
|
|
|
|
setMouseSel(false, true);
|
|
|
|
}
|
|
|
|
|
2014-07-04 11:12:54 +00:00
|
|
|
DialogsListWidget::~DialogsListWidget() {
|
|
|
|
clearSearchResults();
|
|
|
|
}
|
|
|
|
|
2014-10-22 18:39:03 +00:00
|
|
|
void DialogsListWidget::clearSearchResults(bool clearPeople) {
|
|
|
|
if (clearPeople) peopleResults.clear();
|
2014-07-04 11:12:54 +00:00
|
|
|
if (!searchResults.isEmpty()) {
|
|
|
|
for (SearchResults::const_iterator i = searchResults.cbegin(), e = searchResults.cend(); i != e; ++i) {
|
|
|
|
delete *i;
|
|
|
|
}
|
|
|
|
searchResults.clear();
|
|
|
|
}
|
2014-08-22 07:41:39 +00:00
|
|
|
_lastSearchId = 0;
|
2014-07-04 11:12:54 +00:00
|
|
|
}
|
|
|
|
|
2014-10-10 12:46:20 +00:00
|
|
|
void DialogsListWidget::itemReplaced(HistoryItem *oldItem, HistoryItem *newItem) {
|
2014-07-04 11:12:54 +00:00
|
|
|
for (int i = 0; i < searchResults.size(); ++i) {
|
|
|
|
if (searchResults[i]->_item == oldItem) {
|
|
|
|
searchResults[i]->_item = newItem;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-10-10 12:46:20 +00:00
|
|
|
void DialogsListWidget::itemRemoved(HistoryItem *item) {
|
2014-07-04 11:12:54 +00:00
|
|
|
int wasCount = searchResults.size();
|
2014-08-21 12:18:56 +00:00
|
|
|
for (int i = 0; i < searchResults.size();) {
|
2014-07-04 11:12:54 +00:00
|
|
|
if (searchResults[i]->_item == item) {
|
|
|
|
searchResults.remove(i);
|
2014-10-07 17:57:57 +00:00
|
|
|
if (searchedCount > 0) --searchedCount;
|
2014-07-04 11:12:54 +00:00
|
|
|
} else {
|
|
|
|
++i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (wasCount != searchResults.size()) {
|
|
|
|
refresh();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-30 08:53:19 +00:00
|
|
|
void DialogsListWidget::dialogsReceived(const QVector<MTPDialog> &added) {
|
|
|
|
for (QVector<MTPDialog>::const_iterator i = added.cbegin(), e = added.cend(); i != e; ++i) {
|
|
|
|
if (i->type() == mtpc_dialog) {
|
|
|
|
addDialog(i->c_dialog());
|
|
|
|
}
|
|
|
|
}
|
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();
|
|
|
|
}
|
|
|
|
|
2014-07-13 09:50:38 +00:00
|
|
|
void DialogsListWidget::searchReceived(const QVector<MTPMessage> &messages, bool fromStart, int32 fullCount) {
|
2014-07-04 11:12:54 +00:00
|
|
|
if (fromStart) {
|
2014-10-22 18:39:03 +00:00
|
|
|
clearSearchResults(false);
|
2014-07-04 11:12:54 +00:00
|
|
|
}
|
|
|
|
for (QVector<MTPMessage>::const_iterator i = messages.cbegin(), e = messages.cend(); i != e; ++i) {
|
|
|
|
HistoryItem *item = App::histories().addToBack(*i, -1);
|
|
|
|
searchResults.push_back(new FakeDialogRow(item));
|
2014-08-22 07:41:39 +00:00
|
|
|
_lastSearchId = item->id;
|
2014-07-04 11:12:54 +00:00
|
|
|
}
|
2014-07-13 09:50:38 +00:00
|
|
|
searchedCount = fullCount;
|
|
|
|
if (_state == FilteredState) {
|
|
|
|
_state = SearchedState;
|
|
|
|
}
|
2014-07-04 11:12:54 +00:00
|
|
|
refresh();
|
|
|
|
}
|
|
|
|
|
2014-10-23 16:05:33 +00:00
|
|
|
void DialogsListWidget::peopleReceived(const QString &query, const QVector<MTPContactFound> &people) {
|
|
|
|
peopleQuery = query.toLower().trimmed();
|
2014-10-22 18:39:03 +00:00
|
|
|
peopleResults.clear();
|
|
|
|
peopleResults.reserve(people.size());
|
|
|
|
for (QVector<MTPContactFound>::const_iterator i = people.cbegin(), e = people.cend(); i != e; ++i) {
|
|
|
|
int32 uid = i->c_contactFound().vuser_id.v;
|
|
|
|
History *h = App::historyLoaded(uid);
|
|
|
|
if (h && !h->isEmpty()) continue; // skip dialogs
|
|
|
|
|
|
|
|
peopleResults.push_back(App::user(uid));
|
|
|
|
}
|
|
|
|
refresh();
|
|
|
|
}
|
|
|
|
|
2014-05-30 08:53:19 +00:00
|
|
|
void DialogsListWidget::contactsReceived(const QVector<MTPContact> &contacts) {
|
2014-11-25 12:15:29 +00:00
|
|
|
cSetContactsReceived(true);
|
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
|
|
|
}
|
|
|
|
if (!sel && contactsNoDialogs.list.count) {
|
|
|
|
sel = contactsNoDialogs.list.begin;
|
|
|
|
contactSel = true;
|
|
|
|
}
|
|
|
|
refresh();
|
|
|
|
}
|
|
|
|
|
|
|
|
int32 DialogsListWidget::addNewContact(int32 uid, bool select) {
|
|
|
|
PeerId peer = App::peerFromUser(uid);
|
|
|
|
if (!App::peerLoaded(peer)) return -1;
|
|
|
|
|
|
|
|
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);
|
|
|
|
if (!added) return -1;
|
|
|
|
if (select) {
|
|
|
|
sel = added;
|
|
|
|
contactSel = true;
|
|
|
|
}
|
2015-04-04 20:01:34 +00:00
|
|
|
if (contactsNoDialogs.list.count == 1 && !dialogs.list.count) refresh();
|
2014-05-30 08:53:19 +00:00
|
|
|
return added ? ((dialogs.list.count + added->pos) * st::dlgHeight) : -1;
|
|
|
|
}
|
|
|
|
if (select) {
|
|
|
|
sel = i.value();
|
|
|
|
contactSel = false;
|
|
|
|
}
|
|
|
|
return i.value()->pos * st::dlgHeight;
|
|
|
|
}
|
|
|
|
|
|
|
|
void DialogsListWidget::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) {
|
2014-07-13 09:50:38 +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-03-24 10:00:27 +00:00
|
|
|
h = searchedOffset() + (searchResults.count() * st::dlgHeight) + (searchResults.isEmpty() ? 0 : st::searchedBarHeight);
|
2014-11-25 12:15:29 +00:00
|
|
|
} else if (_state == SearchedState) {
|
2015-03-24 10:00:27 +00:00
|
|
|
h = searchedOffset() + (searchResults.count() * st::dlgHeight) + st::searchedBarHeight;
|
2014-11-25 12:15:29 +00:00
|
|
|
}
|
2014-07-04 11:12:54 +00:00
|
|
|
}
|
2014-07-13 09:50:38 +00:00
|
|
|
resize(width(), h);
|
2014-05-30 08:53:19 +00:00
|
|
|
if (toTop) {
|
|
|
|
emit mustScrollTo(0, 0);
|
|
|
|
loadPeerPhotos(0);
|
|
|
|
}
|
|
|
|
parentWidget()->update();
|
|
|
|
}
|
|
|
|
|
|
|
|
void DialogsListWidget::setMouseSel(bool msel, bool toTop) {
|
|
|
|
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-03-24 10:00:27 +00:00
|
|
|
filteredSel = peopleSel = searchedSel = hashtagSel = -1;
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-07-04 11:12:54 +00:00
|
|
|
void DialogsListWidget::setState(State newState) {
|
|
|
|
_state = newState;
|
2014-07-13 09:50:38 +00:00
|
|
|
if (_state == DefaultState) {
|
2014-07-04 11:12:54 +00:00
|
|
|
clearSearchResults();
|
2015-03-24 10:00:27 +00:00
|
|
|
searchedSel = peopleSel = filteredSel = hashtagSel = -1;
|
2014-07-04 11:12:54 +00:00
|
|
|
} else if (_state == DefaultState || _state == SearchedState) {
|
2015-03-24 10:00:27 +00:00
|
|
|
hashtagResults.clear();
|
|
|
|
hashtagSel = -1;
|
2014-07-04 11:12:54 +00:00
|
|
|
filterResults.clear();
|
|
|
|
filteredSel = -1;
|
|
|
|
}
|
|
|
|
onFilterUpdate(filter, true);
|
|
|
|
refresh(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
DialogsListWidget::State DialogsListWidget::state() const {
|
|
|
|
return _state;
|
|
|
|
}
|
|
|
|
|
2015-02-09 23:19:48 +00:00
|
|
|
bool DialogsListWidget::hasFilteredResults() const {
|
2015-03-24 10:00:27 +00:00
|
|
|
return !filterResults.isEmpty() && hashtagResults.isEmpty();
|
2015-02-09 23:19:48 +00:00
|
|
|
}
|
|
|
|
|
2014-05-30 08:53:19 +00:00
|
|
|
void DialogsListWidget::clearFilter() {
|
2014-07-13 09:50:38 +00:00
|
|
|
if (_state == FilteredState || _state == SearchedState) {
|
2014-07-04 11:12:54 +00:00
|
|
|
_state = DefaultState;
|
2015-03-24 10:00:27 +00:00
|
|
|
hashtagResults.clear();
|
2014-07-13 09:50:38 +00:00
|
|
|
filterResults.clear();
|
2014-10-22 18:39:03 +00:00
|
|
|
peopleResults.clear();
|
2014-07-13 09:50:38 +00:00
|
|
|
searchResults.clear();
|
2014-08-22 07:41:39 +00:00
|
|
|
_lastSearchId = 0;
|
2014-05-30 08:53:19 +00:00
|
|
|
filter = QString();
|
|
|
|
refresh(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void DialogsListWidget::addDialog(const MTPDdialog &dialog) {
|
2015-03-13 13:01:25 +00:00
|
|
|
History *history = App::history(App::peerFromMTP(dialog.vpeer), dialog.vunread_count.v, dialog.vread_inbox_max_id.v);
|
2014-05-30 08:53:19 +00:00
|
|
|
History::DialogLinks links = dialogs.addToEnd(history);
|
|
|
|
history->dialogs = links;
|
|
|
|
contactsNoDialogs.del(history->peer);
|
|
|
|
|
|
|
|
App::main()->applyNotifySetting(MTP_notifyPeer(dialog.vpeer), dialog.vnotify_settings, history);
|
|
|
|
}
|
|
|
|
|
|
|
|
void DialogsListWidget::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;
|
|
|
|
} else if (contactsNoDialogs.list.count && direction > 0) {
|
|
|
|
sel = contactsNoDialogs.list.begin;
|
|
|
|
} else {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
} else if (direction > 0) {
|
|
|
|
if (sel->next->next) {
|
|
|
|
sel = sel->next;
|
|
|
|
} else if (sel->next == dialogs.list.end && contactsNoDialogs.list.count) {
|
|
|
|
sel = contactsNoDialogs.list.begin;
|
|
|
|
contactSel = true;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (sel->prev) {
|
|
|
|
sel = sel->prev;
|
|
|
|
} else if (sel == contactsNoDialogs.list.begin && dialogs.list.count) {
|
|
|
|
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-03-24 10:00:27 +00:00
|
|
|
if (hashtagResults.isEmpty() && filterResults.isEmpty() && peopleResults.isEmpty() && searchResults.isEmpty()) return;
|
|
|
|
if ((hashtagSel < 0 || hashtagSel >= hashtagResults.size()) &&
|
|
|
|
(filteredSel < 0 || filteredSel >= filterResults.size()) &&
|
2014-10-22 18:39:03 +00:00
|
|
|
(peopleSel < 0 || peopleSel >= peopleResults.size()) &&
|
|
|
|
(searchedSel < 0 || searchedSel >= searchResults.size())) {
|
2015-03-24 10:00:27 +00:00
|
|
|
if (hashtagResults.isEmpty() && filterResults.isEmpty() && peopleResults.isEmpty()) {
|
2014-10-22 18:39:03 +00:00
|
|
|
searchedSel = 0;
|
2015-03-24 10:00:27 +00:00
|
|
|
} else if (hashtagResults.isEmpty() && filterResults.isEmpty()) {
|
2014-10-22 18:39:03 +00:00
|
|
|
peopleSel = 0;
|
2015-03-24 10:00:27 +00:00
|
|
|
} else if (hashtagResults.isEmpty()) {
|
2014-10-22 18:39:03 +00:00
|
|
|
filteredSel = 0;
|
2015-03-24 10:00:27 +00:00
|
|
|
} else {
|
|
|
|
hashtagSel = 0;
|
2014-07-13 09:50:38 +00:00
|
|
|
}
|
|
|
|
} else {
|
2015-03-24 10:00:27 +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-03-24 10:00:27 +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-03-24 10:00:27 +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);
|
2014-10-22 18:39:03 +00:00
|
|
|
} else if (peopleSel >= 0 && peopleSel < peopleResults.size()) {
|
2015-03-24 10:00:27 +00:00
|
|
|
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-03-24 10:00:27 +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
|
|
|
}
|
2014-10-22 18:39:03 +00:00
|
|
|
parentWidget()->update();
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
|
2014-08-22 07:41:39 +00:00
|
|
|
void DialogsListWidget::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;
|
|
|
|
} else {
|
|
|
|
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) {
|
|
|
|
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) {
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void DialogsListWidget::selectSkipPage(int32 pixels, int32 direction) {
|
|
|
|
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;
|
|
|
|
} else if (direction > 0 && contactsNoDialogs.list.count) {
|
|
|
|
sel = contactsNoDialogs.list.begin;
|
|
|
|
} else {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (direction > 0) {
|
|
|
|
while (toSkip-- && sel->next->next) {
|
|
|
|
sel = sel->next;
|
|
|
|
}
|
|
|
|
if (toSkip >= 0 && sel->next == dialogs.list.end && contactsNoDialogs.list.count) {
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
parentWidget()->update();
|
|
|
|
}
|
|
|
|
|
|
|
|
void DialogsListWidget::loadPeerPhotos(int32 yFrom) {
|
|
|
|
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;
|
2014-07-04 11:12:54 +00:00
|
|
|
if (from < filterResults.size()) {
|
2014-05-30 08:53:19 +00:00
|
|
|
int32 to = (yTo / int32(st::dlgHeight)) + 1, w = width();
|
2014-07-04 11:12:54 +00:00
|
|
|
if (to > filterResults.size()) to = filterResults.size();
|
2014-05-30 08:53:19 +00:00
|
|
|
|
|
|
|
for (; from < to; ++from) {
|
2014-07-04 11:12:54 +00:00
|
|
|
filterResults[from]->history->peer->photo->load();
|
|
|
|
}
|
|
|
|
}
|
2014-07-13 09:50:38 +00:00
|
|
|
|
2015-03-24 10:00:27 +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;
|
2014-10-22 18:39:03 +00:00
|
|
|
if (from < peopleResults.size()) {
|
2015-03-24 10:00:27 +00:00
|
|
|
int32 to = (yTo > filteredOffset() + st::searchedBarHeight ? ((yTo - filteredOffset() - st::searchedBarHeight) / int32(st::dlgHeight)) : 0) - filterResults.size() + 1, w = width();
|
2014-10-22 18:39:03 +00:00
|
|
|
if (to > peopleResults.size()) to = peopleResults.size();
|
|
|
|
|
|
|
|
for (; from < to; ++from) {
|
|
|
|
peopleResults[from]->photo->load();
|
|
|
|
}
|
|
|
|
}
|
2015-03-24 10:00:27 +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;
|
|
|
|
if (from < searchResults.size()) {
|
2015-03-24 10:00:27 +00:00
|
|
|
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();
|
2014-07-04 11:12:54 +00:00
|
|
|
if (to > searchResults.size()) to = searchResults.size();
|
|
|
|
|
|
|
|
for (; from < to; ++from) {
|
|
|
|
searchResults[from]->_item->history()->peer->photo->load();
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-07-04 11:12:54 +00:00
|
|
|
bool DialogsListWidget::choosePeer() {
|
|
|
|
History *history = 0;
|
|
|
|
MsgId msgId = 0;
|
|
|
|
if (_state == DefaultState) {
|
|
|
|
if (sel) history = sel->history;
|
2014-07-13 09:50:38 +00:00
|
|
|
} else if (_state == FilteredState || _state == SearchedState) {
|
2015-03-24 10:00:27 +00:00
|
|
|
if (hashtagSel >= 0 && hashtagSel < hashtagResults.size()) {
|
2015-03-24 15:18:20 +00:00
|
|
|
QString hashtag = hashtagResults.at(hashtagSel);
|
|
|
|
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;
|
|
|
|
}
|
2014-07-13 09:50:38 +00:00
|
|
|
if (filteredSel >= 0 && filteredSel < filterResults.size()) {
|
|
|
|
history = filterResults[filteredSel]->history;
|
2014-10-22 18:39:03 +00:00
|
|
|
} else if (peopleSel >= 0 && peopleSel < peopleResults.size()) {
|
|
|
|
history = App::history(peopleResults[peopleSel]->id);
|
2014-07-13 09:50:38 +00:00
|
|
|
} else if (searchedSel >= 0 && searchedSel < searchResults.size()) {
|
2014-07-04 11:12:54 +00:00
|
|
|
history = searchResults[searchedSel]->_item->history();
|
|
|
|
msgId = searchResults[searchedSel]->_item->id;
|
|
|
|
}
|
|
|
|
}
|
2014-05-30 08:53:19 +00:00
|
|
|
if (history) {
|
2015-03-24 10:00:27 +00:00
|
|
|
if (msgId) {
|
|
|
|
saveRecentHashtags(filter);
|
|
|
|
}
|
2015-04-04 20:01:34 +00:00
|
|
|
bool chosen = (!App::main()->selectingPeer(true) && (_state == FilteredState || _state == SearchedState) && filteredSel >= 0 && filteredSel < filterResults.size());
|
2014-10-22 18:39:03 +00:00
|
|
|
App::main()->showPeer(history->peer->id, msgId);
|
|
|
|
if (chosen) {
|
|
|
|
emit searchResultChosen();
|
|
|
|
}
|
2014-05-30 08:53:19 +00:00
|
|
|
sel = 0;
|
2015-03-24 10:00:27 +00:00
|
|
|
filteredSel = peopleSel = searchedSel = hashtagSel = -1;
|
2014-05-30 08:53:19 +00:00
|
|
|
parentWidget()->update();
|
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-03-24 10:00:27 +00:00
|
|
|
void DialogsListWidget::saveRecentHashtags(const QString &text) {
|
|
|
|
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()) {
|
|
|
|
Local::readRecentStickers();
|
|
|
|
recent = cRecentSearchHashtags();
|
|
|
|
}
|
|
|
|
found = true;
|
|
|
|
incrementRecentHashtag(recent, text.mid(i + 1, next - i - 1));
|
|
|
|
}
|
|
|
|
if (found) {
|
|
|
|
cSetRecentSearchHashtags(recent);
|
|
|
|
Local::writeRecentHashtags();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-30 08:53:19 +00:00
|
|
|
void DialogsListWidget::destroyData() {
|
|
|
|
sel = 0;
|
|
|
|
contactSel = false;
|
2015-03-24 10:00:27 +00:00
|
|
|
hashtagSel = -1;
|
|
|
|
hashtagResults.clear();
|
2014-10-22 18:39:03 +00:00
|
|
|
filteredSel = -1;
|
2014-07-04 11:12:54 +00:00
|
|
|
filterResults.clear();
|
2014-05-30 08:53:19 +00:00
|
|
|
filter.clear();
|
2014-10-22 18:39:03 +00:00
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
2014-08-22 07:41:39 +00:00
|
|
|
void DialogsListWidget::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;
|
|
|
|
outMsg = 0;
|
|
|
|
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;
|
|
|
|
outMsg = 0;
|
|
|
|
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;
|
|
|
|
outMsg = 0;
|
|
|
|
return;
|
2014-05-30 08:53:19 +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 && !searchResults.isEmpty()) {
|
|
|
|
for (SearchResults::const_iterator b = searchResults.cbegin(), i = b + 1, e = searchResults.cend(); i != e; ++i) {
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
2014-10-22 18:39:03 +00:00
|
|
|
if (searchResults.at(0)->_item->history()->peer == inPeer && searchResults.at(0)->_item->id == inMsg) {
|
|
|
|
outMsg = 0;
|
|
|
|
if (peopleResults.isEmpty()) {
|
|
|
|
if (filterResults.isEmpty()) {
|
|
|
|
outPeer = 0;
|
|
|
|
} else {
|
|
|
|
outPeer = filterResults.back()->history->peer;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
outPeer = peopleResults.back();
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!peopleResults.isEmpty() && peopleResults.at(0) == inPeer) {
|
|
|
|
outPeer = filterResults.isEmpty() ? 0 : filterResults.back()->history->peer;
|
|
|
|
outMsg = 0;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (!peopleResults.isEmpty()) {
|
|
|
|
for (PeopleResults::const_iterator b = peopleResults.cbegin(), i = b + 1, e = peopleResults.cend(); i != e; ++i) {
|
|
|
|
if ((*i) == inPeer) {
|
|
|
|
outPeer = (*(i - 1));
|
|
|
|
outMsg = 0;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2014-08-22 07:41:39 +00:00
|
|
|
}
|
|
|
|
if (filterResults.isEmpty() || filterResults.at(0)->history->peer == inPeer) {
|
|
|
|
outPeer = 0;
|
|
|
|
outMsg = 0;
|
|
|
|
return;
|
|
|
|
}
|
2014-07-04 11:12:54 +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;
|
2014-08-22 07:41:39 +00:00
|
|
|
outMsg = 0;
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2014-08-22 07:41:39 +00:00
|
|
|
void DialogsListWidget::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()) {
|
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()->next != contactsNoDialogs.list.end) {
|
2014-08-22 07:41:39 +00:00
|
|
|
outPeer = i.value()->next->history->peer;
|
|
|
|
outMsg = 0;
|
|
|
|
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
|
|
|
}
|
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;
|
|
|
|
outMsg = 0;
|
|
|
|
return;
|
2014-07-04 11:12:54 +00:00
|
|
|
} else if (contactsNoDialogs.list.count) {
|
2014-08-22 07:41:39 +00:00
|
|
|
outPeer = contactsNoDialogs.list.begin->history->peer;
|
|
|
|
outMsg = 0;
|
|
|
|
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) {
|
|
|
|
for (SearchResults::const_iterator i = searchResults.cbegin(), e = searchResults.cend(); i != e; ++i) {
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-10-22 18:39:03 +00:00
|
|
|
for (PeopleResults::const_iterator i = peopleResults.cbegin(), e = peopleResults.cend(); i != e; ++i) {
|
|
|
|
if ((*i) == inPeer) {
|
|
|
|
++i;
|
|
|
|
if (i == e && !searchResults.isEmpty()) {
|
|
|
|
outPeer = searchResults.front()->_item->history()->peer;
|
|
|
|
outMsg = searchResults.front()->_item->id;
|
|
|
|
} else {
|
|
|
|
outPeer = (i == e) ? 0 : (*i);
|
|
|
|
outMsg = 0;
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2014-07-04 11:12:54 +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;
|
2014-10-22 18:39:03 +00:00
|
|
|
if (i == e && !peopleResults.isEmpty()) {
|
|
|
|
outPeer = peopleResults.front();
|
|
|
|
outMsg = 0;
|
|
|
|
} else if (i == e && !searchResults.isEmpty()) {
|
|
|
|
outPeer = searchResults.front()->_item->history()->peer;
|
|
|
|
outMsg = searchResults.front()->_item->id;
|
|
|
|
} else {
|
|
|
|
outPeer = (i == e) ? 0 : (*i)->history->peer;
|
|
|
|
outMsg = 0;
|
|
|
|
}
|
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
|
|
|
}
|
|
|
|
|
|
|
|
DialogsIndexed &DialogsListWidget::contactsList() {
|
|
|
|
return contacts;
|
|
|
|
}
|
|
|
|
|
|
|
|
DialogsIndexed &DialogsListWidget::dialogsList() {
|
|
|
|
return dialogs;
|
|
|
|
}
|
|
|
|
|
2014-10-22 18:39:03 +00:00
|
|
|
DialogsListWidget::FilteredDialogs &DialogsListWidget::filteredList() {
|
|
|
|
return filterResults;
|
|
|
|
}
|
|
|
|
|
|
|
|
DialogsListWidget::PeopleResults &DialogsListWidget::peopleList() {
|
|
|
|
return peopleResults;
|
|
|
|
}
|
|
|
|
|
2014-07-04 11:12:54 +00:00
|
|
|
DialogsListWidget::SearchResults &DialogsListWidget::searchList() {
|
|
|
|
return searchResults;
|
|
|
|
}
|
|
|
|
|
2014-08-22 07:41:39 +00:00
|
|
|
MsgId DialogsListWidget::lastSearchId() const {
|
|
|
|
return _lastSearchId;
|
|
|
|
}
|
|
|
|
|
2014-06-16 09:31:10 +00:00
|
|
|
DialogsWidget::DialogsWidget(MainWidget *parent) : QWidget(parent)
|
|
|
|
, _drawShadow(true)
|
|
|
|
, dlgOffset(0)
|
|
|
|
, dlgCount(-1)
|
|
|
|
, dlgPreloading(0)
|
|
|
|
, contactsRequest(0)
|
|
|
|
, _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)
|
2014-06-16 09:31:10 +00:00
|
|
|
, scroll(this, st::dlgScroll)
|
|
|
|
, list(&scroll, parent)
|
2014-07-04 11:12:54 +00:00
|
|
|
, _searchFull(false)
|
2014-10-22 18:39:03 +00:00
|
|
|
, _peopleFull(false)
|
2014-06-16 09:31:10 +00:00
|
|
|
{
|
2014-05-30 08:53:19 +00:00
|
|
|
scroll.setWidget(&list);
|
|
|
|
scroll.setFocusPolicy(Qt::NoFocus);
|
|
|
|
connect(&list, SIGNAL(mustScrollTo(int, int)), &scroll, SLOT(scrollToY(int, int)));
|
|
|
|
connect(&list, SIGNAL(dialogToTopFrom(int)), this, SLOT(onDialogToTopFrom(int)));
|
2014-07-13 09:50:38 +00:00
|
|
|
connect(&list, SIGNAL(searchMessages()), this, SLOT(onNeedSearchMessages()));
|
2014-10-22 18:39:03 +00:00
|
|
|
connect(&list, SIGNAL(searchResultChosen()), this, SLOT(onCancel()));
|
2015-03-24 10:00:27 +00:00
|
|
|
connect(&list, SIGNAL(completeHashtag(QString)), this, SLOT(onCompleteHashtag(QString)));
|
2015-03-24 15:18:20 +00:00
|
|
|
connect(&list, SIGNAL(refreshHashtags()), this, SLOT(onFilterCursorMoved()));
|
2014-05-30 08:53:19 +00:00
|
|
|
connect(&scroll, SIGNAL(geometryChanged()), &list, SLOT(onParentGeometryChanged()));
|
|
|
|
connect(&scroll, SIGNAL(scrolled()), &list, SLOT(onUpdateSelected()));
|
|
|
|
connect(&scroll, SIGNAL(scrolled()), this, SLOT(onListScroll()));
|
|
|
|
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()));
|
|
|
|
|
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
|
|
|
|
|
|
|
scroll.show();
|
|
|
|
_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();
|
|
|
|
list.activate();
|
|
|
|
}
|
|
|
|
|
|
|
|
void DialogsWidget::createDialogAtTop(History *history, int32 unreadCount) {
|
|
|
|
list.createDialogAtTop(history, unreadCount);
|
|
|
|
}
|
|
|
|
|
|
|
|
void DialogsWidget::dlgUpdated(DialogRow *row) {
|
|
|
|
list.dlgUpdated(row);
|
|
|
|
}
|
|
|
|
|
|
|
|
void DialogsWidget::dlgUpdated(History *row) {
|
|
|
|
list.dlgUpdated(row);
|
|
|
|
}
|
|
|
|
|
|
|
|
void DialogsWidget::dialogsToUp() {
|
|
|
|
if (_filter.text().trimmed().isEmpty()) {
|
|
|
|
scroll.scrollToY(0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void DialogsWidget::setInnerFocus() {
|
|
|
|
_filter.setFocus();
|
|
|
|
}
|
|
|
|
|
2014-12-12 16:27:03 +00:00
|
|
|
void DialogsWidget::animShow(const QPixmap &bgAnimCache) {
|
|
|
|
_bgAnimCache = bgAnimCache;
|
|
|
|
_animCache = myGrab(this, rect());
|
|
|
|
scroll.hide();
|
|
|
|
_filter.hide();
|
|
|
|
_cancelSearch.hide();
|
|
|
|
_newGroup.hide();
|
|
|
|
a_coord = anim::ivalue(-st::introSlideShift, 0);
|
|
|
|
a_alpha = anim::fvalue(0, 1);
|
|
|
|
a_bgCoord = anim::ivalue(0, st::introSlideShift);
|
|
|
|
a_bgAlpha = anim::fvalue(1, 0);
|
2014-05-30 08:53:19 +00:00
|
|
|
anim::start(this);
|
|
|
|
}
|
|
|
|
|
2014-12-12 16:27:03 +00:00
|
|
|
bool DialogsWidget::animStep(float64 ms) {
|
|
|
|
float64 fullDuration = st::introSlideDelta + st::introSlideDuration, dt = ms / fullDuration;
|
|
|
|
float64 dt1 = (ms > st::introSlideDuration) ? 1 : (ms / st::introSlideDuration), dt2 = (ms > st::introSlideDelta) ? (ms - st::introSlideDelta) / (st::introSlideDuration) : 0;
|
|
|
|
bool res = true;
|
|
|
|
if (dt2 >= 1) {
|
|
|
|
res = false;
|
|
|
|
a_bgCoord.finish();
|
|
|
|
a_bgAlpha.finish();
|
|
|
|
a_coord.finish();
|
|
|
|
a_alpha.finish();
|
|
|
|
_bgAnimCache = _animCache = QPixmap();
|
|
|
|
scroll.show();
|
|
|
|
_filter.show();
|
|
|
|
onFilterUpdate(true);
|
|
|
|
activate();
|
|
|
|
} else {
|
|
|
|
a_bgCoord.update(dt1, st::introHideFunc);
|
|
|
|
a_bgAlpha.update(dt1, st::introAlphaHideFunc);
|
|
|
|
a_coord.update(dt2, st::introShowFunc);
|
|
|
|
a_alpha.update(dt2, st::introAlphaShowFunc);
|
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() {
|
2014-12-12 16:27:03 +00:00
|
|
|
if (!onCancelSearch() || !App::main()->selectingPeer()) {
|
|
|
|
emit cancelled();
|
|
|
|
}
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
|
2014-10-10 12:46:20 +00:00
|
|
|
void DialogsWidget::itemRemoved(HistoryItem *item) {
|
|
|
|
list.itemRemoved(item);
|
|
|
|
}
|
|
|
|
|
|
|
|
void DialogsWidget::itemReplaced(HistoryItem *oldItem, HistoryItem *newItem) {
|
|
|
|
list.itemReplaced(oldItem, newItem);
|
|
|
|
}
|
|
|
|
|
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) {
|
|
|
|
const MTPDdialog &d(i->c_dialog());
|
|
|
|
Histories::iterator j = App::histories().find(App::peerFromMTP(d.vpeer));
|
|
|
|
if (j != App::histories().end()) {
|
|
|
|
App::main()->applyNotifySetting(MTP_notifyPeer(d.vpeer), d.vnotify_settings, j.value());
|
2014-12-12 16:27:03 +00:00
|
|
|
if (d.vunread_count.v >= j.value()->unreadCount) {
|
|
|
|
j.value()->setUnreadCount(d.vunread_count.v, false);
|
|
|
|
}
|
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
|
|
|
}
|
|
|
|
|
|
|
|
void DialogsWidget::dialogsReceived(const MTPmessages_Dialogs &dialogs) {
|
|
|
|
const QVector<MTPDialog> *dlgList = 0;
|
|
|
|
switch (dialogs.type()) {
|
|
|
|
case mtpc_messages_dialogs: {
|
|
|
|
const MTPDmessages_dialogs &data(dialogs.c_messages_dialogs());
|
|
|
|
App::feedUsers(data.vusers);
|
|
|
|
App::feedChats(data.vchats);
|
|
|
|
App::feedMsgs(data.vmessages);
|
|
|
|
dlgList = &data.vdialogs.c_vector().v;
|
|
|
|
dlgCount = dlgList->size();
|
|
|
|
} break;
|
|
|
|
case mtpc_messages_dialogsSlice: {
|
|
|
|
const MTPDmessages_dialogsSlice &data(dialogs.c_messages_dialogsSlice());
|
|
|
|
App::feedUsers(data.vusers);
|
|
|
|
App::feedChats(data.vchats);
|
|
|
|
App::feedMsgs(data.vmessages);
|
|
|
|
dlgList = &data.vdialogs.c_vector().v;
|
|
|
|
dlgCount = data.vcount.v;
|
|
|
|
} break;
|
|
|
|
}
|
|
|
|
|
|
|
|
unreadCountsReceived(*dlgList);
|
|
|
|
|
|
|
|
if (!contactsRequest) {
|
|
|
|
contactsRequest = MTP::send(MTPcontacts_GetContacts(MTP_string("")), rpcDone(&DialogsWidget::contactsReceived), rpcFail(&DialogsWidget::contactsFailed));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (dlgList) {
|
|
|
|
list.dialogsReceived(*dlgList);
|
|
|
|
onListScroll();
|
|
|
|
|
|
|
|
if (dlgList->size()) {
|
|
|
|
dlgOffset += dlgList->size();
|
|
|
|
} else {
|
|
|
|
dlgCount = dlgOffset;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
dlgCount = dlgOffset;
|
|
|
|
}
|
|
|
|
|
|
|
|
dlgPreloading = 0;
|
|
|
|
if (dlgList) {
|
|
|
|
loadDialogs();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-04 20:01:34 +00:00
|
|
|
bool DialogsWidget::dialogsFailed(const RPCError &error) {
|
|
|
|
if (error.type().startsWith(qsl("FLOOD_WAIT_"))) return false;
|
|
|
|
|
|
|
|
LOG(("RPC Error: %1 %2: %3").arg(error.code()).arg(error.type()).arg(error.description()));
|
2014-05-30 08:53:19 +00:00
|
|
|
dlgPreloading = 0;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-07-13 09:50:38 +00:00
|
|
|
bool DialogsWidget::onSearchMessages(bool searchCache) {
|
2014-07-04 11:12:54 +00:00
|
|
|
QString q = _filter.text().trimmed();
|
|
|
|
if (q.isEmpty()) {
|
|
|
|
if (_searchRequest) {
|
|
|
|
_searchRequest = 0;
|
|
|
|
}
|
2014-10-22 18:39:03 +00:00
|
|
|
if (_peopleRequest) {
|
|
|
|
_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;
|
|
|
|
_searchFull = false;
|
|
|
|
_searchRequest = 0;
|
|
|
|
searchReceived(true, i.value(), 0);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
} else if (_searchQuery != q) {
|
2014-07-04 11:12:54 +00:00
|
|
|
_searchQuery = q;
|
|
|
|
_searchFull = false;
|
|
|
|
_searchRequest = MTP::send(MTPmessages_Search(MTP_inputPeerEmpty(), MTP_string(_searchQuery), MTP_inputMessagesFilterEmpty(), MTP_int(0), MTP_int(0), MTP_int(0), MTP_int(0), MTP_int(SearchPerPage)), rpcDone(&DialogsWidget::searchReceived, true), rpcFail(&DialogsWidget::searchFailed));
|
2014-07-13 09:50:38 +00:00
|
|
|
_searchQueries.insert(_searchRequest, _searchQuery);
|
|
|
|
}
|
2014-10-22 18:39:03 +00:00
|
|
|
if (q.size() >= MinUsernameLength) {
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-07-16 06:58:36 +00:00
|
|
|
void DialogsWidget::searchMessages(const QString &query) {
|
|
|
|
if (_filter.text() != query) {
|
|
|
|
_filter.setText(query);
|
|
|
|
_filter.updatePlaceholder();
|
|
|
|
onFilterUpdate();
|
|
|
|
_searchTimer.stop();
|
|
|
|
onSearchMessages();
|
2015-03-24 10:00:27 +00:00
|
|
|
|
|
|
|
list.saveRecentHashtags(query);
|
2014-07-16 06:58:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-07-04 11:12:54 +00:00
|
|
|
void DialogsWidget::onSearchMore(MsgId minMsgId) {
|
|
|
|
if (!_searchRequest && !_searchFull) {
|
|
|
|
_searchRequest = MTP::send(MTPmessages_Search(MTP_inputPeerEmpty(), MTP_string(_searchQuery), MTP_inputMessagesFilterEmpty(), MTP_int(0), MTP_int(0), MTP_int(0), MTP_int(minMsgId), MTP_int(SearchPerPage)), rpcDone(&DialogsWidget::searchReceived, !minMsgId), rpcFail(&DialogsWidget::searchFailed));
|
2014-07-13 09:50:38 +00:00
|
|
|
if (!minMsgId) {
|
|
|
|
_searchQueries.insert(_searchRequest, _searchQuery);
|
|
|
|
}
|
2014-07-04 11:12:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-30 08:53:19 +00:00
|
|
|
void DialogsWidget::loadDialogs() {
|
|
|
|
if (dlgPreloading) return;
|
2014-08-01 18:49:43 +00:00
|
|
|
if (dlgCount >= 0 && dlgOffset >= dlgCount) return;
|
2014-05-30 08:53:19 +00:00
|
|
|
|
|
|
|
int32 loadCount = dlgOffset ? DialogsPerPage : DialogsFirstLoad;
|
|
|
|
dlgPreloading = MTP::send(MTPmessages_GetDialogs(MTP_int(dlgOffset), MTP_int(0), MTP_int(loadCount)), rpcDone(&DialogsWidget::dialogsReceived), rpcFail(&DialogsWidget::dialogsFailed));
|
|
|
|
}
|
|
|
|
|
|
|
|
void DialogsWidget::contactsReceived(const MTPcontacts_Contacts &contacts) {
|
|
|
|
if (contacts.type() == mtpc_contacts_contacts) {
|
|
|
|
const MTPDcontacts_contacts &d(contacts.c_contacts_contacts());
|
|
|
|
App::feedUsers(d.vusers);
|
|
|
|
list.contactsReceived(d.vcontacts.c_vector().v);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-04 20:01:34 +00:00
|
|
|
bool DialogsWidget::contactsFailed(const RPCError &error) {
|
|
|
|
if (error.type().startsWith(qsl("FLOOD_WAIT_"))) return false;
|
|
|
|
|
2014-05-30 08:53:19 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-07-04 11:12:54 +00:00
|
|
|
void DialogsWidget::searchReceived(bool fromStart, const MTPmessages_Messages &result, mtpRequestId req) {
|
2014-07-13 09:50:38 +00:00
|
|
|
if (fromStart && (list.state() == DialogsListWidget::FilteredState || list.state() == DialogsListWidget::SearchedState)) {
|
|
|
|
SearchQueries::iterator i = _searchQueries.find(req);
|
|
|
|
if (i != _searchQueries.cend()) {
|
|
|
|
_searchCache[i.value()] = result;
|
|
|
|
_searchQueries.erase(i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-07-04 11:12:54 +00:00
|
|
|
if (_searchRequest == req) {
|
|
|
|
switch (result.type()) {
|
|
|
|
case mtpc_messages_messages: {
|
|
|
|
App::feedUsers(result.c_messages_messages().vusers);
|
|
|
|
App::feedChats(result.c_messages_messages().vchats);
|
|
|
|
const QVector<MTPMessage> &msgs(result.c_messages_messages().vmessages.c_vector().v);
|
2014-07-13 09:50:38 +00:00
|
|
|
list.searchReceived(msgs, fromStart, msgs.size());
|
2014-07-04 11:12:54 +00:00
|
|
|
if (msgs.isEmpty()) {
|
|
|
|
_searchFull = true;
|
|
|
|
}
|
|
|
|
} break;
|
|
|
|
|
|
|
|
case mtpc_messages_messagesSlice: {
|
|
|
|
App::feedUsers(result.c_messages_messagesSlice().vusers);
|
|
|
|
App::feedChats(result.c_messages_messagesSlice().vchats);
|
|
|
|
const QVector<MTPMessage> &msgs(result.c_messages_messagesSlice().vmessages.c_vector().v);
|
2014-07-13 09:50:38 +00:00
|
|
|
list.searchReceived(msgs, fromStart, result.c_messages_messagesSlice().vcount.v);
|
2014-07-04 11:12:54 +00:00
|
|
|
if (msgs.isEmpty()) {
|
|
|
|
_searchFull = true;
|
|
|
|
}
|
|
|
|
} 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;
|
2014-10-22 18:39:03 +00:00
|
|
|
if (list.state() == DialogsListWidget::FilteredState || list.state() == DialogsListWidget::SearchedState) {
|
|
|
|
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);
|
2014-10-23 16:05:33 +00:00
|
|
|
list.peopleReceived(q, result.c_contacts_found().vresults.c_vector().v);
|
2014-10-22 18:39:03 +00:00
|
|
|
} break;
|
|
|
|
}
|
|
|
|
|
|
|
|
_peopleRequest = 0;
|
|
|
|
onListScroll();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-07-04 11:12:54 +00:00
|
|
|
bool DialogsWidget::searchFailed(const RPCError &error, mtpRequestId req) {
|
2015-04-04 20:01:34 +00:00
|
|
|
if (error.type().startsWith(qsl("FLOOD_WAIT_"))) return false;
|
|
|
|
|
2014-07-04 11:12:54 +00:00
|
|
|
if (_searchRequest == req) {
|
|
|
|
_searchRequest = 0;
|
|
|
|
_searchFull = true;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-10-22 18:39:03 +00:00
|
|
|
bool DialogsWidget::peopleFailed(const RPCError &error, mtpRequestId req) {
|
2015-04-04 20:01:34 +00:00
|
|
|
if (error.type().startsWith(qsl("FLOOD_WAIT_"))) return false;
|
|
|
|
|
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());
|
|
|
|
onFilterUpdate();
|
|
|
|
int32 to = list.addNewContact(uid, true);
|
|
|
|
if (to < 0 || !show) return false;
|
|
|
|
list.refresh();
|
|
|
|
scroll.scrollToY(to);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void DialogsWidget::onListScroll() {
|
2015-03-02 12:34:16 +00:00
|
|
|
// if (!App::self()) return;
|
|
|
|
|
2014-05-30 08:53:19 +00:00
|
|
|
list.loadPeerPhotos(scroll.scrollTop());
|
2014-07-04 11:12:54 +00:00
|
|
|
if (list.state() == DialogsListWidget::SearchedState) {
|
2014-10-22 18:39:03 +00:00
|
|
|
if (scroll.scrollTop() > (list.searchList().size() + list.filteredList().size() + list.peopleList().size()) * st::dlgHeight - PreloadHeightsCount * scroll.height()) {
|
2014-08-22 07:41:39 +00:00
|
|
|
onSearchMore(list.lastSearchId());
|
2014-07-04 11:12:54 +00:00
|
|
|
}
|
2014-10-08 07:42:36 +00:00
|
|
|
} else if (scroll.scrollTop() > list.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) {
|
|
|
|
if (animating() && !force) return;
|
|
|
|
|
2014-07-04 11:12:54 +00:00
|
|
|
QString filterText = _filter.text();
|
|
|
|
list.onFilterUpdate(filterText);
|
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-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-03-24 10:00:27 +00:00
|
|
|
QString t = _filter.text(), r;
|
|
|
|
for (int start = to; start > 0;) {
|
|
|
|
--start;
|
|
|
|
if (t.size() <= start) break;
|
|
|
|
if (t.at(start) == '#') {
|
|
|
|
r = t.mid(start, to - start);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (!t.at(start).isLetterOrNumber() && t.at(start) != '_') break;
|
|
|
|
}
|
|
|
|
list.onHashtagFilterUpdate(r);
|
|
|
|
}
|
|
|
|
|
|
|
|
void DialogsWidget::onCompleteHashtag(QString tag) {
|
|
|
|
QString t = _filter.text(), r;
|
|
|
|
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) {
|
|
|
|
int32 w = width() - st::dlgShadow;
|
|
|
|
_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());
|
2014-07-13 09:50:38 +00:00
|
|
|
scroll.move(0, _filter.height() + 2 * st::dlgFilterPadding);
|
|
|
|
scroll.resize(w, height() - _filter.y() - _filter.height() - st::dlgFilterPadding - st::dlgPaddingVer);
|
2014-05-30 08:53:19 +00:00
|
|
|
list.resize(w, list.height());
|
|
|
|
onListScroll();
|
|
|
|
}
|
|
|
|
|
|
|
|
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-02-09 23:19:48 +00:00
|
|
|
if (!list.choosePeer()) {
|
|
|
|
if (list.state() == DialogsListWidget::DefaultState || list.state() == DialogsListWidget::SearchedState || (list.state() == DialogsListWidget::FilteredState && list.hasFilteredResults())) {
|
|
|
|
list.selectSkip(1);
|
|
|
|
list.choosePeer();
|
|
|
|
} 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) {
|
|
|
|
list.setMouseSel(false);
|
|
|
|
list.selectSkip(1);
|
|
|
|
} else if (e->key() == Qt::Key_Up) {
|
|
|
|
list.setMouseSel(false);
|
|
|
|
list.selectSkip(-1);
|
|
|
|
} else if (e->key() == Qt::Key_PageDown) {
|
|
|
|
list.setMouseSel(false);
|
|
|
|
list.selectSkipPage(scroll.height(), 1);
|
|
|
|
} else if (e->key() == Qt::Key_PageUp) {
|
|
|
|
list.setMouseSel(false);
|
|
|
|
list.selectSkipPage(scroll.height(), -1);
|
|
|
|
} else {
|
|
|
|
e->ignore();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void DialogsWidget::paintEvent(QPaintEvent *e) {
|
|
|
|
QPainter p(this);
|
2014-12-12 16:27:03 +00:00
|
|
|
QRect r(e->rect());
|
|
|
|
if (r != rect()) {
|
|
|
|
p.setClipRect(r);
|
|
|
|
}
|
|
|
|
if (animating()) {
|
|
|
|
p.setOpacity(a_bgAlpha.current());
|
|
|
|
p.drawPixmap(a_bgCoord.current(), 0, _bgAnimCache);
|
|
|
|
p.setOpacity(a_alpha.current());
|
|
|
|
p.drawPixmap(a_coord.current(), 0, _animCache);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (cWideMode() && _drawShadow) {
|
|
|
|
QRect sh(width() - st::dlgShadow, 0, st::dlgShadow, height());
|
|
|
|
if (r.intersects(sh)) {
|
|
|
|
p.fillRect(sh, st::dlgShadowColor->b);
|
|
|
|
}
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void DialogsWidget::destroyData() {
|
|
|
|
list.destroyData();
|
|
|
|
}
|
|
|
|
|
2014-08-22 07:41:39 +00:00
|
|
|
void DialogsWidget::peerBefore(const PeerData *inPeer, MsgId inMsg, PeerData *&outPeer, MsgId &outMsg) const {
|
|
|
|
return list.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 {
|
|
|
|
return list.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) {
|
|
|
|
list.scrollToPeer(peer, msgId);
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void DialogsWidget::removePeer(PeerData *peer) {
|
|
|
|
_filter.setText(QString());
|
|
|
|
onFilterUpdate();
|
|
|
|
list.removePeer(peer);
|
|
|
|
}
|
|
|
|
|
|
|
|
void DialogsWidget::removeContact(UserData *user) {
|
|
|
|
_filter.setText(QString());
|
|
|
|
onFilterUpdate();
|
|
|
|
list.removeContact(user);
|
|
|
|
}
|
|
|
|
|
|
|
|
DialogsIndexed &DialogsWidget::contactsList() {
|
|
|
|
return list.contactsList();
|
|
|
|
}
|
|
|
|
|
|
|
|
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-04-02 10:33:19 +00:00
|
|
|
App::wnd()->showLayer(new ContactsBox(true));
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
|
2014-12-12 16:27:03 +00:00
|
|
|
bool DialogsWidget::onCancelSearch() {
|
|
|
|
bool clearing = !_filter.text().isEmpty();
|
2014-07-04 11:12:54 +00:00
|
|
|
list.clearFilter();
|
|
|
|
_filter.clear();
|
|
|
|
_filter.updatePlaceholder();
|
|
|
|
onFilterUpdate();
|
2014-12-12 16:27:03 +00:00
|
|
|
return clearing;
|
2014-07-04 11:12:54 +00:00
|
|
|
}
|
|
|
|
|
2014-05-30 08:53:19 +00:00
|
|
|
void DialogsWidget::onDialogToTopFrom(int movedFrom) {
|
|
|
|
if (scroll.scrollTop() > 0) {
|
|
|
|
if (movedFrom > scroll.scrollTop()) {
|
|
|
|
scroll.scrollToY(scroll.scrollTop() + st::dlgHeight);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void DialogsWidget::enableShadow(bool enable) {
|
|
|
|
_drawShadow = enable;
|
|
|
|
}
|