tdesktop/Telegram/SourceFiles/dialogs/ui/dialogs_layout.cpp

1020 lines
28 KiB
C++
Raw Normal View History

/*
This file is part of Telegram Desktop,
the official desktop application for the Telegram messaging service.
For license and copyright information please follow this link:
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
*/
2021-10-01 10:48:52 +00:00
#include "dialogs/ui/dialogs_layout.h"
#include "data/data_drafts.h"
2022-10-21 11:04:42 +00:00
#include "data/data_forum_topic.h"
2019-01-03 12:36:01 +00:00
#include "data/data_session.h"
#include "dialogs/dialogs_list.h"
#include "dialogs/ui/dialogs_video_userpic.h"
2016-05-31 09:46:31 +00:00
#include "styles/style_dialogs.h"
2019-06-02 19:44:00 +00:00
#include "styles/style_window.h"
2017-03-04 10:23:56 +00:00
#include "storage/localstorage.h"
#include "ui/empty_userpic.h"
2020-10-10 09:15:37 +00:00
#include "ui/text/text_options.h"
#include "ui/text/text_utilities.h"
2019-06-23 12:18:33 +00:00
#include "ui/unread_badge.h"
2022-12-19 11:48:24 +00:00
#include "ui/unread_badge_paint.h"
2022-09-16 20:23:27 +00:00
#include "ui/painter.h"
#include "core/ui_integration.h"
2017-04-13 08:27:10 +00:00
#include "lang/lang_keys.h"
#include "support/support_helper.h"
#include "main/main_session.h"
#include "history/view/history_view_send_action.h"
#include "history/view/history_view_item_preview.h"
#include "history/history_unread_things.h"
#include "history/history_item.h"
2022-12-14 12:15:46 +00:00
#include "history/history_item_components.h"
#include "history/history_item_helpers.h"
#include "history/history.h"
#include "base/unixtime.h"
#include "data/data_channel.h"
#include "data/data_user.h"
#include "data/data_folder.h"
2019-06-02 19:44:00 +00:00
#include "data/data_peer_values.h"
2021-10-01 10:57:24 +00:00
namespace Dialogs::Ui {
namespace {
// Show all dates that are in the last 20 hours in time format.
constexpr int kRecentlyInSeconds = 20 * 3600;
const auto kPsaBadgePrefix = "cloud_lng_badge_psa_";
2020-10-26 13:27:01 +00:00
[[nodiscard]] bool ShowUserBotIcon(not_null<UserData*> user) {
2020-09-11 15:33:26 +00:00
return user->isBot() && !user->isSupport() && !user->isRepliesChat();
2019-03-12 10:36:33 +00:00
}
[[nodiscard]] bool ShowSendActionInDialogs(Data::Thread *thread) {
const auto history = thread ? thread->owningHistory().get() : nullptr;
2022-11-08 10:30:42 +00:00
if (!history) {
return false;
} else if (const auto user = history->peer->asUser()) {
return (user->onlineTill > 0);
}
return !history->isForum();
2020-10-26 13:27:01 +00:00
}
void PaintRowTopRight(
QPainter &p,
const QString &text,
QRect &rectForName,
const PaintContext &context) {
const auto width = st::dialogsDateFont->width(text);
rectForName.setWidth(rectForName.width() - width - st::dialogsDateSkip);
p.setFont(st::dialogsDateFont);
p.setPen(context.active
? st::dialogsDateFgActive
: context.selected
? st::dialogsDateFgOver
: st::dialogsDateFg);
p.drawText(
rectForName.left() + rectForName.width() + st::dialogsDateSkip,
rectForName.top() + st::semiboldFont->height - st::normalFont->descent,
text);
}
void PaintRowDate(
QPainter &p,
QDateTime date,
QRect &rectForName,
const PaintContext &context) {
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 = [&] {
if ((lastDate == nowDate)
|| (qAbs(lastTime.secsTo(now)) < kRecentlyInSeconds)) {
return QLocale().toString(lastTime.time(), QLocale::ShortFormat);
} else if (qAbs(lastDate.daysTo(nowDate)) < 7) {
2019-03-12 10:36:33 +00:00
return langDayOfWeek(lastDate);
} else {
return QLocale().toString(lastDate, QLocale::ShortFormat);
2019-03-12 10:36:33 +00:00
}
}();
PaintRowTopRight(p, dt, rectForName, context);
}
int PaintBadges(
2022-09-16 20:23:27 +00:00
QPainter &p,
const PaintContext &context,
BadgesState badgesState,
int right,
int top,
bool displayPinnedIcon = false,
int pinnedIconTop = 0) {
auto initial = right;
if (badgesState.unread
&& !badgesState.unreadCounter
&& context.st->unreadMarkDiameter > 0) {
const auto d = context.st->unreadMarkDiameter;
UnreadBadgeStyle st;
PainterHighQualityEnabler hq(p);
const auto rect = QRect(
right - st.size + (st.size - d) / 2,
top + (st.size - d) / 2,
d,
d);
p.setPen(Qt::NoPen);
p.setBrush(badgesState.unreadMuted
? (context.active
? st::dialogsUnreadBgMutedActive
: context.selected
? st::dialogsUnreadBgMutedOver
: st::dialogsUnreadBgMuted)
: (context.active
? st::dialogsUnreadBgActive
: context.selected
? st::dialogsUnreadBgOver
: st::dialogsUnreadBg));
p.drawEllipse(rect);
right -= st.size + st.padding;
} else if (badgesState.unread) {
UnreadBadgeStyle st;
st.active = context.active;
st.selected = context.selected;
st.muted = badgesState.unreadMuted;
const auto counter = (badgesState.unreadCounter > 0)
? QString::number(badgesState.unreadCounter)
: QString();
const auto badge = PaintUnreadBadge(p, counter, right, top, st);
right -= badge.width() + st.padding;
} else if (displayPinnedIcon) {
const auto &icon = context.active
2022-01-26 11:47:23 +00:00
? st::dialogsPinnedIconActive
: context.selected
2022-01-26 11:47:23 +00:00
? st::dialogsPinnedIconOver
: st::dialogsPinnedIcon;
icon.paint(p, right - icon.width(), pinnedIconTop, context.width);
right -= icon.width() + st::dialogsUnreadPadding;
}
if (badgesState.mention || badgesState.reaction) {
UnreadBadgeStyle st;
st.sizeId = badgesState.mention
? UnreadBadgeSize::Dialogs
: UnreadBadgeSize::ReactionInDialogs;
st.active = context.active;
st.selected = context.selected;
st.muted = badgesState.mention
? badgesState.mentionMuted
: badgesState.reactionMuted;
st.padding = 0;
st.textTop = 0;
const auto counter = QString();
const auto badge = PaintUnreadBadge(p, counter, right, top, st);
(badgesState.mention
? (st.active
? st::dialogsUnreadMentionActive
: st.selected
? st::dialogsUnreadMentionOver
: st::dialogsUnreadMention)
: (st.active
? st::dialogsUnreadReactionActive
: st.selected
? st::dialogsUnreadReactionOver
: st::dialogsUnreadReaction)).paintInCenter(p, badge);
right -= badge.width() + st.padding + st::dialogsUnreadPadding;
}
return (initial - right);
}
void PaintExpandedTopicsBar(QPainter &p, float64 progress) {
2022-11-30 09:57:00 +00:00
auto hq = PainterHighQualityEnabler(p);
const auto radius = st::roundRadiusLarge;
const auto width = st::forumDialogRow.padding.left() / 2;
p.setPen(Qt::NoPen);
p.setBrush(st::dialogsBgActive);
p.drawRoundedRect(
QRectF(
-3. * radius - width * (1. - progress),
st::forumDialogRow.padding.top(),
3. * radius + width,
st::forumDialogRow.photoSize),
2022-11-30 09:57:00 +00:00
radius,
radius);
}
void PaintNarrowCounter(
QPainter &p,
const PaintContext &context,
BadgesState badgesState) {
const auto top = context.st->padding.top()
+ context.st->photoSize
- st::dialogsUnreadHeight;
PaintBadges(
p,
context,
badgesState,
context.st->padding.left() + context.st->photoSize,
top);
}
int PaintWideCounter(
QPainter &p,
const PaintContext &context,
BadgesState badgesState,
int texttop,
int availableWidth,
bool displayPinnedIcon) {
const auto top = texttop
+ st::dialogsTextFont->ascent
- st::dialogsUnreadFont->ascent
- (st::dialogsUnreadHeight - st::dialogsUnreadFont->height) / 2;
const auto used = PaintBadges(
p,
context,
badgesState,
context.width - context.st->padding.right(),
top,
displayPinnedIcon,
texttop);
return availableWidth - used;
}
void PaintFolderEntryText(
Painter &p,
not_null<Data::Folder*> folder,
const PaintContext &context,
QRect rect) {
if (rect.isEmpty()) {
return;
}
folder->validateListEntryCache();
2022-09-16 20:23:27 +00:00
p.setFont(st::dialogsTextFont);
p.setPen(context.active
? st::dialogsTextFgActive
: context.selected
? st::dialogsTextFgOver
2022-09-16 20:23:27 +00:00
: st::dialogsTextFg);
folder->listEntryCache().draw(p, {
2022-09-16 20:23:27 +00:00
.position = rect.topLeft(),
.availableWidth = rect.width(),
2022-11-11 09:24:37 +00:00
.palette = &(context.active
? st::dialogsTextPaletteArchiveActive
: context.selected
? st::dialogsTextPaletteArchiveOver
: st::dialogsTextPaletteArchive),
2022-09-16 20:23:27 +00:00
.spoiler = Text::DefaultSpoilerCache(),
.now = context.now,
.paused = context.paused,
2022-09-16 20:23:27 +00:00
.elisionLines = rect.height() / st::dialogsTextFont->height,
});
}
enum class Flag {
SavedMessages = 0x08,
2020-09-11 15:33:26 +00:00
RepliesMessages = 0x10,
AllowUserOnline = 0x20,
2022-11-14 07:24:31 +00:00
TopicJumpRipple = 0x40,
};
inline constexpr bool is_flag_type(Flag) { return true; }
template <typename PaintItemCallback>
void PaintRow(
Painter &p,
2019-06-17 14:37:29 +00:00
not_null<const BasicRow*> row,
QRect geometry,
not_null<Entry*> entry,
VideoUserpic *videoUserpic,
PeerData *from,
PeerBadge &fromBadge,
Fn<void()> customEmojiRepaint,
const Text::String &fromName,
const HiddenSenderInfo *hiddenSenderInfo,
HistoryItem *item,
const Data::Draft *draft,
QDateTime date,
const PaintContext &context,
BadgesState badgesState,
base::flags<Flag> flags,
PaintItemCallback &&paintItemCallback) {
2020-06-08 09:06:50 +00:00
const auto supportMode = entry->session().supportMode();
if (supportMode) {
draft = nullptr;
}
auto bg = context.active
? st::dialogsBgActive
: context.selected
? st::dialogsBgOver
: context.currentBg;
p.fillRect(geometry, bg);
2022-11-14 07:24:31 +00:00
if (!(flags & Flag::TopicJumpRipple)) {
auto ripple = context.active
? st::dialogsRippleBgActive
: st::dialogsRippleBg;
row->paintRipple(p, 0, 0, context.width, &ripple->c);
}
const auto history = entry->asHistory();
const auto thread = entry->asThread();
if (flags & Flag::SavedMessages) {
2021-10-01 10:57:24 +00:00
EmptyUserpic::PaintSavedMessages(
p,
context.st->padding.left(),
context.st->padding.top(),
context.width,
context.st->photoSize);
2020-09-11 15:33:26 +00:00
} else if (flags & Flag::RepliesMessages) {
2021-10-01 10:57:24 +00:00
EmptyUserpic::PaintRepliesMessages(
2020-09-11 15:33:26 +00:00
p,
context.st->padding.left(),
context.st->padding.top(),
context.width,
context.st->photoSize);
} else if (from) {
2019-06-17 14:37:29 +00:00
row->paintUserpic(
p,
from,
videoUserpic,
(flags & Flag::AllowUserOnline) ? history : nullptr,
context);
} else if (hiddenSenderInfo) {
hiddenSenderInfo->emptyUserpic.paintCircle(
p,
context.st->padding.left(),
context.st->padding.top(),
context.width,
context.st->photoSize);
} else {
entry->paintUserpic(p, row->userpicView(), context);
}
auto nameleft = context.st->nameLeft;
if (context.topicsExpanded > 0.) {
PaintExpandedTopicsBar(p, context.topicsExpanded);
}
2022-10-21 10:36:05 +00:00
if (context.narrow) {
if (!draft && item && !item->isEmpty()) {
PaintNarrowCounter(p, context, badgesState);
}
return;
}
auto namewidth = context.width - nameleft - context.st->padding.right();
auto rectForName = QRect(
nameleft,
context.st->nameTop,
namewidth,
st::semiboldFont->height);
2020-04-24 10:31:28 +00:00
const auto promoted = (history && history->useTopPromotion())
&& !context.search;
if (promoted) {
const auto type = history->topPromotionType();
const auto custom = type.isEmpty()
? QString()
2020-09-30 09:11:44 +00:00
: Lang::GetNonDefaultValue(kPsaBadgePrefix + type.toUtf8());
const auto text = type.isEmpty()
? tr::lng_proxy_sponsor(tr::now)
: custom.isEmpty()
? tr::lng_badge_psa_default(tr::now)
: custom;
PaintRowTopRight(p, text, rectForName, context);
2021-02-25 13:03:51 +00:00
} else if (from) {
if (const auto chatTypeIcon = ChatTypeIcon(from, context)) {
chatTypeIcon->paint(p, rectForName.topLeft(), context.width);
rectForName.setLeft(rectForName.left()
+ chatTypeIcon->width()
+ st::dialogsChatTypeSkip);
}
}
auto texttop = context.st->textTop;
if (const auto folder = entry->asFolder()) {
const auto availableWidth = PaintWideCounter(
p,
context,
badgesState,
texttop,
namewidth,
false);
const auto rect = QRect(
nameleft,
texttop,
availableWidth,
st::dialogsTextFont->height);
PaintFolderEntryText(p, folder, context, rect);
} else if (promoted && !history->topPromotionMessage().isEmpty()) {
2020-04-29 08:46:02 +00:00
auto availableWidth = namewidth;
p.setFont(st::dialogsTextFont);
if (history->cloudDraftTextCache().isEmpty()) {
history->cloudDraftTextCache().setText(
2020-04-29 08:46:02 +00:00
st::dialogsTextStyle,
history->topPromotionMessage(),
2021-10-01 10:57:24 +00:00
DialogTextOptions());
2020-04-29 08:46:02 +00:00
}
p.setPen(context.active
? st::dialogsTextFgActive
: context.selected
? st::dialogsTextFgOver
: st::dialogsTextFg);
history->cloudDraftTextCache().draw(p, {
2022-09-16 20:23:27 +00:00
.position = { nameleft, texttop },
.availableWidth = availableWidth,
.spoiler = Text::DefaultSpoilerCache(),
.now = context.now,
.paused = context.paused,
2022-09-16 20:23:27 +00:00
.elisionLines = 1,
});
2020-04-29 08:46:02 +00:00
} else if (draft
2018-11-20 13:34:07 +00:00
|| (supportMode
2020-06-08 09:06:50 +00:00
&& entry->session().supportHelper().isOccupiedBySomeone(history))) {
if (!promoted) {
PaintRowDate(p, date, rectForName, context);
}
auto availableWidth = namewidth;
if (entry->isPinnedDialog(context.filter)
&& (context.filter || !entry->fixedOnTopIndex())) {
auto &icon = context.active
? st::dialogsPinnedIconActive
: context.selected
? st::dialogsPinnedIconOver
: st::dialogsPinnedIcon;
icon.paint(
p,
context.width - context.st->padding.right() - icon.width(),
texttop,
context.width);
availableWidth -= icon.width() + st::dialogsUnreadPadding;
}
p.setFont(st::dialogsTextFont);
auto &color = context.active
? st::dialogsTextFgServiceActive
: context.selected
? st::dialogsTextFgServiceOver
: st::dialogsTextFgService;
if (!ShowSendActionInDialogs(thread)
|| !thread->sendActionPainter()->paint(
p,
nameleft,
texttop,
availableWidth,
context.width,
color,
context.paused)) {
auto &cache = thread->cloudDraftTextCache();
if (cache.isEmpty()) {
using namespace TextUtilities;
auto draftWrapped = Text::PlainLink(
tr::lng_dialogs_text_from_wrapped(
tr::now,
lt_from,
tr::lng_from_draft(tr::now)));
auto draftText = supportMode
? Text::PlainLink(
Support::ChatOccupiedString(history))
: tr::lng_dialogs_text_with_from(
tr::now,
lt_from_part,
draftWrapped,
lt_message,
DialogsPreviewText({
.text = draft->textWithTags.text,
.entities = ConvertTextTagsToEntities(
draft->textWithTags.tags),
}),
Text::WithEntities);
const auto context = Core::MarkedTextContext{
.session = &thread->session(),
.customEmojiRepaint = customEmojiRepaint,
};
cache.setMarkedText(
st::dialogsTextStyle,
draftText,
DialogTextOptions(),
context);
}
p.setPen(context.active
? st::dialogsTextFgActive
: context.selected
? st::dialogsTextFgOver
: st::dialogsTextFg);
cache.draw(p, {
2022-09-16 20:23:27 +00:00
.position = { nameleft, texttop },
.availableWidth = availableWidth,
.palette = &(supportMode
? (context.active
2022-09-16 20:23:27 +00:00
? st::dialogsTextPaletteTakenActive
: context.selected
2022-09-16 20:23:27 +00:00
? st::dialogsTextPaletteTakenOver
: st::dialogsTextPaletteTaken)
: (context.active
2022-09-16 20:23:27 +00:00
? st::dialogsTextPaletteDraftActive
: context.selected
2022-09-16 20:23:27 +00:00
? st::dialogsTextPaletteDraftOver
: st::dialogsTextPaletteDraft)),
.spoiler = Text::DefaultSpoilerCache(),
.now = context.now,
.paused = context.paused,
2022-09-16 20:23:27 +00:00
.elisionLines = 1,
});
}
} else if (!item) {
auto availableWidth = namewidth;
if (entry->isPinnedDialog(context.filter)
&& (context.filter || !entry->fixedOnTopIndex())) {
auto &icon = context.active
? st::dialogsPinnedIconActive
: context.selected
? st::dialogsPinnedIconOver
: st::dialogsPinnedIcon;
icon.paint(p, context.width - context.st->padding.right() - icon.width(), texttop, context.width);
availableWidth -= icon.width() + st::dialogsUnreadPadding;
}
auto &color = context.active
? st::dialogsTextFgServiceActive
: context.selected
? st::dialogsTextFgServiceOver
: st::dialogsTextFgService;
p.setFont(st::dialogsTextFont);
if (!ShowSendActionInDialogs(thread)
|| !thread->sendActionPainter()->paint(
p,
nameleft,
texttop,
availableWidth,
context.width,
color,
context.now)) {
// Empty history
}
} else if (!item->isEmpty()) {
if (thread && !promoted) {
PaintRowDate(p, date, rectForName, context);
}
paintItemCallback(nameleft, namewidth);
} else if (entry->isPinnedDialog(context.filter)
&& (context.filter || !entry->fixedOnTopIndex())) {
auto &icon = context.active
? st::dialogsPinnedIconActive
: context.selected
? st::dialogsPinnedIconOver
: st::dialogsPinnedIcon;
icon.paint(p, context.width - context.st->padding.right() - icon.width(), texttop, context.width);
}
const auto sendStateIcon = [&]() -> const style::icon* {
if (!thread) {
return nullptr;
2022-10-21 11:04:42 +00:00
} else if (const auto topic = thread->asTopic()
; !context.search && topic && topic->closed()) {
2022-10-21 11:04:42 +00:00
return &(context.active
? st::dialogsLockIconActive
: context.selected
? st::dialogsLockIconOver
: st::dialogsLockIcon);
} else if (draft) {
if (draft->saveRequestId) {
return &(context.active
? st::dialogsSendingIconActive
: context.selected
? st::dialogsSendingIconOver
: st::dialogsSendingIcon);
}
} else if (item && !item->isEmpty() && item->needCheck()) {
if (!item->isSending() && !item->hasFailed()) {
if (item->unread(thread)) {
return &(context.active
? st::dialogsSentIconActive
: context.selected
? st::dialogsSentIconOver
: st::dialogsSentIcon);
}
return &(context.active
? st::dialogsReceivedIconActive
: context.selected
? st::dialogsReceivedIconOver
: st::dialogsReceivedIcon);
}
return &(context.active
? st::dialogsSendingIconActive
: context.selected
? st::dialogsSendingIconOver
: st::dialogsSendingIcon);
}
return nullptr;
}();
if (sendStateIcon) {
rectForName.setWidth(rectForName.width() - st::dialogsSendStateSkip);
sendStateIcon->paint(p, rectForName.topLeft() + QPoint(rectForName.width(), 0), context.width);
}
p.setFont(st::semiboldFont);
2020-09-11 15:33:26 +00:00
if (flags & (Flag::SavedMessages | Flag::RepliesMessages)) {
auto text = (flags & Flag::SavedMessages)
? tr::lng_saved_messages(tr::now)
: tr::lng_replies_messages(tr::now);
const auto textWidth = st::semiboldFont->width(text);
if (textWidth > rectForName.width()) {
text = st::semiboldFont->elided(text, rectForName.width());
}
p.setPen(context.active
2021-01-21 12:39:40 +00:00
? st::dialogsNameFgActive
: context.selected
2021-01-21 12:39:40 +00:00
? st::dialogsNameFgOver
: st::dialogsNameFg);
p.drawTextLeft(rectForName.left(), rectForName.top(), context.width, text);
} else if (from) {
if (history && !context.search) {
const auto badgeWidth = fromBadge.drawGetWidth(
2019-06-23 12:18:33 +00:00
p,
rectForName,
2022-08-09 11:12:19 +00:00
fromName.maxWidth(),
context.width,
{
.peer = from,
.verified = (context.active
? &st::dialogsVerifiedIconActive
: context.selected
? &st::dialogsVerifiedIconOver
: &st::dialogsVerifiedIcon),
.premium = (context.active
? &st::dialogsPremiumIconActive
: context.selected
? &st::dialogsPremiumIconOver
: &st::dialogsPremiumIcon),
.scam = (context.active
? &st::dialogsScamFgActive
: context.selected
? &st::dialogsScamFgOver
: &st::dialogsScamFg),
.premiumFg = (context.active
2022-08-31 08:29:09 +00:00
? &st::dialogsVerifiedIconBgActive
: context.selected
2022-08-31 08:29:09 +00:00
? &st::dialogsVerifiedIconBgOver
: &st::dialogsVerifiedIconBg),
.customEmojiRepaint = customEmojiRepaint,
.now = context.now,
.paused = context.paused,
});
2019-06-23 12:18:33 +00:00
rectForName.setWidth(rectForName.width() - badgeWidth);
}
p.setPen(context.active
2021-01-21 12:39:40 +00:00
? st::dialogsNameFgActive
: context.selected
2021-01-21 12:39:40 +00:00
? st::dialogsNameFgOver
: st::dialogsNameFg);
2022-08-09 11:12:19 +00:00
fromName.drawElided(p, rectForName.left(), rectForName.top(), rectForName.width());
} else if (hiddenSenderInfo) {
p.setPen(context.active
2021-01-21 12:39:40 +00:00
? st::dialogsNameFgActive
: context.selected
2021-01-21 12:39:40 +00:00
? st::dialogsNameFgOver
: st::dialogsNameFg);
2022-08-09 11:12:19 +00:00
hiddenSenderInfo->nameText().drawElided(p, rectForName.left(), rectForName.top(), rectForName.width());
} else {
p.setPen(context.active
2021-01-21 12:39:40 +00:00
? st::dialogsNameFgActive
: entry->folder()
? (context.selected
? st::dialogsArchiveFgOver
: st::dialogsArchiveFg)
: (context.selected
? st::dialogsNameFgOver
: st::dialogsNameFg));
2019-01-15 11:57:45 +00:00
auto text = entry->chatListName(); // TODO feed name with emoji
auto textWidth = st::semiboldFont->width(text);
if (textWidth > rectForName.width()) {
text = st::semiboldFont->elided(text, rectForName.width());
}
p.drawTextLeft(rectForName.left(), rectForName.top(), context.width, text);
}
}
} // namespace
2022-01-26 11:47:23 +00:00
2022-12-06 16:32:58 +00:00
const style::icon *ChatTypeIcon(not_null<PeerData*> peer) {
return ChatTypeIcon(peer, {
.st = &st::defaultDialogRow,
.currentBg = st::windowBg,
});
}
2022-01-26 11:47:23 +00:00
const style::icon *ChatTypeIcon(
not_null<PeerData*> peer,
const PaintContext &context) {
if (const auto user = peer->asUser()) {
2022-01-26 11:47:23 +00:00
if (ShowUserBotIcon(user)) {
return &(context.active
2022-01-26 11:47:23 +00:00
? st::dialogsBotIconActive
: context.selected
? st::dialogsBotIconOver
: st::dialogsBotIcon);
2022-01-26 11:47:23 +00:00
}
} else if (peer->isBroadcast()) {
return &(context.active
? st::dialogsChannelIconActive
: context.selected
? st::dialogsChannelIconOver
: st::dialogsChannelIcon);
} else if (peer->isForum()) {
return &(context.active
? st::dialogsForumIconActive
: context.selected
? st::dialogsForumIconOver
: st::dialogsForumIcon);
} else {
return &(context.active
? st::dialogsChatIconActive
: context.selected
? st::dialogsChatIconOver
: st::dialogsChatIcon);
2022-01-26 11:47:23 +00:00
}
return nullptr;
}
void RowPainter::Paint(
Painter &p,
not_null<const Row*> row,
VideoUserpic *videoUserpic,
const PaintContext &context) {
const auto entry = row->entry();
const auto history = row->history();
const auto thread = row->thread();
const auto peer = history ? history->peer.get() : nullptr;
const auto badgesState = entry->chatListBadgesState();
2019-01-15 11:57:45 +00:00
const auto item = entry->chatListMessage();
const auto cloudDraft = [&]() -> const Data::Draft*{
if (!thread) {
return nullptr;
}
if ((!peer || !peer->isForum()) && (!item || !badgesState.unread)) {
// Draw item, if there are unread messages.
const auto draft = thread->owningHistory()->cloudDraft(
thread->topicRootId());
if (!Data::DraftIsNull(draft)) {
return draft;
}
}
return nullptr;
}();
const auto displayDate = [&] {
if (item) {
if (cloudDraft) {
return (item->date() > cloudDraft->date)
? ItemDateTime(item)
: base::unixtime::parse(cloudDraft->date);
}
return ItemDateTime(item);
}
return cloudDraft
? base::unixtime::parse(cloudDraft->date)
: QDateTime();
}();
const auto displayPinnedIcon = badgesState.empty()
&& entry->isPinnedDialog(context.filter)
&& (context.filter || !entry->fixedOnTopIndex());
const auto from = history
? (history->peer->migrateTo()
? history->peer->migrateTo()
: history->peer.get())
: nullptr;
const auto allowUserOnline = !context.narrow || badgesState.empty();
const auto flags = (allowUserOnline ? Flag::AllowUserOnline : Flag(0))
2020-09-11 15:33:26 +00:00
| (peer && peer->isSelf() ? Flag::SavedMessages : Flag(0))
2022-11-14 07:24:31 +00:00
| (peer && peer->isRepliesChat() ? Flag::RepliesMessages : Flag(0))
| (row->topicJumpRipple() ? Flag::TopicJumpRipple : Flag(0));
const auto paintItemCallback = [&](int nameleft, int namewidth) {
const auto texttop = context.st->textTop;
const auto availableWidth = PaintWideCounter(
p,
context,
badgesState,
texttop,
namewidth,
displayPinnedIcon);
const auto &color = context.active
? st::dialogsTextFgServiceActive
: context.selected
? st::dialogsTextFgServiceOver
: st::dialogsTextFgService;
2022-11-11 09:24:37 +00:00
auto rect = QRect(
nameleft,
texttop,
availableWidth,
st::dialogsTextFont->height);
const auto actionWasPainted = ShowSendActionInDialogs(thread)
? thread->sendActionPainter()->paint(
2020-10-26 13:27:01 +00:00
p,
rect.x(),
rect.y(),
rect.width(),
context.width,
2020-10-26 13:27:01 +00:00
color,
context.now)
2020-10-26 13:27:01 +00:00
: false;
const auto view = actionWasPainted
? nullptr
: thread
? &thread->lastItemDialogsView()
: nullptr;
if (view) {
const auto forum = context.st->topicsHeight
? row->history()->peer->forum()
: nullptr;
if (!view->prepared(item, forum)) {
view->prepare(
item,
forum,
[=] { entry->updateChatListEntry(); },
{});
}
if (forum) {
rect.setHeight(context.st->topicsHeight + rect.height());
2022-11-11 09:24:37 +00:00
}
view->paint(p, rect, context);
}
};
PaintRow(
p,
row,
QRect(0, 0, context.width, row->height()),
entry,
videoUserpic,
from,
entry->chatListPeerBadge(),
[=] { entry->updateChatListEntry(); },
2022-08-09 11:12:19 +00:00
entry->chatListNameText(),
nullptr,
item,
cloudDraft,
displayDate,
context,
badgesState,
flags,
paintItemCallback);
}
void RowPainter::Paint(
Painter &p,
not_null<const FakeRow*> row,
const PaintContext &context) {
const auto item = row->item();
const auto topic = context.forum ? row->topic() : nullptr;
const auto history = topic ? nullptr : item->history().get();
const auto entry = topic ? (Entry*)topic : (Entry*)history;
auto cloudDraft = nullptr;
const auto from = [&] {
const auto in = row->searchInChat();
return (topic && (in.topic() != topic))
? nullptr
: in
? item->displayFrom()
: history->peer->migrateTo()
? history->peer->migrateTo()
: history->peer.get();
}();
const auto hiddenSenderInfo = [&]() -> const HiddenSenderInfo* {
if (const auto searchChat = row->searchInChat()) {
if (const auto peer = searchChat.peer()) {
2021-01-20 14:09:45 +00:00
if (const auto forwarded = item->Get<HistoryMessageForwarded>()) {
if (peer->isSelf() || forwarded->imported) {
return forwarded->hiddenSenderInfo.get();
}
}
}
}
return nullptr;
}();
const auto previewOptions = [&]() -> HistoryView::ToPreviewOptions {
if (topic) {
return {};
} else if (const auto searchChat = row->searchInChat()) {
if (const auto peer = searchChat.peer()) {
if (!peer->isChannel() || peer->isMegagroup()) {
return { .hideSender = true };
}
}
}
return {};
}();
const auto badgesState = context.displayUnreadInfo
? entry->chatListBadgesState()
: BadgesState();
const auto displayPinnedIcon = false;
const auto paintItemCallback = [&](int nameleft, int namewidth) {
const auto texttop = context.st->textTop;
const auto availableWidth = PaintWideCounter(
p,
context,
badgesState,
texttop,
namewidth,
displayPinnedIcon);
const auto itemRect = QRect(
nameleft,
texttop,
availableWidth,
st::dialogsTextFont->height);
auto &view = row->itemView();
if (!view.prepared(item, nullptr)) {
view.prepare(item, nullptr, row->repaint(), previewOptions);
}
view.paint(p, itemRect, context);
};
const auto showSavedMessages = history
&& history->peer->isSelf()
&& !row->searchInChat();
const auto showRepliesMessages = history
&& history->peer->isRepliesChat()
2020-09-11 15:33:26 +00:00
&& !row->searchInChat();
const auto flags = (showSavedMessages ? Flag::SavedMessages : Flag(0))
| (showRepliesMessages ? Flag::RepliesMessages : Flag(0));
PaintRow(
p,
row,
QRect(0, 0, context.width, context.st->height),
entry,
nullptr,
from,
row->badge(),
row->repaint(),
2022-08-09 11:12:19 +00:00
row->name(),
hiddenSenderInfo,
item,
cloudDraft,
ItemDateTime(item),
context,
badgesState,
flags,
paintItemCallback);
}
QRect RowPainter::SendActionAnimationRect(
not_null<const style::DialogRow*> st,
int animationLeft,
int animationWidth,
int animationHeight,
int fullWidth,
bool textUpdated) {
const auto nameleft = st->nameLeft;
const auto namewidth = fullWidth - nameleft - st->padding.right();
const auto texttop = st->textTop;
return QRect(
nameleft + (textUpdated ? 0 : animationLeft),
texttop,
textUpdated ? namewidth : animationWidth,
animationHeight);
}
void PaintCollapsedRow(
Painter &p,
2019-06-17 14:37:29 +00:00
const BasicRow &row,
Data::Folder *folder,
const QString &text,
int unread,
const PaintContext &context) {
p.fillRect(
QRect{ 0, 0, context.width, st::dialogsImportantBarHeight },
context.selected ? st::dialogsBgOver : context.currentBg);
row.paintRipple(p, 0, 0, context.width);
2018-12-04 10:32:06 +00:00
const auto unreadTop = (st::dialogsImportantBarHeight - st::dialogsUnreadHeight) / 2;
if (!context.narrow || !folder) {
p.setFont(st::semiboldFont);
p.setPen(st::dialogsNameFg);
const auto textBaseline = unreadTop
+ (st::dialogsUnreadHeight - st::dialogsUnreadFont->height) / 2
+ st::dialogsUnreadFont->ascent;
const auto left = context.narrow
? ((context.width - st::semiboldFont->width(text)) / 2)
: context.st->padding.left();
p.drawText(left, textBaseline, text);
} else {
folder->paintUserpic(
p,
(context.width - st::dialogsUnreadHeight) / 2,
unreadTop,
st::dialogsUnreadHeight);
}
if (!context.narrow && unread) {
const auto unreadRight = context.width - context.st->padding.right();
2018-12-04 10:32:06 +00:00
UnreadBadgeStyle st;
st.muted = true;
2022-01-26 11:47:23 +00:00
PaintUnreadBadge(
2018-12-04 10:32:06 +00:00
p,
QString::number(unread),
unreadRight,
unreadTop,
2022-01-26 11:47:23 +00:00
st);
}
}
2021-10-01 10:57:24 +00:00
} // namespace Dialogs::Ui