diff options
Diffstat (limited to 'indra/newview/llfloaterfriends.cpp')
| -rw-r--r-- | indra/newview/llfloaterfriends.cpp | 106 |
1 files changed, 71 insertions, 35 deletions
diff --git a/indra/newview/llfloaterfriends.cpp b/indra/newview/llfloaterfriends.cpp index 55d9aeead9..46727c3698 100644 --- a/indra/newview/llfloaterfriends.cpp +++ b/indra/newview/llfloaterfriends.cpp @@ -44,7 +44,6 @@ #include "llfloateravatarpicker.h" #include "llviewerwindow.h" #include "llbutton.h" -#include "llcallingcard.h" #include "llfloateravatarinfo.h" #include "llinventorymodel.h" #include "llnamelistctrl.h" @@ -143,7 +142,7 @@ void LLPanelFriends::updateFriends(U32 changed_mask) LLDynamicArray<LLUUID> selected_friends = getSelectedIDs(); if(changed_mask & (LLFriendObserver::ADD | LLFriendObserver::REMOVE | LLFriendObserver::ONLINE)) { - refreshNames(); + refreshNames(changed_mask); } else if(changed_mask & LLFriendObserver::POWERS) { @@ -185,7 +184,8 @@ BOOL LLPanelFriends::postBuild() childSetCommitCallback("friend_list", onSelectName, this); childSetDoubleClickCallback("friend_list", onClickIM); - refreshNames(); + U32 changed_mask = LLFriendObserver::ADD | LLFriendObserver::REMOVE | LLFriendObserver::ONLINE; + refreshNames(changed_mask); childSetAction("im_btn", onClickIM, this); childSetAction("profile_btn", onClickProfile, this); @@ -206,7 +206,6 @@ BOOL LLPanelFriends::postBuild() return TRUE; } - BOOL LLPanelFriends::addFriend(const LLUUID& agent_id) { LLAvatarTracker& at = LLAvatarTracker::instance(); @@ -264,7 +263,8 @@ BOOL LLPanelFriends::addFriend(const LLUUID& agent_id) return have_name; } -// propagate actual relationship to UI +// propagate actual relationship to UI. +// Does not resort the UI list because it can be called frequently. JC BOOL LLPanelFriends::updateFriendItem(const LLUUID& agent_id, const LLRelationship* info) { if (!info) return FALSE; @@ -287,9 +287,7 @@ BOOL LLPanelFriends::updateFriendItem(const LLUUID& agent_id, const LLRelationsh // enable this item, in case it was disabled after user input itemp->setEnabled(TRUE); - // changed item in place, need to request sort - mFriendsList->sortItems(); - + // Do not resort, this function can be called frequently. return have_name; } @@ -359,7 +357,7 @@ struct SortFriendsByID } }; -void LLPanelFriends::refreshNames() +void LLPanelFriends::refreshNames(U32 changed_mask) { LLDynamicArray<LLUUID> selected_ids = getSelectedIDs(); S32 pos = mFriendsList->getScrollPos(); @@ -367,27 +365,67 @@ void LLPanelFriends::refreshNames() // get all buddies we know about LLAvatarTracker::buddy_map_t all_buddies; LLAvatarTracker::instance().copyBuddyList(all_buddies); - - // get all friends in list and sort by UUID + + BOOL have_names = TRUE; + + if(changed_mask & (LLFriendObserver::ADD | LLFriendObserver::REMOVE)) + { + have_names &= refreshNamesSync(all_buddies); + } + + if(changed_mask & LLFriendObserver::ONLINE) + { + have_names &= refreshNamesPresence(all_buddies); + } + + if (!have_names) + { + mEventTimer.start(); + } + // Changed item in place, need to request sort and update columns + // because we might have changed data in a column on which the user + // has already sorted. JC + mFriendsList->sortItems(); + + // re-select items + mFriendsList->selectMultiple(selected_ids); + mFriendsList->setScrollPos(pos); +} + +BOOL LLPanelFriends::refreshNamesSync(const LLAvatarTracker::buddy_map_t & all_buddies) +{ + mFriendsList->deleteAllItems(); + + BOOL have_names = TRUE; + LLAvatarTracker::buddy_map_t::const_iterator buddy_it = all_buddies.begin(); + + for(; buddy_it != all_buddies.end(); ++buddy_it) + { + have_names &= addFriend(buddy_it->first); + } + + return have_names; +} + +BOOL LLPanelFriends::refreshNamesPresence(const LLAvatarTracker::buddy_map_t & all_buddies) +{ std::vector<LLScrollListItem*> items = mFriendsList->getAllData(); std::sort(items.begin(), items.end(), SortFriendsByID()); - std::vector<LLScrollListItem*>::iterator item_it = items.begin(); - std::vector<LLScrollListItem*>::iterator item_end = items.end(); - + LLAvatarTracker::buddy_map_t::const_iterator buddy_it = all_buddies.begin(); + std::vector<LLScrollListItem*>::const_iterator item_it = items.begin(); BOOL have_names = TRUE; - LLAvatarTracker::buddy_map_t::iterator buddy_it; - for (buddy_it = all_buddies.begin() ; buddy_it != all_buddies.end(); ++buddy_it) + + while(true) { - // erase any items that reflect residents who are no longer buddies - while(item_it != item_end && buddy_it->first > (*item_it)->getValue().asUUID()) + if(item_it == items.end() || buddy_it == all_buddies.end()) { - mFriendsList->deleteItems((*item_it)->getValue()); - ++item_it; + break; } - // update existing friends with new info - if (item_it != item_end && buddy_it->first == (*item_it)->getValue().asUUID()) + const LLUUID & buddy_uuid = buddy_it->first; + const LLUUID & item_uuid = (*item_it)->getValue().asUUID(); + if(item_uuid == buddy_uuid) { const LLRelationship* info = buddy_it->second; if (!info) @@ -402,27 +440,23 @@ void LLPanelFriends::refreshNames() // update existing item in UI have_names &= updateFriendItem(buddy_it->first, info); } + + ++buddy_it; ++item_it; } - // add new friend to list - else + else if(item_uuid < buddy_uuid) { - have_names &= addFriend(buddy_it->first); + ++item_it; + } + else //if(item_uuid > buddy_uuid) + { + ++buddy_it; } } - if (!have_names) - { - mEventTimer.start(); - } - // changed item in place, need to request sort and update columns - mFriendsList->sortItems(); - // re-select items - mFriendsList->selectMultiple(selected_ids); - mFriendsList->setScrollPos(pos); + return have_names; } - void LLPanelFriends::refreshUI() { BOOL single_selected = FALSE; @@ -732,6 +766,8 @@ void LLPanelFriends::modifyRightsConfirmation(S32 option, void* user_data) { const LLRelationship* info = LLAvatarTracker::instance().getBuddyInfo(rights_it->first); panelp->updateFriendItem(rights_it->first, info); + // Might have changed the column the user is sorted on. + panelp->mFriendsList->sortItems(); } } panelp->refreshUI(); |
