2016-04-09 18:45:55 +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-04-09 18:45:55 +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-04-09 18:45:55 +00:00
|
|
|
*/
|
|
|
|
#include "dialogs/dialogs_layout.h"
|
|
|
|
|
2016-06-09 11:51:24 +00:00
|
|
|
#include "data/data_abstract_structure.h"
|
2016-06-09 14:31:10 +00:00
|
|
|
#include "data/data_drafts.h"
|
2019-01-03 12:36:01 +00:00
|
|
|
#include "data/data_session.h"
|
2016-04-09 18:45:55 +00:00
|
|
|
#include "dialogs/dialogs_list.h"
|
2016-05-31 09:46:31 +00:00
|
|
|
#include "styles/style_dialogs.h"
|
2017-03-04 10:23:56 +00:00
|
|
|
#include "storage/localstorage.h"
|
2017-12-05 14:07:01 +00:00
|
|
|
#include "ui/empty_userpic.h"
|
2017-12-28 13:06:06 +00:00
|
|
|
#include "ui/text_options.h"
|
2017-04-13 08:27:10 +00:00
|
|
|
#include "lang/lang_keys.h"
|
2018-11-15 15:36:04 +00:00
|
|
|
#include "support/support_helper.h"
|
2019-03-15 15:15:56 +00:00
|
|
|
#include "history/history_item_components.h"
|
2018-01-11 19:33:26 +00:00
|
|
|
#include "history/history_item.h"
|
2018-01-13 12:45:11 +00:00
|
|
|
#include "history/history.h"
|
2019-01-04 11:09:48 +00:00
|
|
|
#include "data/data_channel.h"
|
|
|
|
#include "data/data_user.h"
|
2016-04-09 18:45:55 +00:00
|
|
|
|
|
|
|
namespace Dialogs {
|
|
|
|
namespace Layout {
|
2016-04-09 20:41:20 +00:00
|
|
|
namespace {
|
|
|
|
|
2016-07-26 12:09:40 +00:00
|
|
|
// Show all dates that are in the last 20 hours in time format.
|
|
|
|
constexpr int kRecentlyInSeconds = 20 * 3600;
|
|
|
|
|
2019-03-12 10:36:33 +00:00
|
|
|
bool ShowUserBotIcon(not_null<UserData*> user) {
|
|
|
|
return user->isBot() && !user->isSupport();
|
|
|
|
}
|
|
|
|
|
2019-04-23 12:29:23 +00:00
|
|
|
void PaintRowTopRight(Painter &p, const QString &text, QRect &rectForName, bool active, bool selected) {
|
2018-05-11 14:03:53 +00:00
|
|
|
const auto width = st::dialogsDateFont->width(text);
|
|
|
|
rectForName.setWidth(rectForName.width() - width - st::dialogsDateSkip);
|
|
|
|
p.setFont(st::dialogsDateFont);
|
|
|
|
p.setPen(active ? st::dialogsDateFgActive : (selected ? st::dialogsDateFgOver : st::dialogsDateFg));
|
|
|
|
p.drawText(rectForName.left() + rectForName.width() + st::dialogsDateSkip, rectForName.top() + st::msgNameFont->height - st::msgDateFont->descent, text);
|
|
|
|
}
|
|
|
|
|
2019-04-23 12:29:23 +00:00
|
|
|
void PaintRowDate(Painter &p, QDateTime date, QRect &rectForName, bool active, bool selected) {
|
2019-03-12 10:36:33 +00:00
|
|
|
const auto now = QDateTime::currentDateTime();
|
|
|
|
const auto &lastTime = date;
|
|
|
|
const auto nowDate = now.date();
|
|
|
|
const auto lastDate = lastTime.date();
|
|
|
|
|
|
|
|
const auto dt = [&] {
|
|
|
|
const auto wasSameDay = (lastDate == nowDate);
|
|
|
|
const auto wasRecently = qAbs(lastTime.secsTo(now)) < kRecentlyInSeconds;
|
|
|
|
if (wasSameDay || wasRecently) {
|
|
|
|
return lastTime.toString(cTimeFormat());
|
|
|
|
} else if (lastDate.year() == nowDate.year()
|
|
|
|
&& lastDate.weekNumber() == nowDate.weekNumber()) {
|
|
|
|
return langDayOfWeek(lastDate);
|
|
|
|
} else {
|
|
|
|
return lastDate.toString(qsl("d.MM.yy"));
|
|
|
|
}
|
|
|
|
}();
|
2019-04-23 12:29:23 +00:00
|
|
|
PaintRowTopRight(p, dt, rectForName, active, selected);
|
2016-06-03 18:24:27 +00:00
|
|
|
}
|
|
|
|
|
2018-10-09 15:36:06 +00:00
|
|
|
void PaintNarrowCounter(
|
|
|
|
Painter &p,
|
|
|
|
bool displayUnreadCounter,
|
|
|
|
bool displayUnreadMark,
|
|
|
|
bool displayMentionBadge,
|
|
|
|
int unreadCount,
|
|
|
|
bool active,
|
|
|
|
bool unreadMuted) {
|
|
|
|
auto skipBeforeMention = 0;
|
|
|
|
if (displayUnreadCounter || displayUnreadMark) {
|
|
|
|
auto counter = (unreadCount > 0)
|
|
|
|
? QString::number(unreadCount)
|
|
|
|
: QString();
|
|
|
|
const auto allowDigits = displayMentionBadge ? 1 : 3;
|
|
|
|
if (counter.size() > allowDigits + 1) {
|
|
|
|
counter = qsl("..") + counter.mid(counter.size() - allowDigits);
|
|
|
|
}
|
|
|
|
auto unreadRight = st::dialogsPadding.x() + st::dialogsPhotoSize;
|
|
|
|
auto unreadTop = st::dialogsPadding.y() + st::dialogsPhotoSize - st::dialogsUnreadHeight;
|
|
|
|
auto unreadWidth = 0;
|
|
|
|
|
|
|
|
UnreadBadgeStyle st;
|
|
|
|
st.active = active;
|
|
|
|
st.muted = unreadMuted;
|
|
|
|
paintUnreadCount(p, counter, unreadRight, unreadTop, st, &unreadWidth);
|
|
|
|
skipBeforeMention += unreadWidth + st.padding;
|
|
|
|
}
|
|
|
|
if (displayMentionBadge) {
|
|
|
|
auto counter = qsl("@");
|
|
|
|
auto unreadRight = st::dialogsPadding.x() + st::dialogsPhotoSize - skipBeforeMention;
|
|
|
|
auto unreadTop = st::dialogsPadding.y() + st::dialogsPhotoSize - st::dialogsUnreadHeight;
|
|
|
|
auto unreadWidth = 0;
|
|
|
|
|
|
|
|
UnreadBadgeStyle st;
|
|
|
|
st.active = active;
|
|
|
|
st.muted = false;
|
|
|
|
st.padding = 0;
|
|
|
|
st.textTop = 0;
|
|
|
|
paintUnreadCount(p, counter, unreadRight, unreadTop, st, &unreadWidth);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int PaintWideCounter(
|
|
|
|
Painter &p,
|
|
|
|
int texttop,
|
|
|
|
int availableWidth,
|
|
|
|
int fullWidth,
|
|
|
|
bool displayUnreadCounter,
|
|
|
|
bool displayUnreadMark,
|
|
|
|
bool displayMentionBadge,
|
|
|
|
bool displayPinnedIcon,
|
|
|
|
int unreadCount,
|
|
|
|
bool active,
|
|
|
|
bool selected,
|
|
|
|
bool unreadMuted) {
|
|
|
|
const auto initial = availableWidth;
|
|
|
|
auto hadOneBadge = false;
|
|
|
|
if (displayUnreadCounter || displayUnreadMark) {
|
|
|
|
auto counter = (unreadCount > 0)
|
|
|
|
? QString::number(unreadCount)
|
|
|
|
: QString();
|
|
|
|
auto unreadRight = fullWidth - st::dialogsPadding.x();
|
|
|
|
auto unreadTop = texttop + st::dialogsTextFont->ascent - st::dialogsUnreadFont->ascent - (st::dialogsUnreadHeight - st::dialogsUnreadFont->height) / 2;
|
|
|
|
auto unreadWidth = 0;
|
|
|
|
|
|
|
|
UnreadBadgeStyle st;
|
|
|
|
st.active = active;
|
|
|
|
st.muted = unreadMuted;
|
|
|
|
paintUnreadCount(p, counter, unreadRight, unreadTop, st, &unreadWidth);
|
|
|
|
availableWidth -= unreadWidth + st.padding;
|
|
|
|
|
|
|
|
hadOneBadge = true;
|
|
|
|
} else if (displayPinnedIcon) {
|
|
|
|
auto &icon = (active ? st::dialogsPinnedIconActive : (selected ? st::dialogsPinnedIconOver : st::dialogsPinnedIcon));
|
|
|
|
icon.paint(p, fullWidth - st::dialogsPadding.x() - icon.width(), texttop, fullWidth);
|
|
|
|
availableWidth -= icon.width() + st::dialogsUnreadPadding;
|
|
|
|
|
|
|
|
hadOneBadge = true;
|
|
|
|
}
|
|
|
|
if (displayMentionBadge) {
|
|
|
|
auto counter = qsl("@");
|
|
|
|
auto unreadRight = fullWidth - st::dialogsPadding.x() - (initial - availableWidth);
|
|
|
|
auto unreadTop = texttop + st::dialogsTextFont->ascent - st::dialogsUnreadFont->ascent - (st::dialogsUnreadHeight - st::dialogsUnreadFont->height) / 2;
|
|
|
|
auto unreadWidth = 0;
|
|
|
|
|
|
|
|
UnreadBadgeStyle st;
|
|
|
|
st.active = active;
|
|
|
|
st.muted = false;
|
|
|
|
st.padding = 0;
|
|
|
|
st.textTop = 0;
|
|
|
|
paintUnreadCount(p, counter, unreadRight, unreadTop, st, &unreadWidth);
|
|
|
|
availableWidth -= unreadWidth + st.padding + (hadOneBadge ? st::dialogsUnreadPadding : 0);
|
|
|
|
}
|
|
|
|
return availableWidth;
|
|
|
|
}
|
|
|
|
|
2019-04-23 12:29:23 +00:00
|
|
|
void PaintListEntryText(
|
|
|
|
Painter &p,
|
|
|
|
QRect rect,
|
|
|
|
bool active,
|
|
|
|
bool selected,
|
|
|
|
not_null<const Row*> row) {
|
|
|
|
if (rect.isEmpty()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
row->validateListEntryCache();
|
|
|
|
const auto &palette = active
|
|
|
|
? st::dialogsTextPaletteActive
|
|
|
|
: selected
|
|
|
|
? st::dialogsTextPaletteOver
|
|
|
|
: st::dialogsTextPalette;
|
|
|
|
const auto &color = active
|
|
|
|
? st::dialogsTextFgActive
|
|
|
|
: selected
|
|
|
|
? st::dialogsTextFgOver
|
|
|
|
: st::dialogsTextFg;
|
|
|
|
p.setTextPalette(palette);
|
|
|
|
p.setFont(st::dialogsTextFont);
|
|
|
|
p.setPen(color);
|
|
|
|
row->listEntryCache().drawElided(
|
|
|
|
p,
|
|
|
|
rect.left(),
|
|
|
|
rect.top(),
|
|
|
|
rect.width(),
|
|
|
|
rect.height() / st::dialogsTextFont->height);
|
|
|
|
p.restoreTextPalette();
|
|
|
|
}
|
|
|
|
|
2017-12-05 14:07:01 +00:00
|
|
|
enum class Flag {
|
2018-02-14 19:38:01 +00:00
|
|
|
Active = 0x01,
|
|
|
|
Selected = 0x02,
|
2019-04-16 09:29:21 +00:00
|
|
|
SearchResult = 0x04,
|
|
|
|
SavedMessages = 0x08,
|
|
|
|
//FeedSearchResult = 0x10, // #feed
|
2017-12-05 14:07:01 +00:00
|
|
|
};
|
|
|
|
inline constexpr bool is_flag_type(Flag) { return true; }
|
|
|
|
|
2017-01-14 18:50:16 +00:00
|
|
|
template <typename PaintItemCallback, typename PaintCounterCallback>
|
2017-11-05 11:21:30 +00:00
|
|
|
void paintRow(
|
|
|
|
Painter &p,
|
2018-02-22 13:50:56 +00:00
|
|
|
not_null<const RippleRow*> row,
|
2018-01-05 15:57:18 +00:00
|
|
|
not_null<Entry*> entry,
|
2018-02-22 13:50:56 +00:00
|
|
|
Dialogs::Key chat,
|
2018-01-05 15:57:18 +00:00
|
|
|
PeerData *from,
|
2019-03-15 15:15:56 +00:00
|
|
|
const HiddenSenderInfo *hiddenSenderInfo,
|
2017-11-05 11:21:30 +00:00
|
|
|
HistoryItem *item,
|
2018-01-05 15:57:18 +00:00
|
|
|
const Data::Draft *draft,
|
2017-11-05 11:21:30 +00:00
|
|
|
QDateTime date,
|
|
|
|
int fullWidth,
|
2017-12-05 14:07:01 +00:00
|
|
|
base::flags<Flag> flags,
|
2019-02-19 06:57:53 +00:00
|
|
|
crl::time ms,
|
2017-11-05 11:21:30 +00:00
|
|
|
PaintItemCallback &&paintItemCallback,
|
|
|
|
PaintCounterCallback &&paintCounterCallback) {
|
2018-11-15 15:36:04 +00:00
|
|
|
const auto supportMode = Auth().supportMode();
|
|
|
|
if (supportMode) {
|
|
|
|
draft = nullptr;
|
|
|
|
}
|
|
|
|
|
2017-12-05 14:07:01 +00:00
|
|
|
auto active = (flags & Flag::Active);
|
|
|
|
auto selected = (flags & Flag::Selected);
|
|
|
|
auto fullRect = QRect(0, 0, fullWidth, st::dialogsRowHeight);
|
|
|
|
auto bg = active
|
|
|
|
? st::dialogsBgActive
|
|
|
|
: (selected
|
|
|
|
? st::dialogsBgOver
|
|
|
|
: st::dialogsBg);
|
|
|
|
auto ripple = active
|
|
|
|
? st::dialogsRippleBgActive
|
|
|
|
: st::dialogsRippleBg;
|
|
|
|
p.fillRect(fullRect, bg);
|
2019-04-02 09:13:30 +00:00
|
|
|
row->paintRipple(p, 0, 0, fullWidth, &ripple->c);
|
2017-12-05 14:07:01 +00:00
|
|
|
|
|
|
|
if (flags & Flag::SavedMessages) {
|
|
|
|
Ui::EmptyUserpic::PaintSavedMessages(
|
|
|
|
p,
|
|
|
|
st::dialogsPadding.x(),
|
|
|
|
st::dialogsPadding.y(),
|
|
|
|
fullWidth,
|
|
|
|
st::dialogsPhotoSize);
|
2018-01-05 15:57:18 +00:00
|
|
|
} else if (from) {
|
2017-12-05 14:07:01 +00:00
|
|
|
from->paintUserpicLeft(
|
|
|
|
p,
|
|
|
|
st::dialogsPadding.x(),
|
|
|
|
st::dialogsPadding.y(),
|
|
|
|
fullWidth,
|
|
|
|
st::dialogsPhotoSize);
|
2019-03-15 15:15:56 +00:00
|
|
|
} else if (hiddenSenderInfo) {
|
|
|
|
hiddenSenderInfo->userpic.paint(
|
|
|
|
p,
|
|
|
|
st::dialogsPadding.x(),
|
|
|
|
st::dialogsPadding.y(),
|
|
|
|
fullWidth,
|
|
|
|
st::dialogsPhotoSize);
|
2018-01-05 15:57:18 +00:00
|
|
|
} else {
|
|
|
|
entry->paintUserpicLeft(
|
|
|
|
p,
|
|
|
|
st::dialogsPadding.x(),
|
|
|
|
st::dialogsPadding.y(),
|
|
|
|
fullWidth,
|
|
|
|
st::dialogsPhotoSize);
|
2017-12-05 14:07:01 +00:00
|
|
|
}
|
2016-04-09 18:45:55 +00:00
|
|
|
|
2017-12-05 14:07:01 +00:00
|
|
|
auto nameleft = st::dialogsPadding.x()
|
|
|
|
+ st::dialogsPhotoSize
|
|
|
|
+ st::dialogsPhotoPadding;
|
2017-01-14 18:50:16 +00:00
|
|
|
if (fullWidth <= nameleft) {
|
|
|
|
if (!draft && item && !item->isEmpty()) {
|
|
|
|
paintCounterCallback();
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-02-22 13:50:56 +00:00
|
|
|
const auto history = chat.history();
|
2016-12-05 11:01:08 +00:00
|
|
|
auto namewidth = fullWidth - nameleft - st::dialogsPadding.x();
|
2017-12-05 14:07:01 +00:00
|
|
|
auto rectForName = QRect(
|
|
|
|
nameleft,
|
|
|
|
st::dialogsPadding.y() + st::dialogsNameTop,
|
|
|
|
namewidth,
|
|
|
|
st::msgNameFont->height);
|
2016-04-09 18:45:55 +00:00
|
|
|
|
2019-04-18 11:31:30 +00:00
|
|
|
const auto promoted = (history && history->useProxyPromotion())
|
2019-04-15 11:54:03 +00:00
|
|
|
&& !(flags & (Flag::SearchResult/* | Flag::FeedSearchResult*/)); // #feed
|
2018-05-11 14:03:53 +00:00
|
|
|
if (promoted) {
|
2018-05-15 16:38:27 +00:00
|
|
|
const auto text = lang(lng_proxy_sponsor);
|
2019-04-23 12:29:23 +00:00
|
|
|
PaintRowTopRight(p, text, rectForName, active, selected);
|
2019-04-15 11:54:03 +00:00
|
|
|
} else if (from/* && !(flags & Flag::FeedSearchResult)*/) { // #feed
|
2018-02-22 13:50:56 +00:00
|
|
|
if (const auto chatTypeIcon = ChatTypeIcon(from, active, selected)) {
|
2018-01-05 15:57:18 +00:00
|
|
|
chatTypeIcon->paint(p, rectForName.topLeft(), fullWidth);
|
|
|
|
rectForName.setLeft(rectForName.left() + st::dialogsChatTypeSkip);
|
|
|
|
}
|
2019-04-15 11:54:03 +00:00
|
|
|
//} else if (const auto feed = chat.feed()) { // #feed
|
|
|
|
// if (const auto feedTypeIcon = FeedTypeIcon(feed, active, selected)) {
|
|
|
|
// feedTypeIcon->paint(p, rectForName.topLeft(), fullWidth);
|
|
|
|
// rectForName.setLeft(rectForName.left() + st::dialogsChatTypeSkip);
|
|
|
|
// }
|
2016-04-09 18:45:55 +00:00
|
|
|
}
|
2017-12-05 14:07:01 +00:00
|
|
|
auto texttop = st::dialogsPadding.y()
|
|
|
|
+ st::msgNameFont->height
|
|
|
|
+ st::dialogsSkip;
|
2018-11-20 13:34:07 +00:00
|
|
|
if (draft
|
|
|
|
|| (supportMode
|
|
|
|
&& Auth().supportHelper().isOccupiedBySomeone(history))) {
|
2018-05-11 14:03:53 +00:00
|
|
|
if (!promoted) {
|
2019-04-23 12:29:23 +00:00
|
|
|
PaintRowDate(p, date, rectForName, active, selected);
|
2018-05-11 14:03:53 +00:00
|
|
|
}
|
2016-06-03 18:24:27 +00:00
|
|
|
|
2017-01-02 17:11:49 +00:00
|
|
|
auto availableWidth = namewidth;
|
2019-04-18 11:31:30 +00:00
|
|
|
if (entry->isPinnedDialog() && !entry->fixedOnTopIndex()) {
|
2017-01-02 17:11:49 +00:00
|
|
|
auto &icon = (active ? st::dialogsPinnedIconActive : (selected ? st::dialogsPinnedIconOver : st::dialogsPinnedIcon));
|
|
|
|
icon.paint(p, fullWidth - st::dialogsPadding.x() - icon.width(), texttop, fullWidth);
|
|
|
|
availableWidth -= icon.width() + st::dialogsUnreadPadding;
|
|
|
|
}
|
|
|
|
|
2016-06-07 19:59:39 +00:00
|
|
|
p.setFont(st::dialogsTextFont);
|
2016-12-01 19:20:33 +00:00
|
|
|
auto &color = active ? st::dialogsTextFgServiceActive : (selected ? st::dialogsTextFgServiceOver : st::dialogsTextFgService);
|
2018-01-05 15:57:18 +00:00
|
|
|
if (history && !history->paintSendAction(p, nameleft, texttop, availableWidth, fullWidth, color, ms)) {
|
2016-06-03 18:24:27 +00:00
|
|
|
if (history->cloudDraftTextCache.isEmpty()) {
|
2016-06-22 13:39:54 +00:00
|
|
|
auto draftWrapped = textcmdLink(1, lng_dialogs_text_from_wrapped(lt_from, lang(lng_from_draft)));
|
2018-11-15 15:36:04 +00:00
|
|
|
auto draftText = supportMode
|
2018-11-20 13:34:07 +00:00
|
|
|
? textcmdLink(1, Support::ChatOccupiedString(history))
|
2018-11-15 15:36:04 +00:00
|
|
|
: lng_dialogs_text_with_from(lt_from_part, draftWrapped, lt_message, TextUtilities::Clean(draft->textWithTags.text));
|
2017-12-28 13:06:06 +00:00
|
|
|
history->cloudDraftTextCache.setText(st::dialogsTextStyle, draftText, Ui::DialogTextOptions());
|
2016-06-03 18:24:27 +00:00
|
|
|
}
|
2016-11-05 08:36:24 +00:00
|
|
|
p.setPen(active ? st::dialogsTextFgActive : (selected ? st::dialogsTextFgOver : st::dialogsTextFg));
|
2018-11-20 15:36:36 +00:00
|
|
|
if (supportMode) {
|
|
|
|
p.setTextPalette(active ? st::dialogsTextPaletteTakenActive : (selected ? st::dialogsTextPaletteTakenOver : st::dialogsTextPaletteTaken));
|
|
|
|
} else {
|
|
|
|
p.setTextPalette(active ? st::dialogsTextPaletteDraftActive : (selected ? st::dialogsTextPaletteDraftOver : st::dialogsTextPaletteDraft));
|
|
|
|
}
|
2017-01-02 17:11:49 +00:00
|
|
|
history->cloudDraftTextCache.drawElided(p, nameleft, texttop, availableWidth, 1);
|
2016-12-23 13:21:01 +00:00
|
|
|
p.restoreTextPalette();
|
2016-04-09 18:45:55 +00:00
|
|
|
}
|
2016-06-03 18:24:27 +00:00
|
|
|
} else if (!item) {
|
2017-02-16 16:47:50 +00:00
|
|
|
auto availableWidth = namewidth;
|
2019-04-18 11:31:30 +00:00
|
|
|
if (entry->isPinnedDialog() && !entry->fixedOnTopIndex()) {
|
2017-02-16 16:47:50 +00:00
|
|
|
auto &icon = (active ? st::dialogsPinnedIconActive : (selected ? st::dialogsPinnedIconOver : st::dialogsPinnedIcon));
|
|
|
|
icon.paint(p, fullWidth - st::dialogsPadding.x() - icon.width(), texttop, fullWidth);
|
|
|
|
availableWidth -= icon.width() + st::dialogsUnreadPadding;
|
|
|
|
}
|
|
|
|
|
2016-12-01 19:20:33 +00:00
|
|
|
auto &color = active ? st::dialogsTextFgServiceActive : (selected ? st::dialogsTextFgServiceOver : st::dialogsTextFgService);
|
2016-06-07 19:59:39 +00:00
|
|
|
p.setFont(st::dialogsTextFont);
|
2018-01-05 15:57:18 +00:00
|
|
|
if (history && !history->paintSendAction(p, nameleft, texttop, availableWidth, fullWidth, color, ms)) {
|
2017-01-14 18:50:16 +00:00
|
|
|
// Empty history
|
2016-04-09 18:45:55 +00:00
|
|
|
}
|
2016-06-08 19:14:17 +00:00
|
|
|
} else if (!item->isEmpty()) {
|
2018-05-11 14:03:53 +00:00
|
|
|
if (!promoted) {
|
2019-04-23 12:29:23 +00:00
|
|
|
PaintRowDate(p, date, rectForName, active, selected);
|
2018-05-11 14:03:53 +00:00
|
|
|
}
|
2016-04-09 18:45:55 +00:00
|
|
|
|
2017-11-05 11:21:30 +00:00
|
|
|
paintItemCallback(nameleft, namewidth);
|
2019-04-18 11:31:30 +00:00
|
|
|
} else if (entry->isPinnedDialog() && !entry->fixedOnTopIndex()) {
|
2017-02-16 16:47:50 +00:00
|
|
|
auto availableWidth = namewidth;
|
|
|
|
auto &icon = (active ? st::dialogsPinnedIconActive : (selected ? st::dialogsPinnedIconOver : st::dialogsPinnedIcon));
|
|
|
|
icon.paint(p, fullWidth - st::dialogsPadding.x() - icon.width(), texttop, fullWidth);
|
|
|
|
availableWidth -= icon.width() + st::dialogsUnreadPadding;
|
2016-09-30 12:52:03 +00:00
|
|
|
}
|
2018-01-30 12:13:46 +00:00
|
|
|
auto sendStateIcon = [&]() -> const style::icon* {
|
2016-09-30 12:52:03 +00:00
|
|
|
if (draft) {
|
|
|
|
if (draft->saveRequestId) {
|
2018-01-30 12:13:46 +00:00
|
|
|
return &(active
|
|
|
|
? st::dialogsSendingIconActive
|
|
|
|
: (selected
|
|
|
|
? st::dialogsSendingIconOver
|
|
|
|
: st::dialogsSendingIcon));
|
2016-09-30 12:52:03 +00:00
|
|
|
}
|
|
|
|
} else if (item && !item->isEmpty() && item->needCheck()) {
|
2016-04-09 20:41:20 +00:00
|
|
|
if (item->id > 0) {
|
|
|
|
if (item->unread()) {
|
2018-01-30 12:13:46 +00:00
|
|
|
return &(active
|
|
|
|
? st::dialogsSentIconActive
|
|
|
|
: (selected
|
|
|
|
? st::dialogsSentIconOver
|
|
|
|
: st::dialogsSentIcon));
|
2016-04-09 18:45:55 +00:00
|
|
|
}
|
2018-01-30 12:13:46 +00:00
|
|
|
return &(active
|
|
|
|
? st::dialogsReceivedIconActive
|
|
|
|
: (selected
|
|
|
|
? st::dialogsReceivedIconOver
|
|
|
|
: st::dialogsReceivedIcon));
|
2016-04-09 18:45:55 +00:00
|
|
|
}
|
2018-01-30 12:13:46 +00:00
|
|
|
return &(active
|
|
|
|
? st::dialogsSendingIconActive
|
|
|
|
: (selected
|
|
|
|
? st::dialogsSendingIconOver
|
|
|
|
: st::dialogsSendingIcon));
|
2016-04-09 20:41:20 +00:00
|
|
|
}
|
2016-09-30 12:52:03 +00:00
|
|
|
return nullptr;
|
2018-01-30 12:13:46 +00:00
|
|
|
}();
|
|
|
|
if (sendStateIcon && history) {
|
2016-09-30 12:52:03 +00:00
|
|
|
rectForName.setWidth(rectForName.width() - st::dialogsSendStateSkip);
|
2016-12-05 11:01:08 +00:00
|
|
|
sendStateIcon->paint(p, rectForName.topLeft() + QPoint(rectForName.width(), 0), fullWidth);
|
2016-04-09 20:41:20 +00:00
|
|
|
}
|
|
|
|
|
2017-12-05 14:07:01 +00:00
|
|
|
const auto nameFg = active
|
|
|
|
? st::dialogsNameFgActive
|
|
|
|
: (selected
|
|
|
|
? st::dialogsNameFgOver
|
|
|
|
: st::dialogsNameFg);
|
|
|
|
p.setPen(nameFg);
|
|
|
|
if (flags & Flag::SavedMessages) {
|
|
|
|
p.setFont(st::msgNameFont);
|
|
|
|
auto text = lang(lng_saved_messages);
|
|
|
|
auto textWidth = st::msgNameFont->width(text);
|
|
|
|
if (textWidth > rectForName.width()) {
|
|
|
|
text = st::msgNameFont->elided(text, rectForName.width());
|
|
|
|
}
|
|
|
|
p.drawTextLeft(rectForName.left(), rectForName.top(), fullWidth, text);
|
2018-01-05 15:57:18 +00:00
|
|
|
} else if (from) {
|
2017-12-05 14:07:01 +00:00
|
|
|
if (!(flags & Flag::SearchResult) && from->isVerified()) {
|
|
|
|
auto icon = &(active ? st::dialogsVerifiedIconActive : (selected ? st::dialogsVerifiedIconOver : st::dialogsVerifiedIcon));
|
|
|
|
rectForName.setWidth(rectForName.width() - icon->width());
|
|
|
|
icon->paint(p, rectForName.topLeft() + QPoint(qMin(from->dialogName().maxWidth(), rectForName.width()), 0), fullWidth);
|
|
|
|
}
|
|
|
|
from->dialogName().drawElided(p, rectForName.left(), rectForName.top(), rectForName.width());
|
2019-03-15 15:15:56 +00:00
|
|
|
} else if (hiddenSenderInfo) {
|
|
|
|
hiddenSenderInfo->nameText.drawElided(p, rectForName.left(), rectForName.top(), rectForName.width());
|
2018-01-05 15:57:18 +00:00
|
|
|
} else {
|
|
|
|
p.setFont(st::msgNameFont);
|
2019-01-15 11:57:45 +00:00
|
|
|
auto text = entry->chatListName(); // TODO feed name with emoji
|
2018-01-05 15:57:18 +00:00
|
|
|
auto textWidth = st::msgNameFont->width(text);
|
|
|
|
if (textWidth > rectForName.width()) {
|
|
|
|
text = st::msgNameFont->elided(text, rectForName.width());
|
|
|
|
}
|
|
|
|
p.drawTextLeft(rectForName.left(), rectForName.top(), fullWidth, text);
|
2016-04-09 20:41:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-21 15:58:07 +00:00
|
|
|
struct UnreadBadgeSizeData {
|
2016-04-09 20:41:20 +00:00
|
|
|
QImage circle;
|
2016-11-07 11:24:19 +00:00
|
|
|
QPixmap left[6], right[6];
|
2016-06-21 15:58:07 +00:00
|
|
|
};
|
|
|
|
class UnreadBadgeStyleData : public Data::AbstractStructure {
|
|
|
|
public:
|
|
|
|
UnreadBadgeSizeData sizes[UnreadBadgeSizesCount];
|
2016-12-23 13:21:01 +00:00
|
|
|
style::color bg[6] = {
|
|
|
|
st::dialogsUnreadBg,
|
|
|
|
st::dialogsUnreadBgOver,
|
|
|
|
st::dialogsUnreadBgActive,
|
|
|
|
st::dialogsUnreadBgMuted,
|
|
|
|
st::dialogsUnreadBgMutedOver,
|
|
|
|
st::dialogsUnreadBgMutedActive
|
2016-11-03 10:33:57 +00:00
|
|
|
};
|
2016-04-09 20:41:20 +00:00
|
|
|
};
|
2016-06-09 11:51:24 +00:00
|
|
|
Data::GlobalStructurePointer<UnreadBadgeStyleData> unreadBadgeStyle;
|
2016-04-09 20:41:20 +00:00
|
|
|
|
2016-06-21 15:58:07 +00:00
|
|
|
void createCircleMask(UnreadBadgeSizeData *data, int size) {
|
|
|
|
if (!data->circle.isNull()) return;
|
2016-04-09 20:41:20 +00:00
|
|
|
|
2016-06-21 15:58:07 +00:00
|
|
|
data->circle = style::createCircleMask(size);
|
2016-04-09 20:41:20 +00:00
|
|
|
}
|
|
|
|
|
2016-12-23 13:21:01 +00:00
|
|
|
QImage colorizeCircleHalf(UnreadBadgeSizeData *data, int size, int half, int xoffset, style::color color) {
|
2016-06-21 15:58:07 +00:00
|
|
|
auto result = style::colorizeImage(data->circle, color, QRect(xoffset, 0, half, size));
|
2016-04-09 20:41:20 +00:00
|
|
|
result.setDevicePixelRatio(cRetinaFactor());
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2016-06-03 12:45:33 +00:00
|
|
|
} // namepsace
|
|
|
|
|
2018-02-22 13:50:56 +00:00
|
|
|
const style::icon *ChatTypeIcon(
|
|
|
|
not_null<PeerData*> peer,
|
|
|
|
bool active,
|
|
|
|
bool selected) {
|
|
|
|
if (peer->isChat() || peer->isMegagroup()) {
|
|
|
|
return &(active
|
|
|
|
? st::dialogsChatIconActive
|
|
|
|
: (selected ? st::dialogsChatIconOver : st::dialogsChatIcon));
|
2016-09-30 12:52:03 +00:00
|
|
|
} else if (peer->isChannel()) {
|
2018-02-22 13:50:56 +00:00
|
|
|
return &(active
|
|
|
|
? st::dialogsChannelIconActive
|
|
|
|
: (selected
|
|
|
|
? st::dialogsChannelIconOver
|
|
|
|
: st::dialogsChannelIcon));
|
2019-01-23 16:15:21 +00:00
|
|
|
} else if (const auto user = peer->asUser()) {
|
2019-03-12 10:36:33 +00:00
|
|
|
if (ShowUserBotIcon(user)) {
|
2019-01-23 16:15:21 +00:00
|
|
|
return &(active
|
|
|
|
? st::dialogsBotIconActive
|
|
|
|
: (selected
|
|
|
|
? st::dialogsBotIconOver
|
|
|
|
: st::dialogsBotIcon));
|
|
|
|
}
|
2016-09-30 12:52:03 +00:00
|
|
|
}
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2019-04-15 11:54:03 +00:00
|
|
|
//const style::icon *FeedTypeIcon( // #feed
|
|
|
|
// not_null<Data::Feed*> feed,
|
|
|
|
// bool active,
|
|
|
|
// bool selected) {
|
|
|
|
// return &(active ? st::dialogsFeedIconActive
|
|
|
|
// : (selected ? st::dialogsFeedIconOver : st::dialogsFeedIcon));
|
|
|
|
//}
|
|
|
|
//
|
2016-06-21 15:58:07 +00:00
|
|
|
void paintUnreadBadge(Painter &p, const QRect &rect, const UnreadBadgeStyle &st) {
|
2017-08-17 09:06:26 +00:00
|
|
|
Assert(rect.height() == st.size);
|
2016-06-21 15:58:07 +00:00
|
|
|
|
2016-11-07 11:24:19 +00:00
|
|
|
int index = (st.muted ? 0x03 : 0x00) + (st.active ? 0x02 : (st.selected ? 0x01 : 0x00));
|
2016-06-21 15:58:07 +00:00
|
|
|
int size = st.size, sizehalf = size / 2;
|
2016-04-09 20:41:20 +00:00
|
|
|
|
|
|
|
unreadBadgeStyle.createIfNull();
|
2016-06-21 15:58:07 +00:00
|
|
|
auto badgeData = unreadBadgeStyle->sizes;
|
|
|
|
if (st.sizeId > 0) {
|
2017-08-17 09:06:26 +00:00
|
|
|
Assert(st.sizeId < UnreadBadgeSizesCount);
|
2016-06-21 15:58:07 +00:00
|
|
|
badgeData = &unreadBadgeStyle->sizes[st.sizeId];
|
|
|
|
}
|
2016-11-03 10:33:57 +00:00
|
|
|
auto bg = unreadBadgeStyle->bg[index];
|
2016-06-21 15:58:07 +00:00
|
|
|
if (badgeData->left[index].isNull()) {
|
2016-04-09 20:41:20 +00:00
|
|
|
int imgsize = size * cIntRetinaFactor(), imgsizehalf = sizehalf * cIntRetinaFactor();
|
2016-06-21 15:58:07 +00:00
|
|
|
createCircleMask(badgeData, size);
|
2016-12-23 13:21:01 +00:00
|
|
|
badgeData->left[index] = App::pixmapFromImageInPlace(colorizeCircleHalf(badgeData, imgsize, imgsizehalf, 0, bg));
|
|
|
|
badgeData->right[index] = App::pixmapFromImageInPlace(colorizeCircleHalf(badgeData, imgsize, imgsizehalf, imgsize - imgsizehalf, bg));
|
2016-04-09 20:41:20 +00:00
|
|
|
}
|
2016-04-09 18:45:55 +00:00
|
|
|
|
2016-04-09 20:41:20 +00:00
|
|
|
int bar = rect.width() - 2 * sizehalf;
|
2016-06-21 15:58:07 +00:00
|
|
|
p.drawPixmap(rect.x(), rect.y(), badgeData->left[index]);
|
2016-04-09 20:41:20 +00:00
|
|
|
if (bar) {
|
2016-12-23 13:21:01 +00:00
|
|
|
p.fillRect(rect.x() + sizehalf, rect.y(), bar, rect.height(), bg);
|
2016-04-09 20:41:20 +00:00
|
|
|
}
|
2016-06-21 15:58:07 +00:00
|
|
|
p.drawPixmap(rect.x() + sizehalf + bar, rect.y(), badgeData->right[index]);
|
2016-04-09 20:41:20 +00:00
|
|
|
}
|
|
|
|
|
2016-06-21 15:58:07 +00:00
|
|
|
UnreadBadgeStyle::UnreadBadgeStyle()
|
|
|
|
: align(style::al_right)
|
|
|
|
, active(false)
|
2016-11-07 11:24:19 +00:00
|
|
|
, selected(false)
|
2016-06-21 15:58:07 +00:00
|
|
|
, muted(false)
|
|
|
|
, size(st::dialogsUnreadHeight)
|
2016-11-22 09:48:13 +00:00
|
|
|
, padding(st::dialogsUnreadPadding)
|
2016-06-21 15:58:07 +00:00
|
|
|
, sizeId(UnreadBadgeInDialogs)
|
|
|
|
, font(st::dialogsUnreadFont) {
|
|
|
|
}
|
|
|
|
|
2018-10-09 15:36:06 +00:00
|
|
|
void paintUnreadCount(
|
|
|
|
Painter &p,
|
|
|
|
const QString &text,
|
|
|
|
int x,
|
|
|
|
int y,
|
|
|
|
const UnreadBadgeStyle &st,
|
|
|
|
int *outUnreadWidth) {
|
2016-06-21 15:58:07 +00:00
|
|
|
int unreadWidth = st.font->width(text);
|
2016-11-22 09:48:13 +00:00
|
|
|
int unreadRectWidth = unreadWidth + 2 * st.padding;
|
2016-06-21 15:58:07 +00:00
|
|
|
int unreadRectHeight = st.size;
|
2016-04-11 10:59:01 +00:00
|
|
|
accumulate_max(unreadRectWidth, unreadRectHeight);
|
|
|
|
|
2016-06-03 12:45:33 +00:00
|
|
|
int unreadRectLeft = x;
|
2016-06-21 15:58:07 +00:00
|
|
|
if ((st.align & Qt::AlignHorizontal_Mask) & style::al_center) {
|
2016-06-03 12:45:33 +00:00
|
|
|
unreadRectLeft = (x - unreadRectWidth) / 2;
|
2016-06-21 15:58:07 +00:00
|
|
|
} else if ((st.align & Qt::AlignHorizontal_Mask) & style::al_right) {
|
2016-06-03 12:45:33 +00:00
|
|
|
unreadRectLeft = x - unreadRectWidth;
|
|
|
|
}
|
|
|
|
int unreadRectTop = y;
|
|
|
|
if (outUnreadWidth) {
|
|
|
|
*outUnreadWidth = unreadRectWidth;
|
2016-04-11 10:59:01 +00:00
|
|
|
}
|
|
|
|
|
2016-06-21 15:58:07 +00:00
|
|
|
paintUnreadBadge(p, QRect(unreadRectLeft, unreadRectTop, unreadRectWidth, unreadRectHeight), st);
|
2016-04-11 10:59:01 +00:00
|
|
|
|
2016-11-22 09:48:13 +00:00
|
|
|
auto textTop = st.textTop ? st.textTop : (unreadRectHeight - st.font->height) / 2;
|
2016-06-21 15:58:07 +00:00
|
|
|
p.setFont(st.font);
|
2016-11-07 11:24:19 +00:00
|
|
|
p.setPen(st.active ? st::dialogsUnreadFgActive : (st.selected ? st::dialogsUnreadFgOver : st::dialogsUnreadFg));
|
2016-11-22 09:48:13 +00:00
|
|
|
p.drawText(unreadRectLeft + (unreadRectWidth - unreadWidth) / 2, unreadRectTop + textTop + st.font->ascent, text);
|
2016-04-11 10:59:01 +00:00
|
|
|
}
|
|
|
|
|
2017-12-05 14:07:01 +00:00
|
|
|
void RowPainter::paint(
|
|
|
|
Painter &p,
|
2018-01-05 15:57:18 +00:00
|
|
|
not_null<const Row*> row,
|
2017-12-05 14:07:01 +00:00
|
|
|
int fullWidth,
|
|
|
|
bool active,
|
|
|
|
bool selected,
|
2019-02-19 06:57:53 +00:00
|
|
|
crl::time ms) {
|
2018-01-05 15:57:18 +00:00
|
|
|
const auto entry = row->entry();
|
|
|
|
const auto history = row->history();
|
2018-01-13 12:45:11 +00:00
|
|
|
const auto peer = history ? history->peer.get() : nullptr;
|
2018-01-05 15:57:18 +00:00
|
|
|
const auto unreadCount = entry->chatListUnreadCount();
|
2018-06-26 18:03:45 +00:00
|
|
|
const auto unreadMark = entry->chatListUnreadMark();
|
2018-01-05 15:57:18 +00:00
|
|
|
const auto unreadMuted = entry->chatListMutedBadge();
|
2019-01-15 11:57:45 +00:00
|
|
|
const auto item = entry->chatListMessage();
|
2018-01-05 15:57:18 +00:00
|
|
|
const auto cloudDraft = [&]() -> const Data::Draft*{
|
2018-06-26 18:03:45 +00:00
|
|
|
if (history && (!item || (!unreadCount && !unreadMark))) {
|
2018-01-05 15:57:18 +00:00
|
|
|
// Draw item, if there are unread messages.
|
|
|
|
if (const auto draft = history->cloudDraft()) {
|
|
|
|
if (!Data::draftIsNull(draft)) {
|
|
|
|
return draft;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nullptr;
|
|
|
|
}();
|
2019-04-23 12:29:23 +00:00
|
|
|
const auto displayDate = [&] {
|
2016-06-13 18:42:25 +00:00
|
|
|
if (item) {
|
|
|
|
if (cloudDraft) {
|
2018-02-03 19:52:35 +00:00
|
|
|
return (item->date() > cloudDraft->date)
|
|
|
|
? ItemDateTime(item)
|
|
|
|
: ParseDateTime(cloudDraft->date);
|
2016-04-09 18:45:55 +00:00
|
|
|
}
|
2018-02-03 19:52:35 +00:00
|
|
|
return ItemDateTime(item);
|
2016-06-13 18:42:25 +00:00
|
|
|
}
|
2018-02-03 19:52:35 +00:00
|
|
|
return cloudDraft ? ParseDateTime(cloudDraft->date) : QDateTime();
|
2018-01-05 15:57:18 +00:00
|
|
|
}();
|
2018-07-12 19:25:10 +00:00
|
|
|
const auto displayMentionBadge = history
|
|
|
|
? history->hasUnreadMentions()
|
|
|
|
: false;
|
|
|
|
const auto displayUnreadCounter = [&] {
|
|
|
|
if (displayMentionBadge
|
|
|
|
&& unreadCount == 1
|
|
|
|
&& item
|
2018-12-26 10:28:24 +00:00
|
|
|
&& item->isUnreadMention()) {
|
2018-07-12 19:25:10 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return (unreadCount > 0);
|
|
|
|
}();
|
|
|
|
const auto displayUnreadMark = !displayUnreadCounter
|
|
|
|
&& !displayMentionBadge
|
|
|
|
&& history
|
|
|
|
&& unreadMark;
|
|
|
|
const auto displayPinnedIcon = !displayUnreadCounter
|
|
|
|
&& !displayMentionBadge
|
|
|
|
&& !displayUnreadMark
|
2019-04-18 11:31:30 +00:00
|
|
|
&& entry->isPinnedDialog()
|
|
|
|
&& !entry->fixedOnTopIndex();
|
2016-06-13 18:42:25 +00:00
|
|
|
|
2018-01-05 15:57:18 +00:00
|
|
|
const auto from = history
|
|
|
|
? (history->peer->migrateTo()
|
|
|
|
? history->peer->migrateTo()
|
2018-01-13 12:45:11 +00:00
|
|
|
: history->peer.get())
|
2018-01-05 15:57:18 +00:00
|
|
|
: nullptr;
|
2017-12-07 14:27:59 +00:00
|
|
|
const auto flags = (active ? Flag::Active : Flag(0))
|
|
|
|
| (selected ? Flag::Selected : Flag(0))
|
2018-01-05 15:57:18 +00:00
|
|
|
| (peer && peer->isSelf() ? Flag::SavedMessages : Flag(0));
|
|
|
|
const auto paintItemCallback = [&](int nameleft, int namewidth) {
|
2018-10-09 15:36:06 +00:00
|
|
|
const auto texttop = st::dialogsPadding.y()
|
|
|
|
+ st::msgNameFont->height
|
|
|
|
+ st::dialogsSkip;
|
|
|
|
const auto availableWidth = PaintWideCounter(
|
|
|
|
p,
|
|
|
|
texttop,
|
|
|
|
namewidth,
|
|
|
|
fullWidth,
|
|
|
|
displayUnreadCounter,
|
|
|
|
displayUnreadMark,
|
|
|
|
displayMentionBadge,
|
|
|
|
displayPinnedIcon,
|
|
|
|
unreadCount,
|
|
|
|
active,
|
|
|
|
selected,
|
|
|
|
unreadMuted);
|
2018-01-05 15:57:18 +00:00
|
|
|
const auto &color = active
|
2017-11-05 11:21:30 +00:00
|
|
|
? st::dialogsTextFgServiceActive
|
|
|
|
: (selected
|
|
|
|
? st::dialogsTextFgServiceOver
|
|
|
|
: st::dialogsTextFgService);
|
2019-04-23 12:29:23 +00:00
|
|
|
const auto itemRect = QRect(
|
2017-11-05 11:21:30 +00:00
|
|
|
nameleft,
|
|
|
|
texttop,
|
|
|
|
availableWidth,
|
2019-04-23 12:29:23 +00:00
|
|
|
st::dialogsTextFont->height);
|
|
|
|
const auto actionWasPainted = history ? history->paintSendAction(
|
|
|
|
p,
|
|
|
|
itemRect.x(),
|
|
|
|
itemRect.y(),
|
|
|
|
itemRect.width(),
|
2017-11-05 11:21:30 +00:00
|
|
|
fullWidth,
|
|
|
|
color,
|
2018-01-05 15:57:18 +00:00
|
|
|
ms) : false;
|
2019-04-23 12:29:23 +00:00
|
|
|
if (const auto folder = row->folder()) {
|
|
|
|
PaintListEntryText(p, itemRect, active, selected, row);
|
|
|
|
} else if (!actionWasPainted) {
|
2017-09-05 17:21:56 +00:00
|
|
|
item->drawInDialog(
|
|
|
|
p,
|
2017-11-05 11:21:30 +00:00
|
|
|
itemRect,
|
2017-09-05 17:21:56 +00:00
|
|
|
active,
|
|
|
|
selected,
|
|
|
|
HistoryItem::DrawInDialog::Normal,
|
2018-01-05 15:57:18 +00:00
|
|
|
entry->textCachedFor,
|
|
|
|
entry->lastItemTextCache);
|
2016-04-09 18:45:55 +00:00
|
|
|
}
|
2017-11-05 11:21:30 +00:00
|
|
|
};
|
2018-01-05 15:57:18 +00:00
|
|
|
const auto paintCounterCallback = [&] {
|
2018-10-09 15:36:06 +00:00
|
|
|
PaintNarrowCounter(
|
|
|
|
p,
|
|
|
|
displayUnreadCounter,
|
|
|
|
displayUnreadMark,
|
|
|
|
displayMentionBadge,
|
|
|
|
unreadCount,
|
|
|
|
active,
|
|
|
|
unreadMuted);
|
2017-11-05 11:21:30 +00:00
|
|
|
};
|
|
|
|
paintRow(
|
|
|
|
p,
|
|
|
|
row,
|
2018-01-05 15:57:18 +00:00
|
|
|
entry,
|
2018-02-22 13:50:56 +00:00
|
|
|
row->key(),
|
2017-11-05 11:21:30 +00:00
|
|
|
from,
|
2019-03-15 15:15:56 +00:00
|
|
|
nullptr,
|
2017-11-05 11:21:30 +00:00
|
|
|
item,
|
|
|
|
cloudDraft,
|
2018-01-05 15:57:18 +00:00
|
|
|
displayDate,
|
2017-11-05 11:21:30 +00:00
|
|
|
fullWidth,
|
2017-12-05 14:07:01 +00:00
|
|
|
flags,
|
2017-11-05 11:21:30 +00:00
|
|
|
ms,
|
|
|
|
paintItemCallback,
|
|
|
|
paintCounterCallback);
|
2016-04-09 18:45:55 +00:00
|
|
|
}
|
|
|
|
|
2017-12-05 14:07:01 +00:00
|
|
|
void RowPainter::paint(
|
|
|
|
Painter &p,
|
2018-01-05 15:57:18 +00:00
|
|
|
not_null<const FakeRow*> row,
|
2017-12-05 14:07:01 +00:00
|
|
|
int fullWidth,
|
|
|
|
bool active,
|
|
|
|
bool selected,
|
2019-02-19 06:57:53 +00:00
|
|
|
crl::time ms,
|
2018-10-09 15:36:06 +00:00
|
|
|
bool displayUnreadInfo) {
|
2016-04-09 18:45:55 +00:00
|
|
|
auto item = row->item();
|
|
|
|
auto history = item->history();
|
2017-12-05 14:07:01 +00:00
|
|
|
auto cloudDraft = nullptr;
|
2017-12-21 12:29:01 +00:00
|
|
|
const auto from = [&] {
|
2018-02-14 19:38:01 +00:00
|
|
|
if (const auto searchChat = row->searchInChat()) {
|
|
|
|
if (const auto peer = searchChat.peer()) {
|
|
|
|
if (peer->isSelf()) {
|
2019-03-15 15:15:56 +00:00
|
|
|
return item->senderOriginal();
|
2018-02-14 19:38:01 +00:00
|
|
|
} else if (!peer->isChannel() || peer->isMegagroup()) {
|
|
|
|
return item->from().get();
|
|
|
|
}
|
2017-09-05 17:21:56 +00:00
|
|
|
}
|
|
|
|
}
|
2018-01-13 12:45:11 +00:00
|
|
|
return history->peer->migrateTo()
|
|
|
|
? history->peer->migrateTo()
|
|
|
|
: history->peer.get();
|
2017-09-05 17:21:56 +00:00
|
|
|
}();
|
2019-03-15 15:15:56 +00:00
|
|
|
const auto hiddenSenderInfo = [&]() -> const HiddenSenderInfo* {
|
|
|
|
if (const auto searchChat = row->searchInChat()) {
|
|
|
|
if (const auto peer = searchChat.peer()) {
|
|
|
|
if (peer->isSelf()) {
|
|
|
|
return item->hiddenForwardedInfo();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nullptr;
|
|
|
|
}();
|
2017-12-21 12:29:01 +00:00
|
|
|
const auto drawInDialogWay = [&] {
|
2018-02-14 19:38:01 +00:00
|
|
|
if (const auto searchChat = row->searchInChat()) {
|
|
|
|
if (const auto peer = searchChat.peer()) {
|
|
|
|
if (!peer->isChannel() || peer->isMegagroup()) {
|
|
|
|
return HistoryItem::DrawInDialog::WithoutSender;
|
|
|
|
}
|
2017-11-05 11:21:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return HistoryItem::DrawInDialog::Normal;
|
|
|
|
}();
|
2018-10-09 15:36:06 +00:00
|
|
|
|
|
|
|
const auto unreadCount = displayUnreadInfo
|
|
|
|
? history->chatListUnreadCount()
|
|
|
|
: 0;
|
|
|
|
const auto unreadMark = displayUnreadInfo
|
|
|
|
&& history->chatListUnreadMark();
|
|
|
|
const auto unreadMuted = history->chatListMutedBadge();
|
|
|
|
const auto displayMentionBadge = displayUnreadInfo
|
|
|
|
&& history->hasUnreadMentions();
|
|
|
|
const auto displayUnreadCounter = (unreadCount > 0);
|
|
|
|
const auto displayUnreadMark = !displayUnreadCounter
|
|
|
|
&& !displayMentionBadge
|
|
|
|
&& unreadMark;
|
|
|
|
const auto displayPinnedIcon = false;
|
|
|
|
|
2017-12-21 12:29:01 +00:00
|
|
|
const auto paintItemCallback = [&](int nameleft, int namewidth) {
|
2018-10-09 15:36:06 +00:00
|
|
|
const auto texttop = st::dialogsPadding.y()
|
|
|
|
+ st::msgNameFont->height
|
|
|
|
+ st::dialogsSkip;
|
|
|
|
const auto availableWidth = PaintWideCounter(
|
|
|
|
p,
|
|
|
|
texttop,
|
|
|
|
namewidth,
|
|
|
|
fullWidth,
|
|
|
|
displayUnreadCounter,
|
|
|
|
displayUnreadMark,
|
|
|
|
displayMentionBadge,
|
|
|
|
displayPinnedIcon,
|
|
|
|
unreadCount,
|
|
|
|
active,
|
|
|
|
selected,
|
|
|
|
unreadMuted);
|
|
|
|
|
|
|
|
const auto itemRect = QRect(
|
|
|
|
nameleft,
|
|
|
|
texttop,
|
|
|
|
availableWidth,
|
|
|
|
st::dialogsTextFont->height);
|
2017-09-05 17:21:56 +00:00
|
|
|
item->drawInDialog(
|
|
|
|
p,
|
2018-10-09 15:36:06 +00:00
|
|
|
itemRect,
|
2017-09-05 17:21:56 +00:00
|
|
|
active,
|
|
|
|
selected,
|
2017-11-05 11:21:30 +00:00
|
|
|
drawInDialogWay,
|
2017-09-05 17:21:56 +00:00
|
|
|
row->_cacheFor,
|
|
|
|
row->_cache);
|
2017-11-05 11:21:30 +00:00
|
|
|
};
|
2018-10-09 15:36:06 +00:00
|
|
|
const auto paintCounterCallback = [&] {
|
|
|
|
PaintNarrowCounter(
|
|
|
|
p,
|
|
|
|
displayUnreadCounter,
|
|
|
|
displayUnreadMark,
|
|
|
|
displayMentionBadge,
|
|
|
|
unreadCount,
|
|
|
|
active,
|
|
|
|
unreadMuted);
|
|
|
|
};
|
2017-12-21 12:29:01 +00:00
|
|
|
const auto showSavedMessages = history->peer->isSelf()
|
2018-02-14 19:38:01 +00:00
|
|
|
&& !row->searchInChat();
|
2017-12-05 14:07:01 +00:00
|
|
|
const auto flags = (active ? Flag::Active : Flag(0))
|
|
|
|
| (selected ? Flag::Selected : Flag(0))
|
2017-12-21 12:29:01 +00:00
|
|
|
| Flag::SearchResult
|
2019-04-15 11:54:03 +00:00
|
|
|
| (showSavedMessages ? Flag::SavedMessages : Flag(0))/* // #feed
|
|
|
|
| (row->searchInChat().feed() ? Flag::FeedSearchResult : Flag(0))*/;
|
2017-11-05 11:21:30 +00:00
|
|
|
paintRow(
|
|
|
|
p,
|
|
|
|
row,
|
|
|
|
history,
|
2018-01-05 15:57:18 +00:00
|
|
|
history,
|
2017-11-05 11:21:30 +00:00
|
|
|
from,
|
2019-03-15 15:15:56 +00:00
|
|
|
hiddenSenderInfo,
|
2017-11-05 11:21:30 +00:00
|
|
|
item,
|
2017-12-05 14:07:01 +00:00
|
|
|
cloudDraft,
|
2018-02-03 19:52:35 +00:00
|
|
|
ItemDateTime(item),
|
2017-11-05 11:21:30 +00:00
|
|
|
fullWidth,
|
2017-12-05 14:07:01 +00:00
|
|
|
flags,
|
2017-11-05 11:21:30 +00:00
|
|
|
ms,
|
|
|
|
paintItemCallback,
|
|
|
|
paintCounterCallback);
|
2016-04-09 20:41:20 +00:00
|
|
|
}
|
2016-04-09 18:45:55 +00:00
|
|
|
|
2016-12-05 08:45:56 +00:00
|
|
|
QRect RowPainter::sendActionAnimationRect(int animationWidth, int animationHeight, int fullWidth, bool textUpdated) {
|
|
|
|
auto nameleft = st::dialogsPadding.x() + st::dialogsPhotoSize + st::dialogsPhotoPadding;
|
|
|
|
auto namewidth = fullWidth - nameleft - st::dialogsPadding.x();
|
|
|
|
auto texttop = st::dialogsPadding.y() + st::msgNameFont->height + st::dialogsSkip;
|
|
|
|
return QRect(nameleft, texttop, textUpdated ? namewidth : animationWidth, animationHeight);
|
|
|
|
}
|
|
|
|
|
2019-04-16 09:29:21 +00:00
|
|
|
void paintImportantSwitch(Painter &p, Mode current, int fullWidth, bool selected) {
|
2016-12-05 11:01:08 +00:00
|
|
|
p.fillRect(0, 0, fullWidth, st::dialogsImportantBarHeight, selected ? st::dialogsBgOver : st::dialogsBg);
|
2016-04-11 10:59:01 +00:00
|
|
|
|
|
|
|
p.setFont(st::semiboldFont);
|
2016-10-31 12:29:26 +00:00
|
|
|
p.setPen(st::dialogsNameFg);
|
2016-04-11 10:59:01 +00:00
|
|
|
|
2018-12-04 10:32:06 +00:00
|
|
|
const auto unreadTop = (st::dialogsImportantBarHeight - st::dialogsUnreadHeight) / 2;
|
|
|
|
const auto mutedHidden = (current == Dialogs::Mode::Important);
|
|
|
|
const auto text = lang(mutedHidden
|
|
|
|
? lng_dialogs_show_all_chats
|
|
|
|
: lng_dialogs_hide_muted_chats);
|
|
|
|
const auto textBaseline = unreadTop
|
|
|
|
+ (st::dialogsUnreadHeight - st::dialogsUnreadFont->height) / 2
|
|
|
|
+ st::dialogsUnreadFont->ascent;
|
2016-06-07 19:59:39 +00:00
|
|
|
p.drawText(st::dialogsPadding.x(), textBaseline, text);
|
2016-04-11 10:59:01 +00:00
|
|
|
|
2018-12-04 10:32:06 +00:00
|
|
|
if (!mutedHidden) {
|
|
|
|
return;
|
|
|
|
}
|
2019-01-03 12:36:01 +00:00
|
|
|
if (const auto unread = Auth().data().unreadOnlyMutedBadge()) {
|
2018-12-04 10:32:06 +00:00
|
|
|
const auto unreadRight = fullWidth - st::dialogsPadding.x();
|
|
|
|
UnreadBadgeStyle st;
|
|
|
|
st.muted = true;
|
|
|
|
paintUnreadCount(
|
|
|
|
p,
|
|
|
|
QString::number(unread),
|
|
|
|
unreadRight,
|
|
|
|
unreadTop,
|
|
|
|
st,
|
|
|
|
nullptr);
|
2016-04-11 10:59:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-31 13:34:41 +00:00
|
|
|
void clearUnreadBadgesCache() {
|
|
|
|
if (unreadBadgeStyle) {
|
|
|
|
for (auto &data : unreadBadgeStyle->sizes) {
|
|
|
|
for (auto &left : data.left) {
|
|
|
|
left = QPixmap();
|
|
|
|
}
|
|
|
|
for (auto &right : data.right) {
|
|
|
|
right = QPixmap();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-04-09 18:45:55 +00:00
|
|
|
} // namespace Layout
|
|
|
|
} // namespace Dialogs
|