Fixed crash when deleting items.
Fixed unread counter clear when logging out.
This commit is contained in:
parent
40ab82e4bd
commit
b32c6566ff
|
@ -1787,7 +1787,6 @@ namespace App {
|
|||
if (App::wnd()) {
|
||||
App::wnd()->notifyItemRemoved(item);
|
||||
}
|
||||
item->history()->setPendingResize();
|
||||
}
|
||||
|
||||
void historyUnregItem(HistoryItem *item) {
|
||||
|
|
|
@ -1138,6 +1138,10 @@ void Histories::clear() {
|
|||
for (Map::const_iterator i = map.cbegin(), e = map.cend(); i != e; ++i) {
|
||||
delete i.value();
|
||||
}
|
||||
_unreadFull = _unreadMuted = 0;
|
||||
if (App::wnd()) {
|
||||
App::wnd()->updateCounter();
|
||||
}
|
||||
App::historyClearItems();
|
||||
typing.clear();
|
||||
map.clear();
|
||||
|
@ -1999,7 +2003,7 @@ void History::setUnreadCount(int newUnreadCount, bool psUpdate) {
|
|||
if (loadedAtBottom()) showFrom = lastImportantMessage();
|
||||
inboxReadBefore = qMax(inboxReadBefore, msgIdForRead());
|
||||
} else if (!newUnreadCount) {
|
||||
showFrom = 0;
|
||||
showFrom = nullptr;
|
||||
inboxReadBefore = qMax(inboxReadBefore, msgIdForRead() + 1);
|
||||
}
|
||||
if (inChatList()) {
|
||||
|
@ -2564,8 +2568,6 @@ void History::changeMsgId(MsgId oldId, MsgId newId) {
|
|||
}
|
||||
|
||||
void History::removeBlock(HistoryBlock *block) {
|
||||
setPendingResize();
|
||||
|
||||
t_assert(block->items.isEmpty());
|
||||
|
||||
int index = block->indexInHistory();
|
||||
|
@ -2576,7 +2578,6 @@ void History::removeBlock(HistoryBlock *block) {
|
|||
if (index < blocks.size()) {
|
||||
blocks.at(index)->items.front()->previousItemChanged();
|
||||
}
|
||||
delete block;
|
||||
}
|
||||
|
||||
History::~History() {
|
||||
|
@ -2684,26 +2685,26 @@ void HistoryBlock::removeItem(HistoryItem *item) {
|
|||
}
|
||||
}
|
||||
}
|
||||
// blockIndex can be invalid now, because of destroying previous blocks
|
||||
|
||||
// itemIndex/blockIndex can be invalid now, because of destroying previous items/blocks
|
||||
blockIndex = indexInHistory();
|
||||
itemIndex = item->indexInBlock();
|
||||
|
||||
item->detachFast();
|
||||
items.remove(itemIndex);
|
||||
for (int i = itemIndex, l = items.size(); i < l; ++i) {
|
||||
items.at(i)->setIndexInBlock(i);
|
||||
}
|
||||
if (itemIndex < items.size()) {
|
||||
if (items.isEmpty()) {
|
||||
history->removeBlock(this);
|
||||
} else if (itemIndex < items.size()) {
|
||||
items.at(itemIndex)->previousItemChanged();
|
||||
} else if (_indexInHistory + 1 < history->blocks.size()) {
|
||||
history->blocks.at(_indexInHistory + 1)->items.front()->previousItemChanged();
|
||||
}
|
||||
|
||||
if ((!item->out() || item->isPost()) && item->unread() && history->unreadCount) {
|
||||
history->setUnreadCount(history->unreadCount - 1);
|
||||
} else if (blockIndex + 1 < history->blocks.size()) {
|
||||
history->blocks.at(blockIndex + 1)->items.front()->previousItemChanged();
|
||||
}
|
||||
|
||||
if (items.isEmpty()) {
|
||||
history->removeBlock(this);
|
||||
delete this;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2796,6 +2797,9 @@ void HistoryItem::destroy() {
|
|||
history()->clearLastKeyboard();
|
||||
if (App::main()) App::main()->updateBotKeyboard(history());
|
||||
}
|
||||
if ((!out() || isPost()) && unread() && history()->unreadCount > 0) {
|
||||
history()->setUnreadCount(history()->unreadCount - 1);
|
||||
}
|
||||
delete this;
|
||||
}
|
||||
|
||||
|
@ -2806,7 +2810,6 @@ void HistoryItem::detach() {
|
|||
_history->asChannelHistory()->messageDetached(this);
|
||||
}
|
||||
_block->removeItem(this);
|
||||
detachFast();
|
||||
App::historyItemDetached(this);
|
||||
|
||||
_history->setPendingResize();
|
||||
|
|
|
@ -239,7 +239,6 @@ public:
|
|||
return blocks.isEmpty();
|
||||
}
|
||||
void clear(bool leaveItems = false);
|
||||
void removeBlock(HistoryBlock *block);
|
||||
|
||||
virtual ~History();
|
||||
|
||||
|
@ -498,11 +497,16 @@ private:
|
|||
MediaOverviewIds overviewIds[OverviewCount];
|
||||
int32 overviewCountData[OverviewCount]; // -1 - not loaded, 0 - all loaded, > 0 - count, but not all loaded
|
||||
|
||||
void clearBlocks(bool leaveItems);
|
||||
|
||||
friend class HistoryBlock;
|
||||
friend class ChannelHistory;
|
||||
|
||||
// this method just removes a block from the blocks list
|
||||
// when the last item from this block was detached and
|
||||
// calls the required previousItemChanged()
|
||||
void removeBlock(HistoryBlock *block);
|
||||
|
||||
void clearBlocks(bool leaveItems);
|
||||
|
||||
HistoryItem *createItem(const MTPMessage &msg, bool applyServiceAction, bool detachExistingItem);
|
||||
HistoryItem *createItemForwarded(MsgId id, MTPDmessage::Flags flags, QDateTime date, int32 from, HistoryMessage *msg);
|
||||
HistoryItem *createItemDocument(MsgId id, MTPDmessage::Flags flags, int32 viaBotId, MsgId replyTo, QDateTime date, int32 from, DocumentData *doc, const QString &caption);
|
||||
|
|
Loading…
Reference in New Issue