removed itemReplaced

This commit is contained in:
John Preston 2015-12-23 15:55:32 +03:00
parent 41f5a87c80
commit 73a4d3510d
12 changed files with 47 additions and 192 deletions

View file

@ -64,36 +64,6 @@ void ApiWrap::itemRemoved(HistoryItem *item) {
}
}
void ApiWrap::itemReplaced(HistoryItem *oldItem, HistoryItem *newItem) {
if (HistoryReply *reply = oldItem->toHistoryReply()) {
ChannelData *channel = reply->history()->peer->asChannel();
ReplyToRequests *requests(replyToRequests(channel, true));
if (requests) {
ReplyToRequests::iterator i = requests->find(reply->replyToId());
if (i != requests->cend()) {
for (QList<HistoryReply*>::iterator j = i->replies.begin(); j != i->replies.end();) {
if ((*j) == reply) {
if (HistoryReply *newReply = newItem->toHistoryReply()) {
*j = newReply;
++j;
} else {
j = i->replies.erase(j);
}
} else {
++j;
}
}
if (i->replies.isEmpty()) {
requests->erase(i);
}
}
if (channel && requests->isEmpty()) {
_channelReplyToRequests.remove(channel);
}
}
}
}
void ApiWrap::requestReplyTo(HistoryReply *reply, ChannelData *channel, MsgId id) {
ReplyToRequest &req(channel ? _channelReplyToRequests[channel][id] : _replyToRequests[id]);
req.replies.append(reply);

View file

@ -29,7 +29,6 @@ public:
void init();
void itemRemoved(HistoryItem *item);
void itemReplaced(HistoryItem *oldItem, HistoryItem *newItem);
void requestReplyTo(HistoryReply *reply, ChannelData *channel, MsgId id);

View file

@ -1834,47 +1834,16 @@ namespace App {
return 0;
}
void itemReplaced(HistoryItem *oldItem, HistoryItem *newItem) {
if (HistoryReply *r = oldItem->toHistoryReply()) {
QMap<HistoryReply*, bool> &replies(::repliesTo[r->replyToMessage()]);
replies.remove(r);
if (HistoryReply *n = newItem->toHistoryReply()) {
replies.insert(n, true);
}
}
RepliesTo::iterator i = ::repliesTo.find(oldItem);
if (i != ::repliesTo.cend() && oldItem != newItem) {
QMap<HistoryReply*, bool> replies = i.value();
::repliesTo.erase(i);
::repliesTo[newItem] = replies;
for (QMap<HistoryReply*, bool>::iterator i = replies.begin(), e = replies.end(); i != e; ++i) {
i.key()->replyToReplaced(oldItem, newItem);
}
}
newItem->history()->itemReplaced(oldItem, newItem);
if (App::main()) App::main()->itemReplaced(oldItem, newItem);
if (App::hoveredItem() == oldItem) App::hoveredItem(newItem);
if (App::pressedItem() == oldItem) App::pressedItem(newItem);
if (App::hoveredLinkItem() == oldItem) App::hoveredLinkItem(newItem);
if (App::pressedLinkItem() == oldItem) App::pressedLinkItem(newItem);
if (App::contextItem() == oldItem) App::contextItem(newItem);
if (App::mousedItem() == oldItem) App::mousedItem(newItem);
}
HistoryItem *historyRegItem(HistoryItem *item) {
void historyRegItem(HistoryItem *item) {
MsgsData *data = fetchMsgsData(item->channelId());
MsgsData::const_iterator i = data->constFind(item->id);
if (i == data->cend()) {
data->insert(item->id, item);
return 0;
}
if (i.value() != item && !i.value()->block() && item->block()) { // replace search item
itemReplaced(i.value(), item);
delete i.value();
} else if (i.value() != item) {
LOG(("App Error: trying to historyRegItem() an already registered item"));
i.value()->destroy();
data->insert(item->id, item);
return 0;
}
return (i.value() == item) ? 0 : i.value();
}
void historyItemDetached(HistoryItem *item) {

View file

@ -149,7 +149,7 @@ namespace App {
inline HistoryItem *histItemById(const FullMsgId &msgId) {
return histItemById(msgId.channel, msgId.msg);
}
HistoryItem *historyRegItem(HistoryItem *item);
void historyRegItem(HistoryItem *item);
void historyItemDetached(HistoryItem *item);
void historyUnregItem(HistoryItem *item);
void historyClearMsgs();

View file

@ -907,14 +907,6 @@ void DialogsInner::clearSearchResults(bool clearPeople) {
_lastSearchId = _lastSearchMigratedId = 0;
}
void DialogsInner::itemReplaced(HistoryItem *oldItem, HistoryItem *newItem) {
for (int i = 0; i < _searchResults.size(); ++i) {
if (_searchResults[i]->_item == oldItem) {
_searchResults[i]->_item = newItem;
}
}
}
void DialogsInner::updateNotifySettings(PeerData *peer) {
if (_menu && _menuPeer == peer && _menu->actions().size() > 1) {
_menu->actions().at(1)->setText(lang(menuPeerMuted() ? lng_enable_notifications_from_tray : lng_disable_notifications_from_tray));
@ -1870,10 +1862,6 @@ void DialogsWidget::itemRemoved(HistoryItem *item) {
_inner.itemRemoved(item);
}
void DialogsWidget::itemReplaced(HistoryItem *oldItem, HistoryItem *newItem) {
_inner.itemReplaced(oldItem, newItem);
}
void DialogsWidget::updateNotifySettings(PeerData *peer) {
_inner.updateNotifySettings(peer);
}

View file

@ -115,7 +115,6 @@ public:
void onFilterUpdate(QString newFilter, bool force = false);
void onHashtagFilterUpdate(QStringRef newFilter);
void itemRemoved(HistoryItem *item);
void itemReplaced(HistoryItem *oldItem, HistoryItem *newItem);
PeerData *updateFromParentDrag(QPoint globalPos);
@ -258,7 +257,6 @@ public:
void onSearchMore();
void itemRemoved(HistoryItem *item);
void itemReplaced(HistoryItem *oldItem, HistoryItem *newItem);
void updateNotifySettings(PeerData *peer);

View file

@ -526,7 +526,7 @@ void ChannelHistory::insertCollapseItem(MsgId wasMinId) {
HistoryItem *item = block->items.at(itemIndex);
if (insertAfter || item->id > wasMinId || (item->id == wasMinId && !item->isImportant())) {
_collapseMessage = new HistoryCollapse(this, block, wasMinId, item->date);
if (!addNewInTheMiddle(_collapseMessage, blockIndex, itemIndex)) {
if (!addNewInTheMiddle(regItem(_collapseMessage), blockIndex, itemIndex)) {
_collapseMessage = 0;
}
return;
@ -670,12 +670,12 @@ HistoryJoined *ChannelHistory::insertJoinedMessage(bool unread) {
++itemIndex;
if (item->date.date() != inviteDate.date()) {
HistoryDateMsg *joinedDateItem = new HistoryDateMsg(this, block, inviteDate.date());
if (addNewInTheMiddle(joinedDateItem, blockIndex, itemIndex)) {
if (addNewInTheMiddle(regItem(joinedDateItem), blockIndex, itemIndex)) {
++itemIndex;
}
}
_joinedMessage = new HistoryJoined(this, block, inviteDate, inviter, flags);
if (!addNewInTheMiddle(_joinedMessage, blockIndex, itemIndex)) {
if (!addNewInTheMiddle(regItem(_joinedMessage), blockIndex, itemIndex)) {
_joinedMessage = 0;
}
if (lastSeenDateItem && lastSeenDateItem->date.date() == inviteDate.date()) {
@ -709,11 +709,7 @@ HistoryJoined *ChannelHistory::insertJoinedMessage(bool unread) {
HistoryBlock *block = new HistoryBlock(this);
_joinedMessage = new HistoryJoined(this, block, inviteDate, inviter, flags);
if (regItem(_joinedMessage)) {
addItemAfterPrevToBlock(_joinedMessage, 0, block);
} else {
_joinedMessage = 0;
}
addItemAfterPrevToBlock(regItem(_joinedMessage), 0, block);
if (till && _joinedMessage && inviteDate.date() != till->date.date()) {
HistoryItem *dayItem = createDayServiceMsg(this, block, till->date);
block->items.push_back(dayItem);
@ -1316,9 +1312,7 @@ HistoryItem *Histories::addNewMessage(const MTPMessage &msg, NewMessageType type
return findOrInsert(peer, 0, 0)->addNewMessage(msg, type);
}
HistoryItem *History::createItem(HistoryBlock *block, const MTPMessage &msg, bool applyServiceAction, bool returnExisting) {
HistoryItem *result = 0;
HistoryItem *History::createItem(HistoryBlock *block, const MTPMessage &msg, bool applyServiceAction) {
MsgId msgId = 0;
switch (msg.type()) {
case mtpc_messageEmpty: msgId = msg.c_messageEmpty().vid.v; break;
@ -1327,18 +1321,23 @@ HistoryItem *History::createItem(HistoryBlock *block, const MTPMessage &msg, boo
}
if (!msgId) return 0;
HistoryItem *existing = App::histItemById(channelId(), msgId);
if (existing) {
bool regged = false;
if (existing->detached() && block) {
existing->attach(block);
regged = true;
HistoryItem *result = App::histItemById(channelId(), msgId);
if (result) {
if (block) {
if (result->detached()) {
result->attach(block);
} else if (result->block() != block) {
LOG(("App Error: createItem() called for existing item in other block!"));
result->destroy();
result = 0;
}
}
if (msg.type() == mtpc_message) {
existing->updateMedia(msg.c_message().has_media() ? (&msg.c_message().vmedia) : 0, (block ? false : true));
if (result) {
if (msg.type() == mtpc_message) {
result->updateMedia(msg.c_message().has_media() ? (&msg.c_message().vmedia) : 0, (block ? false : true));
}
return result;
}
return (returnExisting || regged) ? existing : 0;
}
switch (msg.type()) {
@ -1545,15 +1544,11 @@ HistoryItem *History::createItem(HistoryBlock *block, const MTPMessage &msg, boo
} break;
}
return regItem(result, returnExisting);
return regItem(result);
}
HistoryItem *History::createItemForwarded(HistoryBlock *block, MsgId id, QDateTime date, int32 from, HistoryMessage *msg) {
HistoryItem *result = 0;
result = new HistoryForwarded(this, block, id, date, from, msg);
return regItem(result);
return regItem(new HistoryForwarded(this, block, id, date, from, msg));
}
HistoryItem *History::createItemDocument(HistoryBlock *block, MsgId id, int32 flags, MsgId replyTo, QDateTime date, int32 from, DocumentData *doc) {
@ -1577,7 +1572,8 @@ HistoryItem *History::addNewService(MsgId msgId, QDateTime date, const QString &
to = blocks.back();
}
return addNewItem(to, newBlock, regItem(new HistoryServiceMsg(this, to, msgId, date, text, flags, media)), newMsg);
HistoryItem *result = new HistoryServiceMsg(this, to, msgId, date, text, flags, media);
return addNewItem(to, newBlock, regItem(result), newMsg);
}
HistoryItem *History::addNewMessage(const MTPMessage &msg, NewMessageType type) {
@ -1606,7 +1602,7 @@ HistoryItem *History::addNewMessage(const MTPMessage &msg, NewMessageType type)
}
HistoryItem *History::addToHistory(const MTPMessage &msg) {
return createItem(0, msg, false, true);
return createItem(0, msg, false);
}
HistoryItem *History::addNewForwarded(MsgId id, QDateTime date, int32 from, HistoryMessage *item) {
@ -2344,15 +2340,12 @@ void History::addUnreadBar() {
}
HistoryBlock *block = showFrom->block();
unreadBar = new HistoryUnreadBar(this, block, count, showFrom->date);
if (!addNewInTheMiddle(unreadBar, blocks.indexOf(block), block->items.indexOf(showFrom))) {
if (!addNewInTheMiddle(regItem(unreadBar), blocks.indexOf(block), block->items.indexOf(showFrom))) {
unreadBar = 0;
}
}
HistoryItem *History::addNewInTheMiddle(HistoryItem *newItem, int32 blockIndex, int32 itemIndex) {
if (!regItem(newItem)) {
return 0;
}
if (blockIndex < 0 || itemIndex < 0 || blockIndex >= blocks.size() || itemIndex > blocks.at(blockIndex)->items.size()) {
delete newItem;
return 0;
@ -3014,16 +3007,11 @@ HistoryItem::~HistoryItem() {
}
}
HistoryItem *regItem(HistoryItem *item, bool returnExisting) {
if (!item) return 0;
HistoryItem *existing = App::historyRegItem(item);
if (existing) {
delete item;
return returnExisting ? existing : 0;
HistoryItem *regItem(HistoryItem *item) {
if (item) {
App::historyRegItem(item);
item->initDimensions();
}
item->initDimensions();
return item;
}

View file

@ -194,7 +194,7 @@ public:
clear();
}
HistoryItem *createItem(HistoryBlock *block, const MTPMessage &msg, bool applyServiceAction, bool returnExisting = false);
HistoryItem *createItem(HistoryBlock *block, const MTPMessage &msg, bool applyServiceAction);
HistoryItem *createItemForwarded(HistoryBlock *block, MsgId id, QDateTime date, int32 from, HistoryMessage *msg);
HistoryItem *createItemDocument(HistoryBlock *block, MsgId id, int32 flags, MsgId replyTo, QDateTime date, int32 from, DocumentData *doc);
@ -268,21 +268,6 @@ public:
if (!notifies.isEmpty() && notifies.back() == item) notifies.pop_back();
}
void itemReplaced(HistoryItem *old, HistoryItem *item) {
if (!notifies.isEmpty()) {
for (NotifyQueue::iterator i = notifies.begin(), e = notifies.end(); i != e; ++i) {
if ((*i) == old) {
*i = item;
break;
}
}
}
if (lastMsg == old) {
lastMsg = item;
}
// showFrom can't be detached
}
void paintDialog(Painter &p, int32 w, bool sel) const;
void eraseFromOverview(MediaOverviewType type, MsgId msgId);
bool updateTyping(uint64 ms = 0, uint32 dots = 0, bool force = false);
@ -1101,7 +1086,7 @@ private:
HistoryItem *_item;
};
HistoryItem *regItem(HistoryItem *item, bool returnExisting = false);
HistoryItem *regItem(HistoryItem *item);
class RadialAnimation {
public:

View file

@ -694,20 +694,6 @@ void HistoryInner::itemRemoved(HistoryItem *item) {
updateDragSelection(_dragSelFrom, _dragSelTo, _dragSelecting, true);
}
void HistoryInner::itemReplaced(HistoryItem *oldItem, HistoryItem *newItem) {
if (_dragItem == oldItem) _dragItem = newItem;
SelectedItems::iterator i = _selected.find(oldItem);
if (i != _selected.cend()) {
uint32 v = i.value();
_selected.erase(i);
_selected.insert(newItem, v);
}
if (_dragSelFrom == oldItem) _dragSelFrom = newItem;
if (_dragSelTo == oldItem) _dragSelTo = newItem;
}
void HistoryInner::dragActionFinish(const QPoint &screenPos, Qt::MouseButton button) {
TextLinkPtr needClick;
@ -5679,13 +5665,6 @@ void HistoryWidget::itemRemoved(HistoryItem *item) {
}
}
void HistoryWidget::itemReplaced(HistoryItem *oldItem, HistoryItem *newItem) {
if (_list) _list->itemReplaced(oldItem, newItem);
if (_replyTo == oldItem) _replyTo = newItem;
if (_kbReplyTo == oldItem) _kbReplyTo = newItem;
if (_replyReturn == oldItem) _replyReturn = newItem;
}
void HistoryWidget::updateScrollColors() {
if (!App::historyScrollBarColor()) return;
_scroll.updateColors(App::historyScrollBarColor(), App::historyScrollBgColor(), App::historyScrollBarOverColor(), App::historyScrollBgOverColor());

View file

@ -80,7 +80,6 @@ public:
void selectItem(HistoryItem *item);
void itemRemoved(HistoryItem *item);
void itemReplaced(HistoryItem *oldItem, HistoryItem *newItem);
void updateBotInfo(bool recount = true);
@ -491,7 +490,6 @@ public:
void fillSelectedItems(SelectedItemSet &sel, bool forDelete = true);
void itemRemoved(HistoryItem *item);
void itemReplaced(HistoryItem *oldItem, HistoryItem *newItem);
void updateScrollColors();

View file

@ -1484,25 +1484,6 @@ void MainWidget::itemRemoved(HistoryItem *item) {
}
}
void MainWidget::itemReplaced(HistoryItem *oldItem, HistoryItem *newItem) {
api()->itemReplaced(oldItem, newItem);
dialogs.itemReplaced(oldItem, newItem);
if (history.peer() == newItem->history()->peer || (history.peer() && history.peer() == newItem->history()->peer->migrateTo())) {
history.itemReplaced(oldItem, newItem);
}
if (!_toForward.isEmpty()) {
SelectedItemSet::iterator i = _toForward.find(oldItem->id);
if (i != _toForward.cend() && i.value() == oldItem) {
i.value() = newItem;
} else {
i = _toForward.find(oldItem->id - ServerMaxMsgId);
if (i != _toForward.cend() && i.value() == oldItem) {
i.value() = newItem;
}
}
}
}
bool MainWidget::overviewFailed(PeerData *peer, const RPCError &error, mtpRequestId req) {
if (mtpIsFlood(error)) return false;
@ -4228,15 +4209,7 @@ void MainWidget::feedUpdate(const MTPUpdate &update) {
if (msg.msg) {
HistoryItem *msgRow = App::histItemById(msg);
if (msgRow) {
App::historyUnregItem(msgRow);
if (App::wnd()) App::wnd()->changingMsgId(msgRow, d.vid.v);
msgRow->setId(d.vid.v);
if (msgRow->history()->peer->isSelf()) {
msgRow->history()->unregTyping(App::self());
}
if (!App::historyRegItem(msgRow)) {
Ui::redrawHistoryItem(msgRow);
} else {
if (App::histItemById(msg.channel, d.vid.v)) {
History *h = msgRow->history();
bool wasLast = (h->lastMsg == msgRow);
msgRow->destroy();
@ -4244,6 +4217,15 @@ void MainWidget::feedUpdate(const MTPUpdate &update) {
checkPeerHistory(h->peer);
}
history.peerMessagesUpdated();
} else {
App::historyUnregItem(msgRow);
if (App::wnd()) App::wnd()->changingMsgId(msgRow, d.vid.v);
msgRow->setId(d.vid.v);
if (msgRow->history()->peer->isSelf()) {
msgRow->history()->unregTyping(App::self());
}
App::historyRegItem(msgRow);
Ui::redrawHistoryItem(msgRow);
}
}
App::historyUnregRandom(d.vrandom_id.v);

View file

@ -335,7 +335,6 @@ public:
void mediaOverviewUpdated(PeerData *peer, MediaOverviewType type);
void changingMsgId(HistoryItem *row, MsgId newId);
void itemRemoved(HistoryItem *item);
void itemReplaced(HistoryItem *oldItem, HistoryItem *newItem);
void loadMediaBack(PeerData *peer, MediaOverviewType type, bool many = false);
void peerUsernameChanged(PeerData *peer);