From 2586268b811ccc38c0d4d965f1436f860ab12507 Mon Sep 17 00:00:00 2001 From: John Preston Date: Tue, 30 Jan 2018 15:32:00 +0300 Subject: [PATCH] Remove HistoryJoined, use plain HistoryService. --- Telegram/SourceFiles/history/history.cpp | 26 ++++++---- Telegram/SourceFiles/history/history.h | 35 +++++++------- .../SourceFiles/history/history_service.cpp | 48 ++++++++++++------- .../SourceFiles/history/history_service.h | 29 ++++------- 4 files changed, 76 insertions(+), 62 deletions(-) diff --git a/Telegram/SourceFiles/history/history.cpp b/Telegram/SourceFiles/history/history.cpp index 98d88dc01..4aced1bd1 100644 --- a/Telegram/SourceFiles/history/history.cpp +++ b/Telegram/SourceFiles/history/history.cpp @@ -423,7 +423,7 @@ void ChannelHistory::getRangeDifferenceNext(int32 pts) { _rangeDifferenceRequestId = MTP::send(MTPupdates_GetChannelDifference(MTP_flags(flags), peer->asChannel()->inputChannel, filter, MTP_int(pts), MTP_int(limit)), App::main()->rpcDone(&MainWidget::gotRangeDifference, peer->asChannel())); } -HistoryJoined *ChannelHistory::insertJoinedMessage(bool unread) { +HistoryService *ChannelHistory::insertJoinedMessage(bool unread) { if (_joinedMessage || !peer->asChannel()->amIn() || (peer->isMegagroup() @@ -434,7 +434,9 @@ HistoryJoined *ChannelHistory::insertJoinedMessage(bool unread) { const auto inviter = (peer->asChannel()->inviter > 0) ? App::userLoaded(peer->asChannel()->inviter) : nullptr; - if (!inviter) return nullptr; + if (!inviter) { + return nullptr; + } MTPDmessage::Flags flags = 0; if (inviter->id == Auth().userPeerId()) { @@ -446,7 +448,11 @@ HistoryJoined *ChannelHistory::insertJoinedMessage(bool unread) { auto inviteDate = peer->asChannel()->inviteDate; if (unread) _maxReadMessageDate = inviteDate; if (isEmpty()) { - _joinedMessage = new HistoryJoined(this, inviteDate, inviter, flags); + _joinedMessage = GenerateJoinedMessage( + this, + inviteDate, + inviter, + flags); addNewItem(_joinedMessage, unread); return _joinedMessage; } @@ -459,13 +465,15 @@ HistoryJoined *ChannelHistory::insertJoinedMessage(bool unread) { // Due to a server bug sometimes inviteDate is less (before) than the // first message in the megagroup (message about migration), let us // ignore that and think, that the inviteDate is always greater-or-equal. - if (item->isGroupMigrate() && peer->isMegagroup() && peer->migrateFrom()) { + if (item->isGroupMigrate() + && peer->isMegagroup() + && peer->migrateFrom()) { peer->asChannel()->mgInfo->joinedMessageFound = true; return nullptr; } if (item->date <= inviteDate) { ++itemIndex; - _joinedMessage = new HistoryJoined( + _joinedMessage = GenerateJoinedMessage( this, inviteDate, inviter, @@ -484,10 +492,12 @@ HistoryJoined *ChannelHistory::insertJoinedMessage(bool unread) { } startBuildingFrontBlock(); - - _joinedMessage = new HistoryJoined(this, inviteDate, inviter, flags); + _joinedMessage = GenerateJoinedMessage( + this, + inviteDate, + inviter, + flags); addItemToBlock(_joinedMessage); - finishBuildingFrontBlock(); return _joinedMessage; diff --git a/Telegram/SourceFiles/history/history.h b/Telegram/SourceFiles/history/history.h index d83e30b74..b5969e22a 100644 --- a/Telegram/SourceFiles/history/history.h +++ b/Telegram/SourceFiles/history/history.h @@ -18,6 +18,21 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "base/flags.h" class History; +class ChannelHistory; +class HistoryBlock; +class HistoryItem; +class HistoryMessage; +class HistoryService; +class HistoryMedia; + +namespace Data { +struct Draft; +} // namespace Data + +namespace Dialogs { +class Row; +class IndexedList; +} // namespace Dialogs namespace HistoryView { class Element; @@ -108,26 +123,11 @@ private: }; -class HistoryBlock; - -namespace Data { -struct Draft; -} // namespace Data - -class HistoryMedia; -class HistoryMessage; - enum class UnreadMentionType { New, // when new message is added to history Existing, // when some messages slice was received }; -namespace Dialogs { -class Row; -class IndexedList; -} // namespace Dialogs - -class ChannelHistory; class History : public Dialogs::Entry { public: using Element = HistoryView::Element; @@ -517,7 +517,6 @@ private: }; -class HistoryJoined; class ChannelHistory : public History { public: using History::History; @@ -527,7 +526,7 @@ public: void getRangeDifference(); void getRangeDifferenceNext(int32 pts); - HistoryJoined *insertJoinedMessage(bool unread); + HistoryService *insertJoinedMessage(bool unread); void checkJoinedMessage(bool createUnread = false); const QDateTime &maxReadMessageDate(); @@ -541,7 +540,7 @@ private: QDateTime _maxReadMessageDate; - HistoryJoined *_joinedMessage = nullptr; + HistoryService *_joinedMessage = nullptr; MsgId _rangeDifferenceFromId, _rangeDifferenceToId; int32 _rangeDifferencePts; diff --git a/Telegram/SourceFiles/history/history_service.cpp b/Telegram/SourceFiles/history/history_service.cpp index 13236d529..afa4f2d0d 100644 --- a/Telegram/SourceFiles/history/history_service.cpp +++ b/Telegram/SourceFiles/history/history_service.cpp @@ -641,23 +641,37 @@ HistoryService::~HistoryService() { _media.reset(); } -HistoryJoined::HistoryJoined(not_null history, const QDateTime &inviteDate, not_null inviter, MTPDmessage::Flags flags) - : HistoryService(history, clientMsgId(), inviteDate, GenerateText(history, inviter), flags) { +HistoryService::PreparedText GenerateJoinedText( + not_null history, + not_null inviter) { + if (inviter->id != Auth().userPeerId()) { + auto result = HistoryService::PreparedText{}; + result.links.push_back(inviter->createOpenLink()); + result.text = (history->isMegagroup() + ? lng_action_add_you_group + : lng_action_add_you)(lt_from, textcmdLink(1, inviter->name)); + return result; + } else if (history->isMegagroup()) { + auto self = App::user(Auth().userPeerId()); + auto result = HistoryService::PreparedText{}; + result.links.push_back(self->createOpenLink()); + result.text = lng_action_user_joined( + lt_from, + textcmdLink(1, self->name)); + return result; + } + return { lang(lng_action_you_joined) }; } -HistoryJoined::PreparedText HistoryJoined::GenerateText(not_null history, not_null inviter) { - if (inviter->id == Auth().userPeerId()) { - if (history->isMegagroup()) { - auto self = App::user(Auth().userPeerId()); - auto result = PreparedText {}; - result.links.push_back(self->createOpenLink()); - result.text = lng_action_user_joined(lt_from, textcmdLink(1, self->name)); - return result; - } - return { lang(lng_action_you_joined) }; - } - auto result = PreparedText {}; - result.links.push_back(inviter->createOpenLink()); - result.text = (history->isMegagroup() ? lng_action_add_you_group : lng_action_add_you)(lt_from, textcmdLink(1, inviter->name)); - return result; +HistoryService *GenerateJoinedMessage( + not_null history, + const QDateTime &inviteDate, + not_null inviter, + MTPDmessage::Flags flags) { + return new HistoryService( + history, + clientMsgId(), + inviteDate, + GenerateJoinedText(history, inviter), + flags); } diff --git a/Telegram/SourceFiles/history/history_service.h b/Telegram/SourceFiles/history/history_service.h index 820192ea4..053b2e4a4 100644 --- a/Telegram/SourceFiles/history/history_service.h +++ b/Telegram/SourceFiles/history/history_service.h @@ -63,12 +63,12 @@ public: not_null history, const MTPDmessageService &message); HistoryService( - not_null history, + not_null history, MsgId msgId, - QDateTime date, - const PreparedText &message, - MTPDmessage::Flags flags = 0, - UserId from = 0, + QDateTime date, + const PreparedText &message, + MTPDmessage::Flags flags = 0, + UserId from = 0, PhotoData *photo = nullptr); bool updateDependencyItem() override; @@ -151,17 +151,8 @@ private: }; -class HistoryJoined : public HistoryService { -public: - HistoryJoined( - not_null history, - const QDateTime &inviteDate, - not_null inviter, - MTPDmessage::Flags flags); - -private: - static PreparedText GenerateText( - not_null history, - not_null inviter); - -}; +HistoryService *GenerateJoinedMessage( + not_null history, + const QDateTime &inviteDate, + not_null inviter, + MTPDmessage::Flags flags);