Advertisement
Guest User

Untitled

a guest
Sep 21st, 2019
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.05 KB | None | 0 0
  1. From eb661f6bfb33631b6e053e0786162caae9691f31 Mon Sep 17 00:00:00 2001
  2. From: "KangJing Huang (Chaserhkj)" <huangkangjing@gmail.com>
  3. Date: Tue, 10 Sep 2019 00:14:59 -0400
  4. Subject: [PATCH] Ignore blocked user in group chat
  5.  
  6. ---
  7. Telegram/SourceFiles/history/history.cpp | 51 ++++++++++++++++++++++++
  8. 1 file changed, 51 insertions(+)
  9.  
  10. diff --git a/Telegram/SourceFiles/history/history.cpp b/Telegram/SourceFiles/history/history.cpp
  11. index 957b71b21..2270cdd1b 100644
  12. --- a/Telegram/SourceFiles/history/history.cpp
  13. +++ b/Telegram/SourceFiles/history/history.cpp
  14. @@ -61,6 +61,38 @@ constexpr auto kSetMyActionForMs = 10000;
  15. constexpr auto kNewBlockEachMessage = 50;
  16. constexpr auto kSkipCloudDraftsFor = TimeId(3);
  17.  
  18. +bool checkFiltered(HistoryItem* item) {
  19. + if (auto history_msg = item->toHistoryMessage()){
  20. + if (auto user = history_msg->author()->asUser()) {
  21. + user->updateFull();
  22. + if (user->isBlocked()){
  23. + return true;
  24. + }
  25. + }
  26. + }
  27. + if (auto reply = item->Get<HistoryMessageReply>()) {
  28. + if (auto reply_msg = reply->replyToMsg) {
  29. + if (auto user = reply_msg->author()->asUser()) {
  30. + user->updateFull();
  31. + if (user->isBlocked()){
  32. + return true;
  33. + }
  34. + }
  35. + }
  36. + }
  37. + if (auto forward = item->Get<HistoryMessageForwarded>()) {
  38. + if (auto peer = forward->originalSender){
  39. + if (auto user = peer->asUser()) {
  40. + user->updateFull();
  41. + if (user->isBlocked()) {
  42. + return true;
  43. + }
  44. + }
  45. + }
  46. + }
  47. + return false;
  48. +}
  49. +
  50. } // namespace
  51.  
  52. History::History(not_null<Data::Session*> owner, PeerId peerId)
  53. @@ -352,6 +384,13 @@ bool History::updateSendActionNeedsAnimating(
  54. return false;
  55. }
  56.  
  57. + if (user) {
  58. + user->updateFull();
  59. + if (user->isBlocked()){
  60. + return false;
  61. + }
  62. + }
  63. +
  64. using Type = SendAction::Type;
  65. if (action.type() == mtpc_sendMessageCancelAction) {
  66. clearSendAction(user);
  67. @@ -1334,6 +1373,9 @@ void History::viewReplaced(not_null<const Element*> was, Element *now) {
  68. }
  69.  
  70. void History::addItemToBlock(not_null<HistoryItem*> item) {
  71. + if (checkFiltered(item)) {
  72. + return;
  73. + }
  74. Expects(!item->mainView());
  75.  
  76. auto block = prepareBlockForAddingItem();
  77. @@ -1450,6 +1492,9 @@ void History::addItemsToLists(
  78. markupSenders = &peer->asChannel()->mgInfo->markupSenders;
  79. }
  80. for (const auto item : ranges::view::reverse(items)) {
  81. + if (checkFiltered(item)) {
  82. + continue;
  83. + }
  84. item->addToUnreadMentions(UnreadMentionType::Existing);
  85. if (item->from()->id) {
  86. if (lastAuthors) { // chats
  87. @@ -1524,6 +1569,9 @@ void History::addToSharedMedia(
  88. const std::vector<not_null<HistoryItem*>> &items) {
  89. std::vector<MsgId> medias[Storage::kSharedMediaTypeCount];
  90. for (const auto item : items) {
  91. + if (checkFiltered(item)) {
  92. + continue;
  93. + }
  94. if (const auto types = item->sharedMediaTypes()) {
  95. for (auto i = 0; i != Storage::kSharedMediaTypeCount; ++i) {
  96. const auto type = static_cast<Storage::SharedMediaType>(i);
  97. @@ -2279,6 +2327,9 @@ void History::clearSharedMedia() {
  98. }
  99.  
  100. void History::setLastMessage(HistoryItem *item) {
  101. + if (checkFiltered(item)) {
  102. + return;
  103. + }
  104. if (_lastMessage) {
  105. if (*_lastMessage == item) {
  106. return;
  107. --
  108. 2.22.1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement