75de08a18b
Protocol messages was added to the API to allow joining abstract rooms by their chat_id― IM_JOIN_ROOM and IM_ROOM_JOINED. To make room in anticipation of future room-related calls, some messages' values have been shifted. A JoinWindow was created (found through [Chat→Join Room] or [Alt-J] in the main window), to allow joining a room with this protocol message. The user can select which account the room should be joined from through a drop-down menu in the lower left-hand corner― a design I think could be replicated in other parts of Caya well. Path() and SetPath() in CayaProtocol were renamed to AddOnPath() and SetAddOnPath() respectively. GetName() and SetName() were also added, where "name" is the account name (aka the leaf of the protocols settings path). To Server, a new KeyMap was added for convenience (AccountInstances), to associate these account names with their instance IDs.
87 lines
2.1 KiB
C++
87 lines
2.1 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 _SERVER_H
|
|
#define _SERVER_H
|
|
|
|
#include <Message.h>
|
|
#include <MessageFilter.h>
|
|
|
|
#include <libsupport/KeyMap.h>
|
|
|
|
#include "CayaConstants.h"
|
|
#include "Contact.h"
|
|
#include "Conversation.h"
|
|
#include "User.h"
|
|
|
|
class CayaProtocol;
|
|
class RosterItem;
|
|
class ProtocolLooper;
|
|
|
|
|
|
typedef KeyMap<BString, Contact*> RosterMap;
|
|
typedef KeyMap<BString, User*> UserMap;
|
|
typedef KeyMap<BString, Conversation*> ChatMap;
|
|
typedef KeyMap<bigtime_t, ProtocolLooper*> ProtocolLoopers;
|
|
typedef KeyMap<BString, bigtime_t> AccountInstances;
|
|
|
|
|
|
class Server: public BMessageFilter {
|
|
public:
|
|
Server();
|
|
void Quit();
|
|
void LoginAll();
|
|
|
|
virtual filter_result Filter(BMessage* message, BHandler** target);
|
|
filter_result ImMessage(BMessage* msg);
|
|
|
|
void AddProtocolLooper(bigtime_t instanceId,
|
|
CayaProtocol* cayap);
|
|
void RemoveProtocolLooper(bigtime_t instanceId);
|
|
ProtocolLooper* GetProtocolLooper(bigtime_t instanceId);
|
|
|
|
AccountInstances
|
|
GetAccounts();
|
|
|
|
void SendProtocolMessage(BMessage* msg);
|
|
void SendAllProtocolMessage(BMessage* msg);
|
|
|
|
RosterMap Contacts() const;
|
|
Contact* ContactById(BString id);
|
|
void AddContact(Contact* contact);
|
|
|
|
UserMap Users() const;
|
|
User* UserById(BString id);
|
|
void AddUser(User* user);
|
|
|
|
ChatMap Conversations() const;
|
|
Conversation* ConversationById(BString id);
|
|
void AddConversation(Conversation* chat);
|
|
|
|
// TODO: there should be a contact for each account.
|
|
BString GetOwnContact();
|
|
|
|
private:
|
|
ProtocolLooper* _LooperFromMessage(BMessage* message);
|
|
|
|
Contact* _EnsureContact(BMessage* message);
|
|
User* _EnsureUser(BMessage* message);
|
|
Conversation* _EnsureConversation(BMessage* message);
|
|
|
|
void _ReplicantStatusNotify(CayaStatus status);
|
|
|
|
RosterMap fRosterMap;
|
|
UserMap fUserMap;
|
|
ChatMap fChatMap;
|
|
ProtocolLoopers fLoopers;
|
|
AccountInstances
|
|
fAccounts;
|
|
BString fMySelf;
|
|
};
|
|
|
|
|
|
#endif // _SERVER_H
|
|
|