2010-05-16 16:02:50 -05:00
|
|
|
/*
|
2021-06-11 17:24:04 -05:00
|
|
|
* Copyright 2021, Jaidyn Levesque. All rights reserved.
|
2011-12-03 16:38:03 -06:00
|
|
|
* Copyright 2009-2011, Andrea Anzani. All rights reserved.
|
|
|
|
* Copyright 2009-2011, Pier Luigi Fiorini. All rights reserved.
|
2010-05-16 16:02:50 -05:00
|
|
|
* Distributed under the terms of the MIT License.
|
|
|
|
*
|
|
|
|
* Authors:
|
|
|
|
* Andrea Anzani, andrea.anzani@gmail.com
|
|
|
|
* Pier Luigi Fiorini, pierluigi.fiorini@gmail.com
|
|
|
|
*/
|
|
|
|
|
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
|
|
|
#include "ProtocolLooper.h"
|
|
|
|
|
2010-05-16 16:02:50 -05:00
|
|
|
#include <String.h>
|
|
|
|
|
|
|
|
#include "Account.h"
|
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
|
|
|
#include "Conversation.h"
|
2021-06-11 17:24:04 -05:00
|
|
|
#include "ConversationAccountItem.h"
|
2010-05-16 16:02:50 -05:00
|
|
|
|
|
|
|
|
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
|
|
|
ProtocolLooper::ProtocolLooper(CayaProtocol* protocol, int64 instance)
|
2010-05-19 17:28:26 -05:00
|
|
|
:
|
|
|
|
BLooper(),
|
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
|
|
|
fProtocol(protocol),
|
2021-06-11 17:24:04 -05:00
|
|
|
fInstance(instance),
|
|
|
|
fListItem(NULL)
|
2010-05-16 16:02:50 -05:00
|
|
|
{
|
|
|
|
Account* account = reinterpret_cast<Account*>(
|
|
|
|
protocol->MessengerInterface());
|
|
|
|
|
|
|
|
BString name(protocol->FriendlySignature());
|
|
|
|
name << " - " << account->Name();
|
|
|
|
|
|
|
|
SetName(name.String());
|
|
|
|
Run();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-06-11 20:33:28 -05:00
|
|
|
ProtocolLooper::~ProtocolLooper()
|
|
|
|
{
|
|
|
|
fProtocol->Shutdown();
|
|
|
|
delete fProtocol;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-05-16 16:02:50 -05:00
|
|
|
void
|
|
|
|
ProtocolLooper::MessageReceived(BMessage* msg)
|
|
|
|
{
|
|
|
|
if (Protocol()->Process(msg) != B_OK)
|
|
|
|
BLooper::MessageReceived(msg);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
CayaProtocol*
|
|
|
|
ProtocolLooper::Protocol()
|
|
|
|
{
|
|
|
|
return fProtocol;
|
|
|
|
}
|
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
|
|
|
|
|
|
|
|
|
|
|
ChatMap
|
|
|
|
ProtocolLooper::Conversations() const
|
|
|
|
{
|
|
|
|
return fChatMap;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Conversation*
|
|
|
|
ProtocolLooper::ConversationById(BString id)
|
|
|
|
{
|
|
|
|
bool found = false;
|
|
|
|
return fChatMap.ValueFor(id, &found);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
ProtocolLooper::AddConversation(Conversation* chat)
|
|
|
|
{
|
|
|
|
fChatMap.AddItem(chat->GetId(), chat);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
ProtocolLooper::RemoveConversation(Conversation* chat)
|
|
|
|
{
|
|
|
|
fChatMap.RemoveItemFor(chat->GetId());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
RosterMap
|
|
|
|
ProtocolLooper::Contacts() const
|
|
|
|
{
|
|
|
|
return fRosterMap;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Contact*
|
|
|
|
ProtocolLooper::ContactById(BString id)
|
|
|
|
{
|
|
|
|
bool found = false;
|
|
|
|
return fRosterMap.ValueFor(id, &found);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
ProtocolLooper::AddContact(Contact* contact)
|
|
|
|
{
|
|
|
|
fRosterMap.AddItem(contact->GetId(), contact);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
UserMap
|
|
|
|
ProtocolLooper::Users() const
|
|
|
|
{
|
|
|
|
UserMap users = fUserMap;
|
|
|
|
|
|
|
|
for (int i = 0; i < fRosterMap.CountItems(); i++) {
|
|
|
|
User* user = (User*)fRosterMap.ValueAt(i);
|
|
|
|
users.AddItem(user->GetId(), user);
|
|
|
|
}
|
|
|
|
|
|
|
|
return users;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
User*
|
|
|
|
ProtocolLooper::UserById(BString id)
|
|
|
|
{
|
|
|
|
bool found = false;
|
|
|
|
User* user = ContactById(id);
|
|
|
|
if (user == NULL)
|
|
|
|
user = fUserMap.ValueFor(id, &found);
|
|
|
|
|
|
|
|
return user;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
ProtocolLooper::AddUser(User* user)
|
|
|
|
{
|
|
|
|
fUserMap.AddItem(user->GetId(), user);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
BString
|
|
|
|
ProtocolLooper::GetOwnId()
|
|
|
|
{
|
|
|
|
return fMySelf;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
ProtocolLooper::SetOwnId(BString user_id)
|
|
|
|
{
|
|
|
|
fMySelf = user_id;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int64
|
|
|
|
ProtocolLooper::GetInstance()
|
|
|
|
{
|
|
|
|
return fInstance;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-06-11 17:24:04 -05:00
|
|
|
ConversationAccountItem*
|
|
|
|
ProtocolLooper::GetListItem()
|
|
|
|
{
|
|
|
|
if (fListItem == NULL)
|
|
|
|
fListItem = new ConversationAccountItem(fProtocol->GetName(),
|
|
|
|
fInstance);
|
|
|
|
return fListItem;
|
|
|
|
}
|
|
|
|
|
|
|
|
|