diff --git a/application/Conversation.cpp b/application/Conversation.cpp index c1410fc..01f26be 100644 --- a/application/Conversation.cpp +++ b/application/Conversation.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2021, Jaidyn Levesque + * Copyright 2021-2022, Jaidyn Levesque * All rights reserved. Distributed under the terms of the MIT license. */ @@ -146,10 +146,10 @@ Conversation::ImMessage(BMessage* msg) // Misc. features Caya contributors planned on adding BWindow* mainWin = ((TheApp*)be_app)->GetMainWindow(); - if (win == NULL && AppPreferences::Get()->MarkUnreadWindow == true) + if (winFocus == false && AppPreferences::Get()->MarkUnreadWindow == true) mainWin->SetTitle(BString(mainWin->Title()).Prepend("[!]")); - if (win == NULL && AppPreferences::Get()->MoveToCurrentWorkspace) + if (winFocus == false && AppPreferences::Get()->MoveToCurrentWorkspace) mainWin->SetWorkspaces(B_CURRENT_WORKSPACE); if (win == NULL && AppPreferences::Get()->RaiseOnMessageReceived) @@ -157,9 +157,9 @@ Conversation::ImMessage(BMessage* msg) // If unattached, highlight the ConversationItem - if (win == NULL && mentioned == true) + if ((win == NULL || GetView()->IsHidden() == true) && mentioned == true) NotifyInteger(INT_NEW_MENTION, fNotifyMentionCount); - else if (win == NULL) + else if (win == NULL || GetView()->IsHidden()) NotifyInteger(INT_NEW_MESSAGE, fNotifyMessageCount); break; @@ -319,7 +319,7 @@ Conversation::ObserveString(int32 what, BString str) void Conversation::ObserveInteger(int32 what, int32 value) { - if (what == INT_WINDOW_FOCUSED) { + if (what == INT_CONV_VIEW_SELECTED) { fNotifyMessageCount = 0; fNotifyMentionCount = 0; } diff --git a/application/NotifyMessage.h b/application/NotifyMessage.h index 606218d..983fb56 100644 --- a/application/NotifyMessage.h +++ b/application/NotifyMessage.h @@ -21,7 +21,7 @@ enum { INT_NEW_MESSAGE, INT_NEW_MENTION, - INT_WINDOW_FOCUSED, + INT_CONV_VIEW_SELECTED, INT_ACCOUNTS_UPDATED }; diff --git a/application/views/ConversationItem.cpp b/application/views/ConversationItem.cpp index a047683..ee837c7 100644 --- a/application/views/ConversationItem.cpp +++ b/application/views/ConversationItem.cpp @@ -71,7 +71,7 @@ ConversationItem::ObserveInteger(int32 what, int32 num) case INT_NEW_MENTION: fStatus |= kMentioned; break; - case INT_WINDOW_FOCUSED: + case INT_CONV_VIEW_SELECTED: fStatus = 0; break; } diff --git a/application/views/ConversationView.cpp b/application/views/ConversationView.cpp index 1682800..e52da46 100644 --- a/application/views/ConversationView.cpp +++ b/application/views/ConversationView.cpp @@ -1,6 +1,6 @@ /* * Copyright 2009-2011, Andrea Anzani. All rights reserved. - * Copyright 2021, Jaidyn Levesque. All rights reserved. + * Copyright 2021-2022, Jaidyn Levesque. All rights reserved. * Distributed under the terms of the MIT License. * * Authors: @@ -67,7 +67,15 @@ ConversationView::AttachedToWindow() if (fSubjectTextView->Text() != fConversation->GetSubject()) fSubjectTextView->SetText(fConversation->GetSubject()); } - NotifyInteger(INT_WINDOW_FOCUSED, 0); +} + + +void +ConversationView::Show() +{ + BView::Show(); + + NotifyInteger(INT_CONV_VIEW_SELECTED, 0); fSendView->MakeFocus(true); fSendView->Invalidate(); } @@ -124,7 +132,7 @@ ConversationView::ImMessage(BMessage* msg) case IM_MESSAGE_RECEIVED: { _AppendOrEnqueueMessage(msg); - fReceiveView->ScrollToBottom(); + _ScrollToBottom(); break; } case IM_MESSAGE_SENT: @@ -132,7 +140,7 @@ ConversationView::ImMessage(BMessage* msg) { _AppendOrEnqueueMessage(msg); if (im_what == IM_MESSAGE_SENT) - fReceiveView->ScrollToBottom(); + _ScrollToBottom(); break; } case IM_ROOM_PARTICIPANT_JOINED: @@ -392,7 +400,7 @@ ConversationView::_AppendOrEnqueueMessage(BMessage* msg) if (msg->HasInt64("when") == false) msg->AddInt64("when", (int64)time(NULL)); - // If not attached to the chat window, then re-handle this message + // If not attached to a chat window, then re-handle this message // later [AttachedToWindow()], since you can't edit an unattached // RenderView. if (Window() == NULL) { @@ -503,6 +511,14 @@ ConversationView::_AppendMessage(BMessage* msg) } +void +ConversationView::_ScrollToBottom() +{ + if (IsHidden() == false) + fReceiveView->ScrollToBottom(); +} + + void ConversationView::_EnableStartingFaces(BMessage* msg, int32 index, uint16* face, UInt16IntMap* indices, int32* next) @@ -607,7 +623,7 @@ ConversationView::_UserMessage(const char* format, const char* bodyFormat, BMessage newMsg; newMsg.AddString("body", newBody); _AppendOrEnqueueMessage(&newMsg); - fReceiveView->ScrollToBottom(); + _ScrollToBottom(); } diff --git a/application/views/ConversationView.h b/application/views/ConversationView.h index 4c92f25..bc88528 100644 --- a/application/views/ConversationView.h +++ b/application/views/ConversationView.h @@ -1,6 +1,6 @@ /* * Copyright 2009-2011, Andrea Anzani. All rights reserved. - * Copyright 2021, Jaidyn Levesque. All rights reserved. + * Copyright 2021-2022, Jaidyn Levesque. All rights reserved. * Distributed under the terms of the MIT License. */ #ifndef _CHAT_VIEW_H @@ -34,6 +34,7 @@ public: ConversationView(Conversation* chat = NULL); virtual void AttachedToWindow(); + void Show(); virtual void MessageReceived(BMessage* message); void ImMessage(BMessage* msg); @@ -58,6 +59,8 @@ private: bool _AppendOrEnqueueMessage(BMessage* msg); void _AppendMessage(BMessage* msg); + void _ScrollToBottom(); + // Helper functions for _AppendFormattedMessage() void _EnableStartingFaces(BMessage* msg, int32 index, uint16* face, UInt16IntMap* indices, int32* next);