CHUI-275 FIXED (Chat history viewer does not show entire user.txt IM log file)

- Renamed LLLogChat::loadAllHistory to LLLogChat::loadChatHistory because it doesn't actually loads all history. Also added parameter to the function which is a flag whether to load all file's content or not.
- Implemented displaying history by pages (as was decided on meeting page): Added showHistory() method to the LLFloaterConversationPreview which shows the chat history page by page starting from the last conversation (or may say starting from the last page). One page contains 100 entries. Added "More history..." button to display next page of history.
master
Paul ProductEngine 2012-08-28 14:48:32 +03:00
parent a1a1410d25
commit d4ee17e533
8 changed files with 88 additions and 46 deletions

View File

@ -1639,6 +1639,17 @@
<key>Value</key>
<string />
</map>
<key>ConversationHistoryPageSize</key>
<map>
<key>Comment</key>
<string>Chat history of conversation opened from call log is displayed by pages. So this is number of entries per page.</string>
<key>Persist</key>
<integer>1</integer>
<key>Type</key>
<string>S32</string>
<key>Value</key>
<integer>100</integer>
</map>
<key>NearbyChatIsNotTornOff</key>
<map>
<key>Comment</key>

View File

@ -33,12 +33,15 @@
LLFloaterConversationPreview::LLFloaterConversationPreview(const LLSD& session_id)
: LLFloater(session_id),
mChatHistory(NULL),
mSessionID(session_id.asUUID())
mSessionID(session_id.asUUID()),
mCurrentPage(0),
mPageSize(gSavedSettings.getS32("ConversationHistoryPageSize"))
{}
BOOL LLFloaterConversationPreview::postBuild()
{
mChatHistory = getChild<LLChatHistory>("chat_history");
getChild<LLUICtrl>("more_history")->setCommitCallback(boost::bind(&LLFloaterConversationPreview::onMoreHistoryBtnClick, this));
const LLConversation* conv = LLConversationLog::instance().getConversation(mSessionID);
if (conv)
@ -52,6 +55,11 @@ BOOL LLFloaterConversationPreview::postBuild()
getChild<LLLineEditor>("description")->setValue(name);
}
std::string file = conv->getHistoryFileName();
LLLogChat::loadChatHistory(file, mMessages, true);
mCurrentPage = mMessages.size() / mPageSize;
return LLFloater::postBuild();
}
@ -62,51 +70,59 @@ void LLFloaterConversationPreview::draw()
void LLFloaterConversationPreview::onOpen(const LLSD& session_id)
{
const LLConversation* conv = LLConversationLog::instance().getConversation(session_id);
if (!conv)
showHistory();
}
void LLFloaterConversationPreview::showHistory()
{
if (!mMessages.size())
{
return;
}
std::list<LLSD> messages;
std::string file = conv->getHistoryFileName();
LLLogChat::loadAllHistory(file, messages);
if (messages.size())
mChatHistory->clear();
std::ostringstream message;
std::list<LLSD>::const_iterator iter = mMessages.begin();
int delta = 0;
if (mCurrentPage)
{
std::ostringstream message;
std::list<LLSD>::const_iterator iter = messages.begin();
for (; iter != messages.end(); ++iter)
{
LLSD msg = *iter;
std::string time = msg["time"].asString();
LLUUID from_id = msg["from_id"].asUUID();
std::string from = msg["from"].asString();
std::string message = msg["message"].asString();
bool is_history = msg["is_history"].asBoolean();
LLChat chat;
chat.mFromID = from_id;
chat.mSessionID = session_id;
chat.mFromName = from;
chat.mTimeStr = time;
chat.mChatStyle = is_history ? CHAT_STYLE_HISTORY : chat.mChatStyle;
chat.mText = message;
appendMessage(chat);
}
double num_of_pages = (double)mMessages.size() / mPageSize;
delta = (ceil(num_of_pages) - num_of_pages) * mPageSize;
}
}
void LLFloaterConversationPreview::appendMessage(const LLChat& chat)
{
if (!chat.mMuted)
std::advance(iter, (mCurrentPage * mPageSize) - delta);
for (int msg_num = 0; (iter != mMessages.end() && msg_num < mPageSize); ++iter, ++msg_num)
{
LLSD args;
args["use_plain_text_chat_history"] = true;
args["show_time"] = true;
args["show_names_for_p2p_conv"] = true;
LLSD msg = *iter;
std::string time = msg["time"].asString();
LLUUID from_id = msg["from_id"].asUUID();
std::string from = msg["from"].asString();
std::string message = msg["message"].asString();
bool is_history = msg["is_history"].asBoolean();
LLChat chat;
chat.mFromID = from_id;
chat.mSessionID = mSessionID;
chat.mFromName = from;
chat.mTimeStr = time;
chat.mChatStyle = is_history ? CHAT_STYLE_HISTORY : chat.mChatStyle;
chat.mText = message;
mChatHistory->appendMessage(chat);
}
}
void LLFloaterConversationPreview::onMoreHistoryBtnClick()
{
if (--mCurrentPage < 0)
{
return;
}
showHistory();
}

View File

@ -42,10 +42,15 @@ public:
virtual void onOpen(const LLSD& session_id);
private:
void appendMessage(const LLChat& chat);
void onMoreHistoryBtnClick();
void showHistory();
LLChatHistory* mChatHistory;
LLUUID mSessionID;
int mCurrentPage;
int mPageSize;
std::list<LLSD> mMessages;
};
#endif /* LLFLOATERCONVERSATIONPREVIEW_H_ */

View File

@ -263,7 +263,7 @@ LLIMModel::LLIMSession::LLIMSession(const LLUUID& session_id, const std::string&
std::list<LLSD> chat_history;
//involves parsing of a chat history
LLLogChat::loadAllHistory(mHistoryFileName, chat_history);
LLLogChat::loadChatHistory(mHistoryFileName, chat_history);
addMessagesFromHistory(chat_history);
}

View File

@ -387,7 +387,7 @@ void append_to_last_message(std::list<LLSD>& messages, const std::string& line)
}
// static
void LLLogChat::loadAllHistory(const std::string& file_name, std::list<LLSD>& messages)
void LLLogChat::loadChatHistory(const std::string& file_name, std::list<LLSD>& messages, bool load_all_history/*= false*/)
{
if (file_name.empty())
{
@ -412,8 +412,8 @@ void LLLogChat::loadAllHistory(const std::string& file_name, std::list<LLSD>& me
S32 len;
bool firstline = TRUE;
if (fseek(fptr, (LOG_RECALL_SIZE - 1) * -1 , SEEK_END))
{ //File is smaller than recall size. Get it all.
if (load_all_history || fseek(fptr, (LOG_RECALL_SIZE - 1) * -1 , SEEK_END))
{ //We need to load the whole historyFile or it's smaller than recall size, so get it all.
firstline = FALSE;
if (fseek(fptr, 0, SEEK_SET))
{

View File

@ -50,12 +50,12 @@ public:
const LLUUID& from_id,
const std::string& line);
/** @deprecated @see loadAllHistory() */
/** @deprecated @see loadChatHistory() */
static void loadHistory(const std::string& filename,
void (*callback)(ELogLineType, const LLSD&, void*),
void* userdata);
static void loadAllHistory(const std::string& file_name, std::list<LLSD>& messages);
static void loadChatHistory(const std::string& file_name, std::list<LLSD>& messages, bool load_all_history = false);
private:
static std::string cleanFileName(std::string filename);
};

View File

@ -262,7 +262,7 @@ void LLNearbyChat::loadHistory()
do_not_log["do_not_log"] = true;
std::list<LLSD> history;
LLLogChat::loadAllHistory("chat", history);
LLLogChat::loadChatHistory("chat", history);
std::list<LLSD>::const_iterator it = history.begin();
while (it != history.end())

View File

@ -3,7 +3,7 @@
legacy_header_height="18"
can_resize="true"
default_tab_group="1"
height="361"
height="391"
layout="topleft"
min_height="243"
min_width="234"
@ -50,4 +50,14 @@
left="5"
width="390">
</chat_history>
<button
follows="bottom|right"
height="22"
layout="topleft"
name="more_history"
label="More history..."
right="-15"
top_pad="5"
width="100">
</button>
</floater>