diff --git a/application/Conversation.cpp b/application/Conversation.cpp index cb96d3a..c4f14e7 100644 --- a/application/Conversation.cpp +++ b/application/Conversation.cpp @@ -504,53 +504,61 @@ Conversation::_LogChatMessage(BMessage* msg) fDateFormatter.Format(date, time(0), B_SHORT_DATE_FORMAT, B_MEDIUM_TIME_FORMAT); BString id = msg->FindString("user_id"); + BString name = msg->FindString("user_name"); BString body = msg->FindString("body"); if (id.IsEmpty() == true) return; + if (name.IsEmpty() == true) { + User* user = UserById(id); + if (user == NULL) + name = id; + else + name = user->GetName(); + } + // Binary logs - // TODO: Don't hardcode 21, expose maximum as a setting - BStringList users, bodies; - int64 times[21] = { 0 }; + // TODO: Don't hardcode 31, expose maximum as a setting + int32 max = 31; + BStringList user_ids, user_names, bodies; + int64 times[max] = { 0 }; times[0] = (int64)time(NULL); BMessage logMsg; if (_GetChatLogs(&logMsg) == B_OK) { logMsg.FindStrings("body", &bodies); - logMsg.FindStrings("user_id", &users); + logMsg.FindStrings("user_id", &user_ids); + logMsg.FindStrings("user_name", &user_names); int64 found; - for (int i = 0; i < 21; i++) + for (int i = 0; i < max; i++) if (logMsg.FindInt64("when", i, &found) == B_OK) times[i + 1] = found; - bodies.Remove(21); - users.Remove(21); + bodies.Remove(max); + user_ids.Remove(max); + user_names.Remove(max); bodies.Add(body, 0); - users.Add(id, 0); + user_ids.Add(id, 0); + user_names.Add(name, 0); } BMessage newLogMsg(IM_MESSAGE); newLogMsg.AddInt32("im_what", IM_LOGS_RECEIVED); newLogMsg.AddStrings("body", bodies); - newLogMsg.AddStrings("user_id", users); + newLogMsg.AddStrings("user_id", user_ids); + newLogMsg.AddStrings("user_name", user_names); newLogMsg.AddInt64("when", time(NULL)); - for (int i = 0; i < 21; i++) + for (int i = 0; i < max; i++) newLogMsg.AddInt64("when", times[i]); BFile logFile(fCachePath.Path(), B_READ_WRITE | B_OPEN_AT_END | B_CREATE_FILE); WriteAttributeMessage(&logFile, "Chat:logs", &newLogMsg); // Plain-text logs - BString uname; - if (id.IsEmpty() == false) - uname = UserById(id)->GetName(); - else - uname = "You"; - BString logLine("["); - logLine << date << "] <" << uname << "> " << body << "\n"; + logLine << date << "] <" << name << "> " << body << "\n"; logFile.Write(logLine.String(), logLine.Length()); } diff --git a/application/views/ConversationView.cpp b/application/views/ConversationView.cpp index d96c446..b47fb5d 100644 --- a/application/views/ConversationView.cpp +++ b/application/views/ConversationView.cpp @@ -287,7 +287,7 @@ ConversationView::ObserveString(int32 what, BString str) { fSubjectTextView->SetText(str); - BString body = B_TRANSLATE("** The subject was changed: %subject%"); + BString body = B_TRANSLATE("** The subject is now: %subject%"); body.ReplaceAll("%subject%", str); BMessage topic(IM_MESSAGE); @@ -401,16 +401,18 @@ ConversationView::_AppendOrEnqueueMessage(BMessage* msg) void ConversationView::_AppendMessage(BMessage* msg) { - BStringList users, bodies; + BStringList user_ids, user_names, bodies; if (msg->FindStrings("body", &bodies) != B_OK) return; - msg->FindStrings("user_id", &users); + msg->FindStrings("user_id", &user_ids); + msg->FindStrings("user_name", &user_names); for (int i = bodies.CountStrings(); i >= 0; i--) { User* sender = NULL; if (fConversation != NULL) - sender = fConversation->UserById(users.StringAt(i)); - BString sender_name = users.StringAt(i); + sender = fConversation->UserById(user_ids.StringAt(i)); + BString sender_id = user_ids.StringAt(i); + BString sender_name = user_names.StringAt(i); BString body = bodies.StringAt(i); rgb_color userColor = ui_color(B_PANEL_TEXT_COLOR); int64 timeInt; @@ -423,7 +425,10 @@ ConversationView::_AppendMessage(BMessage* msg) userColor = sender->fItemColor; } - if (sender_name.IsEmpty() == true) { + if (sender_name.IsEmpty() == true && sender_id.IsEmpty() == false) + sender_name = sender_id; + + if (sender_id.IsEmpty() == true && sender_name.IsEmpty() == true) { fReceiveView->AppendGeneric(body.String()); continue; }