2016-06-07 19:59:39 +00:00
|
|
|
/*
|
|
|
|
This file is part of Telegram Desktop,
|
2018-01-03 10:23:14 +00:00
|
|
|
the official desktop application for the Telegram messaging service.
|
2016-06-07 19:59:39 +00:00
|
|
|
|
2018-01-03 10:23:14 +00:00
|
|
|
For license and copyright information please follow this link:
|
|
|
|
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
2016-06-07 19:59:39 +00:00
|
|
|
*/
|
|
|
|
#include "dialogs/dialogs_row.h"
|
|
|
|
|
2016-12-05 11:01:08 +00:00
|
|
|
#include "ui/effects/ripple_animation.h"
|
2019-04-23 12:29:23 +00:00
|
|
|
#include "ui/text_options.h"
|
2018-01-13 12:45:11 +00:00
|
|
|
#include "dialogs/dialogs_entry.h"
|
2019-04-23 12:29:23 +00:00
|
|
|
#include "data/data_folder.h"
|
2019-06-17 14:37:29 +00:00
|
|
|
#include "data/data_peer_values.h"
|
2019-04-23 12:29:23 +00:00
|
|
|
#include "history/history.h"
|
|
|
|
#include "lang/lang_keys.h"
|
2016-12-05 11:01:08 +00:00
|
|
|
#include "mainwidget.h"
|
2019-04-23 12:29:23 +00:00
|
|
|
#include "styles/style_dialogs.h"
|
2016-06-07 19:59:39 +00:00
|
|
|
|
|
|
|
namespace Dialogs {
|
2019-04-23 12:29:23 +00:00
|
|
|
namespace {
|
|
|
|
|
|
|
|
QString ComposeFolderListEntryText(not_null<Data::Folder*> folder) {
|
2019-05-08 08:50:39 +00:00
|
|
|
const auto &list = folder->lastHistories();
|
2019-04-23 12:29:23 +00:00
|
|
|
if (list.empty()) {
|
2019-05-08 08:50:39 +00:00
|
|
|
return QString();
|
2019-04-23 12:29:23 +00:00
|
|
|
}
|
2019-05-08 08:50:39 +00:00
|
|
|
|
2019-04-23 12:29:23 +00:00
|
|
|
const auto count = std::max(
|
|
|
|
int(list.size()),
|
2020-03-16 10:20:18 +00:00
|
|
|
folder->chatsList()->fullSize().current());
|
2019-05-08 08:50:39 +00:00
|
|
|
|
|
|
|
const auto throwAwayLastName = (list.size() > 1)
|
|
|
|
&& (count == list.size() + 1);
|
|
|
|
auto &&peers = ranges::view::all(
|
|
|
|
list
|
|
|
|
) | ranges::view::take(
|
|
|
|
list.size() - (throwAwayLastName ? 1 : 0)
|
2019-05-08 09:05:15 +00:00
|
|
|
);
|
|
|
|
const auto wrapName = [](not_null<History*> history) {
|
2019-09-13 06:06:02 +00:00
|
|
|
const auto name = TextUtilities::Clean(history->peer->name);
|
2019-05-08 09:05:15 +00:00
|
|
|
return (history->unreadCount() > 0)
|
|
|
|
? (textcmdStartSemibold()
|
|
|
|
+ textcmdLink(1, name)
|
|
|
|
+ textcmdStopSemibold())
|
|
|
|
: name;
|
|
|
|
};
|
2019-05-08 08:50:39 +00:00
|
|
|
const auto shown = int(peers.size());
|
|
|
|
const auto accumulated = [&] {
|
|
|
|
Expects(shown > 0);
|
|
|
|
|
|
|
|
auto i = peers.begin();
|
2019-05-08 09:05:15 +00:00
|
|
|
auto result = wrapName(*i);
|
2019-05-08 08:50:39 +00:00
|
|
|
for (++i; i != peers.end(); ++i) {
|
2019-06-19 16:39:25 +00:00
|
|
|
result = tr::lng_archived_last_list(
|
|
|
|
tr::now,
|
2019-05-08 08:50:39 +00:00
|
|
|
lt_accumulated,
|
|
|
|
result,
|
|
|
|
lt_chat,
|
2019-05-08 09:05:15 +00:00
|
|
|
wrapName(*i));
|
2019-05-08 08:50:39 +00:00
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}();
|
|
|
|
return (shown < count)
|
2019-06-19 16:39:25 +00:00
|
|
|
? tr::lng_archived_last(tr::now, lt_count, (count - shown), lt_chats, accumulated)
|
2019-05-08 08:50:39 +00:00
|
|
|
: accumulated;
|
2019-04-23 12:29:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace
|
2016-06-07 19:59:39 +00:00
|
|
|
|
2019-06-17 14:37:29 +00:00
|
|
|
BasicRow::BasicRow() = default;
|
|
|
|
BasicRow::~BasicRow() = default;
|
2016-12-05 11:01:08 +00:00
|
|
|
|
2019-06-17 14:37:29 +00:00
|
|
|
void BasicRow::setOnline(bool online, Fn<void()> updateCallback) const {
|
|
|
|
if (_online == online) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
_online = online;
|
|
|
|
if (_onlineUserpic && _onlineUserpic->animation.animating()) {
|
|
|
|
_onlineUserpic->animation.change(
|
|
|
|
_online ? 1. : 0.,
|
|
|
|
st::dialogsOnlineBadgeDuration);
|
|
|
|
} else if (updateCallback) {
|
|
|
|
ensureOnlineUserpic();
|
|
|
|
_onlineUserpic->animation.start(
|
|
|
|
std::move(updateCallback),
|
|
|
|
_online ? 0. : 1.,
|
|
|
|
_online ? 1. : 0.,
|
|
|
|
st::dialogsOnlineBadgeDuration);
|
|
|
|
}
|
|
|
|
if (!_online
|
|
|
|
&& _onlineUserpic
|
|
|
|
&& !_onlineUserpic->animation.animating()) {
|
|
|
|
_onlineUserpic = nullptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void BasicRow::addRipple(
|
|
|
|
QPoint origin,
|
|
|
|
QSize size,
|
|
|
|
Fn<void()> updateCallback) {
|
2016-12-05 11:01:08 +00:00
|
|
|
if (!_ripple) {
|
|
|
|
auto mask = Ui::RippleAnimation::rectMask(size);
|
2019-06-17 14:37:29 +00:00
|
|
|
_ripple = std::make_unique<Ui::RippleAnimation>(
|
|
|
|
st::dialogsRipple,
|
|
|
|
std::move(mask),
|
|
|
|
std::move(updateCallback));
|
2016-12-05 11:01:08 +00:00
|
|
|
}
|
|
|
|
_ripple->add(origin);
|
|
|
|
}
|
|
|
|
|
2019-06-17 14:37:29 +00:00
|
|
|
void BasicRow::stopLastRipple() {
|
2016-12-05 11:01:08 +00:00
|
|
|
if (_ripple) {
|
|
|
|
_ripple->lastStop();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-06-17 14:37:29 +00:00
|
|
|
void BasicRow::paintRipple(
|
|
|
|
Painter &p,
|
|
|
|
int x,
|
|
|
|
int y,
|
|
|
|
int outerWidth,
|
|
|
|
const QColor *colorOverride) const {
|
2016-12-05 11:01:08 +00:00
|
|
|
if (_ripple) {
|
2019-04-02 09:13:30 +00:00
|
|
|
_ripple->paint(p, x, y, outerWidth, colorOverride);
|
2016-12-05 11:01:08 +00:00
|
|
|
if (_ripple->empty()) {
|
|
|
|
_ripple.reset();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-06-17 14:37:29 +00:00
|
|
|
void BasicRow::ensureOnlineUserpic() const {
|
|
|
|
if (_onlineUserpic) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
_onlineUserpic = std::make_unique<OnlineUserpic>();
|
|
|
|
}
|
|
|
|
|
|
|
|
void BasicRow::PaintOnlineFrame(
|
|
|
|
not_null<OnlineUserpic*> data,
|
2020-05-28 14:32:10 +00:00
|
|
|
not_null<PeerData*> peer,
|
|
|
|
std::shared_ptr<Data::CloudImageView> &view) {
|
2019-06-17 14:37:29 +00:00
|
|
|
data->frame.fill(Qt::transparent);
|
|
|
|
|
|
|
|
Painter q(&data->frame);
|
|
|
|
peer->paintUserpic(
|
|
|
|
q,
|
2020-05-28 14:32:10 +00:00
|
|
|
view,
|
2019-06-17 14:37:29 +00:00
|
|
|
0,
|
|
|
|
0,
|
|
|
|
st::dialogsPhotoSize);
|
|
|
|
|
|
|
|
PainterHighQualityEnabler hq(q);
|
|
|
|
q.setCompositionMode(QPainter::CompositionMode_Source);
|
|
|
|
|
|
|
|
const auto size = st::dialogsOnlineBadgeSize;
|
|
|
|
const auto stroke = st::dialogsOnlineBadgeStroke;
|
|
|
|
const auto skip = st::dialogsOnlineBadgeSkip;
|
|
|
|
const auto edge = st::dialogsPadding.x() + st::dialogsPhotoSize;
|
|
|
|
const auto shrink = (size / 2) * (1. - data->online);
|
|
|
|
|
|
|
|
auto pen = QPen(Qt::transparent);
|
|
|
|
pen.setWidthF(stroke * data->online);
|
|
|
|
q.setPen(pen);
|
|
|
|
q.setBrush(data->active
|
|
|
|
? st::dialogsOnlineBadgeFgActive
|
|
|
|
: st::dialogsOnlineBadgeFg);
|
|
|
|
q.drawEllipse(QRectF(
|
|
|
|
edge - skip.x() - size,
|
|
|
|
edge - skip.y() - size,
|
|
|
|
size,
|
|
|
|
size
|
|
|
|
).marginsRemoved({ shrink, shrink, shrink, shrink }));
|
|
|
|
}
|
|
|
|
|
|
|
|
void BasicRow::paintUserpic(
|
|
|
|
Painter &p,
|
|
|
|
not_null<PeerData*> peer,
|
|
|
|
bool allowOnline,
|
|
|
|
bool active,
|
|
|
|
int fullWidth) const {
|
|
|
|
setOnline(Data::IsPeerAnOnlineUser(peer));
|
|
|
|
|
|
|
|
const auto online = _onlineUserpic
|
|
|
|
? _onlineUserpic->animation.value(_online ? 1. : 0.)
|
|
|
|
: (_online ? 1. : 0.);
|
|
|
|
if (!allowOnline || online == 0.) {
|
|
|
|
peer->paintUserpicLeft(
|
|
|
|
p,
|
2020-05-28 14:32:10 +00:00
|
|
|
_userpic,
|
2019-06-17 14:37:29 +00:00
|
|
|
st::dialogsPadding.x(),
|
|
|
|
st::dialogsPadding.y(),
|
|
|
|
fullWidth,
|
|
|
|
st::dialogsPhotoSize);
|
|
|
|
if (!allowOnline || !_online) {
|
|
|
|
_onlineUserpic = nullptr;
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
ensureOnlineUserpic();
|
|
|
|
if (_onlineUserpic->frame.isNull()) {
|
|
|
|
_onlineUserpic->frame = QImage(
|
|
|
|
st::dialogsPhotoSize * cRetinaFactor(),
|
|
|
|
st::dialogsPhotoSize * cRetinaFactor(),
|
|
|
|
QImage::Format_ARGB32_Premultiplied);
|
|
|
|
_onlineUserpic->frame.setDevicePixelRatio(cRetinaFactor());
|
|
|
|
}
|
2020-05-28 14:32:10 +00:00
|
|
|
const auto key = peer->userpicUniqueKey(_userpic);
|
2019-06-17 14:37:29 +00:00
|
|
|
if (_onlineUserpic->online != online
|
|
|
|
|| _onlineUserpic->key != key
|
|
|
|
|| _onlineUserpic->active != active) {
|
|
|
|
_onlineUserpic->online = online;
|
|
|
|
_onlineUserpic->key = key;
|
|
|
|
_onlineUserpic->active = active;
|
2020-05-28 14:32:10 +00:00
|
|
|
PaintOnlineFrame(_onlineUserpic.get(), peer, _userpic);
|
2019-06-17 14:37:29 +00:00
|
|
|
}
|
|
|
|
p.drawImage(st::dialogsPadding, _onlineUserpic->frame);
|
|
|
|
}
|
|
|
|
|
|
|
|
Row::Row(Key key, int pos) : _id(key), _pos(pos) {
|
|
|
|
if (const auto history = key.history()) {
|
|
|
|
setOnline(Data::IsPeerAnOnlineUser(history->peer));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-17 13:04:30 +00:00
|
|
|
uint64 Row::sortKey(FilterId filterId) const {
|
|
|
|
return _id.entry()->sortKeyInChatList(filterId);
|
2018-01-13 12:45:11 +00:00
|
|
|
}
|
|
|
|
|
2019-04-23 12:29:23 +00:00
|
|
|
void Row::validateListEntryCache() const {
|
|
|
|
const auto folder = _id.folder();
|
|
|
|
if (!folder) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
const auto version = folder->chatListViewVersion();
|
|
|
|
if (_listEntryCacheVersion == version) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
_listEntryCacheVersion = version;
|
|
|
|
_listEntryCache.setText(
|
|
|
|
st::dialogsTextStyle,
|
|
|
|
ComposeFolderListEntryText(folder),
|
|
|
|
Ui::DialogTextOptions());
|
|
|
|
}
|
|
|
|
|
2018-02-14 19:38:01 +00:00
|
|
|
FakeRow::FakeRow(Key searchInChat, not_null<HistoryItem*> item)
|
|
|
|
: _searchInChat(searchInChat)
|
2017-09-05 17:21:56 +00:00
|
|
|
, _item(item)
|
|
|
|
, _cache(st::dialogsTextWidthMin) {
|
2016-06-07 19:59:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace Dialogs
|