void MainAppNoUI::onGiftUpdate(std::vector<gcRefPtr<UserCore::Misc::NewsItem>>& itemList) { std::vector<gcRefPtr<UserCore::Misc::NewsItem>> oldList; std::vector<gcRefPtr<UserCore::Misc::NewsItem>> output; { std::lock_guard<std::mutex> guard(m_NewsLock); oldList = m_vGiftItems; m_vGiftItems.clear(); for (auto i : itemList) { if (!i) continue; m_vGiftItems.push_back(i); } auto it = std::set_intersection(begin(m_vGiftItems), end(m_vGiftItems), begin(oldList), end(oldList), std::back_inserter(output), [](gcRefPtr<UserCore::Misc::NewsItem> a, gcRefPtr<UserCore::Misc::NewsItem> b){ return a->id < b->id; }); for (auto i : output) i->hasBeenShown = true; } if (m_vGiftItems.size() != output.size()) { gcTrace(""); onNotifyGiftUpdateEvent(); } }
void MainApp::onGiftUpdate(std::vector<UserCore::Misc::NewsItem*>& itemList) { std::vector<UserCore::Misc::NewsItem*> oldList; m_NewsLock.lock(); oldList = m_vGiftItems; m_vGiftItems.clear(); for (size_t x=0; x<itemList.size(); x++) { if (!itemList[x]) continue; m_vGiftItems.push_back(new UserCore::Misc::NewsItem(itemList[x])); } size_t count =0; for (size_t x=0; x<itemList.size(); x++) { for (size_t y=0; y<oldList.size(); y++) { if (oldList[y]->id == itemList[x]->id) { count++; oldList[y]->hasBeenShown = true; break; } } } m_NewsLock.unlock(); safe_delete(oldList); if (m_vGiftItems.size() != count) onNotifyGiftUpdateEvent(); }