PageRenderTime 334ms CodeModel.GetById 161ms app.highlight 12ms RepoModel.GetById 159ms app.codeStats 0ms

/indra/newview/llrecentpeople.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 128 lines | 73 code | 24 blank | 31 comment | 18 complexity | 7346a82aa5eef933fc8769e7e2ea55ed MD5 | raw file
  1/** 
  2 * @file llrecentpeople.cpp
  3 * @brief List of people with which the user has recently interacted.
  4 *
  5 * $LicenseInfo:firstyear=2009&license=viewerlgpl$
  6 * Second Life Viewer Source Code
  7 * Copyright (C) 2010, Linden Research, Inc.
  8 * 
  9 * This library is free software; you can redistribute it and/or
 10 * modify it under the terms of the GNU Lesser General Public
 11 * License as published by the Free Software Foundation;
 12 * version 2.1 of the License only.
 13 * 
 14 * This library is distributed in the hope that it will be useful,
 15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 17 * Lesser General Public License for more details.
 18 * 
 19 * You should have received a copy of the GNU Lesser General Public
 20 * License along with this library; if not, write to the Free Software
 21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 22 * 
 23 * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
 24 * $/LicenseInfo$
 25 */
 26
 27#include "llviewerprecompiledheaders.h"
 28
 29#include "llrecentpeople.h"
 30#include "llgroupmgr.h"
 31
 32#include "llagent.h"
 33
 34using namespace LLOldEvents;
 35
 36bool LLRecentPeople::add(const LLUUID& id, const LLSD& userdata)
 37{
 38	if (id == gAgent.getID())
 39		return false;
 40
 41	bool is_not_group_id = LLGroupMgr::getInstance()->getGroupData(id) == NULL;
 42
 43	if (is_not_group_id)
 44	{
 45		// For each avaline call the id of caller is different even if
 46		// the phone number is the same.
 47		// To avoid duplication of avaline list items in the recent list
 48		// of panel People, deleting id's with similar phone number.
 49		const LLUUID& caller_id = getIDByPhoneNumber(userdata);
 50		if (caller_id.notNull())
 51			mPeople.erase(caller_id);
 52
 53		//[] instead of insert to replace existing id->llsd["date"] with new date value
 54		mPeople[id] = userdata;
 55		mChangedSignal();
 56	}
 57
 58	return is_not_group_id;
 59}
 60
 61bool LLRecentPeople::contains(const LLUUID& id) const
 62{
 63	return mPeople.find(id) != mPeople.end();
 64}
 65
 66void LLRecentPeople::get(uuid_vec_t& result) const
 67{
 68	result.clear();
 69	for (recent_people_t::const_iterator pos = mPeople.begin(); pos != mPeople.end(); ++pos)
 70		result.push_back((*pos).first);
 71}
 72
 73const LLDate LLRecentPeople::getDate(const LLUUID& id) const
 74{
 75	recent_people_t::const_iterator it = mPeople.find(id);
 76	if (it!= mPeople.end()) return it->second["date"].asDate();
 77
 78	static LLDate no_date = LLDate();
 79	return no_date;
 80}
 81
 82const LLSD& LLRecentPeople::getData(const LLUUID& id) const
 83{
 84	recent_people_t::const_iterator it = mPeople.find(id);
 85
 86	if (it != mPeople.end())
 87		return it->second;
 88
 89	static LLSD no_data = LLSD();
 90	return no_data;
 91}
 92
 93bool LLRecentPeople::isAvalineCaller(const LLUUID& id) const
 94{
 95	recent_people_t::const_iterator it = mPeople.find(id);
 96
 97	if (it != mPeople.end())
 98	{
 99		const LLSD& user = it->second;		
100		return user["avaline_call"].asBoolean();
101	}
102
103	return false;
104}
105
106const LLUUID& LLRecentPeople::getIDByPhoneNumber(const LLSD& userdata)
107{
108	if (!userdata["avaline_call"].asBoolean())
109		return LLUUID::null;
110
111	for (recent_people_t::const_iterator it = mPeople.begin(); it != mPeople.end(); ++it)
112	{
113		const LLSD& user_info = it->second;
114		
115		if (user_info["call_number"].asString() == userdata["call_number"].asString())
116			return it->first;
117	}
118	
119	return LLUUID::null;
120}
121
122// virtual
123bool LLRecentPeople::handleEvent(LLPointer<LLEvent> event, const LLSD& userdata)
124{
125	(void) userdata;
126	add(event->getValue().asUUID());
127	return true;
128}