From fde681bbf492fcf20039e0b243fb3fd9092a847d Mon Sep 17 00:00:00 2001 From: Jaidyn Ann Date: Sun, 6 Jun 2021 18:06:46 -0500 Subject: [PATCH] Update conversation name & window title Allow updating a conversation's name through IM_ROOM_NAME, and change the Caya window's title whenever a new chat is selected. --- application/Conversation.cpp | 11 +++++++++++ application/Conversation.h | 1 + application/MainWindow.cpp | 6 ++++++ application/NotifyMessage.h | 1 + application/Server.cpp | 10 ++++++++++ application/views/ConversationItem.cpp | 19 +++++++------------ application/views/ConversationItem.h | 2 -- 7 files changed, 36 insertions(+), 14 deletions(-) diff --git a/application/Conversation.cpp b/application/Conversation.cpp index e01581d..3be62a4 100644 --- a/application/Conversation.cpp +++ b/application/Conversation.cpp @@ -98,6 +98,17 @@ Conversation::ObservePointer(int32 what, void* ptr) } +void +Conversation::SetNotifyName(const char* name) +{ + if (BString(name) == fName) + return; + + fName = name; + NotifyString(STR_ROOM_NAME, fName.String()); +} + + void Conversation::SetNotifySubject(const char* subject) { diff --git a/application/Conversation.h b/application/Conversation.h index a6ca147..ed88612 100644 --- a/application/Conversation.h +++ b/application/Conversation.h @@ -40,6 +40,7 @@ public: void ObserveInteger(int32 what, int32 value); void ObservePointer(int32 what, void* ptr); + void SetNotifyName(const char* name); void SetNotifySubject(const char* subject); BMessenger Messenger() const; diff --git a/application/MainWindow.cpp b/application/MainWindow.cpp index 8dbfe46..d9222a2 100644 --- a/application/MainWindow.cpp +++ b/application/MainWindow.cpp @@ -300,7 +300,13 @@ MainWindow::SetConversation(Conversation* chat) if (chat != NULL) { fChatView = chat->GetView(); fConversation = chat; + + BString title(chat->GetName()); + title << " ― Caya"; + SetTitle(title.String()); } + else + SetTitle("Caya"); fRightView->AddChild(fChatView, 9); fRightView->AddChild(fSendScroll, 1); diff --git a/application/NotifyMessage.h b/application/NotifyMessage.h index 9e1f733..385ade8 100644 --- a/application/NotifyMessage.h +++ b/application/NotifyMessage.h @@ -8,6 +8,7 @@ enum { STR_CONTACT_NAME, STR_PERSONAL_STATUS, + STR_ROOM_NAME, STR_ROOM_SUBJECT, PTR_AVATAR_BITMAP, diff --git a/application/Server.cpp b/application/Server.cpp index 4c9b348..fc2a7fb 100644 --- a/application/Server.cpp +++ b/application/Server.cpp @@ -299,6 +299,16 @@ Server::ImMessage(BMessage* msg) chat->SetRole(user_id, role); break; } + case IM_ROOM_NAME: + { + BString name; + Conversation* chat = _EnsureConversation(msg); + if (msg->FindString("chat_name", &name) != B_OK || chat == NULL) + break; + + chat->SetNotifyName(name.String()); + break; + } case IM_ROOM_SUBJECT: { BString subject; diff --git a/application/views/ConversationItem.cpp b/application/views/ConversationItem.cpp index 2224b85..7e850dc 100644 --- a/application/views/ConversationItem.cpp +++ b/application/views/ConversationItem.cpp @@ -6,6 +6,7 @@ #include "ConversationItem.h" #include "Conversation.h" +#include "NotifyMessage.h" ConversationItem::ConversationItem(const char* name, Conversation* chat) @@ -26,18 +27,12 @@ ConversationItem::GetConversation() void ConversationItem::ObserveString(int32 what, BString str) { -} - - -void -ConversationItem::ObservePointer(int32 what, void* ptr) -{ -} - - -void -ConversationItem::ObserveInteger(int32 what, int32 val) -{ + switch (what) + { + case STR_ROOM_NAME: + SetText(str.String()); + break; + } } diff --git a/application/views/ConversationItem.h b/application/views/ConversationItem.h index 48b8cd7..b12d288 100644 --- a/application/views/ConversationItem.h +++ b/application/views/ConversationItem.h @@ -20,8 +20,6 @@ public: protected: void ObserveString(int32 what, BString str); - void ObservePointer(int32 what, void* ptr); - void ObserveInteger(int32 what, int32 val); private: Conversation* fChat;