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

View File

@ -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;

View File

@ -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);

View File

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

View File

@ -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;

View File

@ -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;
}
}

View File

@ -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;