2021-05-26 07:48:25 -05:00
|
|
|
/*
|
|
|
|
* Copyright 2009-2011, Andrea Anzani. All rights reserved.
|
|
|
|
* Copyright 2009-2011, Pier Luigi Fiorini. All rights reserved.
|
2021-06-18 16:41:09 -05:00
|
|
|
* Copyright 2021, Jaidyn Levesque. All rights reserved.
|
2021-05-26 07:48:25 -05:00
|
|
|
* Distributed under the terms of the MIT License.
|
|
|
|
*
|
|
|
|
* Authors:
|
|
|
|
* Andrea Anzani, andrea.anzani@gmail.com
|
|
|
|
* Pier Luigi Fiorini, pierluigi.fiorini@gmail.com
|
2021-06-18 16:41:09 -05:00
|
|
|
* Jaidyn Levesque, jadedctrl@teknik.io
|
2021-05-26 07:48:25 -05:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "RosterWindow.h"
|
|
|
|
|
2021-06-18 18:42:10 -05:00
|
|
|
#include <Button.h>
|
2021-05-26 07:48:25 -05:00
|
|
|
#include <LayoutBuilder.h>
|
2021-06-18 18:42:10 -05:00
|
|
|
#include <MenuField.h>
|
2021-05-26 07:48:25 -05:00
|
|
|
#include <Notification.h>
|
|
|
|
#include <ScrollView.h>
|
|
|
|
|
|
|
|
#include "CayaMessages.h"
|
|
|
|
#include "CayaPreferences.h"
|
|
|
|
#include "CayaProtocolMessages.h"
|
2021-06-18 18:42:10 -05:00
|
|
|
#include "CayaUtils.h"
|
2021-05-26 07:48:25 -05:00
|
|
|
#include "RosterItem.h"
|
|
|
|
#include "RosterListView.h"
|
2021-06-18 16:41:09 -05:00
|
|
|
#include "RosterView.h"
|
2021-05-26 07:48:25 -05:00
|
|
|
|
|
|
|
|
|
|
|
const uint32 kSendMessage = 'RWSM';
|
2021-06-18 18:42:10 -05:00
|
|
|
const uint32 kSelAccount = 'RWSA';
|
|
|
|
const uint32 kSelNoAccount = 'RWNA';
|
2021-05-26 07:48:25 -05:00
|
|
|
|
|
|
|
|
2021-06-08 21:43:30 -05:00
|
|
|
RosterWindow::RosterWindow(const char* title, BMessage* selectMsg,
|
2021-06-18 18:42:10 -05:00
|
|
|
BMessenger* messenger, Server* server, bigtime_t instance)
|
2021-05-26 07:48:25 -05:00
|
|
|
:
|
2021-06-01 21:42:22 -05:00
|
|
|
BWindow(BRect(0, 0, 300, 400), title, B_FLOATING_WINDOW, 0),
|
2021-05-26 07:48:25 -05:00
|
|
|
fTarget(messenger),
|
2021-06-08 21:43:30 -05:00
|
|
|
fMessage(selectMsg),
|
2021-06-18 18:42:10 -05:00
|
|
|
fAccounts(server->GetAccounts()),
|
2021-05-26 07:48:25 -05:00
|
|
|
fServer(server)
|
|
|
|
{
|
2021-06-18 18:42:10 -05:00
|
|
|
fRosterView = new RosterView("buddyView", server, instance),
|
2021-06-18 16:41:09 -05:00
|
|
|
fRosterView->SetInvocationMessage(new BMessage(kSendMessage));
|
2021-05-26 07:48:25 -05:00
|
|
|
|
2021-06-18 18:42:10 -05:00
|
|
|
fOkButton = new BButton("OK", new BMessage(kSendMessage));
|
2021-06-19 00:11:02 -05:00
|
|
|
|
|
|
|
BMenu* accountMenu;
|
|
|
|
|
|
|
|
// If a specific instance is given, disallow selecting other accounts
|
|
|
|
if (instance > -1) {
|
|
|
|
accountMenu = new BMenu("accountMenu");
|
|
|
|
BString name = "N/A";
|
|
|
|
for (int i = 0; i < fAccounts.CountItems(); i++)
|
|
|
|
if (fAccounts.ValueAt(i) == instance) {
|
|
|
|
name = fAccounts.KeyAt(i);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
accountMenu->AddItem(new BMenuItem(name.String(), NULL));
|
|
|
|
accountMenu->SetLabelFromMarked(true);
|
|
|
|
accountMenu->ItemAt(0)->SetMarked(true);
|
|
|
|
accountMenu->SetEnabled(false);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
accountMenu = CreateAccountMenu(fAccounts, BMessage(kSelAccount),
|
|
|
|
new BMessage(kSelNoAccount));
|
|
|
|
|
|
|
|
fAccountField = new BMenuField("accountMenuField", NULL, accountMenu);
|
2021-06-18 18:42:10 -05:00
|
|
|
|
2021-05-26 07:48:25 -05:00
|
|
|
BLayoutBuilder::Group<>(this, B_VERTICAL, 0.0f)
|
2021-06-18 18:42:10 -05:00
|
|
|
.SetInsets(B_USE_DEFAULT_SPACING)
|
|
|
|
.Add(fRosterView)
|
|
|
|
.AddGroup(B_HORIZONTAL)
|
|
|
|
.Add(fAccountField)
|
|
|
|
.AddGlue()
|
|
|
|
.Add(new BButton("Cancel", new BMessage(B_QUIT_REQUESTED)))
|
|
|
|
.Add(fOkButton)
|
2021-05-26 07:48:25 -05:00
|
|
|
.End()
|
|
|
|
.End();
|
|
|
|
CenterOnScreen();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
RosterWindow::MessageReceived(BMessage* message)
|
|
|
|
{
|
|
|
|
switch (message->what) {
|
|
|
|
case kSendMessage:
|
|
|
|
{
|
|
|
|
int index = message->FindInt32("index");
|
2021-06-18 16:41:09 -05:00
|
|
|
RosterItem* ritem = fRosterView->ListView()->RosterItemAt(index);
|
2021-05-26 07:48:25 -05:00
|
|
|
|
|
|
|
if (ritem == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
User* user = ritem->GetContact();
|
|
|
|
fMessage->AddString("user_id", user->GetId());
|
Explicitly tie Conversations, Contacts, and Users to their ProtocolLoopers
Previously, all Conversations/Contacts/Users were stored in the Server,
each in their respective KeyMaps, identified solely by their
identifiers. This leads to the glaring problem of overlap― if the user
has multiple accounts, some users/rooms might be used or present in multiple
accounts at the same time.
Now, each accounts' Contacts, Conversations, and Users are stored in
its ProtocolLooper, making this overlap impossible. An oversight of only
allowing one user identifier to be stored (fMySelf) in Server was also fixed
this way.
This is the bulk of the work required for multi-account support― now,
the user can join the same XMPP room on two seperate accounts, and it
works perfectly.
2021-06-10 15:16:43 -05:00
|
|
|
fMessage->AddInt64("instance", user->GetProtocolLooper()->GetInstance());
|
2021-05-26 07:48:25 -05:00
|
|
|
fTarget->SendMessage(fMessage);
|
|
|
|
PostMessage(B_QUIT_REQUESTED);
|
|
|
|
break;
|
|
|
|
}
|
2021-06-18 18:42:10 -05:00
|
|
|
case kSelAccount:
|
|
|
|
{
|
|
|
|
int index = message->FindInt32("index") - 1;
|
|
|
|
if (index < 0 || index > (fAccounts.CountItems() - 1))
|
|
|
|
return;
|
|
|
|
fRosterView->SetAccount(fAccounts.ValueAt(index));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case kSelNoAccount:
|
|
|
|
fRosterView->SetAccount(-1);
|
|
|
|
break;
|
2021-05-30 17:12:41 -05:00
|
|
|
case IM_MESSAGE:
|
2021-06-18 16:41:09 -05:00
|
|
|
fRosterView->MessageReceived(message);
|
2021-05-30 17:12:41 -05:00
|
|
|
break;
|
2021-05-26 07:48:25 -05:00
|
|
|
default:
|
|
|
|
BWindow::MessageReceived(message);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
RosterWindow::UpdateListItem(RosterItem* item)
|
|
|
|
{
|
2021-06-18 16:41:09 -05:00
|
|
|
fRosterView->UpdateListItem(item);
|
2021-05-26 07:48:25 -05:00
|
|
|
}
|