item_text_options.cpp 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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 "ui/item_text_options.h"
  8. #include "history/history.h"
  9. #include "history/history_item.h"
  10. #include "data/data_channel.h"
  11. #include "data/data_chat.h"
  12. #include "data/data_user.h"
  13. namespace Ui {
  14. namespace {
  15. bool UseBotTextOptions(
  16. not_null<History*> history,
  17. not_null<PeerData*> author) {
  18. if (const auto user = history->peer->asUser()) {
  19. if (user->isBot()) {
  20. return true;
  21. }
  22. } else if (const auto chat = history->peer->asChat()) {
  23. if (chat->botStatus >= 0) {
  24. return true;
  25. }
  26. } else if (const auto group = history->peer->asMegagroup()) {
  27. if (group->mgInfo->botStatus >= 0) {
  28. return true;
  29. }
  30. }
  31. if (const auto user = author->asUser()) {
  32. if (user->isBot()) {
  33. return true;
  34. }
  35. }
  36. return false;
  37. }
  38. } // namespace
  39. const TextParseOptions &ItemTextOptions(
  40. not_null<History*> history,
  41. not_null<PeerData*> author) {
  42. return UseBotTextOptions(history, author)
  43. ? ItemTextBotDefaultOptions()
  44. : ItemTextDefaultOptions();
  45. }
  46. const TextParseOptions &ItemTextOptions(not_null<const HistoryItem*> item) {
  47. return ItemTextOptions(item->history(), item->author());
  48. }
  49. const TextParseOptions &ItemTextNoMonoOptions(
  50. not_null<History*> history,
  51. not_null<PeerData*> author) {
  52. return UseBotTextOptions(history, author)
  53. ? ItemTextBotNoMonoOptions()
  54. : ItemTextNoMonoOptions();
  55. }
  56. const TextParseOptions &ItemTextNoMonoOptions(
  57. not_null<const HistoryItem*> item) {
  58. return ItemTextNoMonoOptions(item->history(), item->author());
  59. }
  60. } // namespace Ui