diff options
Diffstat (limited to 'indra')
-rw-r--r-- | indra/newview/llfloaterchat.cpp | 13 | ||||
-rw-r--r-- | indra/newview/llfloaterchat.h | 2 | ||||
-rw-r--r-- | indra/newview/llimfloater.cpp | 50 | ||||
-rw-r--r-- | indra/newview/llimfloater.h | 2 | ||||
-rw-r--r-- | indra/newview/llimpanel.cpp | 42 | ||||
-rw-r--r-- | indra/newview/llimpanel.h | 1 | ||||
-rw-r--r-- | indra/newview/llimview.cpp | 56 | ||||
-rw-r--r-- | indra/newview/llimview.h | 6 | ||||
-rw-r--r-- | indra/newview/lllogchat.cpp | 60 | ||||
-rw-r--r-- | indra/newview/lllogchat.h | 11 |
10 files changed, 99 insertions, 144 deletions
diff --git a/indra/newview/llfloaterchat.cpp b/indra/newview/llfloaterchat.cpp index 86abebe7ce..ed14079ae9 100644 --- a/indra/newview/llfloaterchat.cpp +++ b/indra/newview/llfloaterchat.cpp @@ -182,13 +182,7 @@ void add_timestamped_line(LLViewerTextEditor* edit, LLChat chat, const LLColor4& void log_chat_text(const LLChat& chat) { - std::string histstr; - if (gSavedPerAccountSettings.getBOOL("LogTimestamp")) - histstr = LLLogChat::timestamp(gSavedPerAccountSettings.getBOOL("LogTimestampDate")) + chat.mText; - else - histstr = chat.mText; - - LLLogChat::saveHistory(std::string("chat"),histstr); + LLLogChat::saveHistory(std::string("chat"), chat.mFromName, chat.mFromID, chat.mText); } // static void LLFloaterChat::addChatHistory(const LLChat& chat, bool log_to_file) @@ -476,7 +470,7 @@ void LLFloaterChat::loadHistory() } //static -void LLFloaterChat::chatFromLogFile(LLLogChat::ELogLineType type , std::string line, void* userdata) +void LLFloaterChat::chatFromLogFile(LLLogChat::ELogLineType type , const LLSD& line, void* userdata) { switch (type) { @@ -485,9 +479,10 @@ void LLFloaterChat::chatFromLogFile(LLLogChat::ELogLineType type , std::string l // *TODO: nice message from XML file here break; case LLLogChat::LOG_LINE: + case LLLogChat::LOG_LLSD: { LLChat chat; - chat.mText = line; + chat.mText = line["message"].asString(); get_text_color(chat); addChatHistory(chat, FALSE); } diff --git a/indra/newview/llfloaterchat.h b/indra/newview/llfloaterchat.h index 6ba3165d6a..aed82a6781 100644 --- a/indra/newview/llfloaterchat.h +++ b/indra/newview/llfloaterchat.h @@ -78,7 +78,7 @@ public: static void onClickMute(void *data); static void onClickToggleShowMute(LLUICtrl* caller, void *data); static void onClickToggleActiveSpeakers(void* userdata); - static void chatFromLogFile(LLLogChat::ELogLineType type,std::string line, void* userdata); + static void chatFromLogFile(LLLogChat::ELogLineType type, const LLSD& line, void* userdata); static void loadHistory(); static void* createSpeakersPanel(void* data); static void* createChatPanel(void* data); diff --git a/indra/newview/llimfloater.cpp b/indra/newview/llimfloater.cpp index b86795f696..f3fec70ac9 100644 --- a/indra/newview/llimfloater.cpp +++ b/indra/newview/llimfloater.cpp @@ -235,11 +235,6 @@ BOOL LLIMFloater::postBuild() setTitle(LLIMModel::instance().getName(mSessionID)); setDocked(true); - - if ( gSavedPerAccountSettings.getBOOL("LogShowHistory") ) - { - LLLogChat::loadHistory(getTitle(), &chatFromLogFile, (void *)this); - } mTypingStart = LLTrans::getString("IM_typing_start_string"); @@ -453,9 +448,6 @@ void LLIMFloater::updateMessages() { std::list<LLSD> messages; LLIMModel::instance().getMessages(mSessionID, messages, mLastMessageIndex+1); - std::string agent_name; - - gCacheName->getFullName(gAgentID, agent_name); if (messages.size()) { @@ -464,20 +456,17 @@ void LLIMFloater::updateMessages() std::ostringstream message; std::list<LLSD>::const_reverse_iterator iter = messages.rbegin(); std::list<LLSD>::const_reverse_iterator iter_end = messages.rend(); - for (; iter != iter_end; ++iter) + for (; iter != iter_end; ++iter) { LLSD msg = *iter; - std::string from = msg["from"].asString(); std::string time = msg["time"].asString(); LLUUID from_id = msg["from_id"].asUUID(); + std::string from = from_id != gAgentID ? msg["from"].asString() : LLTrans::getString("You"); std::string message = msg["message"].asString(); LLStyle::Params style_params; style_params.color(chat_color); - if (from == agent_name) - from = LLTrans::getString("You"); - LLChat chat(message); chat.mFromID = from_id; chat.mFromName = from; @@ -657,38 +646,3 @@ void LLIMFloater::removeTypingIndicator(const LLIMInfo* im_info) } } -void LLIMFloater::chatFromLogFile(LLLogChat::ELogLineType type, std::string line, void* userdata) -{ - if (!userdata) return; - - LLIMFloater* self = (LLIMFloater*) userdata; - std::string message = line; - S32 im_log_option = gSavedPerAccountSettings.getS32("IMLogOptions"); - switch (type) - { - case LLLogChat::LOG_EMPTY: - // add warning log enabled message - if (im_log_option!=LOG_CHAT) - { - message = LLTrans::getString("IM_logging_string"); - } - break; - case LLLogChat::LOG_END: - // add log end message - if (im_log_option!=LOG_CHAT) - { - message = LLTrans::getString("IM_logging_string"); - } - break; - case LLLogChat::LOG_LINE: - // just add normal lines from file - break; - default: - // nothing - break; - } - - self->mChatHistory->appendText(message, true, LLStyle::Params().color(LLUIColorTable::instance().getColor("ChatHistoryTextColor"))); - self->mChatHistory->blockUndo(); -} - diff --git a/indra/newview/llimfloater.h b/indra/newview/llimfloater.h index 3da27ac941..d2aac57ee2 100644 --- a/indra/newview/llimfloater.h +++ b/indra/newview/llimfloater.h @@ -106,8 +106,6 @@ private: // gets a rect that bounds possible positions for the LLIMFloater on a screen (EXT-1111) void getAllowedRect(LLRect& rect); - static void chatFromLogFile(LLLogChat::ELogLineType type, std::string line, void* userdata); - // Add the "User is typing..." indicator. void addTypingIndicator(const LLIMInfo* im_info); diff --git a/indra/newview/llimpanel.cpp b/indra/newview/llimpanel.cpp index 77ee90f681..c4beb666ea 100644 --- a/indra/newview/llimpanel.cpp +++ b/indra/newview/llimpanel.cpp @@ -181,13 +181,6 @@ LLFloaterIMPanel::LLFloaterIMPanel(const std::string& session_label, // enable line history support for instant message bar mInputEditor->setEnableLineHistory(TRUE); - if ( gSavedPerAccountSettings.getBOOL("LogShowHistory") ) - { - LLLogChat::loadHistory(mSessionLabel, - &chatFromLogFile, - (void *)this); - } - //*TODO we probably need the same "awaiting message" thing in LLIMFloater LLIMModel::LLIMSession* im_session = LLIMModel::getInstance()->findIMSession(mSessionUUID); if (!im_session) @@ -977,41 +970,6 @@ void LLFloaterIMPanel::removeTypingIndicator(const LLIMInfo* im_info) } } -//static -void LLFloaterIMPanel::chatFromLogFile(LLLogChat::ELogLineType type, std::string line, void* userdata) -{ - LLFloaterIMPanel* self = (LLFloaterIMPanel*)userdata; - std::string message = line; - S32 im_log_option = gSavedPerAccountSettings.getS32("IMLogOptions"); - switch (type) - { - case LLLogChat::LOG_EMPTY: - // add warning log enabled message - if (im_log_option!=LOG_CHAT) - { - message = LLTrans::getString("IM_logging_string"); - } - break; - case LLLogChat::LOG_END: - // add log end message - if (im_log_option!=LOG_CHAT) - { - message = LLTrans::getString("IM_logging_string"); - } - break; - case LLLogChat::LOG_LINE: - // just add normal lines from file - break; - default: - // nothing - break; - } - - //self->addHistoryLine(line, LLColor4::grey, FALSE); - self->mHistoryEditor->appendText(message, true, LLStyle::Params().color(LLUIColorTable::instance().getColor("ChatHistoryTextColor"))); - self->mHistoryEditor->blockUndo(); -} - //static void LLFloaterIMPanel::onKickSpeaker(void* user_data) { diff --git a/indra/newview/llimpanel.h b/indra/newview/llimpanel.h index 39107d9a22..b8f99d45c9 100644 --- a/indra/newview/llimpanel.h +++ b/indra/newview/llimpanel.h @@ -127,7 +127,6 @@ public: // Handle other participant in the session typing. void processIMTyping(const LLIMInfo* im_info, BOOL typing); - static void chatFromLogFile(LLLogChat::ELogLineType type, std::string line, void* userdata); private: // Called by UI methods. diff --git a/indra/newview/llimview.cpp b/indra/newview/llimview.cpp index cc848e519f..49fc9d8055 100644 --- a/indra/newview/llimview.cpp +++ b/indra/newview/llimview.cpp @@ -135,7 +135,6 @@ LLIMModel::LLIMModel() addNewMsgCallback(toast_callback); } - LLIMModel::LLIMSession::LLIMSession(const LLUUID& session_id, const std::string& name, const EInstantMessage& type, const LLUUID& other_participant_id, const std::vector<LLUUID>& ids) : mSessionID(session_id), mName(name), @@ -179,6 +178,9 @@ LLIMModel::LLIMSession::LLIMSession(const LLUUID& session_id, const std::string& mTextIMPossible = LLVoiceClient::getInstance()->isSessionTextIMPossible(mSessionID); mOtherParticipantIsAvatar = LLVoiceClient::getInstance()->isParticipantAvatar(mSessionID); } + + if ( gSavedPerAccountSettings.getBOOL("LogShowHistory") ) + LLLogChat::loadHistory(mName, &chatFromLogFile, (void *)this); } LLIMModel::LLIMSession::~LLIMSession() @@ -220,6 +222,34 @@ void LLIMModel::LLIMSession::sessionInitReplyReceived(const LLUUID& new_session_ } } +void LLIMModel::LLIMSession::addMessage(const std::string& from, const LLUUID& from_id, const std::string& utf8_text, const std::string& time) +{ + LLSD message; + message["from"] = from; + message["from_id"] = from_id; + message["message"] = utf8_text; + message["time"] = time; + message["index"] = (LLSD::Integer)mMsgs.size(); + + mMsgs.push_front(message); +} + +void LLIMModel::LLIMSession::chatFromLogFile(LLLogChat::ELogLineType type, const LLSD& msg, void* userdata) +{ + if (!userdata) return; + + LLIMSession* self = (LLIMSession*) userdata; + + if (type == LLLogChat::LOG_LINE) + { + self->addMessage("", LLSD(), msg["message"].asString(), ""); + } + else if (type == LLLogChat::LOG_LLSD) + { + self->addMessage(msg["from"].asString(), msg["from_id"].asUUID(), msg["message"].asString(), msg["time"].asString()); + } +} + LLIMModel::LLIMSession* LLIMModel::findIMSession(const LLUUID& session_id) const { return get_if_there(LLIMModel::instance().sSessionsMap, session_id, @@ -348,39 +378,25 @@ bool LLIMModel::addToHistory(const LLUUID& session_id, const std::string& from, return false; } - LLSD message; - message["from"] = from; - message["from_id"] = from_id; - message["message"] = utf8_text; - message["time"] = LLLogChat::timestamp(false); //might want to add date separately - message["index"] = (LLSD::Integer)session->mMsgs.size(); - - session->mMsgs.push_front(message); + session->addMessage(from, from_id, utf8_text, LLLogChat::timestamp(false)); //might want to add date separately return true; - } //*TODO rewrite chat history persistence using LLSD serialization (IB) -bool LLIMModel::logToFile(const LLUUID& session_id, const std::string& from, const std::string& utf8_text) +bool LLIMModel::logToFile(const LLUUID& session_id, const std::string& from, const LLUUID& from_id, const std::string& utf8_text) { S32 im_log_option = gSavedPerAccountSettings.getS32("IMLogOptions"); if (im_log_option != LOG_CHAT) { - std::string histstr; - if (gSavedPerAccountSettings.getBOOL("LogTimestamp")) - histstr = LLLogChat::timestamp(gSavedPerAccountSettings.getBOOL("LogTimestampDate")) + from + IM_SEPARATOR + utf8_text; - else - histstr = from + IM_SEPARATOR + utf8_text; - if(im_log_option == LOG_BOTH_TOGETHER) { - LLLogChat::saveHistory(std::string("chat"), histstr); + LLLogChat::saveHistory(std::string("chat"), from, from_id, utf8_text); return true; } else { - LLLogChat::saveHistory(LLIMModel::getInstance()->getName(session_id), histstr); + LLLogChat::saveHistory(LLIMModel::getInstance()->getName(session_id), from, from_id, utf8_text); return true; } } @@ -398,7 +414,7 @@ bool LLIMModel::addMessage(const LLUUID& session_id, const std::string& from, co } addToHistory(session_id, from, from_id, utf8_text); - if (log2file) logToFile(session_id, from, utf8_text); + if (log2file) logToFile(session_id, from, from_id, utf8_text); session->mNumUnread++; diff --git a/indra/newview/llimview.h b/indra/newview/llimview.h index ae8fd355ea..d0bd594df1 100644 --- a/indra/newview/llimview.h +++ b/indra/newview/llimview.h @@ -40,6 +40,7 @@ #include "llinstantmessage.h" #include "lluuid.h" #include "llmultifloater.h" +#include "lllogchat.h" class LLFloaterChatterBox; class LLUUID; @@ -57,6 +58,8 @@ public: virtual ~LLIMSession(); void sessionInitReplyReceived(const LLUUID& new_session_id); + void addMessage(const std::string& from, const LLUUID& from_id, const std::string& utf8_text, const std::string& time); + static void chatFromLogFile(LLLogChat::ELogLineType type, const LLSD& msg, void* userdata); LLUUID mSessionID; std::string mName; @@ -193,8 +196,7 @@ private: /** * Save an IM message into a file */ - //*TODO should also save uuid of a sender - bool logToFile(const LLUUID& session_id, const std::string& from, const std::string& utf8_text); + bool logToFile(const LLUUID& session_id, const std::string& from, const LLUUID& from_id, const std::string& utf8_text); }; class LLIMSessionObserver diff --git a/indra/newview/lllogchat.cpp b/indra/newview/lllogchat.cpp index 69214b5cab..a16ffe19c6 100644 --- a/indra/newview/lllogchat.cpp +++ b/indra/newview/lllogchat.cpp @@ -36,6 +36,8 @@ #include "llappviewer.h" #include "llfloaterchat.h" #include "lltrans.h" +#include "llviewercontrol.h" +#include "llsdserialize.h" const S32 LOG_RECALL_SIZE = 2048; @@ -89,41 +91,53 @@ std::string LLLogChat::timestamp(bool withdate) //static -void LLLogChat::saveHistory(std::string filename, std::string line) +void LLLogChat::saveHistory(const std::string& filename, + const std::string& from, + const LLUUID& from_id, + const std::string& line) { + if (!gSavedPerAccountSettings.getBOOL("LogInstantMessages")) + return; + if(!filename.size()) { llinfos << "Filename is Empty!" << llendl; return; } - LLFILE* fp = LLFile::fopen(LLLogChat::makeLogFileName(filename), "a"); /*Flawfinder: ignore*/ - if (!fp) + llofstream file (LLLogChat::makeLogFileName(filename), std::ios_base::app); + if (!file.is_open()) { llinfos << "Couldn't open chat history log!" << llendl; + return; } - else - { - fprintf(fp, "%s\n", line.c_str()); - - fclose (fp); - } + + LLSD item; + + if (gSavedPerAccountSettings.getBOOL("LogTimestamp")) + item["time"] = LLLogChat::timestamp(gSavedPerAccountSettings.getBOOL("LogTimestampDate")); + + item["from"] = from; + item["from_id"] = from_id; + item["message"] = line; + + file << LLSDOStreamer <LLSDNotationFormatter>(item) << std::endl; + + file.close(); } -void LLLogChat::loadHistory(std::string filename , void (*callback)(ELogLineType,std::string,void*), void* userdata) +void LLLogChat::loadHistory(const std::string& filename, void (*callback)(ELogLineType, const LLSD&, void*), void* userdata) { if(!filename.size()) { llwarns << "Filename is Empty!" << llendl; return ; } - + LLFILE* fptr = LLFile::fopen(makeLogFileName(filename), "r"); /*Flawfinder: ignore*/ if (!fptr) { - //LLUIString message = LLTrans::getString("IM_logging_string"); - //callback(LOG_EMPTY,"IM_logging_string",userdata); - callback(LOG_EMPTY,LLStringUtil::null,userdata); + callback(LOG_EMPTY, LLSD(), userdata); return; //No previous conversation with this name. } else @@ -143,6 +157,9 @@ void LLLogChat::loadHistory(std::string filename , void (*callback)(ELogLineType } } + // the parser's destructor is protected so we cannot create in the stack. + LLPointer<LLSDParser> parser = new LLSDNotationParser(); + while ( fgets(buffer, LOG_RECALL_SIZE, fptr) && !feof(fptr) ) { len = strlen(buffer) - 1; /*Flawfinder: ignore*/ @@ -150,14 +167,25 @@ void LLLogChat::loadHistory(std::string filename , void (*callback)(ELogLineType if (!firstline) { - callback(LOG_LINE,std::string(buffer),userdata); + LLSD item; + std::string line(buffer); + std::istringstream iss(line); + if (parser->parse(iss, item, line.length()) == LLSDParser::PARSE_FAILURE) + { + item["message"] = line; + callback(LOG_LINE, item, userdata); + } + else + { + callback(LOG_LLSD, item, userdata); + } } else { firstline = FALSE; } } - callback(LOG_END,LLStringUtil::null,userdata); + callback(LOG_END, LLSD(), userdata); fclose(fptr); } diff --git a/indra/newview/lllogchat.h b/indra/newview/lllogchat.h index ad903b66fe..e252cd7d41 100644 --- a/indra/newview/lllogchat.h +++ b/indra/newview/lllogchat.h @@ -41,13 +41,18 @@ public: enum ELogLineType { LOG_EMPTY, LOG_LINE, + LOG_LLSD, LOG_END }; static std::string timestamp(bool withdate = false); static std::string makeLogFileName(std::string(filename)); - static void saveHistory(std::string filename, std::string line); - static void loadHistory(std::string filename, - void (*callback)(ELogLineType,std::string,void*), + static void saveHistory(const std::string& filename, + const std::string& from, + const LLUUID& from_id, + const std::string& line); + + static void loadHistory(const std::string& filename, + void (*callback)(ELogLineType, const LLSD&, void*), void* userdata); private: static std::string cleanFileName(std::string filename); |