Removed legacy HistoryItem::type() code.

This commit is contained in:
John Preston 2017-02-10 17:16:50 +03:00
parent 2ab3cda743
commit c39bf239ea
12 changed files with 104 additions and 181 deletions

View File

@ -161,7 +161,7 @@ void ConfirmBox::mousePressEvent(QMouseEvent *e) {
void ConfirmBox::mouseReleaseEvent(QMouseEvent *e) { void ConfirmBox::mouseReleaseEvent(QMouseEvent *e) {
_lastMousePos = e->globalPos(); _lastMousePos = e->globalPos();
updateHover(); updateHover();
if (ClickHandlerPtr activated = ClickHandler::unpressed()) { if (auto activated = ClickHandler::unpressed()) {
Ui::hideLayer(); Ui::hideLayer();
App::activateClickHandler(activated, e->button()); App::activateClickHandler(activated, e->button());
} }

View File

@ -39,8 +39,8 @@ bool ClickHandler::setActive(const ClickHandlerPtr &p, ClickHandlerHost *host) {
// other pressed click handler currently, if there is // other pressed click handler currently, if there is
// this method will be called when it is unpressed // this method will be called when it is unpressed
if (_active && *_active) { if (_active && *_active) {
bool emitClickHandlerActiveChanged = (!_pressed || !*_pressed || *_pressed == *_active); auto emitClickHandlerActiveChanged = (!_pressed || !*_pressed || *_pressed == *_active);
ClickHandlerPtr wasactive = *_active; auto wasactive = *_active;
(*_active).clear(); (*_active).clear();
if (_activeHost) { if (_activeHost) {
if (emitClickHandlerActiveChanged) { if (emitClickHandlerActiveChanged) {

View File

@ -32,7 +32,6 @@ enum ExpandLinksMode {
class ClickHandlerHost { class ClickHandlerHost {
protected: protected:
virtual void clickHandlerActiveChanged(const ClickHandlerPtr &action, bool active) { virtual void clickHandlerActiveChanged(const ClickHandlerPtr &action, bool active) {
} }
virtual void clickHandlerPressedChanged(const ClickHandlerPtr &action, bool pressed) { virtual void clickHandlerPressedChanged(const ClickHandlerPtr &action, bool pressed) {

View File

@ -349,17 +349,13 @@ bool History::updateSendActionNeedsAnimating(TimeMs ms, bool force) {
return result; return result;
} }
ChannelHistory::ChannelHistory(const PeerId &peer) : History(peer)
, _joinedMessage(nullptr) {
}
void ChannelHistory::getRangeDifference() { void ChannelHistory::getRangeDifference() {
MsgId fromId = 0, toId = 0; auto fromId = MsgId(0), toId = MsgId(0);
for (int32 blockIndex = 0, blocksCount = blocks.size(); blockIndex < blocksCount; ++blockIndex) { for (auto blockIndex = 0, blocksCount = blocks.size(); blockIndex < blocksCount; ++blockIndex) {
HistoryBlock *block = blocks.at(blockIndex); auto block = blocks.at(blockIndex);
for (int32 itemIndex = 0, itemsCount = block->items.size(); itemIndex < itemsCount; ++itemIndex) { for (auto itemIndex = 0, itemsCount = block->items.size(); itemIndex < itemsCount; ++itemIndex) {
HistoryItem *item = block->items.at(itemIndex); auto item = block->items.at(itemIndex);
if (item->type() == HistoryItemMsg && item->id > 0) { if (item->id > 0) {
fromId = item->id; fromId = item->id;
break; break;
} }
@ -367,11 +363,12 @@ void ChannelHistory::getRangeDifference() {
if (fromId) break; if (fromId) break;
} }
if (!fromId) return; if (!fromId) return;
for (int32 blockIndex = blocks.size(); blockIndex > 0;) {
HistoryBlock *block = blocks.at(--blockIndex); for (auto blockIndex = blocks.size(); blockIndex > 0;) {
for (int32 itemIndex = block->items.size(); itemIndex > 0;) { auto block = blocks.at(--blockIndex);
HistoryItem *item = block->items.at(--itemIndex); for (auto itemIndex = block->items.size(); itemIndex > 0;) {
if (item->type() == HistoryItemMsg && item->id > 0) { auto item = block->items.at(--itemIndex);
if (item->id > 0) {
toId = item->id; toId = item->id;
break; break;
} }
@ -423,31 +420,29 @@ HistoryJoined *ChannelHistory::insertJoinedMessage(bool unread) {
return _joinedMessage; return _joinedMessage;
} }
for (int32 blockIndex = blocks.size(); blockIndex > 0;) { for (auto blockIndex = blocks.size(); blockIndex > 0;) {
HistoryBlock *block = blocks.at(--blockIndex); auto block = blocks.at(--blockIndex);
for (int32 itemIndex = block->items.size(); itemIndex > 0;) { for (auto itemIndex = block->items.size(); itemIndex > 0;) {
HistoryItem *item = block->items.at(--itemIndex); auto item = block->items.at(--itemIndex);
HistoryItemType type = item->type();
if (type == HistoryItemMsg) { // Due to a server bug sometimes inviteDate is less (before) than the
// Due to a server bug sometimes inviteDate is less (before) than the // first message in the megagroup (message about migration), let us
// first message in the megagroup (message about migration), let us // ignore that and think, that the inviteDate is always greater-or-equal.
// 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;
peer->asChannel()->mgInfo->joinedMessageFound = true; return nullptr;
return nullptr; }
} if (item->date <= inviteDate) {
if (item->date <= inviteDate) { ++itemIndex;
++itemIndex; _joinedMessage = HistoryJoined::create(this, inviteDate, inviter, flags);
_joinedMessage = HistoryJoined::create(this, inviteDate, inviter, flags); addNewInTheMiddle(_joinedMessage, blockIndex, itemIndex);
addNewInTheMiddle(_joinedMessage, blockIndex, itemIndex); if (lastMsgDate.isNull() || inviteDate >= lastMsgDate) {
if (lastMsgDate.isNull() || inviteDate >= lastMsgDate) { setLastMessage(_joinedMessage);
setLastMessage(_joinedMessage); if (unread) {
if (unread) { newItemAdded(_joinedMessage);
newItemAdded(_joinedMessage);
}
} }
return _joinedMessage;
} }
return _joinedMessage;
} }
} }
} }
@ -479,34 +474,10 @@ void ChannelHistory::checkJoinedMessage(bool createUnread) {
QDateTime inviteDate = peer->asChannel()->inviteDate; QDateTime inviteDate = peer->asChannel()->inviteDate;
QDateTime firstDate, lastDate; QDateTime firstDate, lastDate;
for (int blockIndex = 0, blocksCount = blocks.size(); blockIndex < blocksCount; ++blockIndex) { if (!blocks.isEmpty()) {
HistoryBlock *block = blocks.at(blockIndex); firstDate = blocks.front()->items.front()->date;
int itemIndex = 0, itemsCount = block->items.size(); lastDate = blocks.back()->items.back()->date;
for (; itemIndex < itemsCount; ++itemIndex) {
HistoryItem *item = block->items.at(itemIndex);
HistoryItemType type = item->type();
if (type == HistoryItemMsg) {
firstDate = item->date;
break;
}
}
if (itemIndex < itemsCount) break;
} }
for (int blockIndex = blocks.size(); blockIndex > 0;) {
HistoryBlock *block = blocks.at(--blockIndex);
int itemIndex = block->items.size();
for (; itemIndex > 0;) {
HistoryItem *item = block->items.at(--itemIndex);
HistoryItemType type = item->type();
if (type == HistoryItemMsg) {
lastDate = item->date;
++itemIndex;
break;
}
}
if (itemIndex) break;
}
if (!firstDate.isNull() && !lastDate.isNull() && (firstDate <= inviteDate || loadedAtTop()) && (lastDate > inviteDate || loadedAtBottom())) { if (!firstDate.isNull() && !lastDate.isNull() && (firstDate <= inviteDate || loadedAtTop()) && (lastDate > inviteDate || loadedAtBottom())) {
bool willBeLastMsg = (inviteDate >= lastDate); bool willBeLastMsg = (inviteDate >= lastDate);
if (insertJoinedMessage(createUnread && willBeLastMsg) && willBeLastMsg) { if (insertJoinedMessage(createUnread && willBeLastMsg) && willBeLastMsg) {
@ -567,25 +538,6 @@ void ChannelHistory::cleared(bool leaveItems) {
_joinedMessage = nullptr; _joinedMessage = nullptr;
} }
HistoryItem *ChannelHistory::findPrevItem(HistoryItem *item) const {
if (item->detached()) return nullptr;
int itemIndex = item->indexInBlock();
int blockIndex = item->block()->indexInHistory();
for (++blockIndex, ++itemIndex; blockIndex > 0;) {
--blockIndex;
HistoryBlock *block = blocks.at(blockIndex);
if (!itemIndex) itemIndex = block->items.size();
for (; itemIndex > 0;) {
--itemIndex;
if (block->items.at(itemIndex)->type() == HistoryItemMsg) {
return block->items.at(itemIndex);
}
}
}
return nullptr;
}
void ChannelHistory::messageDetached(HistoryItem *msg) { void ChannelHistory::messageDetached(HistoryItem *msg) {
if (_joinedMessage == msg) { if (_joinedMessage == msg) {
_joinedMessage = nullptr; _joinedMessage = nullptr;
@ -1415,7 +1367,7 @@ void History::addNewerSlice(const QVector<MTPMessage> &slice) {
if (slice.isEmpty()) { if (slice.isEmpty()) {
newLoaded = true; newLoaded = true;
if (!lastMsg) { if (!lastMsg) {
setLastMessage(lastImportantMessage()); setLastMessage(lastAvailableMessage());
} }
} }
@ -1433,7 +1385,7 @@ void History::addNewerSlice(const QVector<MTPMessage> &slice) {
if (!atLeastOneAdded) { if (!atLeastOneAdded) {
newLoaded = true; newLoaded = true;
setLastMessage(lastImportantMessage()); setLastMessage(lastAvailableMessage());
} }
} }
@ -1452,7 +1404,7 @@ void History::checkLastMsg() {
checkAddAllToOverview(); checkAddAllToOverview();
} }
} else if (newLoaded) { } else if (newLoaded) {
setLastMessage(lastImportantMessage()); setLastMessage(lastAvailableMessage());
} }
} }
@ -1506,7 +1458,7 @@ void History::updateShowFrom() {
--i; --i;
for (auto j = (*i)->items.cend(); j != (*i)->items.cbegin();) { for (auto j = (*i)->items.cend(); j != (*i)->items.cbegin();) {
--j; --j;
if ((*j)->type() == HistoryItemMsg && (*j)->id > 0 && (!(*j)->out() || !showFrom)) { if ((*j)->id > 0 && (!(*j)->out() || !showFrom)) {
if ((*j)->id >= inboxReadBefore) { if ((*j)->id >= inboxReadBefore) {
showFrom = *j; showFrom = *j;
} else { } else {
@ -1556,27 +1508,14 @@ MsgId History::outboxRead(HistoryItem *wasRead) {
return outboxRead(wasRead ? wasRead->id : 0); return outboxRead(wasRead ? wasRead->id : 0);
} }
HistoryItem *History::lastImportantMessage() const { HistoryItem *History::lastAvailableMessage() const {
if (isEmpty()) { return isEmpty() ? nullptr : blocks.back()->items.back();
return nullptr;
}
bool importantOnly = isChannel() && !isMegagroup();
for (int blockIndex = blocks.size(); blockIndex > 0;) {
HistoryBlock *block = blocks.at(--blockIndex);
for (int itemIndex = block->items.size(); itemIndex > 0;) {
HistoryItem *item = block->items.at(--itemIndex);
if (item->type() == HistoryItemMsg) {
return item;
}
}
}
return nullptr;
} }
void History::setUnreadCount(int newUnreadCount) { void History::setUnreadCount(int newUnreadCount) {
if (_unreadCount != newUnreadCount) { if (_unreadCount != newUnreadCount) {
if (newUnreadCount == 1) { if (newUnreadCount == 1) {
if (loadedAtBottom()) showFrom = lastImportantMessage(); if (loadedAtBottom()) showFrom = lastAvailableMessage();
inboxReadBefore = qMax(inboxReadBefore, msgIdForRead()); inboxReadBefore = qMax(inboxReadBefore, msgIdForRead());
} else if (!newUnreadCount) { } else if (!newUnreadCount) {
showFrom = nullptr; showFrom = nullptr;
@ -1626,19 +1565,19 @@ void History::setUnreadCount(int newUnreadCount) {
void History::getNextShowFrom(HistoryBlock *block, int i) { void History::getNextShowFrom(HistoryBlock *block, int i) {
if (i >= 0) { if (i >= 0) {
int l = block->items.size(); auto l = block->items.size();
for (++i; i < l; ++i) { for (++i; i < l; ++i) {
if (block->items.at(i)->type() == HistoryItemMsg) { if (block->items[i]->id > 0) {
showFrom = block->items.at(i); showFrom = block->items.at(i);
return; return;
} }
} }
} }
for (int j = block->indexInHistory() + 1, s = blocks.size(); j < s; ++j) { for (auto j = block->indexInHistory() + 1, s = blocks.size(); j < s; ++j) {
block = blocks.at(j); block = blocks.at(j);
for_const (HistoryItem *item, block->items) { for_const (auto item, block->items) {
if (item->type() == HistoryItemMsg) { if (item->id > 0) {
showFrom = item; showFrom = item;
return; return;
} }
@ -1935,7 +1874,7 @@ void History::updateChatListSortPosition() {
} }
void History::fixLastMessage(bool wasAtBottom) { void History::fixLastMessage(bool wasAtBottom) {
setLastMessage(wasAtBottom ? lastImportantMessage() : 0); setLastMessage(wasAtBottom ? lastAvailableMessage() : 0);
} }
MsgId History::minMsgId() const { MsgId History::minMsgId() const {

View File

@ -240,7 +240,7 @@ public:
MsgId outboxRead(MsgId upTo); MsgId outboxRead(MsgId upTo);
MsgId outboxRead(HistoryItem *wasRead); MsgId outboxRead(HistoryItem *wasRead);
HistoryItem *lastImportantMessage() const; HistoryItem *lastAvailableMessage() const;
int unreadCount() const { int unreadCount() const {
return _unreadCount; return _unreadCount;
@ -584,7 +584,7 @@ private:
class HistoryJoined; class HistoryJoined;
class ChannelHistory : public History { class ChannelHistory : public History {
public: public:
ChannelHistory(const PeerId &peer); using History::History;
void messageDetached(HistoryItem *msg); void messageDetached(HistoryItem *msg);
@ -604,13 +604,11 @@ private:
void checkMaxReadMessageDate(); void checkMaxReadMessageDate();
HistoryItem *findPrevItem(HistoryItem *item) const;
void cleared(bool leaveItems); void cleared(bool leaveItems);
QDateTime _maxReadMessageDate; QDateTime _maxReadMessageDate;
HistoryJoined *_joinedMessage; HistoryJoined *_joinedMessage = nullptr;
MsgId _rangeDifferenceFromId, _rangeDifferenceToId; MsgId _rangeDifferenceFromId, _rangeDifferenceToId;
int32 _rangeDifferencePts; int32 _rangeDifferencePts;

View File

@ -650,7 +650,7 @@ void HistoryItem::destroy() {
// All this must be done for all items manually in History::clear(false)! // All this must be done for all items manually in History::clear(false)!
eraseFromOverview(); eraseFromOverview();
bool wasAtBottom = history()->loadedAtBottom(); auto wasAtBottom = history()->loadedAtBottom();
_history->removeNotification(this); _history->removeNotification(this);
detach(); detach();
if (history()->isChannel()) { if (history()->isChannel()) {

View File

@ -101,11 +101,6 @@ enum InfoDisplayType {
InfoDisplayOverBackground, InfoDisplayOverBackground,
}; };
enum HistoryItemType {
HistoryItemMsg = 0,
HistoryItemJoined
};
struct HistoryMessageVia : public RuntimeComponent<HistoryMessageVia> { struct HistoryMessageVia : public RuntimeComponent<HistoryMessageVia> {
void create(int32 userId); void create(int32 userId);
void resize(int32 availw) const; void resize(int32 availw) const;
@ -630,9 +625,6 @@ public:
void clickHandlerActiveChanged(const ClickHandlerPtr &p, bool active) override; void clickHandlerActiveChanged(const ClickHandlerPtr &p, bool active) override;
void clickHandlerPressedChanged(const ClickHandlerPtr &p, bool pressed) override; void clickHandlerPressedChanged(const ClickHandlerPtr &p, bool pressed) override;
virtual HistoryItemType type() const {
return HistoryItemMsg;
}
virtual bool serviceMsg() const { virtual bool serviceMsg() const {
return false; return false;
} }
@ -687,7 +679,7 @@ public:
} }
bool canDelete() const { bool canDelete() const {
ChannelData *channel = _history->peer->asChannel(); auto channel = _history->peer->asChannel();
if (!channel) return !(_flags & MTPDmessage_ClientFlag::f_is_group_migrate); if (!channel) return !(_flags & MTPDmessage_ClientFlag::f_is_group_migrate);
if (id == 1) return false; if (id == 1) return false;
@ -707,7 +699,7 @@ public:
bool canDeleteForEveryone(const QDateTime &cur) const; bool canDeleteForEveryone(const QDateTime &cur) const;
bool suggestBanReportDeleteAll() const { bool suggestBanReportDeleteAll() const {
ChannelData *channel = history()->peer->asChannel(); auto channel = history()->peer->asChannel();
if (!channel || (!channel->amEditor() && !channel->amCreator())) return false; if (!channel || (!channel->amEditor() && !channel->amCreator())) return false;
return !isPost() && !out() && from()->isUser() && toHistoryMessage(); return !isPost() && !out() && from()->isUser() && toHistoryMessage();
} }

View File

@ -357,10 +357,6 @@ public:
return _create(history, date, from, flags); return _create(history, date, from, flags);
} }
HistoryItemType type() const {
return HistoryItemJoined;
}
protected: protected:
HistoryJoined(History *history, const QDateTime &date, UserData *from, MTPDmessage::Flags flags); HistoryJoined(History *history, const QDateTime &date, UserData *from, MTPDmessage::Flags flags);
using HistoryItemInstantiated<HistoryJoined>::_create; using HistoryItemInstantiated<HistoryJoined>::_create;

View File

@ -989,7 +989,7 @@ void HistoryInner::onDragExec() {
} }
} }
} }
ClickHandlerPtr pressedHandler = ClickHandler::getPressed(); auto pressedHandler = ClickHandler::getPressed();
TextWithEntities sel; TextWithEntities sel;
QList<QUrl> urls; QList<QUrl> urls;
if (uponSelected) { if (uponSelected) {
@ -1004,7 +1004,7 @@ void HistoryInner::onDragExec() {
updateDragSelection(0, 0, false); updateDragSelection(0, 0, false);
_widget->noSelectingScroll(); _widget->noSelectingScroll();
QDrag *drag = new QDrag(App::wnd()); auto drag = std_::make_unique<QDrag>(App::wnd());
if (!urls.isEmpty()) mimeData->setUrls(urls); if (!urls.isEmpty()) mimeData->setUrls(urls);
if (uponSelected && !_selected.isEmpty() && _selected.cbegin().value() == FullSelection && !Adaptive::OneColumn()) { if (uponSelected && !_selected.isEmpty() && _selected.cbegin().value() == FullSelection && !Adaptive::OneColumn()) {
mimeData->setData(qsl("application/x-td-forward-selected"), "1"); mimeData->setData(qsl("application/x-td-forward-selected"), "1");
@ -1017,15 +1017,15 @@ void HistoryInner::onDragExec() {
if (App::main()) App::main()->updateAfterDrag(); if (App::main()) App::main()->updateAfterDrag();
return; return;
} else { } else {
QString forwardMimeType; auto forwardMimeType = QString();
HistoryMedia *pressedMedia = nullptr; auto pressedMedia = static_cast<HistoryMedia*>(nullptr);
if (HistoryItem *pressedItem = App::pressedItem()) { if (auto pressedItem = App::pressedItem()) {
pressedMedia = pressedItem->getMedia(); pressedMedia = pressedItem->getMedia();
if (_dragCursorState == HistoryInDateCursorState || (pressedMedia && pressedMedia->dragItem())) { if (_dragCursorState == HistoryInDateCursorState || (pressedMedia && pressedMedia->dragItem())) {
forwardMimeType = qsl("application/x-td-forward-pressed"); forwardMimeType = qsl("application/x-td-forward-pressed");
} }
} }
if (HistoryItem *pressedLnkItem = App::pressedLinkItem()) { if (auto pressedLnkItem = App::pressedLinkItem()) {
if ((pressedMedia = pressedLnkItem->getMedia())) { if ((pressedMedia = pressedLnkItem->getMedia())) {
if (forwardMimeType.isEmpty() && pressedMedia->dragItemByHandler(pressedHandler)) { if (forwardMimeType.isEmpty() && pressedMedia->dragItemByHandler(pressedHandler)) {
forwardMimeType = qsl("application/x-td-forward-pressed-link"); forwardMimeType = qsl("application/x-td-forward-pressed-link");
@ -1033,12 +1033,12 @@ void HistoryInner::onDragExec() {
} }
} }
if (!forwardMimeType.isEmpty()) { if (!forwardMimeType.isEmpty()) {
QDrag *drag = new QDrag(App::wnd()); auto drag = std_::make_unique<QDrag>(App::wnd());
QMimeData *mimeData = new QMimeData(); auto mimeData = std_::make_unique<QMimeData>();
mimeData->setData(forwardMimeType, "1"); mimeData->setData(forwardMimeType, "1");
if (DocumentData *document = (pressedMedia ? pressedMedia->getDocument() : nullptr)) { if (auto document = (pressedMedia ? pressedMedia->getDocument() : nullptr)) {
QString filepath = document->filepath(DocumentData::FilePathResolveChecked); auto filepath = document->filepath(DocumentData::FilePathResolveChecked);
if (!filepath.isEmpty()) { if (!filepath.isEmpty()) {
QList<QUrl> urls; QList<QUrl> urls;
urls.push_back(QUrl::fromLocalFile(filepath)); urls.push_back(QUrl::fromLocalFile(filepath));
@ -1046,7 +1046,7 @@ void HistoryInner::onDragExec() {
} }
} }
drag->setMimeData(mimeData); drag->setMimeData(mimeData.release());
drag->exec(Qt::CopyAction); drag->exec(Qt::CopyAction);
// We don't receive mouseReleaseEvent when drag is finished. // We don't receive mouseReleaseEvent when drag is finished.
@ -1315,8 +1315,8 @@ void HistoryInner::showContextMenu(QContextMenuEvent *e, bool showFromTouch) {
App::contextItem(App::hoveredLinkItem()); App::contextItem(App::hoveredLinkItem());
} }
} else { // maybe cursor on some text history item? } else { // maybe cursor on some text history item?
bool canDelete = (item && item->type() == HistoryItemMsg) && item->canDelete(); bool canDelete = item && item->canDelete() && (item->id > 0 || !item->serviceMsg());
bool canForward = (item && item->type() == HistoryItemMsg) && (item->id > 0) && !item->serviceMsg(); bool canForward = item && (item->id > 0) && !item->serviceMsg();
HistoryMessage *msg = dynamic_cast<HistoryMessage*>(item); HistoryMessage *msg = dynamic_cast<HistoryMessage*>(item);
if (isUponSelected > 0) { if (isUponSelected > 0) {
@ -1835,7 +1835,7 @@ void HistoryInner::enterEvent(QEvent *e) {
} }
void HistoryInner::leaveEvent(QEvent *e) { void HistoryInner::leaveEvent(QEvent *e) {
if (HistoryItem *item = App::hoveredItem()) { if (auto item = App::hoveredItem()) {
repaintItem(item); repaintItem(item);
App::hoveredItem(nullptr); App::hoveredItem(nullptr);
} }
@ -1948,8 +1948,8 @@ bool HistoryInner::canDeleteSelected() const {
void HistoryInner::getSelectionState(int32 &selectedForForward, int32 &selectedForDelete) const { void HistoryInner::getSelectionState(int32 &selectedForForward, int32 &selectedForDelete) const {
selectedForForward = selectedForDelete = 0; selectedForForward = selectedForDelete = 0;
for (SelectedItems::const_iterator i = _selected.cbegin(), e = _selected.cend(); i != e; ++i) { for (auto i = _selected.cbegin(), e = _selected.cend(); i != e; ++i) {
if (i.key()->type() == HistoryItemMsg && i.value() == FullSelection) { if (i.value() == FullSelection) {
if (i.key()->canDelete()) { if (i.key()->canDelete()) {
++selectedForDelete; ++selectedForDelete;
} }
@ -2005,8 +2005,8 @@ void HistoryInner::onUpdateSelected() {
return; return;
} }
QPoint mousePos(mapFromGlobal(_dragPos)); auto mousePos = mapFromGlobal(_dragPos);
QPoint point(_widget->clampMousePosition(mousePos)); auto point = _widget->clampMousePosition(mousePos);
HistoryBlock *block = 0; HistoryBlock *block = 0;
HistoryItem *item = 0; HistoryItem *item = 0;
@ -6180,15 +6180,15 @@ void HistoryWidget::contextMenuEvent(QContextMenuEvent *e) {
} }
void HistoryWidget::forwardMessage() { void HistoryWidget::forwardMessage() {
HistoryItem *item = App::contextItem(); auto item = App::contextItem();
if (!item || item->type() != HistoryItemMsg || item->serviceMsg()) return; if (!item || item->id < 0 || item->serviceMsg()) return;
App::main()->forwardLayer(); App::main()->forwardLayer();
} }
void HistoryWidget::selectMessage() { void HistoryWidget::selectMessage() {
HistoryItem *item = App::contextItem(); auto item = App::contextItem();
if (!item || item->type() != HistoryItemMsg || item->serviceMsg()) return; if (!item || item->id < 0 || item->serviceMsg()) return;
if (_list) _list->selectItem(item); if (_list) _list->selectItem(item);
} }
@ -7861,12 +7861,12 @@ void HistoryWidget::onReplyToMessage() {
onReplyToMessage(); onReplyToMessage();
App::contextItem(to); App::contextItem(to);
} else { } else {
if (to->type() != HistoryItemMsg || to->serviceMsg()) { if (to->id < 0 || to->serviceMsg()) {
Ui::show(Box<InformBox>(lang(lng_reply_cant))); Ui::show(Box<InformBox>(lang(lng_reply_cant)));
} else { } else {
Ui::show(Box<ConfirmBox>(lang(lng_reply_cant_forward), lang(lng_selected_forward), base::lambda_guarded(this, [this] { Ui::show(Box<ConfirmBox>(lang(lng_reply_cant_forward), lang(lng_selected_forward), base::lambda_guarded(this, [this] {
auto item = App::contextItem(); auto item = App::contextItem();
if (!item || item->type() != HistoryItemMsg || item->serviceMsg()) return; if (!item || item->id < 0 || item->serviceMsg()) return;
App::forward(_peer->id, ForwardContextMessage); App::forward(_peer->id, ForwardContextMessage);
}))); })));
@ -8381,7 +8381,7 @@ void HistoryWidget::onForwardSelected() {
void HistoryWidget::confirmDeleteContextItem() { void HistoryWidget::confirmDeleteContextItem() {
auto item = App::contextItem(); auto item = App::contextItem();
if (!item || item->type() != HistoryItemMsg) return; if (!item) return;
if (auto message = item->toHistoryMessage()) { if (auto message = item->toHistoryMessage()) {
if (message->uploading()) { if (message->uploading()) {
@ -8406,7 +8406,7 @@ void HistoryWidget::deleteContextItem(bool forEveryone) {
Ui::hideLayer(); Ui::hideLayer();
auto item = App::contextItem(); auto item = App::contextItem();
if (!item || item->type() != HistoryItemMsg) { if (!item) {
return; return;
} }

View File

@ -881,16 +881,16 @@ void MainWidget::deleteAllFromUser(ChannelData *channel, UserData *from) {
t_assert(channel != nullptr && from != nullptr); t_assert(channel != nullptr && from != nullptr);
QVector<MsgId> toDestroy; QVector<MsgId> toDestroy;
if (History *history = App::historyLoaded(channel->id)) { if (auto history = App::historyLoaded(channel->id)) {
for (HistoryBlock *block : history->blocks) { for_const (auto block, history->blocks) {
for (HistoryItem *item : block->items) { for_const (auto item, block->items) {
if (item->from() == from && item->type() == HistoryItemMsg && item->canDelete()) { if (item->from() == from && item->canDelete()) {
toDestroy.push_back(item->id); toDestroy.push_back(item->id);
} }
} }
} }
for (const MsgId &msgId : toDestroy) { for_const (auto &msgId, toDestroy) {
if (HistoryItem *item = App::histItemById(peerToChannel(channel->id), msgId)) { if (auto item = App::histItemById(peerToChannel(channel->id), msgId)) {
item->destroy(); item->destroy();
} }
} }
@ -3867,17 +3867,17 @@ void MainWidget::onFullPeerUpdated(PeerData *peer) {
} }
void MainWidget::onSelfParticipantUpdated(ChannelData *channel) { void MainWidget::onSelfParticipantUpdated(ChannelData *channel) {
History *h = App::historyLoaded(channel->id); auto history = App::historyLoaded(channel->id);
if (_updatedChannels.contains(channel)) { if (_updatedChannels.contains(channel)) {
_updatedChannels.remove(channel); _updatedChannels.remove(channel);
if ((h ? h : App::history(channel->id))->isEmpty()) { if ((history ? history : App::history(channel->id))->isEmpty()) {
checkPeerHistory(channel); checkPeerHistory(channel);
} else { } else {
h->asChannelHistory()->checkJoinedMessage(true); history->asChannelHistory()->checkJoinedMessage(true);
_history->peerMessagesUpdated(channel->id); _history->peerMessagesUpdated(channel->id);
} }
} else if (h) { } else if (history) {
h->asChannelHistory()->checkJoinedMessage(); history->asChannelHistory()->checkJoinedMessage();
_history->peerMessagesUpdated(channel->id); _history->peerMessagesUpdated(channel->id);
} }
} }

View File

@ -1142,9 +1142,8 @@ void OverviewInner::enterEvent(QEvent *e) {
} }
void OverviewInner::leaveEvent(QEvent *e) { void OverviewInner::leaveEvent(QEvent *e) {
if (_selectedMsgId) { if (auto selectedMsgId = base::take(_selectedMsgId)) {
repaintItem(_selectedMsgId, -1); repaintItem(selectedMsgId, -1);
_selectedMsgId = 0;
} }
ClickHandler::clearActive(); ClickHandler::clearActive();
if (!ClickHandler::getPressed() && _cursor != style::cur_default) { if (!ClickHandler::getPressed() && _cursor != style::cur_default) {
@ -1406,8 +1405,8 @@ void OverviewInner::goToMessage() {
} }
void OverviewInner::forwardMessage() { void OverviewInner::forwardMessage() {
HistoryItem *item = App::contextItem(); auto item = App::contextItem();
if (!item || item->type() != HistoryItemMsg || item->serviceMsg()) return; if (!item || item->id < 0) return;
App::main()->forwardLayer(); App::main()->forwardLayer();
} }
@ -1417,8 +1416,8 @@ MsgId OverviewInner::complexMsgId(const HistoryItem *item) const {
} }
void OverviewInner::selectMessage() { void OverviewInner::selectMessage() {
HistoryItem *item = App::contextItem(); auto item = App::contextItem();
if (!item || item->type() != HistoryItemMsg || item->serviceMsg()) return; if (!item || item->id < 0) return;
if (!_selected.isEmpty() && _selected.cbegin().value() != FullSelection) { if (!_selected.isEmpty() && _selected.cbegin().value() != FullSelection) {
_selected.clear(); _selected.clear();
@ -2274,7 +2273,7 @@ void OverviewWidget::onForwardSelected() {
void OverviewWidget::confirmDeleteContextItem() { void OverviewWidget::confirmDeleteContextItem() {
auto item = App::contextItem(); auto item = App::contextItem();
if (!item || item->type() != HistoryItemMsg) return; if (!item) return;
if (auto message = item->toHistoryMessage()) { if (auto message = item->toHistoryMessage()) {
if (message->uploading()) { if (message->uploading()) {
@ -2297,7 +2296,7 @@ void OverviewWidget::deleteContextItem(bool forEveryone) {
Ui::hideLayer(); Ui::hideLayer();
auto item = App::contextItem(); auto item = App::contextItem();
if (!item || item->type() != HistoryItemMsg) { if (!item) {
return; return;
} }

View File

@ -1861,6 +1861,6 @@ ClickHandlerPtr peerOpenClickHandler(PeerData *peer) {
MsgId clientMsgId() { MsgId clientMsgId() {
static MsgId currentClientMsgId = StartClientMsgId; static MsgId currentClientMsgId = StartClientMsgId;
Q_ASSERT(currentClientMsgId < EndClientMsgId); t_assert(currentClientMsgId < EndClientMsgId);
return currentClientMsgId++; return currentClientMsgId++;
} }