history_item_components.cpp 35 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276
  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 "history/history_item_components.h"
  8. #include "api/api_text_entities.h"
  9. #include "base/qt/qt_key_modifiers.h"
  10. #include "base/options.h"
  11. #include "lang/lang_keys.h"
  12. #include "ui/effects/ripple_animation.h"
  13. #include "ui/effects/spoiler_mess.h"
  14. #include "ui/image/image.h"
  15. #include "ui/toast/toast.h"
  16. #include "ui/text/format_values.h"
  17. #include "ui/text/text_options.h"
  18. #include "ui/text/text_utilities.h"
  19. #include "ui/chat/chat_style.h"
  20. #include "ui/chat/chat_theme.h"
  21. #include "ui/painter.h"
  22. #include "ui/rect.h"
  23. #include "ui/power_saving.h"
  24. #include "history/history.h"
  25. #include "history/history_item.h"
  26. #include "history/history_item_helpers.h"
  27. #include "history/view/history_view_message.h" // FromNameFg.
  28. #include "history/view/history_view_service_message.h"
  29. #include "history/view/media/history_view_document.h"
  30. #include "core/click_handler_types.h"
  31. #include "core/ui_integration.h"
  32. #include "layout/layout_position.h"
  33. #include "mainwindow.h"
  34. #include "media/audio/media_audio.h"
  35. #include "media/player/media_player_instance.h"
  36. #include "data/business/data_shortcut_messages.h"
  37. #include "data/components/scheduled_messages.h"
  38. #include "data/stickers/data_custom_emoji.h"
  39. #include "data/data_channel.h"
  40. #include "data/data_media_types.h"
  41. #include "data/data_session.h"
  42. #include "data/data_user.h"
  43. #include "data/data_file_origin.h"
  44. #include "data/data_document.h"
  45. #include "data/data_web_page.h"
  46. #include "data/data_file_click_handler.h"
  47. #include "data/data_session.h"
  48. #include "data/data_stories.h"
  49. #include "main/main_session.h"
  50. #include "window/window_session_controller.h"
  51. #include "api/api_bot.h"
  52. #include "support/support_helper.h"
  53. #include "styles/style_boxes.h"
  54. #include "styles/style_chat.h"
  55. #include "styles/style_dialogs.h" // dialogsMiniReplyStory.
  56. #include "styles/style_settings.h"
  57. #include "styles/style_widgets.h"
  58. #include <QtGui/QGuiApplication>
  59. namespace {
  60. const auto kPsaForwardedPrefix = "cloud_lng_forwarded_psa_";
  61. base::options::toggle FastButtonsModeOption({
  62. .id = kOptionFastButtonsMode,
  63. .name = "Fast buttons mode",
  64. .description = "Trigger inline keyboard buttons by 1-9 keyboard keys.",
  65. });
  66. } // namespace
  67. const char kOptionFastButtonsMode[] = "fast-buttons-mode";
  68. bool FastButtonsMode() {
  69. return FastButtonsModeOption.value();
  70. }
  71. void HistoryMessageVia::create(
  72. not_null<Data::Session*> owner,
  73. UserId userId) {
  74. bot = owner->user(userId);
  75. maxWidth = st::msgServiceNameFont->width(
  76. tr::lng_inline_bot_via(
  77. tr::now,
  78. lt_inline_bot,
  79. '@' + bot->username()));
  80. link = std::make_shared<LambdaClickHandler>([bot = this->bot](
  81. ClickContext context) {
  82. const auto my = context.other.value<ClickHandlerContext>();
  83. if (const auto controller = my.sessionWindow.get()) {
  84. if (base::IsCtrlPressed()) {
  85. controller->showPeerInfo(bot);
  86. return;
  87. } else if (!bot->isBot()
  88. || bot->botInfo->inlinePlaceholder.isEmpty()) {
  89. controller->showPeerHistory(
  90. bot->id,
  91. Window::SectionShow::Way::Forward);
  92. return;
  93. }
  94. }
  95. const auto delegate = my.elementDelegate
  96. ? my.elementDelegate()
  97. : nullptr;
  98. if (delegate) {
  99. delegate->elementHandleViaClick(bot);
  100. }
  101. });
  102. }
  103. void HistoryMessageVia::resize(int32 availw) const {
  104. if (availw < 0) {
  105. text = QString();
  106. width = 0;
  107. } else {
  108. text = tr::lng_inline_bot_via(
  109. tr::now,
  110. lt_inline_bot,
  111. '@' + bot->username());
  112. if (availw < maxWidth) {
  113. text = st::msgServiceNameFont->elided(text, availw);
  114. width = st::msgServiceNameFont->width(text);
  115. } else if (width < maxWidth) {
  116. width = maxWidth;
  117. }
  118. }
  119. }
  120. HiddenSenderInfo::HiddenSenderInfo(
  121. const QString &name,
  122. bool external,
  123. std::optional<uint8> colorIndex)
  124. : name(name)
  125. , colorIndex(colorIndex.value_or(
  126. Data::DecideColorIndex(Data::FakePeerIdForJustName(name))))
  127. , emptyUserpic(
  128. Ui::EmptyUserpic::UserpicColor(this->colorIndex),
  129. (external
  130. ? Ui::EmptyUserpic::ExternalName()
  131. : name)) {
  132. Expects(!name.isEmpty());
  133. const auto parts = name.trimmed().split(' ', Qt::SkipEmptyParts);
  134. firstName = parts[0];
  135. for (const auto &part : parts.mid(1)) {
  136. if (!lastName.isEmpty()) {
  137. lastName.append(' ');
  138. }
  139. lastName.append(part);
  140. }
  141. }
  142. const Ui::Text::String &HiddenSenderInfo::nameText() const {
  143. if (_nameText.isEmpty()) {
  144. _nameText.setText(st::msgNameStyle, name, Ui::NameTextOptions());
  145. }
  146. return _nameText;
  147. }
  148. ClickHandlerPtr HiddenSenderInfo::ForwardClickHandler() {
  149. static const auto hidden = std::make_shared<LambdaClickHandler>([](
  150. ClickContext context) {
  151. const auto my = context.other.value<ClickHandlerContext>();
  152. const auto weak = my.sessionWindow;
  153. if (const auto strong = weak.get()) {
  154. strong->showToast(tr::lng_forwarded_hidden(tr::now));
  155. }
  156. });
  157. return hidden;
  158. }
  159. bool HiddenSenderInfo::paintCustomUserpic(
  160. Painter &p,
  161. Ui::PeerUserpicView &view,
  162. int x,
  163. int y,
  164. int outerWidth,
  165. int size) const {
  166. Expects(!customUserpic.empty());
  167. auto valid = true;
  168. if (!customUserpic.isCurrentView(view.cloud)) {
  169. view.cloud = customUserpic.createView();
  170. valid = false;
  171. }
  172. const auto image = *view.cloud;
  173. if (image.isNull()) {
  174. emptyUserpic.paintCircle(p, x, y, outerWidth, size);
  175. return valid;
  176. }
  177. Ui::ValidateUserpicCache(
  178. view,
  179. image.isNull() ? nullptr : &image,
  180. image.isNull() ? &emptyUserpic : nullptr,
  181. size * style::DevicePixelRatio(),
  182. false);
  183. p.drawImage(QRect(x, y, size, size), view.cached);
  184. return valid;
  185. }
  186. void HistoryMessageForwarded::create(
  187. const HistoryMessageVia *via,
  188. not_null<const HistoryItem*> item) const {
  189. auto phrase = TextWithEntities();
  190. auto context = Core::TextContext({
  191. .session = &item->history()->session(),
  192. });
  193. const auto fromChannel = originalSender
  194. && originalSender->isChannel()
  195. && !originalSender->isMegagroup();
  196. const auto name = TextWithEntities{
  197. .text = (originalSender
  198. ? originalSender->name()
  199. : originalHiddenSenderInfo->name)
  200. };
  201. if (const auto copy = originalSender) {
  202. context.repaint = [=] {
  203. // It is important to capture here originalSender by value,
  204. // not capture the HistoryMessageForwarded* and read the
  205. // originalSender field, because the components themselves
  206. // get moved from place to place and the captured `this`
  207. // pointer may become invalid, resulting in a crash.
  208. copy->owner().requestItemRepaint(item);
  209. };
  210. phrase = Ui::Text::SingleCustomEmoji(
  211. copy->owner().customEmojiManager().peerUserpicEmojiData(
  212. copy,
  213. st::fwdTextUserpicPadding));
  214. }
  215. if (!originalPostAuthor.isEmpty()) {
  216. phrase.append(
  217. tr::lng_forwarded_signed(
  218. tr::now,
  219. lt_channel,
  220. name,
  221. lt_user,
  222. { .text = originalPostAuthor },
  223. Ui::Text::WithEntities));
  224. } else {
  225. phrase.append(name);
  226. }
  227. if (story) {
  228. phrase = tr::lng_forwarded_story(
  229. tr::now,
  230. lt_user,
  231. Ui::Text::Wrapped(phrase, EntityType::CustomUrl, QString()), // Link 1.
  232. Ui::Text::WithEntities);
  233. } else if (via && psaType.isEmpty()) {
  234. const auto linkData = Ui::Text::Link(
  235. QString(),
  236. 1).entities.front().data(); // Link 1.
  237. if (fromChannel) {
  238. phrase = tr::lng_forwarded_channel_via(
  239. tr::now,
  240. lt_channel,
  241. Ui::Text::Wrapped(phrase, EntityType::CustomUrl, linkData), // Link 1.
  242. lt_inline_bot,
  243. Ui::Text::Link('@' + via->bot->username(), 2), // Link 2.
  244. Ui::Text::WithEntities);
  245. } else {
  246. phrase = tr::lng_forwarded_via(
  247. tr::now,
  248. lt_user,
  249. Ui::Text::Wrapped(phrase, EntityType::CustomUrl, linkData), // Link 1.
  250. lt_inline_bot,
  251. Ui::Text::Link('@' + via->bot->username(), 2), // Link 2.
  252. Ui::Text::WithEntities);
  253. }
  254. } else {
  255. if (fromChannel || !psaType.isEmpty()) {
  256. auto custom = psaType.isEmpty()
  257. ? QString()
  258. : Lang::GetNonDefaultValue(
  259. kPsaForwardedPrefix + psaType.toUtf8());
  260. if (!custom.isEmpty()) {
  261. custom = custom.replace("{channel}", phrase.text);
  262. const auto index = int(custom.indexOf(phrase.text));
  263. const auto size = int(phrase.text.size());
  264. phrase = TextWithEntities{
  265. .text = custom,
  266. .entities = {{ EntityType::CustomUrl, index, size, {} }},
  267. };
  268. } else {
  269. phrase = (psaType.isEmpty()
  270. ? tr::lng_forwarded_channel
  271. : tr::lng_forwarded_psa_default)(
  272. tr::now,
  273. lt_channel,
  274. Ui::Text::Wrapped(
  275. phrase,
  276. EntityType::CustomUrl,
  277. QString()), // Link 1.
  278. Ui::Text::WithEntities);
  279. }
  280. } else {
  281. phrase = tr::lng_forwarded(
  282. tr::now,
  283. lt_user,
  284. Ui::Text::Wrapped(phrase, EntityType::CustomUrl, QString()), // Link 1.
  285. Ui::Text::WithEntities);
  286. }
  287. }
  288. text.setMarkedText(st::fwdTextStyle, phrase, kMarkupTextOptions, context);
  289. text.setLink(1, fromChannel
  290. ? JumpToMessageClickHandler(originalSender, originalId)
  291. : originalSender
  292. ? originalSender->openLink()
  293. : HiddenSenderInfo::ForwardClickHandler());
  294. if (via) {
  295. text.setLink(2, via->link);
  296. }
  297. }
  298. ReplyFields ReplyFields::clone(not_null<HistoryItem*> parent) const {
  299. return {
  300. .quote = quote,
  301. .externalMedia = (externalMedia
  302. ? externalMedia->clone(parent)
  303. : nullptr),
  304. .externalSenderId = externalSenderId,
  305. .externalSenderName = externalSenderName,
  306. .externalPostAuthor = externalPostAuthor,
  307. .externalPeerId = externalPeerId,
  308. .messageId = messageId,
  309. .topMessageId = topMessageId,
  310. .storyId = storyId,
  311. .quoteOffset = quoteOffset,
  312. .manualQuote = manualQuote,
  313. .topicPost = topicPost,
  314. };
  315. }
  316. ReplyFields ReplyFieldsFromMTP(
  317. not_null<HistoryItem*> item,
  318. const MTPMessageReplyHeader &reply) {
  319. return reply.match([&](const MTPDmessageReplyHeader &data) {
  320. auto result = ReplyFields();
  321. if (const auto peer = data.vreply_to_peer_id()) {
  322. result.externalPeerId = peerFromMTP(*peer);
  323. }
  324. const auto owner = &item->history()->owner();
  325. if (const auto id = data.vreply_to_msg_id().value_or_empty()) {
  326. result.messageId = data.is_reply_to_scheduled()
  327. ? owner->session().scheduledMessages().localMessageId(id)
  328. : item->shortcutId()
  329. ? owner->shortcutMessages().localMessageId(id)
  330. : id;
  331. result.topMessageId
  332. = data.vreply_to_top_id().value_or(result.messageId.bare);
  333. result.topicPost = data.is_forum_topic() ? 1 : 0;
  334. }
  335. if (const auto header = data.vreply_from()) {
  336. const auto &data = header->data();
  337. result.externalPostAuthor
  338. = qs(data.vpost_author().value_or_empty());
  339. result.externalSenderId = data.vfrom_id()
  340. ? peerFromMTP(*data.vfrom_id())
  341. : PeerId();
  342. result.externalSenderName
  343. = qs(data.vfrom_name().value_or_empty());
  344. }
  345. if (const auto media = data.vreply_media()) {
  346. result.externalMedia = HistoryItem::CreateMedia(item, *media);
  347. }
  348. result.quote = TextWithEntities{
  349. qs(data.vquote_text().value_or_empty()),
  350. Api::EntitiesFromMTP(
  351. &owner->session(),
  352. data.vquote_entities().value_or_empty()),
  353. };
  354. result.quoteOffset = data.vquote_offset().value_or_empty();
  355. result.manualQuote = data.is_quote() ? 1 : 0;
  356. return result;
  357. }, [&](const MTPDmessageReplyStoryHeader &data) {
  358. return ReplyFields{
  359. .externalPeerId = peerFromMTP(data.vpeer()),
  360. .storyId = data.vstory_id().v,
  361. };
  362. });
  363. }
  364. FullReplyTo ReplyToFromMTP(
  365. not_null<History*> history,
  366. const MTPInputReplyTo &reply) {
  367. return reply.match([&](const MTPDinputReplyToMessage &data) {
  368. auto result = FullReplyTo{
  369. .messageId = { history->peer->id, data.vreply_to_msg_id().v },
  370. };
  371. if (const auto peer = data.vreply_to_peer_id()) {
  372. const auto parsed = Data::PeerFromInputMTP(
  373. &history->owner(),
  374. *peer);
  375. if (!parsed) {
  376. return FullReplyTo();
  377. }
  378. result.messageId.peer = parsed->id;
  379. }
  380. result.topicRootId = data.vtop_msg_id().value_or_empty();
  381. result.quote = TextWithEntities{
  382. qs(data.vquote_text().value_or_empty()),
  383. Api::EntitiesFromMTP(
  384. &history->session(),
  385. data.vquote_entities().value_or_empty()),
  386. };
  387. result.quoteOffset = data.vquote_offset().value_or_empty();
  388. return result;
  389. }, [&](const MTPDinputReplyToStory &data) {
  390. if (const auto parsed = Data::PeerFromInputMTP(
  391. &history->owner(),
  392. data.vpeer())) {
  393. return FullReplyTo{
  394. .storyId = { parsed->id, data.vstory_id().v },
  395. };
  396. }
  397. return FullReplyTo();
  398. });
  399. }
  400. HistoryMessageReply::HistoryMessageReply() = default;
  401. HistoryMessageReply &HistoryMessageReply::operator=(
  402. HistoryMessageReply &&other) = default;
  403. HistoryMessageReply::~HistoryMessageReply() {
  404. // clearData() should be called by holder.
  405. Expects(resolvedMessage.empty());
  406. _fields.externalMedia = nullptr;
  407. }
  408. void HistoryMessageReply::updateData(
  409. not_null<HistoryItem*> holder,
  410. bool force) {
  411. const auto guard = gsl::finally([&] { refreshReplyToMedia(); });
  412. if (!force) {
  413. if (resolvedMessage || resolvedStory || _unavailable) {
  414. _pendingResolve = 0;
  415. return;
  416. }
  417. }
  418. const auto peerId = _fields.externalPeerId
  419. ? _fields.externalPeerId
  420. : holder->history()->peer->id;
  421. if (!resolvedMessage && _fields.messageId) {
  422. resolvedMessage = holder->history()->owner().message(
  423. peerId,
  424. _fields.messageId);
  425. if (resolvedMessage) {
  426. if (resolvedMessage->isEmpty()) {
  427. // Really it is deleted.
  428. resolvedMessage = nullptr;
  429. force = true;
  430. } else {
  431. holder->history()->owner().registerDependentMessage(
  432. holder,
  433. resolvedMessage.get());
  434. }
  435. }
  436. }
  437. if (!resolvedStory && _fields.storyId) {
  438. const auto maybe = holder->history()->owner().stories().lookup({
  439. peerId,
  440. _fields.storyId,
  441. });
  442. if (maybe) {
  443. resolvedStory = *maybe;
  444. holder->history()->owner().stories().registerDependentMessage(
  445. holder,
  446. resolvedStory.get());
  447. } else if (maybe.error() == Data::NoStory::Deleted) {
  448. force = true;
  449. }
  450. }
  451. const auto asExternal = displayAsExternal(holder);
  452. const auto nonEmptyQuote = !_fields.quote.empty()
  453. && (asExternal || _fields.manualQuote);
  454. _multiline = !_fields.storyId && (asExternal || nonEmptyQuote);
  455. const auto displaying = resolvedMessage
  456. || resolvedStory
  457. || ((nonEmptyQuote || _fields.externalMedia)
  458. && (!_fields.messageId || force));
  459. _displaying = displaying ? 1 : 0;
  460. const auto unavailable = !resolvedMessage
  461. && !resolvedStory
  462. && ((!_fields.storyId && !_fields.messageId) || force);
  463. _unavailable = unavailable ? 1 : 0;
  464. if (force) {
  465. if (!_displaying && (_fields.messageId || _fields.storyId)) {
  466. _unavailable = 1;
  467. }
  468. holder->history()->owner().requestItemResize(holder);
  469. }
  470. if (resolvedMessage
  471. || resolvedStory
  472. || (!_fields.messageId && !_fields.storyId && external())
  473. || _unavailable) {
  474. _pendingResolve = 0;
  475. } else if (!force) {
  476. _pendingResolve = 1;
  477. _requestedResolve = 0;
  478. }
  479. }
  480. void HistoryMessageReply::set(ReplyFields fields) {
  481. _fields = std::move(fields);
  482. }
  483. void HistoryMessageReply::updateFields(
  484. not_null<HistoryItem*> holder,
  485. MsgId messageId,
  486. MsgId topMessageId,
  487. bool topicPost) {
  488. _fields.topicPost = topicPost ? 1 : 0;
  489. if ((_fields.messageId != messageId)
  490. && !IsServerMsgId(_fields.messageId)) {
  491. _fields.messageId = messageId;
  492. updateData(holder);
  493. }
  494. if ((_fields.topMessageId != topMessageId)
  495. && !IsServerMsgId(_fields.topMessageId)) {
  496. _fields.topMessageId = topMessageId;
  497. }
  498. }
  499. bool HistoryMessageReply::acquireResolve() {
  500. if (!_pendingResolve || _requestedResolve) {
  501. return false;
  502. }
  503. _requestedResolve = 1;
  504. return true;
  505. }
  506. void HistoryMessageReply::setTopMessageId(MsgId topMessageId) {
  507. _fields.topMessageId = topMessageId;
  508. }
  509. void HistoryMessageReply::clearData(not_null<HistoryItem*> holder) {
  510. if (resolvedMessage) {
  511. holder->history()->owner().unregisterDependentMessage(
  512. holder,
  513. resolvedMessage.get());
  514. resolvedMessage = nullptr;
  515. }
  516. if (resolvedStory) {
  517. holder->history()->owner().stories().unregisterDependentMessage(
  518. holder,
  519. resolvedStory.get());
  520. resolvedStory = nullptr;
  521. }
  522. _unavailable = 1;
  523. _displaying = 0;
  524. if (_multiline) {
  525. holder->history()->owner().requestItemResize(holder);
  526. _multiline = 0;
  527. }
  528. refreshReplyToMedia();
  529. }
  530. bool HistoryMessageReply::external() const {
  531. return _fields.externalPeerId
  532. || _fields.externalSenderId
  533. || !_fields.externalSenderName.isEmpty();
  534. }
  535. bool HistoryMessageReply::displayAsExternal(
  536. not_null<HistoryItem*> holder) const {
  537. // Don't display replies that could be local as external.
  538. return external()
  539. && (!resolvedMessage
  540. || (holder->history() != resolvedMessage->history())
  541. || (holder->topicRootId() != resolvedMessage->topicRootId()));
  542. }
  543. void HistoryMessageReply::itemRemoved(
  544. not_null<HistoryItem*> holder,
  545. not_null<HistoryItem*> removed) {
  546. if (resolvedMessage.get() == removed) {
  547. clearData(holder);
  548. holder->history()->owner().requestItemResize(holder);
  549. }
  550. }
  551. void HistoryMessageReply::storyRemoved(
  552. not_null<HistoryItem*> holder,
  553. not_null<Data::Story*> removed) {
  554. if (resolvedStory.get() == removed) {
  555. clearData(holder);
  556. holder->history()->owner().requestItemResize(holder);
  557. }
  558. }
  559. void HistoryMessageReply::refreshReplyToMedia() {
  560. replyToDocumentId = 0;
  561. replyToWebPageId = 0;
  562. if (const auto media = resolvedMessage ? resolvedMessage->media() : nullptr) {
  563. if (const auto document = media->document()) {
  564. replyToDocumentId = document->id;
  565. } else if (const auto webpage = media->webpage()) {
  566. replyToWebPageId = webpage->id;
  567. }
  568. }
  569. }
  570. ReplyMarkupClickHandler::ReplyMarkupClickHandler(
  571. not_null<Data::Session*> owner,
  572. int row,
  573. int column,
  574. FullMsgId context)
  575. : _owner(owner)
  576. , _itemId(context)
  577. , _row(row)
  578. , _column(column) {
  579. }
  580. // Copy to clipboard support.
  581. QString ReplyMarkupClickHandler::copyToClipboardText() const {
  582. const auto button = getUrlButton();
  583. return button ? QString::fromUtf8(button->data) : QString();
  584. }
  585. QString ReplyMarkupClickHandler::copyToClipboardContextItemText() const {
  586. const auto button = getUrlButton();
  587. return button ? tr::lng_context_copy_link(tr::now) : QString();
  588. }
  589. // Finds the corresponding button in the items markup struct.
  590. // If the button is not found it returns nullptr.
  591. // Note: it is possible that we will point to the different button
  592. // than the one was used when constructing the handler, but not a big deal.
  593. const HistoryMessageMarkupButton *ReplyMarkupClickHandler::getButton() const {
  594. return HistoryMessageMarkupButton::Get(_owner, _itemId, _row, _column);
  595. }
  596. auto ReplyMarkupClickHandler::getUrlButton() const
  597. -> const HistoryMessageMarkupButton* {
  598. if (const auto button = getButton()) {
  599. using Type = HistoryMessageMarkupButton::Type;
  600. if (button->type == Type::Url || button->type == Type::Auth) {
  601. return button;
  602. }
  603. }
  604. return nullptr;
  605. }
  606. void ReplyMarkupClickHandler::onClick(ClickContext context) const {
  607. if (context.button != Qt::LeftButton) {
  608. return;
  609. }
  610. auto my = context.other.value<ClickHandlerContext>();
  611. my.itemId = _itemId;
  612. Api::ActivateBotCommand(my, _row, _column);
  613. }
  614. // Returns the full text of the corresponding button.
  615. QString ReplyMarkupClickHandler::buttonText() const {
  616. if (const auto button = getButton()) {
  617. return button->text;
  618. }
  619. return QString();
  620. }
  621. QString ReplyMarkupClickHandler::tooltip() const {
  622. if (const auto button = getButton()) {
  623. if (button->type == HistoryMessageMarkupButton::Type::CopyText) {
  624. return tr::lng_bot_copy_text_tooltip(
  625. tr::now,
  626. lt_text,
  627. st::wrap_rtl(QString::fromUtf8(button->data)));
  628. }
  629. }
  630. const auto button = getUrlButton();
  631. const auto url = button ? QString::fromUtf8(button->data) : QString();
  632. const auto text = _fullDisplayed ? QString() : buttonText();
  633. if (!url.isEmpty() && !text.isEmpty()) {
  634. return QString("%1\n\n%2").arg(text, url);
  635. } else if (url.isEmpty() != text.isEmpty()) {
  636. return text + url;
  637. } else {
  638. return QString();
  639. }
  640. }
  641. ReplyKeyboard::Button::Button() = default;
  642. ReplyKeyboard::Button::Button(Button &&other) = default;
  643. ReplyKeyboard::Button &ReplyKeyboard::Button::operator=(
  644. Button &&other) = default;
  645. ReplyKeyboard::Button::~Button() = default;
  646. ReplyKeyboard::ReplyKeyboard(
  647. not_null<const HistoryItem*> item,
  648. std::unique_ptr<Style> &&s)
  649. : _item(item)
  650. , _selectedAnimation([=](crl::time now) {
  651. return selectedAnimationCallback(now);
  652. })
  653. , _st(std::move(s)) {
  654. if (const auto markup = _item->Get<HistoryMessageReplyMarkup>()) {
  655. const auto owner = &_item->history()->owner();
  656. const auto context = _item->fullId();
  657. const auto rowCount = int(markup->data.rows.size());
  658. _rows.reserve(rowCount);
  659. const auto buttonEmoji = Ui::Text::SingleCustomEmoji(
  660. owner->customEmojiManager().registerInternalEmoji(
  661. st::settingsPremiumIconStar,
  662. QMargins(0, -st::moderateBoxExpandInnerSkip, 0, 0),
  663. true));
  664. for (auto i = 0; i != rowCount; ++i) {
  665. const auto &row = markup->data.rows[i];
  666. const auto rowSize = int(row.size());
  667. auto newRow = std::vector<Button>();
  668. newRow.reserve(rowSize);
  669. for (auto j = 0; j != rowSize; ++j) {
  670. auto button = Button();
  671. using Type = HistoryMessageMarkupButton::Type;
  672. const auto isBuy = (row[j].type == Type::Buy);
  673. static const auto RegExp = QRegularExpression("\\b"
  674. + Ui::kCreditsCurrency
  675. + "\\b");
  676. const auto text = isBuy
  677. ? base::duplicate(row[j].text).replace(
  678. RegExp,
  679. QChar(0x2B50))
  680. : row[j].text;
  681. const auto textWithEntities = [&] {
  682. if (!isBuy) {
  683. return TextWithEntities();
  684. }
  685. auto result = TextWithEntities();
  686. auto firstPart = true;
  687. for (const auto &part : text.split(QChar(0x2B50))) {
  688. if (!firstPart) {
  689. result.append(buttonEmoji);
  690. }
  691. result.append(part);
  692. firstPart = false;
  693. }
  694. return result.entities.empty()
  695. ? TextWithEntities()
  696. : result;
  697. }();
  698. button.type = row.at(j).type;
  699. button.link = std::make_shared<ReplyMarkupClickHandler>(
  700. owner,
  701. i,
  702. j,
  703. context);
  704. if (!textWithEntities.text.isEmpty()) {
  705. button.text.setMarkedText(
  706. _st->textStyle(),
  707. TextUtilities::SingleLine(textWithEntities),
  708. kMarkupTextOptions,
  709. Core::TextContext({
  710. .session = &item->history()->owner().session(),
  711. .repaint = [=] { _st->repaint(item); },
  712. }));
  713. } else {
  714. button.text.setText(
  715. _st->textStyle(),
  716. TextUtilities::SingleLine(text),
  717. kPlainTextOptions);
  718. }
  719. button.characters = text.isEmpty() ? 1 : text.size();
  720. newRow.push_back(std::move(button));
  721. }
  722. _rows.push_back(std::move(newRow));
  723. }
  724. }
  725. }
  726. void ReplyKeyboard::updateMessageId() {
  727. const auto msgId = _item->fullId();
  728. for (const auto &row : _rows) {
  729. for (const auto &button : row) {
  730. button.link->setMessageId(msgId);
  731. }
  732. }
  733. }
  734. void ReplyKeyboard::resize(int width, int height) {
  735. _width = width;
  736. auto y = 0.;
  737. auto buttonHeight = _rows.empty()
  738. ? float64(_st->buttonHeight())
  739. : (float64(height + _st->buttonSkip()) / _rows.size());
  740. for (auto &row : _rows) {
  741. int s = row.size();
  742. int widthForButtons = _width - ((s - 1) * _st->buttonSkip());
  743. int widthForText = widthForButtons;
  744. int widthOfText = 0;
  745. int maxMinButtonWidth = 0;
  746. for (const auto &button : row) {
  747. widthOfText += qMax(button.text.maxWidth(), 1);
  748. int minButtonWidth = _st->minButtonWidth(button.type);
  749. widthForText -= minButtonWidth;
  750. accumulate_max(maxMinButtonWidth, minButtonWidth);
  751. }
  752. bool exact = (widthForText == widthOfText);
  753. bool enough = (widthForButtons - s * maxMinButtonWidth) >= widthOfText;
  754. float64 x = 0;
  755. for (auto &button : row) {
  756. int buttonw = qMax(button.text.maxWidth(), 1);
  757. float64 textw = buttonw, minw = _st->minButtonWidth(button.type);
  758. float64 w = textw;
  759. if (exact) {
  760. w += minw;
  761. } else if (enough) {
  762. w = (widthForButtons / float64(s));
  763. textw = w - minw;
  764. } else {
  765. textw = (widthForText / float64(s));
  766. w = minw + textw;
  767. accumulate_max(w, 2 * float64(_st->buttonPadding()));
  768. }
  769. int rectx = static_cast<int>(std::floor(x));
  770. int rectw = static_cast<int>(std::floor(x + w)) - rectx;
  771. button.rect = QRect(rectx, qRound(y), rectw, qRound(buttonHeight - _st->buttonSkip()));
  772. if (rtl()) button.rect.setX(_width - button.rect.x() - button.rect.width());
  773. x += w + _st->buttonSkip();
  774. button.link->setFullDisplayed(textw >= buttonw);
  775. }
  776. y += buttonHeight;
  777. }
  778. }
  779. bool ReplyKeyboard::isEnoughSpace(int width, const style::BotKeyboardButton &st) const {
  780. for (const auto &row : _rows) {
  781. int s = row.size();
  782. int widthLeft = width - ((s - 1) * st.margin + s * 2 * st.padding);
  783. for (const auto &button : row) {
  784. widthLeft -= qMax(button.text.maxWidth(), 1);
  785. if (widthLeft < 0) {
  786. if (row.size() > 3) {
  787. return false;
  788. } else {
  789. break;
  790. }
  791. }
  792. }
  793. }
  794. return true;
  795. }
  796. void ReplyKeyboard::setStyle(std::unique_ptr<Style> &&st) {
  797. _st = std::move(st);
  798. }
  799. int ReplyKeyboard::naturalWidth() const {
  800. auto result = 0;
  801. for (const auto &row : _rows) {
  802. auto maxMinButtonWidth = 0;
  803. for (const auto &button : row) {
  804. accumulate_max(
  805. maxMinButtonWidth,
  806. _st->minButtonWidth(button.type));
  807. }
  808. auto rowMaxButtonWidth = 0;
  809. for (const auto &button : row) {
  810. accumulate_max(
  811. rowMaxButtonWidth,
  812. qMax(button.text.maxWidth(), 1) + maxMinButtonWidth);
  813. }
  814. const auto rowSize = int(row.size());
  815. accumulate_max(
  816. result,
  817. rowSize * rowMaxButtonWidth + (rowSize - 1) * _st->buttonSkip());
  818. }
  819. return result;
  820. }
  821. int ReplyKeyboard::naturalHeight() const {
  822. return (_rows.size() - 1) * _st->buttonSkip() + _rows.size() * _st->buttonHeight();
  823. }
  824. void ReplyKeyboard::paint(
  825. Painter &p,
  826. const Ui::ChatStyle *st,
  827. Ui::BubbleRounding rounding,
  828. int outerWidth,
  829. const QRect &clip) const {
  830. Assert(_st != nullptr);
  831. Assert(_width > 0);
  832. _st->startPaint(p, st);
  833. auto number = hasFastButtonMode() ? 1 : 0;
  834. for (auto y = 0, rowsCount = int(_rows.size()); y != rowsCount; ++y) {
  835. for (auto x = 0, count = int(_rows[y].size()); x != count; ++x) {
  836. const auto guard = gsl::finally([&] { if (number) ++number; });
  837. const auto &button = _rows[y][x];
  838. const auto rect = button.rect;
  839. if (rect.y() >= clip.y() + clip.height()) {
  840. return;
  841. } else if (rect.y() + rect.height() < clip.y()) {
  842. continue;
  843. }
  844. // just ignore the buttons that didn't layout well
  845. if (rect.x() + rect.width() > _width) break;
  846. auto buttonRounding = Ui::BubbleRounding();
  847. using Corner = Ui::BubbleCornerRounding;
  848. buttonRounding.topLeft = buttonRounding.topRight = Corner::Small;
  849. buttonRounding.bottomLeft = ((y + 1 == rowsCount)
  850. && !x
  851. && (rounding.bottomLeft == Corner::Large))
  852. ? Corner::Large
  853. : Corner::Small;
  854. buttonRounding.bottomRight = ((y + 1 == rowsCount)
  855. && (x + 1 == count)
  856. && (rounding.bottomRight == Corner::Large))
  857. ? Corner::Large
  858. : Corner::Small;
  859. _st->paintButton(p, st, outerWidth, button, buttonRounding);
  860. if (number) {
  861. p.setFont(st::dialogsUnreadFont);
  862. p.setPen(st->msgServiceFg());
  863. p.drawText(
  864. rect.x() + st::msgBotKbIconPadding,
  865. rect.y() + st::dialogsUnreadFont->ascent,
  866. QString::number(number));
  867. }
  868. }
  869. }
  870. }
  871. bool ReplyKeyboard::hasFastButtonMode() const {
  872. return FastButtonsMode()
  873. && _item->inlineReplyKeyboard()
  874. && (_item == _item->history()->lastMessage())
  875. && _item->history()->session().fastButtonsBots().enabled(
  876. _item->history()->peer);
  877. }
  878. ClickHandlerPtr ReplyKeyboard::getLink(QPoint point) const {
  879. Assert(_width > 0);
  880. for (const auto &row : _rows) {
  881. for (const auto &button : row) {
  882. QRect rect(button.rect);
  883. // just ignore the buttons that didn't layout well
  884. if (rect.x() + rect.width() > _width) break;
  885. if (rect.contains(point)) {
  886. _savedCoords = point;
  887. return button.link;
  888. }
  889. }
  890. }
  891. return ClickHandlerPtr();
  892. }
  893. ClickHandlerPtr ReplyKeyboard::getLinkByIndex(int index) const {
  894. auto number = 1;
  895. for (const auto &row : _rows) {
  896. for (const auto &button : row) {
  897. if (number == index + 1) {
  898. return button.link;
  899. }
  900. ++number;
  901. }
  902. }
  903. return ClickHandlerPtr();
  904. }
  905. void ReplyKeyboard::clickHandlerActiveChanged(const ClickHandlerPtr &p, bool active) {
  906. if (!p) return;
  907. _savedActive = active ? p : ClickHandlerPtr();
  908. auto coords = findButtonCoordsByClickHandler(p);
  909. if (coords.i >= 0 && _savedPressed != p) {
  910. startAnimation(coords.i, coords.j, active ? 1 : -1);
  911. }
  912. }
  913. ReplyKeyboard::ButtonCoords ReplyKeyboard::findButtonCoordsByClickHandler(const ClickHandlerPtr &p) {
  914. for (int i = 0, rows = _rows.size(); i != rows; ++i) {
  915. auto &row = _rows[i];
  916. for (int j = 0, cols = row.size(); j != cols; ++j) {
  917. if (row[j].link == p) {
  918. return { i, j };
  919. }
  920. }
  921. }
  922. return { -1, -1 };
  923. }
  924. void ReplyKeyboard::clickHandlerPressedChanged(
  925. const ClickHandlerPtr &handler,
  926. bool pressed,
  927. Ui::BubbleRounding rounding) {
  928. if (!handler) return;
  929. _savedPressed = pressed ? handler : ClickHandlerPtr();
  930. auto coords = findButtonCoordsByClickHandler(handler);
  931. if (coords.i >= 0) {
  932. auto &button = _rows[coords.i][coords.j];
  933. if (pressed) {
  934. if (!button.ripple) {
  935. const auto sides = RectPart()
  936. | (!coords.i ? RectPart::Top : RectPart())
  937. | (!coords.j ? RectPart::Left : RectPart())
  938. | ((coords.i + 1 == _rows.size())
  939. ? RectPart::Bottom
  940. : RectPart())
  941. | ((coords.j + 1 == _rows[coords.i].size())
  942. ? RectPart::Right
  943. : RectPart());
  944. auto mask = Ui::RippleAnimation::RoundRectMask(
  945. button.rect.size(),
  946. _st->buttonRounding(rounding, sides));
  947. button.ripple = std::make_unique<Ui::RippleAnimation>(
  948. _st->_st->ripple,
  949. std::move(mask),
  950. [=] { _st->repaint(_item); });
  951. }
  952. button.ripple->add(_savedCoords - button.rect.topLeft());
  953. } else {
  954. if (button.ripple) {
  955. button.ripple->lastStop();
  956. }
  957. if (_savedActive != handler) {
  958. startAnimation(coords.i, coords.j, -1);
  959. }
  960. }
  961. }
  962. }
  963. void ReplyKeyboard::startAnimation(int i, int j, int direction) {
  964. auto notStarted = _animations.empty();
  965. int indexForAnimation = Layout::PositionToIndex(i, j + 1) * direction;
  966. _animations.remove(-indexForAnimation);
  967. if (!_animations.contains(indexForAnimation)) {
  968. _animations.emplace(indexForAnimation, crl::now());
  969. }
  970. if (notStarted && !_selectedAnimation.animating()) {
  971. _selectedAnimation.start();
  972. }
  973. }
  974. bool ReplyKeyboard::selectedAnimationCallback(crl::time now) {
  975. if (anim::Disabled()) {
  976. now += st::botKbDuration;
  977. }
  978. for (auto i = _animations.begin(); i != _animations.end();) {
  979. const auto index = std::abs(i->first) - 1;
  980. const auto &[row, col] = Layout::IndexToPosition(index);
  981. const auto dt = float64(now - i->second) / st::botKbDuration;
  982. if (dt >= 1) {
  983. _rows[row][col].howMuchOver = (i->first > 0) ? 1 : 0;
  984. i = _animations.erase(i);
  985. } else {
  986. _rows[row][col].howMuchOver = (i->first > 0) ? dt : (1 - dt);
  987. ++i;
  988. }
  989. }
  990. _st->repaint(_item);
  991. return !_animations.empty();
  992. }
  993. void ReplyKeyboard::clearSelection() {
  994. for (const auto &[relativeIndex, time] : _animations) {
  995. const auto index = std::abs(relativeIndex) - 1;
  996. const auto &[row, col] = Layout::IndexToPosition(index);
  997. _rows[row][col].howMuchOver = 0;
  998. }
  999. _animations.clear();
  1000. _selectedAnimation.stop();
  1001. }
  1002. int ReplyKeyboard::Style::buttonSkip() const {
  1003. return _st->margin;
  1004. }
  1005. int ReplyKeyboard::Style::buttonPadding() const {
  1006. return _st->padding;
  1007. }
  1008. int ReplyKeyboard::Style::buttonHeight() const {
  1009. return _st->height;
  1010. }
  1011. void ReplyKeyboard::Style::paintButton(
  1012. Painter &p,
  1013. const Ui::ChatStyle *st,
  1014. int outerWidth,
  1015. const ReplyKeyboard::Button &button,
  1016. Ui::BubbleRounding rounding) const {
  1017. const QRect &rect = button.rect;
  1018. paintButtonBg(p, st, rect, rounding, button.howMuchOver);
  1019. if (button.ripple) {
  1020. const auto color = st ? &st->msgBotKbRippleBg()->c : nullptr;
  1021. button.ripple->paint(p, rect.x(), rect.y(), outerWidth, color);
  1022. if (button.ripple->empty()) {
  1023. button.ripple.reset();
  1024. }
  1025. }
  1026. paintButtonIcon(p, st, rect, outerWidth, button.type);
  1027. if (button.type == HistoryMessageMarkupButton::Type::CallbackWithPassword
  1028. || button.type == HistoryMessageMarkupButton::Type::Callback
  1029. || button.type == HistoryMessageMarkupButton::Type::Game) {
  1030. if (const auto data = button.link->getButton()) {
  1031. if (data->requestId) {
  1032. paintButtonLoading(p, st, rect, outerWidth, rounding);
  1033. }
  1034. }
  1035. }
  1036. int tx = rect.x(), tw = rect.width();
  1037. if (tw >= st::botKbStyle.font->elidew + _st->padding * 2) {
  1038. tx += _st->padding;
  1039. tw -= _st->padding * 2;
  1040. } else if (tw > st::botKbStyle.font->elidew) {
  1041. tx += (tw - st::botKbStyle.font->elidew) / 2;
  1042. tw = st::botKbStyle.font->elidew;
  1043. }
  1044. button.text.drawElided(
  1045. p,
  1046. tx,
  1047. rect.y() + _st->textTop + ((rect.height() - _st->height) / 2),
  1048. tw,
  1049. 1,
  1050. style::al_top);
  1051. if (button.type == HistoryMessageMarkupButton::Type::SimpleWebView) {
  1052. const auto &icon = st::markupWebview;
  1053. st::markupWebview.paint(
  1054. p,
  1055. rect::right(rect) - icon.width() - _st->padding / 2,
  1056. rect.y() + _st->padding / 2,
  1057. rect.width(),
  1058. p.pen().color());
  1059. }
  1060. }
  1061. void HistoryMessageReplyMarkup::createForwarded(
  1062. const HistoryMessageReplyMarkup &original) {
  1063. Expects(!inlineKeyboard);
  1064. data.fillForwardedData(original.data);
  1065. }
  1066. void HistoryMessageReplyMarkup::updateData(
  1067. HistoryMessageMarkupData &&markup) {
  1068. data = std::move(markup);
  1069. inlineKeyboard = nullptr;
  1070. }
  1071. bool HistoryMessageReplyMarkup::hiddenBy(Data::Media *media) const {
  1072. if (media && (data.flags & ReplyMarkupFlag::OnlyBuyButton)) {
  1073. if (const auto invoice = media->invoice()) {
  1074. if (HasUnpaidMedia(*invoice)
  1075. || (HasExtendedMedia(*invoice) && !invoice->receiptMsgId)) {
  1076. return true;
  1077. }
  1078. }
  1079. }
  1080. return false;
  1081. }
  1082. HistoryMessageLogEntryOriginal::HistoryMessageLogEntryOriginal() = default;
  1083. HistoryMessageLogEntryOriginal::HistoryMessageLogEntryOriginal(
  1084. HistoryMessageLogEntryOriginal &&other)
  1085. : page(std::move(other.page)) {
  1086. }
  1087. HistoryMessageLogEntryOriginal &HistoryMessageLogEntryOriginal::operator=(
  1088. HistoryMessageLogEntryOriginal &&other) {
  1089. page = std::move(other.page);
  1090. return *this;
  1091. }
  1092. HistoryMessageLogEntryOriginal::~HistoryMessageLogEntryOriginal() = default;
  1093. MessageFactcheck FromMTP(
  1094. not_null<HistoryItem*> item,
  1095. const tl::conditional<MTPFactCheck> &factcheck) {
  1096. return FromMTP(&item->history()->session(), factcheck);
  1097. }
  1098. MessageFactcheck FromMTP(
  1099. not_null<Main::Session*> session,
  1100. const tl::conditional<MTPFactCheck> &factcheck) {
  1101. auto result = MessageFactcheck();
  1102. if (!factcheck) {
  1103. return result;
  1104. }
  1105. const auto &data = factcheck->data();
  1106. if (const auto text = data.vtext()) {
  1107. const auto &data = text->data();
  1108. result.text = {
  1109. qs(data.vtext()),
  1110. Api::EntitiesFromMTP(session, data.ventities().v),
  1111. };
  1112. }
  1113. if (const auto country = data.vcountry()) {
  1114. result.country = qs(country->v);
  1115. }
  1116. result.hash = data.vhash().v;
  1117. result.needCheck = data.is_need_check();
  1118. return result;
  1119. }
  1120. HistoryDocumentCaptioned::HistoryDocumentCaptioned()
  1121. : caption(st::msgFileMinWidth - st::msgPadding.left() - st::msgPadding.right()) {
  1122. }
  1123. HistoryDocumentVoicePlayback::HistoryDocumentVoicePlayback(
  1124. const HistoryView::Document *that)
  1125. : progress(0., 0.)
  1126. , progressAnimation([=](crl::time now) {
  1127. const auto nonconst = const_cast<HistoryView::Document*>(that);
  1128. return nonconst->voiceProgressAnimationCallback(now);
  1129. }) {
  1130. }
  1131. void HistoryDocumentVoice::ensurePlayback(
  1132. const HistoryView::Document *that) const {
  1133. if (!playback) {
  1134. playback = std::make_unique<HistoryDocumentVoicePlayback>(that);
  1135. }
  1136. }
  1137. void HistoryDocumentVoice::checkPlaybackFinished() const {
  1138. if (playback && !playback->progressAnimation.animating()) {
  1139. playback.reset();
  1140. }
  1141. }
  1142. void HistoryDocumentVoice::startSeeking() {
  1143. _seeking = true;
  1144. _seekingCurrent = _seekingStart;
  1145. Media::Player::instance()->startSeeking(AudioMsgId::Type::Voice);
  1146. }
  1147. void HistoryDocumentVoice::stopSeeking() {
  1148. _seeking = false;
  1149. Media::Player::instance()->cancelSeeking(AudioMsgId::Type::Voice);
  1150. }
  1151. bool HistoryDocumentVoice::seeking() const {
  1152. return _seeking;
  1153. }
  1154. float64 HistoryDocumentVoice::seekingStart() const {
  1155. return _seekingStart / kFloatToIntMultiplier;
  1156. }
  1157. void HistoryDocumentVoice::setSeekingStart(float64 seekingStart) const {
  1158. _seekingStart = qRound(seekingStart * kFloatToIntMultiplier);
  1159. }
  1160. float64 HistoryDocumentVoice::seekingCurrent() const {
  1161. return _seekingCurrent / kFloatToIntMultiplier;
  1162. }
  1163. void HistoryDocumentVoice::setSeekingCurrent(float64 seekingCurrent) {
  1164. _seekingCurrent = qRound(seekingCurrent * kFloatToIntMultiplier);
  1165. }