CHUI-340 : WIP : Fix sorting bugs on time for sessions, simplified the update time mechanism and clean up

master
Merov Linden 2012-09-21 18:12:06 -07:00
parent fc6bbee3f4
commit b5583906d0
9 changed files with 75 additions and 29 deletions

View File

@ -226,7 +226,7 @@ public:
mParent(NULL),
mRootViewModel(root_view_model)
{
std::for_each(mChildren.begin(), mChildren.end(), DeletePointer());
mChildren.clear();
}
void requestSort() { mSortVersion = -1; }

View File

@ -38,7 +38,8 @@ LLConversationItem::LLConversationItem(std::string display_name, const LLUUID& u
mName(display_name),
mUUID(uuid),
mNeedsRefresh(true),
mConvType(CONV_UNKNOWN)
mConvType(CONV_UNKNOWN),
mLastActiveTime(0.0)
{
}
@ -47,7 +48,8 @@ LLConversationItem::LLConversationItem(const LLUUID& uuid, LLFolderViewModelInte
mName(""),
mUUID(uuid),
mNeedsRefresh(true),
mConvType(CONV_UNKNOWN)
mConvType(CONV_UNKNOWN),
mLastActiveTime(0.0)
{
}
@ -56,7 +58,8 @@ LLConversationItem::LLConversationItem(LLFolderViewModelInterface& root_view_mod
mName(""),
mUUID(),
mNeedsRefresh(true),
mConvType(CONV_UNKNOWN)
mConvType(CONV_UNKNOWN),
mLastActiveTime(0.0)
{
}
@ -167,8 +170,10 @@ void LLConversationItemSession::setParticipantIsModerator(const LLUUID& particip
}
}
void LLConversationItemSession::setParticipantTimeNow(const LLUUID& participant_id)
void LLConversationItemSession::setTimeNow(const LLUUID& participant_id)
{
mLastActiveTime = LLFrameTimer::getElapsedSeconds();
mNeedsRefresh = true;
LLConversationItemParticipant* participant = findParticipant(participant_id);
if (participant)
{
@ -176,11 +181,11 @@ void LLConversationItemSession::setParticipantTimeNow(const LLUUID& participant_
}
}
// The time of activity of a session is the time of the most recent participation
// The time of activity of a session is the time of the most recent activity, session and participants included
const bool LLConversationItemSession::getTime(F64& time) const
{
bool has_time = false;
F64 most_recent_time = 0.0;
F64 most_recent_time = mLastActiveTime;
bool has_time = (most_recent_time > 0.1);
LLConversationItemParticipant* participant = NULL;
child_list_t::const_iterator iter;
for (iter = mChildren.begin(); iter != mChildren.end(); iter++)
@ -197,7 +202,6 @@ const bool LLConversationItemSession::getTime(F64& time) const
{
time = most_recent_time;
}
llinfos << "Merov debug : get time session, uuid = " << mUUID << ", has_time = " << has_time << ", time = " << time << llendl;
return has_time;
}
@ -220,8 +224,7 @@ void LLConversationItemSession::dumpDebugData()
LLConversationItemParticipant::LLConversationItemParticipant(std::string display_name, const LLUUID& uuid, LLFolderViewModelInterface& root_view_model) :
LLConversationItem(display_name,uuid,root_view_model),
mIsMuted(false),
mIsModerator(false),
mLastActiveTime(0.0)
mIsModerator(false)
{
mConvType = CONV_PARTICIPANT;
}
@ -265,19 +268,34 @@ bool LLConversationSort::operator()(const LLConversationItem* const& a, const LL
{
F64 time_a = 0.0;
F64 time_b = 0.0;
if (a->getTime(time_a) && b->getTime(time_b))
bool has_time_a = a->getTime(time_a);
bool has_time_b = b->getTime(time_b);
if (has_time_a && has_time_b)
{
return (time_a > time_b);
}
else if (has_time_a || has_time_b)
{
// If we have only one time updated, we consider the element with time as the "highest".
// That boils down to "has_time_a" if you think about it.
return has_time_a;
}
// If not time available, we'll default to sort by name at the end of this method
}
else if (sort_order == LLConversationFilter::SO_DISTANCE)
{
F32 dist_a = 0.0;
F32 dist_b = 0.0;
if (a->getDistanceToAgent(dist_a) && b->getDistanceToAgent(dist_b))
bool has_dist_a = a->getDistanceToAgent(dist_a);
bool has_dist_b = b->getDistanceToAgent(dist_b);
if (has_dist_a && has_dist_b)
{
return (dist_a > dist_b);
}
else if (has_dist_a || has_dist_b)
{
return has_dist_a;
}
}
}
else if ((type_a > LLConversationItem::CONV_PARTICIPANT) && (type_b > LLConversationItem::CONV_PARTICIPANT))
@ -288,10 +306,19 @@ bool LLConversationSort::operator()(const LLConversationItem* const& a, const LL
{
F64 time_a = 0.0;
F64 time_b = 0.0;
if (a->getTime(time_a) && b->getTime(time_b))
bool has_time_a = a->getTime(time_a);
bool has_time_b = b->getTime(time_b);
if (has_time_a && has_time_b)
{
return (time_a > time_b);
}
else if (has_time_a || has_time_b)
{
// If we have only one time updated, we consider the element with time as the "highest".
// That boils down to "has_time_a" if you think about it.
return has_time_a;
}
// If not time available, we'll default to sort by name at the end of this method
}
else if (sort_order == LLConversationFilter::SO_SESSION_TYPE)
{

View File

@ -106,7 +106,7 @@ public:
// Methods used in sorting (see LLConversationSort::operator())
EConversationType const getType() const { return mConvType; }
virtual const bool getTime(F64& time) const { return false; }
virtual const bool getTime(F64& time) const { time = mLastActiveTime; return (time > 0.1); }
virtual const bool getDistanceToAgent(F32& distance) const { return false; }
// This method will be called to determine if a drop can be
@ -129,6 +129,7 @@ protected:
LLUUID mUUID; // UUID of the session or the participant
EConversationType mConvType; // Type of conversation item
bool mNeedsRefresh; // Flag signaling to the view that something changed for this item
F64 mLastActiveTime;
};
class LLConversationItemSession : public LLConversationItem
@ -149,7 +150,7 @@ public:
void setParticipantIsMuted(const LLUUID& participant_id, bool is_muted);
void setParticipantIsModerator(const LLUUID& participant_id, bool is_moderator);
void setParticipantTimeNow(const LLUUID& participant_id);
void setTimeNow(const LLUUID& participant_id);
bool isLoaded() { return mIsLoaded; }
@ -172,18 +173,15 @@ public:
bool isModerator() {return mIsModerator; }
void setIsMuted(bool is_muted) { mIsMuted = is_muted; mNeedsRefresh = true; }
void setIsModerator(bool is_moderator) { mIsModerator = is_moderator; mNeedsRefresh = true; }
void setTimeNow() { mLastActiveTime = LLFrameTimer::getElapsedSeconds(); }
void setTimeNow() { mLastActiveTime = LLFrameTimer::getElapsedSeconds(); mNeedsRefresh = true; }
void onAvatarNameCache(const LLAvatarName& av_name);
virtual const bool getTime(F64& time) const { time = mLastActiveTime; return (time > 0.1 ? true : false); }
void dumpDebugData();
private:
bool mIsMuted; // default is false
bool mIsModerator; // default is false
F64 mLastActiveTime;
};
// We don't want to ever filter conversations but we need to declare that class to create a conversation view model.

View File

@ -250,6 +250,14 @@ std::string LLIMConversation::appendTime()
void LLIMConversation::appendMessage(const LLChat& chat, const LLSD &args)
{
// Update the participant activity time
LLIMFloaterContainer* im_box = LLIMFloaterContainer::findInstance();
if (im_box)
{
im_box->setTimeNow(mSessionID,chat.mFromID);
}
LLChat& tmp_chat = const_cast<LLChat&>(chat);
if(tmp_chat.mTimeStr.empty())

View File

@ -907,10 +907,6 @@ void LLIMFloater::updateMessages()
chat.mText = message;
}
// Update the participant activity time
mParticipantList->setParticipantTimeNow(from_id);
llinfos << "Merov debug : LLIMFloater::updateMessages, session = " << mSessionID << ", from = " << msg["from"].asString() << ", uuid = " << msg["from_id"].asString() << ", date = " << LLFrameTimer::getElapsedSeconds() << llendl;
// Add the message to the chat log
appendMessage(chat);
mLastMessageIndex = msg["index"].asInteger();

View File

@ -710,6 +710,21 @@ void LLIMFloaterContainer::setConvItemSelect(LLUUID& session_id)
}
}
void LLIMFloaterContainer::setTimeNow(const LLUUID& session_id, const LLUUID& participant_id)
{
conversations_items_map::iterator item_it = mConversationsItems.find(session_id);
if (item_it != mConversationsItems.end())
{
LLConversationItemSession* item = dynamic_cast<LLConversationItemSession*>(item_it->second);
if (item)
{
item->setTimeNow(participant_id);
mConversationViewModel.requestSortAll();
mConversationsRoot->arrangeAll();
}
}
}
void LLIMFloaterContainer::addConversationListItem(const LLUUID& uuid)
{
bool is_nearby_chat = uuid.isNull();

View File

@ -124,6 +124,7 @@ private:
public:
void removeConversationListItem(const LLUUID& uuid, bool change_focus = true);
void addConversationListItem(const LLUUID& uuid);
void setTimeNow(const LLUUID& session_id, const LLUUID& participant_id);
private:
LLConversationViewSession* createConversationItemWidget(LLConversationItem* item);

View File

@ -233,10 +233,6 @@ void LLNearbyChat::loadHistory()
gCacheName->getUUID(legacy_name, from_id);
}
// Update the participant activity time
mParticipantList->setParticipantTimeNow(from_id);
llinfos << "Merov debug : LLNearbyChat::loadHistory, session = " << mSessionID << ", from = " << msg[IM_FROM].asString() << ", uuid = " << msg[IM_FROM_ID].asString() << ", date = " << LLFrameTimer::getElapsedSeconds() << llendl;
LLChat chat;
chat.mFromName = from;
chat.mFromID = from_id;

View File

@ -34,6 +34,7 @@
#include "llagent.h"
#include "llimview.h"
#include "llimfloatercontainer.h"
#include "llpanelpeoplemenus.h"
#include "llnotificationsutil.h"
#include "llparticipantlist.h"
@ -592,7 +593,11 @@ bool LLParticipantList::onSpeakerUpdateEvent(LLPointer<LLOldEvents::LLEvent> eve
if ( evt_data.has("id") )
{
LLUUID participant_id = evt_data["id"];
setParticipantTimeNow(participant_id);
LLIMFloaterContainer* im_box = LLIMFloaterContainer::findInstance();
if (im_box)
{
im_box->setTimeNow(mUUID,participant_id);
}
}
return true;
}