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.
This commit is contained in:
Jaidyn Ann 2021-06-06 18:06:46 -05:00
parent 260b36012e
commit fde681bbf4
7 changed files with 36 additions and 14 deletions

View File

@ -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 void
Conversation::SetNotifySubject(const char* subject) Conversation::SetNotifySubject(const char* subject)
{ {

View File

@ -40,6 +40,7 @@ public:
void ObserveInteger(int32 what, int32 value); void ObserveInteger(int32 what, int32 value);
void ObservePointer(int32 what, void* ptr); void ObservePointer(int32 what, void* ptr);
void SetNotifyName(const char* name);
void SetNotifySubject(const char* subject); void SetNotifySubject(const char* subject);
BMessenger Messenger() const; BMessenger Messenger() const;

View File

@ -300,7 +300,13 @@ MainWindow::SetConversation(Conversation* chat)
if (chat != NULL) { if (chat != NULL) {
fChatView = chat->GetView(); fChatView = chat->GetView();
fConversation = chat; fConversation = chat;
BString title(chat->GetName());
title << " ― Caya";
SetTitle(title.String());
} }
else
SetTitle("Caya");
fRightView->AddChild(fChatView, 9); fRightView->AddChild(fChatView, 9);
fRightView->AddChild(fSendScroll, 1); fRightView->AddChild(fSendScroll, 1);

View File

@ -8,6 +8,7 @@
enum { enum {
STR_CONTACT_NAME, STR_CONTACT_NAME,
STR_PERSONAL_STATUS, STR_PERSONAL_STATUS,
STR_ROOM_NAME,
STR_ROOM_SUBJECT, STR_ROOM_SUBJECT,
PTR_AVATAR_BITMAP, PTR_AVATAR_BITMAP,

View File

@ -299,6 +299,16 @@ Server::ImMessage(BMessage* msg)
chat->SetRole(user_id, role); chat->SetRole(user_id, role);
break; 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: case IM_ROOM_SUBJECT:
{ {
BString subject; BString subject;

View File

@ -6,6 +6,7 @@
#include "ConversationItem.h" #include "ConversationItem.h"
#include "Conversation.h" #include "Conversation.h"
#include "NotifyMessage.h"
ConversationItem::ConversationItem(const char* name, Conversation* chat) ConversationItem::ConversationItem(const char* name, Conversation* chat)
@ -26,18 +27,12 @@ ConversationItem::GetConversation()
void void
ConversationItem::ObserveString(int32 what, BString str) ConversationItem::ObserveString(int32 what, BString str)
{ {
} switch (what)
void
ConversationItem::ObservePointer(int32 what, void* ptr)
{
}
void
ConversationItem::ObserveInteger(int32 what, int32 val)
{ {
case STR_ROOM_NAME:
SetText(str.String());
break;
}
} }

View File

@ -20,8 +20,6 @@ public:
protected: protected:
void ObserveString(int32 what, BString str); void ObserveString(int32 what, BString str);
void ObservePointer(int32 what, void* ptr);
void ObserveInteger(int32 what, int32 val);
private: private:
Conversation* fChat; Conversation* fChat;