dialogs_layout.cpp 35 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286
  1. /*
  2. This file is part of Telegram Desktop,
  3. the official desktop application for the Telegram messaging service.
  4. For license and copyright information please follow this link:
  5. https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
  6. */
  7. #include "dialogs/ui/dialogs_layout.h"
  8. #include "base/unixtime.h"
  9. #include "core/ui_integration.h"
  10. #include "data/data_channel.h"
  11. #include "data/data_drafts.h"
  12. #include "data/data_folder.h"
  13. #include "data/data_forum_topic.h"
  14. #include "data/data_peer_values.h"
  15. #include "data/data_saved_sublist.h"
  16. #include "data/data_session.h"
  17. #include "data/data_user.h"
  18. #include "data/stickers/data_custom_emoji.h"
  19. #include "dialogs/dialogs_list.h"
  20. #include "dialogs/dialogs_three_state_icon.h"
  21. #include "dialogs/dialogs_quick_action.h"
  22. #include "dialogs/ui/dialogs_video_userpic.h"
  23. #include "history/history.h"
  24. #include "history/history_item.h"
  25. #include "history/history_item_components.h"
  26. #include "history/history_item_helpers.h"
  27. #include "history/history_unread_things.h"
  28. #include "history/view/history_view_item_preview.h"
  29. #include "history/view/history_view_send_action.h"
  30. #include "lang/lang_instance.h"
  31. #include "lang/lang_keys.h"
  32. #include "lottie/lottie_icon.h"
  33. #include "main/main_session.h"
  34. #include "storage/localstorage.h"
  35. #include "support/support_helper.h"
  36. #include "ui/empty_userpic.h"
  37. #include "ui/painter.h"
  38. #include "ui/rect.h"
  39. #include "ui/power_saving.h"
  40. #include "ui/text/format_values.h"
  41. #include "ui/text/text_options.h"
  42. #include "ui/text/text_utilities.h"
  43. #include "ui/unread_badge.h"
  44. #include "ui/unread_badge_paint.h"
  45. #include "styles/style_dialogs.h"
  46. #include "styles/style_widgets.h"
  47. #include "styles/style_window.h"
  48. namespace Dialogs::Ui {
  49. namespace {
  50. const auto kPsaBadgePrefix = "cloud_lng_badge_psa_";
  51. [[nodiscard]] bool ShowUserBotIcon(not_null<UserData*> user) {
  52. return user->isBot()
  53. && !user->isSupport()
  54. && !user->isRepliesChat()
  55. && !user->isVerifyCodes();
  56. }
  57. [[nodiscard]] bool ShowSendActionInDialogs(Data::Thread *thread) {
  58. const auto history = thread ? thread->owningHistory().get() : nullptr;
  59. if (!history) {
  60. return false;
  61. } else if (const auto user = history->peer->asUser()) {
  62. return !user->lastseen().isHidden();
  63. }
  64. return !history->isForum();
  65. }
  66. const style::font &SwipeActionFont(
  67. Dialogs::Ui::QuickDialogActionLabel action,
  68. int availableWidth) {
  69. struct Entry final {
  70. Dialogs::Ui::QuickDialogActionLabel action;
  71. QString langId;
  72. style::font font;
  73. };
  74. static auto Fonts = std::vector<Entry>();
  75. for (auto &entry : Fonts) {
  76. if (entry.action == action) {
  77. if (entry.langId == Lang::GetInstance().id()) {
  78. return entry.font;
  79. }
  80. }
  81. }
  82. constexpr auto kNormalFontSize = 13;
  83. constexpr auto kMinFontSize = 5;
  84. for (auto i = kNormalFontSize; i >= kMinFontSize; --i) {
  85. auto font = style::font(
  86. style::ConvertScale(i, style::Scale()),
  87. st::semiboldFont->flags(),
  88. st::semiboldFont->family());
  89. if (font->width(ResolveQuickDialogLabel(action)) <= availableWidth
  90. || i == kMinFontSize) {
  91. Fonts.emplace_back(Entry{
  92. .action = action,
  93. .langId = Lang::GetInstance().id(),
  94. .font = std::move(font),
  95. });
  96. return Fonts.back().font;
  97. }
  98. }
  99. Unexpected("SwipeActionFont: can't find font.");
  100. }
  101. void PaintRowTopRight(
  102. QPainter &p,
  103. const QString &text,
  104. QRect &rectForName,
  105. const PaintContext &context) {
  106. const auto width = st::dialogsDateFont->width(text);
  107. rectForName.setWidth(rectForName.width() - width - st::dialogsDateSkip);
  108. p.setFont(st::dialogsDateFont);
  109. p.setPen(context.active
  110. ? st::dialogsDateFgActive
  111. : context.selected
  112. ? st::dialogsDateFgOver
  113. : st::dialogsDateFg);
  114. p.drawText(
  115. rectForName.left() + rectForName.width() + st::dialogsDateSkip,
  116. rectForName.top() + st::semiboldFont->height - st::normalFont->descent,
  117. text);
  118. }
  119. int PaintRightButton(QPainter &p, const PaintContext &context) {
  120. if (context.width < st::columnMinimalWidthLeft) {
  121. return 0;
  122. }
  123. if (const auto rightButton = context.rightButton) {
  124. const auto size = rightButton->bg.size() / style::DevicePixelRatio();
  125. const auto left = context.width
  126. - size.width()
  127. - st::dialogRowOpenBotRight;
  128. const auto top = st::dialogRowOpenBotTop;
  129. p.drawImage(
  130. left,
  131. top,
  132. context.active
  133. ? rightButton->activeBg
  134. : context.selected
  135. ? rightButton->selectedBg
  136. : rightButton->bg);
  137. if (rightButton->ripple) {
  138. rightButton->ripple->paint(
  139. p,
  140. left,
  141. top,
  142. size.width() - size.height() / 2,
  143. context.active
  144. ? &st::universalRippleAnimation.color->c
  145. : &st::activeButtonBgRipple->c);
  146. if (rightButton->ripple->empty()) {
  147. rightButton->ripple.reset();
  148. }
  149. }
  150. p.setPen(context.active
  151. ? st::activeButtonBg
  152. : context.selected
  153. ? st::activeButtonFgOver
  154. : st::activeButtonFg);
  155. rightButton->text.draw(p, {
  156. .position = QPoint(
  157. left + size.height() / 2,
  158. top + (st::dialogRowOpenBotHeight - rightButton->text.minHeight()) / 2),
  159. .outerWidth = size.width() - size.height() / 2,
  160. .availableWidth = size.width() - size.height() / 2,
  161. .elisionLines = 1,
  162. });
  163. return size.width() + st::dialogsUnreadPadding;
  164. }
  165. return 0;
  166. }
  167. int PaintBadges(
  168. QPainter &p,
  169. const PaintContext &context,
  170. BadgesState badgesState,
  171. int right,
  172. int top,
  173. bool displayPinnedIcon,
  174. int pinnedIconTop,
  175. bool narrow) {
  176. auto initial = right;
  177. if (badgesState.unread
  178. && !badgesState.unreadCounter
  179. && context.st->unreadMarkDiameter > 0) {
  180. const auto d = context.st->unreadMarkDiameter;
  181. UnreadBadgeStyle st;
  182. PainterHighQualityEnabler hq(p);
  183. const auto rect = QRect(
  184. right - st.size + (st.size - d) / 2,
  185. top + (st.size - d) / 2,
  186. d,
  187. d);
  188. p.setPen(Qt::NoPen);
  189. p.setBrush(badgesState.unreadMuted
  190. ? (context.active
  191. ? st::dialogsUnreadBgMutedActive
  192. : context.selected
  193. ? st::dialogsUnreadBgMutedOver
  194. : st::dialogsUnreadBgMuted)
  195. : (context.active
  196. ? st::dialogsUnreadBgActive
  197. : context.selected
  198. ? st::dialogsUnreadBgOver
  199. : st::dialogsUnreadBg));
  200. p.drawEllipse(rect);
  201. right -= st.size + st.padding;
  202. } else if (badgesState.unread) {
  203. UnreadBadgeStyle st;
  204. st.active = context.active;
  205. st.selected = context.selected;
  206. st.muted = badgesState.unreadMuted;
  207. const auto counter = (badgesState.unreadCounter <= 0)
  208. ? QString()
  209. : !narrow
  210. ? QString::number(badgesState.unreadCounter)
  211. : ((badgesState.mention || badgesState.reaction)
  212. && (badgesState.unreadCounter > 999))
  213. ? (u"99+"_q)
  214. : (badgesState.unreadCounter > 999999)
  215. ? (u"99999+"_q)
  216. : QString::number(badgesState.unreadCounter);
  217. const auto badge = PaintUnreadBadge(p, counter, right, top, st);
  218. right -= badge.width() + st.padding;
  219. } else if (const auto used = PaintRightButton(p, context)) {
  220. return used - st::dialogsUnreadPadding;
  221. } else if (displayPinnedIcon) {
  222. const auto &icon = ThreeStateIcon(
  223. st::dialogsPinnedIcon,
  224. context.active,
  225. context.selected);
  226. icon.paint(p, right - icon.width(), pinnedIconTop, context.width);
  227. right -= icon.width() + st::dialogsUnreadPadding;
  228. }
  229. if (badgesState.mention || badgesState.reaction) {
  230. UnreadBadgeStyle st;
  231. st.sizeId = badgesState.mention
  232. ? UnreadBadgeSize::Dialogs
  233. : UnreadBadgeSize::ReactionInDialogs;
  234. st.active = context.active;
  235. st.selected = context.selected;
  236. st.muted = badgesState.mention
  237. ? badgesState.mentionMuted
  238. : badgesState.reactionMuted;
  239. st.padding = 0;
  240. st.textTop = 0;
  241. const auto counter = QString();
  242. const auto badge = PaintUnreadBadge(p, counter, right, top, st);
  243. ThreeStateIcon(
  244. badgesState.mention
  245. ? st::dialogsUnreadMention
  246. : st::dialogsUnreadReaction,
  247. st.active,
  248. st.selected).paintInCenter(p, badge);
  249. right -= badge.width() + st.padding + st::dialogsUnreadPadding;
  250. }
  251. return (initial - right);
  252. }
  253. void PaintExpandedTopicsBar(QPainter &p, float64 progress) {
  254. auto hq = PainterHighQualityEnabler(p);
  255. const auto radius = st::roundRadiusLarge;
  256. const auto width = st::forumDialogRow.padding.left() / 2;
  257. p.setPen(Qt::NoPen);
  258. p.setBrush(st::dialogsBgActive);
  259. p.drawRoundedRect(
  260. QRectF(
  261. -3. * radius - width * (1. - progress),
  262. st::forumDialogRow.padding.top(),
  263. 3. * radius + width,
  264. st::forumDialogRow.photoSize),
  265. radius,
  266. radius);
  267. }
  268. void PaintNarrowCounter(
  269. QPainter &p,
  270. const PaintContext &context,
  271. BadgesState badgesState) {
  272. const auto top = context.st->padding.top()
  273. + context.st->photoSize
  274. - st::dialogsUnreadHeight;
  275. PaintBadges(
  276. p,
  277. context,
  278. badgesState,
  279. context.st->padding.left() + context.st->photoSize,
  280. top,
  281. false,
  282. 0,
  283. true);
  284. }
  285. int PaintWideCounter(
  286. QPainter &p,
  287. const PaintContext &context,
  288. BadgesState badgesState,
  289. int texttop,
  290. int availableWidth,
  291. bool displayPinnedIcon) {
  292. const auto top = texttop
  293. + st::dialogsTextFont->ascent
  294. - st::dialogsUnreadFont->ascent
  295. - (st::dialogsUnreadHeight - st::dialogsUnreadFont->height) / 2;
  296. const auto used = PaintBadges(
  297. p,
  298. context,
  299. badgesState,
  300. context.width - context.st->padding.right(),
  301. top,
  302. displayPinnedIcon,
  303. texttop,
  304. false);
  305. return availableWidth - used;
  306. }
  307. void PaintFolderEntryText(
  308. Painter &p,
  309. not_null<Data::Folder*> folder,
  310. const PaintContext &context,
  311. QRect rect) {
  312. if (rect.isEmpty()) {
  313. return;
  314. }
  315. folder->validateListEntryCache();
  316. p.setFont(st::dialogsTextFont);
  317. p.setPen(context.active
  318. ? st::dialogsTextFgActive
  319. : context.selected
  320. ? st::dialogsTextFgOver
  321. : st::dialogsTextFg);
  322. folder->listEntryCache().draw(p, {
  323. .position = rect.topLeft(),
  324. .availableWidth = rect.width(),
  325. .palette = &(context.active
  326. ? st::dialogsTextPaletteArchiveActive
  327. : context.selected
  328. ? st::dialogsTextPaletteArchiveOver
  329. : st::dialogsTextPaletteArchive),
  330. .spoiler = Text::DefaultSpoilerCache(),
  331. .now = context.now,
  332. .pausedEmoji = context.paused || On(PowerSaving::kEmojiChat),
  333. .pausedSpoiler = context.paused || On(PowerSaving::kChatSpoiler),
  334. .elisionHeight = rect.height(),
  335. });
  336. }
  337. enum class Flag {
  338. SavedMessages = 0x008,
  339. RepliesMessages = 0x010,
  340. VerifyCodes = 0x020,
  341. AllowUserOnline = 0x040,
  342. TopicJumpRipple = 0x080,
  343. HiddenAuthor = 0x100,
  344. MyNotes = 0x200,
  345. };
  346. inline constexpr bool is_flag_type(Flag) { return true; }
  347. template <typename PaintItemCallback>
  348. void PaintRow(
  349. Painter &p,
  350. not_null<const BasicRow*> row,
  351. QRect geometry,
  352. not_null<Entry*> entry,
  353. VideoUserpic *videoUserpic,
  354. PeerData *from,
  355. PeerBadge &rowBadge,
  356. Fn<void()> customEmojiRepaint,
  357. const Text::String &rowName,
  358. const HiddenSenderInfo *hiddenSenderInfo,
  359. HistoryItem *item,
  360. const Data::Draft *draft,
  361. QDateTime date,
  362. const PaintContext &context,
  363. BadgesState badgesState,
  364. base::flags<Flag> flags,
  365. PaintItemCallback &&paintItemCallback) {
  366. const auto supportMode = entry->session().supportMode();
  367. if (supportMode) {
  368. draft = nullptr;
  369. }
  370. const auto history = entry->asHistory();
  371. const auto thread = entry->asThread();
  372. const auto sublist = entry->asSublist();
  373. auto bg = context.active
  374. ? st::dialogsBgActive
  375. : context.selected
  376. ? st::dialogsBgOver
  377. : context.currentBg;
  378. auto swipeTranslation = 0;
  379. if (history
  380. && context.quickActionContext
  381. && !context.quickActionContext->ripple
  382. && (history->peer->id.value
  383. == context.quickActionContext->data.msgBareId)) {
  384. if (context.quickActionContext->data.translation != 0) {
  385. swipeTranslation = context.quickActionContext->data.translation
  386. * -2;
  387. }
  388. }
  389. if (swipeTranslation) {
  390. p.translate(-swipeTranslation, 0);
  391. }
  392. p.fillRect(geometry, bg);
  393. if (!(flags & Flag::TopicJumpRipple)) {
  394. auto ripple = context.active
  395. ? st::dialogsRippleBgActive
  396. : st::dialogsRippleBg;
  397. row->paintRipple(p, 0, 0, context.width, &ripple->c);
  398. }
  399. if (flags & Flag::SavedMessages) {
  400. EmptyUserpic::PaintSavedMessages(
  401. p,
  402. context.st->padding.left(),
  403. context.st->padding.top(),
  404. context.width,
  405. context.st->photoSize);
  406. } else if (flags & Flag::RepliesMessages) {
  407. EmptyUserpic::PaintRepliesMessages(
  408. p,
  409. context.st->padding.left(),
  410. context.st->padding.top(),
  411. context.width,
  412. context.st->photoSize);
  413. } else if (flags & Flag::HiddenAuthor) {
  414. EmptyUserpic::PaintHiddenAuthor(
  415. p,
  416. context.st->padding.left(),
  417. context.st->padding.top(),
  418. context.width,
  419. context.st->photoSize);
  420. } else if (flags & Flag::MyNotes) {
  421. EmptyUserpic::PaintMyNotes(
  422. p,
  423. context.st->padding.left(),
  424. context.st->padding.top(),
  425. context.width,
  426. context.st->photoSize);
  427. } else if (!from && hiddenSenderInfo) {
  428. hiddenSenderInfo->emptyUserpic.paintCircle(
  429. p,
  430. context.st->padding.left(),
  431. context.st->padding.top(),
  432. context.width,
  433. context.st->photoSize);
  434. } else if (!(flags & Flag::AllowUserOnline)) {
  435. PaintUserpic(
  436. p,
  437. entry,
  438. from,
  439. videoUserpic,
  440. row->userpicView(),
  441. context);
  442. } else {
  443. row->paintUserpic(
  444. p,
  445. entry,
  446. from,
  447. videoUserpic,
  448. context,
  449. (context.narrow
  450. && !badgesState.empty()
  451. && !draft
  452. && item
  453. && !item->isEmpty()));
  454. }
  455. const auto nameleft = context.st->nameLeft;
  456. if (context.topicsExpanded > 0.) {
  457. PaintExpandedTopicsBar(p, context.topicsExpanded);
  458. }
  459. if (context.narrow) {
  460. if (!draft && item && !item->isEmpty()) {
  461. PaintNarrowCounter(p, context, badgesState);
  462. }
  463. return;
  464. }
  465. auto namewidth = context.width - nameleft - context.st->padding.right();
  466. auto rectForName = QRect(
  467. nameleft,
  468. context.st->nameTop,
  469. namewidth,
  470. st::semiboldFont->height);
  471. const auto promoted = (history && history->useTopPromotion())
  472. && !context.search;
  473. const auto verifyInfo = (from && !from->isSelf())
  474. ? from->botVerifyDetails()
  475. : nullptr;
  476. if (promoted) {
  477. const auto type = history->topPromotionType();
  478. const auto custom = type.isEmpty()
  479. ? QString()
  480. : Lang::GetNonDefaultValue(kPsaBadgePrefix + type.toUtf8());
  481. const auto text = type.isEmpty()
  482. ? tr::lng_proxy_sponsor(tr::now)
  483. : custom.isEmpty()
  484. ? tr::lng_badge_psa_default(tr::now)
  485. : custom;
  486. PaintRowTopRight(p, text, rectForName, context);
  487. } else if (verifyInfo) {
  488. if (!rowBadge.ready(verifyInfo)) {
  489. rowBadge.set(
  490. verifyInfo,
  491. from->owner().customEmojiManager().factory(),
  492. customEmojiRepaint);
  493. }
  494. const auto &st = Ui::VerifiedStyle(context);
  495. const auto position = rectForName.topLeft();
  496. const auto skip = rowBadge.drawVerified(p, position, st);
  497. rectForName.setLeft(position.x() + skip + st::dialogsChatTypeSkip);
  498. } else if (from) {
  499. if (const auto chatTypeIcon = ChatTypeIcon(from, context)) {
  500. chatTypeIcon->paint(p, rectForName.topLeft(), context.width);
  501. rectForName.setLeft(rectForName.left()
  502. + chatTypeIcon->width()
  503. + st::dialogsChatTypeSkip);
  504. }
  505. }
  506. auto texttop = context.st->textTop;
  507. if (const auto folder = entry->asFolder()) {
  508. const auto availableWidth = PaintWideCounter(
  509. p,
  510. context,
  511. badgesState,
  512. texttop,
  513. namewidth,
  514. false);
  515. const auto rect = QRect(
  516. nameleft,
  517. texttop,
  518. availableWidth,
  519. st::dialogsTextFont->height);
  520. PaintFolderEntryText(p, folder, context, rect);
  521. } else if (promoted && !history->topPromotionMessage().isEmpty()) {
  522. auto availableWidth = namewidth;
  523. p.setFont(st::dialogsTextFont);
  524. if (history->cloudDraftTextCache().isEmpty()) {
  525. history->cloudDraftTextCache().setText(
  526. st::dialogsTextStyle,
  527. history->topPromotionMessage(),
  528. DialogTextOptions());
  529. }
  530. p.setPen(context.active
  531. ? st::dialogsTextFgActive
  532. : context.selected
  533. ? st::dialogsTextFgOver
  534. : st::dialogsTextFg);
  535. history->cloudDraftTextCache().draw(p, {
  536. .position = { nameleft, texttop },
  537. .availableWidth = availableWidth,
  538. .spoiler = Text::DefaultSpoilerCache(),
  539. .now = context.now,
  540. .pausedEmoji = context.paused || On(PowerSaving::kEmojiChat),
  541. .pausedSpoiler = context.paused || On(PowerSaving::kChatSpoiler),
  542. .elisionLines = 1,
  543. });
  544. } else if (draft
  545. || (supportMode
  546. && entry->session().supportHelper().isOccupiedBySomeone(history))) {
  547. if (!promoted) {
  548. const auto dateString = Ui::FormatDialogsDate(date);
  549. PaintRowTopRight(p, dateString, rectForName, context);
  550. }
  551. auto availableWidth = namewidth;
  552. if (const auto used = PaintRightButton(p, context)) {
  553. availableWidth -= used;
  554. } else if (entry->isPinnedDialog(context.filter)
  555. && (context.filter || !entry->fixedOnTopIndex())) {
  556. auto &icon = ThreeStateIcon(
  557. st::dialogsPinnedIcon,
  558. context.active,
  559. context.selected);
  560. icon.paint(
  561. p,
  562. context.width - context.st->padding.right() - icon.width(),
  563. texttop,
  564. context.width);
  565. availableWidth -= icon.width() + st::dialogsUnreadPadding;
  566. }
  567. p.setFont(st::dialogsTextFont);
  568. auto &color = context.active
  569. ? st::dialogsTextFgServiceActive
  570. : context.selected
  571. ? st::dialogsTextFgServiceOver
  572. : st::dialogsTextFgService;
  573. if (!ShowSendActionInDialogs(thread)
  574. || !thread->sendActionPainter()->paint(
  575. p,
  576. nameleft,
  577. texttop,
  578. availableWidth,
  579. context.width,
  580. color,
  581. context.paused)) {
  582. auto &cache = thread->cloudDraftTextCache();
  583. if (cache.isEmpty()) {
  584. using namespace TextUtilities;
  585. auto draftWrapped = Text::Colorized(
  586. tr::lng_dialogs_text_from_wrapped(
  587. tr::now,
  588. lt_from,
  589. tr::lng_from_draft(tr::now)));
  590. auto draftText = supportMode
  591. ? Text::Colorized(
  592. Support::ChatOccupiedString(history))
  593. : tr::lng_dialogs_text_with_from(
  594. tr::now,
  595. lt_from_part,
  596. std::move(draftWrapped),
  597. lt_message,
  598. DialogsPreviewText({
  599. .text = draft->textWithTags.text,
  600. .entities = ConvertTextTagsToEntities(
  601. draft->textWithTags.tags),
  602. }),
  603. Text::WithEntities);
  604. if (draft && draft->reply) {
  605. auto &data = thread->owner().customEmojiManager();
  606. draftText = Ui::Text::Colorized(
  607. Ui::Text::SingleCustomEmoji(
  608. data.registerInternalEmoji(
  609. st::dialogsMiniReplyIcon,
  610. {},
  611. true))).append(std::move(draftText));
  612. }
  613. const auto context = Core::TextContext({
  614. .session = &thread->session(),
  615. .repaint = customEmojiRepaint,
  616. });
  617. cache.setMarkedText(
  618. st::dialogsTextStyle,
  619. std::move(draftText),
  620. DialogTextOptions(),
  621. context);
  622. }
  623. p.setPen(context.active
  624. ? st::dialogsTextFgActive
  625. : context.selected
  626. ? st::dialogsTextFgOver
  627. : st::dialogsTextFg);
  628. cache.draw(p, {
  629. .position = { nameleft, texttop },
  630. .availableWidth = availableWidth,
  631. .palette = &(supportMode
  632. ? (context.active
  633. ? st::dialogsTextPaletteTakenActive
  634. : context.selected
  635. ? st::dialogsTextPaletteTakenOver
  636. : st::dialogsTextPaletteTaken)
  637. : (context.active
  638. ? st::dialogsTextPaletteDraftActive
  639. : context.selected
  640. ? st::dialogsTextPaletteDraftOver
  641. : st::dialogsTextPaletteDraft)),
  642. .spoiler = Text::DefaultSpoilerCache(),
  643. .now = context.now,
  644. .pausedEmoji = context.paused || On(PowerSaving::kEmojiChat),
  645. .pausedSpoiler = context.paused || On(PowerSaving::kChatSpoiler),
  646. .elisionLines = 1,
  647. });
  648. }
  649. } else if (!item) {
  650. auto availableWidth = namewidth;
  651. if (const auto used = PaintRightButton(p, context)) {
  652. availableWidth -= used;
  653. } else if (entry->isPinnedDialog(context.filter)
  654. && (context.filter || !entry->fixedOnTopIndex())) {
  655. auto &icon = ThreeStateIcon(
  656. st::dialogsPinnedIcon,
  657. context.active,
  658. context.selected);
  659. icon.paint(p, context.width - context.st->padding.right() - icon.width(), texttop, context.width);
  660. availableWidth -= icon.width() + st::dialogsUnreadPadding;
  661. }
  662. auto &color = context.active
  663. ? st::dialogsTextFgServiceActive
  664. : context.selected
  665. ? st::dialogsTextFgServiceOver
  666. : st::dialogsTextFgService;
  667. p.setFont(st::dialogsTextFont);
  668. if (!ShowSendActionInDialogs(thread)
  669. || !thread->sendActionPainter()->paint(
  670. p,
  671. nameleft,
  672. texttop,
  673. availableWidth,
  674. context.width,
  675. color,
  676. context.now)) {
  677. // Empty history
  678. }
  679. } else if (!item->isEmpty()) {
  680. if ((thread || sublist) && !promoted) {
  681. const auto dateString = Ui::FormatDialogsDate(date);
  682. PaintRowTopRight(p, dateString, rectForName, context);
  683. }
  684. paintItemCallback(nameleft, namewidth);
  685. } else if (entry->isPinnedDialog(context.filter)
  686. && (context.filter || !entry->fixedOnTopIndex())) {
  687. auto &icon = ThreeStateIcon(
  688. st::dialogsPinnedIcon,
  689. context.active,
  690. context.selected);
  691. icon.paint(
  692. p,
  693. context.width - context.st->padding.right() - icon.width(),
  694. texttop,
  695. context.width);
  696. }
  697. const auto sendStateIcon = [&]() -> const style::icon* {
  698. if (!thread) {
  699. return nullptr;
  700. } else if (const auto topic = thread->asTopic()
  701. ; !context.search && topic && topic->closed()) {
  702. return &ThreeStateIcon(
  703. st::dialogsLockIcon,
  704. context.active,
  705. context.selected);
  706. } else if (draft) {
  707. if (draft->saveRequestId) {
  708. return &ThreeStateIcon(
  709. st::dialogsSendingIcon,
  710. context.active,
  711. context.selected);
  712. }
  713. } else if (item && !item->isEmpty() && item->needCheck()) {
  714. if (!item->isSending() && !item->hasFailed()) {
  715. if (item->unread(thread)) {
  716. return &ThreeStateIcon(
  717. st::dialogsSentIcon,
  718. context.active,
  719. context.selected);
  720. }
  721. return &ThreeStateIcon(
  722. st::dialogsReceivedIcon,
  723. context.active,
  724. context.selected);
  725. }
  726. return &ThreeStateIcon(
  727. st::dialogsSendingIcon,
  728. context.active,
  729. context.selected);
  730. }
  731. return nullptr;
  732. }();
  733. if (sendStateIcon) {
  734. rectForName.setWidth(rectForName.width() - st::dialogsSendStateSkip);
  735. sendStateIcon->paint(p, rectForName.topLeft() + QPoint(rectForName.width(), 0), context.width);
  736. }
  737. p.setFont(st::semiboldFont);
  738. const auto paintPeerBadge = [&](int rowNameWidth) {
  739. const auto badgeWidth = rowBadge.drawGetWidth(p, {
  740. .peer = from,
  741. .rectForName = rectForName,
  742. .nameWidth = rowNameWidth,
  743. .outerWidth = context.width,
  744. .verified = (context.active
  745. ? &st::dialogsVerifiedIconActive
  746. : context.selected
  747. ? &st::dialogsVerifiedIconOver
  748. : &st::dialogsVerifiedIcon),
  749. .premium = &ThreeStateIcon(
  750. st::dialogsPremiumIcon,
  751. context.active,
  752. context.selected),
  753. .scam = (context.active
  754. ? &st::dialogsScamFgActive
  755. : context.selected
  756. ? &st::dialogsScamFgOver
  757. : &st::dialogsScamFg),
  758. .premiumFg = (context.active
  759. ? &st::dialogsVerifiedIconBgActive
  760. : context.selected
  761. ? &st::dialogsVerifiedIconBgOver
  762. : &st::dialogsVerifiedIconBg),
  763. .customEmojiRepaint = customEmojiRepaint,
  764. .now = context.now,
  765. .paused = context.paused,
  766. });
  767. rectForName.setWidth(rectForName.width() - badgeWidth);
  768. };
  769. if (flags
  770. & (Flag::SavedMessages
  771. | Flag::RepliesMessages
  772. | Flag::VerifyCodes
  773. | Flag::HiddenAuthor
  774. | Flag::MyNotes)) {
  775. auto text = (flags & Flag::SavedMessages)
  776. ? tr::lng_saved_messages(tr::now)
  777. : (flags & Flag::RepliesMessages)
  778. ? tr::lng_replies_messages(tr::now)
  779. : (flags & Flag::VerifyCodes)
  780. ? tr::lng_verification_codes(tr::now)
  781. : (flags & Flag::MyNotes)
  782. ? tr::lng_my_notes(tr::now)
  783. : tr::lng_hidden_author_messages(tr::now);
  784. const auto textWidth = st::semiboldFont->width(text);
  785. if (!context.search && (flags & Flag::VerifyCodes)) {
  786. paintPeerBadge(textWidth);
  787. }
  788. if (textWidth > rectForName.width()) {
  789. text = st::semiboldFont->elided(text, rectForName.width());
  790. }
  791. p.setPen(context.active
  792. ? st::dialogsNameFgActive
  793. : context.selected
  794. ? st::dialogsNameFgOver
  795. : st::dialogsNameFg);
  796. p.drawTextLeft(
  797. rectForName.left(),
  798. rectForName.top(),
  799. context.width,
  800. text);
  801. } else if (from) {
  802. if ((history || sublist) && !context.search) {
  803. paintPeerBadge(rowName.maxWidth());
  804. }
  805. p.setPen(context.active
  806. ? st::dialogsNameFgActive
  807. : context.selected
  808. ? st::dialogsNameFgOver
  809. : st::dialogsNameFg);
  810. rowName.draw(p, {
  811. .position = rectForName.topLeft(),
  812. .availableWidth = rectForName.width(),
  813. .elisionLines = 1,
  814. });
  815. } else if (hiddenSenderInfo) {
  816. p.setPen(context.active
  817. ? st::dialogsNameFgActive
  818. : context.selected
  819. ? st::dialogsNameFgOver
  820. : st::dialogsNameFg);
  821. hiddenSenderInfo->nameText().draw(p, {
  822. .position = rectForName.topLeft(),
  823. .availableWidth = rectForName.width(),
  824. .elisionLines = 1,
  825. });
  826. } else {
  827. p.setPen(context.active
  828. ? st::dialogsNameFgActive
  829. : entry->folder()
  830. ? (context.selected
  831. ? st::dialogsArchiveFgOver
  832. : st::dialogsArchiveFg)
  833. : (context.selected
  834. ? st::dialogsNameFgOver
  835. : st::dialogsNameFg));
  836. rowName.draw(p, {
  837. .position = rectForName.topLeft(),
  838. .availableWidth = rectForName.width(),
  839. .elisionLines = 1,
  840. });
  841. }
  842. if (const auto tags = context.chatsFilterTags) {
  843. auto left = nameleft;
  844. for (const auto &tag : *tags) {
  845. p.drawImage(left, context.st->tagTop, *tag);
  846. left += st::dialogRowFilterTagSkip
  847. + (tag->width() / style::DevicePixelRatio());
  848. }
  849. }
  850. if (swipeTranslation) {
  851. p.translate(swipeTranslation, 0);
  852. const auto swipeActionRect = QRect(
  853. rect::right(geometry) - swipeTranslation,
  854. geometry.y(),
  855. swipeTranslation,
  856. geometry.height());
  857. p.setClipRegion(swipeActionRect);
  858. const auto labelType = ResolveQuickDialogLabel(
  859. history,
  860. context.quickActionContext->action,
  861. context.filter);
  862. p.fillRect(swipeActionRect, ResolveQuickActionBg(labelType));
  863. if (context.quickActionContext->data.reachRatio) {
  864. p.setPen(Qt::NoPen);
  865. p.setBrush(ResolveQuickActionBgActive(labelType));
  866. const auto r = swipeTranslation
  867. * context.quickActionContext->data.reachRatio;
  868. const auto offset = st::dialogsQuickActionSize
  869. + st::dialogsQuickActionSize / 2.;
  870. p.drawEllipse(QPointF(geometry.width() - offset, offset), r, r);
  871. }
  872. const auto quickWidth = st::dialogsQuickActionSize * 3;
  873. DrawQuickAction(
  874. p,
  875. QRect(
  876. rect::right(geometry) - quickWidth,
  877. geometry.y(),
  878. quickWidth,
  879. geometry.height()),
  880. context.quickActionContext->icon.get(),
  881. labelType);
  882. p.setClipping(false);
  883. }
  884. if (const auto quick = context.quickActionContext;
  885. quick && quick->ripple && quick->rippleFg) {
  886. const auto labelType = ResolveQuickDialogLabel(
  887. history,
  888. context.quickActionContext->action,
  889. context.filter);
  890. const auto ripple = ResolveQuickActionBg(labelType);
  891. const auto size = st::dialogsQuickActionRippleSize;
  892. const auto x = geometry.width() - size;
  893. quick->ripple->paint(p, x, 0, size, &ripple->c);
  894. quick->rippleFg->paint(p, x, 0, size, &st::premiumButtonFg->c);
  895. if (quick->ripple->empty()) {
  896. quick->ripple.reset();
  897. }
  898. if (quick->rippleFg->empty()) {
  899. quick->rippleFg.reset();
  900. }
  901. }
  902. }
  903. } // namespace
  904. const style::icon *ChatTypeIcon(not_null<PeerData*> peer) {
  905. return ChatTypeIcon(peer, {
  906. .st = &st::defaultDialogRow,
  907. .currentBg = st::windowBg,
  908. });
  909. }
  910. const style::icon *ChatTypeIcon(
  911. not_null<PeerData*> peer,
  912. const PaintContext &context) {
  913. if (const auto user = peer->asUser()) {
  914. if (ShowUserBotIcon(user)) {
  915. return &ThreeStateIcon(
  916. st::dialogsBotIcon,
  917. context.active,
  918. context.selected);
  919. }
  920. } else if (peer->isBroadcast()) {
  921. return &ThreeStateIcon(
  922. st::dialogsChannelIcon,
  923. context.active,
  924. context.selected);
  925. } else if (peer->isForum()) {
  926. return &ThreeStateIcon(
  927. st::dialogsForumIcon,
  928. context.active,
  929. context.selected);
  930. } else {
  931. return &ThreeStateIcon(
  932. st::dialogsChatIcon,
  933. context.active,
  934. context.selected);
  935. }
  936. return nullptr;
  937. }
  938. const style::VerifiedBadge &VerifiedStyle(const PaintContext &context) {
  939. return context.active
  940. ? st::dialogsVerifiedColorsActive
  941. : context.selected
  942. ? st::dialogsVerifiedColorsOver
  943. : st::dialogsVerifiedColors;
  944. }
  945. void RowPainter::Paint(
  946. Painter &p,
  947. not_null<const Row*> row,
  948. VideoUserpic *videoUserpic,
  949. const PaintContext &context) {
  950. const auto entry = row->entry();
  951. const auto history = row->history();
  952. const auto thread = row->thread();
  953. const auto sublist = row->sublist();
  954. const auto peer = history ? history->peer.get() : nullptr;
  955. const auto badgesState = entry->chatListBadgesState();
  956. entry->chatListPreloadData(); // Allow chat list message resolve.
  957. const auto item = entry->chatListMessage();
  958. const auto cloudDraft = [&]() -> const Data::Draft*{
  959. if (!thread) {
  960. return nullptr;
  961. }
  962. if ((!peer || !peer->isForum()) && (!item || !badgesState.unread)) {
  963. // Draw item, if there are unread messages.
  964. const auto draft = thread->owningHistory()->cloudDraft(
  965. thread->topicRootId());
  966. if (!Data::DraftIsNull(draft)) {
  967. return draft;
  968. }
  969. }
  970. return nullptr;
  971. }();
  972. const auto displayDate = [&] {
  973. if (item) {
  974. if (cloudDraft) {
  975. return (item->date() > cloudDraft->date)
  976. ? ItemDateTime(item)
  977. : base::unixtime::parse(cloudDraft->date);
  978. }
  979. return ItemDateTime(item);
  980. }
  981. return cloudDraft
  982. ? base::unixtime::parse(cloudDraft->date)
  983. : QDateTime();
  984. }();
  985. const auto displayPinnedIcon = badgesState.empty()
  986. && entry->isPinnedDialog(context.filter)
  987. && (context.filter || !entry->fixedOnTopIndex());
  988. const auto from = history
  989. ? (history->peer->migrateTo()
  990. ? history->peer->migrateTo()
  991. : history->peer.get())
  992. : sublist
  993. ? sublist->peer().get()
  994. : nullptr;
  995. const auto allowUserOnline = true;// !context.narrow || badgesState.empty();
  996. const auto flags = (allowUserOnline ? Flag::AllowUserOnline : Flag(0))
  997. | ((sublist && from->isSelf())
  998. ? Flag::MyNotes
  999. : (peer && peer->isSelf())
  1000. ? Flag::SavedMessages
  1001. : Flag(0))
  1002. | ((from && from->isRepliesChat())
  1003. ? Flag::RepliesMessages
  1004. : Flag(0))
  1005. | ((from && from->isVerifyCodes())
  1006. ? Flag::VerifyCodes
  1007. : Flag(0))
  1008. | ((sublist && from->isSavedHiddenAuthor())
  1009. ? Flag::HiddenAuthor
  1010. : Flag(0))
  1011. | (row->topicJumpRipple() ? Flag::TopicJumpRipple : Flag(0));
  1012. const auto paintItemCallback = [&](int nameleft, int namewidth) {
  1013. const auto texttop = context.st->textTop;
  1014. const auto availableWidth = PaintWideCounter(
  1015. p,
  1016. context,
  1017. badgesState,
  1018. texttop,
  1019. namewidth,
  1020. displayPinnedIcon);
  1021. const auto &color = context.active
  1022. ? st::dialogsTextFgServiceActive
  1023. : context.selected
  1024. ? st::dialogsTextFgServiceOver
  1025. : st::dialogsTextFgService;
  1026. auto rect = QRect(
  1027. nameleft,
  1028. texttop,
  1029. availableWidth,
  1030. st::dialogsTextFont->height);
  1031. const auto actionWasPainted = ShowSendActionInDialogs(thread)
  1032. ? thread->sendActionPainter()->paint(
  1033. p,
  1034. rect.x(),
  1035. rect.y(),
  1036. rect.width(),
  1037. context.width,
  1038. color,
  1039. context.now)
  1040. : false;
  1041. const auto view = actionWasPainted
  1042. ? nullptr
  1043. : thread
  1044. ? &thread->lastItemDialogsView()
  1045. : sublist
  1046. ? &sublist->lastItemDialogsView()
  1047. : nullptr;
  1048. if (view) {
  1049. const auto forum = context.st->topicsHeight
  1050. ? row->history()->peer->forum()
  1051. : nullptr;
  1052. if (!view->prepared(item, forum)) {
  1053. view->prepare(
  1054. item,
  1055. forum,
  1056. [=] { entry->updateChatListEntry(); },
  1057. {});
  1058. }
  1059. if (forum) {
  1060. rect.setHeight(context.st->topicsHeight + rect.height());
  1061. }
  1062. view->paint(p, rect, context);
  1063. }
  1064. };
  1065. PaintRow(
  1066. p,
  1067. row,
  1068. QRect(0, 0, context.width, row->height()),
  1069. entry,
  1070. videoUserpic,
  1071. from,
  1072. entry->chatListPeerBadge(),
  1073. [=] { entry->updateChatListEntry(); },
  1074. entry->chatListNameText(),
  1075. nullptr,
  1076. item,
  1077. cloudDraft,
  1078. displayDate,
  1079. context,
  1080. badgesState,
  1081. flags,
  1082. paintItemCallback);
  1083. }
  1084. void RowPainter::Paint(
  1085. Painter &p,
  1086. not_null<const FakeRow*> row,
  1087. const PaintContext &context) {
  1088. const auto item = row->item();
  1089. const auto topic = context.forum ? row->topic() : nullptr;
  1090. const auto history = topic ? nullptr : item->history().get();
  1091. const auto entry = topic ? (Entry*)topic : (Entry*)history;
  1092. auto cloudDraft = nullptr;
  1093. const auto from = [&] {
  1094. const auto in = row->searchInChat();
  1095. return (topic && (in.topic() != topic))
  1096. ? nullptr
  1097. : in
  1098. ? item->displayFrom()
  1099. : history->peer->migrateTo()
  1100. ? history->peer->migrateTo()
  1101. : history->peer.get();
  1102. }();
  1103. const auto hiddenSenderInfo = [&]() -> const HiddenSenderInfo* {
  1104. if (const auto searchChat = row->searchInChat()) {
  1105. if (const auto peer = searchChat.peer()) {
  1106. if (const auto forwarded = item->Get<HistoryMessageForwarded>()) {
  1107. if (peer->isSelf() || forwarded->imported) {
  1108. return forwarded->savedFromHiddenSenderInfo.get()
  1109. ? forwarded->savedFromHiddenSenderInfo.get()
  1110. : forwarded->originalHiddenSenderInfo.get();
  1111. }
  1112. }
  1113. }
  1114. }
  1115. return nullptr;
  1116. }();
  1117. auto previewOptions = [&]() -> HistoryView::ToPreviewOptions {
  1118. if (topic) {
  1119. return {};
  1120. } else if (const auto searchChat = row->searchInChat()) {
  1121. if (const auto peer = searchChat.peer()) {
  1122. if (!peer->isChannel() || peer->isMegagroup()) {
  1123. return { .hideSender = true };
  1124. }
  1125. }
  1126. }
  1127. return {};
  1128. }();
  1129. previewOptions.ignoreGroup = true;
  1130. const auto badgesState = context.displayUnreadInfo
  1131. ? entry->chatListBadgesState()
  1132. : BadgesState();
  1133. const auto displayPinnedIcon = false;
  1134. const auto paintItemCallback = [&](int nameleft, int namewidth) {
  1135. const auto texttop = context.st->textTop;
  1136. const auto availableWidth = PaintWideCounter(
  1137. p,
  1138. context,
  1139. badgesState,
  1140. texttop,
  1141. namewidth,
  1142. displayPinnedIcon);
  1143. const auto itemRect = QRect(
  1144. nameleft,
  1145. texttop,
  1146. availableWidth,
  1147. st::dialogsTextFont->height);
  1148. auto &view = row->itemView();
  1149. if (!view.prepared(item, nullptr)) {
  1150. view.prepare(item, nullptr, row->repaint(), previewOptions);
  1151. }
  1152. view.paint(p, itemRect, context);
  1153. };
  1154. const auto showSavedMessages = history
  1155. && history->peer->isSelf()
  1156. && !row->searchInChat();
  1157. const auto showRepliesMessages = history
  1158. && history->peer->isRepliesChat()
  1159. && !row->searchInChat();
  1160. const auto showVerifyCodes = history
  1161. && history->peer->isVerifyCodes()
  1162. && !row->searchInChat();
  1163. const auto flags = (showSavedMessages ? Flag::SavedMessages : Flag(0))
  1164. | (showRepliesMessages ? Flag::RepliesMessages : Flag(0))
  1165. | (showVerifyCodes ? Flag::VerifyCodes : Flag(0));
  1166. PaintRow(
  1167. p,
  1168. row,
  1169. QRect(0, 0, context.width, context.st->height),
  1170. entry,
  1171. nullptr,
  1172. from,
  1173. row->badge(),
  1174. row->repaint(),
  1175. row->name(),
  1176. hiddenSenderInfo,
  1177. item,
  1178. cloudDraft,
  1179. ItemDateTime(item),
  1180. context,
  1181. badgesState,
  1182. flags,
  1183. paintItemCallback);
  1184. }
  1185. QRect RowPainter::SendActionAnimationRect(
  1186. not_null<const style::DialogRow*> st,
  1187. int animationLeft,
  1188. int animationWidth,
  1189. int animationHeight,
  1190. int fullWidth,
  1191. bool textUpdated) {
  1192. const auto nameleft = st->nameLeft;
  1193. const auto namewidth = fullWidth - nameleft - st->padding.right();
  1194. const auto texttop = st->textTop;
  1195. return QRect(
  1196. nameleft + (textUpdated ? 0 : animationLeft),
  1197. texttop,
  1198. textUpdated ? namewidth : animationWidth,
  1199. animationHeight);
  1200. }
  1201. void PaintCollapsedRow(
  1202. Painter &p,
  1203. const BasicRow &row,
  1204. Data::Folder *folder,
  1205. const QString &text,
  1206. int unread,
  1207. const PaintContext &context) {
  1208. p.fillRect(
  1209. QRect{ 0, 0, context.width, st::dialogsImportantBarHeight },
  1210. context.selected ? st::dialogsBgOver : context.currentBg);
  1211. row.paintRipple(p, 0, 0, context.width);
  1212. const auto unreadTop = (st::dialogsImportantBarHeight - st::dialogsUnreadHeight) / 2;
  1213. if (!context.narrow || !folder) {
  1214. p.setFont(st::semiboldFont);
  1215. p.setPen(st::dialogsNameFg);
  1216. const auto textBaseline = unreadTop
  1217. + (st::dialogsUnreadHeight - st::dialogsUnreadFont->height) / 2
  1218. + st::dialogsUnreadFont->ascent;
  1219. const auto left = context.narrow
  1220. ? ((context.width - st::semiboldFont->width(text)) / 2)
  1221. : context.st->padding.left();
  1222. p.drawText(left, textBaseline, text);
  1223. } else {
  1224. folder->paintUserpic(
  1225. p,
  1226. (context.width - st::dialogsUnreadHeight) / 2,
  1227. unreadTop,
  1228. st::dialogsUnreadHeight);
  1229. }
  1230. if (!context.narrow && unread) {
  1231. const auto unreadRight = context.width - context.st->padding.right();
  1232. UnreadBadgeStyle st;
  1233. st.muted = true;
  1234. PaintUnreadBadge(
  1235. p,
  1236. QString::number(unread),
  1237. unreadRight,
  1238. unreadTop,
  1239. st);
  1240. }
  1241. }
  1242. } // namespace Dialogs::Ui