diff --git a/application/CayaProtocolMessages.h b/application/CayaProtocolMessages.h index 3de5be0..44aca5b 100644 --- a/application/CayaProtocolMessages.h +++ b/application/CayaProtocolMessages.h @@ -73,29 +73,6 @@ enum im_what_code { IM_LOGS_RECEIVED = 28, - /* - * Messages related to rooms - */ - - //! Create an individual chat - IM_CREATE_CHAT = 30, - - //! Chat has been created - IM_CHAT_CREATED = 31, - - //! Join a room - IM_JOIN_ROOM = 32, - - //! Confirm the room's been joined - IM_ROOM_JOINED = 33, - - //! Returning a (not necessarily complete) list of room users - IM_ROOM_PARTICIPANTS = 34, - - //! A user left the room - IM_ROOM_PARTICIPANT_LEFT = 35, - - /* * Messages related to contact changes. */ @@ -197,6 +174,44 @@ enum im_what_code { //! Notifications IM_NOTIFICATION = 141, + + /* + * Room membership + */ + + //! Create an individual chat + IM_CREATE_CHAT = 150, + + //! Chat has been created + IM_CHAT_CREATED = 151, + + //! Join a room + IM_JOIN_ROOM = 152, + + //! Confirm the room's been joined + IM_ROOM_JOINED = 153, + + //! Quietly add a user(s) to the chat + IM_ROOM_PARTICIPANTS = 154, + + //! User has newly and explicitly joined + IM_ROOM_PARTICIPANT_JOINED = 155, + + //! A user left the room + IM_ROOM_PARTICIPANT_LEFT = 156, + + + /* + * Room metadata + */ + + //! Room name + IM_ROOM_NAME = 160, + + //! Room subject + IM_ROOM_SUBJECT = 161, + + /* * Special messages */ diff --git a/application/CayaUtils.cpp b/application/CayaUtils.cpp index 6e3460e..3a8d70b 100644 --- a/application/CayaUtils.cpp +++ b/application/CayaUtils.cpp @@ -9,6 +9,7 @@ #include #include +#include #include #include #include @@ -145,6 +146,35 @@ CayaLogPath(const char* signature, const char* subsignature) } +rgb_color +CayaTintColor(rgb_color color, int severity) +{ + bool dark = false; + if (color.Brightness() < 127) + dark = true; + + switch (severity) + { + case 1: + if (dark == true) + return tint_color(color, B_LIGHTEN_1_TINT + 0.2f); + else + return tint_color(color, B_DARKEN_1_TINT); + case 2: + if (dark == true) + return tint_color(color, B_LIGHTEN_1_TINT); + else + return tint_color(color, B_DARKEN_2_TINT); + case 3: + if (dark == true) + return tint_color(color, B_LIGHTEN_2_TINT + 0.1f); + else + return tint_color(color, B_DARKEN_3_TINT); + } + return color; +} + + extern "C" { status_t diff --git a/application/CayaUtils.h b/application/CayaUtils.h index bb37a14..d99f9b5 100644 --- a/application/CayaUtils.h +++ b/application/CayaUtils.h @@ -7,6 +7,7 @@ #include +#include #include #include @@ -23,6 +24,11 @@ const char* CayaAccountPath(const char* signature, const char* subsignature); const char* CayaCachePath(); const char* CayaLogPath(const char* signature, const char* subsignature); +// Will return a tinted color― light or dark― based on brightness. +rgb_color CayaTintColor(rgb_color color, int severity); + extern "C" status_t our_image(image_info& image); + #endif // _CAYA_UTILS_H + diff --git a/application/Conversation.cpp b/application/Conversation.cpp index 92c8c8e..eca210d 100644 --- a/application/Conversation.cpp +++ b/application/Conversation.cpp @@ -16,6 +16,7 @@ #include "ConversationItem.h" #include "ConversationView.h" #include "MainWindow.h" +#include "NotifyMessage.h" #include "ProtocolLooper.h" #include "ProtocolManager.h" #include "Server.h" @@ -29,6 +30,7 @@ Conversation::Conversation(BString id, BMessenger msgn) fMessenger(msgn), fChatView(NULL), fLooper(NULL), + fIcon(NULL), fDateFormatter() { fConversationItem = new ConversationItem(fName.String(), this); @@ -96,6 +98,16 @@ Conversation::ObservePointer(int32 what, void* ptr) } +void +Conversation::SetNotifySubject(const char* subject) +{ + if (BString(subject) == fSubject) + return; + + fSubject = subject; + NotifyString(STR_ROOM_SUBJECT, fSubject.String()); +} + BMessenger Conversation::Messenger() const @@ -125,6 +137,24 @@ Conversation::SetProtocolLooper(ProtocolLooper* looper) } +BBitmap* +Conversation::ProtocolBitmap() const +{ + CayaProtocol* protocol = fLooper->Protocol(); + CayaProtocolAddOn* addOn + = ProtocolManager::Get()->ProtocolAddOn(protocol->Signature()); + + return addOn->ProtoIcon(); +} + + +BBitmap* +Conversation::IconBitmap() const +{ + return fIcon; +} + + BString Conversation::GetName() const { diff --git a/application/Conversation.h b/application/Conversation.h index 5b7ecaa..832e0c5 100644 --- a/application/Conversation.h +++ b/application/Conversation.h @@ -15,6 +15,7 @@ #include "Server.h" #include "User.h" +class BBitmap; class ConversationItem; class ConversationView; class ProtocolLooper; @@ -37,12 +38,17 @@ public: void ObserveInteger(int32 what, int32 value); void ObservePointer(int32 what, void* ptr); + void SetNotifySubject(const char* subject); + BMessenger Messenger() const; void SetMessenger(BMessenger messenger); ProtocolLooper* GetProtocolLooper() const; void SetProtocolLooper(ProtocolLooper* looper); + BBitmap* ProtocolBitmap() const; + BBitmap* IconBitmap() const; + void ShowView(bool typing, bool userAction); ConversationView* GetView(); @@ -71,6 +77,9 @@ private: BString fID; BString fName; + BString fSubject; + + BBitmap* fIcon; BPath fLogPath; BDateTimeFormat fDateFormatter; diff --git a/application/NotifyMessage.h b/application/NotifyMessage.h index 983a0e4..99600e1 100644 --- a/application/NotifyMessage.h +++ b/application/NotifyMessage.h @@ -8,6 +8,7 @@ enum { STR_CONTACT_NAME, STR_PERSONAL_STATUS, + STR_ROOM_SUBJECT, PTR_AVATAR_BITMAP, diff --git a/application/Server.cpp b/application/Server.cpp index 5e05f90..46799f0 100644 --- a/application/Server.cpp +++ b/application/Server.cpp @@ -285,6 +285,16 @@ Server::ImMessage(BMessage* msg) chat->RemoveUser(user); break; } + case IM_ROOM_SUBJECT: + { + BString subject; + Conversation* chat = _EnsureConversation(msg); + if (msg->FindString("subject", &subject) != B_OK || chat == NULL) + break; + + chat->SetNotifySubject(subject.String()); + break; + } case IM_SEND_MESSAGE: { // Route this message through the appropriate ProtocolLooper diff --git a/application/views/ConversationView.cpp b/application/views/ConversationView.cpp index 56878c0..4b2a1eb 100644 --- a/application/views/ConversationView.cpp +++ b/application/views/ConversationView.cpp @@ -21,6 +21,7 @@ #include "CayaPreferences.h" #include "CayaProtocolMessages.h" #include "CayaRenderView.h" +#include "CayaUtils.h" #include "Conversation.h" #include "NotifyMessage.h" #include "User.h" @@ -133,10 +134,6 @@ ConversationView::ImMessage(BMessage* msg) } _AppendOrEnqueueMessage(msg); - - // Message received, clear status anyway -// fStatus->SetText(""); - break; } case IM_MESSAGE_SENT: @@ -145,17 +142,6 @@ ConversationView::ImMessage(BMessage* msg) _AppendOrEnqueueMessage(msg); break; } - case IM_CONTACT_STARTED_TYPING: - fStatus->SetText("Contact is typing..."); - break; - case IM_CONTACT_STOPPED_TYPING: - fStatus->SetText(""); - break; - case IM_CONTACT_GONE: - fStatus->SetText("Contact closed the chat window!"); - snooze(10000); - fStatus->SetText(""); - break; default: break; } @@ -173,24 +159,16 @@ void ConversationView::SetConversation(Conversation* chat) { fConversation = chat; - fContact = chat->Users().ValueAt(0); - fPersonalMessage->SetText(chat->GetName()); + fNameTextView->SetText(chat->GetName()); + fProtocolView->SetBitmap(chat->ProtocolBitmap()); } void -ConversationView::UpdateAvatar() +ConversationView::UpdateIcon() { - if (fContact->AvatarBitmap() != NULL) - fAvatar->SetBitmap(fContact->AvatarBitmap()); -} - - -void -ConversationView::UpdatePersonalMessage() -{ - if (fContact->GetNotifyPersonalStatus() != NULL) - fPersonalMessage->SetText(fContact->GetNotifyPersonalStatus()); + if (fConversation->IconBitmap() != NULL) + fIcon->SetBitmap(fConversation->IconBitmap()); } @@ -217,18 +195,14 @@ ConversationView::InvalidateUserList() void ConversationView::ObserveString(int32 what, BString str) { -} - - -void -ConversationView::ObservePointer(int32 what, void* ptr) -{ -} - - -void -ConversationView::ObserveInteger(int32 what, int32 val) -{ + switch (what) + { + case STR_ROOM_SUBJECT: + { + fSubjectTextView->SetText(str); + break; + } + } } @@ -239,20 +213,18 @@ ConversationView::_InitInterface() BScrollView* scrollViewReceive = new BScrollView("receiveScrollView", fReceiveView, B_WILL_DRAW, false, true); - fPersonalMessage = new BTextView("personalMessage", B_WILL_DRAW); - fPersonalMessage->SetExplicitAlignment( - BAlignment(B_ALIGN_LEFT, B_ALIGN_MIDDLE)); + fNameTextView = new BTextView("roomName", B_WILL_DRAW); + fNameTextView->SetViewUIColor(B_PANEL_BACKGROUND_COLOR); + fNameTextView->MakeEditable(false); - fPersonalMessage->SetText(""); - fPersonalMessage->MakeEditable(false); - fPersonalMessage->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); + fSubjectTextView = new BTextView("roomSubject", B_WILL_DRAW); + fSubjectTextView->SetViewUIColor(B_PANEL_BACKGROUND_COLOR); + fSubjectTextView->MakeEditable(false); - fStatus = new BStringView("status", ""); - - fAvatar = new BitmapView("ContactIcon"); - fAvatar->SetExplicitMinSize(BSize(50, 50)); - fAvatar->SetExplicitPreferredSize(BSize(50, 50)); - fAvatar->SetExplicitAlignment(BAlignment(B_ALIGN_RIGHT, B_ALIGN_MIDDLE)); + fIcon = new BitmapView("ContactIcon"); + fIcon->SetExplicitMinSize(BSize(50, 50)); + fIcon->SetExplicitPreferredSize(BSize(50, 50)); + fIcon->SetExplicitAlignment(BAlignment(B_ALIGN_RIGHT, B_ALIGN_MIDDLE)); fProtocolView = new BitmapView("protocolView"); @@ -262,15 +234,17 @@ ConversationView::_InitInterface() BLayoutBuilder::Group<>(this, B_VERTICAL) .AddGroup(B_HORIZONTAL) + .Add(fIcon) + .AddGroup(B_VERTICAL) + .Add(fNameTextView) + .Add(fSubjectTextView) + .End() .Add(fProtocolView) - .Add(fPersonalMessage) - .Add(fAvatar) .End() .AddSplit(B_HORIZONTAL, 0) .Add(scrollViewReceive, 5) .Add(scrollViewUsers, 1) .End(); -// .Add(fStatus, 4) } diff --git a/application/views/ConversationView.h b/application/views/ConversationView.h index 66d8a44..307430d 100644 --- a/application/views/ConversationView.h +++ b/application/views/ConversationView.h @@ -35,15 +35,12 @@ public: Conversation* GetConversation(); void SetConversation(Conversation* chat); - void UpdateAvatar(); - void UpdatePersonalMessage(); + void UpdateIcon(); void UpdateUserList(UserMap users); void InvalidateUserList(); void ObserveString(int32 what, BString str); - void ObservePointer(int32 what, void* ptr); - void ObserveInteger(int32 what, int32 val); void AvoidFocus(bool avoid); @@ -54,15 +51,15 @@ private: void _AppendMessage(BMessage* msg); Conversation* fConversation; - User* fContact; int32 fMessageCount; BObjectList fMessageQueue; - CayaRenderView* fReceiveView; - BStringView* fStatus; - BTextView* fPersonalMessage; + BTextView* fNameTextView; + BTextView* fSubjectTextView; BitmapView* fProtocolView; - BitmapView* fAvatar; + BitmapView* fIcon; + + CayaRenderView* fReceiveView; UserListView* fUserList; }; diff --git a/application/views/UserItem.cpp b/application/views/UserItem.cpp index 1c9427e..046964c 100644 --- a/application/views/UserItem.cpp +++ b/application/views/UserItem.cpp @@ -9,6 +9,7 @@ #include #include "CayaConstants.h" +#include "CayaUtils.h" #include "NotifyMessage.h" #include "User.h" @@ -17,9 +18,8 @@ UserItem::UserItem(const char* name, User* user, int32 status) : BStringItem(name), fUser(user), - fTextColor(ui_color(B_LIST_ITEM_TEXT_COLOR)) + fStatus(status) { - _UpdateColor(status); } @@ -27,7 +27,7 @@ void UserItem::DrawItem(BView* owner, BRect frame, bool complete) { rgb_color highColor = owner->HighColor(); - owner->SetHighColor(fTextColor); + owner->SetHighColor(_GetTextColor(highColor)); BStringItem::DrawItem(owner, frame, complete); @@ -52,7 +52,7 @@ UserItem::ObserveInteger(int32 what, int32 value) switch (what) { case INT_CONTACT_STATUS: { - _UpdateColor(value); + fStatus = value; break; } } @@ -66,54 +66,20 @@ UserItem::GetUser() } -void -UserItem::_UpdateColor(int32 status) +rgb_color +UserItem::_GetTextColor(rgb_color highColor) { - switch (status) + switch (fStatus) { case CAYA_AWAY: - fTextColor = _TintColor(ui_color(B_LIST_ITEM_TEXT_COLOR), 1); - break; + return CayaTintColor(ui_color(B_LIST_ITEM_TEXT_COLOR), 1); case CAYA_INVISIBLE: case CAYA_DO_NOT_DISTURB: - fTextColor = _TintColor(ui_color(B_LIST_ITEM_TEXT_COLOR), 2); - break; + return CayaTintColor(ui_color(B_LIST_ITEM_TEXT_COLOR), 2); case CAYA_OFFLINE: - fTextColor = _TintColor(ui_color(B_LIST_ITEM_TEXT_COLOR), 3); - break; - default: - fTextColor = ui_color(B_LIST_ITEM_TEXT_COLOR); - } -} - - -rgb_color -UserItem::_TintColor(rgb_color color, int severity) -{ - bool dark = false; - if (color.Brightness() < 127) - dark = true; - - switch (severity) - { - case 0: - return color; - case 1: - if (dark == true) - return tint_color(color, B_LIGHTEN_1_TINT + 0.2f); - else - return tint_color(color, B_DARKEN_1_TINT); - case 2: - if (dark == true) - return tint_color(color, B_LIGHTEN_1_TINT); - else - return tint_color(color, B_DARKEN_2_TINT); - case 3: - if (dark == true) - return tint_color(color, B_LIGHTEN_2_TINT + 0.1f); - else - return tint_color(color, B_DARKEN_3_TINT); + return CayaTintColor(ui_color(B_LIST_ITEM_TEXT_COLOR), 3); } + return highColor; } diff --git a/application/views/UserItem.h b/application/views/UserItem.h index e50fac9..c9d5b9c 100644 --- a/application/views/UserItem.h +++ b/application/views/UserItem.h @@ -25,12 +25,11 @@ public: User* GetUser(); protected: - void _UpdateColor(int32 status); - rgb_color _TintColor(rgb_color color, int severity); + rgb_color _GetTextColor(rgb_color highColor); private: - rgb_color fTextColor; User* fUser; + int fStatus; }; diff --git a/protocols/xmpp/JabberHandler.cpp b/protocols/xmpp/JabberHandler.cpp index c491619..76a32c7 100644 --- a/protocols/xmpp/JabberHandler.cpp +++ b/protocols/xmpp/JabberHandler.cpp @@ -1207,6 +1207,20 @@ void JabberHandler::handleMUCSubject(gloox::MUCRoom *room, const std::string &nick, const std::string &subject) { + BString user_id; + BString chat_id = _MUCChatId(room); + bool isSelf = _MUCUserId(chat_id, nick.c_str(), &user_id); + + if (chat_id.IsEmpty() == true) + return; + + BMessage msg(IM_MESSAGE); + msg.AddInt32("im_what", IM_ROOM_SUBJECT); + msg.AddString("subject", subject.c_str()); + msg.AddString("chat_id", chat_id); + if (user_id.IsEmpty() == false) + msg.AddString("user_id", user_id); + _SendMessage(&msg); }