Remove HistoryJoined, use plain HistoryService.

This commit is contained in:
John Preston 2018-01-30 15:32:00 +03:00
parent 280ddb4629
commit 2586268b81
4 changed files with 76 additions and 62 deletions

View file

@ -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;

View file

@ -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;

View file

@ -641,23 +641,37 @@ HistoryService::~HistoryService() {
_media.reset();
}
HistoryJoined::HistoryJoined(not_null<History*> history, const QDateTime &inviteDate, not_null<UserData*> inviter, MTPDmessage::Flags flags)
: HistoryService(history, clientMsgId(), inviteDate, GenerateText(history, inviter), flags) {
HistoryService::PreparedText GenerateJoinedText(
not_null<History*> history,
not_null<UserData*> 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*> history, not_null<UserData*> 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*> history,
const QDateTime &inviteDate,
not_null<UserData*> inviter,
MTPDmessage::Flags flags) {
return new HistoryService(
history,
clientMsgId(),
inviteDate,
GenerateJoinedText(history, inviter),
flags);
}

View file

@ -63,12 +63,12 @@ public:
not_null<History*> history,
const MTPDmessageService &message);
HistoryService(
not_null<History*> history,
not_null<History*> 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*> history,
const QDateTime &inviteDate,
not_null<UserData*> inviter,
MTPDmessage::Flags flags);
private:
static PreparedText GenerateText(
not_null<History*> history,
not_null<UserData*> inviter);
};
HistoryService *GenerateJoinedMessage(
not_null<History*> history,
const QDateTime &inviteDate,
not_null<UserData*> inviter,
MTPDmessage::Flags flags);