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
|
|
|
*/
|
2021-10-01 10:48:52 +00:00
|
|
|
#include "dialogs/ui/dialogs_layout.h"
|
2016-04-09 18:45:55 +00:00
|
|
|
|
2016-06-09 14:31:10 +00:00
|
|
|
#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"
|
2016-04-09 18:45:55 +00:00
|
|
|
#include "dialogs/dialogs_list.h"
|
2023-08-30 02:25:34 +00:00
|
|
|
#include "dialogs/dialogs_three_state_icon.h"
|
2022-05-16 11:38:35 +00:00
|
|
|
#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"
|
2017-12-05 14:07:01 +00:00
|
|
|
#include "ui/empty_userpic.h"
|
2020-10-10 09:15:37 +00:00
|
|
|
#include "ui/text/text_options.h"
|
2021-12-26 17:17:26 +00:00
|
|
|
#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"
|
2023-02-21 12:31:55 +00:00
|
|
|
#include "ui/power_saving.h"
|
2022-07-04 06:14:24 +00:00
|
|
|
#include "core/ui_integration.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"
|
2020-06-18 12:47:09 +00:00
|
|
|
#include "main/main_session.h"
|
2020-09-29 08:36:30 +00:00
|
|
|
#include "history/view/history_view_send_action.h"
|
2021-12-21 17:43:15 +00:00
|
|
|
#include "history/view/history_view_item_preview.h"
|
2022-01-26 16:01:40 +00:00
|
|
|
#include "history/history_unread_things.h"
|
2018-01-11 19:33:26 +00:00
|
|
|
#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"
|
2018-01-13 12:45:11 +00:00
|
|
|
#include "history/history.h"
|
2019-07-10 17:28:33 +00:00
|
|
|
#include "base/unixtime.h"
|
2019-01-04 11:09:48 +00:00
|
|
|
#include "data/data_channel.h"
|
|
|
|
#include "data/data_user.h"
|
2019-05-03 13:02:00 +00:00
|
|
|
#include "data/data_folder.h"
|
2019-06-02 19:44:00 +00:00
|
|
|
#include "data/data_peer_values.h"
|
2016-04-09 18:45:55 +00:00
|
|
|
|
2021-10-01 10:57:24 +00:00
|
|
|
namespace Dialogs::Ui {
|
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;
|
2020-04-24 12:40:20 +00:00
|
|
|
const auto kPsaBadgePrefix = "cloud_lng_badge_psa_";
|
2016-07-26 12:09:40 +00:00
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2022-10-17 16:29:48 +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);
|
|
|
|
}
|
2022-12-02 14:19:56 +00:00
|
|
|
return !history->isForum();
|
2020-10-26 13:27:01 +00:00
|
|
|
}
|
|
|
|
|
2022-09-29 07:52:18 +00:00
|
|
|
void PaintRowTopRight(
|
|
|
|
QPainter &p,
|
|
|
|
const QString &text,
|
|
|
|
QRect &rectForName,
|
|
|
|
const PaintContext &context) {
|
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);
|
2022-09-29 07:52:18 +00:00
|
|
|
p.setPen(context.active
|
|
|
|
? st::dialogsDateFgActive
|
|
|
|
: context.selected
|
|
|
|
? st::dialogsDateFgOver
|
|
|
|
: st::dialogsDateFg);
|
|
|
|
p.drawText(
|
|
|
|
rectForName.left() + rectForName.width() + st::dialogsDateSkip,
|
2022-09-30 07:25:02 +00:00
|
|
|
rectForName.top() + st::semiboldFont->height - st::normalFont->descent,
|
2022-09-29 07:52:18 +00:00
|
|
|
text);
|
2018-05-11 14:03:53 +00:00
|
|
|
}
|
|
|
|
|
2022-09-29 07:52:18 +00:00
|
|
|
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 = [&] {
|
2022-12-29 06:26:22 +00:00
|
|
|
if ((lastDate == nowDate)
|
|
|
|
|| (qAbs(lastTime.secsTo(now)) < kRecentlyInSeconds)) {
|
2022-12-15 09:47:56 +00:00
|
|
|
return QLocale().toString(lastTime.time(), QLocale::ShortFormat);
|
2022-12-29 06:26:22 +00:00
|
|
|
} else if (qAbs(lastDate.daysTo(nowDate)) < 7) {
|
2019-03-12 10:36:33 +00:00
|
|
|
return langDayOfWeek(lastDate);
|
|
|
|
} else {
|
2022-12-15 09:47:56 +00:00
|
|
|
return QLocale().toString(lastDate, QLocale::ShortFormat);
|
2019-03-12 10:36:33 +00:00
|
|
|
}
|
|
|
|
}();
|
2022-09-29 07:52:18 +00:00
|
|
|
PaintRowTopRight(p, dt, rectForName, context);
|
2016-06-03 18:24:27 +00:00
|
|
|
}
|
|
|
|
|
2022-10-20 08:57:12 +00:00
|
|
|
int PaintBadges(
|
2022-09-16 20:23:27 +00:00
|
|
|
QPainter &p,
|
2022-09-29 07:52:18 +00:00
|
|
|
const PaintContext &context,
|
2022-10-20 08:57:12 +00:00
|
|
|
BadgesState badgesState,
|
|
|
|
int right,
|
|
|
|
int top,
|
|
|
|
bool displayPinnedIcon = false,
|
|
|
|
int pinnedIconTop = 0) {
|
|
|
|
auto initial = right;
|
2022-11-15 15:49:14 +00:00
|
|
|
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) {
|
2018-10-09 15:36:06 +00:00
|
|
|
UnreadBadgeStyle st;
|
2022-09-29 07:52:18 +00:00
|
|
|
st.active = context.active;
|
|
|
|
st.selected = context.selected;
|
2022-10-20 08:57:12 +00:00
|
|
|
st.muted = badgesState.unreadMuted;
|
|
|
|
const auto counter = (badgesState.unreadCounter > 0)
|
|
|
|
? QString::number(badgesState.unreadCounter)
|
2018-10-09 15:36:06 +00:00
|
|
|
: QString();
|
2022-10-20 08:57:12 +00:00
|
|
|
const auto badge = PaintUnreadBadge(p, counter, right, top, st);
|
|
|
|
right -= badge.width() + st.padding;
|
2018-10-09 15:36:06 +00:00
|
|
|
} else if (displayPinnedIcon) {
|
2023-08-30 02:25:34 +00:00
|
|
|
const auto &icon = ThreeStateIcon(
|
|
|
|
st::dialogsPinnedIcon,
|
|
|
|
context.active,
|
|
|
|
context.selected);
|
2022-10-20 08:57:12 +00:00
|
|
|
icon.paint(p, right - icon.width(), pinnedIconTop, context.width);
|
|
|
|
right -= icon.width() + st::dialogsUnreadPadding;
|
2018-10-09 15:36:06 +00:00
|
|
|
}
|
2022-10-20 08:57:12 +00:00
|
|
|
if (badgesState.mention || badgesState.reaction) {
|
2018-10-09 15:36:06 +00:00
|
|
|
UnreadBadgeStyle st;
|
2022-10-20 08:57:12 +00:00
|
|
|
st.sizeId = badgesState.mention
|
2022-09-29 07:52:18 +00:00
|
|
|
? UnreadBadgeSize::Dialogs
|
|
|
|
: UnreadBadgeSize::ReactionInDialogs;
|
|
|
|
st.active = context.active;
|
|
|
|
st.selected = context.selected;
|
2022-10-20 08:57:12 +00:00
|
|
|
st.muted = badgesState.mention
|
|
|
|
? badgesState.mentionMuted
|
|
|
|
: badgesState.reactionMuted;
|
2018-10-09 15:36:06 +00:00
|
|
|
st.padding = 0;
|
|
|
|
st.textTop = 0;
|
2022-10-20 08:57:12 +00:00
|
|
|
const auto counter = QString();
|
|
|
|
const auto badge = PaintUnreadBadge(p, counter, right, top, st);
|
2023-08-30 02:25:34 +00:00
|
|
|
ThreeStateIcon(
|
|
|
|
badgesState.mention
|
|
|
|
? st::dialogsUnreadMention
|
|
|
|
: st::dialogsUnreadReaction,
|
|
|
|
st.active,
|
|
|
|
st.selected).paintInCenter(p, badge);
|
2022-10-20 08:57:12 +00:00
|
|
|
right -= badge.width() + st.padding + st::dialogsUnreadPadding;
|
2018-10-09 15:36:06 +00:00
|
|
|
}
|
2022-10-20 08:57:12 +00:00
|
|
|
return (initial - right);
|
|
|
|
}
|
|
|
|
|
2022-12-01 13:48:33 +00:00
|
|
|
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(
|
2022-12-01 13:48:33 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2022-10-20 08:57:12 +00:00
|
|
|
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;
|
2018-10-09 15:36:06 +00:00
|
|
|
}
|
|
|
|
|
2022-11-13 19:38:18 +00:00
|
|
|
void PaintFolderEntryText(
|
2019-04-23 12:29:23 +00:00
|
|
|
Painter &p,
|
2022-11-13 19:38:18 +00:00
|
|
|
not_null<Data::Folder*> folder,
|
2022-09-29 07:52:18 +00:00
|
|
|
const PaintContext &context,
|
|
|
|
QRect rect) {
|
2019-04-23 12:29:23 +00:00
|
|
|
if (rect.isEmpty()) {
|
|
|
|
return;
|
|
|
|
}
|
2022-11-13 19:38:18 +00:00
|
|
|
folder->validateListEntryCache();
|
2022-09-16 20:23:27 +00:00
|
|
|
p.setFont(st::dialogsTextFont);
|
2022-09-29 07:52:18 +00:00
|
|
|
p.setPen(context.active
|
2019-04-23 12:29:23 +00:00
|
|
|
? st::dialogsTextFgActive
|
2022-09-29 07:52:18 +00:00
|
|
|
: context.selected
|
2019-04-23 12:29:23 +00:00
|
|
|
? st::dialogsTextFgOver
|
2022-09-16 20:23:27 +00:00
|
|
|
: st::dialogsTextFg);
|
2022-11-13 19:38:18 +00:00
|
|
|
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(),
|
2022-09-29 07:52:18 +00:00
|
|
|
.now = context.now,
|
2023-02-21 12:31:55 +00:00
|
|
|
.pausedEmoji = context.paused || On(PowerSaving::kEmojiChat),
|
|
|
|
.pausedSpoiler = context.paused || On(PowerSaving::kChatSpoiler),
|
2023-10-03 13:50:33 +00:00
|
|
|
.elisionHeight = rect.height(),
|
2022-09-16 20:23:27 +00:00
|
|
|
});
|
2019-04-23 12:29:23 +00:00
|
|
|
}
|
|
|
|
|
2017-12-05 14:07:01 +00:00
|
|
|
enum class Flag {
|
2019-04-16 09:29:21 +00:00
|
|
|
SavedMessages = 0x08,
|
2020-09-11 15:33:26 +00:00
|
|
|
RepliesMessages = 0x10,
|
|
|
|
AllowUserOnline = 0x20,
|
2022-11-14 07:24:31 +00:00
|
|
|
TopicJumpRipple = 0x40,
|
2017-12-05 14:07:01 +00:00
|
|
|
};
|
|
|
|
inline constexpr bool is_flag_type(Flag) { return true; }
|
|
|
|
|
2022-10-20 08:57:12 +00:00
|
|
|
template <typename PaintItemCallback>
|
2022-09-29 07:52:18 +00:00
|
|
|
void PaintRow(
|
2017-11-05 11:21:30 +00:00
|
|
|
Painter &p,
|
2019-06-17 14:37:29 +00:00
|
|
|
not_null<const BasicRow*> row,
|
2022-11-11 06:23:23 +00:00
|
|
|
QRect geometry,
|
2018-01-05 15:57:18 +00:00
|
|
|
not_null<Entry*> entry,
|
2022-05-16 11:38:35 +00:00
|
|
|
VideoUserpic *videoUserpic,
|
2018-01-05 15:57:18 +00:00
|
|
|
PeerData *from,
|
2022-12-05 12:18:10 +00:00
|
|
|
PeerBadge &fromBadge,
|
2022-08-09 15:53:40 +00:00
|
|
|
Fn<void()> customEmojiRepaint,
|
2022-12-05 12:18:10 +00:00
|
|
|
const Text::String &fromName,
|
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,
|
2022-09-29 07:52:18 +00:00
|
|
|
const PaintContext &context,
|
2022-10-20 08:57:12 +00:00
|
|
|
BadgesState badgesState,
|
2017-12-05 14:07:01 +00:00
|
|
|
base::flags<Flag> flags,
|
2022-10-20 08:57:12 +00:00
|
|
|
PaintItemCallback &&paintItemCallback) {
|
2020-06-08 09:06:50 +00:00
|
|
|
const auto supportMode = entry->session().supportMode();
|
2018-11-15 15:36:04 +00:00
|
|
|
if (supportMode) {
|
|
|
|
draft = nullptr;
|
|
|
|
}
|
|
|
|
|
2022-09-29 07:52:18 +00:00
|
|
|
auto bg = context.active
|
2017-12-05 14:07:01 +00:00
|
|
|
? st::dialogsBgActive
|
2022-09-29 07:52:18 +00:00
|
|
|
: context.selected
|
|
|
|
? st::dialogsBgOver
|
2022-12-06 09:05:05 +00:00
|
|
|
: context.currentBg;
|
2022-11-11 06:23:23 +00:00
|
|
|
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);
|
|
|
|
}
|
2017-12-05 14:07:01 +00:00
|
|
|
|
2022-10-26 12:33:58 +00:00
|
|
|
const auto history = entry->asHistory();
|
|
|
|
const auto thread = entry->asThread();
|
2020-12-02 10:52:19 +00:00
|
|
|
|
2017-12-05 14:07:01 +00:00
|
|
|
if (flags & Flag::SavedMessages) {
|
2021-10-01 10:57:24 +00:00
|
|
|
EmptyUserpic::PaintSavedMessages(
|
2017-12-05 14:07:01 +00:00
|
|
|
p,
|
2022-09-29 10:33:17 +00:00
|
|
|
context.st->padding.left(),
|
|
|
|
context.st->padding.top(),
|
2022-09-29 07:52:18 +00:00
|
|
|
context.width,
|
2022-09-29 10:33:17 +00:00
|
|
|
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,
|
2022-09-29 10:33:17 +00:00
|
|
|
context.st->padding.left(),
|
|
|
|
context.st->padding.top(),
|
2022-09-29 07:52:18 +00:00
|
|
|
context.width,
|
2022-09-29 10:33:17 +00:00
|
|
|
context.st->photoSize);
|
2023-07-18 08:15:19 +00:00
|
|
|
} else if (!from && hiddenSenderInfo) {
|
2022-12-05 12:18:10 +00:00
|
|
|
hiddenSenderInfo->emptyUserpic.paintCircle(
|
2019-03-15 15:15:56 +00:00
|
|
|
p,
|
2022-09-29 10:33:17 +00:00
|
|
|
context.st->padding.left(),
|
|
|
|
context.st->padding.top(),
|
2022-09-29 07:52:18 +00:00
|
|
|
context.width,
|
2022-09-29 10:33:17 +00:00
|
|
|
context.st->photoSize);
|
2023-07-18 08:15:19 +00:00
|
|
|
} else if (!(flags & Flag::AllowUserOnline)) {
|
|
|
|
PaintUserpic(
|
|
|
|
p,
|
|
|
|
entry,
|
|
|
|
from,
|
|
|
|
videoUserpic,
|
|
|
|
row->userpicView(),
|
|
|
|
context);
|
2018-01-05 15:57:18 +00:00
|
|
|
} else {
|
2023-07-18 08:15:19 +00:00
|
|
|
row->paintUserpic(p, entry, from, videoUserpic, context);
|
2017-12-05 14:07:01 +00:00
|
|
|
}
|
2016-04-09 18:45:55 +00:00
|
|
|
|
2022-09-29 10:33:17 +00:00
|
|
|
auto nameleft = context.st->nameLeft;
|
2022-12-01 13:48:33 +00:00
|
|
|
if (context.topicsExpanded > 0.) {
|
|
|
|
PaintExpandedTopicsBar(p, context.topicsExpanded);
|
|
|
|
}
|
2022-10-21 10:36:05 +00:00
|
|
|
if (context.narrow) {
|
2017-01-14 18:50:16 +00:00
|
|
|
if (!draft && item && !item->isEmpty()) {
|
2022-10-20 08:57:12 +00:00
|
|
|
PaintNarrowCounter(p, context, badgesState);
|
2017-01-14 18:50:16 +00:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-09-29 10:33:17 +00:00
|
|
|
auto namewidth = context.width - nameleft - context.st->padding.right();
|
2017-12-05 14:07:01 +00:00
|
|
|
auto rectForName = QRect(
|
|
|
|
nameleft,
|
2022-09-29 10:33:17 +00:00
|
|
|
context.st->nameTop,
|
2017-12-05 14:07:01 +00:00
|
|
|
namewidth,
|
2022-09-30 07:25:02 +00:00
|
|
|
st::semiboldFont->height);
|
2016-04-09 18:45:55 +00:00
|
|
|
|
2020-04-24 10:31:28 +00:00
|
|
|
const auto promoted = (history && history->useTopPromotion())
|
2022-09-29 07:52:18 +00:00
|
|
|
&& !context.search;
|
2018-05-11 14:03:53 +00:00
|
|
|
if (promoted) {
|
2020-04-24 12:40:20 +00:00
|
|
|
const auto type = history->topPromotionType();
|
|
|
|
const auto custom = type.isEmpty()
|
|
|
|
? QString()
|
2020-09-30 09:11:44 +00:00
|
|
|
: Lang::GetNonDefaultValue(kPsaBadgePrefix + type.toUtf8());
|
2020-04-24 12:40:20 +00:00
|
|
|
const auto text = type.isEmpty()
|
|
|
|
? tr::lng_proxy_sponsor(tr::now)
|
|
|
|
: custom.isEmpty()
|
|
|
|
? tr::lng_badge_psa_default(tr::now)
|
|
|
|
: custom;
|
2022-09-29 07:52:18 +00:00
|
|
|
PaintRowTopRight(p, text, rectForName, context);
|
2021-02-25 13:03:51 +00:00
|
|
|
} else if (from) {
|
2022-09-29 07:52:18 +00:00
|
|
|
if (const auto chatTypeIcon = ChatTypeIcon(from, context)) {
|
|
|
|
chatTypeIcon->paint(p, rectForName.topLeft(), context.width);
|
2022-10-25 12:40:54 +00:00
|
|
|
rectForName.setLeft(rectForName.left()
|
|
|
|
+ chatTypeIcon->width()
|
|
|
|
+ st::dialogsChatTypeSkip);
|
2018-01-05 15:57:18 +00:00
|
|
|
}
|
2016-04-09 18:45:55 +00:00
|
|
|
}
|
2022-09-29 10:33:17 +00:00
|
|
|
auto texttop = context.st->textTop;
|
2022-11-13 19:38:18 +00:00
|
|
|
if (const auto folder = entry->asFolder()) {
|
2022-11-23 21:56:37 +00:00
|
|
|
const auto availableWidth = PaintWideCounter(
|
|
|
|
p,
|
|
|
|
context,
|
|
|
|
badgesState,
|
|
|
|
texttop,
|
|
|
|
namewidth,
|
|
|
|
false);
|
2022-11-13 19:38:18 +00:00
|
|
|
const auto rect = QRect(
|
|
|
|
nameleft,
|
|
|
|
texttop,
|
2022-11-23 21:56:37 +00:00
|
|
|
availableWidth,
|
2022-11-13 19:38:18 +00:00
|
|
|
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);
|
2022-10-13 10:32:03 +00:00
|
|
|
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
|
|
|
}
|
2022-09-29 07:52:18 +00:00
|
|
|
p.setPen(context.active
|
|
|
|
? st::dialogsTextFgActive
|
|
|
|
: context.selected
|
|
|
|
? st::dialogsTextFgOver
|
|
|
|
: st::dialogsTextFg);
|
2022-10-13 10:32:03 +00:00
|
|
|
history->cloudDraftTextCache().draw(p, {
|
2022-09-16 20:23:27 +00:00
|
|
|
.position = { nameleft, texttop },
|
|
|
|
.availableWidth = availableWidth,
|
|
|
|
.spoiler = Text::DefaultSpoilerCache(),
|
2022-09-29 07:52:18 +00:00
|
|
|
.now = context.now,
|
2023-02-21 12:31:55 +00:00
|
|
|
.pausedEmoji = context.paused || On(PowerSaving::kEmojiChat),
|
|
|
|
.pausedSpoiler = context.paused || On(PowerSaving::kChatSpoiler),
|
2023-10-03 13:50:33 +00:00
|
|
|
.elisionOneLine = true,
|
2022-09-16 20:23:27 +00:00
|
|
|
});
|
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))) {
|
2018-05-11 14:03:53 +00:00
|
|
|
if (!promoted) {
|
2022-09-29 07:52:18 +00:00
|
|
|
PaintRowDate(p, date, rectForName, context);
|
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;
|
2022-09-29 07:52:18 +00:00
|
|
|
if (entry->isPinnedDialog(context.filter)
|
|
|
|
&& (context.filter || !entry->fixedOnTopIndex())) {
|
2023-08-30 02:25:34 +00:00
|
|
|
auto &icon = ThreeStateIcon(
|
|
|
|
st::dialogsPinnedIcon,
|
|
|
|
context.active,
|
|
|
|
context.selected);
|
2022-09-29 07:52:18 +00:00
|
|
|
icon.paint(
|
|
|
|
p,
|
2022-09-29 10:33:17 +00:00
|
|
|
context.width - context.st->padding.right() - icon.width(),
|
2022-09-29 07:52:18 +00:00
|
|
|
texttop,
|
|
|
|
context.width);
|
2017-01-02 17:11:49 +00:00
|
|
|
availableWidth -= icon.width() + st::dialogsUnreadPadding;
|
|
|
|
}
|
|
|
|
|
2016-06-07 19:59:39 +00:00
|
|
|
p.setFont(st::dialogsTextFont);
|
2022-09-29 07:52:18 +00:00
|
|
|
auto &color = context.active
|
|
|
|
? st::dialogsTextFgServiceActive
|
|
|
|
: context.selected
|
|
|
|
? st::dialogsTextFgServiceOver
|
|
|
|
: st::dialogsTextFgService;
|
2022-10-17 16:29:48 +00:00
|
|
|
if (!ShowSendActionInDialogs(thread)
|
|
|
|
|| !thread->sendActionPainter()->paint(
|
2022-09-29 07:52:18 +00:00
|
|
|
p,
|
|
|
|
nameleft,
|
|
|
|
texttop,
|
|
|
|
availableWidth,
|
|
|
|
context.width,
|
|
|
|
color,
|
|
|
|
context.paused)) {
|
2022-10-17 16:29:48 +00:00
|
|
|
auto &cache = thread->cloudDraftTextCache();
|
|
|
|
if (cache.isEmpty()) {
|
2022-07-04 06:14:24 +00:00
|
|
|
using namespace TextUtilities;
|
2023-10-03 13:50:33 +00:00
|
|
|
auto draftWrapped = Text::Colorized(
|
2021-12-26 17:17:26 +00:00
|
|
|
tr::lng_dialogs_text_from_wrapped(
|
|
|
|
tr::now,
|
|
|
|
lt_from,
|
|
|
|
tr::lng_from_draft(tr::now)));
|
2018-11-15 15:36:04 +00:00
|
|
|
auto draftText = supportMode
|
2023-10-03 13:50:33 +00:00
|
|
|
? Text::Colorized(
|
2021-12-26 17:17:26 +00:00
|
|
|
Support::ChatOccupiedString(history))
|
|
|
|
: tr::lng_dialogs_text_with_from(
|
|
|
|
tr::now,
|
|
|
|
lt_from_part,
|
|
|
|
draftWrapped,
|
|
|
|
lt_message,
|
2022-07-05 07:50:40 +00:00
|
|
|
DialogsPreviewText({
|
2022-07-04 06:14:24 +00:00
|
|
|
.text = draft->textWithTags.text,
|
|
|
|
.entities = ConvertTextTagsToEntities(
|
|
|
|
draft->textWithTags.tags),
|
2022-07-05 07:50:40 +00:00
|
|
|
}),
|
2022-05-16 11:38:35 +00:00
|
|
|
Text::WithEntities);
|
2022-07-04 06:14:24 +00:00
|
|
|
const auto context = Core::MarkedTextContext{
|
2022-10-17 16:29:48 +00:00
|
|
|
.session = &thread->session(),
|
2022-08-09 15:53:40 +00:00
|
|
|
.customEmojiRepaint = customEmojiRepaint,
|
2022-07-04 06:14:24 +00:00
|
|
|
};
|
2022-10-17 16:29:48 +00:00
|
|
|
cache.setMarkedText(
|
2021-12-26 17:17:26 +00:00
|
|
|
st::dialogsTextStyle,
|
|
|
|
draftText,
|
2022-07-04 06:14:24 +00:00
|
|
|
DialogTextOptions(),
|
|
|
|
context);
|
2016-06-03 18:24:27 +00:00
|
|
|
}
|
2022-09-29 07:52:18 +00:00
|
|
|
p.setPen(context.active
|
|
|
|
? st::dialogsTextFgActive
|
|
|
|
: context.selected
|
|
|
|
? st::dialogsTextFgOver
|
|
|
|
: st::dialogsTextFg);
|
2022-10-17 16:29:48 +00:00
|
|
|
cache.draw(p, {
|
2022-09-16 20:23:27 +00:00
|
|
|
.position = { nameleft, texttop },
|
|
|
|
.availableWidth = availableWidth,
|
|
|
|
.palette = &(supportMode
|
2022-09-29 07:52:18 +00:00
|
|
|
? (context.active
|
2022-09-16 20:23:27 +00:00
|
|
|
? st::dialogsTextPaletteTakenActive
|
2022-09-29 07:52:18 +00:00
|
|
|
: context.selected
|
2022-09-16 20:23:27 +00:00
|
|
|
? st::dialogsTextPaletteTakenOver
|
|
|
|
: st::dialogsTextPaletteTaken)
|
2022-09-29 07:52:18 +00:00
|
|
|
: (context.active
|
2022-09-16 20:23:27 +00:00
|
|
|
? st::dialogsTextPaletteDraftActive
|
2022-09-29 07:52:18 +00:00
|
|
|
: context.selected
|
2022-09-16 20:23:27 +00:00
|
|
|
? st::dialogsTextPaletteDraftOver
|
|
|
|
: st::dialogsTextPaletteDraft)),
|
|
|
|
.spoiler = Text::DefaultSpoilerCache(),
|
2022-09-29 07:52:18 +00:00
|
|
|
.now = context.now,
|
2023-02-21 12:31:55 +00:00
|
|
|
.pausedEmoji = context.paused || On(PowerSaving::kEmojiChat),
|
|
|
|
.pausedSpoiler = context.paused || On(PowerSaving::kChatSpoiler),
|
2023-10-03 13:50:33 +00:00
|
|
|
.elisionOneLine = true,
|
2022-09-16 20:23:27 +00:00
|
|
|
});
|
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;
|
2022-09-29 07:52:18 +00:00
|
|
|
if (entry->isPinnedDialog(context.filter)
|
|
|
|
&& (context.filter || !entry->fixedOnTopIndex())) {
|
2023-08-30 02:25:34 +00:00
|
|
|
auto &icon = ThreeStateIcon(
|
|
|
|
st::dialogsPinnedIcon,
|
|
|
|
context.active,
|
|
|
|
context.selected);
|
2022-09-29 10:33:17 +00:00
|
|
|
icon.paint(p, context.width - context.st->padding.right() - icon.width(), texttop, context.width);
|
2017-02-16 16:47:50 +00:00
|
|
|
availableWidth -= icon.width() + st::dialogsUnreadPadding;
|
|
|
|
}
|
|
|
|
|
2022-09-29 07:52:18 +00:00
|
|
|
auto &color = context.active
|
|
|
|
? st::dialogsTextFgServiceActive
|
|
|
|
: context.selected
|
|
|
|
? st::dialogsTextFgServiceOver
|
|
|
|
: st::dialogsTextFgService;
|
2016-06-07 19:59:39 +00:00
|
|
|
p.setFont(st::dialogsTextFont);
|
2022-10-17 16:29:48 +00:00
|
|
|
if (!ShowSendActionInDialogs(thread)
|
|
|
|
|| !thread->sendActionPainter()->paint(
|
2022-09-29 07:52:18 +00:00
|
|
|
p,
|
|
|
|
nameleft,
|
|
|
|
texttop,
|
|
|
|
availableWidth,
|
|
|
|
context.width,
|
|
|
|
color,
|
|
|
|
context.now)) {
|
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()) {
|
2022-10-13 10:32:03 +00:00
|
|
|
if (thread && !promoted) {
|
2022-09-29 07:52:18 +00:00
|
|
|
PaintRowDate(p, date, rectForName, context);
|
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);
|
2022-09-29 07:52:18 +00:00
|
|
|
} else if (entry->isPinnedDialog(context.filter)
|
|
|
|
&& (context.filter || !entry->fixedOnTopIndex())) {
|
2023-08-30 02:25:34 +00:00
|
|
|
auto &icon = ThreeStateIcon(
|
|
|
|
st::dialogsPinnedIcon,
|
|
|
|
context.active,
|
|
|
|
context.selected);
|
|
|
|
icon.paint(
|
|
|
|
p,
|
|
|
|
context.width - context.st->padding.right() - icon.width(),
|
|
|
|
texttop,
|
|
|
|
context.width);
|
2016-09-30 12:52:03 +00:00
|
|
|
}
|
2022-10-17 16:29:48 +00:00
|
|
|
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()
|
2022-10-26 12:33:58 +00:00
|
|
|
; !context.search && topic && topic->closed()) {
|
2023-08-30 02:25:34 +00:00
|
|
|
return &ThreeStateIcon(
|
|
|
|
st::dialogsLockIcon,
|
|
|
|
context.active,
|
|
|
|
context.selected);
|
2022-10-17 16:29:48 +00:00
|
|
|
} else if (draft) {
|
2016-09-30 12:52:03 +00:00
|
|
|
if (draft->saveRequestId) {
|
2023-08-30 02:25:34 +00:00
|
|
|
return &ThreeStateIcon(
|
|
|
|
st::dialogsSendingIcon,
|
|
|
|
context.active,
|
|
|
|
context.selected);
|
2016-09-30 12:52:03 +00:00
|
|
|
}
|
|
|
|
} else if (item && !item->isEmpty() && item->needCheck()) {
|
2021-11-07 08:06:00 +00:00
|
|
|
if (!item->isSending() && !item->hasFailed()) {
|
2022-10-17 16:29:48 +00:00
|
|
|
if (item->unread(thread)) {
|
2023-08-30 02:25:34 +00:00
|
|
|
return &ThreeStateIcon(
|
|
|
|
st::dialogsSentIcon,
|
|
|
|
context.active,
|
|
|
|
context.selected);
|
2016-04-09 18:45:55 +00:00
|
|
|
}
|
2023-08-30 02:25:34 +00:00
|
|
|
return &ThreeStateIcon(
|
|
|
|
st::dialogsReceivedIcon,
|
|
|
|
context.active,
|
|
|
|
context.selected);
|
2016-04-09 18:45:55 +00:00
|
|
|
}
|
2023-08-30 02:25:34 +00:00
|
|
|
return &ThreeStateIcon(
|
|
|
|
st::dialogsSendingIcon,
|
|
|
|
context.active,
|
|
|
|
context.selected);
|
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
|
|
|
}();
|
2022-10-17 16:29:48 +00:00
|
|
|
if (sendStateIcon) {
|
2016-09-30 12:52:03 +00:00
|
|
|
rectForName.setWidth(rectForName.width() - st::dialogsSendStateSkip);
|
2022-09-29 07:52:18 +00:00
|
|
|
sendStateIcon->paint(p, rectForName.topLeft() + QPoint(rectForName.width(), 0), context.width);
|
2016-04-09 20:41:20 +00:00
|
|
|
}
|
|
|
|
|
2022-09-30 07:25:02 +00:00
|
|
|
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);
|
2022-09-30 07:25:02 +00:00
|
|
|
const auto textWidth = st::semiboldFont->width(text);
|
2017-12-05 14:07:01 +00:00
|
|
|
if (textWidth > rectForName.width()) {
|
2022-09-30 07:25:02 +00:00
|
|
|
text = st::semiboldFont->elided(text, rectForName.width());
|
2017-12-05 14:07:01 +00:00
|
|
|
}
|
2022-09-29 07:52:18 +00:00
|
|
|
p.setPen(context.active
|
2021-01-21 12:39:40 +00:00
|
|
|
? st::dialogsNameFgActive
|
2022-09-29 07:52:18 +00:00
|
|
|
: context.selected
|
2021-01-21 12:39:40 +00:00
|
|
|
? st::dialogsNameFgOver
|
|
|
|
: st::dialogsNameFg);
|
2022-09-29 07:52:18 +00:00
|
|
|
p.drawTextLeft(rectForName.left(), rectForName.top(), context.width, text);
|
2018-01-05 15:57:18 +00:00
|
|
|
} else if (from) {
|
2022-09-29 07:52:18 +00:00
|
|
|
if (history && !context.search) {
|
2022-08-09 15:53:40 +00:00
|
|
|
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(),
|
2022-09-29 07:52:18 +00:00
|
|
|
context.width,
|
2022-08-09 15:53:40 +00:00
|
|
|
{
|
|
|
|
.peer = from,
|
2022-09-29 07:52:18 +00:00
|
|
|
.verified = (context.active
|
2022-08-09 15:53:40 +00:00
|
|
|
? &st::dialogsVerifiedIconActive
|
2022-09-29 07:52:18 +00:00
|
|
|
: context.selected
|
2022-08-09 15:53:40 +00:00
|
|
|
? &st::dialogsVerifiedIconOver
|
|
|
|
: &st::dialogsVerifiedIcon),
|
2023-08-30 02:25:34 +00:00
|
|
|
.premium = &ThreeStateIcon(
|
|
|
|
st::dialogsPremiumIcon,
|
|
|
|
context.active,
|
|
|
|
context.selected),
|
2022-09-29 07:52:18 +00:00
|
|
|
.scam = (context.active
|
2022-08-09 15:53:40 +00:00
|
|
|
? &st::dialogsScamFgActive
|
2022-09-29 07:52:18 +00:00
|
|
|
: context.selected
|
2022-08-09 15:53:40 +00:00
|
|
|
? &st::dialogsScamFgOver
|
|
|
|
: &st::dialogsScamFg),
|
2022-09-29 07:52:18 +00:00
|
|
|
.premiumFg = (context.active
|
2022-08-31 08:29:09 +00:00
|
|
|
? &st::dialogsVerifiedIconBgActive
|
2022-09-29 07:52:18 +00:00
|
|
|
: context.selected
|
2022-08-31 08:29:09 +00:00
|
|
|
? &st::dialogsVerifiedIconBgOver
|
|
|
|
: &st::dialogsVerifiedIconBg),
|
2022-08-09 15:53:40 +00:00
|
|
|
.customEmojiRepaint = customEmojiRepaint,
|
2022-09-29 07:52:18 +00:00
|
|
|
.now = context.now,
|
|
|
|
.paused = context.paused,
|
2022-08-09 15:53:40 +00:00
|
|
|
});
|
2019-06-23 12:18:33 +00:00
|
|
|
rectForName.setWidth(rectForName.width() - badgeWidth);
|
2017-12-05 14:07:01 +00:00
|
|
|
}
|
2022-09-29 07:52:18 +00:00
|
|
|
p.setPen(context.active
|
2021-01-21 12:39:40 +00:00
|
|
|
? st::dialogsNameFgActive
|
2022-09-29 07:52:18 +00:00
|
|
|
: 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());
|
2019-03-15 15:15:56 +00:00
|
|
|
} else if (hiddenSenderInfo) {
|
2022-09-29 07:52:18 +00:00
|
|
|
p.setPen(context.active
|
2021-01-21 12:39:40 +00:00
|
|
|
? st::dialogsNameFgActive
|
2022-09-29 07:52:18 +00:00
|
|
|
: 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());
|
2018-01-05 15:57:18 +00:00
|
|
|
} else {
|
2022-09-29 07:52:18 +00:00
|
|
|
p.setPen(context.active
|
2021-01-21 12:39:40 +00:00
|
|
|
? st::dialogsNameFgActive
|
2022-10-26 14:18:00 +00:00
|
|
|
: 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
|
2022-09-30 07:25:02 +00:00
|
|
|
auto textWidth = st::semiboldFont->width(text);
|
2018-01-05 15:57:18 +00:00
|
|
|
if (textWidth > rectForName.width()) {
|
2022-09-30 07:25:02 +00:00
|
|
|
text = st::semiboldFont->elided(text, rectForName.width());
|
2018-01-05 15:57:18 +00:00
|
|
|
}
|
2022-09-29 07:52:18 +00:00
|
|
|
p.drawTextLeft(rectForName.left(), rectForName.top(), context.width, text);
|
2016-04-09 20:41:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-02-10 09:56:57 +00:00
|
|
|
} // 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,
|
2022-09-29 07:52:18 +00:00
|
|
|
const PaintContext &context) {
|
2022-10-25 12:40:54 +00:00
|
|
|
if (const auto user = peer->asUser()) {
|
2022-01-26 11:47:23 +00:00
|
|
|
if (ShowUserBotIcon(user)) {
|
2023-08-30 02:25:34 +00:00
|
|
|
return &ThreeStateIcon(
|
|
|
|
st::dialogsBotIcon,
|
|
|
|
context.active,
|
|
|
|
context.selected);
|
2022-01-26 11:47:23 +00:00
|
|
|
}
|
2022-10-25 12:40:54 +00:00
|
|
|
} else if (peer->isBroadcast()) {
|
2023-08-30 02:25:34 +00:00
|
|
|
return &ThreeStateIcon(
|
|
|
|
st::dialogsChannelIcon,
|
|
|
|
context.active,
|
|
|
|
context.selected);
|
2022-10-25 12:40:54 +00:00
|
|
|
} else if (peer->isForum()) {
|
2023-08-30 02:25:34 +00:00
|
|
|
return &ThreeStateIcon(
|
|
|
|
st::dialogsForumIcon,
|
|
|
|
context.active,
|
|
|
|
context.selected);
|
2022-10-25 12:40:54 +00:00
|
|
|
} else {
|
2023-08-30 02:25:34 +00:00
|
|
|
return &ThreeStateIcon(
|
|
|
|
st::dialogsChatIcon,
|
|
|
|
context.active,
|
|
|
|
context.selected);
|
2022-01-26 11:47:23 +00:00
|
|
|
}
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2022-09-29 07:52:18 +00:00
|
|
|
void RowPainter::Paint(
|
2017-12-05 14:07:01 +00:00
|
|
|
Painter &p,
|
2018-01-05 15:57:18 +00:00
|
|
|
not_null<const Row*> row,
|
2022-05-16 11:38:35 +00:00
|
|
|
VideoUserpic *videoUserpic,
|
2022-09-29 07:52:18 +00:00
|
|
|
const PaintContext &context) {
|
2018-01-05 15:57:18 +00:00
|
|
|
const auto entry = row->entry();
|
|
|
|
const auto history = row->history();
|
2022-10-13 10:32:03 +00:00
|
|
|
const auto thread = row->thread();
|
2018-01-13 12:45:11 +00:00
|
|
|
const auto peer = history ? history->peer.get() : nullptr;
|
2022-10-20 08:57:12 +00:00
|
|
|
const auto badgesState = entry->chatListBadgesState();
|
2023-02-09 05:56:47 +00:00
|
|
|
entry->chatListPreloadData(); // Allow chat list message resolve.
|
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*{
|
2022-10-20 11:14:55 +00:00
|
|
|
if (!thread) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
if ((!peer || !peer->isForum()) && (!item || !badgesState.unread)) {
|
2018-01-05 15:57:18 +00:00
|
|
|
// Draw item, if there are unread messages.
|
2022-10-17 16:29:48 +00:00
|
|
|
const auto draft = thread->owningHistory()->cloudDraft(
|
|
|
|
thread->topicRootId());
|
|
|
|
if (!Data::DraftIsNull(draft)) {
|
|
|
|
return draft;
|
2018-01-05 15:57:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
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)
|
2019-07-10 17:28:33 +00:00
|
|
|
: base::unixtime::parse(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
|
|
|
}
|
2019-07-10 17:28:33 +00:00
|
|
|
return cloudDraft
|
|
|
|
? base::unixtime::parse(cloudDraft->date)
|
|
|
|
: QDateTime();
|
2018-01-05 15:57:18 +00:00
|
|
|
}();
|
2022-10-20 08:57:12 +00:00
|
|
|
const auto displayPinnedIcon = badgesState.empty()
|
2022-09-29 07:52:18 +00:00
|
|
|
&& entry->isPinnedDialog(context.filter)
|
|
|
|
&& (context.filter || !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;
|
2023-07-18 08:15:19 +00:00
|
|
|
const auto allowUserOnline = true;// !context.narrow || badgesState.empty();
|
2022-09-29 07:52:18 +00:00
|
|
|
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));
|
2018-01-05 15:57:18 +00:00
|
|
|
const auto paintItemCallback = [&](int nameleft, int namewidth) {
|
2022-09-29 10:33:17 +00:00
|
|
|
const auto texttop = context.st->textTop;
|
2018-10-09 15:36:06 +00:00
|
|
|
const auto availableWidth = PaintWideCounter(
|
|
|
|
p,
|
2022-09-29 07:52:18 +00:00
|
|
|
context,
|
2022-10-20 08:57:12 +00:00
|
|
|
badgesState,
|
2018-10-09 15:36:06 +00:00
|
|
|
texttop,
|
|
|
|
namewidth,
|
2022-10-20 08:57:12 +00:00
|
|
|
displayPinnedIcon);
|
2022-09-29 07:52:18 +00:00
|
|
|
const auto &color = context.active
|
2017-11-05 11:21:30 +00:00
|
|
|
? st::dialogsTextFgServiceActive
|
2022-09-29 07:52:18 +00:00
|
|
|
: context.selected
|
|
|
|
? st::dialogsTextFgServiceOver
|
|
|
|
: st::dialogsTextFgService;
|
2022-11-11 09:24:37 +00:00
|
|
|
auto rect = QRect(
|
2017-11-05 11:21:30 +00:00
|
|
|
nameleft,
|
|
|
|
texttop,
|
|
|
|
availableWidth,
|
2019-04-23 12:29:23 +00:00
|
|
|
st::dialogsTextFont->height);
|
2022-10-17 16:29:48 +00:00
|
|
|
const auto actionWasPainted = ShowSendActionInDialogs(thread)
|
|
|
|
? thread->sendActionPainter()->paint(
|
2020-10-26 13:27:01 +00:00
|
|
|
p,
|
2022-08-09 15:53:40 +00:00
|
|
|
rect.x(),
|
|
|
|
rect.y(),
|
|
|
|
rect.width(),
|
2022-09-29 07:52:18 +00:00
|
|
|
context.width,
|
2020-10-26 13:27:01 +00:00
|
|
|
color,
|
2022-09-29 07:52:18 +00:00
|
|
|
context.now)
|
2020-10-26 13:27:01 +00:00
|
|
|
: false;
|
2022-09-23 19:21:31 +00:00
|
|
|
const auto view = actionWasPainted
|
|
|
|
? nullptr
|
2022-10-13 10:32:03 +00:00
|
|
|
: thread
|
|
|
|
? &thread->lastItemDialogsView()
|
2022-09-23 19:21:31 +00:00
|
|
|
: nullptr;
|
2022-11-13 19:38:18 +00:00
|
|
|
if (view) {
|
|
|
|
const auto forum = context.st->topicsHeight
|
|
|
|
? row->history()->peer->forum()
|
|
|
|
: nullptr;
|
|
|
|
if (!view->prepared(item, forum)) {
|
2022-09-23 19:21:31 +00:00
|
|
|
view->prepare(
|
2022-08-09 15:53:40 +00:00
|
|
|
item,
|
2022-11-13 19:38:18 +00:00
|
|
|
forum,
|
2022-09-23 19:21:31 +00:00
|
|
|
[=] { entry->updateChatListEntry(); },
|
2022-11-13 19:38:18 +00:00
|
|
|
{});
|
2022-08-09 15:53:40 +00:00
|
|
|
}
|
2022-11-13 19:38:18 +00:00
|
|
|
if (forum) {
|
|
|
|
rect.setHeight(context.st->topicsHeight + rect.height());
|
2022-11-11 09:24:37 +00:00
|
|
|
}
|
2022-09-29 07:52:18 +00:00
|
|
|
view->paint(p, rect, context);
|
2016-04-09 18:45:55 +00:00
|
|
|
}
|
2017-11-05 11:21:30 +00:00
|
|
|
};
|
2022-09-29 07:52:18 +00:00
|
|
|
PaintRow(
|
2017-11-05 11:21:30 +00:00
|
|
|
p,
|
|
|
|
row,
|
2022-11-11 06:23:23 +00:00
|
|
|
QRect(0, 0, context.width, row->height()),
|
2018-01-05 15:57:18 +00:00
|
|
|
entry,
|
2022-05-16 11:38:35 +00:00
|
|
|
videoUserpic,
|
2017-11-05 11:21:30 +00:00
|
|
|
from,
|
2022-10-20 08:57:12 +00:00
|
|
|
entry->chatListPeerBadge(),
|
2022-10-26 12:33:58 +00:00
|
|
|
[=] { entry->updateChatListEntry(); },
|
2022-08-09 11:12:19 +00:00
|
|
|
entry->chatListNameText(),
|
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,
|
2022-09-29 07:52:18 +00:00
|
|
|
context,
|
2022-10-20 08:57:12 +00:00
|
|
|
badgesState,
|
2017-12-05 14:07:01 +00:00
|
|
|
flags,
|
2022-10-20 08:57:12 +00:00
|
|
|
paintItemCallback);
|
2016-04-09 18:45:55 +00:00
|
|
|
}
|
|
|
|
|
2022-09-29 07:52:18 +00:00
|
|
|
void RowPainter::Paint(
|
2017-12-05 14:07:01 +00:00
|
|
|
Painter &p,
|
2018-01-05 15:57:18 +00:00
|
|
|
not_null<const FakeRow*> row,
|
2022-09-29 07:52:18 +00:00
|
|
|
const PaintContext &context) {
|
2022-10-26 12:33:58 +00:00
|
|
|
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;
|
2017-12-05 14:07:01 +00:00
|
|
|
auto cloudDraft = nullptr;
|
2017-12-21 12:29:01 +00:00
|
|
|
const auto from = [&] {
|
2022-10-26 14:49:07 +00:00
|
|
|
const auto in = row->searchInChat();
|
|
|
|
return (topic && (in.topic() != topic))
|
2022-10-26 12:33:58 +00:00
|
|
|
? nullptr
|
2022-10-26 14:49:07 +00:00
|
|
|
: in
|
2022-10-26 12:33:58 +00:00
|
|
|
? item->displayFrom()
|
|
|
|
: history->peer->migrateTo()
|
2018-01-13 12:45:11 +00:00
|
|
|
? 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()) {
|
2021-01-20 14:09:45 +00:00
|
|
|
if (const auto forwarded = item->Get<HistoryMessageForwarded>()) {
|
|
|
|
if (peer->isSelf() || forwarded->imported) {
|
|
|
|
return forwarded->hiddenSenderInfo.get();
|
|
|
|
}
|
2019-03-15 15:15:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nullptr;
|
|
|
|
}();
|
2021-10-01 12:42:44 +00:00
|
|
|
const auto previewOptions = [&]() -> HistoryView::ToPreviewOptions {
|
2022-10-26 12:33:58 +00:00
|
|
|
if (topic) {
|
|
|
|
return {};
|
|
|
|
} else if (const auto searchChat = row->searchInChat()) {
|
2018-02-14 19:38:01 +00:00
|
|
|
if (const auto peer = searchChat.peer()) {
|
|
|
|
if (!peer->isChannel() || peer->isMegagroup()) {
|
2021-10-01 12:42:44 +00:00
|
|
|
return { .hideSender = true };
|
2018-02-14 19:38:01 +00:00
|
|
|
}
|
2017-11-05 11:21:30 +00:00
|
|
|
}
|
|
|
|
}
|
2021-10-01 12:42:44 +00:00
|
|
|
return {};
|
2017-11-05 11:21:30 +00:00
|
|
|
}();
|
2018-10-09 15:36:06 +00:00
|
|
|
|
2022-10-20 08:57:12 +00:00
|
|
|
const auto badgesState = context.displayUnreadInfo
|
2022-10-26 12:33:58 +00:00
|
|
|
? entry->chatListBadgesState()
|
2022-10-20 08:57:12 +00:00
|
|
|
: BadgesState();
|
2018-10-09 15:36:06 +00:00
|
|
|
const auto displayPinnedIcon = false;
|
|
|
|
|
2017-12-21 12:29:01 +00:00
|
|
|
const auto paintItemCallback = [&](int nameleft, int namewidth) {
|
2022-09-29 10:33:17 +00:00
|
|
|
const auto texttop = context.st->textTop;
|
2018-10-09 15:36:06 +00:00
|
|
|
const auto availableWidth = PaintWideCounter(
|
|
|
|
p,
|
2022-09-29 07:52:18 +00:00
|
|
|
context,
|
2022-10-20 08:57:12 +00:00
|
|
|
badgesState,
|
2018-10-09 15:36:06 +00:00
|
|
|
texttop,
|
|
|
|
namewidth,
|
2022-10-20 08:57:12 +00:00
|
|
|
displayPinnedIcon);
|
2018-10-09 15:36:06 +00:00
|
|
|
|
|
|
|
const auto itemRect = QRect(
|
|
|
|
nameleft,
|
|
|
|
texttop,
|
|
|
|
availableWidth,
|
|
|
|
st::dialogsTextFont->height);
|
2022-08-09 15:53:40 +00:00
|
|
|
auto &view = row->itemView();
|
2022-11-13 19:38:18 +00:00
|
|
|
if (!view.prepared(item, nullptr)) {
|
|
|
|
view.prepare(item, nullptr, row->repaint(), previewOptions);
|
2022-08-09 15:53:40 +00:00
|
|
|
}
|
2022-11-13 19:38:18 +00:00
|
|
|
view.paint(p, itemRect, context);
|
2017-11-05 11:21:30 +00:00
|
|
|
};
|
2022-10-26 12:33:58 +00:00
|
|
|
const auto showSavedMessages = history
|
|
|
|
&& history->peer->isSelf()
|
2018-02-14 19:38:01 +00:00
|
|
|
&& !row->searchInChat();
|
2022-10-26 12:33:58 +00:00
|
|
|
const auto showRepliesMessages = history
|
|
|
|
&& history->peer->isRepliesChat()
|
2020-09-11 15:33:26 +00:00
|
|
|
&& !row->searchInChat();
|
2022-09-29 07:52:18 +00:00
|
|
|
const auto flags = (showSavedMessages ? Flag::SavedMessages : Flag(0))
|
|
|
|
| (showRepliesMessages ? Flag::RepliesMessages : Flag(0));
|
|
|
|
PaintRow(
|
2017-11-05 11:21:30 +00:00
|
|
|
p,
|
|
|
|
row,
|
2022-11-11 06:23:23 +00:00
|
|
|
QRect(0, 0, context.width, context.st->height),
|
2022-10-26 12:33:58 +00:00
|
|
|
entry,
|
2022-05-16 11:38:35 +00:00
|
|
|
nullptr,
|
2017-11-05 11:21:30 +00:00
|
|
|
from,
|
2022-08-09 15:53:40 +00:00
|
|
|
row->badge(),
|
|
|
|
row->repaint(),
|
2022-08-09 11:12:19 +00:00
|
|
|
row->name(),
|
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),
|
2022-09-29 07:52:18 +00:00
|
|
|
context,
|
2022-10-20 08:57:12 +00:00
|
|
|
badgesState,
|
2017-12-05 14:07:01 +00:00
|
|
|
flags,
|
2022-10-20 08:57:12 +00:00
|
|
|
paintItemCallback);
|
2016-04-09 20:41:20 +00:00
|
|
|
}
|
2016-04-09 18:45:55 +00:00
|
|
|
|
2022-09-29 07:52:18 +00:00
|
|
|
QRect RowPainter::SendActionAnimationRect(
|
2022-09-29 10:33:17 +00:00
|
|
|
not_null<const style::DialogRow*> st,
|
2021-08-30 17:38:11 +00:00
|
|
|
int animationLeft,
|
|
|
|
int animationWidth,
|
|
|
|
int animationHeight,
|
|
|
|
int fullWidth,
|
|
|
|
bool textUpdated) {
|
2022-09-29 10:33:17 +00:00
|
|
|
const auto nameleft = st->nameLeft;
|
|
|
|
const auto namewidth = fullWidth - nameleft - st->padding.right();
|
|
|
|
const auto texttop = st->textTop;
|
2021-08-30 17:38:11 +00:00
|
|
|
return QRect(
|
|
|
|
nameleft + (textUpdated ? 0 : animationLeft),
|
|
|
|
texttop,
|
|
|
|
textUpdated ? namewidth : animationWidth,
|
|
|
|
animationHeight);
|
2016-12-05 08:45:56 +00:00
|
|
|
}
|
|
|
|
|
2019-05-03 13:02:00 +00:00
|
|
|
void PaintCollapsedRow(
|
|
|
|
Painter &p,
|
2019-06-17 14:37:29 +00:00
|
|
|
const BasicRow &row,
|
2019-05-03 13:02:00 +00:00
|
|
|
Data::Folder *folder,
|
|
|
|
const QString &text,
|
|
|
|
int unread,
|
2022-09-29 10:33:17 +00:00
|
|
|
const PaintContext &context) {
|
|
|
|
p.fillRect(
|
|
|
|
QRect{ 0, 0, context.width, st::dialogsImportantBarHeight },
|
2022-12-06 09:05:05 +00:00
|
|
|
context.selected ? st::dialogsBgOver : context.currentBg);
|
2019-05-03 10:55:44 +00:00
|
|
|
|
2022-09-29 10:33:17 +00:00
|
|
|
row.paintRipple(p, 0, 0, context.width);
|
2016-04-11 10:59:01 +00:00
|
|
|
|
2018-12-04 10:32:06 +00:00
|
|
|
const auto unreadTop = (st::dialogsImportantBarHeight - st::dialogsUnreadHeight) / 2;
|
2022-09-29 10:33:17 +00:00
|
|
|
if (!context.narrow || !folder) {
|
2019-05-03 13:02:00 +00:00
|
|
|
p.setFont(st::semiboldFont);
|
|
|
|
p.setPen(st::dialogsNameFg);
|
|
|
|
|
|
|
|
const auto textBaseline = unreadTop
|
|
|
|
+ (st::dialogsUnreadHeight - st::dialogsUnreadFont->height) / 2
|
|
|
|
+ st::dialogsUnreadFont->ascent;
|
2022-09-29 10:33:17 +00:00
|
|
|
const auto left = context.narrow
|
|
|
|
? ((context.width - st::semiboldFont->width(text)) / 2)
|
|
|
|
: context.st->padding.left();
|
2019-05-03 13:02:00 +00:00
|
|
|
p.drawText(left, textBaseline, text);
|
|
|
|
} else {
|
2022-09-29 10:33:17 +00:00
|
|
|
folder->paintUserpic(
|
2019-05-03 13:02:00 +00:00
|
|
|
p,
|
2022-09-29 10:33:17 +00:00
|
|
|
(context.width - st::dialogsUnreadHeight) / 2,
|
2019-05-03 13:02:00 +00:00
|
|
|
unreadTop,
|
|
|
|
st::dialogsUnreadHeight);
|
|
|
|
}
|
2022-09-29 10:33:17 +00:00
|
|
|
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);
|
2016-04-11 10:59:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-10-01 10:57:24 +00:00
|
|
|
} // namespace Dialogs::Ui
|