5b5840a79e
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.
64 lines
1.3 KiB
C++
64 lines
1.3 KiB
C++
/*
|
|
* Copyright 2009-2011, Andrea Anzani. All rights reserved.
|
|
* Copyright 2009-2011, Pier Luigi Fiorini. All rights reserved.
|
|
* Distributed under the terms of the MIT License.
|
|
*/
|
|
#ifndef _PROTOCOL_LOOPER_H
|
|
#define _PROTOCOL_LOOPER_H
|
|
|
|
#include <Looper.h>
|
|
#include <String.h>
|
|
|
|
#include <libsupport/KeyMap.h>
|
|
|
|
#include "CayaProtocol.h"
|
|
|
|
class Contact;
|
|
class Conversation;
|
|
class User;
|
|
|
|
|
|
typedef KeyMap<BString, Conversation*> ChatMap;
|
|
typedef KeyMap<BString, Contact*> RosterMap;
|
|
typedef KeyMap<BString, User*> UserMap;
|
|
|
|
|
|
class ProtocolLooper : public BLooper {
|
|
public:
|
|
ProtocolLooper(CayaProtocol* protocol, int64 instance);
|
|
|
|
void MessageReceived(BMessage* msg);
|
|
|
|
CayaProtocol* Protocol();
|
|
|
|
ChatMap Conversations() const;
|
|
Conversation* ConversationById(BString id);
|
|
void AddConversation(Conversation* chat);
|
|
void RemoveConversation(Conversation* chat);
|
|
|
|
RosterMap Contacts() const;
|
|
Contact* ContactById(BString id);
|
|
void AddContact(Contact* contact);
|
|
|
|
UserMap Users() const;
|
|
User* UserById(BString id);
|
|
void AddUser(User* user);
|
|
|
|
BString GetOwnId();
|
|
void SetOwnId(BString user_id);
|
|
|
|
int64 GetInstance();
|
|
|
|
private:
|
|
CayaProtocol* fProtocol;
|
|
int64 fInstance;
|
|
|
|
BString fMySelf;
|
|
|
|
ChatMap fChatMap;
|
|
RosterMap fRosterMap;
|
|
UserMap fUserMap;
|
|
};
|
|
|
|
#endif // _PROTOCOL_LOOPER_H
|