diff --git a/application/CayaProtocolMessages.h b/application/CayaProtocolMessages.h index 4a1a36b..26f5871 100644 --- a/application/CayaProtocolMessages.h +++ b/application/CayaProtocolMessages.h @@ -388,7 +388,15 @@ enum im_what_code { // Bool "x_to_protocol", Bool "x_priority", int32 "x_perms", // int32 "x_target_perms", int32 "x_target_antiperms" // Allowed: int64 "instance" - IM_REGISTER_USER_ITEM = 1101 + IM_REGISTER_USERLIST_ITEM = 1101, + + //! Register a pop-up item →Caya + // Just an archived BMenuItem with extra slots; if "instance" isn't + // specified, the item is global, rather than protocol-only. + // Requires: String "_label", Message "_msg", String "class" = "BMenuItem" + // Bool "x_to_protocol", int32 "x_perms" + // Allowed: int64 "instance" + IM_REGISTER_CHATLIST_ITEM = 1102 }; diff --git a/application/DefaultItems.cpp b/application/DefaultItems.cpp index 68193e3..c064015 100644 --- a/application/DefaultItems.cpp +++ b/application/DefaultItems.cpp @@ -95,6 +95,23 @@ DefaultCommands(BLooper* target) } +void +DefaultChatPopUpItems(BLooper* target) +{ + BMessage* leave = new BMessage(IM_MESSAGE); + leave->AddInt32("im_what", IM_LEAVE_ROOM); + + BMessage* item = new BMessage(IM_MESSAGE); + item->AddInt32("im_what", IM_REGISTER_CHATLIST_ITEM); + item->AddString("class", "BMenuItem"); + item->AddString("_label", "Leave chat"); + item->AddMessage("_msg", leave); + item->AddBool("x_to_protocol", true); + + target->PostMessage(item); +} + + void DefaultUserPopUpItems(BLooper* target) { @@ -142,7 +159,7 @@ _UserMenuItem(const char* label, BMessage* msg, int32 user_perms, bool toProtocol) { BMessage* item = new BMessage(IM_MESSAGE); - item->AddInt32("im_what", IM_REGISTER_USER_ITEM); + item->AddInt32("im_what", IM_REGISTER_USERLIST_ITEM); item->AddString("class", "BMenuItem"); item->AddString("_label", label); diff --git a/application/DefaultItems.h b/application/DefaultItems.h index 93fa0cb..f64f38a 100644 --- a/application/DefaultItems.h +++ b/application/DefaultItems.h @@ -12,6 +12,7 @@ class BMessage; void DefaultCommands(BLooper* target); +void DefaultChatPopUpItems(BLooper* target); void DefaultUserPopUpItems(BLooper* target); BMessage* _UserMenuItem(const char* label, BMessage* msg, int32 user_perms, int32 target_perms, diff --git a/application/ProtocolLooper.cpp b/application/ProtocolLooper.cpp index fdad8e1..7436a7d 100644 --- a/application/ProtocolLooper.cpp +++ b/application/ProtocolLooper.cpp @@ -178,6 +178,20 @@ ProtocolLooper::AddUserPopUpItem(BMessage* archived) } +BObjectList +ProtocolLooper::ChatPopUpItems() const +{ + return fChatItems; +} + + +void +ProtocolLooper::AddChatPopUpItem(BMessage* archived) +{ + fChatItems.AddItem(archived); +} + + BString ProtocolLooper::GetOwnId() { diff --git a/application/ProtocolLooper.h b/application/ProtocolLooper.h index 9d3f1fe..e452832 100644 --- a/application/ProtocolLooper.h +++ b/application/ProtocolLooper.h @@ -57,6 +57,10 @@ public: UserPopUpItems() const; void AddUserPopUpItem(BMessage* archived); + BObjectList + ChatPopUpItems() const; + void AddChatPopUpItem(BMessage* archived); + BString GetOwnId(); void SetOwnId(BString user_id); @@ -77,6 +81,7 @@ private: CommandMap fCommands; BObjectList fUserItems; + BObjectList fChatItems; ConversationAccountItem* fListItem; diff --git a/application/Server.cpp b/application/Server.cpp index 7b5db21..255ea12 100644 --- a/application/Server.cpp +++ b/application/Server.cpp @@ -532,7 +532,7 @@ Server::ImMessage(BMessage* msg) looper->AddCommand(cmd); break; } - case IM_REGISTER_USER_ITEM: + case IM_REGISTER_USERLIST_ITEM: { ProtocolLooper* looper = _LooperFromMessage(msg); if (looper == NULL) @@ -541,6 +541,15 @@ Server::ImMessage(BMessage* msg) looper->AddUserPopUpItem(new BMessage(*msg)); break; } + case IM_REGISTER_CHATLIST_ITEM: + { + ProtocolLooper* looper = _LooperFromMessage(msg); + if (looper == NULL) + fChatItems.AddItem(new BMessage(*msg)); + else + looper->AddChatPopUpItem(new BMessage(*msg)); + break; + } case IM_PROTOCOL_READY: { // Ready notification @@ -798,7 +807,7 @@ Server::CommandById(BString id, int64 instance) BObjectList -Server::ConversationPopUpItems() +Server::ChatPopUpItems() { return fChatItems; } diff --git a/application/Server.h b/application/Server.h index 4c47b20..f3184e4 100644 --- a/application/Server.h +++ b/application/Server.h @@ -61,7 +61,7 @@ public: ChatCommand* CommandById(BString id, int64 instance); - BObjectList ConversationPopUpItems(); + BObjectList ChatPopUpItems(); BObjectList UserPopUpItems(); private: diff --git a/application/views/ConversationListView.cpp b/application/views/ConversationListView.cpp index 35f40cd..5b519c4 100644 --- a/application/views/ConversationListView.cpp +++ b/application/views/ConversationListView.cpp @@ -46,21 +46,6 @@ ConversationListView::MessageReceived(BMessage* msg) break; } - case kLeaveSelectedChat: - { - ConversationItem* item; - int32 selIndex = CurrentSelection(); - - if ((item = (ConversationItem*)ItemAt(selIndex)) == NULL) - break; - - BMessage leave(IM_MESSAGE); - leave.AddInt32("im_what", IM_LEAVE_ROOM); - leave.AddString("chat_id", item->GetConversation()->GetId()); - item->GetConversation()->GetProtocolLooper()->MessageReceived(&leave); - break; - } - default: BListView::MessageReceived(msg); } @@ -172,13 +157,36 @@ BPopUpMenu* ConversationListView::_ConversationPopUp() { BPopUpMenu* menu = new BPopUpMenu("chatPopUp"); - menu->AddItem(new BMenuItem("Open chat" B_UTF8_ELLIPSIS, - new BMessage(kOpenSelectedChat))); - menu->AddItem(new BMenuItem("Leave chat", new BMessage(kLeaveSelectedChat))); - menu->SetTargetForItems(this); + int32 selIndex = CurrentSelection(); + ConversationItem* item; + if ((item = (ConversationItem*)ItemAt(selIndex)) == NULL) + return _BlankPopUp(); + Conversation* chat = item->GetConversation(); + ProtocolLooper* looper = chat->GetProtocolLooper(); + + Server* server = ((TheApp*)be_app)->GetMainWindow()->GetServer(); + BObjectList items = server->ChatPopUpItems(); + BObjectList protoItems = looper->ChatPopUpItems(); + items.AddList(&protoItems); + + for (int i = 0; i < items.CountItems(); i++) { + BMessage* itemMsg = items.ItemAt(i); + BMessage* msg = new BMessage(*itemMsg); + BMessage toSend; + msg->FindMessage("_msg", &toSend); + toSend.AddString("chat_id", chat->GetId()); + toSend.AddInt64("instance", looper->GetInstance()); + msg->ReplaceMessage("_msg", &toSend); + + BMenuItem* item = new BMenuItem(msg); + if (msg->GetBool("x_to_protocol", true) == true) + item->SetTarget(looper); + else + item->SetTarget(Window()); + menu->AddItem(item); + } return menu; - } diff --git a/application/views/UserListView.cpp b/application/views/UserListView.cpp index 0312fea..fdfa3ab 100644 --- a/application/views/UserListView.cpp +++ b/application/views/UserListView.cpp @@ -65,6 +65,8 @@ UserListView::_UserPopUp() Server* server = ((TheApp*)be_app)->GetMainWindow()->GetServer(); BObjectList items = server->UserPopUpItems(); + BObjectList protoItems = fChat->GetProtocolLooper()->UserPopUpItems(); + items.AddList(&protoItems); for (int i = 0; i < items.CountItems(); i++) { BMessage* itemMsg = items.ItemAt(i); diff --git a/application/windows/MainWindow.cpp b/application/windows/MainWindow.cpp index d99c884..3fd8646 100644 --- a/application/windows/MainWindow.cpp +++ b/application/windows/MainWindow.cpp @@ -56,6 +56,7 @@ MainWindow::MainWindow() // Register default commands & items DefaultCommands(this); DefaultUserPopUpItems(this); + DefaultChatPopUpItems(this); // Also through the editing filter (enter to send) AddCommonFilter(new EditingFilter(fSendView));