From 5723f5543330aba26cdc0364ad65ea10d8fc74ff Mon Sep 17 00:00:00 2001 From: Jaidyn Ann Date: Tue, 8 Jun 2021 21:43:30 -0500 Subject: [PATCH] Support sending invitations Fixes #5 --- application/views/UserListView.cpp | 1 - application/windows/MainWindow.cpp | 28 ++++++++++++++++++++++++---- application/windows/RosterWindow.cpp | 6 ++---- application/windows/RosterWindow.h | 2 +- protocols/xmpp/JabberHandler.cpp | 11 +++++++++++ 5 files changed, 38 insertions(+), 10 deletions(-) diff --git a/application/views/UserListView.cpp b/application/views/UserListView.cpp index 2d85103..f829116 100644 --- a/application/views/UserListView.cpp +++ b/application/views/UserListView.cpp @@ -139,7 +139,6 @@ UserListView::_BlankPopUp() BMenuItem* invite = new BMenuItem("Invite user…" B_UTF8_ELLIPSIS, new BMessage(CAYA_SEND_INVITE), 'I', B_COMMAND_KEY); - invite->SetEnabled(false); menu->AddItem(invite); menu->SetTargetForItems(Window()); diff --git a/application/windows/MainWindow.cpp b/application/windows/MainWindow.cpp index d9222a2..c7c582c 100644 --- a/application/windows/MainWindow.cpp +++ b/application/windows/MainWindow.cpp @@ -106,8 +106,11 @@ MainWindow::MessageReceived(BMessage* message) case CAYA_NEW_CHAT: { + BMessage* newMsg = new BMessage(IM_MESSAGE); + newMsg->AddInt32("im_what", IM_CREATE_CHAT); + fRosterWindow = new RosterWindow("Invite contact to chat" - B_UTF8_ELLIPSIS, IM_CREATE_CHAT, new BMessenger(this), fServer); + B_UTF8_ELLIPSIS, newMsg, new BMessenger(this), fServer); fRosterWindow->Show(); break; } @@ -120,10 +123,28 @@ MainWindow::MessageReceived(BMessage* message) break; } + case CAYA_SEND_INVITE: + { + if (fConversation == NULL) + break; + BString chat_id = fConversation->GetId(); + + BMessage* invite = new BMessage(IM_MESSAGE); + invite->AddInt32("im_what", IM_ROOM_SEND_INVITE); + invite->AddString("chat_id", chat_id); + + BLooper* looper = (BLooper*)fConversation->GetProtocolLooper(); + fRosterWindow = new RosterWindow("Invite contact to chat" + B_UTF8_ELLIPSIS, invite, new BMessenger(looper), fServer); + + fRosterWindow->Show(); + break; + } + case CAYA_MOVE_UP: { if (fConversation == NULL) - return; + break; int32 index = fListView->IndexOf(fConversation->GetListItem()); if (index > 0) @@ -134,7 +155,7 @@ MainWindow::MessageReceived(BMessage* message) case CAYA_MOVE_DOWN: { if (fConversation == NULL) - return; + break; int32 index = fListView->IndexOf(fConversation->GetListItem()); int32 count = fListView->CountItems(); @@ -372,7 +393,6 @@ MainWindow::_CreateMenuBar() BMenu* chatMenu = new BMenu("Chat"); BMenuItem* invite = new BMenuItem("Invite user" B_UTF8_ELLIPSIS, new BMessage(CAYA_SEND_INVITE), 'I', B_COMMAND_KEY); - invite->SetEnabled(false); BMenuItem* newRoom = new BMenuItem("New room" B_UTF8_ELLIPSIS, new BMessage(), 'N', B_COMMAND_KEY); newRoom->SetEnabled(false); diff --git a/application/windows/RosterWindow.cpp b/application/windows/RosterWindow.cpp index 69ee2d2..02a9db0 100644 --- a/application/windows/RosterWindow.cpp +++ b/application/windows/RosterWindow.cpp @@ -28,16 +28,14 @@ const uint32 kSearchContact = 'RWSC'; const uint32 kSendMessage = 'RWSM'; -RosterWindow::RosterWindow(const char* title, int32 selectMsg, +RosterWindow::RosterWindow(const char* title, BMessage* selectMsg, BMessenger* messenger, Server* server) : BWindow(BRect(0, 0, 300, 400), title, B_FLOATING_WINDOW, 0), fTarget(messenger), + fMessage(selectMsg), fServer(server) { - fMessage = new BMessage(IM_MESSAGE); - fMessage->AddInt32("im_what", selectMsg); - SearchBarTextControl* searchBox = new SearchBarTextControl(new BMessage(kSearchContact)); diff --git a/application/windows/RosterWindow.h b/application/windows/RosterWindow.h index 76bd17e..3380ae2 100644 --- a/application/windows/RosterWindow.h +++ b/application/windows/RosterWindow.h @@ -21,7 +21,7 @@ class Server; the server with contact info, once a contact is selected. */ class RosterWindow : public BWindow { public: - RosterWindow(const char* title, int32 selectMsg, BMessenger* messenger, + RosterWindow(const char* title, BMessage* selectMsg, BMessenger* messenger, Server* server); void MessageReceived(BMessage* message); diff --git a/protocols/xmpp/JabberHandler.cpp b/protocols/xmpp/JabberHandler.cpp index 415074f..b738406 100644 --- a/protocols/xmpp/JabberHandler.cpp +++ b/protocols/xmpp/JabberHandler.cpp @@ -181,6 +181,17 @@ JabberHandler::Process(BMessage* msg) break; } + case IM_ROOM_SEND_INVITE: { + BString chat_id = msg->FindString("chat_id"); + gloox::MUCRoom* room = fRooms.ValueFor(chat_id); + BString user_id; + if (room == NULL || msg->FindString("user_id", &user_id) != B_OK) + break; + + room->invite(gloox::JID(user_id.String()), ""); + break; + } + case IM_ROOM_KICK_PARTICIPANT: case IM_ROOM_BAN_PARTICIPANT: case IM_ROOM_UNBAN_PARTICIPANT: