diff --git a/application/views/ConversationView.cpp b/application/views/ConversationView.cpp index a5b1106..4285e57 100644 --- a/application/views/ConversationView.cpp +++ b/application/views/ConversationView.cpp @@ -387,6 +387,23 @@ ConversationView::_InitInterface() bool ConversationView::_AppendOrEnqueueMessage(BMessage* msg) { + // Fill the message with user information not provided by protocol + BString user_id = msg->FindString("user_id"); + if (msg->FindString("user_id", &user_id) == B_OK) { + User* user = NULL; + if (fConversation != NULL) + user = fConversation->UserById(user_id); + if (user != NULL) { + if (msg->HasString("user_name") == false) + if (user->GetName().IsEmpty() == false) + msg->AddString("user_name", user->GetName()); + msg->AddColor("user_color", user->fItemColor); + } + if (msg->HasString("user_name") == false) + msg->AddString("user_name", user_id); + } + + // Fill the message with receive time if not provided if (msg->HasInt64("when") == false) msg->AddInt64("when", (int64)time(NULL)); @@ -423,31 +440,16 @@ ConversationView::_AppendMessage(BMessage* msg) } // Otherwise, it's message time! - int64 timeInt; - BString user_id; + int64 timeInt = msg->GetInt64("when", time(NULL)); BString user_name = msg->FindString("user_name"); + rgb_color userColor = msg->GetColor("user_color", ui_color(B_PANEL_TEXT_COLOR)); BString body; - rgb_color userColor = ui_color(B_PANEL_TEXT_COLOR); if (msg->FindString("body", &body) != B_OK) return; - if (msg->FindInt64("when", &timeInt) != B_OK) - timeInt = (int64)time(NULL); - - if (msg->FindString("user_id", &user_id) == B_OK) { - User* user = NULL; - if (fConversation != NULL - && (user = fConversation->UserById(user_id)) != NULL) { - user_name = user->GetName(); - userColor = user->fItemColor; - } - else if (user_name.IsEmpty() == true) - user_name = user_id; - } - if (user_name.IsEmpty() == true) { - fReceiveView->AppendGeneric(body); + fReceiveView->AppendGeneric(body, timeInt); return; } @@ -455,7 +457,7 @@ ConversationView::_AppendMessage(BMessage* msg) BString meMsg = "** "; meMsg << user_name.String() << " "; meMsg << body.RemoveFirst("/me "); - fReceiveView->AppendGeneric(meMsg.String()); + fReceiveView->AppendGeneric(meMsg.String(), timeInt); return; } diff --git a/application/views/RenderView.cpp b/application/views/RenderView.cpp index 6b45287..c267826 100644 --- a/application/views/RenderView.cpp +++ b/application/views/RenderView.cpp @@ -18,10 +18,10 @@ RenderView::RenderView(const char* name) void -RenderView::AppendGeneric(const char* message) +RenderView::AppendGeneric(const char* message, int64 when) { if (BString(message).IsEmpty() == true) return; - AppendTimestamp(time(NULL)); + AppendTimestamp(when); Append(message, ui_color(B_PANEL_TEXT_COLOR), B_BOLD_FACE); if (BString(message).EndsWith("\n") == false) Append("\n"); } diff --git a/application/views/RenderView.h b/application/views/RenderView.h index 1cc2d82..7c9d334 100644 --- a/application/views/RenderView.h +++ b/application/views/RenderView.h @@ -12,7 +12,7 @@ class RenderView : public RunView { public: RenderView(const char* name); - void AppendGeneric(const char* message); + void AppendGeneric(const char* message, int64 when); void AppendUserstamp(const char* nick, rgb_color nameColor); void AppendTimestamp(time_t time = 0);